Multi-agent: spawn_agent fails with 'not found' when re-spawning after worker death
Bug
When using Codex CLI multi-agent ([features] multi_agent = true), if a spawned worker agent dies mid-run, the coordinator's attempt to spawn_agent a replacement fails with not found.
Environment
- Codex CLI version: latest (March 2026)
- Config:
multi_agent = true,max_threads = 8,max_depth = 2 - Running via:
codex exec --dangerously-bypass-approvals-and-sandboxthrough anunbufferPTY wrapper
Reproduction
- Start Codex with a multi-agent task that spawns 3 worker agents
- Workers start successfully (
spawn_agent ... pending init) - One worker crashes or is interrupted mid-execution
- Coordinator detects the dead worker and attempts to spawn a replacement:
````
spawn_agent(call_B5FBNHPxBfpcYsN4hHnR5qLn, prompt="You are taking over PR #46303 from an interrupted worker...") not found:
- The
spawn_agentcall fails withnot foundeven though it should create a fresh agent with a new session ID
Expected Behavior
spawn_agent should always be able to create a new agent session, even when a previous worker has died. The dead worker's session ID should not prevent new spawns.
Actual Behavior
spawn_agent returns not found when attempting to create a replacement worker after another worker has died. This appears to crash the coordinator thread — the entire Codex process exits without writing its normal result JSON, suggesting an unhandled error path.
Possible Causes
- Dead worker's session slot isn't cleaned up in the internal registry, preventing new spawns
max_threadslimit counts dead sessions toward the cap- The
not founderror may relate to something other than the session (file/tool reference from dead worker's context)
Additional Context
- Initial
spawn_agentcalls succeed — the feature works for the first spawn - A broken skill file (
missing field description) logged ERROR on each spawn but didn't prevent initial spawns from succeeding - The coordinator was able to use
send_inputto communicate with live workers before the crash - Running through
unbufferPTY (needed for Codex to produce output in non-interactive mode)
Logs
[collab] spawn_agent(call_whV7OWzXK2Rc4l3mfV3kFFXW, prompt="You own PR #46303...") pending init:
agent: 019cee4d-f3b0-72c1-aab3-0782d817756f
[collab] spawn_agent(call_DdKH6eHKZataSda6gpD9QRMF, prompt="You own PR #46417...") pending init:
agent: 019cee4d-f438-7132-9029-5e2b90f955d2
[collab] spawn_agent(call_cwRO0EdzlkNKIf1flbbX4Aqn, prompt="You own PR #46454...") pending init:
...
[later, after worker death]
spawn_agent(call_B5FBNHPxBfpcYsN4hHnR5qLn, prompt="You are taking over PR #46303 from an interrupted worker...") not found:This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗