feat: count V2 concurrency by active execution (#26969)

## Why

Multi-Agent V2 concurrency should count active non-root turns, not
resident or durable agent threads. The limit is intentionally best
effort: admission checks are synchronous, but concurrent successful
checks may overshoot slightly.

## What changed

- Keep one root-derived execution limit on the shared `AgentControl`.
- Count active V2 subagent turns with an RAII guard owned by
`RunningTask`.
- Check capacity before spawning or starting an idle agent, including
direct app-server `turn/start` submissions.
- Preserve queued delivery for agents that are already running.
- Exempt automatic idle continuations so `/goal` work is not dropped
when capacity is temporarily full.
- Keep root and V1 turns outside this limiter.

## Test coverage

- `execution_guards_count_active_v2_subagent_turns`
- `execution_guards_ignore_root_and_v1_turns`
- `v2_nested_spawn_checks_shared_active_execution_capacity`
This commit is contained in:
jif
2026-06-08 14:21:28 +02:00
committed by GitHub
parent 8f1aad58dc
commit 743f5aad38
11 changed files with 340 additions and 13 deletions
+6
View File
@@ -234,6 +234,12 @@ impl CodexThread {
trace: Option<W3cTraceContext>,
client_user_message_id: Option<String>,
) -> CodexResult<String> {
self.codex
.session
.services
.agent_control
.ensure_execution_capacity_for_op(self.session_configured.thread_id, &op)
.await?;
self.codex
.submit_user_input_with_client_user_message_id(op, trace, client_user_message_id)
.await