fix: handle 'no choices' response gracefully in xtab fetch stream (fixes #318235)#318236
Open
vs-code-engineering[bot] wants to merge 1 commit into
Open
fix: handle 'no choices' response gracefully in xtab fetch stream (fixes #318235)#318236vs-code-engineering[bot] wants to merge 1 commit into
vs-code-engineering[bot] wants to merge 1 commit into
Conversation
#318235) The .then() handler on fetchResultPromise was rejecting the fetch stream with an error for the 'Response contained no choices' case, even though this is an expected outcome handled gracefully at line 855. When the Promise.race resolved with the fetchResult directly, the stream rejection went unhandled, surfacing as an unhandlederror in telemetry. Add the same RESPONSE_CONTAINED_NO_CHOICES check that exists at line 855 into the .then() handler, resolving the stream instead of rejecting it with an error for this expected case. 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
GitHub.copilot-chatextension's xtab provider (Next Edit Suggestions) was surfacing anunhandlederrorin telemetry when the model returned a "Response contained no choices" response. The error is benign — it means the model had no edit to suggest — but was being wrapped inErrorUtils.fromUnknown()and used to reject a fetch stream that was never consumed, causing an unhandled promise rejection. This affects ~9,400 users across versions 0.48.0 and 0.49.0 on Windows.Fixes #318235
Recommended reviewer:
@ulugbeknaCulprit Commit
This is a pre-existing issue — the error bucket has hits in both extension version 0.48.0 (first seen 2026-05-12) and 0.49.0 (first seen 2026-05-19). The code pattern has been present since the fetch stream architecture was introduced. No single culprit commit introduced this regression.
Code Flow
sequenceDiagram participant Model as LLM Model participant Fetch as fetchResultPromise participant ThenHandler as .then() handler (L823) participant RaceHandler as Promise.race (L846) participant Stream as fetchStreamSource Model->>Fetch: Response (type=Unknown, reason="no choices") Fetch->>ThenHandler: resolves Fetch->>RaceHandler: resolves ThenHandler->>Stream: reject(FetchStreamError(ErrorUtils.fromUnknown(...))) Note over ThenHandler: Creates Error with full JSON payload RaceHandler->>RaceHandler: L855 check passes, returns NoSuggestions early Note over Stream: Stream rejected but never consumed Note over Stream: Unhandled rejection surfaces in telemetryAffected Files
extensions/copilot/src/extension/xtab/node/xtabProvider.tsfetchStreamSource.reject(new FetchStreamError(mapChatFetcherErrorToNoNextEditReason(response)))extensions/copilot/src/util/common/errors.tsnew Error(\An unexpected error occurred: ${safeStringify(error)}`)`Repro Steps
{type: "unknown", reason: "Response contained no choices."}This is non-deterministic — it depends on the model deciding it has no edits to suggest.
How the Fix Works
Chosen approach (
extensions/copilot/src/extension/xtab/node/xtabProvider.ts):Added a check for
RESPONSE_CONTAINED_NO_CHOICESin the.then()handler at line 825, mirroring the existing check at line 855. When the response is typeUnknownwith reason "Response contained no choices", the stream is resolved (not rejected with an error) because this is an expected outcome — the model simply has no edit to suggest. The main code path at line 855 already handles this case gracefully by returningNoSuggestions, so the stream will never be consumed anyway. Fix at the data producer (the.then()handler that creates the error), not the crash site (the unhandled rejection handler).Alternatives considered: Wrapping the stream consumption in try/catch would hide the error without fixing the data producer — rejected.
Recommended Owner
@ulugbekna— owns NES (Next Edit Suggestions) extension side perworking-areas.md. Active in the last 90 days (commits as recent as 2026-05-23).