Skip to content

Commit 416905b

Browse files
committed
fix: classify HTTP 429 'temporarily overloaded' as overloaded, not rate_limit
Some providers (Z.ai/GLM, Anthropic) return HTTP 429 with an 'overloaded' message body when their model fleet is at capacity. This is a transient server-side overload, not a per-account rate limit. Two changes in errors.ts: 1. classifyFailoverClassificationFromMessage: check isOverloadedErrorMessage BEFORE isRateLimitErrorMessage. The rateLimit pattern /429/ was matching '429 The service may be temporarily overloaded' first, returning 'rate_limit' before isOverloadedErrorMessage was ever evaluated. 2. classifyFailoverClassificationFromHttpStatus: add overloaded check for HTTP 429 (matching existing 503/499 handlers that already check messageReason === 'overloaded'). Previously, 429 overloaded responses triggered immediate model fallback instead of retry-with-backoff, causing unnecessary failovers and ~30-60s stalls on every turn when ZAI was overloaded. Added 6 test cases covering: 'temporarily overloaded', bare 'overloaded', 'model is at capacity', and regression tests for 'rate limit exceeded', 'too many requests', and billing messages.
1 parent ec737ee commit 416905b

2 files changed

Lines changed: 60 additions & 3 deletions

File tree

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,14 @@ function classifyFailoverClassificationFromHttpStatus(
808808
if (message && isBilling429MessageForProvider(message, provider)) {
809809
return toReasonClassification("billing");
810810
}
811+
// Some providers (e.g. Z.ai/GLM) return HTTP 429 with an "overloaded"
812+
// message body when their model fleet is at capacity — this is a
813+
// transient server-side overload, not a per-account rate limit.
814+
// Classify it as "overloaded" so the runner retries with backoff
815+
// instead of immediately falling over to the next model.
816+
if (messageReason === "overloaded") {
817+
return messageClassification;
818+
}
811819
return toReasonClassification("rate_limit");
812820
}
813821
if (status === 401 || status === 403) {
@@ -1031,12 +1039,17 @@ function classifyFailoverClassificationFromMessage(
10311039
if (isPeriodicUsageLimitErrorMessage(raw)) {
10321040
return toReasonClassification(isBillingErrorMessage(raw) ? "billing" : "rate_limit");
10331041
}
1034-
if (isRateLimitErrorMessage(raw)) {
1035-
return toReasonClassification("rate_limit");
1036-
}
1042+
// Check overloaded BEFORE rate limit: some providers (Z.ai/GLM, Anthropic)
1043+
// return HTTP 429 with an "overloaded" message body when their model fleet
1044+
// is at capacity. The rateLimit pattern /429/ would match these first,
1045+
// misclassifying a transient server-side overload as a per-account rate
1046+
// limit and triggering immediate model fallback instead of retry-with-backoff.
10371047
if (isOverloadedErrorMessage(raw)) {
10381048
return toReasonClassification("overloaded");
10391049
}
1050+
if (isRateLimitErrorMessage(raw)) {
1051+
return toReasonClassification("rate_limit");
1052+
}
10401053
if (
10411054
isStructuredServerErrorMessage(raw) &&
10421055
!isBillingErrorMessage(raw) &&

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

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,50 @@ describe("server error status classification", () => {
179179
});
180180
});
181181

182+
describe("HTTP 429 with overloaded message body", () => {
183+
// Some providers (Z.ai/GLM, Anthropic) return HTTP 429 with an
184+
// "overloaded" message when their model fleet is at capacity.
185+
// This is a transient server-side overload, not a per-account
186+
// rate limit — it should be classified as "overloaded" so the
187+
// runner retries with backoff instead of immediately falling
188+
// over to the next model.
189+
it("classifies 429 'temporarily overloaded' as overloaded, not rate_limit", () => {
190+
const raw = "429 The service may be temporarily overloaded, please try again later";
191+
expect(isOverloadedErrorMessage(raw)).toBe(true);
192+
expect(classifyFailoverReason(raw)).toBe("overloaded");
193+
});
194+
195+
it("classifies 429 'overloaded' (bare) as overloaded", () => {
196+
const raw = "429 overloaded";
197+
expect(isOverloadedErrorMessage(raw)).toBe(true);
198+
expect(classifyFailoverReason(raw)).toBe("overloaded");
199+
});
200+
201+
it("classifies 429 'model is at capacity' as overloaded", () => {
202+
const raw = "429 The selected model is at capacity";
203+
expect(isOverloadedErrorMessage(raw)).toBe(true);
204+
expect(classifyFailoverReason(raw)).toBe("overloaded");
205+
});
206+
207+
it("still classifies 429 'rate limit exceeded' as rate_limit", () => {
208+
const raw = "429 Rate limit exceeded";
209+
expect(isRateLimitErrorMessage(raw)).toBe(true);
210+
expect(classifyFailoverReason(raw)).toBe("rate_limit");
211+
});
212+
213+
it("still classifies 429 'too many requests' as rate_limit", () => {
214+
const raw = "429 Too many requests";
215+
expect(isRateLimitErrorMessage(raw)).toBe(true);
216+
expect(classifyFailoverReason(raw)).toBe("rate_limit");
217+
});
218+
219+
it("still classifies 429 billing messages as billing", () => {
220+
const raw =
221+
'429 {"code":1311,"message":"The model you requested is not available in your current plan"}';
222+
expect(classifyFailoverReason(raw)).toBe("billing");
223+
});
224+
});
225+
182226
describe("generic assistant error text classification (#93931)", () => {
183227
it("classifies the generic 'LLM request failed.' as a timeout (transient)", () => {
184228
// The generic error text wraps provider availability failures (model not

0 commit comments

Comments
 (0)