GeezerVison is showing github.com — Provider availability: one state machine for quota / rate-limit / unknown / infra stops · Issue #1828 · developing-today-forks/opencode
Provider availability: one state machine for quota / rate-limit / unknown / infra stops #1828DescriptionProvider availability: one state machine for quota / rate-limit / unknown / infra stops (Drew, 2026-11-06)
Drew's spec, verbatim intent:
make a system to show available providers that aren't errored or showing max quota or empty api balance. make providers stop trying when quota burned until it shows an increase, stop rate limit until retry after, block provider for increasing times if errors unknown. if its erroring because it can't route like our dns or the opencode server is having issues or something it shouldn't be exactly same, should wait until [the path] starts working again etc
And the binding design principle: plan seats are never removed/re-added around quota walls. Config is the standing design; availability is a dynamic routing-layer state. commandcode sits in disabled_providers today only because this system was missing — the router kept trying an erroring provider, throwing errors and adding delay even when calls ultimately succeeded. Seamlessness is the core acceptance property: a stopped provider costs a session ~nothing.
This generalizes the #1806 defect family (it does not duplicate it: #1806 tracks the resolver cascade — sticky pin, pool-level tried-set, worst-credential judging; this issue is the availability/classification layer underneath, plus the two #1806 secondaries that live here: the flat cooldown ignoring the provider-stated reset, and the AG-vs-Mistral classification split).
What already exists (built on, not rebuilt)
- Benches (
model-route.ts bench()): escalating ladder per consecutive failure; a stated retry-after is believed as-is; quota benches bounded by a trustworthy window reset with a single half-open probe at the reset (fix(core): quota bench escalates to 24h decoupled from the provider window reset — benched credential can never earn the success that clears it #1123, core(model-routing): bench probe claim release gaps in non-title resolution consumers (compaction, resolver load failure, runner failover) #1486).
- Quota gates: per-credential and per-provider gates fed by the quota subsystem (the single quota source); balance holds are increase-only with no expiry (ensure(core+openchamber): repeated errors of ANY class remove a model from rotation for escalating time, or until its expected resolution #1014, fix(core): #1014 follow-ups — stale balance holds on deleted/reclassified plans + balance-exhaustion classification breadth #1380); known-full snapshots gate until their reset; re-admission on a not-full reading is logged (
quota-readmitted).
- Rate-limit window holds from response headers (
ModelRouteLimits snapshots; fix(routes): thread the credential dimension through restore, escalation, ranking, rate-limit holds and catalog headers (PR #854 follow-up) #870).
- Correlated-transport forgiveness (
networkSuspect): transport failures across unrelated providers clear each other's benches (fix(core): networkSuspect cooldown undo leaves consecutiveFailures incremented, so the next failure after an outage gets a doubled bench #1034).
route_health / route_attempt ledgers and the route-stats tool, which already exposes activeBenches (stopped targets with reason + until).
Gaps this design closes
- Classification split (fix(core): route failover traps sessions on a quota-walled member — sticky pin + fallback never re-draws the origin pool (89 sessions died 2026-11-05 while Luna served 3,149 successes in the same route) #1806 secondary). The identical condition — window quota exhausted — classifies as
QuotaExceeded (quota bench) for Mistral but RateLimit/retryable for Antigravity, whose reset is stated only in message text ("Individual quota reached… Resets in 81h35m49s"). The hint layer must recognize a quota statement in text, and bind the stated reset to the bench.
- No infra class. A DNS failure (
ENOTFOUND), a refused connection (ECONNREFUSED), or a dead local service is not a provider being unhealthy: the request never reached an API, it says nothing about quota or balance, and it must not escalate the provider's error standing. Today it rides the same bench ladder as a provider 500.
- Quota benches don't hear the quota feed. Gates re-admit on a measured increase; benches only wait out their timer/reset. Drew's rule — stop until it shows an increase — must apply to benches too: a fresh, known, not-full quota reading for the scope releases quota-class benches early.
- The availability surface is partial.
activeBenches shows benches only. A provider stopped by a balance hold, a quota gate, a rate-limit window hold, or (new) an infra hold is invisible in the readout. Drew asked for one surface: which providers are available, which are stopped, why, until when, and what resumes them.
The availability state machine
Per provider / credential / target (finest scope that carries evidence wins; a leaf is unavailable when any scope that binds it is stopped):
| State |
Entered by |
Router behavior |
Resume rule |
| available |
— (default; also every release below) |
candidate normally |
— |
| quota-stopped |
QuotaExceeded tag, or a quota statement in error text (window exhaustion wording); known-full quota snapshot |
not a candidate; attempts trend to zero |
measured increase: a fresh known quota reading for the scope shows headroom (not-full) — or the window's stated reset passes (one half-open probe at the reset, full release on probe success) |
| balance-stopped |
balance-exhaustion evidence only (QuotaExceeded tag or credit/balance-specific text — #1380's bar) |
not a candidate, no expiry |
measured balance increase over the benched baseline (existing increase-only hold) |
| ratelimit-stopped |
HTTP 429 / RateLimit without quota evidence; provider rate-limit window snapshots |
not a candidate |
the provider-stated retry-after timestamp (header, details, or message text), believed as-is, never multiplied |
| unknown-blocked |
any other failure (5xx, unrecognized errors) |
not a candidate |
escalating timer: base bench × multiplier per consecutive failure, capped; a success resets the count |
| infra-held |
transport path failures whose OS code proves the request never reached an API: ENOTFOUND / EAI_AGAIN (DNS), ECONNREFUSED (dead local service / proxy) |
not a candidate (sessions fail over silently) |
path-health: short fixed cadence holds (30s → 60s → 120s → 240s, cap 5 min); first success on the target clears the hold. Infra failures never increment the unknown-error escalation count, never plant quota/balance evidence, never gate a pool |
| auth-stopped |
401/403, org-disabled credential |
not a candidate |
long bench (existing): it cannot heal by itself; resumes on timer or credential change |
Classification precedence on one failure: balance evidence → balance-stopped (plus quota bench accounting) · quota tag/text → quota-stopped · retry-after present → ratelimit-stopped · infra code → infra-held · auth → auth-stopped · else unknown-blocked. A stated retry-after on a quota failure is believed for the bench length, but the bench stays quota-class and bound by the stated reset.
Stale-read doctrine (standing): a failed or stale quota read never idles a pool and never releases a stop — releases require a known, fresh reading.
Availability surface
ModelRoute.availability(now) in packages/core/src/model-route.ts, merging every stop in force — benches, quota gates, balance holds, rate-limit window holds, infra holds — into one list of { providerID, modelID?, credentialID?, class, reason, until?, resume } where resume ∈ reset | increase | retry-after | timer | path. It is exposed through the existing route-stats tool output (new availability field beside benches) — the surface the fleet already reads — rather than a new silo. Absence from the list = available. The effective stop for a leaf is the latest until among its entries (a balance hold has no until: it is stopped until an increase is measured).
Acceptance (harness scenarios, mock-provider fixtures)
- Quota burn (AG-shaped text wall and Mistral-shaped tag) classifies identically as quota; the bench binds the stated reset; attempts to the walled member trend to zero while blocked.
- A fresh not-full quota reading releases a quota bench before its reset; a stale/unknown reading releases nothing.
- A 429 with retry-after resumes at the retry-after, not before, and the wait is never multiplied.
- Unknown errors escalate: successive benches grow by the ladder multiplier; a success resets the count.
- Seamlessness: a pool with one permanently erroring member serves every step on its sibling; after the first bench, attempts to the bad member stay at zero while it is stopped; the session sees no error.
- A DNS failure fails over, holds as infra on the short cadence, and leaves the target's unknown-error count and quota standing untouched; the next success after the hold clears it.
- A balance hold still releases only on a measured increase (regression guard for ensure(core+openchamber): repeated errors of ANY class remove a model from rotation for escalating time, or until its expected resolution #1014).
Proving case
commandcode comes out of disabled_providers only when the seamlessness acceptance is demonstrable: harness scenarios green and a driven live session against a deliberately failing leaf completing on siblings with attempts-to-the-bad-leaf trending to zero. Prepared as a config PR in developing-today/code with the evidence attached; merged only if both legs pass.
Related: #1806 (resolver cascade family), #1014 / #1380 (balance holds), #1123 / #1486 (reset-bound benches + probes), #870 (rate-limit windows), #1034 (transport forgiveness), PR #1807 (mock harness). Activitydezren39 commented on Nov 6, 2026 Results — implemented, tested, live-proven, and the proving case merged
Implementation: PR #1832, merged as 6b178f665a. Proving case: code PR #6503, merged e4742dc384 — commandcode is out of disabled_providers and the fork pin carries this system (aba451ef); both activate at the next switch.
What landed, against the design above
- Classification parity.
SessionStep.failureHint classifies quota from error text as well as the QuotaExceeded tag (narrow quotaText: individual quota / quota exhausted-reached-exceeded / insufficient credits-balance-funds / out of credits / usage limit / reached your limit), and extracts the provider-stated reset (resetAtFromMessage) into the hint. Antigravity's wall and Mistral's tag now produce the same hint, bench class, and availability class. The bench binds the earliest trustworthy reset (snapshot-derived or error-stated) — mechanism 4 of fix(core): route failover traps sessions on a quota-walled member — sticky pin + fallback never re-draws the origin pool (89 sessions died 2026-11-05 while Luna served 3,149 successes in the same route) #1806, generalized.
- Measured-increase release. Fresh, known, not-full readings through the existing
observeProviderQuota / observeCredentialQuotaState funnels release that scope's quota-class benches immediately. Stale/unknown readings release nothing (tested).
- Infra holds. Transport failures with ENOTFOUND / EAI_AGAIN / ECONNREFUSED and no HTTP response take a hold (30s→60s→120s→240s, cap 5min) instead of a bench: no escalation count, no quota accounting, no pool gating; folded into
cooldownUntil so every candidacy check skips the target; first success clears it. Kept downstream of networkSuspect correlation handling.
- Availability surface.
ModelRoute.availability(now) merges benches, quota gates + balance holds, rate-limit window holds, and infra holds into {providerID, modelID?, credentialID?, class, reason, until?, resume} entries, exposed on the route-stats tool beside benches. Balance holds carry no until and subsume their gate entry.
- Unchanged by design: retry-after believed, never multiplied; unknown errors keep the existing ladder; auth keeps its ladder; balance holds keep increase-over-baseline.
Acceptance, item by item
- AG wall ≡ Mistral quota: same class, reset-bound bench — ✅ harness (
model-route-availability.test.ts, 12 scenarios).
- Quota stops until measured increase (provider + credential scope); stale readings free nothing — ✅ harness.
- 429 stops until the stated retry-after (120s honored to the second, never multiplied) — ✅ harness.
- Unknown errors escalate 60s→120s→240s; a success resets the ladder — ✅ harness.
- Infra failure: no bench, no quota evidence, error ladder untouched (a following unknown error benches at the 60s base), cadence lapse + escalation, success clears — ✅ harness.
- Seamlessness — ✅ harness (bad member: exactly 1 attempt across 5 sessions) and live (below).
- Availability surface shows class/reason/until/resume for every stop in force — ✅ unit-tested per class; exposed on route-stats.
Full @opencode/core suite: 1414 pass / 0 fail; tsc --noEmit clean.
Live leg (driven session, deliberately failing leaf)
A scratch server built from the merged fork (systemd user unit, isolated XDG data/config, production untouched) ran route livetest = ordered [deadleaf — local mock, always HTTP 500; goodleaf — local mock, canned SSE]. Three sessions driven over the HTTP API:
- All 3 sessions succeeded, served by goodleaf (
route_attempt: goodleaf success ×3).
- The dead leaf was attempted only in session 1's opening race (title generation + first prompt in flight before the first failure was recorded), then zero attempts in sessions 2–3;
failed_over_to = goodleaf/good-model recorded on the failover; route_health shows its cooldown-start.
That is the property whose absence put commandcode in disabled_providers. Closing this issue as complete; the remaining #1806 resolver items (sticky pin, tried-set, worst-credential judging) stay open there — this system neither needed nor touched them. dezren39 commented on Nov 6, 2026 Correction to the test figures in the results above
The "1414 pass / 0 fail" full-suite figure quoted in my results comment (and in PR #1832 / code PR anomalyco#6503) came from a background tool delivery that proved unreliable on re-check, so I re-ran the full @opencode/core suite detached, writing to a log file read back directly. The true figures:
Full suite on the merged branch: 8206 pass / 15 skip / 11 fail (8232 tests, 343 files). All 11 failures are accounted for and none is a regression from this change:
DatabaseMigration > declared schema has no ungenerated migrations — fails identically on pristine origin/main (verified in a clean worktree).
Core test environment > isolates global home and XDG roots — fails identically on pristine origin/main.
native in-process embeddings backend ×4 — fail identically on pristine origin/main (the parity backend isn't available in this environment).
Session.shell ×5 — 30s timeouts under the loaded full-suite run; the same file passes 9/9 in isolation on both pristine main and this branch.
Everything that exercises the changed code was verified in foreground runs: availability + mock-provider 34 pass / 1 pre-existing skip; the model-route family 409 pass; resolver/title/tuning/persona 127 pass; session runner + step 298 pass (the 3 initial failureHint shape failures were fixed by omitting unset hint fields, per the codebase convention); tsc --noEmit clean. The live-session evidence stands as reported (it was read from the scratch server's own route_attempt / route_health tables and the mock leaves' counters, not from tool narration).
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|