Multi-agent: spawn_agent fails with 'not found' when re-spawning after worker death

Resolved 💬 3 comments Opened Mar 14, 2026 by joeykrug Closed Mar 19, 2026

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-sandbox through an unbuffer PTY wrapper

Reproduction

  1. Start Codex with a multi-agent task that spawns 3 worker agents
  2. Workers start successfully (spawn_agent ... pending init)
  3. One worker crashes or is interrupted mid-execution
  4. 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:
``

  1. The spawn_agent call fails with not found even 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

  1. Dead worker's session slot isn't cleaned up in the internal registry, preventing new spawns
  2. max_threads limit counts dead sessions toward the cap
  3. The not found error may relate to something other than the session (file/tool reference from dead worker's context)

Additional Context

  • Initial spawn_agent calls 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_input to communicate with live workers before the crash
  • Running through unbuffer PTY (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:

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗