Skip to content

Commit c9a6c54

Browse files
Add HTTP 499 to transient error codes for model fallback (openclaw#41468)
Merged via squash. Prepared head SHA: 0053bae Co-authored-by: zeroasterisk <[email protected]> Co-authored-by: altaywtf <[email protected]> Reviewed-by: @altaywtf
1 parent de4c3db commit c9a6c54

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Docs: https://docs.openclaw.ai
3838
- Protocol/Swift model sync: regenerate pending node work Swift bindings after the landed `node.pending.*` schema additions so generated protocol artifacts are consistent again. (#41477) Thanks @mbelinky.
3939
- Discord/reply chunking: resolve the effective `maxLinesPerMessage` config across live reply paths and preserve `chunkMode` in the fast send path so long Discord replies no longer split unexpectedly at the default 17-line limit. (#40133) thanks @rbutera.
4040
- Logging/probe observations: suppress structured embedded and model-fallback probe warnings on the console without hiding error or fatal output. (#41338) thanks @altaywtf.
41+
- Agents/fallback: treat HTTP 499 responses as transient in both raw-text and structured failover paths so Anthropic-style client-closed overload responses trigger model fallback reliably. (#41468) thanks @zeroasterisk.
4142

4243
## 2026.3.8
4344

src/agents/failover-error.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ describe("failover-error", () => {
6767
expect(resolveFailoverReasonFromError({ statusCode: "429" })).toBe("rate_limit");
6868
expect(resolveFailoverReasonFromError({ status: 403 })).toBe("auth");
6969
expect(resolveFailoverReasonFromError({ status: 408 })).toBe("timeout");
70+
expect(resolveFailoverReasonFromError({ status: 499 })).toBe("timeout");
7071
expect(resolveFailoverReasonFromError({ status: 400 })).toBe("format");
7172
// Keep the status-only path behavior-preserving and conservative.
7273
expect(resolveFailoverReasonFromError({ status: 500 })).toBeNull();
@@ -93,6 +94,12 @@ describe("failover-error", () => {
9394
message: ANTHROPIC_OVERLOADED_PAYLOAD,
9495
}),
9596
).toBe("overloaded");
97+
expect(
98+
resolveFailoverReasonFromError({
99+
status: 499,
100+
message: ANTHROPIC_OVERLOADED_PAYLOAD,
101+
}),
102+
).toBe("overloaded");
96103
expect(
97104
resolveFailoverReasonFromError({
98105
status: 429,

src/agents/pi-embedded-helpers.isbillingerrormessage.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,7 @@ describe("isLikelyContextOverflowError", () => {
443443

444444
describe("isTransientHttpError", () => {
445445
it("returns true for retryable 5xx status codes", () => {
446+
expect(isTransientHttpError("499 Client Closed Request")).toBe(true);
446447
expect(isTransientHttpError("500 Internal Server Error")).toBe(true);
447448
expect(isTransientHttpError("502 Bad Gateway")).toBe(true);
448449
expect(isTransientHttpError("503 Service Unavailable")).toBe(true);
@@ -457,6 +458,19 @@ describe("isTransientHttpError", () => {
457458
});
458459
});
459460

461+
describe("classifyFailoverReasonFromHttpStatus", () => {
462+
it("treats HTTP 499 as transient for structured errors", () => {
463+
expect(classifyFailoverReasonFromHttpStatus(499)).toBe("timeout");
464+
expect(classifyFailoverReasonFromHttpStatus(499, "499 Client Closed Request")).toBe("timeout");
465+
expect(
466+
classifyFailoverReasonFromHttpStatus(
467+
499,
468+
'{"type":"error","error":{"type":"overloaded_error","message":"Overloaded"}}',
469+
),
470+
).toBe("overloaded");
471+
});
472+
});
473+
460474
describe("isFailoverErrorMessage", () => {
461475
it("matches auth/rate/billing/timeout", () => {
462476
const samples = [

src/agents/pi-embedded-helpers/errors.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ const HTTP_STATUS_PREFIX_RE = /^(?:http\s*)?(\d{3})\s+(.+)$/i;
189189
const HTTP_STATUS_CODE_PREFIX_RE = /^(?:http\s*)?(\d{3})(?:\s+([\s\S]+))?$/i;
190190
const HTML_ERROR_PREFIX_RE = /^\s*(?:<!doctype\s+html\b|<html\b)/i;
191191
const CLOUDFLARE_HTML_ERROR_CODES = new Set([521, 522, 523, 524, 525, 526, 530]);
192-
const TRANSIENT_HTTP_ERROR_CODES = new Set([500, 502, 503, 504, 521, 522, 523, 524, 529]);
192+
const TRANSIENT_HTTP_ERROR_CODES = new Set([499, 500, 502, 503, 504, 521, 522, 523, 524, 529]);
193193
const HTTP_ERROR_HINTS = [
194194
"error",
195195
"bad request",
@@ -375,6 +375,12 @@ export function classifyFailoverReasonFromHttpStatus(
375375
}
376376
return "timeout";
377377
}
378+
if (status === 499) {
379+
if (message && isOverloadedErrorMessage(message)) {
380+
return "overloaded";
381+
}
382+
return "timeout";
383+
}
378384
if (status === 502 || status === 504) {
379385
return "timeout";
380386
}

0 commit comments

Comments
 (0)