Skip to content

Agents window: corrupted session file silently loads as empty instead of surfacing error #319244

Description

@digitarald

Bug Description

When opening an old session in the Agents window, if the Copilot SDK rejects session.resume due to a validation error in the session file, the agent host silently falls back to createSession with the same ID. This results in the session appearing to load successfully but showing 0 turns — all conversation history is lost without any user-facing error.

Steps to Reproduce

  1. Have an existing agent session with conversation history
  2. The session file becomes corrupted (in this case, a compaction metadata field fails validation)
  3. Open the session in the Agents window
  4. Session appears empty — no error shown to user

Expected Behavior

The user should be informed that the session could not be restored due to corruption, rather than silently presenting an empty session.

Actual Behavior

The session loads with 0 turns. The user sees a blank conversation with no indication that data was lost.

Relevant Logs

[Copilot:df7c418f-...] _resumeSession called — session not in memory, resuming...
[Copilot:df7c418f-...] Calling SDK resumeSession...
[Copilot:df7c418f-...] SDK resumeSession failed: code=-32603, message=Request session.resume failed with message: Session file is corrupted (line 19567: data.compactionTokensUsed.copilotUsage.tokenDetails.0.batchSize: Number must be greater than 0)
[Copilot:df7c418f-...] Resume failed (code=-32603), falling back to createSession with same ID
[Copilot:df7c418f-...] Fallback createSession succeeded
[AgentHostStateManager] Restored session: copilotcli:/df7c418f-... (0 turns)
[AgentService] Restored session copilotcli:/df7c418f-... with 0 turns

Analysis

The fallback logic is in src/vs/platform/agentHost/node/copilot/copilotAgent.ts around line 1626:

if (!err || errCode !== -32603) {
    throw err;
}
// Falls back to createSession with same ID

The comment says "The SDK fails to resume sessions that have no messages" — but error code -32603 is also returned for data corruption, not just empty sessions. The fallback does not distinguish between these cases.

Suggested Fix

Two potential approaches:

  1. Agent Host: Parse the error message to distinguish "no messages" from "corrupted" — surface a notification to the user when data is actually corrupted rather than silently creating an empty session
  2. SDK: The validation on batchSize > 0 in compaction metadata should not prevent loading the actual conversation turns — this is metadata, not content

Metadata

Metadata

Assignees

Labels

agents-windowbugIssue identified by VS Code Team member as probable bug

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions