Uh oh!
There was an error while loading. Please reload this page.
fix(provider): handle SSE reader cancel rejections - #44912
fix(provider): handle SSE reader cancel rejections#44912AlexanderWillner wants to merge 2 commits into
Conversation
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.
This PR doesn't fully meet our contributing guidelines and PR template. What needs to be fixed:
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. |
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
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 |
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. |
Issue for this PR
Closes#44943
Type of change
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