fix: dont retry on agents limit exceeded (#1035)

This commit is contained in:
cthomas
2026-02-19 11:57:56 -08:00
committed by GitHub
parent 9920b3a42d
commit 7fdd163665
2 changed files with 19 additions and 1 deletions

View File

@@ -46,6 +46,7 @@ const NON_RETRYABLE_PROVIDER_DETAIL_PATTERNS = [
"context_length_exceeded",
"invalid_encrypted_content",
];
const NON_RETRYABLE_429_REASONS = ["agents-limit-exceeded"];
const NON_RETRYABLE_4XX_PATTERN = /Error code:\s*4(0[0-8]|1\d|2\d|3\d|4\d|51)/i;
const RETRYABLE_429_PATTERN = /Error code:\s*429|rate limit|too many requests/i;
@@ -109,7 +110,16 @@ export function shouldRetryPreStreamTransientError(opts: {
detail: unknown;
}): boolean {
const { status, detail } = opts;
if (status === 429) return true;
if (status === 429) {
// Don't retry non-recoverable 429s (e.g. agent limit reached)
if (
typeof detail === "string" &&
NON_RETRYABLE_429_REASONS.some((r) => detail.includes(r))
) {
return false;
}
return true;
}
if (status !== undefined && status >= 500) return true;
if (status !== undefined && status >= 400) return false;

View File

@@ -210,6 +210,14 @@ describe("provider detail retry helpers", () => {
detail: "rate limited",
}),
).toBe(true);
// Non-recoverable 429: agents-limit-exceeded should NOT retry
expect(
shouldRetryPreStreamTransientError({
status: 429,
detail:
'429 {"error":"Rate limited","reasons":["agents-limit-exceeded"]}',
}),
).toBe(false);
expect(
shouldRetryPreStreamTransientError({
status: 401,