mirror of
https://github.com/openai/codex.git
synced 2026-12-02 00:31:03 +00:00
Support the V3 multi-agent selector on the V2 runtime (#64735)
## Why Enabling `multi_agent_v2` forced the V2 tool version before a fresh thread could use the model selected for its first turn. The shared runtime needs to support both V2 and V3 selections. ## What changed - Let the first turn select V2 or V3 from the active model, with V2 as the fallback when the shared runtime is enabled. - Pass the selected version to fresh and forked subagents, including through host-prepared child creation. - Report both selections as `v2` in app-server model metadata because they use the same runtime. ## Testing Extend integration tests to cover model switches between V2 and V3 before the first turn and V3 inheritance in fresh, forked, and host-prepared children. GitOrigin-RevId: de1fd9836d8cb3c4dc19805507462f4f5cfe3959
This commit is contained in:
BIN
Binary file not shown.
@@ -27,14 +27,36 @@ v2_enum_from_core!(
|
||||
}
|
||||
);
|
||||
|
||||
v2_enum_from_core!(
|
||||
/// Multi-agent runtime supported by a model.
|
||||
pub enum MultiAgentVersion from CoreMultiAgentVersion {
|
||||
Disabled,
|
||||
V1,
|
||||
V2
|
||||
/// Multi-agent runtime supported by a model.
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, JsonSchema, TS)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[ts(export_to = "v2/")]
|
||||
pub enum MultiAgentVersion {
|
||||
Disabled,
|
||||
V1,
|
||||
V2,
|
||||
}
|
||||
|
||||
impl From<CoreMultiAgentVersion> for MultiAgentVersion {
|
||||
fn from(value: CoreMultiAgentVersion) -> Self {
|
||||
match value {
|
||||
CoreMultiAgentVersion::Disabled => Self::Disabled,
|
||||
CoreMultiAgentVersion::V1 => Self::V1,
|
||||
// V3 selects a different set of tools on the V2 runtime.
|
||||
CoreMultiAgentVersion::V2 | CoreMultiAgentVersion::V3 => Self::V2,
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
impl MultiAgentVersion {
|
||||
pub fn to_core(self) -> CoreMultiAgentVersion {
|
||||
match self {
|
||||
Self::Disabled => CoreMultiAgentVersion::Disabled,
|
||||
Self::V1 => CoreMultiAgentVersion::V1,
|
||||
Self::V2 => CoreMultiAgentVersion::V2,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Default, JsonSchema, TS)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
|
||||
@@ -1935,7 +1935,7 @@ async fn thread_fork_freezes_active_paginated_turn_as_interrupted(
|
||||
let codex_home = TempDir::new()?;
|
||||
let config = MockResponsesConfig::new(&server.uri());
|
||||
let (config, expected_marker_role, thread_source) = match multi_agent_version {
|
||||
MultiAgentVersion::V2 => (
|
||||
MultiAgentVersion::V2 | MultiAgentVersion::V3 => (
|
||||
config.enable_feature(Feature::MultiAgentV2),
|
||||
"developer",
|
||||
Some(ThreadSource::Subagent),
|
||||
|
||||
@@ -575,7 +575,7 @@ impl LocalAgentControl {
|
||||
{
|
||||
MultiAgentVersion::Disabled => None,
|
||||
MultiAgentVersion::V1 => Some(ContentItemNamespace::MultiAgentV1),
|
||||
MultiAgentVersion::V2 => Some(
|
||||
MultiAgentVersion::V2 | MultiAgentVersion::V3 => Some(
|
||||
config
|
||||
.multi_agent_v2
|
||||
.tool_namespace
|
||||
|
||||
@@ -231,7 +231,9 @@ impl AgentControl for LocalAgentControl {
|
||||
self.interrupt_agent(target, Op::Interrupt).await?;
|
||||
Ok(snapshot)
|
||||
}
|
||||
MultiAgentVersion::V2 => self.interrupt_spawned_agent(caller, target).await,
|
||||
MultiAgentVersion::V2 | MultiAgentVersion::V3 => {
|
||||
self.interrupt_spawned_agent(caller, target).await
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ pub(super) fn record_spawn_success(
|
||||
MultiAgentVersion::Disabled => "disabled",
|
||||
MultiAgentVersion::V1 => "v1",
|
||||
MultiAgentVersion::V2 => "v2",
|
||||
MultiAgentVersion::V3 => "v3",
|
||||
};
|
||||
let record_phase = |phase, duration| {
|
||||
telemetry.record_multi_agent_spawn_phase(
|
||||
|
||||
@@ -381,7 +381,7 @@ pub(super) async fn prepare_forked_history(
|
||||
.subagent_developer_instructions
|
||||
.as_ref(),
|
||||
) {
|
||||
(MultiAgentVersion::V2, override_instructions)
|
||||
(MultiAgentVersion::V2 | MultiAgentVersion::V3, override_instructions)
|
||||
if override_instructions.is_some() || session_source.get_agent_role().is_some() =>
|
||||
{
|
||||
let parent_developer_instructions = match parent_thread
|
||||
@@ -399,9 +399,8 @@ pub(super) async fn prepare_forked_history(
|
||||
parent_developer_instructions,
|
||||
)
|
||||
}
|
||||
(MultiAgentVersion::Disabled | MultiAgentVersion::V1, _) | (MultiAgentVersion::V2, _) => {
|
||||
(None, None)
|
||||
}
|
||||
(MultiAgentVersion::Disabled | MultiAgentVersion::V1, _)
|
||||
| (MultiAgentVersion::V2 | MultiAgentVersion::V3, _) => (None, None),
|
||||
};
|
||||
let parent_history_mode = parent_thread.config_snapshot().await.history_mode;
|
||||
// `record_conversation_items` only queues persistence writes asynchronously.
|
||||
|
||||
@@ -228,6 +228,7 @@ pub(crate) async fn prepare(
|
||||
let (exec_policy, exec_policy_source_requirements) =
|
||||
thread.session.services.exec_policy.snapshot();
|
||||
Ok(PreparedChildContext {
|
||||
multi_agent_version: turn.multi_agent_version,
|
||||
originator: turn.originator.clone(),
|
||||
base_instructions: thread.session.get_base_instructions().await,
|
||||
developer_instructions: inherited_developer_instructions(turn),
|
||||
|
||||
@@ -25,7 +25,6 @@ use codex_protocol::SessionId;
|
||||
use codex_protocol::error::AgentErrorContext;
|
||||
use codex_protocol::error::CodexErr;
|
||||
use codex_protocol::error::Result;
|
||||
use codex_protocol::protocol::MultiAgentVersion;
|
||||
use codex_protocol::protocol::ThreadSource;
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -50,15 +49,16 @@ async fn prepare_spawn_inputs(
|
||||
let snapshot = options.environments.as_ref().ok_or_else(|| {
|
||||
CodexErr::InvalidRequest("prepared spawn requires captured environments".into())
|
||||
})?;
|
||||
let version = parent
|
||||
.multi_agent_version()
|
||||
.ok_or_else(|| CodexErr::InvalidRequest("missing invoking agent version".into()))?;
|
||||
let (initial_history, history_mode, dynamic_tools) = if options.fork_mode.is_some() {
|
||||
let (history, mode) =
|
||||
prepare_forked_history(&state, &source, &options, &config, MultiAgentVersion::V2)
|
||||
.await
|
||||
.map_err(|error| error.with_agent_context(AgentErrorContext::ForkHistory))?;
|
||||
let (history, mode) = prepare_forked_history(&state, &source, &options, &config, version)
|
||||
.await
|
||||
.map_err(|error| error.with_agent_context(AgentErrorContext::ForkHistory))?;
|
||||
(history, mode, Vec::new())
|
||||
} else {
|
||||
let (mode, tools) =
|
||||
fresh_child_history_and_tools(parent, &config, MultiAgentVersion::V2).await;
|
||||
let (mode, tools) = fresh_child_history_and_tools(parent, &config, version).await;
|
||||
(InitialHistory::New, mode, tools)
|
||||
};
|
||||
if !std::ptr::eq(state.get_thread(caller).await?.as_ref(), parent) {
|
||||
@@ -66,6 +66,7 @@ async fn prepare_spawn_inputs(
|
||||
}
|
||||
let exec_policy = inherited_exec_policy_for_parent(parent, &config).await;
|
||||
let mut thread_options = StartThreadOptions {
|
||||
inherited_multi_agent_version: Some(version),
|
||||
request_country: options.request_country,
|
||||
session_source: Some(source),
|
||||
thread_source: Some(ThreadSource::Subagent),
|
||||
|
||||
@@ -62,6 +62,8 @@ pub struct HostThreadSpawnReservation {
|
||||
/// The host binds the destination's services and applies the requested child settings.
|
||||
/// Repository instructions are discovered at the destination.
|
||||
pub struct PreparedChildContext {
|
||||
/// Pass to StartThreadOptions::inherited_multi_agent_version on the destination.
|
||||
pub multi_agent_version: codex_protocol::protocol::MultiAgentVersion,
|
||||
pub originator: String,
|
||||
/// Effective parent base instructions, including whether they are custom or model-owned.
|
||||
/// Apply both `text` and `provenance` to the destination config so model-owned instructions
|
||||
|
||||
@@ -1651,8 +1651,14 @@ impl CodexThread {
|
||||
(Arc::new(mcp_config), runtime_context)
|
||||
}
|
||||
|
||||
/// Returns the selected version, or V2 when configuration enables its runtime
|
||||
/// and the first turn has yet to select a tool version.
|
||||
pub fn multi_agent_version(&self) -> Option<MultiAgentVersion> {
|
||||
self.session.multi_agent_version()
|
||||
self.session.multi_agent_version().or_else(|| {
|
||||
self.session
|
||||
.enabled(Feature::MultiAgentV2)
|
||||
.then_some(MultiAgentVersion::V2)
|
||||
})
|
||||
}
|
||||
|
||||
/// Shares an immutable view of the live parent model context and retained host facts.
|
||||
|
||||
@@ -1856,9 +1856,17 @@ impl Config {
|
||||
&& reviewer_provider_id == OPENAI_PROVIDER_ID
|
||||
}
|
||||
|
||||
pub(crate) fn multi_agent_version_override(&self) -> Option<MultiAgentVersion> {
|
||||
pub(crate) fn multi_agent_version_override(
|
||||
&self,
|
||||
selected: Option<MultiAgentVersion>,
|
||||
) -> Option<MultiAgentVersion> {
|
||||
if self.features.enabled(Feature::MultiAgentV2) {
|
||||
Some(MultiAgentVersion::V2)
|
||||
// This feature enables the shared runtime. Honor a more specific tool version.
|
||||
Some(
|
||||
selected
|
||||
.filter(|version| version.uses_v2_runtime())
|
||||
.unwrap_or(MultiAgentVersion::V2),
|
||||
)
|
||||
} else if !self.agents_enabled {
|
||||
Some(MultiAgentVersion::Disabled)
|
||||
} else {
|
||||
@@ -1867,20 +1875,21 @@ impl Config {
|
||||
}
|
||||
|
||||
pub(crate) fn multi_agent_version_from_features(&self) -> MultiAgentVersion {
|
||||
self.multi_agent_version_override().unwrap_or_else(|| {
|
||||
if self.features.enabled(Feature::Collab) {
|
||||
MultiAgentVersion::V1
|
||||
} else {
|
||||
MultiAgentVersion::Disabled
|
||||
}
|
||||
})
|
||||
self.multi_agent_version_override(/*selected*/ None)
|
||||
.unwrap_or_else(|| {
|
||||
if self.features.enabled(Feature::Collab) {
|
||||
MultiAgentVersion::V1
|
||||
} else {
|
||||
MultiAgentVersion::Disabled
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn multi_agent_version_for_model(
|
||||
&self,
|
||||
model_multi_agent_version: Option<MultiAgentVersion>,
|
||||
) -> MultiAgentVersion {
|
||||
self.multi_agent_version_override()
|
||||
self.multi_agent_version_override(model_multi_agent_version)
|
||||
.or(model_multi_agent_version)
|
||||
.unwrap_or_else(|| self.multi_agent_version_from_features())
|
||||
}
|
||||
@@ -1890,7 +1899,7 @@ impl Config {
|
||||
multi_agent_version: MultiAgentVersion,
|
||||
) -> Option<usize> {
|
||||
match multi_agent_version {
|
||||
MultiAgentVersion::V2 => Some(
|
||||
MultiAgentVersion::V2 | MultiAgentVersion::V3 => Some(
|
||||
self.multi_agent_v2
|
||||
.max_concurrent_threads_per_session
|
||||
.saturating_sub(1),
|
||||
|
||||
@@ -957,9 +957,20 @@ impl Session {
|
||||
token_budget::apply_model_defaults(Arc::make_mut(&mut config), &model_info);
|
||||
}
|
||||
let configured_config = Arc::clone(&config);
|
||||
let multi_agent_version = config.multi_agent_version_override().or_else(|| {
|
||||
resolve_multi_agent_version(&conversation_history, inherited_multi_agent_version)
|
||||
});
|
||||
let inherited =
|
||||
resolve_multi_agent_version(&conversation_history, inherited_multi_agent_version);
|
||||
// The feature selects the shared runtime. A fresh root's first turn selects
|
||||
// its tool version, which may differ from the startup model's preference.
|
||||
let multi_agent_version = if inherited.is_none()
|
||||
&& !session_source.is_non_root_agent()
|
||||
&& config.features.enabled(Feature::MultiAgentV2)
|
||||
{
|
||||
None
|
||||
} else {
|
||||
config
|
||||
.multi_agent_version_override(inherited.or(model_info.multi_agent_version))
|
||||
.or(inherited)
|
||||
};
|
||||
let history_mode = conversation_history.get_history_mode(
|
||||
requested_history_mode.unwrap_or_else(|| thread_store.default_history_mode()),
|
||||
);
|
||||
|
||||
@@ -193,7 +193,7 @@ impl Session {
|
||||
&& matches!(self.agent_runtime, AgentRuntimeServices::Controller)
|
||||
{
|
||||
match turn_context.multi_agent_version {
|
||||
MultiAgentVersion::V2 => format_agent_paths(
|
||||
MultiAgentVersion::V2 | MultiAgentVersion::V3 => format_agent_paths(
|
||||
self.services
|
||||
.agent_control
|
||||
.child_agent_paths(self.thread_id)
|
||||
@@ -532,7 +532,7 @@ impl Session {
|
||||
Some(MULTI_AGENT_V1_NAMESPACE.to_string()),
|
||||
"spawn_agent",
|
||||
)),
|
||||
MultiAgentVersion::V2 => turn_context
|
||||
MultiAgentVersion::V2 | MultiAgentVersion::V3 => turn_context
|
||||
.config
|
||||
.multi_agent_v2
|
||||
.expose_spawn_agent_model_overrides
|
||||
@@ -562,7 +562,7 @@ impl Session {
|
||||
.with_namespace(match turn_context.multi_agent_version {
|
||||
MultiAgentVersion::Disabled => None,
|
||||
MultiAgentVersion::V1 => Some(ContentItemNamespace::MultiAgentV1),
|
||||
MultiAgentVersion::V2 => Some(v2_namespace),
|
||||
MultiAgentVersion::V2 | MultiAgentVersion::V3 => Some(v2_namespace),
|
||||
}),
|
||||
);
|
||||
if !crate::guardian::is_basic_session_source(&turn_context.session_source) {
|
||||
|
||||
@@ -355,6 +355,8 @@ pub enum PromptCacheKey {
|
||||
}
|
||||
|
||||
pub struct StartThreadOptions {
|
||||
/// Tool version captured by a host preparing a child on another runtime.
|
||||
pub inherited_multi_agent_version: Option<MultiAgentVersion>,
|
||||
pub config: Config,
|
||||
/// Opt out of root enrollment unless managed policy requires propagation.
|
||||
pub prevent_daybreak_program_propagation_enrollment: bool,
|
||||
@@ -463,6 +465,7 @@ impl StartThreadOptions {
|
||||
thread_instructions_provider: None,
|
||||
allow_provider_model_fallback: false,
|
||||
initial_history: InitialHistory::New,
|
||||
inherited_multi_agent_version: None,
|
||||
resume_preparation: None,
|
||||
internal_parent: None,
|
||||
history_mode: None,
|
||||
@@ -2296,17 +2299,15 @@ impl ThreadManagerState {
|
||||
forked_from_thread_id: Option<ThreadId>,
|
||||
config: &Config,
|
||||
) -> MultiAgentVersion {
|
||||
if let Some(multi_agent_version) = config.multi_agent_version_override() {
|
||||
return multi_agent_version;
|
||||
}
|
||||
self.initial_multi_agent_version_for_spawn(
|
||||
initial_history,
|
||||
session_source,
|
||||
parent_thread_id,
|
||||
forked_from_thread_id,
|
||||
)
|
||||
.await
|
||||
.unwrap_or_else(|| config.multi_agent_version_from_features())
|
||||
let inherited = self
|
||||
.initial_multi_agent_version_for_spawn(
|
||||
initial_history,
|
||||
session_source,
|
||||
parent_thread_id,
|
||||
forked_from_thread_id,
|
||||
)
|
||||
.await;
|
||||
config.multi_agent_version_for_model(inherited)
|
||||
}
|
||||
|
||||
async fn initial_multi_agent_version_for_spawn(
|
||||
@@ -2666,6 +2667,7 @@ impl ThreadManagerState {
|
||||
HistoryInitialization::from_history(&options.initial_history)
|
||||
};
|
||||
let StartThreadOptions {
|
||||
inherited_multi_agent_version,
|
||||
mut config,
|
||||
prevent_daybreak_program_propagation_enrollment,
|
||||
request_country,
|
||||
@@ -2891,8 +2893,8 @@ impl ThreadManagerState {
|
||||
}
|
||||
let (exec_policy, multi_agent_version) = match isolation {
|
||||
SessionIsolation::Isolated => (None, Some(MultiAgentVersion::Disabled)),
|
||||
SessionIsolation::Inherit if prepared_child.is_some() => {
|
||||
(inherited_exec_policy, Some(MultiAgentVersion::V2))
|
||||
SessionIsolation::Inherit if inherited_multi_agent_version.is_some() => {
|
||||
(inherited_exec_policy, inherited_multi_agent_version)
|
||||
}
|
||||
SessionIsolation::Inherit => (
|
||||
inherited_exec_policy,
|
||||
|
||||
@@ -101,6 +101,7 @@ pub(crate) fn record_collab_spawn_failure(
|
||||
MultiAgentVersion::Disabled => "disabled",
|
||||
MultiAgentVersion::V1 => "v1",
|
||||
MultiAgentVersion::V2 => "v2",
|
||||
MultiAgentVersion::V3 => "v3",
|
||||
};
|
||||
telemetry
|
||||
.clone()
|
||||
|
||||
@@ -3,7 +3,6 @@ use super::*;
|
||||
use crate::agent::api::AgentTarget;
|
||||
use crate::tools::handlers::multi_agents_spec::create_interrupt_agent_tool_v2;
|
||||
use codex_otel::SubagentStopAction;
|
||||
use codex_protocol::protocol::MultiAgentVersion;
|
||||
use codex_tools::ToolSpec;
|
||||
|
||||
pub(crate) struct Handler;
|
||||
@@ -49,7 +48,7 @@ async fn handle_interrupt_agent(
|
||||
.interrupt(
|
||||
session.thread_id,
|
||||
AgentTarget::Id(agent_id),
|
||||
MultiAgentVersion::V2,
|
||||
turn.multi_agent_version,
|
||||
)
|
||||
.await
|
||||
.map_err(|err| collab_v2_agent_error(agent_id, err))?;
|
||||
|
||||
@@ -10,7 +10,6 @@ use crate::tools::handlers::multi_agents_spec::create_spawn_agent_tool_v2;
|
||||
use crate::tools::handlers::multi_agents_v2::message_tool::message_content;
|
||||
use crate::turn_timing::now_unix_timestamp_ms;
|
||||
use codex_protocol::ThreadId;
|
||||
use codex_protocol::protocol::MultiAgentVersion;
|
||||
use codex_tools::ToolSpec;
|
||||
use std::num::NonZeroUsize;
|
||||
|
||||
@@ -143,7 +142,7 @@ async fn handle_spawn_agent(
|
||||
&call_id,
|
||||
&turn.sub_id,
|
||||
fork_mode.as_ref(),
|
||||
MultiAgentVersion::V2,
|
||||
turn.multi_agent_version,
|
||||
);
|
||||
collab_spawn_error(err)
|
||||
}
|
||||
|
||||
@@ -736,7 +736,7 @@ fn collab_tools_enabled(turn_context: &TurnContext, model_info: &ModelInfo) -> b
|
||||
next_thread_spawn_depth(&turn_context.session_source),
|
||||
turn_context.config.agent_max_depth,
|
||||
),
|
||||
MultiAgentVersion::V2 => {
|
||||
MultiAgentVersion::V2 | MultiAgentVersion::V3 => {
|
||||
!turn_context.config.multi_agent_v2.disable_native_tools
|
||||
&& (turn_context.session_source.get_agent_path().is_none()
|
||||
|| model_info
|
||||
@@ -760,7 +760,7 @@ fn required_child_management_tool_names(
|
||||
Some(MULTI_AGENT_V1_NAMESPACE),
|
||||
&["send_input", "wait_agent", "resume_agent", "close_agent"],
|
||||
),
|
||||
MultiAgentVersion::V2 => (
|
||||
MultiAgentVersion::V2 | MultiAgentVersion::V3 => (
|
||||
turn_context.config.multi_agent_v2.tool_namespace.as_deref(),
|
||||
if turn_context.config.multi_agent_v2.disable_direct_message {
|
||||
&["interrupt_agent", "list_agents"]
|
||||
|
||||
@@ -536,15 +536,23 @@ async fn migrating_only_the_project_agent_setting_preserves_v1_tools() -> Result
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test_case::test_case(MultiAgentVersion::V1, MultiAgentVersion::V2, false; "v2")]
|
||||
#[test_case::test_case(MultiAgentVersion::V1, MultiAgentVersion::V3, false; "v3")]
|
||||
#[test_case::test_case(MultiAgentVersion::V2, MultiAgentVersion::V3, true; "v2_feature_selects_v3")]
|
||||
#[test_case::test_case(MultiAgentVersion::V3, MultiAgentVersion::V2, true; "v2_feature_selects_v2")]
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn remote_multi_agent_selector_uses_model_selected_before_first_turn() -> Result<()> {
|
||||
async fn remote_multi_agent_selector_uses_model_selected_before_first_turn(
|
||||
initial_version: MultiAgentVersion,
|
||||
version: MultiAgentVersion,
|
||||
enable_v2: bool,
|
||||
) -> Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
|
||||
let server = wiremock::MockServer::start().await;
|
||||
let mut initial_model = remote_model(ROOT_MODEL);
|
||||
initial_model.multi_agent_version = Some(MultiAgentVersion::V1);
|
||||
initial_model.multi_agent_version = Some(initial_version);
|
||||
let mut selected_model = remote_model(CHILD_MODEL);
|
||||
selected_model.multi_agent_version = Some(MultiAgentVersion::V2);
|
||||
selected_model.multi_agent_version = Some(version);
|
||||
let models_mock = mount_models_once(
|
||||
&server,
|
||||
ModelsResponse {
|
||||
@@ -564,16 +572,23 @@ async fn remote_multi_agent_selector_uses_model_selected_before_first_turn() ->
|
||||
|
||||
let mut builder = test_codex()
|
||||
.with_auth(CodexAuth::create_dummy_chatgpt_auth_for_testing())
|
||||
.with_config(|config| {
|
||||
.with_config(move |config| {
|
||||
config.model = Some(ROOT_MODEL.to_string());
|
||||
if enable_v2 {
|
||||
config
|
||||
.features
|
||||
.enable(Feature::MultiAgentV2)
|
||||
.expect("enable shared runtime");
|
||||
}
|
||||
});
|
||||
let test = builder.build(&server).await?;
|
||||
let before_turn = enable_v2.then_some(MultiAgentVersion::V2);
|
||||
assert_eq!(
|
||||
(
|
||||
models_mock.requests().len(),
|
||||
test.codex.multi_agent_version(),
|
||||
),
|
||||
(1, None)
|
||||
(1, before_turn)
|
||||
);
|
||||
|
||||
submit_thread_settings(
|
||||
@@ -584,7 +599,7 @@ async fn remote_multi_agent_selector_uses_model_selected_before_first_turn() ->
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
assert_eq!(test.codex.multi_agent_version(), None);
|
||||
assert_eq!(test.codex.multi_agent_version(), before_turn);
|
||||
|
||||
test.codex
|
||||
.start_or_steer_turn(TurnInputRequest::user_input(vec![UserInput::Text {
|
||||
@@ -609,7 +624,7 @@ async fn remote_multi_agent_selector_uses_model_selected_before_first_turn() ->
|
||||
)
|
||||
.contains(&MULTI_AGENT_V2_NAMESPACE.to_string()),
|
||||
),
|
||||
(1, Some(MultiAgentVersion::V2), true)
|
||||
(1, Some(version), true)
|
||||
);
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -91,7 +91,6 @@ use codex_protocol::protocol::AdditionalContextEntry;
|
||||
use codex_protocol::protocol::AdditionalContextKind;
|
||||
use codex_protocol::protocol::EnvironmentConfigState;
|
||||
use codex_protocol::protocol::EventMsg;
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
use codex_protocol::protocol::MultiAgentVersion;
|
||||
use codex_protocol::protocol::Op;
|
||||
use codex_protocol::protocol::ThreadSettingsOverrides;
|
||||
|
||||
@@ -42,6 +42,7 @@ use wiremock::MockServer;
|
||||
async fn host_spawn_fixture(
|
||||
server: &MockServer,
|
||||
builder: TestCodexBuilder,
|
||||
version: MultiAgentVersion,
|
||||
application_network_policy: NetworkPolicy,
|
||||
thread_instructions_provider: Option<Arc<dyn ThreadInstructionsProvider>>,
|
||||
) -> Result<(TestCodex, Arc<CodexThread>, Arc<TestAgentControl>)> {
|
||||
@@ -84,6 +85,7 @@ async fn host_spawn_fixture(
|
||||
.build_with_auto_env(server)
|
||||
.await?;
|
||||
let mut options = test.start_thread_options().await;
|
||||
options.inherited_multi_agent_version = Some(version);
|
||||
options
|
||||
.thread_extension_init
|
||||
.insert(HostToolInvocationLookup);
|
||||
@@ -167,11 +169,13 @@ fn create_request(name: &str, fork_history: bool) -> ThreadCreateRequest {
|
||||
}
|
||||
}
|
||||
|
||||
#[test_case::test_case(Some("Keep the custom base instructions."), None; "custom")]
|
||||
#[test_case::test_case(Some("Keep the custom base instructions."), Some("Report worker findings concisely."); "subagent override")]
|
||||
#[test_case::test_case(None, None; "model owned")]
|
||||
#[test_case::test_case(MultiAgentVersion::V2, Some("Keep the custom base instructions."), None; "custom")]
|
||||
#[test_case::test_case(MultiAgentVersion::V2, Some("Keep the custom base instructions."), Some("Report worker findings concisely."); "subagent override")]
|
||||
#[test_case::test_case(MultiAgentVersion::V2, None, None; "model owned")]
|
||||
#[test_case::test_case(MultiAgentVersion::V3, None, None; "v3 model owned")]
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn prepared_child_instructions_preserve_native_inheritance(
|
||||
version: MultiAgentVersion,
|
||||
custom_base: Option<&'static str>,
|
||||
subagent_developer: Option<&'static str>,
|
||||
) -> Result<()> {
|
||||
@@ -193,6 +197,7 @@ async fn prepared_child_instructions_preserve_native_inheritance(
|
||||
.enable(Feature::IncrementalTools)
|
||||
.expect("test config should allow incremental tools");
|
||||
}),
|
||||
version,
|
||||
NetworkPolicy::unmanaged(),
|
||||
/*thread_instructions_provider*/ None,
|
||||
)
|
||||
@@ -230,6 +235,7 @@ async fn prepared_child_instructions_preserve_native_inheritance(
|
||||
// A portable host forwards prepared instructions into its destination config, then applies
|
||||
// the requested child model. Model-owned instructions must still resolve for that model.
|
||||
let mut options = test.start_thread_options().await;
|
||||
options.inherited_multi_agent_version = Some(prepared.multi_agent_version);
|
||||
options.config.base_instructions = Some(prepared.base_instructions.text);
|
||||
options.config.base_instructions_provenance = prepared.base_instructions.provenance;
|
||||
options.config.developer_instructions = prepared.developer_instructions;
|
||||
@@ -244,6 +250,7 @@ async fn prepared_child_instructions_preserve_native_inheritance(
|
||||
)]))
|
||||
.await?;
|
||||
wait_for_successful_turn(&child).await;
|
||||
assert_eq!(child.multi_agent_version(), Some(version));
|
||||
let request = mock.single_request();
|
||||
let child_model = catalog
|
||||
.models
|
||||
@@ -277,10 +284,13 @@ async fn prepared_child_instructions_preserve_native_inheritance(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test_case::test_case(false; "fresh")]
|
||||
#[test_case::test_case(true; "forked")]
|
||||
#[test_case::test_case(MultiAgentVersion::V2, false; "fresh")]
|
||||
#[test_case::test_case(MultiAgentVersion::V2, true; "forked")]
|
||||
#[test_case::test_case(MultiAgentVersion::V3, false; "v3 fresh")]
|
||||
#[test_case::test_case(MultiAgentVersion::V3, true; "v3 forked")]
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn same_manager_creation_preserves_live_bindings_and_attachments(
|
||||
version: MultiAgentVersion,
|
||||
fork_history: bool,
|
||||
) -> Result<()> {
|
||||
const PR: &str = "openai/codex#123";
|
||||
@@ -310,6 +320,7 @@ async fn same_manager_creation_preserves_live_bindings_and_attachments(
|
||||
.enable(Feature::FastMode)
|
||||
.expect("test config should allow fast mode");
|
||||
}),
|
||||
version,
|
||||
network_policy.clone(),
|
||||
Some(provider.clone()),
|
||||
)
|
||||
@@ -388,6 +399,7 @@ async fn same_manager_creation_preserves_live_bindings_and_attachments(
|
||||
captured.disabled_plugin_ids
|
||||
);
|
||||
let worker = test.thread_manager.get_thread(child_id).await?;
|
||||
assert_eq!(worker.multi_agent_version(), Some(version));
|
||||
// A handle cannot be used through a different source runtime.
|
||||
assert!(matches!(
|
||||
worker.prepare_child(&context).await,
|
||||
@@ -487,6 +499,7 @@ async fn cancelled_creation_cleans_registered_child() -> Result<()> {
|
||||
let (test, parent, controller) = host_spawn_fixture(
|
||||
&server,
|
||||
test_codex().with_extensions(Arc::new(extensions.build())),
|
||||
MultiAgentVersion::V2,
|
||||
NetworkPolicy::unmanaged(),
|
||||
/*thread_instructions_provider*/ None,
|
||||
)
|
||||
|
||||
@@ -375,7 +375,7 @@ pub(super) async fn model_catalog_refresh_requests(
|
||||
let body = request.body_json();
|
||||
let namespace = match multi_agent_version {
|
||||
MultiAgentVersion::V1 => MULTI_AGENT_V1_NAMESPACE,
|
||||
MultiAgentVersion::V2 => MULTI_AGENT_V2_NAMESPACE,
|
||||
MultiAgentVersion::V2 | MultiAgentVersion::V3 => MULTI_AGENT_V2_NAMESPACE,
|
||||
MultiAgentVersion::Disabled => unreachable!("this scenario requires spawning"),
|
||||
};
|
||||
let description = spawn_agent_description(&body, namespace)
|
||||
|
||||
@@ -3504,12 +3504,13 @@ pub enum MultiAgentVersion {
|
||||
Disabled,
|
||||
V1,
|
||||
V2,
|
||||
V3,
|
||||
}
|
||||
|
||||
impl MultiAgentVersion {
|
||||
/// Whether this version uses path-addressed workers with turn-scoped execution slots.
|
||||
pub fn uses_v2_runtime(self) -> bool {
|
||||
matches!(self, Self::V2)
|
||||
matches!(self, Self::V2 | Self::V3)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user