fix: handle corrupted session files gracefully in getChatHistoryImpl (fixes #317566)#317576
Merged
vs-code-engineering[bot] merged 1 commit intoMay 20, 2026
Conversation
…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>
meganrogge
approved these changes
May 20, 2026
meganrogge
approved these changes
May 20, 2026
dmitrivMS
approved these changes
May 20, 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.
Summary
The Copilot CLI session service throws an unhandled error when
sessionManager.getSession()encounters a corrupted session file on disk (e.g., invalidephemeralfield value). The error "Session file is corrupted (line 51: ephemeral: Invalid literal value, expected true)" propagates up from the@github/copilot/sdkthroughgetChatHistoryImpl→getChatHistory→getSessionHistory→provideChatSessionContentto 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:
@meganroggeCulprit Commit
This is a pre-existing issue — the
getChatHistoryImplmethod was written without error handling for thegetSession()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 telemetryAffected Files
extensions/copilot/src/extension/chatSessions/copilotcli/node/copilotcliSessionService.tsconst session = await sessionManager.getSession({ sessionId }, false)extensions/copilot/node_modules/@github/copilot/sdk/index.jsRepro Steps
ephemeralfield (e.g., a value other thantrueon line 51)How the Fix Works
Chosen approach (
copilotcliSessionService.ts): Added acatchclause to the existingtryblock aroundsessionManager.getSession(). When the SDK throws (e.g., due to file corruption), the error is logged vialogService.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 insessionReindexer.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 thecopilotcliSessionService.tscode and active contributor (commits within last 90 days). Owns Copilot terminal/chat integration areas.