GeezerVison is showing github.com — router: auto-disable providers at 100% quota until a fresh read shows headroom (cline-pass, commandcode, go) · Issue #984 · developing-today-forks/opencode
router: auto-disable providers at 100% quota until a fresh read shows headroom (cline-pass, commandcode, go) #984DescriptionDrew's directive (2026-10-30)
OpenCode should disable a provider on its own when the provider's quota reads 100% (exhausted), and keep it disabled until a regular quota read shows less than 100% again. Fix at the source (the router), not by editing pools in config. Named cases: cline-pass and commandcode; the mechanism must be general (opencode-go workspaces hit the same wall).
Live evidence (laptop route_attempt ledger, 2026-10-30)
Six probe turns through the default workhorse route after the 07:17 CDT server restart. Every single turn walked the same gauntlet before succeeding:
- opencode-go.personal / .lab / (base) —
QuotaExceeded "Go usage limit exceeded" (retry-after ≈ 313,773s)
- cline-pass —
RateLimit 429 "You have reached your monthly Clinepass limit" (monthly 100%, resets ~Nov 5)
- commandcode ×2 —
UnknownProvider wrapping "insufficient credits" (its $10 credit is spent; resets Nov 2)
- muse / openai — success
Last 6h totals: cline-pass 138 attempts, 138 failures. Last 30 min: 253 attempts for 164 successes — roughly a third of all attempts are known-dead doors being tried first. Each doomed attempt costs a network round trip before the first token, so this is also the fleet's biggest avoidable TTFT tax.
Required behavior
- The router already ingests quota signal (route_attempt.quota; the laptop quota-gatherer records per-pool reads). When a provider's current quota read is ≥100% / exhausted — or an attempt returns a quota-exhaustion error (429 limit, QuotaExceeded, insufficient-credits) — mark the provider gated and exclude it from route candidacy before attempting.
- The gate lifts automatically when a subsequent regular quota read shows <100% (or the recorded reset time passes and a probe/read confirms headroom). No config edit, no restart, no manual step.
- Gating is per provider (per workspace for opencode-go.*), never per model.
- Ledger: gated providers should still be visible in diagnostics as gated-with-reason, not silently absent.
Acceptance
- With cline-pass at monthly 100%, a workhorse turn records zero cline-pass attempts.
- Same for commandcode while its credits read exhausted, and for any opencode-go workspace whose limit is hit.
- When a pool's read drops below 100% (e.g. OpenRouter/Command Code resets), its leaves rejoin routes without a config change or restart.
- Existing behavior otherwise unchanged: failover across live leaves still works; quota demotion semantics already in the router are the starting point — this makes the gate pre-attempt instead of post-failure.
Activitydezren39 commented on Oct 30, 2026 Intake review
Fleet monitor intake pass (2026-10-30 run). Labels normalised this pass: kind/enhancement, priority/high, effort/m, status/needs-triage, app/core, source/human, meta/enriched. The body's existing ## Acceptance section is retained as the acceptance criteria (no duplicate section appended).
Partially solved — do NOT close: PR #991 ("feat(core): gate quota-exhausted pools until their stated reset (#984)", merged 2026-10-30T13:27Z) implements what its own description calls the reactive half of this issue: a provider that answers an attempt on quota grounds is gated until its stated reset, per-credential, with re-admission when a fresher below-limit snapshot arrives. Code PR #2746 already bumps the opencode input carrying it.
What remains (the proactive half): this issue's required behaviour also gates before the first doomed attempt — when a regular quota read already shows a provider at ≥100% / exhausted, route candidacy excludes it without needing a fresh failure (the body's acceptance: "a workhorse turn records zero cline-pass attempts" while cline-pass reads 100%). PR #991's gate is armed by an observed failure or a synthesized known-full snapshot from an attempt; a provider already known-full from the quota-gatherer at turn start, with no attempt yet this session, is the remaining case to verify and close.
Related: developing-today/code#2732 (the fleet-side sibling: seating-time pace guards for dispatcher/lane seatings — same principle one layer up).
Suggested approach: verify the remaining case empirically against the route_attempt ledger (turns started while cline-pass reads monthly 100%: count cline-pass attempts), then wire the quota-gatherer's current reads into candidacy if the gap is real, reusing #991's gate machinery rather than adding a second gate. dezren39 commented on Oct 30, 2026 Triage evidence — issue-sweep-rotating (feeder), 2026-10-30
Verified fresh against current main d2af8df514 (local clone at that exact SHA, code reading only):
What already landed (reactive half): PR #991 (merged 2026-10-30T13:27Z) added ModelRoute.observeQuotaFailure at packages/core/src/model-route.ts:532 — one attempt's quota-exhaustion answer gates its credential (or, for a credential-less provider, a skip adjustment on the provider) until the stated reset, 30-day cap / 30-minute fallback. Its only production caller is packages/core/src/session/runner/step.ts:449.
The remaining gap (proactive half) is still present:
ModelRoute.observeCredentialQuota (model-route.ts:495) is the proactive gate: a known-full snapshot gates a credential out before any attempt, and model-resolver.ts:565 honours it via credentialQuotaBlocked.
- Grep across
packages/ for production callers of observeCredentialQuota: none. The only references are its definition, observeQuotaFailure's internal synthesis at model-route.ts:540, and tests (model-route-credential.test.ts, model-resolver.test.ts). No quota-gatherer / snapshot producer feeds current quota reads into it at turn start.
- Credential-less providers (the body's named cases, cline-pass and commandcode) have no proactive path at all: their only gate is the reactive
skip adjustment, which is armed only after a first doomed attempt in this session.
So the acceptance case — a fresh workhorse turn recording zero cline-pass attempts while cline-pass reads monthly 100% — is not yet met when the provider is already known-full from regular quota reads but has not failed yet this session.
Done looks like: current quota reads are fed into the existing gate machinery before route candidacy (credential gate where a credential exists; an equivalent provider-level gate for credential-less providers), gated providers stay visible in diagnostics as gated-with-reason, a fresher below-100% snapshot (or a passed reset plus a confirming read) re-admits automatically with no config edit or restart, and a test pins zero attempts for a known-full provider at turn start.
Enqueueing this as a triage packet to repo-health-opencode-pilot for the queue lane to verify the ledger case and implement/wire the proactive feed.
dezren39 commented on Oct 30, 2026 agent-note:v1
state: queued
Agent: issue-sweep-rotating (triage feeder)
Session/ID: issue-sweep-rotating run 2026-10-30 17:24 CDT
Found via: feeder triage (evidence comment 6534885631)
Task: Enqueued triage packet to repo-health-opencode-pilot as task 4017 (dedupe repo-health:v1:triage:developing-today/opencode:issue:984; packet hidden_files/packet-opencode-984-triage.json)
Expectation: queue lane verifies the known-full-at-turn-start ledger case and routes the proactive gate wiring; feeder took no implementation action.
dezren39 commented on Oct 30, 2026 Design note — proactive gate wiring (queue task 4028, lane A worker)
Verified on origin/main be8dd99 this shift; implementation parked for a fresh full shift rather than rushed into the routing core in a 45-minute remainder (packet timebox 45m understates this effort/m change — see estimate below). Wiring points, all confirmed by reading the code:
Feed point. model-resolver.ts resolveRoute: credentialByProvider is built just before the candidacy loop, and the loop's ready filter already honours ModelRoute.credentialQuotaBlocked (:565, plus :594 last-resort and :676 credential fallback). Feed derived snapshots once per top-level resolution, immediately after credentialByProvider is built and before the while loop — resolveRoute recurses for fallbacks, so guard the feed with a process-local TTL (suggested 60s, in the resolver or a ModelRoute module timestamp) or candidacy pays a plans-store + DB read per fallback hop.
Derivation. Exactly the route-usage.ts pattern, which is the only production derivation today: ModelPlan.readStore(dataDir).plans → per plan, per quota window with windowHours defined → ModelRouteLog.withDb + targetUsage(db, now - windowHours) → ModelUsage.sum(rows.filter(providerID === plan.providerID)) → QuotaSnapshot.deriveAll(plans, totals, observedAt = now, { now }) (a fresh DB read, so observedAt = now and snapshots are fresh by construction). Open point for the implementing lane: which dataDir the resolver service can reach — the plan tools take options.dataDir; find the resolver's equivalent (Global/location context) rather than inventing a path.
Credential arm. For each snapshot and each route target with target.providerID === snapshot.providerID whose provider has an active credential in credentialByProvider: ModelRoute.observeCredentialQuota(target, credentialID, snapshot, now). No new gate — re-admission (fresher below-100% snapshot, or reset passing) is already credentialQuotaBlocked's contract.
Credential-less arm (cline-pass, commandcode). Add one exported primitive to model-route.ts, e.g. observeProviderQuota(target, snapshot, now): when QuotaSnapshot.isKnownFull(snapshot, now), arm the same skip adjustment observeQuotaFailure's credential-less arm uses (id: quota:<providerID>, match: <providerID>/, action: "skip", note naming the proactive read), with until = min(snapshot.resetAt ?? now + QUOTA_GATE_FALLBACK_MS, now + QUOTA_GATE_MAX_MS), and logHealth(target, "quota-gated", "provider:<id> quota-known-full", resetAt). Re-feeding at each candidacy re-arms while reads stay full; when a fresher read drops below 100% nothing re-arms and the adjustment expires — last-resort semantics stay the skip store's (a route with no other door still tries it). Diagnostics: gated targets already surface in the resolver's unavailable map via skipped(), plus the route_health quota-gated row. Per-workspace opencode-go is covered: providerID distinguishes workspaces and its credentials take the credential arm.
Tests. (1) model-route unit tests for observeProviderQuota: known-full arms the skip and skipped() honours it, a passed reset re-admits, an unknown/stale snapshot never arms, reset capping matches observeQuotaFailure. (2) A resolver-level test that a known-full snapshot fed at candidacy records zero attempts for the provider (the acceptance case) — needs the dataDir/DB fixture the implementing lane settles above. (3) Existing suites must pass: model-route, model-route-credential, model-resolver, quota-snapshot.
Estimate. Implementation + tests ≈ one full worker shift with verification; the routing core is the wrong place for a partial, unverified version of this.
dezren39 commented on Oct 30, 2026 agent-note:v1
state: picked-up
Agent: openchamber-scheduled-lane (repo-worker-opencode)
Session/ID: ses_e5e70d0bddfffebHLE0mvgICsZ
Found via: queue claim (task 4028, repo-health-opencode-pilot)
Task: Resuming task 4028 — implementing proactive gate wiring (#984 proactive half) per design note.
dezren39 commented on Oct 30, 2026 agent-note:v1
state: done
Agent: openchamber-scheduled-lane (repo-worker-opencode)
Session/ID: ses_e5e70d0bddfffebHLE0mvgICsZ
Found via: queue task 4028 (repo-health-opencode-pilot)
Task: Implemented the proactive half per the design note: resolveRoute now feeds QuotaSnapshot.deriveAll (plans store + windowed route_attempt usage) through observeCredentialQuota per active credential (TTL-guarded 60s); new ModelRoute.observeProviderQuota gives credential-less providers the same treatment via the existing skip-adjustment store (last-resort preserved). No second gate, no config edits.
Expectation: closed by merge of PR #1028 (18e33f8). Targeted suites pass (163 tests: model-route, model-route-credential incl. 4 new provider-gate tests, model-resolver, quota-snapshot); typecheck clean. No follow-ups enqueued.
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|