fix(ai): keep exhausted request rate limits retryable (#59816)

This commit is contained in:
Kyle Bush
2026-11-10 23:04:13 -06:00
committed by GitHub
Unverified
parent 791a2c489e
commit 1002a979f9
2 changed files with 10 additions and 4 deletions
+1 -1
View File
@@ -142,7 +142,7 @@ const RATE_LIMIT_TEXT = /rate increased too quickly|rate[-_\s]?limit|too[_\s]?ma
// Z.ai reports balance, plan expiry, plan limits, and plan model access on 429.
// Cerebras reports its per-minute token throttle as `token_quota_exceeded`; that is a rate limit.
const QUOTA_TEXT =
/insufficient[-_\s]?(?:quota|balance)|(?<!token_)quota[-_\s]?exceeded|budget exceeded|usage limit|limit exhausted|package has expired|plan does not yet include/i
/insufficient[-_\s]?(?:quota|balance)|(?<!token_)quota[-_\s]?exceeded|budget exceeded|usage limit|(?<!rate[-_\s]?)limit exhausted|package has expired|plan does not yet include/i
// Policy rejections without a dedicated code, matched against the provider's own
// explanation only. OpenAI reuses `invalid_prompt` for usage-policy rejections while
// Bedrock Mantle reuses it for schema validation; Anthropic reports blocked output
+9 -3
View File
@@ -447,17 +447,23 @@ describe("provider error classification", () => {
expect(isContextOverflow("Too many tokens")).toBe(true)
})
test("classifies 429 token throttles as retryable rate limits, not context overflow", () => {
test("classifies 429 throttles as retryable rate limits, not context overflow", () => {
const bodies = [
// Cerebras, captured live
'{"message":"Tokens per minute limit exceeded - too many tokens processed.","type":"too_many_tokens_error","param":"quota","code":"token_quota_exceeded"}',
'{"message":"Token limit reached: too many tokens per minute for this model."}',
'{"error":{"message":"User 10s request rate limit exhausted (3 of 3).","type":"rate_limit_exceeded","code":null}}',
]
for (const body of bodies) {
const error = new AIError({
reason: classifyProviderFailure({ message: providerErrorMessage(body), status: 429, rawBody: body }),
reason: classifyProviderFailure({
message: providerErrorMessage(body),
status: 429,
rawBody: body,
retryAfterMs: 4000,
}),
})
expect(error.reason._tag).toBe("RateLimit")
expect(error.reason).toMatchObject({ _tag: "RateLimit", retryAfterMs: 4000 })
expect(isRetryable(error)).toBe(true)
}
})