Persist resolved multi-agent version per thread

This commit is contained in:
Ahmed Ibrahim
2026-05-29 13:12:44 -07:00
parent fb3905f59d
commit 91d87fcd09
47 changed files with 467 additions and 109 deletions
+9 -13
View File
@@ -511,14 +511,12 @@ impl AgentControl {
config: crate::config::Config,
thread_id: ThreadId,
session_source: SessionSource,
multi_agent_version: Option<MultiAgentVersion>,
) -> CodexResult<ThreadId> {
let root_depth = thread_spawn_depth(&session_source).unwrap_or(0);
let resumed_thread_id = Box::pin(self.resume_single_agent_from_rollout(
config.clone(),
thread_id,
session_source,
multi_agent_version,
))
.await?;
let state = self.upgrade()?;
@@ -571,7 +569,6 @@ impl AgentControl {
config.clone(),
child_thread_id,
child_session_source,
multi_agent_version,
))
.await
{
@@ -596,8 +593,16 @@ impl AgentControl {
mut config: crate::config::Config,
thread_id: ThreadId,
session_source: SessionSource,
multi_agent_version: Option<MultiAgentVersion>,
) -> CodexResult<ThreadId> {
let state = self.upgrade()?;
let stored_thread = state
.read_stored_thread(ReadThreadParams {
thread_id,
include_archived: true,
include_history: true,
})
.await?;
let multi_agent_version = stored_thread.multi_agent_version;
if let SessionSource::SubAgent(SubAgentSource::ThreadSpawn { depth, .. }) = &session_source
&& *depth >= config.agent_max_depth
&& multi_agent_version != Some(MultiAgentVersion::V2)
@@ -605,7 +610,6 @@ impl AgentControl {
let _ = config.features.disable(Feature::SpawnCsv);
let _ = config.features.disable(Feature::Collab);
}
let state = self.upgrade()?;
let state_db_ctx = state.state_db();
let mut reservation = self.state.reserve_spawn_slot(config.agent_max_threads)?;
let (session_source, agent_metadata) = match session_source {
@@ -644,13 +648,6 @@ impl AgentControl {
let inherited_exec_policy = self
.inherited_exec_policy_for_source(&state, Some(&session_source), &config)
.await;
let stored_thread = state
.read_stored_thread(ReadThreadParams {
thread_id,
include_archived: true,
include_history: true,
})
.await?;
let history = stored_thread
.history
.ok_or_else(|| CodexErr::ThreadNotFound(thread_id))?
@@ -666,7 +663,6 @@ impl AgentControl {
}),
agent_control: self.clone(),
session_source,
inherited_multi_agent_version: multi_agent_version,
inherited_shell_snapshot,
inherited_exec_policy,
})
+78 -30
View File
@@ -341,12 +341,7 @@ async fn resume_agent_errors_when_manager_dropped() {
let control = AgentControl::default();
let (_home, config) = test_config().await;
let err = control
.resume_agent_from_rollout(
config,
ThreadId::new(),
SessionSource::Exec,
/*multi_agent_version*/ None,
)
.resume_agent_from_rollout(config, ThreadId::new(), SessionSource::Exec)
.await
.expect_err("resume_agent should fail without a manager");
assert_eq!(
@@ -1235,6 +1230,7 @@ async fn spawn_agent_fork_last_n_turns_strips_parent_usage_hints() {
SpawnAgentOptions {
fork_parent_spawn_call_id: Some(parent_spawn_call_id),
fork_mode: Some(SpawnAgentForkMode::LastNTurns(2)),
multi_agent_version: Some(MultiAgentVersion::V2),
..Default::default()
},
)
@@ -1447,12 +1443,7 @@ async fn resume_agent_respects_max_threads_limit() {
.expect("spawn_agent should succeed for active slot");
let err = control
.resume_agent_from_rollout(
config,
resumable_id,
SessionSource::Exec,
/*multi_agent_version*/ None,
)
.resume_agent_from_rollout(config, resumable_id, SessionSource::Exec)
.await
.expect_err("resume should respect max threads");
let CodexErr::AgentLimitReached {
@@ -1486,12 +1477,7 @@ async fn resume_agent_releases_slot_after_resume_failure() {
let control = manager.agent_control();
let _ = control
.resume_agent_from_rollout(
config.clone(),
ThreadId::new(),
SessionSource::Exec,
/*multi_agent_version*/ None,
)
.resume_agent_from_rollout(config.clone(), ThreadId::new(), SessionSource::Exec)
.await
.expect_err("resume should fail for missing rollout path");
@@ -1888,7 +1874,6 @@ async fn resume_thread_subagent_restores_stored_nickname_and_role() {
agent_nickname: None,
agent_role: None,
}),
/*multi_agent_version*/ None,
)
.await
.expect("resume should succeed");
@@ -1962,12 +1947,7 @@ async fn resume_agent_from_rollout_reads_archived_rollout_path() {
let resumed_thread_id = harness
.control
.resume_agent_from_rollout(
harness.config.clone(),
child_thread_id,
SessionSource::Exec,
/*multi_agent_version*/ None,
)
.resume_agent_from_rollout(harness.config.clone(), child_thread_id, SessionSource::Exec)
.await
.expect("resume should find archived rollout");
assert_eq!(resumed_thread_id, child_thread_id);
@@ -2410,7 +2390,6 @@ async fn resume_agent_from_rollout_does_not_reopen_closed_descendants() {
harness.config.clone(),
parent_thread_id,
SessionSource::Exec,
/*multi_agent_version*/ None,
)
.await
.expect("single-thread resume should succeed");
@@ -2507,7 +2486,6 @@ async fn resume_closed_child_reopens_open_descendants() {
agent_nickname: None,
agent_role: None,
}),
/*multi_agent_version*/ None,
)
.await
.expect("child resume should succeed");
@@ -2533,6 +2511,79 @@ async fn resume_closed_child_reopens_open_descendants() {
.expect("parent shutdown should succeed");
}
#[tokio::test]
async fn resume_agent_from_rollout_restores_persisted_multi_agent_version() {
let harness = AgentControlHarness::new().await;
let (parent_thread_id, _parent_thread) = harness.start_thread().await;
let child_thread_id = harness
.control
.spawn_agent_with_metadata(
harness.config.clone(),
text_input("hello"),
Some(SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
parent_thread_id,
depth: 1,
agent_path: None,
agent_nickname: None,
agent_role: None,
})),
SpawnAgentOptions {
multi_agent_version: Some(MultiAgentVersion::V2),
..Default::default()
},
)
.await
.expect("child spawn should succeed")
.thread_id;
let child_thread = harness
.manager
.get_thread(child_thread_id)
.await
.expect("child thread should exist");
persist_thread_for_tree_resume(&child_thread, "persist selector").await;
assert_eq!(
child_thread.codex.session.multi_agent_version,
Some(MultiAgentVersion::V2)
);
let _ = harness
.control
.shutdown_live_agent(child_thread_id)
.await
.expect("child shutdown should submit");
let resumed_thread_id = harness
.control
.resume_agent_from_rollout(
harness.config.clone(),
child_thread_id,
SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
parent_thread_id,
depth: 1,
agent_path: None,
agent_nickname: None,
agent_role: None,
}),
)
.await
.expect("child resume should succeed");
let resumed_thread = harness
.manager
.get_thread(resumed_thread_id)
.await
.expect("resumed child thread should exist");
assert_eq!(
resumed_thread.codex.session.multi_agent_version,
Some(MultiAgentVersion::V2)
);
let _ = harness
.control
.shutdown_agent_tree(parent_thread_id)
.await
.expect("agent tree shutdown should succeed");
}
#[tokio::test]
async fn resume_agent_from_rollout_reopens_open_descendants_after_manager_shutdown() {
let harness = AgentControlHarness::new().await;
@@ -2600,7 +2651,6 @@ async fn resume_agent_from_rollout_reopens_open_descendants_after_manager_shutdo
harness.config.clone(),
parent_thread_id,
SessionSource::Exec,
/*multi_agent_version*/ None,
)
.await
.expect("tree resume should succeed");
@@ -2714,7 +2764,6 @@ async fn resume_agent_from_rollout_uses_edge_data_when_descendant_metadata_sourc
harness.config.clone(),
parent_thread_id,
SessionSource::Exec,
/*multi_agent_version*/ None,
)
.await
.expect("tree resume should succeed");
@@ -2830,7 +2879,6 @@ async fn resume_agent_from_rollout_skips_descendants_when_parent_resume_fails()
harness.config.clone(),
parent_thread_id,
SessionSource::Exec,
/*multi_agent_version*/ None,
)
.await
.expect("root resume should succeed");
+1 -1
View File
@@ -77,7 +77,7 @@ pub(crate) async fn run_codex_thread_interactive(
let CodexSpawnOk { codex, .. } = Box::pin(Codex::spawn(CodexSpawnArgs {
config,
installation_id: parent_session.installation_id.clone(),
inherited_multi_agent_version: None,
parent_multi_agent_version: parent_ctx.multi_agent_version,
auth_manager,
models_manager,
environment_manager: Arc::clone(&parent_session.services.environment_manager),
@@ -55,6 +55,7 @@ async fn write_rollout_with_user_event(dir: &Path, thread_id: ThreadId) -> io::R
agent_nickname: None,
agent_role: None,
model_provider: None,
multi_agent_version: None,
base_instructions: None,
dynamic_tools: None,
memory_mode: None,
@@ -37,6 +37,7 @@ fn stored_thread(cwd: &str, title: &str, first_user_message: &str) -> StoredThre
model_provider: "test-provider".to_string(),
model: Some("gpt-5.2".to_string()),
reasoning_effort: None,
multi_agent_version: None,
created_at: Utc
.timestamp_opt(1_709_251_100, 0)
.single()
+22 -11
View File
@@ -226,6 +226,7 @@ use self::turn::collect_explicit_app_ids_from_skill_items;
use self::turn::realtime_text_for_event;
use self::turn_context::TurnContext;
use self::turn_context::TurnSkillsContext;
use self::turn_context::resolve_multi_agent_version;
#[cfg(test)]
mod rollout_reconstruction_tests;
@@ -393,7 +394,7 @@ pub struct CodexSpawnOk {
pub(crate) struct CodexSpawnArgs {
pub(crate) config: Config,
pub(crate) installation_id: String,
pub(crate) inherited_multi_agent_version: Option<MultiAgentVersion>,
pub(crate) parent_multi_agent_version: Option<MultiAgentVersion>,
pub(crate) auth_manager: Arc<AuthManager>,
pub(crate) models_manager: SharedModelsManager,
pub(crate) environment_manager: Arc<EnvironmentManager>,
@@ -459,7 +460,7 @@ impl Codex {
let CodexSpawnArgs {
mut config,
installation_id,
inherited_multi_agent_version,
parent_multi_agent_version,
auth_manager,
models_manager,
environment_manager,
@@ -488,14 +489,6 @@ impl Codex {
let (tx_sub, rx_sub) = async_channel::bounded(SUBMISSION_CHANNEL_CAPACITY);
let (tx_event, rx_event) = async_channel::unbounded();
if let SessionSource::SubAgent(SubAgentSource::ThreadSpawn { depth, .. }) = session_source
&& depth >= config.agent_max_depth
&& inherited_multi_agent_version != Some(MultiAgentVersion::V2)
{
let _ = config.features.disable(Feature::SpawnCsv);
let _ = config.features.disable(Feature::Collab);
}
let primary_environment = environment_selections.primary_environment();
let mut user_instruction_warnings = Vec::new();
let user_instructions = AgentsMdManager::new(&config)
@@ -546,6 +539,24 @@ impl Codex {
let model_info = models_manager
.get_model_info(model.as_str(), &config.to_models_manager_config())
.await;
let multi_agent_version = match &conversation_history {
InitialHistory::Resumed(_) => conversation_history.get_multi_agent_version(),
InitialHistory::New | InitialHistory::Cleared | InitialHistory::Forked(_) => {
resolve_multi_agent_version(
&model_info,
&config,
&session_source,
parent_multi_agent_version,
)
}
};
if let SessionSource::SubAgent(SubAgentSource::ThreadSpawn { depth, .. }) = session_source
&& depth >= config.agent_max_depth
&& multi_agent_version != Some(MultiAgentVersion::V2)
{
let _ = config.features.disable(Feature::SpawnCsv);
let _ = config.features.disable(Feature::Collab);
}
let base_instructions = config
.base_instructions
.clone()
@@ -613,7 +624,7 @@ impl Codex {
session_configuration,
config.clone(),
installation_id,
inherited_multi_agent_version,
multi_agent_version,
auth_manager.clone(),
models_manager.clone(),
exec_policy,
+6 -4
View File
@@ -20,8 +20,8 @@ use tokio::sync::Semaphore;
pub(crate) struct Session {
pub(crate) conversation_id: ThreadId,
pub(crate) installation_id: String,
/// Parent turn's resolved selector for child sessions.
pub(crate) inherited_multi_agent_version: Option<MultiAgentVersion>,
/// Thread-scoped multi-agent runtime selector, resolved when the thread starts.
pub(crate) multi_agent_version: Option<MultiAgentVersion>,
pub(super) tx_event: Sender<Event>,
pub(super) agent_status: watch::Sender<AgentStatus>,
pub(super) out_of_band_elicitation_paused: watch::Sender<bool>,
@@ -487,7 +487,7 @@ impl Session {
mut session_configuration: SessionConfiguration,
config: Arc<Config>,
installation_id: String,
inherited_multi_agent_version: Option<MultiAgentVersion>,
multi_agent_version: Option<MultiAgentVersion>,
auth_manager: Arc<AuthManager>,
models_manager: SharedModelsManager,
exec_policy: Arc<ExecPolicyManager>,
@@ -563,6 +563,7 @@ impl Session {
metadata: ThreadPersistenceMetadata {
cwd: Some(config.cwd.to_path_buf()),
model_provider: config.model_provider_id.clone(),
multi_agent_version,
memory_mode: if config.memories.generate_memories {
ThreadMemoryMode::Enabled
} else {
@@ -585,6 +586,7 @@ impl Session {
metadata: ThreadPersistenceMetadata {
cwd: Some(config.cwd.to_path_buf()),
model_provider: config.model_provider_id.clone(),
multi_agent_version,
memory_mode: if config.memories.generate_memories {
ThreadMemoryMode::Enabled
} else {
@@ -1059,7 +1061,7 @@ impl Session {
let sess = Arc::new(Session {
conversation_id: thread_id,
installation_id,
inherited_multi_agent_version,
multi_agent_version,
tx_event: tx_event.clone(),
agent_status,
out_of_band_elicitation_paused,
+27 -7
View File
@@ -3458,6 +3458,7 @@ async fn attach_thread_persistence(session: &mut Session) -> PathBuf {
metadata: ThreadPersistenceMetadata {
cwd: Some(config.cwd.to_path_buf()),
model_provider: config.model_provider_id.clone(),
multi_agent_version: None,
memory_mode: if config.memories.generate_memories {
ThreadMemoryMode::Enabled
} else {
@@ -4494,7 +4495,7 @@ async fn session_new_fails_when_zsh_fork_enabled_without_packaged_zsh() {
session_configuration,
Arc::clone(&config),
"11111111-1111-4111-8111-111111111111".to_string(),
/*inherited_multi_agent_version*/ None,
/*multi_agent_version*/ None,
auth_manager,
models_manager,
Arc::new(ExecPolicyManager::default()),
@@ -4724,13 +4725,13 @@ pub(crate) async fn make_session_and_context() -> (Session, TurnContext) {
"turn_id".to_string(),
skills_outcome,
/*goal_tools_supported*/ true,
/*inherited_multi_agent_version*/ None,
/*multi_agent_version*/ None,
);
let session = Session {
conversation_id: thread_id,
installation_id: "11111111-1111-4111-8111-111111111111".to_string(),
inherited_multi_agent_version: None,
multi_agent_version: None,
tx_event,
agent_status: agent_status_tx,
out_of_band_elicitation_paused: watch::channel(false).0,
@@ -4843,7 +4844,7 @@ async fn make_session_with_config_and_rx(
session_configuration,
Arc::clone(&config),
"11111111-1111-4111-8111-111111111111".to_string(),
/*inherited_multi_agent_version*/ None,
/*multi_agent_version*/ None,
auth_manager,
models_manager,
Arc::new(ExecPolicyManager::default()),
@@ -4948,7 +4949,7 @@ async fn make_session_with_history_source_and_agent_control_and_rx(
session_configuration,
Arc::clone(&config),
"11111111-1111-4111-8111-111111111111".to_string(),
/*inherited_multi_agent_version*/ None,
/*multi_agent_version*/ None,
auth_manager,
models_manager,
Arc::new(ExecPolicyManager::default()),
@@ -5958,6 +5959,7 @@ async fn shutdown_complete_does_not_append_to_thread_store_after_shutdown() {
metadata: ThreadPersistenceMetadata {
cwd: Some(config.cwd.to_path_buf()),
model_provider: config.model_provider_id.clone(),
multi_agent_version: None,
memory_mode: if config.memories.generate_memories {
ThreadMemoryMode::Enabled
} else {
@@ -6571,13 +6573,13 @@ where
"turn_id".to_string(),
skills_outcome,
/*goal_tools_supported*/ true,
/*inherited_multi_agent_version*/ None,
/*multi_agent_version*/ None,
));
let session = Arc::new(Session {
conversation_id: thread_id,
installation_id: "11111111-1111-4111-8111-111111111111".to_string(),
inherited_multi_agent_version: None,
multi_agent_version: None,
tx_event,
agent_status: agent_status_tx,
out_of_band_elicitation_paused: watch::channel(false).0,
@@ -7255,6 +7257,24 @@ async fn spawned_child_multi_agent_version_follows_parent_system() {
);
}
#[tokio::test]
async fn model_switch_preserves_thread_multi_agent_version() {
let (session, mut turn_context) = make_session_and_context().await;
turn_context.multi_agent_version = Some(MultiAgentVersion::V1);
let switched_context = turn_context
.with_model(
turn_context.model_info.slug.clone(),
&session.services.models_manager,
)
.await;
assert_eq!(
switched_context.multi_agent_version,
Some(MultiAgentVersion::V1)
);
}
#[tokio::test]
async fn build_initial_context_omits_default_image_save_location_with_image_history() {
let (session, turn_context) = make_session_and_context().await;
@@ -681,7 +681,7 @@ async fn guardian_subagent_does_not_inherit_parent_exec_policy_rules() {
let CodexSpawnOk { codex, .. } = Codex::spawn(CodexSpawnArgs {
config,
installation_id: "11111111-1111-4111-8111-111111111111".to_string(),
inherited_multi_agent_version: None,
parent_multi_agent_version: None,
auth_manager,
models_manager,
environment_manager: Arc::new(EnvironmentManager::default_for_tests()),
+5 -20
View File
@@ -110,7 +110,7 @@ pub(crate) fn resolve_multi_agent_version(
model_info: &ModelInfo,
config: &Config,
session_source: &SessionSource,
inherited_multi_agent_version: Option<MultiAgentVersion>,
parent_multi_agent_version: Option<MultiAgentVersion>,
) -> Option<MultiAgentVersion> {
if is_guardian_reviewer_source(session_source)
|| matches!(
@@ -120,7 +120,7 @@ pub(crate) fn resolve_multi_agent_version(
{
return None;
}
inherited_multi_agent_version.or_else(|| {
parent_multi_agent_version.or_else(|| {
model_info.multi_agent_version.or_else(|| {
if config.features.enabled(Feature::MultiAgentV2) {
Some(MultiAgentVersion::V2)
@@ -217,16 +217,7 @@ impl TurnContext {
ToolMode::Direct
}
});
let multi_agent_version = if self.session_source.is_non_root_agent() {
self.multi_agent_version
} else {
resolve_multi_agent_version(
&model_info,
&config,
&self.session_source,
/*inherited_multi_agent_version*/ None,
)
};
let multi_agent_version = self.multi_agent_version;
let truncation_policy = model_info.truncation_policy.into();
let supported_reasoning_levels = model_info
.supported_reasoning_levels
@@ -508,7 +499,7 @@ impl Session {
sub_id: String,
skills_outcome: Arc<SkillLoadOutcome>,
goal_tools_supported: bool,
inherited_multi_agent_version: Option<MultiAgentVersion>,
multi_agent_version: Option<MultiAgentVersion>,
) -> TurnContext {
let reasoning_effort = session_configuration.collaboration_mode.reasoning_effort();
let reasoning_summary = session_configuration
@@ -542,12 +533,6 @@ impl Session {
ToolMode::Direct
}
});
let multi_agent_version = resolve_multi_agent_version(
&model_info,
&per_turn_config,
&session_source,
inherited_multi_agent_version,
);
per_turn_config.service_tier = get_service_tier(
per_turn_config.service_tier,
per_turn_config.features.enabled(Feature::FastMode),
@@ -797,7 +782,7 @@ impl Session {
sub_id,
skills_outcome,
goal_tools_supported,
self.inherited_multi_agent_version,
self.multi_agent_version,
);
turn_context.realtime_active = self.conversation.running_state().await.is_some();
+5 -3
View File
@@ -50,7 +50,6 @@ use codex_protocol::protocol::TurnAbortedEvent;
use codex_protocol::protocol::TurnCompleteEvent;
use codex_protocol::protocol::WarningEvent;
use codex_features::Feature;
use codex_protocol::models::ContentItem;
use codex_protocol::openai_models::MultiAgentVersion;
pub(crate) use compact::CompactTask;
@@ -71,11 +70,14 @@ pub(crate) enum InterruptedTurnHistoryMarker {
}
impl InterruptedTurnHistoryMarker {
pub(crate) fn from_config(config: &Config) -> Self {
pub(crate) fn from_config(
config: &Config,
multi_agent_version: Option<MultiAgentVersion>,
) -> Self {
if !config.agent_interrupt_message_enabled {
return Self::Disabled;
}
if config.features.enabled(Feature::MultiAgentV2) {
if multi_agent_version == Some(MultiAgentVersion::V2) {
Self::Developer
} else {
Self::ContextualUser
+18 -14
View File
@@ -188,7 +188,6 @@ pub(crate) struct ResumeThreadWithHistoryOptions {
pub(crate) initial_history: InitialHistory,
pub(crate) agent_control: AgentControl,
pub(crate) session_source: SessionSource,
pub(crate) inherited_multi_agent_version: Option<MultiAgentVersion>,
pub(crate) inherited_shell_snapshot: Option<Arc<ShellSnapshot>>,
pub(crate) inherited_exec_policy: Option<Arc<crate::exec_policy::ExecPolicyManager>>,
}
@@ -597,13 +596,14 @@ impl ThreadManager {
let thread_source = options
.thread_source
.or_else(|| options.initial_history.get_resumed_thread_source());
let parent_multi_agent_version = options.initial_history.get_multi_agent_version();
Box::pin(self.state.spawn_thread_with_source(
options.config,
options.initial_history,
Arc::clone(&self.state.auth_manager),
self.agent_control(),
session_source,
/*inherited_multi_agent_version*/ None,
parent_multi_agent_version,
forked_from_thread_id,
thread_source,
options.dynamic_tools,
@@ -643,7 +643,10 @@ impl ThreadManager {
options.initial_history = fork_history_from_snapshot(
ForkSnapshot::Interrupted,
history,
InterruptedTurnHistoryMarker::from_config(&options.config),
InterruptedTurnHistoryMarker::from_config(
&options.config,
fork_source.codex.session.multi_agent_version,
),
);
self.start_thread_with_options_and_fork_source(options, Some(forked_from_thread_id))
.await
@@ -898,7 +901,8 @@ impl ThreadManager {
InitialHistory::Forked(_) => history.forked_from_id(),
InitialHistory::New | InitialHistory::Cleared => None,
};
let interrupted_marker = InterruptedTurnHistoryMarker::from_config(&config);
let interrupted_marker =
InterruptedTurnHistoryMarker::from_config(&config, history.get_multi_agent_version());
let history = fork_history_from_snapshot(snapshot, history, interrupted_marker);
let environments = default_thread_environment_selections(
self.state.environment_manager.as_ref(),
@@ -1032,7 +1036,7 @@ impl ThreadManagerState {
config,
agent_control,
self.session_source.clone(),
/*inherited_multi_agent_version*/ None,
/*parent_multi_agent_version*/ None,
/*forked_from_thread_id*/ None,
/*thread_source*/ None,
/*persist_extended_history*/ false,
@@ -1050,7 +1054,7 @@ impl ThreadManagerState {
config: Config,
agent_control: AgentControl,
session_source: SessionSource,
inherited_multi_agent_version: Option<MultiAgentVersion>,
parent_multi_agent_version: Option<MultiAgentVersion>,
forked_from_thread_id: Option<ThreadId>,
thread_source: Option<ThreadSource>,
persist_extended_history: bool,
@@ -1068,7 +1072,7 @@ impl ThreadManagerState {
Arc::clone(&self.auth_manager),
agent_control,
session_source,
inherited_multi_agent_version,
parent_multi_agent_version,
forked_from_thread_id,
thread_source,
Vec::new(),
@@ -1092,7 +1096,6 @@ impl ThreadManagerState {
initial_history,
agent_control,
session_source,
inherited_multi_agent_version,
inherited_shell_snapshot,
inherited_exec_policy,
} = options;
@@ -1105,7 +1108,7 @@ impl ThreadManagerState {
Arc::clone(&self.auth_manager),
agent_control,
session_source,
inherited_multi_agent_version,
/*parent_multi_agent_version*/ None,
/*forked_from_thread_id*/ None,
thread_source,
Vec::new(),
@@ -1127,7 +1130,7 @@ impl ThreadManagerState {
initial_history: InitialHistory,
agent_control: AgentControl,
session_source: SessionSource,
inherited_multi_agent_version: Option<MultiAgentVersion>,
parent_multi_agent_version: Option<MultiAgentVersion>,
thread_source: Option<ThreadSource>,
forked_from_thread_id: Option<ThreadId>,
persist_extended_history: bool,
@@ -1144,7 +1147,7 @@ impl ThreadManagerState {
Arc::clone(&self.auth_manager),
agent_control,
session_source,
inherited_multi_agent_version,
parent_multi_agent_version,
forked_from_thread_id,
thread_source,
Vec::new(),
@@ -1176,13 +1179,14 @@ impl ThreadManagerState {
environments: Vec<TurnEnvironmentSelection>,
user_shell_override: Option<crate::shell::Shell>,
) -> CodexResult<NewThread> {
let parent_multi_agent_version = initial_history.get_multi_agent_version();
Box::pin(self.spawn_thread_with_source(
config,
initial_history,
auth_manager,
agent_control,
self.session_source.clone(),
/*inherited_multi_agent_version*/ None,
parent_multi_agent_version,
forked_from_thread_id,
thread_source,
dynamic_tools,
@@ -1205,7 +1209,7 @@ impl ThreadManagerState {
auth_manager: Arc<AuthManager>,
agent_control: AgentControl,
session_source: SessionSource,
inherited_multi_agent_version: Option<MultiAgentVersion>,
parent_multi_agent_version: Option<MultiAgentVersion>,
forked_from_thread_id: Option<ThreadId>,
thread_source: Option<ThreadSource>,
dynamic_tools: Vec<codex_protocol::dynamic_tools::DynamicToolSpec>,
@@ -1250,7 +1254,7 @@ impl ThreadManagerState {
} = Codex::spawn(CodexSpawnArgs {
config,
installation_id: self.installation_id.clone(),
inherited_multi_agent_version,
parent_multi_agent_version,
auth_manager,
models_manager: Arc::clone(&self.models_manager),
environment_manager: Arc::clone(&self.environment_manager),
@@ -192,7 +192,6 @@ async fn try_resume_closed_agent(
/*agent_role*/ None,
/*task_name*/ None,
)?,
turn.multi_agent_version,
))
.await
.map(|_| ())
@@ -32,6 +32,7 @@ use codex_protocol::models::PermissionProfile;
use codex_protocol::models::ResponseInputItem;
use codex_protocol::models::ResponseItem;
use codex_protocol::models::SandboxEnforcement;
use codex_protocol::openai_models::MultiAgentVersion;
use codex_protocol::openai_models::ReasoningEffort;
use codex_protocol::protocol::AgentStatus;
use codex_protocol::protocol::AskForApproval;
@@ -382,6 +383,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: Some(MultiAgentVersion::V2),
..turn
};
@@ -425,6 +427,7 @@ async fn multi_agent_v2_spawn_defaults_to_full_fork_and_rejects_child_model_over
.enable(Feature::MultiAgentV2)
.expect("test config should allow feature update");
turn.config = Arc::new(config);
turn.multi_agent_version = Some(MultiAgentVersion::V2);
let err = SpawnAgentHandlerV2::default()
.handle(invocation(
@@ -892,6 +895,7 @@ async fn multi_agent_v2_full_history_fork_accepts_explicit_service_tier() {
.enable(Feature::MultiAgentV2)
.expect("test config should allow feature update");
turn.config = Arc::new(config);
turn.multi_agent_version = Some(MultiAgentVersion::V2);
let manager = thread_manager();
let root = manager
.start_thread((*turn.config).clone())
@@ -959,6 +963,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: Some(MultiAgentVersion::V2),
..turn
};
@@ -1041,6 +1046,7 @@ async fn multi_agent_v2_spawn_requires_task_name() {
.enable(Feature::MultiAgentV2)
.expect("test config should allow feature update");
turn.config = Arc::new(config);
turn.multi_agent_version = Some(MultiAgentVersion::V2);
let invocation = invocation(
Arc::new(session),
@@ -1075,6 +1081,7 @@ async fn multi_agent_v2_spawn_rejects_legacy_items_field() {
.enable(Feature::MultiAgentV2)
.expect("test config should allow feature update");
turn.config = Arc::new(config);
turn.multi_agent_version = Some(MultiAgentVersion::V2);
let invocation = invocation(
Arc::new(session),
@@ -1135,6 +1142,7 @@ async fn multi_agent_v2_spawn_returns_path_and_send_message_accepts_relative_pat
.enable(Feature::MultiAgentV2)
.expect("test config should allow feature update");
turn.config = Arc::new(config);
turn.multi_agent_version = Some(MultiAgentVersion::V2);
let session = Arc::new(session);
let turn = Arc::new(turn);
@@ -1232,6 +1240,7 @@ async fn multi_agent_v2_spawn_rejects_legacy_fork_context() {
.enable(Feature::MultiAgentV2)
.expect("test config should allow feature update");
turn.config = Arc::new(config);
turn.multi_agent_version = Some(MultiAgentVersion::V2);
let err = SpawnAgentHandlerV2::default()
.handle(invocation(
@@ -1272,6 +1281,7 @@ async fn multi_agent_v2_spawn_rejects_invalid_fork_turns_string() {
.enable(Feature::MultiAgentV2)
.expect("test config should allow feature update");
turn.config = Arc::new(config);
turn.multi_agent_version = Some(MultiAgentVersion::V2);
let err = SpawnAgentHandlerV2::default()
.handle(invocation(
@@ -1312,6 +1322,7 @@ async fn multi_agent_v2_spawn_rejects_zero_fork_turns() {
.enable(Feature::MultiAgentV2)
.expect("test config should allow feature update");
turn.config = Arc::new(config);
turn.multi_agent_version = Some(MultiAgentVersion::V2);
let err = SpawnAgentHandlerV2::default()
.handle(invocation(
@@ -1352,6 +1363,7 @@ async fn multi_agent_v2_send_message_accepts_root_target_from_child() {
.enable(Feature::MultiAgentV2)
.expect("test config should allow feature update");
turn.config = Arc::new(config);
turn.multi_agent_version = Some(MultiAgentVersion::V2);
let child_path = AgentPath::try_from("/root/worker").expect("agent path");
let child_thread_id = session
@@ -1428,6 +1440,7 @@ async fn multi_agent_v2_followup_task_rejects_root_target_from_child() {
.enable(Feature::MultiAgentV2)
.expect("test config should allow feature update");
turn.config = Arc::new(config);
turn.multi_agent_version = Some(MultiAgentVersion::V2);
let child_path = AgentPath::try_from("/root/worker").expect("agent path");
let child_thread_id = session
@@ -1506,6 +1519,7 @@ async fn multi_agent_v2_list_agents_returns_completed_status_and_last_task_messa
let mut config = (*turn.config).clone();
let _ = config.features.enable(Feature::MultiAgentV2);
turn.config = Arc::new(config);
turn.multi_agent_version = Some(MultiAgentVersion::V2);
let session = Arc::new(session);
let turn = Arc::new(turn);
@@ -1600,6 +1614,7 @@ async fn multi_agent_v2_list_agents_filters_by_relative_path_prefix() {
let mut config = (*turn.config).clone();
let _ = config.features.enable(Feature::MultiAgentV2);
turn.config = Arc::new(config.clone());
turn.multi_agent_version = Some(MultiAgentVersion::V2);
let researcher_path = AgentPath::from_string("/root/researcher".to_string()).expect("path");
let worker_path = AgentPath::from_string("/root/researcher/worker".to_string()).expect("path");
@@ -1687,6 +1702,7 @@ async fn multi_agent_v2_list_agents_omits_closed_agents() {
let mut config = (*turn.config).clone();
let _ = config.features.enable(Feature::MultiAgentV2);
turn.config = Arc::new(config);
turn.multi_agent_version = Some(MultiAgentVersion::V2);
let session = Arc::new(session);
let turn = Arc::new(turn);
@@ -1751,6 +1767,7 @@ async fn multi_agent_v2_send_message_rejects_legacy_items_field() {
let mut config = turn.config.as_ref().clone();
let _ = config.features.enable(Feature::MultiAgentV2);
turn.config = Arc::new(config);
turn.multi_agent_version = Some(MultiAgentVersion::V2);
let session = Arc::new(session);
let turn = Arc::new(turn);
@@ -1807,6 +1824,7 @@ async fn multi_agent_v2_send_message_rejects_interrupt_parameter() {
let mut config = turn.config.as_ref().clone();
let _ = config.features.enable(Feature::MultiAgentV2);
turn.config = Arc::new(config);
turn.multi_agent_version = Some(MultiAgentVersion::V2);
let session = Arc::new(session);
let turn = Arc::new(turn);
@@ -1880,6 +1898,7 @@ async fn multi_agent_v2_followup_task_completion_notifies_parent_on_every_turn()
let mut config = turn.config.as_ref().clone();
let _ = config.features.enable(Feature::MultiAgentV2);
turn.config = Arc::new(config);
turn.multi_agent_version = Some(MultiAgentVersion::V2);
let session = Arc::new(session);
let turn = Arc::new(turn);
@@ -2015,6 +2034,7 @@ async fn multi_agent_v2_followup_task_rejects_legacy_items_field() {
let mut config = turn.config.as_ref().clone();
let _ = config.features.enable(Feature::MultiAgentV2);
turn.config = Arc::new(config);
turn.multi_agent_version = Some(MultiAgentVersion::V2);
let session = Arc::new(session);
let turn = Arc::new(turn);
@@ -2068,6 +2088,7 @@ async fn multi_agent_v2_interrupted_turn_does_not_notify_parent() {
let mut config = turn.config.as_ref().clone();
let _ = config.features.enable(Feature::MultiAgentV2);
turn.config = Arc::new(config);
turn.multi_agent_version = Some(MultiAgentVersion::V2);
let session = Arc::new(session);
let turn = Arc::new(turn);
@@ -2148,6 +2169,7 @@ async fn multi_agent_v2_spawn_omits_agent_id_when_named() {
.enable(Feature::MultiAgentV2)
.expect("test config should allow feature update");
turn.config = Arc::new(config);
turn.multi_agent_version = Some(MultiAgentVersion::V2);
let output = SpawnAgentHandlerV2::default()
.handle(invocation(
@@ -2187,6 +2209,7 @@ async fn multi_agent_v2_spawn_surfaces_task_name_validation_errors() {
.enable(Feature::MultiAgentV2)
.expect("test config should allow feature update");
turn.config = Arc::new(config);
turn.multi_agent_version = Some(MultiAgentVersion::V2);
let invocation = invocation(
Arc::new(session),
@@ -2397,6 +2420,7 @@ async fn multi_agent_v2_spawn_agent_ignores_configured_max_depth() {
session.services.agent_control = manager.agent_control();
session.conversation_id = root.thread_id;
turn.config = Arc::new(config);
turn.multi_agent_version = Some(MultiAgentVersion::V2);
let parent_path = AgentPath::try_from("/root/parent").expect("agent path");
turn.session_source = SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
parent_thread_id: root.thread_id,
@@ -2871,6 +2895,7 @@ async fn multi_agent_v2_wait_agent_accepts_timeout_only_argument() {
.enable(Feature::MultiAgentV2)
.expect("test config should allow feature update");
turn.config = Arc::new(config);
turn.multi_agent_version = Some(MultiAgentVersion::V2);
let session = Arc::new(session);
let turn = Arc::new(turn);
@@ -2956,6 +2981,7 @@ async fn multi_agent_v2_wait_agent_rejects_timeout_below_configured_min() {
config.multi_agent_v2.max_wait_timeout_ms = 1_000;
config.multi_agent_v2.default_wait_timeout_ms = 50;
turn.config = Arc::new(config);
turn.multi_agent_version = Some(MultiAgentVersion::V2);
let Err(err) = WaitAgentHandlerV2::default()
.handle(invocation(
@@ -2986,6 +3012,7 @@ async fn multi_agent_v2_wait_agent_accepts_explicit_timeout_at_configured_min()
config.multi_agent_v2.max_wait_timeout_ms = 1_000;
config.multi_agent_v2.default_wait_timeout_ms = 50;
turn.config = Arc::new(config);
turn.multi_agent_version = Some(MultiAgentVersion::V2);
let output = WaitAgentHandlerV2::default()
.handle(invocation(
@@ -3021,6 +3048,7 @@ async fn multi_agent_v2_wait_agent_uses_configured_default_timeout() {
config.multi_agent_v2.max_wait_timeout_ms = 1_000;
config.multi_agent_v2.default_wait_timeout_ms = 50;
turn.config = Arc::new(config);
turn.multi_agent_version = Some(MultiAgentVersion::V2);
let session = Arc::new(session);
let turn = Arc::new(turn);
@@ -3076,6 +3104,7 @@ async fn multi_agent_v2_wait_agent_allows_zero_configured_timeout() {
config.multi_agent_v2.max_wait_timeout_ms = 0;
config.multi_agent_v2.default_wait_timeout_ms = 0;
turn.config = Arc::new(config);
turn.multi_agent_version = Some(MultiAgentVersion::V2);
let session = Arc::new(session);
let turn = Arc::new(turn);
@@ -3116,6 +3145,7 @@ async fn multi_agent_v2_wait_agent_rejects_timeout_above_configured_max() {
config.multi_agent_v2.max_wait_timeout_ms = 50;
config.multi_agent_v2.default_wait_timeout_ms = 1;
turn.config = Arc::new(config);
turn.multi_agent_version = Some(MultiAgentVersion::V2);
let Err(err) = WaitAgentHandlerV2::default()
.handle(invocation(
@@ -3146,6 +3176,7 @@ async fn multi_agent_v2_wait_agent_accepts_explicit_timeout_at_configured_max()
config.multi_agent_v2.max_wait_timeout_ms = 1;
config.multi_agent_v2.default_wait_timeout_ms = 1;
turn.config = Arc::new(config);
turn.multi_agent_version = Some(MultiAgentVersion::V2);
let output = WaitAgentHandlerV2::default()
.handle(invocation(
@@ -3354,6 +3385,7 @@ async fn multi_agent_v2_wait_agent_returns_summary_for_mailbox_activity() {
.enable(Feature::MultiAgentV2)
.expect("test config should allow feature update");
turn.config = Arc::new(config);
turn.multi_agent_version = Some(MultiAgentVersion::V2);
let session = Arc::new(session);
let turn = Arc::new(turn);
@@ -3448,6 +3480,7 @@ async fn multi_agent_v2_wait_agent_returns_for_already_queued_mail() {
.enable(Feature::MultiAgentV2)
.expect("test config should allow feature update");
turn.config = Arc::new(config);
turn.multi_agent_version = Some(MultiAgentVersion::V2);
let session = Arc::new(session);
let turn = Arc::new(turn);
@@ -3529,6 +3562,7 @@ async fn multi_agent_v2_wait_agent_wakes_on_any_mailbox_notification() {
.enable(Feature::MultiAgentV2)
.expect("test config should allow feature update");
turn.config = Arc::new(config);
turn.multi_agent_version = Some(MultiAgentVersion::V2);
let session = Arc::new(session);
let turn = Arc::new(turn);
@@ -3620,6 +3654,7 @@ async fn multi_agent_v2_wait_agent_does_not_return_completed_content() {
.enable(Feature::MultiAgentV2)
.expect("test config should allow feature update");
turn.config = Arc::new(config);
turn.multi_agent_version = Some(MultiAgentVersion::V2);
let session = Arc::new(session);
let turn = Arc::new(turn);
@@ -3709,6 +3744,7 @@ async fn multi_agent_v2_close_agent_accepts_task_name_target() {
.enable(Feature::MultiAgentV2)
.expect("test config should allow feature update");
turn.config = Arc::new(config);
turn.multi_agent_version = Some(MultiAgentVersion::V2);
let session = Arc::new(session);
let turn = Arc::new(turn);
@@ -3782,6 +3818,7 @@ async fn multi_agent_v2_close_agent_reaps_stale_task_name_target() {
session.services.agent_control = manager.agent_control();
session.conversation_id = root.thread_id;
turn.config = Arc::new(config.clone());
turn.multi_agent_version = Some(MultiAgentVersion::V2);
let session = Arc::new(session);
let turn = Arc::new(turn);
@@ -3888,6 +3925,7 @@ async fn multi_agent_v2_close_agent_rejects_root_target_and_id() {
.enable(Feature::MultiAgentV2)
.expect("test config should allow feature update");
turn.config = Arc::new(config);
turn.multi_agent_version = Some(MultiAgentVersion::V2);
let session = Arc::new(session);
let turn = Arc::new(turn);
+2 -2
View File
@@ -888,7 +888,7 @@ async fn multi_agent_version_selector_overrides_feature_flags() {
&turn.model_info,
turn.config.as_ref(),
&turn.session_source,
/*inherited_multi_agent_version*/ None,
/*multi_agent_version*/ None,
);
})
.await;
@@ -909,7 +909,7 @@ async fn multi_agent_version_selector_overrides_feature_flags() {
&turn.model_info,
turn.config.as_ref(),
&turn.session_source,
/*inherited_multi_agent_version*/ None,
/*multi_agent_version*/ None,
);
})
.await;
@@ -71,6 +71,7 @@ async fn write_rollout_with_user_event(dir: &Path, thread_id: ThreadId) -> io::R
agent_nickname: None,
agent_role: None,
model_provider: None,
multi_agent_version: None,
base_instructions: None,
dynamic_tools: None,
memory_mode: None,
@@ -119,6 +120,7 @@ async fn write_rollout_with_meta_only(dir: &Path, thread_id: ThreadId) -> io::Re
agent_nickname: None,
agent_role: None,
model_provider: None,
multi_agent_version: None,
base_instructions: None,
dynamic_tools: None,
memory_mode: None,
@@ -186,6 +186,7 @@ async fn find_locates_rollout_file_written_by_recorder() -> std::io::Result<()>
/*forked_from_id*/ None,
SessionSource::Exec,
/*thread_source*/ None,
/*multi_agent_version*/ None,
BaseInstructions::default(),
Vec::new(),
),
@@ -221,6 +221,7 @@ async fn backfill_scans_existing_rollouts() -> Result<()> {
agent_nickname: None,
agent_role: None,
model_provider: None,
multi_agent_version: None,
base_instructions: None,
dynamic_tools: None,
memory_mode: None,