From ba247bedd5c3a9726ac5049c33cbba39ed62fa69 Mon Sep 17 00:00:00 2001 From: Probe Test Date: Thu, 23 Jul 2026 03:51:29 -0300 Subject: [PATCH] fix(sse): export PROVIDER_BREAKER_FAILURE_STATUSES so chat.ts stops throwing ReferenceError MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Base-red slice 4 (single root cause across the whole handleChat cluster). src/sse/handlers/chat.ts:1273 references PROVIDER_BREAKER_FAILURE_STATUSES to decide whether an all-rate-limited provider result should trip the provider breaker, but the constant was only a FILE-LOCAL const in chatPredicates.ts (a refactor extracted it out of chat.ts and never re-exported it). Every request that reached that branch threw `ReferenceError: PROVIDER_BREAKER_FAILURE_STATUSES is not defined`, so the global fallback and breaker-gate paths blew up — surfacing as "All models failed | PROVIDER_BREAKER_FAILURE_STATUSES is not defined" and breaking the handleChat coverage tests (combo-error passthrough, 503 for cooled-down/open-breaker, budget-error, model cooldown, body-derived retry-after, non-JSON rate-limit bodies). Fix: export the const from chatPredicates.ts and import it in chat.ts (one canonical definition, restoring the pre-refactor behavior). Validated: chat-route-coverage 15/0 (was 12/3), chat-cooldown-aware-retry 6/0, chat-rate-limit-body-lock 2/0; breaker guards (7907, combo-breaker-429, openrouter-6842) unchanged; typecheck:core clean. --- src/sse/handlers/chat.ts | 1 + src/sse/handlers/chatPredicates.ts | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/sse/handlers/chat.ts b/src/sse/handlers/chat.ts index 5ba707fd37..73dfbeb74a 100644 --- a/src/sse/handlers/chat.ts +++ b/src/sse/handlers/chat.ts @@ -75,6 +75,7 @@ import { import { isAntigravityMissingProjectError, shouldTripProviderBreakerForResult, + PROVIDER_BREAKER_FAILURE_STATUSES, } from "./chatPredicates"; import { connectionHasExtraKeys } from "@omniroute/open-sse/services/apiKeyRotator.ts"; import { diff --git a/src/sse/handlers/chatPredicates.ts b/src/sse/handlers/chatPredicates.ts index a45dbc4d5a..fd14015c8d 100644 --- a/src/sse/handlers/chatPredicates.ts +++ b/src/sse/handlers/chatPredicates.ts @@ -1,7 +1,7 @@ import { isLocalStreamLifecycleError } from "../../shared/utils/circuitBreaker"; import { isRequestScopedUpstreamFailure } from "./comboFailureLogging"; -const PROVIDER_BREAKER_FAILURE_STATUSES = new Set([408, 500, 502, 503, 504]); +export const PROVIDER_BREAKER_FAILURE_STATUSES = new Set([408, 500, 502, 503, 504]); // #7907/#7908: single-model breaker trip bypasses the `isFailure` option (only applies // inside `breaker.execute()`), so it needs its own `isLocalStreamLifecycleError` guard —