Repository navigation
Resolve a client tool to the client that is still there - #331300
Ryan Ewen (RyanEwen) wants to merge 3 commits into
Conversation
A tool call is stamped with an owning clientId from ownerOf, which without a caller preference returned the first-inserted contributor. A window reload connects with a new clientId while the departed client's entry can still be present, so every later call was stamped with a client that had gone away and failed on arrival — permanently, not for the grace window. The host is both right and wrong about this at once: the "another active client provides it" advice reads state.activeClients and sees the live client, while ownerOf reads the tool model and answers with the dead one. Retrying, as the advice suggests, resolves to the same departed client. The model now tracks the most recent contributor and prefers it when the caller expresses none. A reconnecting window re-pushes its tools, so the newest contributor is the one most recently known to be alive. An explicit preference still wins, and removing the latest contributor falls back to whoever remains. Two tests asserted the first-inserted default, which is what produced the bug, and are updated. Coverage added for the reconnect case and the fallback.
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Updates tool ownership resolution to prefer the most recently contributing client, addressing stale client IDs after reconnects, and adjusts/adds tests to match the new ownership policy.
Changes:
- Track the latest tool contributor and use it as the default preference when resolving tool ownership.
- Update existing ownership tests to reflect “most recent contributor wins”.
- Add tests for reconnect and owner fallback after removing the latest contributor.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/vs/platform/agentHost/node/claude/clientTools/claudeSessionClientToolsModel.ts | Implements “latest contributor wins” ownership behavior via _latestContributor. |
| src/vs/platform/agentHost/test/node/clientTools/claudeSessionClientToolsModel.test.ts | Updates expectations and adds new test cases covering reconnect and removal behavior. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
📬 CODENOTIFYThe following users are being notified based on files changed in this PR: TylerLeonhardtMatched files:
|
Review feedback: clearing the latest contributor on removal fell back to insertion order, which is the behaviour this change exists to avoid. With three clients, removing the newest resolved to the oldest. Recency is now an ordered list, so removing a contributor falls back to the next most recent. Re-contributing moves a client back to the front, which matters because a reconnect re-pushes a structurally identical tool list and the merged observable dedupes that write. Tests cover three contributors removed newest-first, and re-contribution.
|
Both comments were right; fixed and pushed. Recency needs to be an order, not a single id. Clearing the latest contributor on removal fell back to Coverage for that case added, as suggested: three contributors, removed newest-first, asserting I added one more that the comment did not ask for but the fix needs. A reconnecting window re-pushes a structurally identical tool list, and While verifying this I found that AI disclosure: this comment and the related code were written with the assistance of AI. |
|
Note on scope, after trying to widen it. Codex resolves ownership the same way — That breaks Copilot, and the test that catches it is worth reading before anyone else tries the same thing: Copilot deliberately ties ownership to the merged dedupe order: So this PR stays scoped to the Claude model, where Fixing codex properly means deciding whether AI disclosure: this comment was written with the assistance of AI. |
|
Verified against a real reconnect, not just by unit test. I ported this change into an installed agent host, ran a session in a dev container, reloaded the window so the client reconnected with a new id, and then asked for a client-contributed tool. Reading the host log for which client the call was stamped with: Four client generations accumulated in the tool set across reloads, and the call resolved to the live one. Insertion order would have picked Note the departed entries are still present — four of them — which is the point. Nothing removed them, and nothing needs to: resolution no longer depends on them being cleaned up. AI disclosure: this comment was written with the assistance of AI. |
The guidelines allow 1-2 short sentences of JSDoc and at most one line inline. The reasoning belongs in the commit message and the pull request, which is where it already is.
Fixes #331289.
A client tool call is stamped with an owning
clientIdresolved throughSessionClientToolsModel.ownerOf. With no caller-supplied preference that resolved to the first-inserted contributor, and a window reload connects with a newclientIdwhile the departed client's entry can still be present. Every subsequent call was then stamped with a client that had gone away, and failed on arrival:Three milliseconds from start to failure, and the retry advice cannot be taken: the retry resolves to the same departed client. In the session this came from it was still happening 2 hours 8 minutes after that client disconnected, so it is not the disconnect-grace window elapsing — the tool is dead for the life of the session, and the model eventually concludes the tool itself is broken.
The host is simultaneously right and wrong about this: the "another active client provides it" sentence is guarded by
_hasReplacementActiveClientTool, which readsstate.activeClientsand correctly sees the live client, whileownerOfreads the tool model and answers with the dead one. Two registries, permanently disagreeing.This makes the resolution self-correcting rather than chasing the disagreement. The model now tracks the most recent contributor and prefers it when the caller expresses no preference. A reconnecting window re-pushes its tool list, so the newest contributor is the one most recently known to be alive; an explicit
preferredClientIdstill wins, and removing the latest contributor falls back to whoever remains.canRefineContributormakes this worth fixing at the point of resolution: a client contributor may only be refined by the same client, so once a call is stamped with a departed id nothing downstream can re-point it.Scope is deliberately narrow — only the Claude path goes through
SessionClientToolsModel.codexMapAppServerEvents.ts:748resolves throughActiveClientToolSetdirectly and has the same shape, but I have not reproduced it there and have left it alone.Two existing tests asserted the first-inserted default and are updated to the new behaviour, since that default is what produced the bug. Added coverage for the reconnect case itself and for the fallback when the latest contributor is removed.
AI disclosure: this description and the code it proposes were written with the assistance of AI.
Public patches and patcher scripts
Source patch and installed-bundle workaround mapping. The public collection includes the maintained patchers, rollback instructions, regression scripts, and historical snapshots. Build restrictions and exact installer coverage are documented there.