Skip to content

agentHost: recover client tools after silent disconnects - #346681

Merged
Connor Peet (connor4312) merged 3 commits into
mainfrom
connor4312/322990
Nov 6, 2026
Merged

Connor Peet (connor4312) merged 3 commits into
mainfrom
connor4312/322990

Conversation

@connor4312

@connor4312 Connor Peet (connor4312) commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

agentHost: recover client tools after silent disconnects

  • 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]

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:

    ./scripts/test.sh \
      --run src/vs/platform/agentHost/test/electron-browser/agentHostProtocolClient.test.ts \
      --run src/vs/platform/agentHost/test/node/protocolServerHandler.test.ts \
      --reporter dot
  • Changed TypeScript lint (passed):

    pnpm run eslint \
      src/vs/platform/agentHost/common/protocolLivenessMonitor.ts \
      src/vs/platform/agentHost/browser/agentHostProtocolClient.ts \
      src/vs/platform/agentHost/node/protocolServerHandler.ts \
      src/vs/platform/agentHost/test/electron-browser/agentHostProtocolClient.test.ts \
      src/vs/platform/agentHost/test/node/protocolServerHandler.test.ts \
      src/vs/platform/agentHost/node/copilot/copilotAgentSession.ts \
      src/vs/platform/agentHost/test/node/copilotAgentSession.test.ts
  • 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 dot
  • WebSocket 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 dot
  • pnpm run build-fast --client-only (passed).

  • pnpm run typecheck-client (passed).

  • Follow-up TypeScript lint (passed):

    pnpm run eslint \
      src/vs/platform/agentHost/node/webSocketTransport.ts \
      src/vs/platform/agentHost/test/node/webSocketTransport.test.ts \
      src/vs/platform/agentHost/test/node/copilotAgent.test.ts
  • 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:

./scripts/test-integration.sh \
  --run src/vs/platform/agentHost/test/node/providerIntegration/copilotCredentialSponsorship.integrationTest.ts \
  --reporter dot

pnpm run build-fast --client-only, pnpm run eslint src/vs/platform/agentHost/test/node/providerIntegration/copilotAgentIntegrationTestHarness.ts, and git diff --check also passed.

- 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]>
Copilot AI balanced review requested due to automatic review settings November 6, 2026 22:56
@connor4312
Connor Peet (connor4312) enabled auto-merge (squash) November 6, 2026 22:56

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

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]>
@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Base: ec554943 Current: 192975af

No screenshot changes.

- 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]>
@connor4312
Connor Peet (connor4312) merged commit f98ccff into main Nov 6, 2026
52 checks passed
@connor4312
Connor Peet (connor4312) deleted the connor4312/322990 branch November 6, 2026 23:53
@vs-code-engineering vs-code-engineering Bot added this to the 1.146.0 milestone Nov 6, 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