fix: no retry on quota limit errors (#1072)

This commit is contained in:
Charles Packer
2026-02-20 16:30:20 -08:00
committed by GitHub
parent 2e8b00f8cc
commit 150ff0d998
4 changed files with 116 additions and 15 deletions

View File

@@ -182,6 +182,60 @@ describe("formatErrorDetails", () => {
expect(message).toContain("/model");
});
test("uses premium-specific guidance for premium-usage-exceeded", () => {
const error = new APIError(
429,
{
error: "Rate limited",
reasons: ["premium-usage-exceeded"],
},
undefined,
new Headers(),
);
const message = formatErrorDetails(error);
expect(message).toContain("Premium model usage limit");
expect(message).toContain("Standard or Basic hosted models");
expect(message).toContain("/model");
expect(message).not.toContain("hosted model usage limit");
});
test("uses standard-specific guidance for standard-usage-exceeded", () => {
const error = new APIError(
429,
{
error: "Rate limited",
reasons: ["standard-usage-exceeded"],
},
undefined,
new Headers(),
);
const message = formatErrorDetails(error);
expect(message).toContain("Standard model usage limit");
expect(message).toContain("Basic hosted models");
expect(message).toContain("/model");
});
test("uses basic-specific guidance for basic-usage-exceeded", () => {
const error = new APIError(
429,
{
error: "Rate limited",
reasons: ["basic-usage-exceeded"],
},
undefined,
new Headers(),
);
const message = formatErrorDetails(error);
expect(message).toContain("Basic model usage limit");
expect(message).toContain("/model");
});
test("formats Z.ai error from APIError with embedded error code", () => {
const error = new APIError(
429,

View File

@@ -195,6 +195,18 @@ describe("provider detail retry helpers", () => {
"OpenAI API error: invalid_request_error",
),
).toBe(false);
expect(
shouldRetryRunMetadataError(
"llm_error",
'429 {"error":"Rate limited","reasons":["exceeded-quota"]}',
),
).toBe(false);
expect(
shouldRetryRunMetadataError(
"llm_error",
"You've reached your hosted model usage limit.",
),
).toBe(false);
});
test("pre-stream transient classifier handles status and detail", () => {
@@ -218,6 +230,13 @@ describe("provider detail retry helpers", () => {
'429 {"error":"Rate limited","reasons":["agents-limit-exceeded"]}',
}),
).toBe(false);
expect(
shouldRetryPreStreamTransientError({
status: 429,
detail:
'429 {"error":"Rate limited","reasons":["premium-usage-exceeded"]}',
}),
).toBe(false);
expect(
shouldRetryPreStreamTransientError({
status: 401,