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
This commit is contained in:
Marceli Pawlinski
2026-07-27 23:06:45 +01:00
committed by GitHub
parent 82bed08404
commit dfd4d33287
2 changed files with 2 additions and 0 deletions

View File

@@ -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`;

View File

@@ -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);
});