Skip to content

agentHost: fix orphaned client tool calls after window reload - #320672

Merged
Connor Peet (connor4312) merged 5 commits into
mainfrom
connor4312/319641
Jun 9, 2026
Merged

Connor Peet (connor4312) merged 5 commits into
mainfrom
connor4312/319641

Conversation

@connor4312

Copy link
Copy Markdown
Member
  • 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)

- 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)
Copilot AI review requested due to automatic review settings June 9, 2026 21:02

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.

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 ActiveClientState to track the owning clientId live 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 PendingRequestRegistry with respondOrBuffer to 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

# Conflicts:
#	src/vs/platform/agentHost/node/copilot/copilotAgentSession.ts
#	src/vs/platform/agentHost/test/node/copilotAgentSession.test.ts
@connor4312
Connor Peet (connor4312) merged commit d5dc82c into main Jun 9, 2026
25 checks passed
@connor4312
Connor Peet (connor4312) deleted the connor4312/319641 branch June 9, 2026 23:00
@vs-code-engineering vs-code-engineering Bot added this to the 1.125.0 milestone Jun 9, 2026
@vs-code-engineering vs-code-engineering Bot locked and limited conversation to collaborators Jul 24, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

client tool call stuck

4 participants