From 984f98be951137a207ba72f2e4bd9a46ea4f356d Mon Sep 17 00:00:00 2001 From: Craig Allan-McWilliams Date: Fri, 27 Mar 2026 00:05:15 +0000 Subject: [PATCH] Fix: treat HTTP 500 as a transient failover error (#55332) HTTP 500 (Internal Server Error) was not triggering model fallback, causing agents to fail outright instead of trying the next candidate. This is inconsistent with TRANSIENT_HTTP_ERROR_CODES which already includes 500. Aligns the direct status check with that constant. Co-authored-by: Craig McWilliams Co-authored-by: Claude Opus 4.6 (1M context) --- src/agents/failover-error.test.ts | 4 ++-- src/agents/pi-embedded-helpers/errors.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/agents/failover-error.test.ts b/src/agents/failover-error.test.ts index 38e3530f011..9f312d5c928 100644 --- a/src/agents/failover-error.test.ts +++ b/src/agents/failover-error.test.ts @@ -70,8 +70,8 @@ describe("failover-error", () => { expect(resolveFailoverReasonFromError({ status: 499 })).toBe("timeout"); expect(resolveFailoverReasonFromError({ status: 400 })).toBe("format"); expect(resolveFailoverReasonFromError({ status: 422 })).toBe("format"); - // Keep the status-only path behavior-preserving and conservative. - expect(resolveFailoverReasonFromError({ status: 500 })).toBeNull(); + // Transient server errors (500/502/503/504) should trigger failover as timeout. + expect(resolveFailoverReasonFromError({ status: 500 })).toBe("timeout"); expect(resolveFailoverReasonFromError({ status: 502 })).toBe("timeout"); expect(resolveFailoverReasonFromError({ status: 503 })).toBe("timeout"); expect(resolveFailoverReasonFromError({ status: 504 })).toBe("timeout"); diff --git a/src/agents/pi-embedded-helpers/errors.ts b/src/agents/pi-embedded-helpers/errors.ts index ff94ea58831..0167e7f8d0f 100644 --- a/src/agents/pi-embedded-helpers/errors.ts +++ b/src/agents/pi-embedded-helpers/errors.ts @@ -494,7 +494,7 @@ export function classifyFailoverReasonFromHttpStatus( } return "timeout"; } - if (status === 502 || status === 504) { + if (status === 500 || status === 502 || status === 504) { return "timeout"; } if (status === 529) {