fix(failover): narrow service-unavailable to require overload indicator

This commit is contained in:
jiangnan
2026-03-06 03:51:50 +08:00
committed by Altay
parent f014e255df
commit dda7f3b0bc
2 changed files with 14 additions and 2 deletions

View File

@@ -540,13 +540,22 @@ describe("classifyFailoverReason", () => {
"This model is currently experiencing high demand. Please try again later.",
),
).toBe("rate_limit");
expect(classifyFailoverReason("LLM error: service unavailable")).toBe("rate_limit");
// "service unavailable" combined with overload indicator → rate_limit
expect(
classifyFailoverReason("service unavailable due to high demand and overloaded servers"),
).toBe("rate_limit");
expect(
classifyFailoverReason(
'{"error":{"code":503,"message":"The model is overloaded. Please try later","status":"UNAVAILABLE"}}',
),
).toBe("rate_limit");
});
it("does not classify bare 'service unavailable' as rate_limit (#32828)", () => {
// A generic "service unavailable" from a proxy/CDN should not trigger
// provider-overload failover — it may be a transient proxy error or an
// unrelated upstream failure.
expect(classifyFailoverReason("LLM error: service unavailable")).toBeNull();
});
it("classifies permanent auth errors as auth_permanent", () => {
expect(classifyFailoverReason("invalid_api_key")).toBe("auth_permanent");
expect(classifyFailoverReason("Your api key has been revoked")).toBe("auth_permanent");

View File

@@ -15,7 +15,10 @@ const ERROR_PATTERNS = {
overloaded: [
/overloaded_error|"type"\s*:\s*"overloaded_error"/i,
"overloaded",
"service unavailable",
// Match "service unavailable" only when combined with an explicit overload
// indicator — a generic 503 from a proxy/CDN should not be classified as
// provider-overload (#32828).
/service[_ ]unavailable.*(?:overload|capacity|high[_ ]demand)|(?:overload|capacity|high[_ ]demand).*service[_ ]unavailable/i,
"high demand",
],
timeout: [