From effd037c897bdd8e1a1b2370ae345490d3f5c059 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E9=B9=A40668001310?= Date: Thu, 5 Mar 2026 09:42:49 +0800 Subject: [PATCH] fix: narrow rate-limit pattern to avoid billing misclassification --- src/agents/pi-embedded-helpers.isbillingerrormessage.test.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/agents/pi-embedded-helpers.isbillingerrormessage.test.ts b/src/agents/pi-embedded-helpers.isbillingerrormessage.test.ts index 5c40bf58369..bb5aa36dba2 100644 --- a/src/agents/pi-embedded-helpers.isbillingerrormessage.test.ts +++ b/src/agents/pi-embedded-helpers.isbillingerrormessage.test.ts @@ -535,6 +535,8 @@ describe("classifyFailoverReason", () => { ).toBe("rate_limit"); expect(classifyFailoverReason("all credentials for model x are cooling down")).toBeNull(); expect(classifyFailoverReason("invalid request format")).toBe("format"); + expect(classifyFailoverReason("credit balance too low")).toBe("billing"); + // Billing with "limit exhausted" must stay billing, not rate_limit (avoids key-disable regression) expect( classifyFailoverReason("HTTP 402 payment required. Your limit exhausted for this plan."), ).toBe("billing"); @@ -593,6 +595,7 @@ describe("classifyFailoverReason", () => { "LLM error 1310: Weekly/Monthly Limit Exhausted. Your limit will reset at 2026-03-06 22:19:54 (request_id: 20260303141547610b7f574d1b44cb)", ), ).toBe("rate_limit"); + // Independent coverage for /weekly\/monthly limit/i (no generic "limit exhausted") expect(classifyFailoverReason("LLM error: weekly/monthly limit reached")).toBe("rate_limit"); }); it("classifies permanent auth errors as auth_permanent", () => {