Skip to content

Background agent completion retention #2595

Open

Description

@yannickwellens

Describe the bug

Completed background agents are purged from the CLI agent registry very quickly, so read_agent can
return Agent not found even after a successful completion notification.

Summary
Background agents are retrievable while running, but completed agents appear to have only a very short retention
window. In this session, the original code-review-auditor agent auth-audit showed as running for several minutes,
then later vanished entirely from list_agents, and read_agent returned Agent not found. A separate live repro showed
the same behavior with tiny probe agents, so this does not look specific to the custom reviewer.

Affected version

GitHub Copilot CLI 1.0.21.

Steps to reproduce the behavior

  1. Start a tiny background agent.
  2. Confirm it appears in list_agents while running.
  3. Wait for completion notification.
  4. Immediately call read_agent / list_agents --include_completed and observe it is briefly available.
  5. Wait a few more seconds and call them again.
  6. The completed agent disappears from list_agents, and read_agent returns no agent found.

Expected behavior

Completed background agents should remain readable/listed for a reasonable period, at least long enough for normal
follow-up after the completion notification.

Additional context

Actual
Completed agents are purged very quickly after finishing, sometimes within a few seconds of post-completion access.

Impact
Long-running background reviews can finish successfully but become unrecoverable before the user or orchestrator
reads the result, which makes background mode unreliable for required audit outputs.

Evidence from this session

  • auth-audit was started and later observed as still running.
  • Later, read_agent(auth-audit) returned Agent not found.
  • Live repro agents showed the same short-lived post-completion availability.

Current workaround

  • Use mode: "sync" when the result must be preserved before handoff.
  • If using background, read and capture the result immediately after completion.

Activity

  1. added
    area:agentsSub-agents, fleet, autopilot, plan mode, background agents, and custom agents
    and removed on Apr 16, 2026
  2. antonech commented on Jul 4, 2026

    @antonech

    Still reproducing on 1.0.68 (47 releases after the 1.0.21 report), and in my case the agent became unreachable before the foreground session ever received the completion notification — so it's not just a short post-completion retention window; the orchestrator can lose the agent entirely with no notification and no result.

    Environment

    Property Value
    Copilot CLI 1.0.68
    Node.js v20.20.0
    OS Linux 6.5.0-45-generic (Ubuntu 22.04 / Kubuntu 22), x64
    Model Claude Opus 4.8

    What I saw

    1. Launched a background agent (Task tool, mode="background", name="dff-lights-explore"). Tool returned: "Agent started in background with agent_id: dff-lights-explore. You'll be notified when it completes."
    2. ~1–8 min later list_agents() → <no background agents>.
    3. read_agent("dff-lights-explore") → Agent not found.
    4. No completion notification arrived in the foreground session; result was unrecoverable. Reproduced 3+ times the same session; re-dispatching a fresh agent worked.

    Log evidence (the tell)

    The agent did finish internally — the CLI's own log shows the completion firing — yet the foreground registry had already dropped it:

    ~/.copilot/logs/process-1783150390191-1014720.log
    2026-07-04T07:41:41.594Z [INFO] Started background agent with id: dff-lights-explore
    2026-07-04T07:46:08.238Z [INFO] System notification: Agent "dff-lights-explore" (code-explore) has finished processing and is now idle...
    

    An earlier session shows the internal callback firing too:

    ~/.copilot/logs/process-1783069781574-747979.log
    2026-07-04T03:46:24.869Z [INFO] notifySubagentComplete called for agent reviewer (...), failed=false
    

    So the completion callback runs, but the user-facing registry entry is already gone — no notification is surfaced and read_agent/list_agents can't find it.

    Hypothesis

    The parent CLI keeps the agent registry in-memory and drops the child's entry (fork/detach or premature cleanup) before the completion notification is delivered to the foreground turn. Persisting the registry across the process boundary and deferring cleanup until after the notification is surfaced (and the result read) would fix it.

    Impact / workaround

    Same as reported — background delegation is unreliable for required outputs; mode:"sync" (or reading immediately on completion) is the workaround, but here even immediate reads failed because the entry was already gone before any notification.

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