microsoft / microsoft/vscode

Audit Copilot SDK events with agentId for subagent-safe handling

Open
#326,710 0 comments 0 reactions 1 assignee Claimed by @roblourens View on GitHub
agent-host bug
Dominant language
TypeScript
Stars
193k
Forks
42.4k
PR merge metrics
PR metrics pending

Description

## Context

Copilot SDK session event envelopes can carry an optional `agentId` when emitted for a subagent. We hardened `user.message` handling so subagent messages do not mutate root steering/event-ID state or emit root-only instruction telemetry, and replay restores them in the subagent transcript.

The SDK exposes `agentId` across its event union. Audit the remaining Agent Host consumers for root-only assumptions and either route, ignore, or explicitly document each subagent event.

## Events to review

Highest-risk state-mutating consumers:

- `system.notification`: currently creates or appends root turns in live handling and replay.
- `session.idle`: currently completes or aborts the root turn.
- `session.error`: currently emits a root chat error.
- `session.auto_mode_resolved`: currently updates root model and usage state.
- `assistant.intent`: currently updates root session activity.
- `session.model_change`: currently affects root replay model selection.
- `assistant.usage`: an unmapped subagent event can currently fall back to root usage.
- MCP server, tool, and command inventory events: currently treated as session-global; verify whether subagent-scoped variants should be ignored or projected globally.

Logging-only and memo-invalidation listeners do not need guards unless their behavior gains stateful side effects.

## Acceptance criteria

- Classify every consumed SDK event that may carry `agentId` as session-global, root-only, or subagent-routed.
- Add explicit guards or routing for root-only and subagent-scoped behavior.
- Drop and warn for unmapped subagent events where ordering/correlation is required.
- Keep live handling and persisted-history replay behavior consistent.
- Add focused regression tests for each state-mutating path changed.

(Written by Copilot)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.