Keep multi-agent thread limits in config resolution

This commit is contained in:
Ahmed Ibrahim
2026-05-29 11:09:42 -07:00
parent d926f6c05e
commit 7de051e1ec
3 changed files with 3 additions and 75 deletions
+2 -18
View File
@@ -224,15 +224,7 @@ impl AgentControl {
}
_ => config.features.enabled(Feature::MultiAgentV2),
};
let max_threads = multi_agent_v2
.then(|| {
config
.multi_agent_v2
.max_concurrent_threads_per_session
.saturating_sub(1)
})
.or(config.agent_max_threads);
let mut reservation = self.state.reserve_spawn_slot(max_threads)?;
let mut reservation = self.state.reserve_spawn_slot(config.agent_max_threads)?;
let inherited_shell_snapshot = self
.inherited_shell_snapshot_for_source(&state, session_source.as_ref())
.await;
@@ -618,15 +610,7 @@ impl AgentControl {
}
let state = self.upgrade()?;
let state_db_ctx = state.state_db();
let max_threads = multi_agent_v2
.then(|| {
config
.multi_agent_v2
.max_concurrent_threads_per_session
.saturating_sub(1)
})
.or(config.agent_max_threads);
let mut reservation = self.state.reserve_spawn_slot(max_threads)?;
let mut reservation = self.state.reserve_spawn_slot(config.agent_max_threads)?;
let (session_source, agent_metadata) = match session_source {
SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
parent_thread_id,
-48
View File
@@ -1312,54 +1312,6 @@ async fn spawn_agent_respects_max_threads_limit() {
.expect("shutdown agent");
}
#[tokio::test]
async fn spawn_agent_uses_multi_agent_v2_selector_thread_limit() {
let harness = AgentControlHarness::new().await;
let mut config = harness.config.clone();
config.agent_max_threads = Some(4);
config.multi_agent_v2.max_concurrent_threads_per_session = 2;
let session_source = Some(SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
parent_thread_id: ThreadId::new(),
depth: 1,
agent_path: Some(AgentPath::try_from("/root/worker").expect("agent path")),
agent_nickname: None,
agent_role: None,
}));
let first_agent_id = harness
.control
.spawn_agent_with_metadata(
config.clone(),
text_input("hello"),
session_source.clone(),
SpawnAgentOptions::default(),
)
.await
.expect("spawn_agent should succeed")
.thread_id;
let err = harness
.control
.spawn_agent_with_metadata(
config,
text_input("hello again"),
session_source,
SpawnAgentOptions::default(),
)
.await
.expect_err("spawn_agent should use the v2 thread limit");
let CodexErr::AgentLimitReached { max_threads } = err else {
panic!("expected CodexErr::AgentLimitReached");
};
assert_eq!(max_threads, 1);
let _ = harness
.control
.shutdown_live_agent(first_agent_id)
.await
.expect("shutdown agent");
}
#[tokio::test]
async fn spawn_agent_releases_slot_after_shutdown() {
let max_threads = 1usize;
@@ -10,7 +10,6 @@ use crate::tools::handlers::multi_agents::build_agent_spawn_config;
use crate::tools::handlers::parse_arguments;
use codex_protocol::ThreadId;
use codex_protocol::error::CodexErr;
use codex_protocol::openai_models::MultiAgentVersion;
use codex_protocol::protocol::AgentStatus;
use codex_protocol::protocol::SessionSource;
use codex_protocol::protocol::SubAgentSource;
@@ -120,14 +119,7 @@ async fn build_runner_options(
"agent depth limit reached; this session cannot spawn more subagents".to_string(),
));
}
let max_threads = (turn.multi_agent_version == Some(MultiAgentVersion::V2))
.then(|| {
turn.config
.multi_agent_v2
.max_concurrent_threads_per_session
.saturating_sub(1)
})
.or(turn.config.agent_max_threads);
let max_threads = turn.config.agent_max_threads;
if max_threads == Some(0) {
return Err(FunctionCallError::RespondToModel(
"agent thread limit reached; this session cannot spawn more subagents".to_string(),