Repository navigation
fix: swallow reader.cancel rejection when stream source already errored - #627
Open
mattapperson wants to merge 2 commits into
Open
mattapperson wants to merge 2 commits into
mattapperson wants to merge 2 commits into
Conversation
Add an offline e2e/issues regression test that drives chat and completion doStream through a mocked fetch, errors the body with an AbortError at queue depths 0-6, cancels, and asserts no unhandledRejection (fails at depth 2 without the fix). Also skip controller access in pull once the wrapper has been cancelled, so a read settling after cancel no longer passes a spurious 'Controller is already closed' TypeError to onError.
mattapperson
force-pushed
the
claude/fix-stream-cancel-abort-error
branch
from
November 4, 2026 14:35
64b83ca to
2663716
Compare
christineschen
approved these changes
Nov 4, 2026
| }); | ||
|
|
||
| it('should not leak an unhandled rejection when cancelled after the source errored', async () => { | ||
| // Regression test for #615 / #625: an aborted fetch errors the response |
Contributor
There was a problem hiding this comment.
[nit] do we want the issue numbers still in the comment here?
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.
Description
Fixes #615
Fixes #625
withStreamErrorHandling'scancelhook calledreader.cancel(reason)and dropped the promise. When a streaming request is aborted,fetcherrors the response body while the consumer cancels the wrapper; if the body's error lands first,reader.cancel()rejects with theAbortErrorand Node reports an unhandled rejection (crashing processes under the default--unhandled-rejections=throw).The hook now returns
reader.cancel(reason).catch(() => {}), matching the guard already used inpull. This covers both chat and completion streaming, which share the helper.Added a regression test in
src/utils/with-stream-error-handling.test.tsthat errors the source with anAbortError, cancels the wrapper, and asserts nounhandledRejectionfires. It fails onmainand passes with the fix (node + edge).Checklist
pnpm stylecheckandpnpm typecheckpnpm testand all tests passChangeset
pnpm changesetto create a changeset file