Skip to content

[External] Copilot SDK: session.idle should not fire while sub-agents are active #537

@PureWeen

Description

@PureWeen

Problem

SessionIdleEvent fires multiple times during a turn when sub-agents (background tasks) are active. The event payload includes backgroundTasks.agents count, but the event itself semantically means 'turn is complete' — which it is not.

Impact on PolyPilot

This forces three independent workaround mechanisms:

  1. IDLE-DEFER (~60 lines) — When session.idle arrives with backgroundTasks.agents > 0, defer completion until a subsequent idle with agents=0. Must track deferred state, re-arm IsProcessing if it was cleared.

  2. IDLE-DEFER-REARM (~20 lines) — When IDLE-DEFER fires but IsProcessing was already cleared (by watchdog or race), must re-arm IsProcessing=true and restart the watchdog.

  3. DISPATCH-RECOVER (~90 lines) — Workers in multi-agent orchestration sometimes receive premature session.idle even without sub-agents. Two-phase mtime check with 2s grace period needed to detect false completions.

Desired CLI/SDK Behavior

Option A: Don't emit session.idle until all background tasks (agents + shells) have completed. Emit a separate session.background_progress event for intermediate status.

Option B: Add a separate session.complete event that ONLY fires when the turn is truly finished (no background tasks). Keep session.idle as-is but document it as 'foreground idle, not turn complete'.

Observed Frequency

During a typical PR review session with 3 sub-agents, session.idle fires 3-4 times before the turn is actually complete. Each must be inspected and deferred.

SDK Reference

GitHub.Copilot.SDK v0.2.1 — SessionIdleEvent / SessionIdleData.BackgroundTasks

Metadata

Metadata

Assignees

No one assigned

    Labels

    externalUpstream bug or dependency issue

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions