Skip to content

Main agent needs subagent capacity/status preflight before spawn_agent attempts #23479

Open

Description

@0xZoharHuang

Summary

The main agent needs a reliable subagent capacity/status preflight before deciding to call spawn_agent.

Today, the agent can decide that delegation would be useful, attempt to spawn a subagent, hit a thread limit or stale subagent state, and then degrade into not using subagents at all. The failure mode is especially painful in long engineering sessions where subagents are needed for read-only exploration and parallel investigation.

Current behavior

From the user's perspective, the parent agent may not have a clear way to know:

  • how many subagent slots are currently available
  • whether completed subagents are still retained and counting against a limit
  • whether any subagents are running, waiting, completed, or failed
  • whether the last spawn failed because of thread limit, quota, provider failure, MCP startup, or another cause
  • whether closing completed agents would free capacity
  • whether retrying, waiting, reusing, or not delegating is the right next action

When spawn_agent fails, the parent agent may treat the failure as a generic inability to delegate and continue locally, instead of recovering or explaining the precise cause.

Expected behavior

Before or as part of spawn_agent, Codex should expose a compact capacity/status preflight to the main agent.

The exact API shape is flexible, but the agent needs information like:

subagent capacity: 0/6 slots available
active: 2 running, 0 waiting
retained completed: 4
recent spawn failure: thread limit reached
recommended recovery: close completed agents, then retry

The important behavior is:

  1. The parent agent can see whether spawning is likely to succeed.
  2. If spawning cannot succeed, the agent gets an explicit reason.
  3. If there is a safe recovery path, the agent can take it or ask the user.
  4. The agent should not silently abandon delegation just because one blind spawn attempt failed.

Why this matters

For large codebases, subagents are not just a convenience. They are how the parent keeps context clean while parallel read-only investigation happens in bounded lanes.

When a long-running session reaches subagent capacity, the current experience can turn into:

need research -> try spawn -> spawn failed -> stop using subagents -> parent context bloats

A preflight/status surface would let the parent agent recover intentionally:

need research -> inspect capacity -> close completed / wait / retry / explain -> continue delegation

Related issues

This overlaps with several existing subagent lifecycle issues, but the focus here is narrower: parent-agent preflight before delegation.

Related:

Those issues cover specific lifecycle or UI failures. This issue asks for a model-visible/runtime-visible preflight so the parent agent can make a good delegation decision before attempting spawn_agent.

Activity

  1. added
    enhancementNew feature or request
    subagentIssues involving subagents or multi-agent features
    on May 19, 2026
  2. github-actions commented on May 19, 2026

    @github-actions
    Contributor
  3. Juanma-Voltti commented on May 25, 2026

    @Juanma-Voltti

    Adding fresh operational evidence from Codex CLI 0.133.0, linked from internal tracking issue https://github.com/Juanma-Voltti/dev-tools/issues/6679.

    In a long-running repo-governed workflow, bounded explorer fan-out was appropriate and authorized by repo/skill instructions, but a spawn attempt failed with agent thread limit reached while completed descendants were still retained. The only successful recovery was manual: close completed agents with close_agent, then retry the bounded explorer spawn.

    That matches this issue's preflight ask exactly. The parent needs a model-visible admission/status surface before calling spawn_agent, or at minimum a thread-limit failure payload that says:

    • current running/waiting/completed descendant counts
    • whether completed descendants are still occupying slots
    • which completed descendants can safely be closed
    • whether close_agent will free capacity
    • recommended next action: close/wait/retry/do not delegate

    Today the failure is too terse for a parent agent to recover reliably. It can easily degrade into doing parallel investigation serially in the main thread, which is exactly the context-bloat failure this issue describes.

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

    enhancementNew feature or requestsubagentIssues 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