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.
This commit is contained in:
WodenJay
2026-06-07 15:47:49 +08:00
parent 39646a44d3
commit 483fa8df3c
+2 -3
View File
@@ -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();