From 0afa3708691cac8497b2e4d373462bacbbe075ea Mon Sep 17 00:00:00 2001 From: Jonathan Wilkins Date: Sat, 10 Jan 2026 13:49:23 -0800 Subject: [PATCH] fix: add 'usage limit' to rate limit detection patterns OpenAI/ChatGPT returns "You have hit your ChatGPT usage limit (plus plan)" when users exceed their plan quota. This error wasn't being recognized as a rate limit, so fallback to alternative models wasn't triggering. Co-Authored-By: Claude Opus 4.5 --- src/agents/pi-embedded-helpers.test.ts | 8 ++++++++ src/agents/pi-embedded-helpers.ts | 1 + 2 files changed, 9 insertions(+) diff --git a/src/agents/pi-embedded-helpers.test.ts b/src/agents/pi-embedded-helpers.test.ts index 0a4d5069f..4d981663b 100644 --- a/src/agents/pi-embedded-helpers.test.ts +++ b/src/agents/pi-embedded-helpers.test.ts @@ -272,6 +272,14 @@ describe("classifyFailoverReason", () => { ); expect(classifyFailoverReason("bad request")).toBeNull(); }); + + it("classifies OpenAI usage limit errors as rate_limit", () => { + expect( + classifyFailoverReason( + "You have hit your ChatGPT usage limit (plus plan)", + ), + ).toBe("rate_limit"); + }); }); describe("isCloudCodeAssistFormatError", () => { diff --git a/src/agents/pi-embedded-helpers.ts b/src/agents/pi-embedded-helpers.ts index 579e3f18e..d1e28b7fe 100644 --- a/src/agents/pi-embedded-helpers.ts +++ b/src/agents/pi-embedded-helpers.ts @@ -343,6 +343,7 @@ const ERROR_PATTERNS = { "resource has been exhausted", "quota exceeded", "resource_exhausted", + "usage limit", ], timeout: [ "timeout",