Repository navigation
CLI: after compaction, Codex may keep saying "Agent spawn failed" even though earlier subagents already finished #16328
Description
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?
- Start a Codex CLI session.
- Work on a task that causes Codex to spawn many subagents, for example enough to reach the configured subagent limit.
- Let those subagents finish their work.
- Manually compact the session, or wait for auto-compaction.
- Continue the same task in the same terminal session.
- Let Codex try to spawn more subagents.
- Notice that it may repeatedly show
Agent spawn failed. - In Terminal.app, press
Command+Tto open a new tab. - In that new tab, go to the same repository and either start Codex again or resume the previous conversation.
- Try the same kind of task again.
- 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:
- bug: Collab subagents leak spawn slots, lack cascading cancellation, and wait is wait-any #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.
Activity
github-actions commentedon Mar 31, 2026
Potential duplicates detected. Please review them and close your issue if it is a duplicate.
Powered by Codex Action
Keesan12 commentedon May 18, 2026
This reads like a slot-lifecycle bug more than a spawn bug. If finished children keep counting after compaction, the system needs an explicit terminal release step that survives compaction and a visible distinction between inished,
eleased, and
estorable. Otherwise the parent cannot tell whether the slot is still reserved for a useful reason or just leaked state. We have been hitting the same shape in MartinLoop when wrapping long-running agent trees. A compacted run summary really needs to carry live-child count, releasable-child count, and root budget state forward.