Skip to content

Commit c298577

Browse files
committed
fix: classify overloaded 429 responses as overloaded, not rate_limit
When a provider returns HTTP 429 with an overloaded body (e.g. z.ai code 1305, 'temporarily overloaded'), the error was misclassified as rate_limit because: 1. In classifyFailoverClassificationFromMessage: isRateLimitErrorMessage matches the bare '429' pattern before isOverloadedErrorMessage runs. 2. In classifyFailoverClassificationFromHttpStatus: the 429 branch only checks billing then defaults to rate_limit, unlike 503/499 which check overloaded first. Fix: reorder isOverloadedErrorMessage before isRateLimitErrorMessage in the message classifier, and add an overloaded check in the 429 branch of the status classifier (matching the existing 503/499 pattern). Fixes #98101
1 parent 738b2be commit c298577

2 files changed

Lines changed: 31 additions & 4 deletions

File tree

‎src/agents/embedded-agent-helpers/errors.ts‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,13 @@ function classifyFailoverClassificationFromHttpStatus(
809809
if (message && isBilling429MessageForProvider(message, provider)) {
810810
return toReasonClassification("billing");
811811
}
812+
// Overloaded 429 (e.g. z.ai code 1305, "temporarily overloaded") must be
813+
// distinguished from genuine rate limits so the user-facing copy and
814+
// failover reason are accurate. 503 and 499 already perform this check;
815+
// 429 should follow the same pattern.
816+
if (messageReason === "overloaded") {
817+
return messageClassification;
818+
}
812819
return toReasonClassification("rate_limit");
813820
}
814821
if (status === 401 || status === 403) {
@@ -1052,12 +1059,12 @@ function classifyFailoverClassificationFromMessage(
10521059
if (isPeriodicUsageLimitErrorMessage(raw)) {
10531060
return toReasonClassification(isBillingErrorMessage(raw) ? "billing" : "rate_limit");
10541061
}
1055-
if (isRateLimitErrorMessage(raw)) {
1056-
return toReasonClassification("rate_limit");
1057-
}
10581062
if (isOverloadedErrorMessage(raw)) {
10591063
return toReasonClassification("overloaded");
10601064
}
1065+
if (isRateLimitErrorMessage(raw)) {
1066+
return toReasonClassification("rate_limit");
1067+
}
10611068
if (
10621069
isStructuredServerErrorMessage(raw) &&
10631070
!isBillingErrorMessage(raw) &&

‎src/agents/embedded-agent-helpers/failover-matches.test.ts‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Covers provider-specific failover matcher regressions.
22
import { describe, expect, it } from "vitest";
3-
import { classifyFailoverReason } from "./errors.js";
3+
import { classifyFailoverReason, classifyFailoverReasonFromHttpStatus } from "./errors.js";
44
import {
55
isAuthErrorMessage,
66
isBillingErrorMessage,
@@ -210,3 +210,23 @@ describe("generic assistant error text classification (#93931)", () => {
210210
).toBe(false);
211211
});
212212
});
213+
214+
describe("HTTP 429 overloaded vs rate-limit classification (#98101)", () => {
215+
it("classifies a 429 with overloaded body as overloaded, not rate_limit", () => {
216+
// z.ai code 1305: "The service may be temporarily overloaded, please try again later"
217+
const message =
218+
"429 status code (exceeded limit)\n" +
219+
'{"code":1305,"message":"The service may be temporarily overloaded, please try again later."}';
220+
expect(classifyFailoverReasonFromHttpStatus(429, message)).toBe("overloaded");
221+
});
222+
223+
it("classifies a 429 with generic rate-limit body as rate_limit", () => {
224+
const message = "429 status code (exceeded limit)\nRate limit exceeded. Try again in 60s.";
225+
expect(classifyFailoverReasonFromHttpStatus(429, message)).toBe("rate_limit");
226+
});
227+
228+
it("classifies a 429 with billing body as billing, not rate_limit", () => {
229+
const message = "429 status code\nInsufficient balance or no resource package.";
230+
expect(classifyFailoverReasonFromHttpStatus(429, message)).toBe("billing");
231+
});
232+
});

0 commit comments

Comments
 (0)