From 33190a9fd5b5db4b2785bf4ad2d0f0fc4edb0e95 Mon Sep 17 00:00:00 2001 From: Erik Weathers <1111441+erikdw@users.noreply.github.com> Date: Tue, 24 Nov 2026 15:58:03 -0800 Subject: [PATCH] Tolerate null Codex feature flags during hook activation Codex's config/read reports every feature flag, and leaves some unset flags as null (for example network_proxy). Setup decoded the whole map as bool, so one null failed the response and `bt trace update codex` reported "Codex plugin installed, but hook activation failed". Decode only the two flags setup reads, as Option. Null and absent both mean Codex's default; only an explicit false disables hooks. Co-Authored-By: Claude Opus 5.5 --- bt-daemon/src/codex_hooks/config.rs | 17 +++++++++++++---- bt-daemon/src/codex_hooks/tests.rs | 19 +++++++++++++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/bt-daemon/src/codex_hooks/config.rs b/bt-daemon/src/codex_hooks/config.rs index c3d5b48f..77a8d7b6 100644 --- a/bt-daemon/src/codex_hooks/config.rs +++ b/bt-daemon/src/codex_hooks/config.rs @@ -1,15 +1,24 @@ use serde::Deserialize; -use std::collections::BTreeMap; #[derive(Deserialize)] pub(super) struct Config { #[serde(default)] - pub(super) features: BTreeMap, + pub(super) features: Features, +} + +/// Only the flags setup reads. Codex reports every feature flag here, and some +/// are `null` when unset (for example `network_proxy`), so other flags must not +/// be decoded. `null` and an absent flag both mean Codex's default. +#[derive(Default, Deserialize)] +pub(super) struct Features { + #[serde(default)] + hooks: Option, + #[serde(default)] + codex_hooks: Option, } impl Config { pub(super) fn hooks_enabled(&self) -> bool { - self.features.get("hooks") != Some(&false) - && self.features.get("codex_hooks") != Some(&false) + self.features.hooks != Some(false) && self.features.codex_hooks != Some(false) } } diff --git a/bt-daemon/src/codex_hooks/tests.rs b/bt-daemon/src/codex_hooks/tests.rs index 0ecc412b..dd50351a 100644 --- a/bt-daemon/src/codex_hooks/tests.rs +++ b/bt-daemon/src/codex_hooks/tests.rs @@ -53,3 +53,22 @@ async fn rpc_ignores_notifications_and_reports_unsupported_methods() { "hooks/list" ); } + +#[test] +fn config_read_tolerates_null_feature_flags() { + let read = |features: Value| { + serde_json::from_value::(json!({"config": {"features": features}})) + .unwrap() + .config + .hooks_enabled() + }; + assert!(read(json!({"hooks": true, "network_proxy": null}))); + assert!(read(json!({"hooks": null, "codex_hooks": null}))); + assert!(read(json!({"network_proxy": {"enabled": true}}))); + assert!(!read(json!({"hooks": false, "network_proxy": null}))); + assert!(!read(json!({"hooks": true, "codex_hooks": false}))); + assert!(serde_json::from_value::(json!({"config": {}})) + .unwrap() + .config + .hooks_enabled()); +}