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:
-
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.
-
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.
-
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
Problem
SessionIdleEventfires multiple times during a turn when sub-agents (background tasks) are active. The event payload includesbackgroundTasks.agentscount, but the event itself semantically means 'turn is complete' — which it is not.Impact on PolyPilot
This forces three independent workaround mechanisms:
IDLE-DEFER (~60 lines) — When
session.idlearrives withbackgroundTasks.agents > 0, defer completion until a subsequent idle with agents=0. Must track deferred state, re-arm IsProcessing if it was cleared.IDLE-DEFER-REARM (~20 lines) — When IDLE-DEFER fires but
IsProcessingwas already cleared (by watchdog or race), must re-armIsProcessing=trueand restart the watchdog.DISPATCH-RECOVER (~90 lines) — Workers in multi-agent orchestration sometimes receive premature
session.idleeven 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.idleuntil all background tasks (agents + shells) have completed. Emit a separatesession.background_progressevent for intermediate status.Option B: Add a separate
session.completeevent that ONLY fires when the turn is truly finished (no background tasks). Keepsession.idleas-is but document it as 'foreground idle, not turn complete'.Observed Frequency
During a typical PR review session with 3 sub-agents,
session.idlefires 3-4 times before the turn is actually complete. Each must be inspected and deferred.SDK Reference
GitHub.Copilot.SDKv0.2.1 —SessionIdleEvent/SessionIdleData.BackgroundTasks