Skip to content

agentHost: retain steering messages during Copilot startup - #340432

Merged
roblourens merged 5 commits into
mainfrom
roblou/agents/steering-message-blocked-fix
Oct 8, 2026
Merged

roblourens merged 5 commits into
mainfrom
roblou/agents/steering-message-blocked-fix

Conversation

@roblourens

@roblourens roblourens commented Oct 8, 2026 •

Copy link
Copy Markdown
Member

Summary

Fix steering messages getting stuck when submitted while the Copilot SDK session is starting or being replaced during configuration refresh/MCP startup. The host previously looked up only the live SDK session, logged chat not found during the replacement gap, and dropped delivery while leaving the message pending in the client.

Buffer the latest steering message and sender per addressed chat during preparation. Root SDK user-message and turn-start events release the buffer as soon as a dispatched turn is running, even while the original send/continuation admission RPC is unresolved. New mid-turn steering dispatches immediately. Successful admission also releases the buffer; there is no separate steering operation queue. Failed preparation/send retains buffered steering for a successful retry. Replacements (including same-ID edits), removal, Stop, chat disposal, and shutdown update or clear the buffer.

The live SDK-session wrapper takes ownership synchronously before awaiting MCP reconciliation. Abort and disposal can clear steering throughout the handoff; gated tests verify that each clears the pending message exactly once without dispatching it afterward.

Pending-message updates are rejected once host shutdown starts, including while live SDK sessions are still disconnecting.

Independent subagent reviews, including Opus, led to simplification and regression coverage for failed sends, history-only working-directory guards, replacement after failure, same-ID edits, and root SDK events arriving before the admission response. The final Opus review found no significant issues in the readiness callback fix. No SDK/runtime changes are required. This follows a locally reported reproduction; no separate issue has been filed.

Validation

  • npm run build-fast -- --client-only — passed.
  • env -u COPILOT_HOME ./scripts/test.sh --run src/vs/platform/agentHost/test/node/copilotAgent.test.ts --run src/vs/platform/agentHost/test/node/copilotAgentSession.test.ts --grep 'MCP configuration preparation|steering|Steering|prepareTurn|Stop releases a preparation' --reporter dot — passed, 68 focused tests.
  • env -u COPILOT_HOME ./scripts/test.sh --run src/vs/platform/agentHost/test/node/copilotAgent.test.ts --run src/vs/platform/agentHost/test/node/copilotAgentSession.test.ts --reporter dot — passed, 1,514 tests and 1 pending. Unsetting the inherited override lets filesystem fixtures control their own home.
  • env -u COPILOT_HOME ./scripts/test-integration.sh --run src/vs/platform/agentHost/test/node/e2e/providers/copilotAgentHostE2E.integrationTest.ts --grep 'request error survives a host restart|resumes the same turn after repeated failures' — passed, 2 existing E2E scenarios in strict replay.
  • npm run eslint -- src/vs/platform/agentHost/node/copilot/copilotAgent.ts src/vs/platform/agentHost/test/node/copilotAgent.test.ts — passed.
  • npm run typecheck-client — passed.
  • git diff --check — passed.
  • Commit hygiene hook — passed.

Focused tests cover initial creation, ahead-of-send preparation, disconnect/resume, continuation, duplicates, removal/replacement/Stop, cancelled predecessor ordering, failed preparation/send retries, the working-directory guard, and abort/disposal during MCP reconciliation. The active-turn matrix verifies steering arriving before and after readiness, while normal sends and continuations have unresolved or resolved admission responses; the original turn remains active and no idle event is needed. It also checks identical original/steering text does not falsely consume the original echo. The shutdown test verifies no extra SDK send while disconnect is blocked or after shutdown completes; it failed before the shutdown guard. No live-CAPI recording was performed.

(Written by Copilot)

Buffer steering for the addressed chat while its SDK session is being prepared or refreshed. Deliver it only after a successful send or continuation, preserving replacement edits and cancellation without a second operation queue.

Co-authored-by: Copilot <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 8, 2026 04:28
@github-actions

github-actions Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Base: e37f29d5 Current: 0e2899ca

No screenshot changes.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Steering ownership and disposal races can still dispatch or strand pending messages.

1 open finding
What changed in this PR

Buffers Copilot steering messages during SDK session preparation and refresh to prevent dropped delivery.

Changes:

  • Buffers, replaces, delivers, and clears steering messages across lifecycle events.
  • Adds regression tests for startup, retries, replacement, abort, and working-directory guards.
  • Documents steering buffering behavior.
File Description
src/​vs/​platform/​agentHost/​node/​copilot/​copilotAgent.ts Implements steering buffering and lifecycle cleanup.
src/​vs/​platform/​agentHost/​test/​node/​copilotAgent.test.ts Adds focused steering regression tests.
src/​vs/​platform/​agentHost/​AGENTS.md Documents buffering semantics.

🧠 Review effort: Balanced


Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.

Register pending steering in the live SDK-session wrapper before awaiting MCP reconciliation, so abort and disposal can always clear the pending message. Cover both cleanup races with gated regression tests.

Co-authored-by: Copilot <[email protected]>
Preserve upstream continuation-stage diagnostics alongside buffered steering delivery.

Co-authored-by: Copilot <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The preparation check also covers active SDK sends, delaying normal mid-turn steering until the original send resolves.

1 open finding
Previously missed (1)

In code that hasn't changed since last review

Medium severity Pending turn blocks steering during long SDK sends

src/​vs/​platform/​agentHost/​node/​copilot/​copilotAgent.ts:5112

_pendingChatTurns remains populated for the entire queued operation, including while entry.send() is awaiting the SDK call after the original prompt has already been dispatched. Treating that as “preparing” therefore buffers ordinary mid-turn steering until entry.send() resolves, so a long-running SDK send can no longer be interrupted by steering—the behavior this hook previously provided. Please track the replacement/startup gap separately (or clear the preparation marker once the original SDK call is dispatched) so steering against an already-running current runtime is delivered immediately while only the unsafe gap is buffered.

🧠 Review effort: Balanced


Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.

@roblourens
roblourens marked this pull request as ready for review October 8, 2026 16:48
@roblourens
roblourens enabled auto-merge (squash) October 8, 2026 16:48
@roblourens
roblourens marked this pull request as draft October 8, 2026 16:49
auto-merge was automatically disabled October 8, 2026 16:49

Pull request was converted to draft

Flush buffered steering when root SDK events confirm a dispatched turn is running, without waiting for the admission RPC response. Keep preflight, failed-send, exact-instance and cancellation guards. Cover sends and continuations with steering arriving before and after readiness and admission settlement.

Co-authored-by: Copilot <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Concurrent shutdown or chat disposal can repopulate or dispatch steering after cleanup begins.

1 open finding
1 resolved since last review

🧠 Review effort: Balanced

Ignore pending-message updates once shutdown starts, preventing new buffered or dispatched steering while live SDK sessions are still disconnecting. Cover the live disconnect window and updates after shutdown.

Co-authored-by: Copilot <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Follow-up steering can remain buffered on promoted turns, and failed asynchronous steering delivery can discard its only retryable copy.

0 open findings

1 resolved since last review
Previously missed (2)

In code that hasn't changed since last review

Medium severity Preserve buffered steering messages until delivery succeeds

src/​vs/​platform/​agentHost/​node/​copilot/​copilotAgent.ts:5134

Do not discard the only buffered copy before sendSteering succeeds. sendSteering can fail during MCP reconciliation, attachment conversion, or the SDK send and currently catches the error, but this line has already removed the entry. Because the protocol state remains unchanged, no new setPendingMessages call is guaranteed, so later successful turn admission cannot retry it and the steering bubble remains stuck. Keep delivery ownership until success, or return a result that lets this layer restore the pending entry on failure.

Medium severity Mark promoted steering turns as SDK-dispatched

src/​vs/​platform/​agentHost/​node/​copilot/​copilotAgentSession.ts:1157

A promoted steering turn is explicitly marked running in _beginSteeringTurn, but that fresh CopilotTurn never sets sdkSendInvoked. As a result, after the first steering echo promotes the turn, a second steering message arriving while the original send/continuation admission is still pending sees hasRunningTurn === false and remains buffered until that admission resolves—often after the active turn has ended. Treat promoted steering turns as SDK-dispatched/running so subsequent mid-turn steering is delivered immediately.

🧠 Review effort: Balanced

@roblourens
roblourens marked this pull request as ready for review October 8, 2026 21:49
@roblourens
roblourens enabled auto-merge (squash) October 8, 2026 21:49
@roblourens
roblourens merged commit 4bd93ff into main Oct 8, 2026
36 checks passed
@roblourens
roblourens deleted the roblou/agents/steering-message-blocked-fix branch October 8, 2026 22:07
@vs-code-engineering vs-code-engineering Bot added this to the 1.142.0 milestone Oct 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants