Skip to content

fix(provider): handle SSE reader cancel rejections - #44912

Closed
AlexanderWillner wants to merge 2 commits into
anomalyco:devfrom
AlexanderWillner:bun14-robustness
Closed

fix(provider): handle SSE reader cancel rejections#44912
AlexanderWillner wants to merge 2 commits into
anomalyco:devfrom
AlexanderWillner:bun14-robustness

Conversation

@AlexanderWillner

@AlexanderWillnerAlexanderWillner commented Aug 25, 2026

Copy link
Copy Markdown

Issue for this PR

Closes#44943

Type of change

  • Bug fix

What does this PR do?

When the SSE chunk-timeout fires, the fetch-body reader is cancelled after the request signal is aborted. Under Bun 1.4 reader.cancel() then rejects and the voided promise surfaces as an unhandled rejection, which fails the running test even though its assertions passed. This handles the cancellation explicitly in both wrapSSE implementations (packages/opencode/src/provider/provider.ts, packages/core/src/aisdk.ts).

Also relaxes one PTY test's exit-poll deadline from 5s to 20s: under a fully parallel suite run the PTY exit event was observed at ~5.3s, so the poll deadline was exceeded despite correct behaviour. Assertion unchanged.

How did you verify your code works?

Full suite from packages/opencode under Bun 1.4.0 and Bun 1.3.14: 3339 tests, 0 fail with these changes (before: one deterministic failure under 1.4.0, one load-dependent PTY failure). tsgo typecheck clean. darwin-arm64 binaries built with both runtimes, smoke tests pass.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

When the chunk-timeout fires, the fetch-body reader is cancelled after
the request signal is aborted. Under Bun 1.4 reader.cancel() then
rejects, and the voided promise surfaces as an unhandled rejection
that fails tests (and can crash strict runtimes). Handle the
rejection explicitly.
The 5s deadline is load-sensitive: under a fully parallel test run
the PTY exit event was observed too late and the test failed even
though the behaviour under test is correct.
@github-actionsgithub-actionsBot added the needs:compliance This means the issue will auto-close after 2 hours. label Aug 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

No duplicate PRs found.

The search identified several related but distinct PRs addressing different aspects of SSE stream handling (PRs #39970, #43607, #40010, #39516), but none of them are duplicates of PR #44912. This PR specifically addresses unhandled promise rejections from reader.cancel() under Bun 1.4, which is a distinct issue from prior SSE robustness improvements.

@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.

Feel free to open a new pull request that follows our guidelines.

@github-actionsgithub-actionsBot removed the needs:compliance This means the issue will auto-close after 2 hours. label Aug 25, 2026
Sign up for freeto 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.

provider: unhandled rejection when SSE chunk-timeout cancels the fetch reader (suite red under Bun 1.4)

1 participant

@AlexanderWillner