Skip to content

Agent host: after a client reconnects, new client tool calls are still attributed to the disconnected client and fail immediately #331289

Open

Agent suggestions

Public preview

Description

@RyanEwen

After a client reconnects, client tool calls created afterwards are still attributed to the client that went away, and fail on arrival. The session never recovers: every subsequent call to that tool fails the same way for as long as the session lives.

What happens

In a dev container session, the window reloaded at 16:45:23Z. The new client ade2f5ea initialized and is the only client ever named in session/activeClientSet (33 tools) for the rest of the log.

At 17:14:38Z — half an hour later — a fresh openBrowserPage call is announced as belonging to the old client:

[1786] 17:14:38.827 s2c  chat/toolCallStart      clientId=fbac6cdc…
[1790] 17:14:38.830 s2c  chat/toolCallComplete   Client fbac6cdc-798c-415c-a75e-3a2782d74493 disconnected before completing openBrowserPage
[1798] 17:14:40.646 s2c  chat/toolCallComplete   The client that was running openBrowserPage disconnected, but another active
                                                 client now provides openBrowserPage. You may try calling the tool again.

Three milliseconds from start to failure. The model took the advice and retried; every retry was attributed to fbac6cdc and failed identically. The same thing was still happening at 18:53:20Z, 2 hours and 8 minutes after that client disconnected — so this is not the disconnect-grace window elapsing, it is permanent.

Two calls in the same log carried no clientId on their start line and completed normally (17:10:28, 18:53:37). The failure tracks the stale attribution, not the tool.

From the user's side the tool is simply broken, and the model reasonably concludes the same — in this session it gave up and installed Chromium instead, then reported the integrated browser as failing on every call.

Why it never recovers

_pendingClientToolCalls yields each call's owner from toolCall.contributor.clientId, and _completeDisconnectedClientToolCalls fails the ones whose owner matches a departed client. Nothing re-attributes a new call to a live client that provides the same tool.

The host demonstrably knows a live client provides it: the retry sentence is guarded by _hasReplacementActiveClientTool, which returns true only when a different, active client offers the same tool name. So at the moment of failure the host holds both "this call belongs to a dead client" and "a live client provides this tool", and acts on the first.

Two chat/toolCallComplete actions are also dispatched for the same toolCallId (~2s apart), which looks wrong independent of the attribution.

Expected

A client tool call created after its contributor disconnected should be attributed to an active client that provides the tool. Failing that, the retry advice should not be emitted, since retrying cannot succeed — it currently sends the model into a loop that costs a turn and ends in a wrong conclusion about the tool.

Steps to reproduce

  1. Open a remote or dev container window and start an agent session that uses a client-contributed tool (the integrated browser tools are convenient).
  2. Reload the window, so the client reconnects with a new clientId.
  3. Ask the agent to use that tool.

Version

  • VS Code 1.133.0, commit a5b500951314efd502d07465bd138dfbd714a960
  • Windows 11 client, dev container remote (linux-arm64 server)

Disclosure: this agent host is a locally patched build carrying approximations of several of my open PRs (#330683, #330684, #330730, #330746, #330775, #330933). None of them set contributor.clientId — the closest, the single-trigger change, only reads contributor.kind — and both the attribution and the failure path quoted above are unmodified. But #330933 does change when a client tool executes, so it is fair to ask whether it widens the window; I would rather say so than have it discovered later. The log evidence above is from that build.

AI disclosure: this issue was written with the assistance of AI.

Public patches and patcher scripts

Public patch catalog and patcher scripts · Source patch index. The public collection includes the maintained patchers, rollback instructions, regression scripts, and historical snapshots. Build restrictions and exact installer coverage are documented there.

Activity

  1. RyanEwen commented on Aug 17, 2026

    @RyanEwen
    ContributorAuthor

    Traced this to the end. There are two registries of "which client provides this tool" and a reconnect can leave them permanently disagreeing.

    Where the dead id comes from. A Claude tool call is stamped at claudeMapSessionEvents.ts:616:

    const toolClientId = isClientTool ? clientToolOwner?.(toolName) : undefined;

    clientToolOwner is supplied at claudeAgentSession.ts:601 as (toolName: string) => this.toolDiff.model.ownerOf(toolName) — with no preferredClientId. Without it, ActiveClientToolSet.ownerOf falls through to "the first-inserted contributor wins":

    for (const [clientId, tools] of this._byClient) {
        if (tools.some(tool => tool.name === toolName)) { return clientId; }
    }

    The pre-reload client was inserted first, so it keeps winning for the life of the session.

    Why the stale entry is never removed. toolDiff.model is only cleaned through SessionActiveClientRemoved → agentSideEffects.ts:1637 → removeActiveClient → removeClientTools. That action is dispatched by _removeActiveClient, which is guarded:

    if (state && this._isActiveClient(state, clientId)) { … dispatch … }

    So if the client is already out of state.activeClients when release runs, the guard skips the dispatch, and nothing ever tells the tool model to drop it. state.activeClients and toolDiff.model._byClient then disagree permanently — the first knows only the live client, the second still answers with the dead one.

    That is exactly the contradiction in the original report: _hasReplacementActiveClientTool consults state.activeClients and correctly reports a live provider (hence the "you may try again" sentence), while ownerOf consults _byClient and hands back the corpse. Both are right about their own registry.

    This is a gap against documented intent, not a missing feature. ownerOf already takes preferredClientId ("When preferredClientId currently provides the tool it wins"), and ActiveClientState says exactly what should happen here:

    The clientId is read at tool-call stamp time (not cached per turn) so that a window reload — which connects with a new clientId and re-pushes an identical tool list — stamps subsequent client tool calls with the new, live clientId instead of a frozen one baked in at session creation.

    That is the scenario in this issue, and the mechanism for it exists. The Claude stamp site just doesn't pass the argument.

    canRefineContributor then makes it terminal: a client contributor may only be refined by the same client, so once a call is stamped with the dead id nothing downstream can re-point it at the live one.

    Suggested fix, smallest first:

    1. Pass the session's live client id as preferredClientId at claudeAgentSession.ts:601. Self-healing regardless of how the registries drift, and uses the parameter as designed.
    2. Additionally, make the tool-model cleanup unconditional so _byClient cannot outlive state.activeClients — otherwise the stale entry keeps shadowing any client that is not preferred.

    The codex path looks like it has the same shape — codexMapAppServerEvents.ts:748 calls state.clientToolSet.ownerOf(params.item.tool) with no preferred id — though I have not reproduced it there.

    One inferential step, stated plainly: I did not capture the moment the guard was skipped, so "already out of state.activeClients when release ran" is the mechanism that fits the evidence rather than something I watched happen. The two-registry disagreement itself is directly observed — the log has the host naming one client as active while stamping calls with another, two hours after that other client went away.

    AI disclosure: this comment was written with the assistance of AI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions