fix: handle errors in initial chat session refresh (fixes #318225)#318230
Open
vs-code-engineering[bot] wants to merge 1 commit into
Open
fix: handle errors in initial chat session refresh (fixes #318225)#318230vs-code-engineering[bot] wants to merge 1 commit into
vs-code-engineering[bot] wants to merge 1 commit into
Conversation
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>
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
registerChatSessionItemControllermethod inchatSessions.contribution.tscallscontroller.refresh()and stores the resulting promise asinitialRefreshwithout any error handling. When an extension'srefreshHandlerthrows (in this case, the built-in Copilot extension fails to load a native moduleruntime.node), the promise rejects and becomes an unhandled promise rejection, surfacing asunhandlederrorin telemetry.218 hits affecting 67 users on Windows, version 1.122.0-insider.
Fixes #318225
Recommended reviewer:
@mjbvzCulprit Commit
Not a recent regression from a single commit — the unhandled promise pattern has existed since
registerChatSessionItemControllerwas 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 promiseAffected Files
src/vs/workbench/contrib/chat/browser/chatSessions/chatSessions.contribution.tsinitialRefreshpromise without error handling (line 967)src/vs/workbench/api/common/extHostChatSessions.ts$refreshChatSessionItemscalls extension handler without catch (line 1133)extensions/copilot/node_modules/@github/copilot/sdk/runtime.nodebinaryRepro Steps
extensions/copilot/node_modules/@github/copilot/sdk/prebuilds/win32-x64/runtime.nodeis missingrefresh()refreshHandlerattempts to lazily load the native SDK moduledlopenfails → error propagates as unhandled promise rejectionHow the Fix Works
Chosen approach (
src/vs/workbench/contrib/chat/browser/chatSessions/chatSessions.contribution.ts): Added.catch()to thecontroller.refresh()promise at the creation site (line 967) that logs the error vialogService.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 inrefreshChatSessionItems(). 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
$refreshChatSessionItemsin try/catch in extHostChatSessions.ts would only catch errors in that specific call path, butinitialRefreshis 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.