Skip to content

fix: handle corrupted session files gracefully in getChatHistoryImpl (fixes #317566)#317576

Merged
vs-code-engineering[bot] merged 1 commit into
mainfrom
fix/corrupted-session-file-317566-7c1d9333f28d7ec0
May 20, 2026
Merged

fix: handle corrupted session files gracefully in getChatHistoryImpl (fixes #317566)#317576
vs-code-engineering[bot] merged 1 commit into
mainfrom
fix/corrupted-session-file-317566-7c1d9333f28d7ec0

Conversation

@vs-code-engineering
Copy link
Copy Markdown
Contributor

Summary

The Copilot CLI session service throws an unhandled error when sessionManager.getSession() encounters a corrupted session file on disk (e.g., invalid ephemeral field value). The error "Session file is corrupted (line 51: ephemeral: Invalid literal value, expected true)" propagates up from the @github/copilot/sdk through getChatHistoryImplgetChatHistorygetSessionHistoryprovideChatSessionContent to the VS Code extension host as an unhandled rejection. This affects users on Windows and Mac running VS Code 1.121.0.

Fixes #317566
Recommended reviewer: @meganrogge

Culprit Commit

This is a pre-existing issue — the getChatHistoryImpl method was written without error handling for the getSession() SDK call. The error surfaces when a user's local session file becomes corrupted (invalid schema values). No specific regression commit introduced this; the missing error handling has been present since the code was introduced.

Code Flow

sequenceDiagram
    participant ExtHost as extHostChatSessions
    participant Provider as copilotCLIChatSessionsContribution
    participant Service as copilotcliSessionService
    participant SDK as copilotSDK

    ExtHost->>Provider: provideChatSessionContent()
    Provider->>Service: getChatHistory()
    Service->>SDK: sessionManager.getSession()
    Note over SDK: Session file on disk has<br/>invalid ephemeral field
    SDK-->>Service: throws Error("Session file is corrupted...")
    Note over Service: No catch block exists
    Service-->>ExtHost: unhandled rejection propagates
    Note over ExtHost: Error reaches telemetry
Loading

Affected Files

File Role Evidence
extensions/copilot/src/extension/chatSessions/copilotcli/node/copilotcliSessionService.ts crash site + fix location L1031: const session = await sessionManager.getSession({ sessionId }, false)
extensions/copilot/node_modules/@github/copilot/sdk/index.js error origin (external SDK) throws "Session file is corrupted" when parsing invalid session data

Repro Steps

  1. Open VS Code with the Copilot extension active
  2. Have a chat session file on disk that contains an invalid ephemeral field (e.g., a value other than true on line 51)
  3. Trigger any action that loads chat session history (e.g., open chat panel, switch sessions)
  4. The SDK throws a validation error that propagates as an unhandled error

How the Fix Works

Chosen approach (copilotcliSessionService.ts): Added a catch clause to the existing try block around sessionManager.getSession(). When the SDK throws (e.g., due to file corruption), the error is logged via logService.error() (preserving telemetry visibility) and empty history is returned — treating the corrupted session the same as a missing session. This fixes at the boundary where VS Code interacts with the SDK (the data producer boundary), rather than suppressing errors downstream. The pattern matches the existing approach in sessionReindexer.ts (line 101) where corrupt sessions are logged and skipped.

Alternatives considered: Attempting to repair/delete the corrupted session file was rejected — the SDK owns the file format and lifecycle, and VS Code should not manipulate it directly.

Recommended Owner

@meganrogge — author of the copilotcliSessionService.ts code and active contributor (commits within last 90 days). Owns Copilot terminal/chat integration areas.

Generated by errors-fix · ● 57.6M ·

…ixes #317566)

When sessionManager.getSession() throws due to a corrupted session file,
catch the error, log it, and return empty history instead of letting the
error propagate as an unhandled rejection.

This follows the same pattern used in sessionReindexer.ts where corrupt
sessions are skipped gracefully.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 20, 2026 17:20
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@vs-code-engineering vs-code-engineering Bot marked this pull request as ready for review May 20, 2026 17:25
@vs-code-engineering vs-code-engineering Bot enabled auto-merge (squash) May 20, 2026 17:25
@meganrogge meganrogge added this to the 1.122.0 milestone May 20, 2026
@vs-code-engineering vs-code-engineering Bot merged commit 382e40a into main May 20, 2026
25 checks passed
@vs-code-engineering vs-code-engineering Bot deleted the fix/corrupted-session-file-317566-7c1d9333f28d7ec0 branch May 20, 2026 19:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Error] unhandlederror-Session file is corrupted (line 51: ephemeral: Invalid literal value, expected true)

3 participants