Skip to content

Reap stale multi-agent slots#24903

Merged
jif-oai merged 6 commits into
mainfrom
jif/reap-stale-agent-slots
May 28, 2026
Merged

Reap stale multi-agent slots#24903
jif-oai merged 6 commits into
mainfrom
jif/reap-stale-agent-slots

Conversation

@jif-oai
Copy link
Copy Markdown
Collaborator

@jif-oai jif-oai commented May 28, 2026

Summary

  • Let close_agent clean up an agent that is still registered in AgentRegistry even when its underlying thread is already missing.
  • Preserve the explicit-close boundary: for known stale thread-spawn agents, mark the persisted spawn edge Closed, then treat ThreadNotFound / InternalAgentDied as a successful close so the registry slot can be released.
  • Add a regression for MultiAgentV2 task-name targets where close_agent("worker") succeeds after the worker thread has already disappeared.

Motivation

A worker can disappear from ThreadManager while its metadata still exists in the root AgentRegistry. Before this change, the close tool failed while trying to subscribe to the missing thread status, so it never reached the cleanup path that releases the registered agent slot. With agents.max_threads = 1, an explicit close of that stale task-name agent could fail and leave the session unable to spawn a replacement.

Scope

This PR intentionally does not add automatic stale-agent reaping to spawn_agent, resume_agent, or list_agents. A thread being missing from ThreadManager is not the same as an explicit close: persisted open spawn edges are still the durable source of truth for resume and task-name ownership until close_agent is called.

Validation

  • just test -p codex-core -E 'test(multi_agent_v2_close_agent_reaps_stale_task_name_target) | test(resume_agent_from_rollout_reopens_open_descendants_after_manager_shutdown)'
  • just fix -p codex-core

@jif-oai jif-oai marked this pull request as ready for review May 28, 2026 11:42
@jif-oai jif-oai requested a review from a team as a code owner May 28, 2026 11:42
@jif-oai jif-oai changed the title [codex] Reap stale multi-agent slots Reap stale multi-agent slots May 28, 2026
@jif-oai
Copy link
Copy Markdown
Collaborator Author

jif-oai commented May 28, 2026

@codex review

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

Here are some automated review suggestions for this pull request.

Reviewed commit: 9a8026d1ff

ℹ️ 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/control.rs Outdated
Comment thread codex-rs/core/src/tools/handlers/multi_agents_v2/close_agent.rs
Comment thread codex-rs/core/src/agent/control_tests.rs Outdated
@jif-oai jif-oai force-pushed the jif/reap-stale-agent-slots branch from 9a8026d to d881246 Compare May 28, 2026 14:08
@jif-oai jif-oai merged commit e2551a5 into main May 28, 2026
31 checks passed
@jif-oai jif-oai deleted the jif/reap-stale-agent-slots branch May 28, 2026 16:48
@github-actions github-actions Bot locked and limited conversation to collaborators May 28, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants