agentHost: add diagnostic tracing for session disconnect errors#312078
Merged
agentHost: add diagnostic tracing for session disconnect errors#312078
Conversation
Add logging at key decision points to diagnose 'Session not found' errors after WebSocket reconnect. The logs will reveal: - Whether the stale in-memory SDK session is reused (cachedEntry=true) - Whether isOutdated correctly detects clientId changes - The exact error code from the SDK when send() fails - Client disconnect/reconnect lifecycle with old/new clientIds Also adds a retry path in sendMessage: if entry.send() fails with code -32603, dispose the stale entry and retry via _resumeSession. Also adds clientId comparison to ActiveClient.isOutdated() so the SDK session is proactively refreshed when a different client takes over.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds diagnostic tracing across the agent host session lifecycle to help pinpoint the cause of “Session not found” failures after reconnects, by emitting structured logs around reconnect/disconnect, session caching, resume/create fallbacks, and send failures.
Changes:
- Add detailed lifecycle and failure-path logging in
CopilotAgentaroundsetClientTools,sendMessage, and_resumeSession. - Improve disconnect logging to include subscription counts and reconnect logging to include old/new client IDs.
- Enhance
AgentSideEffectssend failure logs to include error code/type/message.
Show a summary per file
| File | Description |
|---|---|
| src/vs/sessions/contrib/remoteAgentHost/browser/remoteAgentHost.contribution.ts | Logs old/new clientId and whether name changed when reconnecting a contribution. |
| src/vs/platform/agentHost/node/protocolServerHandler.ts | Logs subscription count when a protocol client disconnects. |
| src/vs/platform/agentHost/node/copilot/copilotAgent.ts | Adds detailed logs around session caching, resumeSession/createSession behavior, and send failures. |
| src/vs/platform/agentHost/node/agentSideEffects.ts | Logs sendMessage failures with code/type/message context. |
Copilot's findings
Comments suppressed due to low confidence (1)
src/vs/platform/agentHost/node/copilot/copilotAgent.ts:972
SDK resumeSession failedis logged without including the thrown error object, which can hide stack traces and any additional fields the SDK attaches. Passerras an additional logger argument (as is done forgetSessionMetadata failed) so the diagnostic output remains actionable.
const snapshot = activeClient ? await activeClient.snapshot() : undefined;
const storedMetadata = await this._readSessionMetadata(sessionUri);
const sessionMetadata = await client.getSessionMetadata(sessionId).catch(err => {
this._logService.warn(`[Copilot:${sessionId}] getSessionMetadata failed`, err);
return undefined;
- Files reviewed: 4/4 changed files
- Comments generated: 5
Contributor
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
TylerLeonhardt
approved these changes
Apr 23, 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.
Problem
After a WebSocket reconnect (e.g. tab hidden → server kills socket → tab visible), sending a message to an existing agent session fails with:
The root cause is unclear — multiple theories exist but none are proven:
-32603error codeChanges
Diagnostic logging (4 files)
Adds logging at every decision point in the session lifecycle to determine the exact failure path:
copilotAgent.ts—sendMessage: logs cached entry status, isOutdated result, full error code/message/type on failure.setClientTools: logs clientId + whether a cached SDK session exists._resumeSession: logs SDK resumeSession/createSession calls and results.agentSideEffects.ts— logs error code and type on sendMessage failure (was only logging raw error)protocolServerHandler.ts— logs subscription count on client disconnectremoteAgentHost.contribution.ts— logs old vs new clientId on reconnectWhat the logs will tell us
When the error reproduces, the sequence will reveal:
This proves whether it's path A (stale cached entry) or something else.