From d9cdf3b8acc6ea92578804eaa9865f01d1d7a0e2 Mon Sep 17 00:00:00 2001 From: CI <112553441+pcty-nextgen-ios-builder@users.noreply.github.com> Date: Mon, 5 Jan 2026 19:16:38 +0100 Subject: [PATCH] fix(model): treat quota errors as rate limits --- src/agents/pi-embedded-helpers.test.ts | 8 ++++++++ src/agents/pi-embedded-helpers.ts | 5 ++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/agents/pi-embedded-helpers.test.ts b/src/agents/pi-embedded-helpers.test.ts index 97a332224..1fb719c2b 100644 --- a/src/agents/pi-embedded-helpers.test.ts +++ b/src/agents/pi-embedded-helpers.test.ts @@ -26,6 +26,14 @@ describe("isRateLimitAssistantError", () => { expect(isRateLimitAssistantError(msg)).toBe(true); }); + it("detects quota exceeded messages", () => { + const msg = asAssistant({ + errorMessage: + "You exceeded your current quota, please check your plan and billing details. For more information on this error, read the docs: https://platform.openai.com/docs/guides/error-codes/api-errors.", + }); + expect(isRateLimitAssistantError(msg)).toBe(true); + }); + it("returns false for non-error messages", () => { const msg = asAssistant({ stopReason: "end_turn", diff --git a/src/agents/pi-embedded-helpers.ts b/src/agents/pi-embedded-helpers.ts index 79808d9e2..4cb5f86a2 100644 --- a/src/agents/pi-embedded-helpers.ts +++ b/src/agents/pi-embedded-helpers.ts @@ -117,7 +117,10 @@ export function isRateLimitAssistantError( if (!msg || msg.stopReason !== "error") return false; const raw = (msg.errorMessage ?? "").toLowerCase(); if (!raw) return false; - return /rate[_ ]limit|too many requests|429/.test(raw); + return ( + /rate[_ ]limit|too many requests|429/.test(raw) || + raw.includes("exceeded your current quota") + ); } function extractSupportedValues(raw: string): string[] {