#1981 refused every quota route to a gateway key held to a budget, models
or accounts, so a Remote magpie set up with such a key showed none of the
providers it may use. A key's owner can now let it be told them:
access.Key.Quotas, set from the key's new "Quotas" badge on the Gateway
page or `magpie gateway-key quotas <id> on|off`. Off stays the default,
so #1981's answer is unchanged for every key until its owner says so.
With it on, /v1/magpie/quotas (and ?kept=1), /quotas/history,
/quotas/cards and POST /quotas/refresh go through scopeQuotas
(internal/gateway/quotas_scope.go):
- a provider is told only when the key may use every model the catalog
lists of it: a key with some of a provider's models is told nothing of
it, since the models it may not use spend the same quota;
- of those, only cards of accounts and keys AllowsAccount lets it use,
matched by the card's User against AccountIDs (a name two accounts
share needs both; a card no account is known by only where the key's
list names none of that provider's); a provider's only key's card,
named by no one, is that key's;
- cards read from another magpie (From) are never told;
- a refresh of a card outside the scope is 403 gateway_key_held, one
naming no card reads again only the scope's cards, not ReadAllCards;
- a scope with no card answers the cards routes 403 gateway_key_held, so
the remote shows the key's own card rather than "nothing read".
/v1/magpie/concurrency and /v1/magpie/usage still refuse a held key.
Run at the reviewed head:
- gofmt -l: clean; go vet ./... (darwin), GOOS=linux -tags nogui,
GOOS=windows: clean.
- go test -tags nogui -timeout 45m ./... in a sandbox HOME, after the
rebase onto 7be68467f (#2227's several limits; conflicts in access,
the CLI usage and test, keys.js and providers-accounts.md resolved by
keeping both): every package ok but internal/gateway, whose
TestTranslatedSilenceStillTimesOut went red once at load ~95 (its
400ms deadline also covers the response headers; filed #2248) and
passed 5 of 5 alone. Before the rebase the whole suite was ok, with
agent and gateway rerun at -timeout 40m after the 10m timeout under
load.
- TestHeldKeyToldItsOwnQuotas (new): a provider-wide key sees A only,
a key with A/m1 sees nothing of A, an account-held key sees only its
key's card, a provider's only key, a key told nothing gets 403 from
the cards route, Quotas-off still 403 everywhere, refreshes outside
the scope 403. Broken by hand, each red: scope returned nil (every
card told), every[id] forced true (partial models), the account check
skipped, the refresh check removed, the only-key rule removed, and the
told-none 403 removed. TestHeldKeyToldNoAccounts (#1981) still green.
- TestRemoteMagpieShowsHeldKeyItsQuotas (new): a magpie with this one as
its Remote magpie provider, through a key held to alpha's Two, shows
office/alpha's Two card beside the key's own; a key told none shows its
own card alone. Red with the told-none 403 removed ("nothing read on
that magpie yet").
- TestGatewayKeyQuotasCLI (new): show, on, off, bad values refused.
- GUI: gateway-key-quotas.test.cjs (new) in chromium and webkit, at 1100
and 420, in en, zh, zh-TW, ja, de: 20/20; red when the badge sends the
value it already has.
- The badge is a gateway key row's: off, it folds to no width until the
row is hovered (the row had no room left at 390px: gateway-connect-keys
went red in en until it did), and on a phone it is shown like the
row's other controls (phone-rows went red until its rule won).
- GUI, 119 files matching gateway|key|usage|quota|remote|i18n|caller|
web-|phone|narrow, both engines, concurrency 2: 1349/1385. The reds
besides phone-rows (since fixed, above): quota-count-wrap and
quota-name-translated webkit (#2228), usage-agents-hide (#2211) and
usage-fold chromium en/zh (#2163), each red alike on a fresh
origin/main. gateway-key-quotas, gateway-connect-keys, phone-rows and
gateway-key-groups rerun: 38/38; after the rebase every gateway-*,
phone-rows and key-limit file, both engines: 210/210.
Not tried: a real Remote magpie against a second machine with a held key;
the GUI badge in the Linux and Windows apps.
Subsystem design references
These pages describe current responsibilities, runtime paths, state, and contracts. Start with the subsystem relevant to your task, then follow its source links to verify the implementation you change.
| Subsystem | Reference |
|---|---|
| Built-in subscriptions moving to plugins | Provider and plugin ownership |
| Built-in plugins: registry, lifecycle, plugins.yml, presets, settings schemas, the window's kernel (slots, error boundary, kit) | Plugin runtime |
| Plugins that run on the gateway's requests and replies | Gateway middleware |
| Claude subscription turns across Claude Code runs | Claude subscription bridge |
| How the gateway picks a provider, key or account, and falls back | Gateway routing and fallback |
| Gateway Session Aggregation | Gateway Session Aggregation |
| Connecting an agent's config to the gateway, drift, disconnect, WSL twins | Agent wiring |
| Providers, keys, subscription accounts, refresh and allowance | Providers and accounts |
| Instructions, MCP servers, skills and RTK written into agents | Library |
Tray, panel, window, magpie web and the page's JSON API |
GUI app shell |
| Encrypted backups and setup synchronization over WebDAV, S3 or GitHub | Sync and backup |
A subsystem can span several packages or repositories. Its reference describes the behavior those parts provide together; it does not need to list every function.
Maintain a reference
Update the owning reference in the same PR when a change alters a documented responsibility, interface, state transition, runtime path, compatibility rule, or failure behavior. An internal refactor that preserves these contracts does not require a prose change.
Keep each fact in one reference and link to it from agent instructions or other pages. Link to source files and named symbols rather than copying implementation details that change frequently. Explain field meanings and constraints that signatures alone do not express.
For a new reference, include the responsibilities and boundaries, source of truth, main runtime paths, state transitions, important constraints, and existing verification commands. Include failure and compatibility behavior where relevant. Document current behavior separately from proposed changes; the proposal belongs in its issue or PR.
Describe a PR's semantic changes
For each affected subsystem, explain the observable change with its trigger and before/after behavior. Include changes to interfaces, state, compatibility, and failure behavior when relevant. Link the affected reference, implementation, and verification evidence. State when a refactor preserves the documented behavior.
For example, a change to plugin adoption should explain which migration state and account condition trigger it, which implementation handles requests before and after adoption, and which test exercises that transition.
This is an author-provided explanation that a reviewer verifies against the diff and surrounding code. It is not an automatically proven compatibility verdict.
Review a change
- Identify the affected subsystem and the actual runtime path, including plugin or built-in ownership.
- Compare the claimed before/after behavior with the base and head implementation. Trace relevant callers and state transitions beyond the changed lines.
- Check that changed contracts appear in the owning reference and that source links still resolve.
- Check that the cited tests or runtime evidence exercise the claimed behavior. Report checks that were not run.
A documentation update alone does not prove the implementation. Existing tests and runtime evidence remain necessary for behavior changes.