fix(failover): classify Gemini MALFORMED_RESPONSE stop reason as retryable

This commit is contained in:
jiangnan
2026-03-10 23:34:45 +08:00
committed by Altay
parent bc9b35d6ce
commit cd0cda616e
2 changed files with 17 additions and 3 deletions

View File

@@ -501,6 +501,20 @@ describe("isFailoverErrorMessage", () => {
expect(isFailoverErrorMessage(sample)).toBe(true);
}
});
it("matches Gemini MALFORMED_RESPONSE stop reason as timeout (#42149)", () => {
const samples = [
"Unhandled stop reason: MALFORMED_RESPONSE",
"Unhandled stop reason: malformed_response",
"Unhandled stop reason: MALFORMED_FUNCTION_CALL",
"stop reason: MALFORMED_RESPONSE",
];
for (const sample of samples) {
expect(isTimeoutErrorMessage(sample)).toBe(true);
expect(classifyFailoverReason(sample)).toBe("timeout");
expect(isFailoverErrorMessage(sample)).toBe(true);
}
});
});
describe("parseImageSizeError", () => {

View File

@@ -40,9 +40,9 @@ const ERROR_PATTERNS = {
/\benotfound\b/i,
/\beai_again\b/i,
/without sending (?:any )?chunks?/i,
/\bstop reason:\s*(?:abort|error)\b/i,
/\breason:\s*(?:abort|error)\b/i,
/\bunhandled stop reason:\s*(?:abort|error)\b/i,
/\bstop reason:\s*(?:abort|error|malformed_\w+)\b/i,
/\breason:\s*(?:abort|error|malformed_\w+)\b/i,
/\bunhandled stop reason:\s*(?:abort|error|malformed_\w+)\b/i,
],
billing: [
/["']?(?:status|code)["']?\s*[:=]\s*402\b|\bhttp\s*402\b|\berror(?:\s+code)?\s*[:=]?\s*402\b|\b(?:got|returned|received)\s+(?:a\s+)?402\b|^\s*402\s+payment/i,