You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
agentHost: retain steering messages during Copilot startup - #340432
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.
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.
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]>
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]>
_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.
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]>
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]>
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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 foundduring 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.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)