fix: avoid rate-limit false positives in likely overflow detection

This commit is contained in:
Vladimir Peshekhonov
2026-02-11 15:22:31 +01:00
committed by Tak Hoffman
parent 883a638e49
commit 86a7ecb45e
2 changed files with 8 additions and 1 deletions

View File

@@ -30,6 +30,8 @@ describe("isLikelyContextOverflowError", () => {
"too many requests", "too many requests",
"429 Too Many Requests", "429 Too Many Requests",
"exceeded your current quota", "exceeded your current quota",
"This request would exceed your account's rate limit",
"429 Too Many Requests: request exceeds rate limit",
]; ];
for (const sample of samples) { for (const sample of samples) {
expect(isLikelyContextOverflowError(sample)).toBe(false); expect(isLikelyContextOverflowError(sample)).toBe(false);

View File

@@ -38,7 +38,9 @@ export function isContextOverflowError(errorMessage?: string): boolean {
const CONTEXT_WINDOW_TOO_SMALL_RE = /context window.*(too small|minimum is)/i; const CONTEXT_WINDOW_TOO_SMALL_RE = /context window.*(too small|minimum is)/i;
const CONTEXT_OVERFLOW_HINT_RE = const CONTEXT_OVERFLOW_HINT_RE =
/context.*overflow|context window.*(too (?:large|long)|exceed|over|limit|max(?:imum)?|requested|sent|tokens)|(?:prompt|request|input).*(too (?:large|long)|exceed|over|limit|max(?:imum)?)/i; /context.*overflow|context window.*(too (?:large|long)|exceed|over|limit|max(?:imum)?|requested|sent|tokens)|prompt.*(too (?:large|long)|exceed|over|limit|max(?:imum)?)|(?:request|input).*(?:context|window|length|token).*(too (?:large|long)|exceed|over|limit|max(?:imum)?)/i;
const RATE_LIMIT_HINT_RE =
/rate limit|too many requests|requests per (?:minute|hour|day)|quota|throttl|429\b/i;
export function isLikelyContextOverflowError(errorMessage?: string): boolean { export function isLikelyContextOverflowError(errorMessage?: string): boolean {
if (!errorMessage) { if (!errorMessage) {
@@ -56,6 +58,9 @@ export function isLikelyContextOverflowError(errorMessage?: string): boolean {
if (isContextOverflowError(errorMessage)) { if (isContextOverflowError(errorMessage)) {
return true; return true;
} }
if (RATE_LIMIT_HINT_RE.test(errorMessage)) {
return false;
}
return CONTEXT_OVERFLOW_HINT_RE.test(errorMessage); return CONTEXT_OVERFLOW_HINT_RE.test(errorMessage);
} }