From dda7f3b0bc4a91b5c6057b852a2d5324a38c8c2b Mon Sep 17 00:00:00 2001 From: jiangnan <1394485448@qq.com> Date: Fri, 6 Mar 2026 03:51:50 +0800 Subject: [PATCH] fix(failover): narrow service-unavailable to require overload indicator --- .../pi-embedded-helpers.isbillingerrormessage.test.ts | 11 ++++++++++- src/agents/pi-embedded-helpers/failover-matches.ts | 5 ++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/agents/pi-embedded-helpers.isbillingerrormessage.test.ts b/src/agents/pi-embedded-helpers.isbillingerrormessage.test.ts index 599440ca0b2..5651728deb3 100644 --- a/src/agents/pi-embedded-helpers.isbillingerrormessage.test.ts +++ b/src/agents/pi-embedded-helpers.isbillingerrormessage.test.ts @@ -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"); diff --git a/src/agents/pi-embedded-helpers/failover-matches.ts b/src/agents/pi-embedded-helpers/failover-matches.ts index ecf7be953d9..92bd7e20eaf 100644 --- a/src/agents/pi-embedded-helpers/failover-matches.ts +++ b/src/agents/pi-embedded-helpers/failover-matches.ts @@ -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: [