Skip to content

Copilot ACP background agents are cancelled or lost across turns #121

Description

@cxxxxxn

Summary

When GitHub Copilot CLI is used as an external ACP agent, its background-agent tools report that an agent was started successfully and return an agent_id. However, attempts to retrieve that agent from a later Huabu turn fail consistently:

  • read_agent returns Cancelled shortly after the parent ACP turn ends.
  • read_agent returns Agent not found after the ACP session has been idle and its underlying process has been suspended or recreated.

Huabu persists the outer chat thread and ACP session state, but Copilot CLI background-agent handles appear to be process- or turn-local and are not recoverable across those lifecycle boundaries.

Reproduction A: parent turn ends

  1. Configure GitHub Copilot CLI as an external ACP Agent.
  2. Ask it to start one or more background research agents.
  3. Observe successful tool results such as:
   Agent started in background with agent_id: <id>. You will be notified when it completes.  
  1. Allow the parent ACP turn to finish.
  2. In the next turn, call read_agent with the returned ID.

Actual result

status: failed
message: Cancelled

In one observed run, five agents were created successfully. The parent turn emitted done about 50 seconds later. Reading all five IDs approximately five minutes after creation returned Cancelled immediately.

Reproduction B: idle suspension or process recreation

  1. Start background agents and retain their IDs.
  2. Call read_agent(wait=true, timeout=180) in the same active session.
  3. Observe successful results reporting status: running.
  4. Leave the external ACP session idle long enough for suspension, then send a new prompt so Huabu resumes or recreates the underlying ACP process.
  5. Call read_agent with the same IDs.

Actual result

status: failed
message: Agent not found

In one observed run, all five IDs were readable as running, but all five returned Agent not found after the session had been idle overnight.

Expected behavior

One of the following contracts should be explicit and reliable:

  1. Background agents survive the end of the parent prompt and remain addressable from later turns in the same durable ACP session; or
  2. Background agents are explicitly documented and surfaced as turn-scoped, and the tool must not instruct the model to end its response and wait for a later completion notification; or
  3. Huabu receives a structured ACP task resource with lifecycle and recovery metadata, allowing it to persist or reconnect to the task.

At minimum, the UI/tool result should distinguish a task cancelled with its parent turn from a task lost because the ACP process was replaced.

Analysis

The observed lifecycle appears to be:

Huabu durable chat thread\n  
-> recoverable ACP session
-> Copilot CLI process
-> process-local background-agent registry

Huabu receives the background-agent creation and read_agent calls only as ordinary ACP tool events. The agent_id is embedded in tool output; ACP does not currently expose it as a durable task resource. Huabu can therefore restore the outer thread/session without restoring Copilot CLI internal background-agent state.

This is adjacent to #38 and #84, but neither tracks background/sub-agent handles becoming Cancelled or Agent not found across turn/session recovery boundaries.

Suggested investigation

  • Confirm whether Copilot CLI background agents inherit the parent session/prompt abort signal.
  • Confirm whether their registry is scoped to one prompt, one ACP session, or one CLI process.
  • Define behavior when Huabu idle-suspends and later repairs an ACP session.
    • Consider persisting background-task metadata or exposing a structured ACP task lifecycle.
  • Until recovery is supported, adjust the Copilot tool guidance so it does not promise later notification/readback after the parent turn ends

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions