diff --git a/codex-rs/app-server/tests/suite/conversation_summary.rs b/codex-rs/app-server/tests/suite/conversation_summary.rs index a71e31e3dd..fc32716a9b 100644 --- a/codex-rs/app-server/tests/suite/conversation_summary.rs +++ b/codex-rs/app-server/tests/suite/conversation_summary.rs @@ -129,7 +129,7 @@ async fn get_conversation_summary_by_thread_id_reads_pathless_store_thread() -> thread_source: None, base_instructions: BaseInstructions::default(), dynamic_tools: Vec::new(), - multi_agent_version: codex_protocol::protocol::MultiAgentVersion::None, + multi_agent_version: None, metadata: ThreadPersistenceMetadata { cwd: None, model_provider: "test-provider".to_string(), diff --git a/codex-rs/app-server/tests/suite/v2/thread_read.rs b/codex-rs/app-server/tests/suite/v2/thread_read.rs index 9e6be687bb..ce375fc330 100644 --- a/codex-rs/app-server/tests/suite/v2/thread_read.rs +++ b/codex-rs/app-server/tests/suite/v2/thread_read.rs @@ -1363,7 +1363,7 @@ async fn seed_pathless_store_thread( thread_source: None, base_instructions: BaseInstructions::default(), dynamic_tools: Vec::new(), - multi_agent_version: codex_protocol::protocol::MultiAgentVersion::None, + multi_agent_version: None, metadata: ThreadPersistenceMetadata { cwd: None, model_provider: "test-provider".to_string(), diff --git a/codex-rs/app-server/tests/suite/v2/thread_unarchive.rs b/codex-rs/app-server/tests/suite/v2/thread_unarchive.rs index f6a31c750e..7be1ba82ba 100644 --- a/codex-rs/app-server/tests/suite/v2/thread_unarchive.rs +++ b/codex-rs/app-server/tests/suite/v2/thread_unarchive.rs @@ -216,7 +216,7 @@ async fn thread_unarchive_preserves_pathless_store_metadata() -> Result<()> { thread_source: None, base_instructions: BaseInstructions::default(), dynamic_tools: Vec::new(), - multi_agent_version: codex_protocol::protocol::MultiAgentVersion::None, + multi_agent_version: None, metadata: ThreadPersistenceMetadata { cwd: None, model_provider: "test-provider".to_string(), diff --git a/codex-rs/core/src/agent/control.rs b/codex-rs/core/src/agent/control.rs index cb75b32533..4d58f68073 100644 --- a/codex-rs/core/src/agent/control.rs +++ b/codex-rs/core/src/agent/control.rs @@ -57,7 +57,7 @@ pub(crate) struct SpawnAgentOptions { pub(crate) fork_mode: Option, pub(crate) parent_thread_id: Option, pub(crate) environments: Option>, - pub(crate) multi_agent_version: Option, + pub(crate) multi_agent_version: Option>, } #[derive(Clone, Debug)] @@ -357,7 +357,7 @@ impl AgentControl { self.send_input(new_thread.thread_id, initial_operation) .await?; - if new_thread.thread.multi_agent_version().await != MultiAgentVersion::V2 { + if new_thread.thread.multi_agent_version().await != Some(MultiAgentVersion::V2) { let child_reference = agent_metadata .agent_path .as_ref() @@ -386,7 +386,7 @@ impl AgentControl { options: &SpawnAgentOptions, inherited_shell_snapshot: Option>, inherited_exec_policy: Option>, - inherited_multi_agent_version: Option, + inherited_multi_agent_version: Option>, ) -> CodexResult { if options.fork_parent_spawn_call_id.is_none() { return Err(CodexErr::Fatal( @@ -449,7 +449,7 @@ impl AgentControl { } let multi_agent_v2_usage_hint_texts_to_filter: Vec = if let Some(parent_thread) = parent_thread.as_ref() { - if multi_agent_version == MultiAgentVersion::V2 { + if multi_agent_version == Some(MultiAgentVersion::V2) { let parent_config = parent_thread.codex.session.get_config().await; [ parent_config @@ -467,7 +467,7 @@ impl AgentControl { } else { Vec::new() } - } else if multi_agent_version == MultiAgentVersion::V2 { + } else if multi_agent_version == Some(MultiAgentVersion::V2) { [ config.multi_agent_v2.root_agent_usage_hint_text.clone(), config.multi_agent_v2.subagent_usage_hint_text.clone(), @@ -503,7 +503,7 @@ impl AgentControl { } } if preserve_reference_context_item - && multi_agent_version == MultiAgentVersion::V2 + && multi_agent_version == Some(MultiAgentVersion::V2) && let Some(subagent_usage_hint_text) = config.multi_agent_v2.subagent_usage_hint_text.clone() && let Some(subagent_usage_hint_message) = @@ -706,7 +706,7 @@ impl AgentControl { // Resumed threads are re-registered in-memory and need the same listener // attachment path as freshly spawned threads. state.notify_thread_created(resumed_thread.thread_id); - if resumed_thread.thread.multi_agent_version().await != MultiAgentVersion::V2 { + if resumed_thread.thread.multi_agent_version().await != Some(MultiAgentVersion::V2) { let child_reference = agent_metadata .agent_path .as_ref() @@ -1093,7 +1093,7 @@ impl AgentControl { let message = format_subagent_notification_message(child_reference.as_str(), &status); let child_uses_multi_agent_v2 = match child_thread.as_ref() { Some(child_thread) => { - child_thread.multi_agent_version().await == MultiAgentVersion::V2 + child_thread.multi_agent_version().await == Some(MultiAgentVersion::V2) } None => true, }; @@ -1195,8 +1195,8 @@ impl AgentControl { &self, state: &Arc, session_source: Option<&SessionSource>, - requested_multi_agent_version: Option, - ) -> Option { + requested_multi_agent_version: Option>, + ) -> Option> { if requested_multi_agent_version.is_some() { return requested_multi_agent_version; } diff --git a/codex-rs/core/src/agent/control_tests.rs b/codex-rs/core/src/agent/control_tests.rs index 006ca5f63e..9b67c75a8c 100644 --- a/codex-rs/core/src/agent/control_tests.rs +++ b/codex-rs/core/src/agent/control_tests.rs @@ -611,7 +611,10 @@ async fn spawn_agent_inherits_parent_multi_agent_version_over_child_feature_flag .await .expect("child thread should be registered"); - assert_eq!(child.multi_agent_version().await, MultiAgentVersion::V2); + assert_eq!( + child.multi_agent_version().await, + Some(MultiAgentVersion::V2) + ); } #[tokio::test] diff --git a/codex-rs/core/src/codex_delegate.rs b/codex-rs/core/src/codex_delegate.rs index 7fcbd2b015..e54e166a6e 100644 --- a/codex-rs/core/src/codex_delegate.rs +++ b/codex-rs/core/src/codex_delegate.rs @@ -72,7 +72,7 @@ pub(crate) async fn run_codex_thread_interactive( cancel_token: CancellationToken, subagent_source: SubAgentSource, initial_history: Option, - multi_agent_version: MultiAgentVersion, + multi_agent_version: Option, ) -> Result { let (tx_sub, rx_sub) = async_channel::bounded(SUBMISSION_CHANNEL_CAPACITY); let (tx_ops, rx_ops) = async_channel::bounded(SUBMISSION_CHANNEL_CAPACITY); @@ -178,7 +178,7 @@ pub(crate) async fn run_codex_thread_one_shot( subagent_source: SubAgentSource, final_output_json_schema: Option, initial_history: Option, - multi_agent_version: MultiAgentVersion, + multi_agent_version: Option, ) -> Result { // Use a child token so we can stop the delegate after completion without // requiring the caller to cancel the parent token. diff --git a/codex-rs/core/src/codex_delegate_tests.rs b/codex-rs/core/src/codex_delegate_tests.rs index 0c7981f064..f72ad03e64 100644 --- a/codex-rs/core/src/codex_delegate_tests.rs +++ b/codex-rs/core/src/codex_delegate_tests.rs @@ -172,7 +172,7 @@ async fn run_codex_thread_interactive_respects_pre_cancelled_spawn() { cancel_token, SubAgentSource::Review, /*initial_history*/ None, - codex_protocol::protocol::MultiAgentVersion::None, + /*multi_agent_version*/ None, ), ) .await diff --git a/codex-rs/core/src/codex_thread.rs b/codex-rs/core/src/codex_thread.rs index 8d80cfd530..9e60783230 100644 --- a/codex-rs/core/src/codex_thread.rs +++ b/codex-rs/core/src/codex_thread.rs @@ -503,7 +503,7 @@ impl CodexThread { self.codex.session.get_config().await } - pub async fn multi_agent_version(&self) -> MultiAgentVersion { + pub async fn multi_agent_version(&self) -> Option { self.codex.session.multi_agent_version().await } diff --git a/codex-rs/core/src/config/config_tests.rs b/codex-rs/core/src/config/config_tests.rs index 85f594580b..3f22670e28 100644 --- a/codex-rs/core/src/config/config_tests.rs +++ b/codex-rs/core/src/config/config_tests.rs @@ -9910,10 +9910,7 @@ async fn multi_agent_version_resolution_prefers_v2_then_v1_then_disabled() -> st .features .disable(Feature::Collab) .expect("test config should allow feature update"); - assert_eq!( - config.multi_agent_version_from_features(), - codex_protocol::protocol::MultiAgentVersion::None - ); + assert_eq!(config.multi_agent_version_from_features(), None); config .features @@ -9921,7 +9918,7 @@ async fn multi_agent_version_resolution_prefers_v2_then_v1_then_disabled() -> st .expect("test config should allow feature update"); assert_eq!( config.multi_agent_version_from_features(), - codex_protocol::protocol::MultiAgentVersion::V1 + Some(codex_protocol::protocol::MultiAgentVersion::V1) ); config @@ -9930,7 +9927,7 @@ async fn multi_agent_version_resolution_prefers_v2_then_v1_then_disabled() -> st .expect("test config should allow feature update"); assert_eq!( config.multi_agent_version_from_features(), - codex_protocol::protocol::MultiAgentVersion::V2 + Some(codex_protocol::protocol::MultiAgentVersion::V2) ); Ok(()) @@ -9955,7 +9952,7 @@ max_threads = 3 .build() .await?; let err = config - .apply_multi_agent_version(codex_protocol::protocol::MultiAgentVersion::V2) + .apply_multi_agent_version(Some(codex_protocol::protocol::MultiAgentVersion::V2)) .expect_err("agents.max_threads should conflict with multi_agent_v2"); assert_eq!(err.kind(), std::io::ErrorKind::InvalidInput); diff --git a/codex-rs/core/src/config/mod.rs b/codex-rs/core/src/config/mod.rs index 46a3d3c1e6..c552f06dad 100644 --- a/codex-rs/core/src/config/mod.rs +++ b/codex-rs/core/src/config/mod.rs @@ -1284,22 +1284,22 @@ impl ConfigBuilder { } impl Config { - pub(crate) fn multi_agent_version_from_features(&self) -> MultiAgentVersion { + pub(crate) fn multi_agent_version_from_features(&self) -> Option { if self.features.enabled(Feature::MultiAgentV2) { - MultiAgentVersion::V2 + Some(MultiAgentVersion::V2) } else if self.features.enabled(Feature::Collab) { - MultiAgentVersion::V1 + Some(MultiAgentVersion::V1) } else { - MultiAgentVersion::None + None } } pub(crate) fn apply_multi_agent_version( &mut self, - multi_agent_version: MultiAgentVersion, + multi_agent_version: Option, ) -> std::io::Result<()> { self.agent_max_threads = match multi_agent_version { - MultiAgentVersion::V2 => { + Some(MultiAgentVersion::V2) => { if self.configured_agent_max_threads.is_some() { return Err(std::io::Error::new( std::io::ErrorKind::InvalidInput, @@ -1312,7 +1312,7 @@ impl Config { .saturating_sub(1), ) } - MultiAgentVersion::None | MultiAgentVersion::V1 => self + None | Some(MultiAgentVersion::V1) => self .configured_agent_max_threads .or(DEFAULT_AGENT_MAX_THREADS), }; diff --git a/codex-rs/core/src/guardian/review_session.rs b/codex-rs/core/src/guardian/review_session.rs index 2394affe81..88ffa7d225 100644 --- a/codex-rs/core/src/guardian/review_session.rs +++ b/codex-rs/core/src/guardian/review_session.rs @@ -19,7 +19,6 @@ use codex_protocol::protocol::Event; use codex_protocol::protocol::EventMsg; use codex_protocol::protocol::ForkedHistory; use codex_protocol::protocol::InitialHistory; -use codex_protocol::protocol::MultiAgentVersion; use codex_protocol::protocol::Op; use codex_protocol::protocol::RolloutItem; use codex_protocol::protocol::SandboxPolicy; @@ -611,7 +610,7 @@ async fn spawn_guardian_review_session( cancel_token.clone(), SubAgentSource::Other(GUARDIAN_REVIEWER_NAME.to_string()), initial_history, - MultiAgentVersion::None, + /*multi_agent_version*/ None, )) .await?; diff --git a/codex-rs/core/src/session/config_lock.rs b/codex-rs/core/src/session/config_lock.rs index 9cea171cf1..a614d6735e 100644 --- a/codex-rs/core/src/session/config_lock.rs +++ b/codex-rs/core/src/session/config_lock.rs @@ -147,18 +147,15 @@ fn save_config_resolved_fields( .features .get_or_insert_with(FeaturesToml::default); let mut materialized_features = config.features.get().clone(); - materialized_features.set_enabled( - Feature::Collab, - sc.multi_agent_version != MultiAgentVersion::None, - ); + materialized_features.set_enabled(Feature::Collab, sc.multi_agent_version.is_some()); materialized_features.set_enabled( Feature::MultiAgentV2, - sc.multi_agent_version == MultiAgentVersion::V2, + sc.multi_agent_version == Some(MultiAgentVersion::V2), ); features.materialize_resolved_enabled(&materialized_features); let mut multi_agent_v2: MultiAgentV2ConfigToml = resolved_config_to_toml(&config.multi_agent_v2, "features.multi_agent_v2")?; - multi_agent_v2.enabled = Some(sc.multi_agent_version == MultiAgentVersion::V2); + multi_agent_v2.enabled = Some(sc.multi_agent_version == Some(MultiAgentVersion::V2)); features.multi_agent_v2 = Some(FeatureToml::Config(multi_agent_v2)); features.apps_mcp_path_override = Some(FeatureToml::Config(AppsMcpPathOverrideConfigToml { enabled: Some(config.features.enabled(Feature::AppsMcpPathOverride)), @@ -172,7 +169,7 @@ fn save_config_resolved_fields( let agents = lock_config.agents.get_or_insert_with(Default::default); // Multi-agent v2 owns thread fanout through its feature config. Preserve // the legacy agents.max_threads setting only when v2 is disabled. - agents.max_threads = if sc.multi_agent_version == MultiAgentVersion::V2 { + agents.max_threads = if sc.multi_agent_version == Some(MultiAgentVersion::V2) { None } else { config.agent_max_threads @@ -295,9 +292,9 @@ mod tests { sc.original_config_do_not_use = Arc::new(config); for (multi_agent_version, collab, multi_agent_v2) in [ - (MultiAgentVersion::None, false, false), - (MultiAgentVersion::V1, true, false), - (MultiAgentVersion::V2, true, true), + (None, false, false), + (Some(MultiAgentVersion::V1), true, false), + (Some(MultiAgentVersion::V2), true, true), ] { sc.multi_agent_version = multi_agent_version; let lockfile = sc.to_config_lockfile_toml().expect("lock should serialize"); @@ -318,7 +315,7 @@ mod tests { .expect("lock should materialize agent config") .max_threads .is_none(), - multi_agent_version == MultiAgentVersion::V2 + multi_agent_version == Some(MultiAgentVersion::V2) ); } } diff --git a/codex-rs/core/src/session/mod.rs b/codex-rs/core/src/session/mod.rs index 856be547b3..57a3f42d3c 100644 --- a/codex-rs/core/src/session/mod.rs +++ b/codex-rs/core/src/session/mod.rs @@ -421,7 +421,7 @@ pub(crate) struct CodexSpawnArgs { pub(crate) analytics_events_client: Option, pub(crate) thread_store: Arc, pub(crate) attestation_provider: Option>, - pub(crate) multi_agent_version: MultiAgentVersion, + pub(crate) multi_agent_version: Option, } pub(crate) const INITIAL_SUBMIT_ID: &str = ""; @@ -1652,7 +1652,7 @@ impl Session { turn_context: &TurnContext, msg: &EventMsg, ) { - if turn_context.multi_agent_version != MultiAgentVersion::V2 { + if turn_context.multi_agent_version != Some(MultiAgentVersion::V2) { return; } @@ -2623,7 +2623,7 @@ impl Session { state.session_configuration.collaboration_mode.clone() } - pub(crate) async fn multi_agent_version(&self) -> MultiAgentVersion { + pub(crate) async fn multi_agent_version(&self) -> Option { let state = self.state.lock().await; state.session_configuration.multi_agent_version } diff --git a/codex-rs/core/src/session/multi_agents.rs b/codex-rs/core/src/session/multi_agents.rs index a78a9c938e..e4423b29ed 100644 --- a/codex-rs/core/src/session/multi_agents.rs +++ b/codex-rs/core/src/session/multi_agents.rs @@ -7,7 +7,7 @@ pub(super) fn usage_hint_text<'a>( turn_context: &'a TurnContext, session_source: &SessionSource, ) -> Option<&'a str> { - if turn_context.multi_agent_version != MultiAgentVersion::V2 { + if turn_context.multi_agent_version != Some(MultiAgentVersion::V2) { return None; } diff --git a/codex-rs/core/src/session/session.rs b/codex-rs/core/src/session/session.rs index 6527092272..5d3d615db5 100644 --- a/codex-rs/core/src/session/session.rs +++ b/codex-rs/core/src/session/session.rs @@ -46,7 +46,7 @@ pub(crate) struct SessionConfiguration { pub(super) provider: ModelProviderInfo, pub(super) collaboration_mode: CollaborationMode, - pub(super) multi_agent_version: MultiAgentVersion, + pub(super) multi_agent_version: Option, pub(super) model_reasoning_summary: Option, pub(super) service_tier: Option, diff --git a/codex-rs/core/src/session/tests.rs b/codex-rs/core/src/session/tests.rs index 43dfb20107..c930b1d6df 100644 --- a/codex-rs/core/src/session/tests.rs +++ b/codex-rs/core/src/session/tests.rs @@ -3466,7 +3466,7 @@ async fn attach_thread_persistence(session: &mut Session) -> PathBuf { thread_source: None, base_instructions: BaseInstructions::default(), dynamic_tools: Vec::new(), - multi_agent_version: codex_protocol::protocol::MultiAgentVersion::None, + multi_agent_version: None, metadata: ThreadPersistenceMetadata { cwd: Some(config.cwd.to_path_buf()), model_provider: config.model_provider_id.clone(), @@ -5974,7 +5974,7 @@ async fn shutdown_complete_does_not_append_to_thread_store_after_shutdown() { thread_source: None, base_instructions: BaseInstructions::default(), dynamic_tools: Vec::new(), - multi_agent_version: codex_protocol::protocol::MultiAgentVersion::None, + multi_agent_version: None, metadata: ThreadPersistenceMetadata { cwd: Some(config.cwd.to_path_buf()), model_provider: config.model_provider_id.clone(), diff --git a/codex-rs/core/src/session/tests/guardian_tests.rs b/codex-rs/core/src/session/tests/guardian_tests.rs index 4881211bd8..06d65c495a 100644 --- a/codex-rs/core/src/session/tests/guardian_tests.rs +++ b/codex-rs/core/src/session/tests/guardian_tests.rs @@ -710,7 +710,7 @@ async fn guardian_subagent_does_not_inherit_parent_exec_policy_rules() { analytics_events_client: None, thread_store, attestation_provider: None, - multi_agent_version: codex_protocol::protocol::MultiAgentVersion::None, + multi_agent_version: None, }) .await .expect("spawn guardian subagent"); @@ -730,10 +730,7 @@ async fn guardian_subagent_does_not_inherit_parent_exec_policy_rules() { }], } ); - assert_eq!( - codex.session.multi_agent_version().await, - codex_protocol::protocol::MultiAgentVersion::None - ); + assert_eq!(codex.session.multi_agent_version().await, None); drop(codex); } diff --git a/codex-rs/core/src/session/turn_context.rs b/codex-rs/core/src/session/turn_context.rs index 11145a93c7..50ad3c3538 100644 --- a/codex-rs/core/src/session/turn_context.rs +++ b/codex-rs/core/src/session/turn_context.rs @@ -79,7 +79,7 @@ pub struct TurnContext { pub(crate) compact_prompt: Option, pub(crate) user_instructions: Option, pub(crate) collaboration_mode: CollaborationMode, - pub(crate) multi_agent_version: MultiAgentVersion, + pub(crate) multi_agent_version: Option, pub(crate) personality: Option, pub(crate) approval_policy: Constrained, pub(crate) permission_profile: PermissionProfile, diff --git a/codex-rs/core/src/tasks/mod.rs b/codex-rs/core/src/tasks/mod.rs index 76d5e6478e..a3cd10cf82 100644 --- a/codex-rs/core/src/tasks/mod.rs +++ b/codex-rs/core/src/tasks/mod.rs @@ -73,12 +73,12 @@ pub(crate) enum InterruptedTurnHistoryMarker { impl InterruptedTurnHistoryMarker { pub(crate) fn from_config_and_version( config: &Config, - multi_agent_version: MultiAgentVersion, + multi_agent_version: Option, ) -> Self { if !config.agent_interrupt_message_enabled { return Self::Disabled; } - if multi_agent_version == MultiAgentVersion::V2 { + if multi_agent_version == Some(MultiAgentVersion::V2) { Self::Developer } else { Self::ContextualUser diff --git a/codex-rs/core/src/tasks/review.rs b/codex-rs/core/src/tasks/review.rs index 725fdff4cf..65b11be8b0 100644 --- a/codex-rs/core/src/tasks/review.rs +++ b/codex-rs/core/src/tasks/review.rs @@ -12,7 +12,6 @@ use codex_protocol::protocol::Event; use codex_protocol::protocol::EventMsg; use codex_protocol::protocol::ExitedReviewModeEvent; use codex_protocol::protocol::ItemCompletedEvent; -use codex_protocol::protocol::MultiAgentVersion; use codex_protocol::protocol::ReviewOutputEvent; use codex_protocol::protocol::SubAgentSource; use tokio_util::sync::CancellationToken; @@ -133,7 +132,7 @@ async fn start_review_conversation( SubAgentSource::Review, /*final_output_json_schema*/ None, /*initial_history*/ None, - MultiAgentVersion::None, + /*multi_agent_version*/ None, ) .await) .ok() diff --git a/codex-rs/core/src/thread_manager.rs b/codex-rs/core/src/thread_manager.rs index c01dc2fc98..76da8bbe9b 100644 --- a/codex-rs/core/src/thread_manager.rs +++ b/codex-rs/core/src/thread_manager.rs @@ -194,7 +194,7 @@ pub(crate) struct ResumeThreadWithHistoryOptions { pub(crate) parent_thread_id: Option, pub(crate) inherited_shell_snapshot: Option>, pub(crate) inherited_exec_policy: Option>, - pub(crate) inherited_multi_agent_version: Option, + pub(crate) inherited_multi_agent_version: Option>, } /// Shared, `Arc`-owned state for [`ThreadManager`]. This `Arc` is required to have a single @@ -605,7 +605,7 @@ impl ThreadManager { &self, options: StartThreadOptions, forked_from_thread_id: Option, - inherited_multi_agent_version: Option, + inherited_multi_agent_version: Option>, ) -> CodexResult { let (resumed_session_source, resumed_thread_source) = options .initial_history @@ -1112,7 +1112,7 @@ impl ThreadManagerState { inherited_shell_snapshot: Option>, inherited_exec_policy: Option>, environments: Option>, - inherited_multi_agent_version: Option, + inherited_multi_agent_version: Option>, ) -> CodexResult { let environments = environments.unwrap_or_else(|| { default_thread_environment_selections(self.environment_manager.as_ref(), &config.cwd) @@ -1192,7 +1192,7 @@ impl ThreadManagerState { inherited_shell_snapshot: Option>, inherited_exec_policy: Option>, environments: Option>, - inherited_multi_agent_version: Option, + inherited_multi_agent_version: Option>, ) -> CodexResult { let environments = environments.unwrap_or_else(|| { default_thread_environment_selections(self.environment_manager.as_ref(), &config.cwd) @@ -1224,21 +1224,24 @@ impl ThreadManagerState { config: &Config, initial_history: &InitialHistory, forked_from_thread_id: Option, - inherited_multi_agent_version: Option, - ) -> MultiAgentVersion { + inherited_multi_agent_version: Option>, + ) -> Option { if let Some(multi_agent_version) = initial_history.get_multi_agent_version() { - return multi_agent_version; + return Some(multi_agent_version); } let multi_agent_version = inherited_multi_agent_version .unwrap_or_else(|| config.multi_agent_version_from_features()); + let Some(multi_agent_version) = multi_agent_version else { + return None; + }; let source_thread_id = match initial_history { InitialHistory::Resumed(resumed) => Some(resumed.conversation_id), InitialHistory::Forked(_) => forked_from_thread_id, InitialHistory::New | InitialHistory::Cleared => None, }; let Some(source_thread_id) = source_thread_id else { - return multi_agent_version; + return Some(multi_agent_version); }; match self .thread_store @@ -1249,12 +1252,12 @@ impl ThreadManagerState { }) .await { - Ok(multi_agent_version) => multi_agent_version, + Ok(multi_agent_version) => Some(multi_agent_version), Err(err) => { warn!( "failed to lock multi-agent version for legacy thread {source_thread_id}: {err}" ); - multi_agent_version + Some(multi_agent_version) } } } @@ -1276,7 +1279,7 @@ impl ThreadManagerState { parent_trace: Option, environments: Vec, user_shell_override: Option, - inherited_multi_agent_version: Option, + inherited_multi_agent_version: Option>, ) -> CodexResult { Box::pin(self.spawn_thread_with_source( config, @@ -1319,7 +1322,7 @@ impl ThreadManagerState { parent_trace: Option, environments: Vec, user_shell_override: Option, - inherited_multi_agent_version: Option, + inherited_multi_agent_version: Option>, ) -> CodexResult { let is_resumed_thread = matches!(&initial_history, InitialHistory::Resumed(_)); if let InitialHistory::Resumed(resumed) = &initial_history { diff --git a/codex-rs/core/src/thread_manager_tests.rs b/codex-rs/core/src/thread_manager_tests.rs index 1beff2421b..47ccae1d22 100644 --- a/codex-rs/core/src/thread_manager_tests.rs +++ b/codex-rs/core/src/thread_manager_tests.rs @@ -805,7 +805,7 @@ async fn resume_and_fork_preserve_stored_multi_agent_version() { .expect("start source thread"); assert_eq!( source.thread.multi_agent_version().await, - MultiAgentVersion::V1 + Some(MultiAgentVersion::V1) ); source.thread.ensure_rollout_materialized().await; source @@ -840,7 +840,7 @@ async fn resume_and_fork_preserve_stored_multi_agent_version() { .expect("resume source thread"); assert_eq!( resumed.thread.multi_agent_version().await, - MultiAgentVersion::V1 + Some(MultiAgentVersion::V1) ); resumed .thread @@ -862,7 +862,7 @@ async fn resume_and_fork_preserve_stored_multi_agent_version() { .expect("fork source thread"); assert_eq!( forked.thread.multi_agent_version().await, - MultiAgentVersion::V1 + Some(MultiAgentVersion::V1) ); forked .thread @@ -930,7 +930,7 @@ async fn legacy_resume_continues_when_multi_agent_version_seed_fails() { .expect("legacy resume should continue after seed failure"); assert_eq!( resumed.thread.multi_agent_version().await, - MultiAgentVersion::V2 + Some(MultiAgentVersion::V2) ); assert_eq!( in_memory_store diff --git a/codex-rs/core/src/tools/handlers/multi_agents_tests.rs b/codex-rs/core/src/tools/handlers/multi_agents_tests.rs index a9858bc2e7..9d8250a6cf 100644 --- a/codex-rs/core/src/tools/handlers/multi_agents_tests.rs +++ b/codex-rs/core/src/tools/handlers/multi_agents_tests.rs @@ -388,7 +388,7 @@ async fn multi_agent_v2_spawn_fork_turns_all_rejects_agent_type_override() { .expect("test config should allow feature update"); let turn = TurnContext { config: Arc::new(config), - multi_agent_version: codex_protocol::protocol::MultiAgentVersion::V2, + multi_agent_version: Some(codex_protocol::protocol::MultiAgentVersion::V2), ..turn }; @@ -966,7 +966,7 @@ async fn multi_agent_v2_spawn_partial_fork_turns_allows_agent_type_override() { .expect("test config should allow feature update"); let turn = TurnContext { config: Arc::new(config), - multi_agent_version: codex_protocol::protocol::MultiAgentVersion::V2, + multi_agent_version: Some(codex_protocol::protocol::MultiAgentVersion::V2), ..turn }; diff --git a/codex-rs/core/src/tools/spec_plan.rs b/codex-rs/core/src/tools/spec_plan.rs index d6e038ea78..48f5d7f8b9 100644 --- a/codex-rs/core/src/tools/spec_plan.rs +++ b/codex-rs/core/src/tools/spec_plan.rs @@ -289,17 +289,17 @@ fn namespace_tools_enabled(turn_context: &TurnContext) -> bool { } fn multi_agent_v2_enabled(turn_context: &TurnContext) -> bool { - turn_context.multi_agent_version == MultiAgentVersion::V2 + turn_context.multi_agent_version == Some(MultiAgentVersion::V2) } fn collab_tools_enabled(turn_context: &TurnContext) -> bool { match turn_context.multi_agent_version { - MultiAgentVersion::None => false, - MultiAgentVersion::V1 => !exceeds_thread_spawn_depth_limit( + None => false, + Some(MultiAgentVersion::V1) => !exceeds_thread_spawn_depth_limit( next_thread_spawn_depth(&turn_context.session_source), turn_context.config.agent_max_depth, ), - MultiAgentVersion::V2 => true, + Some(MultiAgentVersion::V2) => true, } } diff --git a/codex-rs/core/src/tools/spec_plan_tests.rs b/codex-rs/core/src/tools/spec_plan_tests.rs index 77a169ded8..b5bc9861e8 100644 --- a/codex-rs/core/src/tools/spec_plan_tests.rs +++ b/codex-rs/core/src/tools/spec_plan_tests.rs @@ -532,7 +532,7 @@ async fn host_context_gates_goal_and_agent_job_tools() { let agent_job_without_multi_agent = probe(|turn| { set_feature(turn, Feature::SpawnCsv, /*enabled*/ true); - turn.multi_agent_version = MultiAgentVersion::None; + turn.multi_agent_version = None; }) .await; agent_job_without_multi_agent.assert_visible_contains(&["spawn_agents_on_csv"]); @@ -878,7 +878,7 @@ async fn multi_agent_feature_selects_one_agent_tool_family() { async fn multi_agent_tool_family_uses_locked_version_instead_of_features() { let v1 = probe(|turn| { set_feature(turn, Feature::MultiAgentV2, /*enabled*/ true); - turn.multi_agent_version = MultiAgentVersion::V1; + turn.multi_agent_version = Some(MultiAgentVersion::V1); }) .await; v1.assert_visible_contains(&[MULTI_AGENT_V1_NAMESPACE]); @@ -886,7 +886,7 @@ async fn multi_agent_tool_family_uses_locked_version_instead_of_features() { let v2 = probe(|turn| { set_feature(turn, Feature::Collab, /*enabled*/ false); - turn.multi_agent_version = MultiAgentVersion::V2; + turn.multi_agent_version = Some(MultiAgentVersion::V2); }) .await; v2.assert_visible_contains(&["spawn_agent", "send_message", "assign_task", "list_agents"]); @@ -894,7 +894,7 @@ async fn multi_agent_tool_family_uses_locked_version_instead_of_features() { let disabled = probe(|turn| { set_feature(turn, Feature::Collab, /*enabled*/ true); - turn.multi_agent_version = MultiAgentVersion::None; + turn.multi_agent_version = None; }) .await; disabled.assert_visible_lacks(&[ diff --git a/codex-rs/core/tests/suite/rollout_list_find.rs b/codex-rs/core/tests/suite/rollout_list_find.rs index cf11334105..690ccf9786 100644 --- a/codex-rs/core/tests/suite/rollout_list_find.rs +++ b/codex-rs/core/tests/suite/rollout_list_find.rs @@ -189,7 +189,7 @@ async fn find_locates_rollout_file_written_by_recorder() -> std::io::Result<()> /*thread_source*/ None, BaseInstructions::default(), Vec::new(), - codex_protocol::protocol::MultiAgentVersion::None, + /*multi_agent_version*/ None, ), ) .await?; diff --git a/codex-rs/protocol/src/protocol.rs b/codex-rs/protocol/src/protocol.rs index 4d3f7b8bc5..329c1406e0 100644 --- a/codex-rs/protocol/src/protocol.rs +++ b/codex-rs/protocol/src/protocol.rs @@ -2749,11 +2749,9 @@ fn multi_agent_version_from_items( }) } -#[derive(Serialize, Deserialize, Clone, Copy, Debug, Default, PartialEq, Eq, JsonSchema, TS)] +#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq, JsonSchema, TS)] #[serde(rename_all = "snake_case")] pub enum MultiAgentVersion { - #[default] - None, V1, V2, } @@ -4047,7 +4045,7 @@ mod tests { } #[test] - fn session_meta_multi_agent_version_distinguishes_missing_and_locked_values() { + fn session_meta_multi_agent_version_treats_missing_and_null_as_unresolved() { let mut meta = SessionMeta::default(); let serialized = serde_json::to_value(&meta).expect("serialize legacy session metadata"); assert_eq!(serialized.get("multi_agent_version"), None); @@ -4055,11 +4053,18 @@ mod tests { serde_json::from_value(serialized).expect("deserialize legacy session metadata"); assert_eq!(deserialized.multi_agent_version, None); - for version in [ - MultiAgentVersion::None, - MultiAgentVersion::V1, - MultiAgentVersion::V2, - ] { + let deserialized: SessionMeta = serde_json::from_value(serde_json::json!({ + "id": ThreadId::default(), + "timestamp": "", + "cwd": "", + "originator": "", + "cli_version": "", + "multi_agent_version": null + })) + .expect("deserialize null session metadata"); + assert_eq!(deserialized.multi_agent_version, None); + + for version in [MultiAgentVersion::V1, MultiAgentVersion::V2] { meta.multi_agent_version = Some(version); let serialized = serde_json::to_value(&meta).expect("serialize locked session metadata"); diff --git a/codex-rs/rollout/src/recorder.rs b/codex-rs/rollout/src/recorder.rs index 57010ff979..7798cb6172 100644 --- a/codex-rs/rollout/src/recorder.rs +++ b/codex-rs/rollout/src/recorder.rs @@ -88,7 +88,7 @@ pub enum RolloutRecorderParams { thread_source: Option, base_instructions: BaseInstructions, dynamic_tools: Vec, - multi_agent_version: MultiAgentVersion, + multi_agent_version: Option, }, Resume { path: PathBuf, @@ -165,7 +165,7 @@ impl RolloutRecorderParams { thread_source: Option, base_instructions: BaseInstructions, dynamic_tools: Vec, - multi_agent_version: MultiAgentVersion, + multi_agent_version: Option, ) -> Self { Self::Create { conversation_id, @@ -701,7 +701,7 @@ impl RolloutRecorder { Some(dynamic_tools) }, memory_mode: (!config.generate_memories()).then_some("disabled".to_string()), - multi_agent_version: Some(multi_agent_version), + multi_agent_version, }; (None, Some(log_file_info), path, Some(session_meta)) diff --git a/codex-rs/rollout/src/recorder_tests.rs b/codex-rs/rollout/src/recorder_tests.rs index 8771c5f5f7..6a5f6dfe33 100644 --- a/codex-rs/rollout/src/recorder_tests.rs +++ b/codex-rs/rollout/src/recorder_tests.rs @@ -376,7 +376,7 @@ async fn recorder_materializes_on_flush_with_pending_items() -> std::io::Result< /*thread_source*/ None, BaseInstructions::default(), Vec::new(), - codex_protocol::protocol::MultiAgentVersion::None, + /*multi_agent_version*/ None, ), ) .await?; @@ -458,7 +458,7 @@ async fn persist_reports_filesystem_error_and_retries_buffered_items() -> std::i /*thread_source*/ None, BaseInstructions::default(), Vec::new(), - codex_protocol::protocol::MultiAgentVersion::None, + /*multi_agent_version*/ None, ), ) .await?; diff --git a/codex-rs/thread-store/src/in_memory.rs b/codex-rs/thread-store/src/in_memory.rs index 008fee6cbe..4e7b76bbc6 100644 --- a/codex-rs/thread-store/src/in_memory.rs +++ b/codex-rs/thread-store/src/in_memory.rs @@ -66,7 +66,7 @@ mod tests { thread_source: None, base_instructions: BaseInstructions::default(), dynamic_tools: Vec::new(), - multi_agent_version: MultiAgentVersion::V2, + multi_agent_version: Some(MultiAgentVersion::V2), metadata: ThreadPersistenceMetadata { cwd: None, model_provider: "test-provider".to_string(), @@ -283,7 +283,7 @@ impl ThreadStore for InMemoryThreadStore { dynamic_tools: (!params.dynamic_tools.is_empty()).then(|| params.dynamic_tools.clone()), memory_mode: matches!(params.metadata.memory_mode, ThreadMemoryMode::Disabled) .then_some("disabled".to_string()), - multi_agent_version: Some(params.multi_agent_version), + multi_agent_version: params.multi_agent_version, ..SessionMeta::default() }; state diff --git a/codex-rs/thread-store/src/local/mod.rs b/codex-rs/thread-store/src/local/mod.rs index 445641931e..4e3d37db64 100644 --- a/codex-rs/thread-store/src/local/mod.rs +++ b/codex-rs/thread-store/src/local/mod.rs @@ -1085,7 +1085,7 @@ mod tests { thread_source: None, base_instructions: BaseInstructions::default(), dynamic_tools: Vec::new(), - multi_agent_version: codex_protocol::protocol::MultiAgentVersion::None, + multi_agent_version: None, metadata: thread_metadata(), event_persistence_mode: ThreadEventPersistenceMode::Limited, } diff --git a/codex-rs/thread-store/src/types.rs b/codex-rs/thread-store/src/types.rs index 8b51cb155b..8026c798ac 100644 --- a/codex-rs/thread-store/src/types.rs +++ b/codex-rs/thread-store/src/types.rs @@ -95,7 +95,7 @@ pub struct CreateThreadParams { /// Dynamic tools available to the thread at startup. pub dynamic_tools: Vec, /// Multi-agent runtime selected when the thread was created. - pub multi_agent_version: MultiAgentVersion, + pub multi_agent_version: Option, /// Metadata captured for the newly created thread. pub metadata: ThreadPersistenceMetadata, /// Whether persistence should include the extended event surface.