Repository navigation
agentHost: fix orphaned client tool calls after window reload - #320672
Merged
Merged
Conversation
- A window reload reconnects with a new clientId but an identical tool list. The cached SDK session was reused with the dead window's clientId baked in, so every later client tool call was stamped with that dead id, routed to passive render, and hung forever with nobody to invoke it. - Introduces a live, shared ActiveClientState so the owning clientId is read at tool-call stamp time instead of being frozen at session creation, and makes the staleness check restart only on structural tool/plugin changes — a clientId-only change no longer needlessly restarts (Copilot) or yield-rebinds (Claude) the session. - Adds a server-side safety net so a client tool call stamped for a client that is not connected (including one that disconnected before the call was even issued) fails after a grace window rather than hanging, with the grace measured from when that client was last seen. - Lets a completion that races ahead of the SDK tool handler resolve via a buffered result, preserving the previous out-of-order tolerance. Fixes #319641 (Commit message generated by Copilot)
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes client-contributed tool calls hanging after window reloads by decoupling tool-call stamping from a session’s creation-time clientId, adding server-side orphan detection/timeouts, and improving tolerance for out-of-order tool completions.
Changes:
- Introduces
ActiveClientStateto track the owningclientIdlive and limits “session restart needed” checks to structural tool/plugin changes. - Adds server-side orphan detection for client tool calls and completes them after a disconnect grace period (instead of hanging forever).
- Extends
PendingRequestRegistrywithrespondOrBufferto handle completions that arrive before the awaiting handler registers.
Show a summary per file
| File | Description |
|---|---|
| src/vs/platform/agentHost/node/activeClientState.ts | New shared live state for clientId + structural tool snapshot comparisons. |
| src/vs/platform/agentHost/node/copilot/copilotAgent.ts | Uses ActiveClientState and updates staleness logic to ignore clientId-only changes. |
| src/vs/platform/agentHost/node/copilot/copilotAgentSession.ts | Stamps client tool calls using live clientId; buffers early completions via PendingRequestRegistry. |
| src/vs/platform/agentHost/node/copilot/copilotSessionLauncher.ts | Removes clientId from IActiveClientSnapshot; adds activeClientState to launch plan. |
| src/vs/platform/agentHost/node/claude/clientTools/claudeSessionClientToolsModel.ts | Dirty tracking now flips only on structural tool changes (not clientId-only reload changes). |
| src/vs/platform/agentHost/node/protocolServerHandler.ts | Tracks disconnected client records, arms orphan timeouts at issuance-time, and completes orphaned tool calls after grace. |
| src/vs/platform/agentHost/common/pendingRequestRegistry.ts | Adds early-result buffering (respondOrBuffer) and clears buffers on reject/deny. |
| src/vs/platform/agentHost/test/common/pendingRequestRegistry.test.ts | Adds tests for early-result buffering semantics and buffer clearing. |
| src/vs/platform/agentHost/test/node/clientTools/claudeSessionClientToolsModel.test.ts | Updates expectation: clientId-only change no longer marks tools “dirty”. |
| src/vs/platform/agentHost/test/node/copilotAgent.test.ts | Adds reload regression tests: clientId-only change updates live id without restart; structural change still restarts. |
| src/vs/platform/agentHost/test/node/copilotAgentSession.test.ts | Adds tests for live clientId stamping and early completion buffering; updates internals access. |
| src/vs/platform/agentHost/test/node/protocolServerHandler.test.ts | Adds coverage for tool calls stamped for never/late-connected clients and empty clientId behavior. |
Copilot's findings
- Files reviewed: 12/12 changed files
- Comments generated: 4
…-fail no-client tool calls
Michael Lively (Yoyokrazy)
previously approved these changes
Jun 9, 2026
# Conflicts: # src/vs/platform/agentHost/node/copilot/copilotAgentSession.ts # src/vs/platform/agentHost/test/node/copilotAgentSession.test.ts
Matt Bierner (mjbvz)
approved these changes
Jun 9, 2026
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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Fixes #319641
(Commit message generated by Copilot)