docs: a key's usage cap (@wanggenjidev on X)

gateway-routing.md and providers-accounts.md: a key whose usage windows magpie reads takes the same usage cap an account does.

Record for the three commits (@wanggenjidev on X: Codex-style percent cap for OpenCode Go keys, generically for every key with windows magpie reads):
- Run at the pushed head (rebased on 08a852a36): TestKeyTakesUsageCap and TestKeyUsageCapPassesTheKeyOver ok; gofmt clean; key-usage-cap, key-spend-cap, account-cap, window-cap, i18n-keys: 180 pass, 0 fail on WSL, chromium and webkit. window-cap in webkit alone: 60/0 on this head and on origin/main a3d2a85dd.
- Earlier on mote at the previous base: provider/gateway/cli targeted tests ok; ./internal/gui ok 188s with -timeout 45m; vet darwin, linux nogui, windows clean.
- Broken by hand: the gateway hold removed, TestKeyUsageCapPassesTheKeyOver goes red.
- mote's disk filled during checking (52 webkit window-cap fails there, 60/0 on WSL on both main and this head); not a window-cap bug found on this change.
- Not tried: a real OpenCode Go key with live windows, Windows/Linux GUI runs, WebKitGTK. The whole GUI suite and the Go suite run after the tag.
This commit is contained in:
yetone
2026-11-11 14:21:06 +08:00
parent a46c90e7c3
commit 69453574d7
2 changed files with 2 additions and 2 deletions
+1 -1
View File
@@ -272,7 +272,7 @@ recorded as a prediction failure (`noPrediction`).
- Antigravity's 429 for a model's quota used up writes how long until it is back as Go prints a duration: "You have exhausted your capacity on this model. Your quota will reset after 3h19m30s." (`quotaResetAfter`, read by `resetsAfter` beside Factory's "resets in …", held to `longestWritten`). The account (or, as `pooled` says, that model on it) rests that long (`resets`), and the agent's Retry-After says it when no account is left. Unread, it rested `quotaRest`, so the account first in order was asked again, and refused, every 15 minutes while the next ticked account had its quota (Dani Ariyanto on Discord, 10-24; `TestAntigravityQuotaRestsUntilItsReset`). Its other 429, "Resource has been exhausted (e.g. check quota).", names no time and rests `quotaRest` as before.
- A ZCode plugin account's Start Plan trial entry (`<model>-Trial`) that the plugin refuses before sending anything rests that entry alone (`zcodeTrialRefused`, `restID`), not the account: a 400 "ZCode has no active limited quota for GLM-5.3-Trial" when no live plan holds it any more (the trial ended), and a 429 "ZCode's limited quota for glm-5.3 is exhausted or temporarily unavailable" when its bucket is spent (the plugin names the bucket, the entry less `-Trial`). Read as `failQuota` by their words, both rested `zcode@…`, and the account's GLM Coding Plan models were paused with the trial (#3661, orion-nebula-dev; after skygunner's e04a1b994, which covered the 400). Only the plugin's exact words naming the model asked for count: another model named, a model without `-Trial`, the words on another status, the account's own quota or key, and the same words from another vendor still rest the account (`TestZCodeTrialRefusalRestsTheTrialAlone`). An expired trial still kept in a group is asked first and refused locally, as the guessed quota rest is asked again a minute on; the Routing page strikes it as skipped, which the gateway doesn't do for a member no account lists (#3805). ZCode's risk control refusing a trial entry (3012, `failRestricted`) rests that entry alone too (`zcodeTrialRestricted`): the entry goes to zcode.z.ai, a dual account's plain models to its GLM Coding Plan on api.z.ai, which kept serving them (young02036 on Discord, 11-07). The plain model's own 3012 rests the account, as on a gift-only account, where it goes to zcode.z.ai too.
- An account resting out of its window (a Claude account by the time Claude Code's refusal named, `resets`, or any by `window`) is back once magpie's reading of its windows (`provider.Allowances`) finds it full till sooner: the window used below `SpentShareOf`, or its reset passed, with no other window over the same models still full. The reading tells `provider.OnRenewed` as the account's `UsageAgent` and user, and `renewed` lifts that account's rests out of quota or by `window`; its rests for a rate limit, its credit, a verification or a failure stay, as a key's do, and so does every rest of other accounts still out of their windows. Planning reads every account candidate's allowance, ordered groups included, so this needs no step of its own in `restingOf`.
- Only an account is held at a usage cap (`capHeld`) or rested out of one model's pool (`pooled`); a key's windows order it and rest it, nothing more. A key is held only at its own spend cap (below).
- An account is held at a usage cap (`capHeld`) or rested out of one model's pool (`pooled`). A key whose windows magpie reads (`provider.TakesUsageCap`: `readsKeyWindows`, OpenCode Go's 5 hours, week and month among them) takes the same cap by its key id (`AccountCaps`, `AccountWindowCaps`; @wanggenjidev on X) and is barred in `perKeyEvery` (`keyCapHeld`, `Provider.KeyCapHeld`) once a window is at it, as an account is, and back when that window renews. Windows not read yet, or a read that failed, hold nothing (`KeyAllowance` keeps the last good reading, `TestKeyUsageCapPassesTheKeyOver`). `CapCareful` and the one-turn-at-a-time rule near a cap are an account's only. A key is also held at its own spend cap (below).
- A key at its spend cap ([providers](providers-accounts.md), `provider.SpendCap`) is barred in `perKeyEvery` (`spendHeld`) with a `capHold` whose `spend` is set: it is passed over and the provider's other keys and its fallbacks take the request. Routing's row says what it spent of its cap (`Weighed.SpendCap`, `Spent`, `SpendPeriod`, `SpendSince`). With every candidate held, `cappedError` answers 429 naming each key, what it spent of its cap and when it is back (the next day or month, or not until a cap in all is raised), and the command that changes it, with `Retry-After` at the soonest; a cap in all gives none. A spend hold is not a usage cap: `capHeldOnly` leaves it out, so neither Stop at the caps (`CapStop`) nor Strict's `strictKeep` sends a request to a key past what it may spend. `TestKeySpendCapPassesTheKeyOver`.
- A 429 for want of rate or quota whose words name the model asked (`modelNamed`: OpenAI's "Rate limit reached for gpt-4o in organization …", Groq's "for model `…`", Gemini's QuotaFailure with the model in `quotaDimensions`, WJaunita45604 on X) rests that model on that key or account alone (`modelLimited`, `restID`), with its backoff and its sink, and the other models are asked straight. The name is matched as a whole id (`gpt-4o` is not `gpt-4o-mini`). A refusal that names no model, one for want of credit, and a plain failure still rest the key or account whole.
- A rest of one model alone (keyed by `restID`: a pool, a model not served, a paid model beside free ones) names that model in the trace (`Rest.Model`). The Routing page shows it on that model's rows only: the account's other models' rows on the stage, and the account's row under Accounts and keys, don't read as resting. The account's row names the models resting on a line of their own under what it has left, and its Try now lifts their rests. A kept request from before `Rest.Model` has the model on the end of `Rest.Key`, which the page reads the same (`restModel` in `plugins/routing/client.js`, #1960, `routing-model-rest.test.cjs`).
File diff suppressed because one or more lines are too long