Return actionable recovery guidance when /goal continuations hit the spawn_agent thread limit
Running /goal on codex-cli 0.128.0, I hit this failure mode:
The subagent pool is already at its thread limit in this session, so I can't spawn new workers. I'll keep moving locally...
The cap itself may be fine. The rough edge is the recovery path, and /goal makes that rough edge much easier to hit. Goals are meant for longer-running work, and each continuation reuses the same session/subagent pool. If earlier completed agents are still open, a later continuation can hit the cap and simply stop delegating.
Completed subagents still occupy slots until close_agent runs. Once the cap is reached, the model-visible error does not seem to point Codex toward the obvious recovery steps, so it tends to give up on delegation and continue locally even when it may only need to close or reuse existing agents.
The failure would be much easier for the model to recover from if the spawn_agent error said something closer to:
agent thread limit reached. Completed agents still count against the limit until close_agent is called. Use list_agents to inspect existing agents, close completed or unneeded agents, or reuse an existing agent before retrying spawn_agent.
I don't think this needs automatic closing; that could break useful follow-up workflows. It just needs the limit failure to be actionable enough that long-running /goal sessions can manage their agent pool instead of silently degrading to local-only work.
This is related to #19197, but narrower. That issue is about orphaned/stuck subagents and lifecycle controls generally. This one is specifically about the new persisted /goal workflow making thread-limit recovery important during long-running continuation work.
Code paths I checked in rust-v0.128.0:
codex-rs/core/src/agent/registry.rsfor slot reservation/releasecodex-rs/core/src/agent/control.rsforclose_agent/ shutdown behaviorcodex-rs/core/src/tools/handlers/multi_agents_common.rsforcollab_spawn_errorcodex-rs/core/src/goals.rsfor/goalcontinuation behavior
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗