Skip to content

Plan Mode should allow safe cleanup of completed subagents #24508

Open

Description

@tiziano-contorno

Summary

Plan Mode instructions can cause the model to avoid close_agent because it appears to be a mutating action, even when the target subagents are already completed and cleanup is only session resource hygiene.

This is not a report that close_agent is unavailable in Plan Mode. In the observed case, the tool was available and later worked. The problem is that the Plan Mode policy text can lead the assistant to classify completed-subagent cleanup as forbidden mutation, blocking the safe recovery path for agent thread limit reached.

Current behavior

In Plan Mode:

  1. The user asks for broad read-only planning/research.
  2. The assistant uses subagents appropriately for read-only sidecar review.
  3. The subagents complete.
  4. Later, more sidecars would be useful.
  5. spawn_agent fails or is expected to fail because completed subagents still occupy thread slots.
  6. The safe recovery is close_agent on completed agents.
  7. The assistant may refuse or defer that cleanup because Plan Mode says not to perform mutating actions.

In the observed session, close_agent was not platform-blocked. The assistant self-blocked due to a conservative interpretation of Plan Mode.

Expected behavior

Plan Mode should explicitly allow safe session lifecycle cleanup that does not modify source, git state, files, runtime product config, permissions, or external systems.

Examples of allowed Plan Mode hygiene should include:

  • closing completed subagents after their results have been captured
  • closing failed/canceled/stale sidecars when they are no longer useful
  • freeing subagent slots before further read-only planning work
  • cleaning up retained sidecar state when the user explicitly asks

This should be framed as session resource management, not implementation mutation.

Non-goals

This is not asking Plan Mode to allow:

  • editing source files
  • staging/committing/pushing
  • materializing runtime configs
  • changing workspace state
  • terminating active useful sidecars merely for impatience
  • deleting evidence before results are captured

Suggested instruction refinement

Add something like:

In Plan Mode, closing completed, failed, canceled, or genuinely stale sidecars to free capacity is allowed session hygiene, provided their useful results have been captured and no source, git, workspace, runtime product, credential, permission, or external state is changed.

Why it matters

Long planning sessions often rely on read-only sidecars. If completed sidecars cannot be cleaned up, the thread can hit agent thread limit reached, after which the assistant either stops using sidecars or asks the user to leave Plan Mode solely to perform cleanup.

That creates a false conflict: the planning work should remain read-only, but the session needs basic lifecycle hygiene.

Related issues

Activity

  1. added
    enhancementNew feature or request
    subagentIssues involving subagents or multi-agent features
    planIssues involving plan mode
    sessionIssues involving session (thread) management, resuming, forking, naming, archiving
    on May 26, 2026
  2. github-actions commented on May 26, 2026

    @github-actions
    Contributor

    Potential duplicates detected. Please review them and close your issue if it is a duplicate.

    Powered by Codex Action

  3. omarpinarecords commented on May 26, 2026

    @omarpinarecords

    Related public chain: #23930 tracks stale/unclosable subagent UI after close/readback reports no live agent, and #23971 tracks a close/wrap-up failure that surfaced as agent loop died unexpectedly plus repeated message-submit failures.

    This enhancement looks complementary because it separates completed/failed/stale sidecar cleanup from source/workspace mutation. That distinction matters for recovering subagent slots without leaving Plan Mode solely to run lifecycle hygiene. Keeping the canonical bug reports open pending maintainer direction or upstream fix.

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 requestplanIssues involving plan modesessionIssues involving session (thread) management, resuming, forking, naming, archivingsubagentIssues 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