Skip to content

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

Open

Description

@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:

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

  1. added
    bugSomething isn't working
    agentIssues related to the core agent loop
    on Mar 31, 2026
  2. added
    subagentIssues involving subagents or multi-agent features
    and removed
    agentIssues related to the core agent loop
    on Apr 11, 2026
  3. Keesan12 commented on May 18, 2026

    @Keesan12

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingsubagentIssues involving subagents or multi-agent features

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions