CLI: after compaction, Codex may keep saying "Agent spawn failed" even though earlier subagents already finished

Open 💬 2 comments Opened Mar 31, 2026 by Boulea7

What version of Codex CLI is running?

codex-cli 0.117.0

What subscription do you have?

Pro

Which model were you using?

gpt-5.4

What platform is your computer?

Darwin 25.4.0 arm64 arm (MacBook Pro, M2 Pro, Apple Silicon)

What terminal emulator and version are you using (if applicable)?

Terminal.app (Apple_Terminal), no multiplexer

What issue are you seeing?

I noticed a frustrating issue when using subagents in Codex CLI.

If a session uses many subagents and reaches the configured limit, that part is expected. The problem starts after the session is manually compacted or auto-compacted.

In the same terminal session, when I continue working and Codex wants to spawn more subagents, it can get stuck repeatedly showing Agent spawn failed, even though the earlier subagents have already finished their work.

What makes this especially confusing is that I can avoid the problem by starting Codex again from a new Terminal tab in the same directory.

For example, if I press Command+T in Terminal.app, open a new tab, stay in the same repo, and then either:

  • start Codex again and continue the work, or
  • resume the previous conversation,

then spawning subagents works normally again.

So it feels like the finished subagents may still be counted in the current compacted session, even though they are already done, while a newly started terminal tab/session does not have the same problem.

This creates an awkward workflow because I have to manually tell the model to close old completed subagents before it can continue. It feels like Codex should be able to handle this automatically.

What steps can reproduce the bug?

  1. Start a Codex CLI session.
  2. Work on a task that causes Codex to spawn many subagents, for example enough to reach the configured subagent limit.
  3. Let those subagents finish their work.
  4. Manually compact the session, or wait for auto-compaction.
  5. Continue the same task in the same terminal session.
  6. Let Codex try to spawn more subagents.
  7. Notice that it may repeatedly show Agent spawn failed.
  8. In Terminal.app, press Command+T to open a new tab.
  9. In that new tab, go to the same repository and either start Codex again or resume the previous conversation.
  10. Try the same kind of task again.
  11. Notice that subagent spawning works normally there and the spawn failure does not happen.

What is the expected behavior?

Once subagents have finished, they should stop counting against the spawn limit.

After compaction, Codex should ideally clean this up automatically so the user does not need to manually ask it to close already-finished subagents before continuing.

Additional information

I searched for similar issues and found this related one:

  • #13947: bug: Collab subagents leak spawn slots, lack cascading cancellation, and wait is wait-any

My report may be related, but the main user-facing behavior I am seeing is:

  • same terminal session after compaction: repeated Agent spawn failed
  • new Terminal tab in the same directory, or resumed conversation from there: subagent spawning works normally again

A simple improvement would be to automatically release or close finished subagents, and only restore them later if they are actually needed again.

View original on GitHub ↗

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