From eb5a1b0278ccd714469c8e710303ed7bd36e19d8 Mon Sep 17 00:00:00 2001 From: zhb <50901800+zhbdesign@users.noreply.github.com> Date: Sun, 21 Jun 2026 13:35:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=81=9C=E6=AD=A2=EF=BC=8C?= =?UTF-8?q?=E5=87=BA=E7=8E=B0API=20Error:=20Stream=20ended=20without=20rec?= =?UTF-8?q?eiving=20any=20events?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 优化停止,出现API Error: Stream ended without receiving any events --- src/server/ws/handler.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/server/ws/handler.ts b/src/server/ws/handler.ts index e1e37b6d..26d10310 100644 --- a/src/server/ws/handler.ts +++ b/src/server/ws/handler.ts @@ -1407,6 +1407,13 @@ export function translateCliMessage(cliMsg: any, sessionId: string): ServerMessa switch (cliMsg.type) { case 'assistant': { if (cliMsg.error || cliMsg.isApiErrorMessage) { + // If the user requested stop, suppress API errors caused by the + // stream being interrupted (e.g. "Stream ended without receiving + // any events"). The result message handler also checks this flag, + // but the assistant error arrives first and would leak to the UI. + if (sessionStopRequested.has(sessionId)) { + return [] + } const message = extractAssistantText(cliMsg) || cliMsg.error || 'Unknown API error' const code = typeof cliMsg.error === 'string' ? cliMsg.error : 'API_ERROR' streamState.lastApiError = { message, code }