feat: add agent execution slot accounting#26614
Conversation
There was a problem hiding this comment.
💡 Codex Review
codex/codex-rs/core/src/agent/control/spawn.rs
Lines 578 to 580 in e92893d
Resuming a closed V2 agent now commits a spawn reservation, which inserts the thread into active_thread_ids, but resume_agent does not start a turn or call the idle release path afterward. In a session that resumes an idle agent (or its open descendants) and then leaves it idle, that agent keeps consuming max_concurrent_threads_per_session capacity indefinitely, so subsequent runnable agents can be rejected even though nothing is executing. Please release the execution slot for resumed V2 threads unless they immediately have work to run.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
## Summary Mechanically splits `AgentControl` into focused modules so later agent runtime changes are easier to review. The shared lookup, messaging, and completion logic remains in `control.rs`, while spawn-specific code and V1 legacy close/resume behavior move into dedicated files. ## Changes - Extract spawn-agent code into `agent/control/spawn.rs`. - Extract V1-only legacy close/resume behavior into `agent/control/legacy.rs`. - Keep shared control-plane behavior in `agent/control.rs`. - Preserve existing behavior; this PR is intended to be mechanical. ## Stack 1. This PR - Mechanical `AgentControl` split: extracts spawn and V1 legacy code without behavior changes. 2. #26614 - Execution slot accounting: separates logical agents from active execution slots. 3. #26611 - Residency and reload runtime: adds resident-agent LRU, eviction/reload, durable lookup, and V2 delivery through reload. 4. #26612 - V2 tool semantics: narrows `close_agent` to interrupt-only and updates V2 tool coverage.
569848b to
bdb868f
Compare
|
This routes idle releases through the same counter the spawn path checks, so an idle-but-alive sub-agent frees spawn budget. The cap now bounds concurrently executing threads rather than live threads: a parent agent can spawn A → A finishes and idles → spawn B → … and accumulate an unbounded set of long-lived idle sub-agent threads, each still holding a Fix: if a bound on total live sub-agents is still wanted, add a separate live-thread cap or an idle-thread reaper; otherwise it's worth documenting the new model and confirming the per-idle-thread footprint is negligible. |
Summary
Separates logical agent registration from active execution-slot accounting for multi-agent sessions. This keeps spawned agents addressable after they become idle while allowing V2 pending turns to reserve capacity only when they actually need to run.
The V2 configured concurrency limit continues to include the root thread, so spawned-agent execution uses the non-root capacity derived from that limit.
Changes
Stack
AgentControlsplit: extracts spawn and V1 legacy code without behavior changes.close_agentto interrupt-only and updates V2 tool coverage.