From 17db82635d84d7ee52eff5042ccb8812053b7a98 Mon Sep 17 00:00:00 2001 From: Dylan Hurd Date: Fri, 6 Mar 2026 23:02:26 -0800 Subject: [PATCH] codex: fix CI failure on PR #13187 Co-authored-by: Codex --- codex-rs/core/src/codex.rs | 40 +++++++++++++++++++++ codex-rs/core/src/models_manager/manager.rs | 16 ++++++++- codex-rs/core/src/test_support.rs | 8 ++++- codex-rs/core/src/thread_manager.rs | 24 ++++++++++--- codex-rs/core/tests/common/test_codex.rs | 1 + 5 files changed, 82 insertions(+), 7 deletions(-) diff --git a/codex-rs/core/src/codex.rs b/codex-rs/core/src/codex.rs index 87240d398c..f46e2f567e 100644 --- a/codex-rs/core/src/codex.rs +++ b/codex-rs/core/src/codex.rs @@ -302,6 +302,7 @@ use codex_async_utils::OrCancelExt; use codex_otel::SessionTelemetry; use codex_otel::TelemetryAuthMode; use codex_protocol::config_types::CollaborationMode; +use codex_protocol::config_types::CollaborationModeMask; use codex_protocol::config_types::Personality; use codex_protocol::config_types::ReasoningSummary as ReasoningSummaryConfig; use codex_protocol::config_types::ServiceTier; @@ -973,6 +974,26 @@ impl SessionConfiguration { } } +fn merge_collaboration_mode_with_preset( + collaboration_mode: CollaborationMode, + preset: &CollaborationModeMask, +) -> CollaborationMode { + CollaborationMode { + mode: collaboration_mode.mode, + settings: Settings { + model: collaboration_mode.settings.model, + reasoning_effort: collaboration_mode + .settings + .reasoning_effort + .or(preset.reasoning_effort.flatten()), + developer_instructions: collaboration_mode + .settings + .developer_instructions + .or_else(|| preset.developer_instructions.clone().flatten()), + }, + } +} + #[derive(Default, Clone)] pub(crate) struct SessionSettingsUpdate { pub(crate) cwd: Option, @@ -988,6 +1009,23 @@ pub(crate) struct SessionSettingsUpdate { } impl Session { + fn resolve_session_settings_update( + &self, + mut updates: SessionSettingsUpdate, + ) -> SessionSettingsUpdate { + updates.collaboration_mode = updates.collaboration_mode.map(|collaboration_mode| { + self.services + .models_manager + .list_collaboration_modes() + .into_iter() + .find(|preset| preset.mode == Some(collaboration_mode.mode)) + .map_or(collaboration_mode.clone(), |preset| { + merge_collaboration_mode_with_preset(collaboration_mode, &preset) + }) + }); + updates + } + /// Builds the `x-codex-beta-features` header value for this session. /// /// `ModelClient` is session-scoped and intentionally does not depend on the full `Config`, so @@ -2081,6 +2119,7 @@ impl Session { &self, updates: SessionSettingsUpdate, ) -> ConstraintResult<()> { + let updates = self.resolve_session_settings_update(updates); let mut state = self.state.lock().await; match state.session_configuration.apply(&updates) { @@ -2113,6 +2152,7 @@ impl Session { sub_id: String, updates: SessionSettingsUpdate, ) -> ConstraintResult> { + let updates = self.resolve_session_settings_update(updates); let ( session_configuration, sandbox_policy_changed, diff --git a/codex-rs/core/src/models_manager/manager.rs b/codex-rs/core/src/models_manager/manager.rs index 98e8febdb5..c21728631c 100644 --- a/codex-rs/core/src/models_manager/manager.rs +++ b/codex-rs/core/src/models_manager/manager.rs @@ -386,6 +386,20 @@ impl ModelsManager { codex_home: PathBuf, auth_manager: Arc, provider: ModelProviderInfo, + ) -> Self { + Self::with_provider_and_plan_instructions_for_tests( + codex_home, + auth_manager, + provider, + None, + ) + } + + pub(crate) fn with_provider_and_plan_instructions_for_tests( + codex_home: PathBuf, + auth_manager: Arc, + provider: ModelProviderInfo, + plan_mode_developer_instructions: Option, ) -> Self { let cache_path = codex_home.join(MODEL_CACHE_FILE); let cache_manager = ModelsCacheManager::new(cache_path, DEFAULT_MODEL_CACHE_TTL); @@ -400,7 +414,7 @@ impl ModelsManager { etag: RwLock::new(None), cache_manager, provider, - plan_mode_developer_instructions: None, + plan_mode_developer_instructions, } } diff --git a/codex-rs/core/src/test_support.rs b/codex-rs/core/src/test_support.rs index 70a52c0249..64cae4b245 100644 --- a/codex-rs/core/src/test_support.rs +++ b/codex-rs/core/src/test_support.rs @@ -60,8 +60,14 @@ pub fn thread_manager_with_models_provider_and_home( auth: CodexAuth, provider: ModelProviderInfo, codex_home: PathBuf, + plan_mode_developer_instructions: Option, ) -> ThreadManager { - ThreadManager::with_models_provider_and_home_for_tests(auth, provider, codex_home) + ThreadManager::with_models_provider_and_home_and_plan_instructions_for_tests( + auth, + provider, + codex_home, + plan_mode_developer_instructions, + ) } pub fn models_manager_with_provider( diff --git a/codex-rs/core/src/thread_manager.rs b/codex-rs/core/src/thread_manager.rs index bcf41f7cf3..077b9adfa2 100644 --- a/codex-rs/core/src/thread_manager.rs +++ b/codex-rs/core/src/thread_manager.rs @@ -209,6 +209,17 @@ impl ThreadManager { auth: CodexAuth, provider: ModelProviderInfo, codex_home: PathBuf, + ) -> Self { + Self::with_models_provider_and_home_and_plan_instructions_for_tests( + auth, provider, codex_home, None, + ) + } + + pub(crate) fn with_models_provider_and_home_and_plan_instructions_for_tests( + auth: CodexAuth, + provider: ModelProviderInfo, + codex_home: PathBuf, + plan_mode_developer_instructions: Option, ) -> Self { set_thread_manager_test_mode_for_tests(true); let auth_manager = AuthManager::from_auth_for_testing(auth); @@ -224,11 +235,14 @@ impl ThreadManager { state: Arc::new(ThreadManagerState { threads: Arc::new(RwLock::new(HashMap::new())), thread_created_tx, - models_manager: Arc::new(ModelsManager::with_provider_for_tests( - codex_home, - auth_manager.clone(), - provider, - )), + models_manager: Arc::new( + ModelsManager::with_provider_and_plan_instructions_for_tests( + codex_home, + auth_manager.clone(), + provider, + plan_mode_developer_instructions, + ), + ), skills_manager, plugins_manager, mcp_manager, diff --git a/codex-rs/core/tests/common/test_codex.rs b/codex-rs/core/tests/common/test_codex.rs index 9776291dd7..860ea22efb 100644 --- a/codex-rs/core/tests/common/test_codex.rs +++ b/codex-rs/core/tests/common/test_codex.rs @@ -193,6 +193,7 @@ impl TestCodexBuilder { auth.clone(), config.model_provider.clone(), config.codex_home.clone(), + config.plan_mode_developer_instructions.clone(), ) }; let thread_manager = Arc::new(thread_manager);