Skip to content

Autopilot repeatedly retries write_agent for completed non-resumable agent with conflicting selectors #5210

Open
github/docs
#46389

Description

@jessesanford

Describe the bug

When a background agent has completed as blocked and is non-resumable, the coordinator can repeatedly call write_agent instead of replacing it. In the observed failure, the model also supplied all three mutually exclusive selectors (agent_id, agent_ids, and scope) on every retry, so each call failed schema validation before the runtime could report the target agent's terminal lifecycle state.

The result was a long Autopilot loop displaying repeated Write <agent-id> calls with no recovery.

Observed sequence:

  1. A background general-purpose agent was launched successfully.

  2. The agent completed with a blocked result because it started from the wrong working directory. Its launch metadata reported resumable: false.

  3. The coordinator attempted to steer/resume the completed agent repeatedly.

  4. Every generated write_agent call contained all three selectors:

    {
      "agent_id": "<agent-id>",
      "agent_ids": ["<agent-id>"],
      "scope": "children",
      "message": "Resume..."
    }
  5. The tool returned:

    Provide exactly one of "agent_id", "agent_ids", or "scope"
    
  6. Autopilot retried the same malformed operation many times instead of inspecting lifecycle state and starting a replacement.

The old agent had no durable resumable session. Starting a fresh agent with the original objective, preserved worktree, and absolute project root recovered the work.

Affected version

1.0.100

Steps to reproduce the behavior

  1. Start a background agent with mode: "background".
  2. Have the agent finish with a blocked result and a terminal/non-resumable lifecycle state.
  3. Ask the main agent to resume or steer that completed agent.
  4. Observe the main model call write_agent repeatedly.
  5. In the failing case, inspect the tool calls and observe that agent_id, agent_ids, and scope are all populated.
  6. Observe every call fail with Provide exactly one of "agent_id", "agent_ids", or "scope".
  7. Observe Autopilot continue retrying the dead agent instead of launching a replacement.

Expected behavior

The tool and orchestrator should defend against both failure modes:

  1. The generated write_agent call should contain exactly one selector.

  2. When the target is completed, failed, cancelled, missing, or non-resumable, the tool should return a structured actionable result, for example:

    agent_not_resumable:
    Agent <id> is completed/blocked and cannot accept messages.
    Do not retry write_agent. Start a new task agent using the original objective and preserved context.
    
  3. Autopilot should treat that response as terminal for the old agent ID and automatically start a fresh replacement with the original objective and durable context.

  4. After an invalid-selector response, the coordinator should retry at most once with only agent_id, not loop indefinitely.

Additional context

  • OS: macOS, arm64
  • Interface: interactive TUI, Autopilot
  • Agent: background general-purpose agent
  • Model: gpt-6.1-sol, accessed through a custom OpenAI-compatible gateway
  • API subtype: OpenAI Responses (/v1/responses)
  • The replacement-agent workaround was successful when explicitly given the original objective, absolute worktree/project root, approved plan, constraints, and known progress.

Related open issues:

Those issues cover adjacent delivery, status, and retention failures, but I could not find one covering the exact combination of malformed selector retries plus failure to replace a terminal/non-resumable agent.

Suggested lifecycle handling:

  • Permit write_agent only for agents currently reported as running or idle.
  • Reject terminal/non-resumable agents with a dedicated error code and replacement guidance.
  • Persist enough final metadata/result for the coordinator to seed a replacement safely.
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

    area:agentsSub-agents, fleet, autopilot, plan mode, background agents, and custom agents

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions