From 483fa8df3c192685ce09d6ad693a2a58fc69db6d Mon Sep 17 00:00:00 2001 From: WodenJay Date: Sun, 7 Jun 2026 15:47:49 +0800 Subject: [PATCH] fix(proxy): throw error when server disconnects without terminal event When the proxy SSE stream ends without sending a done or error terminal event, streamProxy now throws an error instead of silently calling stream.end() with no arguments. The thrown error is caught by the existing catch block, which pushes an error event with stopReason='error' and resolves finalResultPromise. Previously, server disconnects produced a silent success: the stream iterator completed normally with stopReason='stop' (the default) and empty content, and finalResultPromise never resolved, causing callers that awaited stream.result() to hang indefinitely. This matches the pattern used by the codex provider (openai-codex-responses.ts) which already guards against missing terminal events. --- packages/agent/src/proxy.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/agent/src/proxy.ts b/packages/agent/src/proxy.ts index b1f71ba84..92d2a5553 100644 --- a/packages/agent/src/proxy.ts +++ b/packages/agent/src/proxy.ts @@ -167,9 +167,8 @@ export function streamProxy(model: Model, context: Context, options: ProxyStream } } - if (options.signal?.aborted && !sawTerminalEvent) { - const reason = options.signal.reason; - throw reason instanceof Error ? reason : new Error(String(reason ?? "Request aborted")); + if (!sawTerminalEvent) { + throw new Error("Proxy stream ended without a terminal event (done or error)"); } stream.end();