fix: trigger model failover for generic provider error messages

When Anthropic returns a generic error like 'An unknown error occurred'
without a type field, classifyFailoverReason() now recognizes it as a
transient failure and returns 'timeout' to trigger model failover.

Also handles other generic error patterns: 'an error occurred',
'internal server error', and 'service unavailable'.

Fixes #49706
This commit is contained in:
ShionElia 2026-03-18 10:05:29 +00:00
parent 92700940d9
commit 627743aa38
2 changed files with 29 additions and 0 deletions

View File

@ -860,4 +860,17 @@ describe("classifyFailoverReason", () => {
),
).toBe("timeout");
});
it("classifies generic provider errors as timeout", () => {
expect(classifyFailoverReason("An unknown error occurred")).toBe("timeout");
expect(classifyFailoverReason("An error occurred")).toBe("timeout");
expect(classifyFailoverReason("Internal server error")).toBe("timeout");
expect(classifyFailoverReason("Service unavailable")).toBe("timeout");
// Case-insensitive
expect(classifyFailoverReason("AN UNKNOWN ERROR OCCURRED")).toBe("timeout");
expect(classifyFailoverReason("an error occurred while processing")).toBe("timeout");
// Wrapped in provider payload
expect(classifyFailoverReason('{"error":{"message":"An unknown error occurred"}}')).toBe(
"timeout",
);
});
});

View File

@ -846,6 +846,19 @@ export function isBillingAssistantError(msg: AssistantMessage | undefined): bool
return isBillingErrorMessage(msg.errorMessage ?? "");
}
function isGenericProviderError(raw: string): boolean {
if (!raw) {
return false;
}
const lower = raw.toLowerCase();
return (
lower.includes("an unknown error occurred") ||
lower.includes("an error occurred") ||
lower.includes("internal server error") ||
lower.includes("service unavailable")
);
}
function isJsonApiInternalServerError(raw: string): boolean {
if (!raw) {
return false;
@ -1024,6 +1037,9 @@ export function classifyFailoverReason(raw: string): FailoverReason | null {
if (isAuthErrorMessage(raw)) {
return "auth";
}
if (isGenericProviderError(raw)) {
return "timeout";
}
return null;
}