Skip to content

feat: add agent execution slot accounting#26614

Open
jif-oai wants to merge 3 commits into
mainfrom
jif/agent-runtime-slots
Open

feat: add agent execution slot accounting#26614
jif-oai wants to merge 3 commits into
mainfrom
jif/agent-runtime-slots

Conversation

@jif-oai
Copy link
Copy Markdown
Collaborator

@jif-oai jif-oai commented Jun 5, 2026

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

  • Track active execution slots separately from logical agent metadata.
  • Add execution reservations for idle agents that wake up from queued trigger-turn mail.
  • Release V2 execution slots once a thread is idle and has no trigger-turn mailbox work.
  • Preserve existing V1 spawned-thread accounting.

Stack

  1. refactor: split agent control modules #26610 - Mechanical AgentControl split: extracts spawn and V1 legacy code without behavior changes.
  2. This PR - Execution slot accounting: separates logical agents from active execution slots.
  3. feat: add agent residency reload runtime #26611 - Residency and reload runtime: adds resident-agent LRU, eviction/reload, durable lookup, and V2 delivery through reload.
  4. feat: make v2 close_agent interrupt only #26612 - V2 tool semantics: narrows close_agent to interrupt-only and updates V2 tool coverage.

Copy link
Copy Markdown
Contributor

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

let mut agent_metadata = agent_metadata;
agent_metadata.agent_id = Some(resumed_thread.thread_id);
reservation.commit(agent_metadata.clone());

P2 Badge Release idle slots after resuming agents

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".

Comment thread codex-rs/core/src/agent/registry.rs
Comment thread codex-rs/core/src/agent/registry_tests.rs
Comment thread codex-rs/core/src/tasks/mod.rs Outdated
Comment thread codex-rs/core/src/tasks/lifecycle.rs
jif-oai added a commit that referenced this pull request Jun 5, 2026
## 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.
Base automatically changed from jif/agent-control-split to main June 5, 2026 14:24
@jif-oai jif-oai force-pushed the jif/agent-runtime-slots branch from 569848b to bdb868f Compare June 5, 2026 14:26
@parasol-aser
Copy link
Copy Markdown

agent/registry.rsrelease_execution_slot / reserve_spawn_slot (shared total_count)

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 Session, a rollout file handle, and possibly MCP connections. Spawn depth still bounds the tree, but nothing bounds breadth over time, and I don't see an idle-thread reaper anywhere in codex-rs/core/src (release_spawned_thread only fires on death/close). This looks like the intended design of the feature, so this is mostly a question of confirming the resource model rather than a clear bug.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants