Repository navigation
agentHost: recover client tools after silent disconnects - #346681
Merged
Merged
Conversation
- Share the protocol liveness monitor between the renderer and host. - Probe idle remote clients after 10 seconds and close silent transports after 30 seconds. - Keep the existing 30-second tool reconnect grace after disconnect detection. - Route later Copilot tool calls to a connected client with a matching tool definition. - Keep in-flight calls on their original client and preserve renderer timeout behavior. - Add tests for replacement clients, ping responses, transport cleanup, and grace deadlines. Related: #322990 Related: #346456 Related: #335565 (Commit message generated by Copilot) Co-authored-by: Copilot <[email protected]>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The watchdog can close healthy connections during uploads exceeding 30 seconds because the server-side transport does not expose partial inbound activity, requiring a transport fix and regression coverage.
1 open issue
What changed in this PR
This PR improves Agent Host recovery from silent client disconnects and routes subsequent Copilot tool calls to compatible connected clients, while preserving ownership of in-flight calls.
Changes:
- Shares liveness monitoring between renderer and host, adding host-side idle probes and disconnect detection.
- Prefers connected clients with matching tool definitions while retaining the existing reconnect grace period.
- Adds regression tests and documents recovery behavior and limits.
| File | Description |
|---|---|
src/vs/platform/agentHost/test/node/protocolServerHandler.test.ts |
Tests host watchdog behavior, transport cleanup, and grace deadlines. |
src/vs/platform/agentHost/test/node/copilotAgentSession.test.ts |
Tests compatible replacement routing and retained in-flight ownership. |
src/vs/platform/agentHost/test/electron-browser/agentHostProtocolClient.test.ts |
Tests responses to host liveness pings. |
src/vs/platform/agentHost/node/protocolServerHandler.ts |
Adds per-transport host watchdogs using normal disconnect cleanup. |
src/vs/platform/agentHost/node/copilot/copilotAgentSession.ts |
Prefers connected compatible tool contributors. |
src/vs/platform/agentHost/common/protocolLivenessMonitor.ts |
Introduces shared liveness timers and load deferrals. |
src/vs/platform/agentHost/browser/agentHostProtocolClient.ts |
Adopts the shared monitor and answers host pings. |
src/vs/platform/agentHost/AGENTS.md |
Documents routing precedence, watchdog deadlines, and recovery scope. |
Review effort: Balanced
- Report raw inbound WebSocket bytes before a complete protocol message arrives. - Test fragmented uploads that continue beyond the 30-second silence deadline. - Register the client connection service in the CopilotAgent test fixture. (Commit message generated by Copilot) Co-authored-by: Copilot <[email protected]>
Contributor
|
Base:
|
- Register the client connection service in the standalone provider fixture. - Keep its lifetime tied to the fixture's disposable store. (Commit message generated by Copilot) Co-authored-by: Copilot <[email protected]>
Dmitriy Vasyura (dmitrivMS)
approved these changes
Nov 6, 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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

agentHost: recover client tools after silent disconnects
Related: #322990
Related: #346456
Related: #335565
(Commit message generated by Copilot)
Co-authored-by: Copilot [email protected]
Behavior and scope
A silent connection can take about 60 seconds to fail its pending client tools: 30 seconds for host-side detection, followed by the existing 30-second reconnect grace. This is not an unconditional tool-execution timeout. Outstanding calls stay on their original client; only subsequent calls can use a compatible connected replacement.
No tunnel shutdown behavior changes. Local MessagePort connections retain their process-owned lifetime. The renderer keeps its existing liveness deadlines and deferrals. Older clients can answer the host ping with an unsupported-method error and still demonstrate liveness.
The Node WebSocket transport counts raw inbound socket bytes, including control frames, so a client does not time out while a large message is still arriving.
The related issues are not auto-closed. In particular, this change does not directly address the empty-argument/late-confirmation race described in #322990.
Validation
The following checks passed before the initial publication; follow-up validation is recorded below:
pnpm run build-fast --client-only(passed).pnpm run typecheck-client(passed).Protocol client/server tests: 957 passed, 1 skipped:
Changed TypeScript lint (passed):
git diff --cached --check(passed).git merge-tree --write-tree HEAD origin/main(passed; no merge conflicts).Live reverse-proxy verification also passed with the actual protocol client and production host using a scripted mock provider: healthy renderer pings produced no host pings; directional blackholes closed after approximately 25 seconds on the renderer and 30 seconds on the host; preserving an orphaned upstream socket led to tool failure after approximately 60 seconds total. No fake timers were used for these network checks.
Real-provider tool handoff, UI flows, full integration tests, and smoke tests were not exercised.
Follow-up validation
The initial Linux and Windows unit-test failures came from a missing client-connection service in the CopilotAgent test fixture. The fixture now registers the real disposable service.
The Copilot review also identified missing partial-upload activity in the Node WebSocket transport. The transport now exposes that activity. A real WebSocket regression test uses a fake clock to keep an incomplete upload active for 40 seconds, finish the message, and verify that a later 30-second silence still expires.
Copilot client-tool and configuration regression tests: 194 passed:
./scripts/test.sh \ --run src/vs/platform/agentHost/test/node/copilotAgent.test.ts \ --run src/vs/platform/agentHost/test/node/copilotAgentSession.test.ts \ --grep 'client tool|client-tool|active-client chat membership fan-out|config-driven session refresh' \ --reporter dotWebSocket transport and host watchdog tests: 12 passed:
./scripts/test.sh \ --run src/vs/platform/agentHost/test/node/webSocketTransport.test.ts \ --run src/vs/platform/agentHost/test/node/protocolServerHandler.test.ts \ --grep 'WebSocketProtocolServer|host watchdog' \ --reporter dotpnpm run build-fast --client-only(passed).pnpm run typecheck-client(passed).Follow-up TypeScript lint (passed):
git diff --check(passed).Provider integration fixture validation
The subsequent Linux Node.js integration run found the same missing bootstrap dependency in the standalone credential-sponsorship fixture. That fixture now registers the client-connection service with fixture-owned disposal, matching production bootstrap.
All three existing credential-sponsorship integration tests passed locally, including cold history restoration and real provider startup with isolated synthetic credentials:
pnpm run build-fast --client-only,pnpm run eslint src/vs/platform/agentHost/test/node/providerIntegration/copilotAgentIntegrationTestHarness.ts, andgit diff --checkalso passed.