From 706138e7fe17fd77b7b07f3eb7a2b89e9a877826 Mon Sep 17 00:00:00 2001 From: Hannes Rudolph Date: Wed, 10 Dec 2025 00:50:28 -0700 Subject: [PATCH] Handle terminal failures in background resume/poll --- src/api/providers/openai-native.ts | 31 +++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/api/providers/openai-native.ts b/src/api/providers/openai-native.ts index e35a6c6162..e6bcc5d021 100644 --- a/src/api/providers/openai-native.ts +++ b/src/api/providers/openai-native.ts @@ -1197,10 +1197,25 @@ export class OpenAiNativeHandler extends BaseProvider implements SingleCompletio Authorization: `Bearer ${apiKey}`, Accept: "text/event-stream", }, + signal: this.abortController?.signal, }) if (!res.ok) { - throw new Error(`Resume request failed (${res.status})`) + const status = res.status + if (status === 401 || status === 403 || status === 404) { + yield { + type: "status", + mode: "background", + status: "failed", + responseId, + } + + const terminalErr = createTerminalBackgroundError(`Resume request failed (${status})`) + ;(terminalErr as any).status = status + throw terminalErr + } + + throw new Error(`Resume request failed (${status})`) } if (!res.body) { throw new Error("Resume request failed (no body)") @@ -1271,9 +1286,23 @@ export class OpenAiNativeHandler extends BaseProvider implements SingleCompletio headers: { Authorization: `Bearer ${apiKey}`, }, + signal: this.abortController?.signal, }) if (!pollRes.ok) { + const status = pollRes.status + if (status === 401 || status === 403 || status === 404) { + yield { + type: "status", + mode: "background", + status: "failed", + responseId, + } + const terminalErr = createTerminalBackgroundError(`Polling failed with status ${status}`) + ;(terminalErr as any).status = status + throw terminalErr + } + // transient; wait and retry await new Promise((r) => setTimeout(r, pollIntervalMs)) continue