From dfd4d33287d33b44d923834d609438061213bf5b Mon Sep 17 00:00:00 2001 From: Marceli Pawlinski Date: Mon, 27 Jul 2026 23:06:45 +0100 Subject: [PATCH] fix(backend): add error.code to synthOpenAIErrorChunk for guard compatibility (#8570) synthOpenAIErrorChunk() sets error.type to upstream_empty_response but omits error.code. The isRequestScopedUpstreamFailure guard only checks type for context_length_exceeded, so an upstream_empty_response error slips past it. - Added code: upstream_empty_response to the error object in synthOpenAIErrorChunk() - Added test assertion verifying error.code matches error.type This ensures the guard correctly identifies upstream empty responses as request-scoped failures. Closes #8469 --- open-sse/utils/diagnostics.ts | 1 + tests/unit/diagnostics.test.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/open-sse/utils/diagnostics.ts b/open-sse/utils/diagnostics.ts index 39161e4137..4402656281 100644 --- a/open-sse/utils/diagnostics.ts +++ b/open-sse/utils/diagnostics.ts @@ -122,6 +122,7 @@ export function synthOpenAIErrorChunk(opts: { error: { message: safeMessage, type: "upstream_empty_response", + code: "upstream_empty_response", }, }; return `data: ${JSON.stringify(body)}\n\n`; diff --git a/tests/unit/diagnostics.test.ts b/tests/unit/diagnostics.test.ts index 901feebff7..93a85380b5 100644 --- a/tests/unit/diagnostics.test.ts +++ b/tests/unit/diagnostics.test.ts @@ -39,6 +39,7 @@ test("synthOpenAIErrorChunk payload has expected OpenAI chunk shape", () => { assert.equal(payload.choices.length, 1); assert.ok(payload.error, "must have error field"); assert.equal(payload.error.type, "upstream_empty_response"); + assert.equal(payload.error.code, "upstream_empty_response"); assert.ok(typeof payload.error.message === "string" && payload.error.message.length > 0); });