From 624065c4f10c01683ce246ad12d8696e97c6e092 Mon Sep 17 00:00:00 2001 From: Shujakuinkuraudo Date: Thu, 17 Sep 2026 22:53:11 +0800 Subject: [PATCH] fix(pi-devin): observe errored stream cancel rejection in reader teardown --- src/stream.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/stream.ts b/src/stream.ts index 6fd71dd..e78a232 100644 --- a/src/stream.ts +++ b/src/stream.ts @@ -400,7 +400,11 @@ async function* streamChatEvents(args: { // ignore } try { - void resp.body?.cancel(); + // cancel() on an already-errored stream rejects with the stored + // error (e.g. undici TypeError("terminated") after the server drops + // the socket). try/catch cannot observe that rejection, so swallow + // it explicitly or it escapes as an uncaughtException and kills pi. + void resp.body?.cancel()?.catch(() => {}); } catch { // ignore }