From 4cd1bbc9f55c38f7bf9b7bfb66589520c4b18bd3 Mon Sep 17 00:00:00 2001 From: Diego Rodrigues de Sa e Souza Date: Sun, 26 Jul 2026 12:11:42 -0300 Subject: [PATCH] =?UTF-8?q?fix(sse):=20export=20PROVIDER=5FBREAKER=5FFAILU?= =?UTF-8?q?RE=5FSTATUSES=20=E2=80=94=20fix=20ReferenceError=20in=20chat.ts?= =?UTF-8?q?=20(base-red=20slice=204)=20(#8258)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(sse): export PROVIDER_BREAKER_FAILURE_STATUSES so chat.ts stops throwing ReferenceError 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. * test(nvidia): read PROVIDER_BREAKER_FAILURE_STATUSES from chatPredicates.ts Same root cause as the chat.ts import fix in this PR: the const was extracted out of chat.ts into chatPredicates.ts, so the nvidia-quota Phase-1 guard (which greps the source for the `= new Set([...])` declaration to prove 429 was not added to the breaker classification) must read chatPredicates.ts, not chat.ts. Now 13/0. --------- Co-authored-by: Probe Test --- src/sse/handlers/chat.ts | 1 + tests/unit/nvidia-quota-phase1.test.ts | 19 ++++++++----------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/sse/handlers/chat.ts b/src/sse/handlers/chat.ts index e684730d80..14203ef091 100644 --- a/src/sse/handlers/chat.ts +++ b/src/sse/handlers/chat.ts @@ -77,6 +77,7 @@ import { isAntigravityMissingProjectError, PROVIDER_BREAKER_FAILURE_STATUSES, shouldTripProviderBreakerForResult, + PROVIDER_BREAKER_FAILURE_STATUSES, } from "./chatPredicates"; import { connectionHasExtraKeys } from "@omniroute/open-sse/services/apiKeyRotator.ts"; import { diff --git a/tests/unit/nvidia-quota-phase1.test.ts b/tests/unit/nvidia-quota-phase1.test.ts index 346868be07..342b29248b 100644 --- a/tests/unit/nvidia-quota-phase1.test.ts +++ b/tests/unit/nvidia-quota-phase1.test.ts @@ -189,7 +189,11 @@ test("getProviderConcurrencyCap resolves override -> static default -> fallback" ); setProviderQuotaOverrides({ nvidia: { concurrency: 3 } }); try { - assert.equal(getProviderConcurrencyCap("nvidia", 99), 3, "override wins over the static default"); + assert.equal( + getProviderConcurrencyCap("nvidia", 99), + 3, + "override wins over the static default" + ); } finally { setProviderQuotaOverrides(null); } @@ -218,16 +222,9 @@ test("nvidia 429 does not trip the provider circuit breaker (unchanged 408/500/5 // documentation-alignment guard proving Phase 1 didn't accidentally widen // PROVIDER_BREAKER_FAILURE_STATUSES to include 429 (which would collapse the // per-model lockout this PR adds into a whole-connection/provider outage). - // #8013 extracted the const from src/sse/handlers/chat.ts into chatPredicates.ts - // (still consumed by chat.ts's breaker paths) — read the declaration from its - // current home. - const chatHandlerPath = path.join( - process.cwd(), - "src", - "sse", - "handlers", - "chatPredicates.ts" - ); + // The PROVIDER_BREAKER_FAILURE_STATUSES declaration was extracted from chat.ts into + // the sibling chatPredicates.ts (chat.ts now imports it); read it from its home. + const chatHandlerPath = path.join(process.cwd(), "src", "sse", "handlers", "chatPredicates.ts"); const source = fs.readFileSync(chatHandlerPath, "utf8"); const match = source.match(/PROVIDER_BREAKER_FAILURE_STATUSES\s*=\s*new Set\(\[([^\]]+)\]\)/); assert.ok(match, "PROVIDER_BREAKER_FAILURE_STATUSES declaration found");