Skip to content

fix: handle errors in initial chat session refresh (fixes #318225)#318230

Open
vs-code-engineering[bot] wants to merge 1 commit into
mainfrom
fix/unhandled-error-chat-session-refresh-464bc7272f5b60eb
Open

fix: handle errors in initial chat session refresh (fixes #318225)#318230
vs-code-engineering[bot] wants to merge 1 commit into
mainfrom
fix/unhandled-error-chat-session-refresh-464bc7272f5b60eb

Conversation

@vs-code-engineering
Copy link
Copy Markdown
Contributor

Summary

The registerChatSessionItemController method in chatSessions.contribution.ts calls controller.refresh() and stores the resulting promise as initialRefresh without any error handling. When an extension's refreshHandler throws (in this case, the built-in Copilot extension fails to load a native module runtime.node), the promise rejects and becomes an unhandled promise rejection, surfacing as unhandlederror in telemetry.

218 hits affecting 67 users on Windows, version 1.122.0-insider.

Fixes #318225
Recommended reviewer: @mjbvz

Culprit Commit

Not a recent regression from a single commit — the unhandled promise pattern has existed since registerChatSessionItemController was introduced. The error manifests when an extension's native module is missing from the installation (packaging/environment issue on user machines).

Code Flow

sequenceDiagram
    participant Main as MainThread ChatSessionsService
    participant MT as MainThreadChatSessionItemController
    participant EH as ExtHost ChatSessions
    participant Ext as Copilot Extension
    participant SDK as copilot SDK native module

    Main->>MT: registerChatSessionItemController()
    Main->>MT: controller.refresh(token)
    MT->>EH: $refreshChatSessionItems(handle, token)
    EH->>Ext: refreshHandler(token)
    Ext->>SDK: require(runtime.node)
    SDK-->>Ext: Error: module not found
    Ext-->>EH: throws Error
    EH-->>MT: Promise rejects
    MT-->>Main: initialRefresh rejects (UNHANDLED)
    Note over Main: No .catch() on stored promise
Loading

Affected Files

File Role
src/vs/workbench/contrib/chat/browser/chatSessions/chatSessions.contribution.ts Stores initialRefresh promise without error handling (line 967)
src/vs/workbench/api/common/extHostChatSessions.ts $refreshChatSessionItems calls extension handler without catch (line 1133)
extensions/copilot/node_modules/@github/copilot/sdk/ Tries to load native runtime.node binary

Repro Steps

  1. Install VS Code Insiders on Windows
  2. Have a corrupted or incomplete Copilot extension installation where extensions/copilot/node_modules/@github/copilot/sdk/prebuilds/win32-x64/runtime.node is missing
  3. Open VS Code — the chat session controller registers and calls refresh()
  4. The Copilot extension's refreshHandler attempts to lazily load the native SDK module
  5. dlopen fails → error propagates as unhandled promise rejection

How the Fix Works

Chosen approach (src/vs/workbench/contrib/chat/browser/chatSessions/chatSessions.contribution.ts): Added .catch() to the controller.refresh() promise at the creation site (line 967) that logs the error via logService.error() (preserving telemetry) and prevents the unhandled rejection. This is the correct fix location because it handles extension errors at the extension API boundary — the same pattern already used at line 946-953 in refreshChatSessionItems(). The fix is at the data producer of the unhandled promise (where it's created without a handler), not at the crash site.

Alternatives considered: Wrapping $refreshChatSessionItems in try/catch in extHostChatSessions.ts would only catch errors in that specific call path, but initialRefresh is also awaited at line 1048 without error handling. Fixing at the storage site handles all downstream consumers.

Recommended Owner

@mjbvz — most recent contributor to chat session infrastructure in this file, with commits related to chat session types and controller registration.

Generated by errors-fix · ● 61.8M ·

The initialRefresh promise from controller.refresh() was stored without
error handling. When an extension's refreshHandler throws (e.g., due to
a missing native module), this caused an unhandled promise rejection.

Add .catch() at the creation site to log the error and prevent unhandled
rejections, consistent with the error handling pattern already used in
refreshChatSessionItems().

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 25, 2026 15:53
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 25, 2026 15:55
@vs-code-engineering vs-code-engineering Bot enabled auto-merge (squash) May 25, 2026 15:55
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-The specified module could not be found. \\?\\extensions\copilot\node_modules\@github...

2 participants