Skip to content

xtab: replace getFetchFailure polling with stream-level error propagation#309474

Merged
ulugbekna merged 2 commits intomainfrom
ulugbekna/agents/mathematical-hoverfly
Apr 13, 2026
Merged

xtab: replace getFetchFailure polling with stream-level error propagation#309474
ulugbekna merged 2 commits intomainfrom
ulugbekna/agents/mathematical-hoverfly

Conversation

@ulugbekna
Copy link
Copy Markdown
Contributor

Fixes #308745

Summary

Replaces the fragile chatResponseFailure mutable variable + getFetchFailure() polling pattern with stream-level error propagation in the XtabProvider's NES streaming pipeline.

What changed

Core mechanism: FetchStreamSource gains a reject(error) method that delegates to AsyncIterableSource.reject(), propagating errors through the async iterable stream. A new FetchStreamError class carries the mapped NoNextEditReason so catch sites can extract it cleanly.

_performFetch: Now calls fetchStreamSource.reject() on fetch failure and fetchStreamSource.resolve() on success — replacing the pattern of setting a mutable chatResponseFailure variable and calling resolve() in .finally().

Removed polling: All ~7 getFetchFailure() call sites across _streamEditsImpl, handleEditWindowWithEditIntent, handleUnifiedWithXml, generateInsertEdits, generateEditLines, and XtabCustomDiffPatchResponseHandler.handleResponse have been removed.

Error handling: Two catch sites handle FetchStreamError:

  • _streamEditsImpl — the main orchestrator loop
  • XtabCustomDiffPatchResponseHandler.handleResponse — has its own for await loop

Layering

FetchStreamError lives in extension/xtab/common/ (same layer as its consumers), keeping platform/chat free of platform/inlineEdits dependencies.

Testing

  • Updated 6 tests in responseFormatHandlers.spec.ts and xtabCustomDiffPatchResponseHandler.spec.ts to use stream-based error injection instead of polling callbacks
  • All 163 tests pass (3 pre-existing failures unrelated to this change)
  • TypeScript compiles cleanly

Result

Net −58 lines (97 added, 155 removed). Error propagation is now structural rather than polling-based, making it impossible to miss a failure check.

…tion (#308745)

Add FetchStreamError class and reject() method to FetchStreamSource so fetch
failures propagate through the async iterable stream. Consumers now
catch errors naturally via for-await instead of polling a mutable
closure at ~7 call sites.

- Added FetchStreamError (carries NoNextEditReason) in xtab/common,
  keeping platform/chat free of inlineEdits dependencies
- Added FetchStreamSource.reject() delegating to AsyncIterableSource
- Updated _performFetch to call reject()/resolve() instead of setting
  chatResponseFailure
- Removed getFetchFailure parameter from all response format handlers
- Added FetchStreamError catch in _streamEditsImpl and
  xtabCustomDiffPatchResponseHandler

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 13, 2026 14:25
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 13, 2026

Screenshot Changes

Base: 06f94d56 Current: d110623e

Changed (1)

chat/aiCustomizations/aiCustomizationManagementEditor/PromptsTabScrolled/Dark
Before After
before after

@ulugbekna ulugbekna enabled auto-merge (squash) April 13, 2026 14:30
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.

Pull request overview

This PR refactors the XtabProvider NES streaming pipeline to propagate fetch failures through the async line stream itself (instead of relying on a mutable chatResponseFailure + getFetchFailure() polling), aligning failure handling with the stream consumption model.

Changes:

  • Added FetchStreamSource.reject(error) to propagate errors through AsyncIterableSource.
  • Introduced FetchStreamError to carry a mapped NoNextEditReason through stream rejection.
  • Removed getFetchFailure() polling from xtab response handlers and updated unit tests to inject stream errors directly.
Show a summary per file
File Description
extensions/copilot/src/platform/chat/common/chatMLFetcher.ts Adds FetchStreamSource.reject() to forward failures into the stream.
extensions/copilot/src/extension/xtab/common/fetchStreamError.ts Introduces typed FetchStreamError containing NoNextEditReason.
extensions/copilot/src/extension/xtab/node/xtabProvider.ts Switches from polling to rejecting the stream on fetch failure; adds FetchStreamError handling (currently only around the diff loop).
extensions/copilot/src/extension/xtab/node/xtabCustomDiffPatchResponseHandler.ts Removes polling and returns FetchStreamError.reason when the line stream rejects.
extensions/copilot/src/extension/xtab/node/responseFormatHandlers.ts Removes getFetchFailure checks so stream rejection drives termination/errors.
extensions/copilot/src/extension/xtab/test/node/responseFormatHandlers.spec.ts Updates tests to validate stream-error propagation instead of polling callbacks.
extensions/copilot/src/extension/xtab/test/node/xtabCustomDiffPatchResponseHandler.spec.ts Updates tests to reject the input stream with FetchStreamError and assert handler behavior.

Copilot's findings

  • Files reviewed: 7/7 changed files
  • Comments generated: 1

Comment thread extensions/copilot/src/extension/xtab/node/xtabProvider.ts Outdated
The try/catch only covered the diff loop, but handleEditWindowWithEditIntent
and handleUnifiedWithXml read from the stream during dispatch and could throw
FetchStreamError before the diff phase. Extend the try/catch to wrap both the
switch dispatch and the diff loop.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@ulugbekna ulugbekna merged commit d9b443d into main Apr 13, 2026
26 checks passed
@ulugbekna ulugbekna deleted the ulugbekna/agents/mathematical-hoverfly branch April 13, 2026 15:02
@vs-code-engineering vs-code-engineering bot added this to the 1.117.0 milestone Apr 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NES: Replace chatResponseFailure polling with stream-level error propagation in XtabProvider

3 participants