fix(resilience): don't clear an active rate-limit cooldown for non-quota_exhausted errors (#11277) - #11310
Merged
diegosouzapw merged 1 commit intoAug 24, 2026
Conversation
…ota_exhausted errors (#11277) maybeClearRecoveredQuotaState() only guarded against clearing a still-future rateLimitedUntil inside the lastErrorType === "quota_exhausted" branch. Any other lastErrorType (rate_limited, free_quota_exhausted, etc.) skipped straight to clearRecoveredProviderState() with no future-cooldown check at all, so a multi-day cooldown got wiped on the next quota sync a few minutes later — a self-restart loop burning real upstream calls against a known-exhausted connection. Added a universal fallback guard for every other lastErrorType: a future rateLimitedUntil is a hard statement from whatever handler persisted it, and no quota poll finding some usable window elsewhere may overrule it. Also fixed a pre-existing test that encoded the same defect class with a shorter window (asserted a still-future cooldown got cleared by a successful refresh) and added a regression test pinning the new guard.
muhamadgalihsaputra
pushed a commit
to niyatna/NiyatnaRoute
that referenced
this pull request
Sep 27, 2026
…ota_exhausted errors (diegosouzapw#11277) (diegosouzapw#11310) Merging --admin: only fails are ESLint warnings ratchet drift (inherited base-red) and dast-smoke (advisory, isRequired:null). Zero overlap with this PR's scope (src/lib/usage/providerLimits.ts).
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.
What
maybeClearRecoveredQuotaState()(src/lib/usage/providerLimits.ts:462) only guarded against clearing a still-futurerateLimitedUntilinside thelastErrorType === "quota_exhausted"branch. Any otherlastErrorType(rate_limited,free_quota_exhausted, etc.) skipped straight toclearRecoveredProviderState()with no future-cooldown check at all.In production this caused a self-restart loop: a 146-hour cooldown got cleared every few minutes by the periodic quota sync, the connection went back to priority position 1, burned a real upstream call, took the same 429, was cooled down again, and the next sync cleared it again.
Fix
Added a universal fallback guard: for every
lastErrorTypeother thanquota_exhausted, ifrateLimitedUntilis still in the future, don't clear. A futurerateLimitedUntilis a hard statement made by the handler that persisted it — no quota poll finding some usable window elsewhere should be able to overrule it.Also fixed a pre-existing test (
provider-limits-recovery.test.ts) that encoded the same defect class with a shorter window — it asserted a still-future cooldown got cleared by a successful refresh, which was the bug, just less visible.Validation (TDD, Hard Rule #18)
New test:
a still-future rateLimitedUntil is not cleared by a successful quota refresh, regardless of lastErrorType (#11277)— RED before the fix, GREEN after. Fullprovider-limits-recovery.test.tssuite: 15/15 pass.typecheck:coreclean. ESLint clean on both touched files.Closes #11277