codex: simplify multi-agent version lock

This commit is contained in:
Ahmed Ibrahim
2026-06-01 13:13:16 -07:00
parent 745307ad08
commit 514afd0441
32 changed files with 107 additions and 107 deletions
@@ -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(),
@@ -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(),
@@ -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(),
+10 -10
View File
@@ -57,7 +57,7 @@ pub(crate) struct SpawnAgentOptions {
pub(crate) fork_mode: Option<SpawnAgentForkMode>,
pub(crate) parent_thread_id: Option<ThreadId>,
pub(crate) environments: Option<Vec<TurnEnvironmentSelection>>,
pub(crate) multi_agent_version: Option<MultiAgentVersion>,
pub(crate) multi_agent_version: Option<Option<MultiAgentVersion>>,
}
#[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<Arc<ShellSnapshot>>,
inherited_exec_policy: Option<Arc<crate::exec_policy::ExecPolicyManager>>,
inherited_multi_agent_version: Option<MultiAgentVersion>,
inherited_multi_agent_version: Option<Option<MultiAgentVersion>>,
) -> CodexResult<crate::thread_manager::NewThread> {
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<String> =
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<ThreadManagerState>,
session_source: Option<&SessionSource>,
requested_multi_agent_version: Option<MultiAgentVersion>,
) -> Option<MultiAgentVersion> {
requested_multi_agent_version: Option<Option<MultiAgentVersion>>,
) -> Option<Option<MultiAgentVersion>> {
if requested_multi_agent_version.is_some() {
return requested_multi_agent_version;
}
+4 -1
View File
@@ -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]
+2 -2
View File
@@ -72,7 +72,7 @@ pub(crate) async fn run_codex_thread_interactive(
cancel_token: CancellationToken,
subagent_source: SubAgentSource,
initial_history: Option<InitialHistory>,
multi_agent_version: MultiAgentVersion,
multi_agent_version: Option<MultiAgentVersion>,
) -> Result<Codex, CodexErr> {
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<Value>,
initial_history: Option<InitialHistory>,
multi_agent_version: MultiAgentVersion,
multi_agent_version: Option<MultiAgentVersion>,
) -> Result<Codex, CodexErr> {
// Use a child token so we can stop the delegate after completion without
// requiring the caller to cancel the parent token.
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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<MultiAgentVersion> {
self.codex.session.multi_agent_version().await
}
+4 -7
View File
@@ -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);
+7 -7
View File
@@ -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<MultiAgentVersion> {
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<MultiAgentVersion>,
) -> 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),
};
+1 -2
View File
@@ -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?;
+8 -11
View File
@@ -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)
);
}
}
+3 -3
View File
@@ -421,7 +421,7 @@ pub(crate) struct CodexSpawnArgs {
pub(crate) analytics_events_client: Option<AnalyticsEventsClient>,
pub(crate) thread_store: Arc<dyn ThreadStore>,
pub(crate) attestation_provider: Option<Arc<dyn AttestationProvider>>,
pub(crate) multi_agent_version: MultiAgentVersion,
pub(crate) multi_agent_version: Option<MultiAgentVersion>,
}
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<MultiAgentVersion> {
let state = self.state.lock().await;
state.session_configuration.multi_agent_version
}
+1 -1
View File
@@ -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;
}
+1 -1
View File
@@ -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<MultiAgentVersion>,
pub(super) model_reasoning_summary: Option<ReasoningSummaryConfig>,
pub(super) service_tier: Option<String>,
+2 -2
View File
@@ -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(),
@@ -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);
}
+1 -1
View File
@@ -79,7 +79,7 @@ pub struct TurnContext {
pub(crate) compact_prompt: Option<String>,
pub(crate) user_instructions: Option<String>,
pub(crate) collaboration_mode: CollaborationMode,
pub(crate) multi_agent_version: MultiAgentVersion,
pub(crate) multi_agent_version: Option<MultiAgentVersion>,
pub(crate) personality: Option<Personality>,
pub(crate) approval_policy: Constrained<AskForApproval>,
pub(crate) permission_profile: PermissionProfile,
+2 -2
View File
@@ -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<MultiAgentVersion>,
) -> 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
+1 -2
View File
@@ -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()
+15 -12
View File
@@ -194,7 +194,7 @@ pub(crate) struct ResumeThreadWithHistoryOptions {
pub(crate) parent_thread_id: Option<ThreadId>,
pub(crate) inherited_shell_snapshot: Option<Arc<ShellSnapshot>>,
pub(crate) inherited_exec_policy: Option<Arc<crate::exec_policy::ExecPolicyManager>>,
pub(crate) inherited_multi_agent_version: Option<MultiAgentVersion>,
pub(crate) inherited_multi_agent_version: Option<Option<MultiAgentVersion>>,
}
/// 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<ThreadId>,
inherited_multi_agent_version: Option<MultiAgentVersion>,
inherited_multi_agent_version: Option<Option<MultiAgentVersion>>,
) -> CodexResult<NewThread> {
let (resumed_session_source, resumed_thread_source) = options
.initial_history
@@ -1112,7 +1112,7 @@ impl ThreadManagerState {
inherited_shell_snapshot: Option<Arc<ShellSnapshot>>,
inherited_exec_policy: Option<Arc<crate::exec_policy::ExecPolicyManager>>,
environments: Option<Vec<TurnEnvironmentSelection>>,
inherited_multi_agent_version: Option<MultiAgentVersion>,
inherited_multi_agent_version: Option<Option<MultiAgentVersion>>,
) -> CodexResult<NewThread> {
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<Arc<ShellSnapshot>>,
inherited_exec_policy: Option<Arc<crate::exec_policy::ExecPolicyManager>>,
environments: Option<Vec<TurnEnvironmentSelection>>,
inherited_multi_agent_version: Option<MultiAgentVersion>,
inherited_multi_agent_version: Option<Option<MultiAgentVersion>>,
) -> CodexResult<NewThread> {
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<ThreadId>,
inherited_multi_agent_version: Option<MultiAgentVersion>,
) -> MultiAgentVersion {
inherited_multi_agent_version: Option<Option<MultiAgentVersion>>,
) -> Option<MultiAgentVersion> {
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<W3cTraceContext>,
environments: Vec<TurnEnvironmentSelection>,
user_shell_override: Option<crate::shell::Shell>,
inherited_multi_agent_version: Option<MultiAgentVersion>,
inherited_multi_agent_version: Option<Option<MultiAgentVersion>>,
) -> CodexResult<NewThread> {
Box::pin(self.spawn_thread_with_source(
config,
@@ -1319,7 +1322,7 @@ impl ThreadManagerState {
parent_trace: Option<W3cTraceContext>,
environments: Vec<TurnEnvironmentSelection>,
user_shell_override: Option<crate::shell::Shell>,
inherited_multi_agent_version: Option<MultiAgentVersion>,
inherited_multi_agent_version: Option<Option<MultiAgentVersion>>,
) -> CodexResult<NewThread> {
let is_resumed_thread = matches!(&initial_history, InitialHistory::Resumed(_));
if let InitialHistory::Resumed(resumed) = &initial_history {
+4 -4
View File
@@ -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
@@ -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
};
+4 -4
View File
@@ -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,
}
}
+4 -4
View File
@@ -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(&[
@@ -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?;
+14 -9
View File
@@ -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");
+3 -3
View File
@@ -88,7 +88,7 @@ pub enum RolloutRecorderParams {
thread_source: Option<ThreadSource>,
base_instructions: BaseInstructions,
dynamic_tools: Vec<DynamicToolSpec>,
multi_agent_version: MultiAgentVersion,
multi_agent_version: Option<MultiAgentVersion>,
},
Resume {
path: PathBuf,
@@ -165,7 +165,7 @@ impl RolloutRecorderParams {
thread_source: Option<ThreadSource>,
base_instructions: BaseInstructions,
dynamic_tools: Vec<DynamicToolSpec>,
multi_agent_version: MultiAgentVersion,
multi_agent_version: Option<MultiAgentVersion>,
) -> 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))
+2 -2
View File
@@ -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?;
+2 -2
View File
@@ -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
+1 -1
View File
@@ -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,
}
+1 -1
View File
@@ -95,7 +95,7 @@ pub struct CreateThreadParams {
/// Dynamic tools available to the thread at startup.
pub dynamic_tools: Vec<DynamicToolSpec>,
/// Multi-agent runtime selected when the thread was created.
pub multi_agent_version: MultiAgentVersion,
pub multi_agent_version: Option<MultiAgentVersion>,
/// Metadata captured for the newly created thread.
pub metadata: ThreadPersistenceMetadata,
/// Whether persistence should include the extended event surface.