fix(routing): skip known-exhausted accounts at admission#57
Open
iceteaSA wants to merge 4 commits into
Open
Conversation
There was a problem hiding this comment.
All reported issues were addressed across 10 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
iceteaSA
force-pushed
the
fix/routing-skip-exhausted
branch
from
July 22, 2026 10:03
d5f1fdd to
8dfde55
Compare
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.
Why
Rate-limit marks are per-process and in-memory. With several concurrent opencode processes and
fallback-firstrouting pinned at an exhausted account, every process independently pays one doomed admission probe (admission-timeusage_limit_reached→ mark → retryable error → reroute) before learning what the machine-global sidebar file already knows: the account is at 100% with a reset days away. The operator sees each discovery as a visible retry/error flash.What
Admission-time candidate selection now consults quota before probing:
primary.checkedAt, then snapshotcheckedAt, then entrycheckedAt). The fresher source is selected — the file wins only when strictly newer, memory wins ties, and an empty in-memory cache (fresh process) defers to a valid file row.isQuotaExhausted(type-safe, fail-open) is applied only to the selected source.fallback-first) gate and the reactive iterator via a shared memoized selection.quota-exhausted,Retry-Afterfrom the account's ownresetsAt) so the reroute happens without the doomed probe — only when a non-exhausted fallback survives.admission skip: exhausted account {accountId, source, resetsAt}.Verification
client-alt, gotwork-alt), fresh-process file exhaustion, newer-exhausted-file vs stale-healthy-memory, exhausted primary reroute — all fail pre-fix; 7 fail-open characterizations proven non-vacuous by reverse-applying the src diff (they pass on reverted source, i.e. they pin non-interference).Need help on this PR? Tag
/codesmithwith what you need. Autofix is disabled.Summary by cubic
Skip probing accounts that are already quota‑exhausted at admission by using the freshest quota from memory or the shared sidebar, and add a background quota refresh to keep snapshots current and reduce error flashes. Also fixes stale per‑session active account display and prevents fresher on‑disk quota from being clobbered.
New Features
getSidebarStateand respectsmainAccountId), drops exhausted fallbacks, and if main is exhausted returns a synthetic 429 (quota-exhausted) with Retry‑After from itsresetsAt; proactive and reactive fallback paths share this selection and log skips.BackgroundQuotaRefresh/refreshQuotaInBackground) runs ~every 5m with ±30s jitter, respects backoff, skips snapshots fresher than 4m (using memory or the shared sidebar), keeps one in‑flight run, and writes the sidebar only when quota changed.checkedAtfor main/fallbacks, addmainAccountId, addisQuotaExhausted, ignore exhausted entries inresolveSessionSidebarRouting, and record routing for a parent session viax-parent-session-id.Bug Fixes
setSidebarMachineStatemerges quota by freshness per account and never carries main quota across identities, fixing stale per‑session active account displays.Written for commit 8dfde55. Summary will update on new commits.