Repository navigation
fix(providers): carve cookie-auth providers out of terminal 401 'expired' classification so one 401 cooldowns instead of killing the connection - #8321
Merged
diegosouzapw merged 1 commit intoJul 24, 2026
Conversation
…red' classification so one 401 cooldowns instead of killing the connection
HouMinXi
pushed a commit
to HouMinXi/OmniRoute
that referenced
this pull request
Aug 2, 2026
…red' classification so one 401 cooldowns instead of killing the connection (cheaper-inference#8321)
muhamadgalihsaputra
pushed a commit
to niyatna/NiyatnaRoute
that referenced
this pull request
Sep 27, 2026
…red' classification so one 401 cooldowns instead of killing the connection (cheaper-inference#8321)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #8200 (part A — one-401 terminal misclassification fixed; part B cookie rotation/keepalive tracked as follow-up, issue kept open)
Root cause
src/sse/services/auth.ts::resolveTerminalConnectionStatus()mapped ANY HTTP 401that wasn't classified
OAUTH_INVALID_TOKEN/PROJECT_ROUTE_ERRORto the TERMINALtestStatus: "expired"via the fallthroughproviderErrorType === UNAUTHORIZED || status === 401.perplexity-webis registeredauthType: "apikey"(cookie-based),so its recoverable session-expiry 401s went through
classifyProviderError()as plainUNAUTHORIZEDand landed on the terminal branch — withcheckFallbackError'sstatus_401rule giving a hard-codedcooldownMs: 0,markAccountUnavailable()persisted a permanent
testStatus: "expired"on the very first 401. ThengetProviderCredentials()filters connections viaisTerminalConnectionStatus()regardless of
isActive, so the connection dropped out of selection on the nextrequest, surfacing as
404 No active credentials for provider: perplexity-web—even though the row stayed
is_active=1and the account was still configured.This 401→expired mapping is intentional/tested for ordinary API-key providers, but
perplexity-web(and other cookie/session-auth providers) had no carve-out — unlikegrok-web, which already gets a non-terminal, mode-local lockout for its 403s.Fix
Added a
providerparameter toresolveTerminalConnectionStatus()and a smallisRecoverableCookieAuth401()helper: a 401/UNAUTHORIZEDclassification on anyprovider registered in
WEB_COOKIE_PROVIDERS(perplexity-web, grok-web, etc.) is nowrouted to the ordinary recoverable-cooldown path instead of the zero-cooldown terminal
expiredpath — mirroring the existing OAuth-invalid-token / grok-web carve-outs.ACCOUNT_DEACTIVATED(a confirmed permanent signal) is explicitly excluded from thecarve-out, so genuine terminal bans still terminal-expire.
Scoped strictly to this issue: no changes to cookie rotation/
Set-Cookiecapture(issue's part B) — that is tracked separately and is a larger, independently-testable
change (new
mergeRefreshedCookie-style helper + executor wiring) that this reprodoes not cover.
TDD evidence (Hard Rule #18)
New permanent regression test:
tests/unit/8200-perplexity-web-401-cooldown.test.tsRED (before fix):
GREEN (after fix):
Sibling tests re-run and green:
tests/unit/auth-terminal-status.test.ts(10/10),tests/unit/auth-ollama-cloud-per-model-403-3027.test.ts(3/3),tests/unit/combo-skip-conn-disable-plugin-block-7806.test.ts(4/4),tests/unit/perplexity-web.test.ts(31/31).Gates run
node scripts/check/check-file-size.mjs→ OK (src/sse/services/auth.ts2461 lines, under the 2462 baseline)node scripts/check/check-complexity.mjs→ pre-existing repo-wide drift (2167 vs baseline 2130) confirmed identical on a cleanorigin/release/v3.8.49probe worktree — not introduced by this diff; touched functions have zero reported violationsnode scripts/check/check-cognitive-complexity.mjs→ same pre-existing drift confirmed (956 vs baseline 951 on both this branch and the pure tip)npm run typecheck:core→ exit 0npx eslint --suppressions-location config/quality/eslint-suppressions.json src/sse/services/auth.ts tests/unit/8200-perplexity-web-401-cooldown.test.ts→ exit 0node scripts/check/check-changelog-integrity.mjs→ OKRelated
PR #8201 (same reporter) proposed essentially this diagnosis + a cookie-rotation
follow-up but was closed for catastrophic base drift (547 files, diff exceeded
GitHub's API limit), not on technical merits. This PR is a fresh, focused
implementation off the current
release/v3.8.49tip covering part (A) of thatdiagnosis, proven by a clean TDD repro.