fix: contain AbortError from aborted response body cancellation

`void resp.body?.cancel()` in streamChatEvents' finally floated a
rejected promise: an aborted fetch errors the body with the abort
reason, and cancel() on an errored stream rejects with it, escaping
as unhandledRejection -> uncaughtException and killing pi on Escape.

Await the cancel inside the existing try/catch so the rejection is
actually swallowed. Adds a regression test that aborts a mocked
in-flight stream and asserts no unhandled rejection is raised.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
denispol
2026-09-23 23:49:59 +02:00
co-authored by Devin
parent dc815fc15f
commit 463f29e76a
2 changed files with 70 additions and 1 deletions
+1 -1
View File
@@ -359,7 +359,7 @@ async function* streamChatEvents(args: {
// ignore
}
try {
void resp.body?.cancel();
await resp.body?.cancel();
} catch {
// ignore
}