copilot-cli icon indicating copy to clipboard operation
copilot-cli copied to clipboard

Background sub-agent `agent_idle` notification is held for 60 s while another background task runs, even when the main agent is idle

Open ncksol opened this issue 1 week ago • 0 comments

Describe the bug

Setup: the main agent starts sub-agents with the task tool and mode: "background", often several at the same time. It then ends its turn and waits for each sub-agent's agent_idle notification before it calls read_agent for the result.

When a background sub-agent finishes while another background task is still running, the CLI holds its agent_idle notification. It releases the notification after 60 s, or when the last other background task finishes, whichever comes first. If no other background task is running, the notification arrives at once.

The CLI holds the notification even when the main agent is idle and has ended its turn to wait for the result. The result is ready, but nothing happens for a minute.

My main agent coordinates several child sessions. It runs code reviews in background sub-agents, often several at the same time. In 13 of these sessions, 98 of 239 background results reached the main agent 55 to 65 s after the sub-agent finished. Each 60 s hold happened while another background sub-agent was running. The holds added about 3 to 7 minutes of idle time per session. Often a child session also waited for the result, for example for a go-ahead to merge its PR. I also ran the same jobs as child sessions, which report by message. That setup had no gap and finished noticeably faster.

read_agent with wait: true isn't affected. It returns the result within 0.05 s.

Affected version

GitHub Copilot CLI 1.0.106. Session logs from 1.0.99-2 and 1.0.102-0 show the same delay.

Steps to reproduce the behavior

  1. In an empty folder, run:

    copilot -p 'Make exactly two task tool calls in one response, both with agent_type "task", model "claude-haiku-4.5" and mode "background": one named "slow" with the prompt "Run the shell command: sleep 150; date (use initial_wait 200). Reply with its output only.", and one named "quick" with the prompt "Run the shell command date and reply with its output only.". Then end your turn immediately. Do not call read_agent for "quick" until you receive a notification that it is idle. After that notification, call read_agent once for "quick", then wait for "slow" with read_agent wait: true and timeout 300, and reply DONE.' \
      --model claude-haiku-4.5 --allow-all-tools --log-level all --log-dir ./logs
    
  2. In the session's events.jsonl, compare the subagent.completed time for "quick" with the time of its system.notification (kind.type == "agent_idle"):

    12:01:25.669Z subagent.completed   quick
    12:02:25.743Z system.notification  quick   (60.07 s later)
    12:03:56.833Z subagent.completed   slow
    

    In 4 runs, the gap was 60.057, 60.072, 60.077 and 60.085 s. Sometimes the model calls read_agent early, even though the prompt tells it not to. Skip those runs.

  3. To compare, change the prompt so that the main agent calls read_agent for "quick" with wait: true at once. The result arrives 0.007 to 0.05 s after "quick" finishes, in 5 of 5 runs.

The debug log shows the decision to hold the notification when "quick" finishes. After that, the log shows only telemetry until the CLI releases the notification:

12:01:25.670Z [DEBUG] [rust:native_notification_delivery::implementation] Notification settlement inspected an empty executable queue {"active_immediate_completion":false,"queue_resume_requested":false,"idle_deferred":true,"has_running":true,"has_batch":true}
12:02:25.673Z [INFO] [rust:native_notification_delivery::implementation] Agent "quick" (task) has finished processing and is now idle.

Expected behavior

When the main agent is idle, the CLI should deliver a finished background sub-agent's notification at once. The main agent can then act on the result.

I understand the reason for batching. But when the main agent is idle, the hold only adds delay. Any of these changes would fix the problem for me:

  • Deliver the notification at once when the main agent is idle. Keep batching only while a turn is in progress.
  • Hold notifications for a much shorter time, such as a few seconds, to group sub-agents that finish at almost the same time.
  • Make the hold time a setting.

Today the only workaround is to make the main agent wait in read_agent with wait: true. But while it waits, it doesn't see messages from its child sessions or other notifications.

Additional context

  • OS: macOS (darwin-arm64)
  • I ran the repro headless with copilot -p. The same delay happens in interactive sessions that the GitHub Copilot app hosts.
  • I couldn't find an environment variable or setting for the 60 s hold.
  • I can share the debug logs from the repro on request.

ncksol avatar Nov 18 '26 14:11 ncksol