Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.
gateway: a provider's fallback can be a routing group, routed as the group
yetoneb4267de59550
diff --git a/docs/subsystems/gateway-routing.md b/docs/subsystems/gateway-routing.mdindex 4fb1063b4..19baeaee0 100644--- a/docs/subsystems/gateway-routing.md+++ b/docs/subsystems/gateway-routing.md@@ -32,7 +32,7 @@ backfilled; see [Gateway Session Aggregation](gateway-sessions.md).| HTTP surface | `Handler` routes `/v1/chat/completions`, `/v1/responses`, `/v1/messages` (each also without `/v1`), `/v1/models`, Gemini's `/v1beta/models/…`, the Codex backend path, `/v1/codex/models` (Codex's catalog shape for a Codex elsewhere with a gateway key, `codexCatalog`, kept to the key's models by `keyAllowed`; #1281), Ollama's `GET /api/version`, `GET /api/tags` and `POST /api/show` (`ollama.go`, for a client that takes a custom endpoint only as an Ollama server: Visual Studio's and VS Code's Copilot, wani on Discord; the list is `catalogFor`'s, so a key's models alone, `/api/show` tells `capabilities` (`completion`, `tools`, `vision` from `Images`, `thinking` from `Thinks`) and `model_info` with `general.architecture` `magpie`, `general.basename`, `magpie.context_length` (32768, VS Code's own default, when the window isn't known, since VS Code would take a 0) and the `general.parameter_count` and `magpie.embedding_length` the ollama CLI before 0.7 reads unchecked; a name ending `:latest`, as the ollama CLI asks, is the bare id unless a model is really called that (`ollamaName`); the client then chats on `/v1/chat/completions`, or on Ollama's own `POST /api/chat` and `POST /api/generate` (`ollama_chat.go`, Zed's Ollama provider, super_lalalalala on Discord), which `ollamaChatBody` turns into a `/v1/chat/completions` body handed to the same `handle(provider.Chat)` on a clone of the request, so they are routed, held to a key's models and counted as it is: `messages` with `images` (base64, its type sniffed, as data-URL parts; a tool message's in a user message after it), an assistant's `thinking` as `reasoning_content` and its `tool_calls` given ids where Ollama sent none, a tool result matched to its call by `tool_call_id`, else `tool_name`, else in order (one with no call is a 400), `tools`, `format` (`json` or a schema), `think` (a level is `reasoning_effort`), and `options`' `temperature`, `top_p`, `seed`, `stop`, the two penalties and a positive `num_predict` as `max_tokens` (`num_ctx`, `top_k` and the rest of Ollama's own are dropped); `ollamaWriter` turns the reply into Ollama's NDJSON lines (streamed unless `stream:false`, then one object), tool calls with their `arguments` as an object and an `id`, and a last `done` line with `done_reason` and the token counts, and an error into `{"error":"…"}` with the status `/v1` would give; a request with no messages or prompt is answered `done_reason:"load"`, as Ollama does to warm a model), `/mcp/{name}`, `/mcp/magpie/web-search`, `/mcp/magpie/vision` and `/mcp/magpie/image` with its `/mcp/magpie/image/files/{name}` (magpie's own web search, image recognition and image generation as MCP servers, below) and the `/v1/magpie/*` status endpoints. `/v1/magpie/heap` (`heapProfile`, [`heap.go`](../../internal/gateway/heap.go), for `magpie heap`) is held tighter than the rest by `heapRefused` in the handler itself, so it holds where `Handler` is served without `lanGuard` too: only a loopback caller that isn't proxied (`local`), carries no browser mark (`fromBrowser`) and names a loopback `Host` (`loopbackHost`) gets the profile; a gateway key never lets anything else in. `/v1/magpie/cpu` (`cpuProfile`, [`cpu.go`](../../internal/gateway/cpu.go), for `magpie cpu`) records a CPU profile for `?seconds=` (30, from 5 to 120) and is held to the same callers by `cpuRefused`, which shares `profileRefused` with `heapRefused`; one profile records at a time (`cpuRecording`), a second is answered 409, and a caller that hangs up stops it. `/v1/magpie/goroutines` (`goroutineDump`, [`goroutines.go`](../../internal/gateway/goroutines.go), for `magpie goroutines`, #3362) answers every goroutine's stack and wait as text (`runtime/pprof`'s `goroutine` profile at debug 2) to the same callers, through `goroutinesRefused`, and is answered ahead of everything below (`dumpFirst`, around `Handler`'s wrappers and around `lanGuard` in `Front`), since it is asked for while magpie hangs: the allow list reads settings.json under its lock, and `holdCatalog` takes `provider.Hold`'s and `filememo`'s, so a stuck holder of any of them would hold the dump too; a caller `goroutinesRefused` lets in is one those let in anyway, and any other goes through them as before (`TestGoroutineDumpAnswersWhileRequestsWait`). `/v1/alpha/search` (also without `/v1`, and on the Codex backend path for a magpie model) is Codex's web.run search (`alphaSearch`, `codex_search.go`): a ChatGPT account's model goes to the ChatGPT backend's `/alpha/search` on the account's sign-in, the next account asked on 401, 403, 429 or 5xx; any other model's `search_query` is searched by `webSearch`, and when nothing answers the reason is a 200 with `output`, since Codex ends the turn on any failed web.run (anton on Discord). A GET on `/v1/responses` (a client opening Responses over a WebSocket) is answered 426, a plain one 405: Responses is relayed over HTTP only. Every route is wrapped in `counted`, `corsGuard`, `callerGuard`, `withCaller` and `keyLimited`; `/v1/messages`, `/messages` and `/v1/messages/count_tokens` in `keepsSignIn` too. `corsGuard` (#1051) serves CORS only to the origins listed in Settings › Network › Web pages (`settings.CORSOrigins`, cleaned to `scheme://host[:port]` by `settings.CleanOrigins`, which refuses a wildcard). A browser extension's own pages, popup and service worker are listed the same way by their origin, which is the browser's scheme and the extension's id: `chrome-extension://<id>` (Chromium, the id 32 letters a–p), `moz-extension://<uuid>` (Firefox, the Internal UUID about:debugging shows, not the add-on id) and `safari-web-extension://<uuid>` (Safari, which picks a new UUID on each launch, so a listing lasts until Safari restarts); the id must have that browser's shape, cased any way, and nothing else is taken — no bare scheme, no wildcard, no path (SkyAerope on Discord: an extension without host permissions is held to CORS like a page). A content script's fetch carries the page's origin, not the extension's. A listed extension is treated exactly as a listed page, below; one not listed passes as before (other schemes, below) with no CORS headers. For a listed origin it answers the preflight (204) and adds `Access-Control-Allow-Origin`, and every other request from it needs an enabled gateway key (`access.Authenticate`), even on loopback, or gets a 401. It takes the key from the caller `lanGuard` recorded too, since on the running server `lanGuard` has already put magpie's own token in the key's place. Any other web page is refused 403 on every route (`foreignPage`): on loopback a call needs no key and the body's Content-Type isn't checked, so a page the user visits could otherwise send a "simple" `text/plain` POST and spend their subscriptions blind. Only an `http`/`https` Origin is judged, and one on this computer (`localhost`, `*.localhost`, `127.0.0.0/8`, `[::1]`, any port) or the request's own origin (its host and port equal to `Host`, such as a page on the gateway's LAN address) passes, as does usemagpie.ai on `/v1/magpie/omarchy`. Other schemes (`app://`, `file://`, `tauri://`, `vscode-webview://`, `chrome-extension://`) come from desktop apps, webviews and extensions that don't enforce CORS, and pass keyless as before; `null` is not one of them, since any web page sends it from a sandboxed frame and an opened file sends it too, so a call with it needs an enabled gateway key as a listed origin's does, and is answered 403 without one (no CORS headers either way, so a frame or a local page still reads no reply). A page at a subdomain of localhost (`localhostSubdomain`, #2256) needs a key the same way: Chrome and Firefox resolve `*.localhost` to loopback themselves, but Safari and other WebKit views ask the system resolver, which before macOS 26 asks the network's DNS (WebKit bug 160504), so a resolver that answers serves such a page from anywhere. `tauri.localhost` and `wails.localhost` stay keyless on Windows only, where Tauri's and Wails' webviews serve themselves at those names; on macOS and Linux those apps use `tauri://` and `wails://`. A request with no Origin (every agent's) passes through with no CORS headers, as before. A page whose own name resolves to 127.0.0.1 (DNS rebinding) would count as same-origin here, so `lanGuard` refuses it first (`rebound`, 403): a loopback request carrying a browser's marks (`Origin`, `Sec-Fetch-Site`/`Sec-Fetch-Mode`, a `Mozilla/` user agent) whose `Host` isn't this computer's (an IP, `localhost` but not a subdomain of it, which WebKit asks the DNS for (#2256), a container runtime's name for the host such as `host.docker.internal`, `MAGPIE_PUBLIC_URL`'s or `MAGPIE_ADDR`'s host, the machine's own name) needs an enabled gateway key. Agents send none of those marks and pass under any name. Before any of that, `lanGuard` lets in one request without a key from anywhere: `POST /_magpie/claude-mcp/<token>` with the token of a Claude subscription run now live (`ownCallback`, see [the Claude subscription bridge](claude-subscription-bridge.md)), the run's MCP helper calling back to a `MAGPIE_ADDR` that isn't loopback (#1546). Next, before the key or `rebound` is looked at, the allow list (lc on Discord, magpie in Docker on a public host): with `MAGPIE_ALLOW_IPS` or Settings › Network › Allowed addresses (`settings.AllowIPs`, this computer's own, never brought by a sync or restore: see [sync and backup](sync-backup.md#what-stays-on-each-computer); the variable wins and the page then only shows it) naming IPs and CIDR ranges, a request whose connection (`RemoteAddr`, IPv4-mapped IPv6 unmapped, zone dropped) is outside them is refused 403 naming its address, even with an enabled gateway key (`refuseNotAllowed`). Loopback and this computer's own interface addresses always pass. A forwarding header is never taken for the address, so a proxy or tunnel on this computer passes (it arrives from loopback) and its clients are limited at the proxy. An entry that doesn't parse lets nothing in and is logged once; the list stays on. Settings' list is read with `settings.LoadChecked`: a settings.json that can't be read, or doesn't parse with no last good generation, is unknown, never "no list", so the list read last in this process stays in force (`lastAllow`), and with none read yet only this computer passes, the 403 saying settings.json couldn't be read; logged once. No file, or an empty one, is no list. The Settings page's saves read with `LoadChecked` too and refuse such a file, as `settings.Save` does. `magpie web`'s server is wrapped in the same check (`AllowGuard`), and its port hands the gateway's client routes (`ClientPath`) to `Server.Front`, the same lanGuard-over-Handler the gateway's listener serves, each marked by `FromPagePort` so `local` is false for it (`viaPagePort`; `lanGuard` refuses it 403 while magpie isn't shared, saying to call the gateway's own address, and asks a gateway key otherwise): a raw TCP forward or a proxy with no forwarding header reaches that port from loopback, so no request there counts as an agent here (`TestClientPathCoversHandler` fails when a route Handler adds is in neither `ClientPath` nor its list of routes that stay on the gateway's port). Settings refuses a list that would leave out the address the page saving it is open from (`KeepsOut`); the page names that address, which behind Docker or a proxy is the proxy's, and offers to add it to the refused list (`allowSays`, Mathresearcher on Discord). | [`gateway.go`](../../internal/gateway/gateway.go), [`allow.go`](../../internal/gateway/allow.go), [`internal/settings/allowips.go`](../../internal/settings/allowips.go), [`cors.go`](../../internal/gateway/cors.go), [`codex_catalog.go`](../../internal/gateway/codex_catalog.go), [`ollama.go`](../../internal/gateway/ollama.go), [`ollama_chat.go`](../../internal/gateway/ollama_chat.go), [`internal/settings/origins.go`](../../internal/settings/origins.go) || Model resolution | `serve` resolves the model the agent asked for: Claude tier stand-ins, a routing group (`provider.GroupFor`: its id, the model's id however a vendor spells it, else the one group whose name it is, unless a provider serves a model by that id; the user's own groups only while the `groups` plugin is on, [the plugin runtime](plugin-runtime.md#gateway-extension-points-p3-router-strategy)), auto stand-ins, the agent's own stand-in (`StandIn`: Codex's config.toml `model` when magpie is its provider — in a WSL distro, the distro's own, of the ones running now — for a name it sends that magpie doesn't serve, such as its auto-review's `codex-auto-review`), itself taken through `GroupFor` and auto stand-ins so a config naming a group bare reaches it, then `provider.Resolve`. A Codex memory call or auto-review (`x-openai-subagent: guardian`, or `codex-auto-review`) that still names no served model goes to the model Codex's last turn was answered on (`codexMemoryStandIn`, per agent and gateway key; a memory call first waits beside the turn it was started with, through `codexLeads`, see the side turns below), so a Codex on magpie through another provider table, a profile or another computer isn't answered 404 (Adam on Discord, `TestCodexAutoReviewReachesItsTurnsModel`). A bare model id several providers serve (MOMO on Discord: `glm-5.3` under opencode-go and a6api) is never refused: with found groups on (the default) `GroupFor` takes it to the group magpie found for it (`auto-<slug>`), its members in the Providers order, routed and failed over as any group, a conversation staying with the member that answered it while its cache is worth it (affinity); with them off, `Resolve` takes the first provider in the Providers order that exposes it, with no fallback. magpie writes only `provider/model` ids into agents' configs (`magpieModels`), so a bare id is one the user wrote. `/v1/models` lists bare ids only when the user asks for them ([Model ids without the provider](#model-ids-without-the-provider)). Every reply says who answered in `X-Magpie-Provider` and `X-Magpie-Model` (`noteMember`), and the usage log and the Routing page keep it. A model id with `~` and no slash that resolves as nothing else is the one served id (a provider's model or a group) whose slashes it spells as `~` (`unflat`, `provider.Unflat`; MiniMax Code's spelling, #1387), taken back in `validateModel` before key limits, middleware and usage see it; two ids spelled alike are neither. A Claude model id whose version is dashed (`relay/claude-opus-4-6-us`, with or without `:level` and `[1m]`) that is not served as spelled is the one served id it dashes (`provider.ClaudeUndashed`; the spelling magpie gives Claude Code, which reads a dotted version as Claude Opus 4), taken back in `validateModel` and `unprefixed` the same way. An unknown model gets a 404 naming why: a switched-off provider, a disabled group or an empty group. Otherwise it names up to three ids nearest to what was asked (`provider.Closest`: words of a model's display name count before words of its id, and a provider's id or name only alongside them, so "Zen-Space-Bunny" is told `opencode-zen-free/space-bunny-free`, MOMO on Discord), then the ways a model can be named, then every id (`unknownModel`; chat and embeddings). | [`gateway.go`](../../internal/gateway/gateway.go), [`internal/provider/group.go`](../../internal/provider/group.go), [`internal/provider/flat.go`](../../internal/provider/flat.go), [`internal/provider/claudedash.go`](../../internal/provider/claudedash.go) || A found group's two ids | A group magpie found is listed (`/v1/models`, the catalog, the lists written into agents, the pickers, the CLI and TUI) as `auto/<model>`: the model's id as a vendor spells it, dots kept and with no vendor prefix (`auto/claude-opus-5.5`; `provider.Group.Ref`, `spelledIn`, preferring a spelling models.dev lists), so a client that looks the part after the slash up on models.dev finds it (ZeroClover on X). Its old id `group/auto-<slug>` is served forever. Inside magpie the group keeps that one id: `validateModel` takes `auto/<model>` (with `:level` or `[1m]`) back to it with `provider.CanonicalRef` before key limits, routing, affinity and the usage log see the request, and the request body is rewritten to it, so both ids count as one group. A gateway key naming either id, `group/*` or `auto/*` passes for both (`allows` in `key_models.go`). `SaveGroup` stores a member, rule or classifier picked as `auto/<model>` by the old id. An agent field magpie set to `group/auto-<slug>` moves to `auto/<model>` on the next `SyncCatalog` (`agent.renameFoundGroups`), but only while its value is still what applied.json says magpie wrote; a value the user set or changed stays. A pick of the group by its old id written now (`Agent.Apply`) is written as `auto/<model>`. An agent's hidden, picked and ordered models saved by the old id hold for the new one (`PublicRef` in `visible.go`), and a bare model id still reaches its found group (`bareTarget`). Claude Code is given a dotted Claude version dashed, so it may send `auto/claude-sonnet-4-5`: that is the same group, and `Reseat` still moves an agent off it once the group is gone (`samePick`). `auto` is no provider id: `Save` and `Rename` refuse it for a new provider, and a plugin's `auto` is `auto-plugin` (`PluginID`). A provider of the user's saved as `auto` before keeps its models: while it exists, `auto/<x>` is its model and found groups list as `group/auto-<slug>` (`autoRefsOn`). Hand-made groups stay `group/<id>`. | [`internal/provider/autoref.go`](../../internal/provider/autoref.go), [`key_models.go`](../../internal/gateway/key_models.go), [`internal/agent/autoref.go`](../../internal/agent/autoref.go) |-| Candidates | `plan` lists one provider's candidates: one per key or account on, then each `Fallback` model, with resting ones last (`restLast`). A fallback the user unchecked in its own provider's model list is skipped, as a group's member is (`provider.ResolveRoute`, #3911; `fallback_unpicked_test.go`), and so is it where fallbacks are read for careful accounts, native compaction, redaction and Codex's own turns. `planGroup` and `planLevel` weigh a group's members together. A nested group plans by its own routing (#576); one left on the default (Smart) in a group that pools (Smart, In turn, Least used, Weekly pace, Free first, Speed first, a plugin's) takes the outer group's, as a provider left on the default does (`provider.Group.Within`, set on `Member.Via`, so the trace's `Subs` and the Routing page read the routing that applies, #3847). In a group In order, By weight or Manual it stays Smart. `TestFreeFirstReachesAGroupInItLeftOnTheDefault`. So does a member whose provider routes other than Smart (`ownRouting`): weighed as one by its first not resting (`firstAwake`), tried whole in its own order; `leastHeld` leaves such a group's order alone too. A provider on Smart, or routed as the group is, is pooled with the group's other keys and accounts. `group_own_routing_test.go`. A member's own fallbacks are not the group's. | [`fallback.go`](../../internal/gateway/fallback.go) |+| Candidates | `plan` lists one provider's candidates: one per key or account on, then each `Fallback` model, with resting ones last (`restLast`). A fallback the user unchecked in its own provider's model list is skipped, as a group's member is (`provider.ResolveRoute`, #3911; `fallback_unpicked_test.go`), and so is it where fallbacks are read for careful accounts, native compaction, redaction and Codex's own turns. A fallback can be a routing group (`group/<id>`, 01huadalang on Discord): `planPaused` hands its members to `planLevel` as a request to the group would (`planFallbackGroup`), in the group's own routing and sink, its pause rules applied in `serve`, and its trace rows marked `Fallback` with the group in `Via`. Its turn rules (`ruleFor`, which may ask a classifier) are not applied: the plan is made before the primary is tried, and a classifier call on every request the primary answers costs too much. Each provider/model is tried once a round: a member that is the primary, an earlier fallback or another fallback group's is left out where it came second, so a group holding this provider is no loop (groups have no fallbacks of their own, and a member's are not followed). A group that is gone is passed over. Every place that reads fallbacks (careful accounts, native compaction, redaction, Codex's own turns, Claude's review) reads a group's members through `provider.FallbackModels`. `fallback_group_test.go`. `planGroup` and `planLevel` weigh a group's members together. A nested group plans by its own routing (#576); one left on the default (Smart) in a group that pools (Smart, In turn, Least used, Weekly pace, Free first, Speed first, a plugin's) takes the outer group's, as a provider left on the default does (`provider.Group.Within`, set on `Member.Via`, so the trace's `Subs` and the Routing page read the routing that applies, #3847). In a group In order, By weight or Manual it stays Smart. `TestFreeFirstReachesAGroupInItLeftOnTheDefault`. So does a member whose provider routes other than Smart (`ownRouting`): weighed as one by its first not resting (`firstAwake`), tried whole in its own order; `leastHeld` leaves such a group's order alone too. A provider on Smart, or routed as the group is, is pooled with the group's other keys and accounts. `group_own_routing_test.go`. A member's own fallbacks are not the group's. | [`fallback.go`](../../internal/gateway/fallback.go) || Order of keys and accounts | `Routing`: smart (""), `order`, `rotate`, `usage` (least used, with an `usageHalfLife` of 1h), `pace`, `weight`, `free` (free first) or `fast` (speed first). `weighRouted` reads each candidate into a `routes.Seat` and asks the strategy serving its routing (`routes.Find`, the router strategy point of [the plugin runtime](plugin-runtime.md#gateway-extension-points-p3-router-strategy)) for the order: Smart is `routes.Smart`, the core's; the others are `routes.Builtin`, registered by the built-in plugin `rotation`. With it off a routing no strategy serves is tried in its listed order, and `routingOf` treats it as `order` wherever the core asks about a routing (a turn's mark, `goesRound`, `sinks`, a rotate group's sessions, a group's heads). Smart, `usage` and `pace` weigh a subscription by its allowance (`allowances`), and a key by its own usage windows when magpie reads them (`keyAllowance`: a sub2api key given a 5-hour, day or 7-day limit, or a key bought as a plan, such as Kimi Code's or a GLM Coding Plan's); any other key has none. Among accounts a plugin reads as prepaid wallets (a window's `balance`, #3950), Smart, `usage` and `pace` put the one with more left first where they would otherwise tie, only within one provider and unit (`routes.Seat.Left`/`LeftIn`, see [provider plugins](provider-plugins.md#a-wallets-balance)): each kind is ordered in the places its own seats take, so a group weighing several providers' accounts as one pool orders each provider's wallets too (#4095, `TestGroupWalletsGoByWhatTheyHaveLeft`). `free` weighs by what a model costs there and nothing else: only a strategy with `routes.Strategy.ByFree` set (`routes.FreeFirst` is the one) has `weighRouted` fill `routes.Seat.Free`, from `provider.FreeModel` — the vendor's own `catalog.Model.Free` word, else a list price of $0 on every count — so a pool routed any other way never reads a model list for it, and one routed `free` spends the members whose model costs nothing before those that spend the allowance or credits, each tier in its listed order (nothing free is left behind a paid one, and a pool with no free model behaves as `order`). A group routed `free` weighs its members whole, each over its own accounts or keys as its provider routes them. `fast` weighs by speed lately and nothing else: only a strategy with `routes.Strategy.BySpeed` set (`routes.Fastest`) has `weighRouted` fill `routes.Seat.TTFT` and `TPS`, from `speedOf` ([`speed.go`](../../internal/gateway/speed.go)): per `restID` (account or key, and model), a decayed average (half-life 20m) of a streamed answer's ms to its first content and of its output tokens a second as `usage.DecodeOf` counts them, written once as an answer ends (`noteTrySpeed`, beside `servedCandidate`) and read with one map lookup per candidate, never from the usage history; past an hour since its last answer a seat counts as not measured, the records are capped at 4096, and a restart forgets them. `routes.Fastest` ranks the awake by their first token plus 200 tokens at their pace (a seat with no pace at the measured seats' middle pace), keeps seats within a tenth of their band's fastest in listed order, and of a pool's requests with seats both measured and not, gives every fifth to one not measured (round the unmeasured, `probes`, so one is never starved); resting seats go after the awake, used-up ones (`UsedShare`) after those, and rests and failover are as for any routing. The trace's rows carry `lateTtft`/`lateTps` for the Routing page's story ("answered fastest lately — first token in 0.8s"). A non-streamed reply tells nothing (no first token), so a pool that never streams stays in listed order bar the probes. A group routed `weight` (#1910) takes its members, not their keys, by smooth weighted round robin: `planLevel` makes each model member (its keys ordered by its own provider's routing) and each nested group one unit, and `weightedUnits` puts the round's pick (`routes.Round` over `group/<id>`, keyed by the member's spelling, `Group.Weights`, 1 if unset) first and the rest in member order for failover; a unit whose head rests leaves the round, while one whose accounts are only near their limit (Smart's 90% band, not resting) keeps its share, the band ordering only its own accounts (`TestWeightedGroupGivesALowGroupItsShare`; Creat.wu on Discord read the Routing page's "kept for when the others can't" as the member passed over, so the page now tells a member behind another by a group's weights or order as such, `memberSplit` in the routing plugin's `client.js`), and a kept conversation moves the round's charge to the member that kept it (`wrrSeat`, `routes.MoveRound`). A lone key or account is weighed against nobody, but what it has left is still read into the trace (`weighRouted`), so the Routing page shows it as it does for several (#1016); all but used up, it keeps its conversation rather than being said to move (`affine`). A failure rests a candidate (`failure`, `failureOf`). | [`routing.go`](../../internal/gateway/routing.go), [`weighted.go`](../../internal/gateway/weighted.go), [`internal/routes/`](../../internal/routes), [`internal/provider/routing.go`](../../internal/provider/routing.go) || Limits | Each key or account (a candidate's `who()`) has at most `MaxConcurrency` requests out at once (its own `AccountConcurrency` over it); one more waits in its lane's queue, bounded by `QueueLimit` and `QueueWait` and turned away with a 429 past either (`lanes.take`). One with no limit still counts its requests out in a lane of `Limit` 0, which never waits, so `Lanes` (`/v1/magpie/concurrency`, the GUI's `/api/lanes`) says how many run there too and the Providers page's pill shows it (chentuoyan on Discord, `TestLanesCountWithNoLimit`); a limit set while they are out counts them. `MaxRPM` (coeo91 on Discord: OpenRouter's free models take 20 a minute) bounds how many requests it sends the vendor in any rolling 60 seconds (`rpms`), counting each for a second more (`rpmSlack`), since the vendor counts a request when it arrives and the first on a new connection arrives later by its dial: one more waits for room in the minute, in the order they came, after it has its slot and right before it is sent. A wait that would be longer than 2 minutes (or the provider's `QueueWait`, when shorter: `rpmWait`) is turned away at once with a 429 whose `Retry-After` is when the minute has room; nothing rests for it. An agent gone while it waits gives its place back. Every request that reaches the vendor counts: each try of the candidate loop (a retry, the next key, a fallback) waits in `serve`, and the requests a try makes on the way and the gateway's own asks (count_tokens, System One's decisions, embeddings, drawing, Kimi's search) are counted by `rpmTransport` on `s.client` (`metered`, `paidFor`). count_tokens never waits: a candidate with no room is skipped, and the local estimate answers. A full lane or a minute with no room gives way to a ready key or account of the provider or the group (`laneMate`, `ready`); a fallback is never asked for want of either. A plugin's account sends through its own transport, so only its tries are counted, not a plugin's own extra requests. Set in the provider editor (Concurrency, Requests per minute, Queue size, Queue wait) or with `magpie provider account-concurrency`, `queue` and `rpm`; a subscription's are kept with its picks, and every account of it keeps them, those on beside the first as well (`withPicks`, called by `All` and `AlsoOn`; #1899: a second WorkBuddy AI account had none, and queued 62s with the wait set to 1s). | [`concurrency.go`](../../internal/gateway/concurrency.go), [`rpm.go`](../../internal/gateway/rpm.go), [`internal/provider/concurrency.go`](../../internal/provider/concurrency.go) || Sink | With `Sink` on, a key or account that answers 429 while it still has quota goes to the back, behind every one not rate limited since. Held in memory until restart, or until its rest is lifted by hand (Try now, `Unrest` calls `unsink`, `UnrestAll` `unsinkAll` for the key and each of its models), which puts it back in its place (`TestTryNowPutsASunkAccountBack`, `TestUnrestAllUnsinksTheModels`). Another magpie's model rate limited there, whose rest is the model's alone (`remoteModelRest`), sinks alone too (`restID`), and `sunkAt` reads a candidate's model before its key, so the remote's other models keep their place (#2167, ggbdpq; `TestRemoteMagpieRateLimitSinksTheModel`, `TestMagpieAddedByHandRateLimitSinksTheModel`). A group in a group sinks by its own Sink, within its own order (`sinkOwn`, #2255), and the group asked for then sinks the whole by its own; `TestNestedGroupSinksItsOwnOrder`. | [`sink.go`](../../internal/gateway/sink.go) |diff --git a/internal/agent/claude.go b/internal/agent/claude.goindex 6f6b3a21b..76b9552a3 100644--- a/internal/agent/claude.go+++ b/internal/agent/claude.go@@ -332,9 +332,8 @@ func claudeReviewed(catalogs []string, models ...string) bool {if gateway.AutoModeReviewable(p, model) {return true}- return slices.ContainsFunc(p.Fallback, func(id string) bool {- fp, fm, ok := provider.Resolve(id)- return ok && gateway.AutoModeReviewable(fp, fm)+ return slices.ContainsFunc(provider.FallbackModels(p), func(m provider.Member) bool {+ return gateway.AutoModeReviewable(m.Provider, m.Model)})}find := provider.GroupFinder()diff --git a/internal/cli/fallback_group_cli_test.go b/internal/cli/fallback_group_cli_test.gonew file mode 100644index 000000000..6e5137526--- /dev/null+++ b/internal/cli/fallback_group_cli_test.go@@ -0,0 +1,44 @@+package cli++import (+ "slices"+ "testing"++ "github.com/yetone/magpie/internal/provider"+)++// magpie provider fallback takes a routing group's id ("group/<id>") as a+// fallback beside models (01huadalang on Discord); a group that isn't+// there is an error, as a model none serves is.+func TestFallbackCmdTakesGroup(t *testing.T) {+ home := t.TempDir()+ t.Setenv("HOME", home)+ t.Setenv("USERPROFILE", home)+ t.Setenv("XDG_CONFIG_HOME", t.TempDir())+ t.Setenv("XDG_CACHE_HOME", t.TempDir())+ t.Setenv("DSH_HOME", "")+ for _, p := range []provider.Provider{+ {ID: "plan", Name: "Plan", Key: "kp", Models: []string{"m"}, Chat: "http://127.0.0.1:1/v1"},+ {ID: "a", Name: "A", Key: "ka", Models: []string{"x"}, Chat: "http://127.0.0.1:2/v1"},+ } {+ if err := provider.Save(p); err != nil {+ t.Fatal(err)+ }+ }+ if err := provider.SaveGroup(provider.Group{ID: "backup", Name: "Backup", Members: []string{"a/x"}}); err != nil {+ t.Fatal(err)+ }+ if err := providerCmd([]string{"provider", "fallback", "plan", "group/backup", "a/x"}); err != nil {+ t.Fatal(err)+ }+ p, err := provider.Find("plan")+ if err != nil {+ t.Fatal(err)+ }+ if want := []string{"group/backup", "a/x"}; !slices.Equal(p.Fallback, want) {+ t.Fatalf("fallback %v, want %v", p.Fallback, want)+ }+ if err := providerCmd([]string{"provider", "fallback", "plan", "group/nothing"}); err == nil {+ t.Fatal("a group that isn't there was taken")+ }+}diff --git a/internal/cli/providers_cli.go b/internal/cli/providers_cli.goindex 65461a3a1..7c2c6910e 100644--- a/internal/cli/providers_cli.go+++ b/internal/cli/providers_cli.go@@ -511,7 +511,7 @@ func providerCmd(args []string) error {// where requests go when this provider is out of quota, rate// limited or down; "none" clears the listif len(rest) < 1 {- return fmt.Errorf("magpie provider fallback <id> [provider/model… | none]")+ return fmt.Errorf("magpie provider fallback <id> [provider/model… | group/<id>… | none]")}p, err := provider.Find(rest[0])if err != nil {@@ -521,8 +521,10 @@ func providerCmd(args []string) error {p.Fallback = nilif !(len(rest) == 2 && rest[1] == "none") {for _, id := range rest[1:] {+ // a routing group's id ("group/<id>") resolves too: the+ // gateway sends the request through the groupif _, _, ok := provider.Resolve(id); !ok {- return fmt.Errorf("magpie knows no model %q (magpie models lists them)", id)+ return fmt.Errorf("magpie knows no model or group %q (magpie models lists them)", id)}p.Fallback = append(p.Fallback, id)}diff --git a/internal/gateway/cap_careful.go b/internal/gateway/cap_careful.goindex 82a0de61f..e40e23116 100644--- a/internal/gateway/cap_careful.go+++ b/internal/gateway/cap_careful.go@@ -128,10 +128,8 @@ func carefulOf(p provider.Provider, model string, ms []provider.Member) ([]provireturn ps, models}ps, models = append(ps, p), append(models, model)- for _, id := range p.Fallback {- if fp, fm, ok := provider.ResolveRoute(id); ok {- ps, models = append(ps, fp), append(models, fm)- }+ for _, m := range provider.FallbackModels(p) {+ ps, models = append(ps, m.Provider), append(models, m.Model)}return ps, models}diff --git a/internal/gateway/codex_backend.go b/internal/gateway/codex_backend.goindex b120e5a93..167fb9c7c 100644--- a/internal/gateway/codex_backend.go+++ b/internal/gateway/codex_backend.go@@ -1424,12 +1424,7 @@ func (s *Server) codexFallsBack(model string, body []byte) bool {if !ok || p.Account == nil || p.Account.Agent != "codex" {return false}- for _, id := range p.Fallback {- if _, _, ok := provider.ResolveRoute(id); ok {- return true- }- }- return false+ return len(provider.FallbackModels(p)) > 0}// codexFallBack serves Codex's turn on its own sign-in, which the backenddiff --git a/internal/gateway/fallback.go b/internal/gateway/fallback.goindex 00e3ca94a..1d4d820a5 100644--- a/internal/gateway/fallback.go+++ b/internal/gateway/fallback.go@@ -405,6 +405,13 @@ func (s *Server) candidates(p provider.Provider, model string, from provider.Pro// plan is candidates, and for the routing trace what each stood where it// did by, and those left out.func (s *Server) plan(p provider.Provider, model string, from provider.Protocol) ([]candidate, planned) {+ return s.planPaused(p, model, from, nil)+}++// planPaused is plan, a routing group among the fallbacks (01huadalang on+// Discord) less the models paused leaves out of it: its pause rules, as+// a request to the group would have them; nil pauses none.+func (s *Server) planPaused(p provider.Provider, model string, from provider.Protocol, paused func(provider.Group, []provider.Member) []provider.Member) ([]candidate, planned) {var pl plannedadd := func(q provider.Provider, m string, fallback bool) []candidate {cs, aside, left, barred := perKeyBarred(q, m, from)@@ -436,6 +443,25 @@ func (s *Server) plan(p provider.Provider, model string, from provider.Protocol)}seen := map[string]bool{p.ID + "/" + model: true}for _, id := range p.Fallback {+ if g, ms, ok := provider.FallbackGroup(id); ok {+ // a routing group: its members as a request to it has them,+ // in its order, routing and sink, less any model tried+ // already (this provider's own, another fallback's); a+ // member's fallbacks are not followed, so nothing leads back+ if paused != nil {+ ms = paused(g, ms)+ }+ ms = slices.DeleteFunc(ms, func(m provider.Member) bool {+ k := m.Provider.ID + "/" + m.Model+ if seen[k] {+ return true+ }+ seen[k] = true+ return false+ })+ out = append(out, planFallbackGroup(g, ms, from, &pl)...)+ continue+ }fp, fm, ok := provider.ResolveRoute(id)if !ok || seen[fp.ID+"/"+fm] {continue@@ -446,6 +472,36 @@ func (s *Server) plan(p provider.Provider, model string, from provider.Protocol)return restLast(out, pl)}+// planFallbackGroup is planGroup for a routing group a provider falls back+// to, its rows added to pl as fallbacks reached through g: the group's+// keys and accounts in its own order, sunk by its own Sink, those set+// aside after them.+func planFallbackGroup(g provider.Group, ms []provider.Member, from provider.Protocol, pl *planned) []candidate {+ if len(ms) == 0 {+ return nil+ }+ at, leftAt, unlistedAt := len(pl.order), len(pl.left), len(pl.unlistedW)+ var asides []candidate+ var wAsides []Weighed+ out := planLevel(g, ms, 0, from, pl, &asides, &wAsides)+ if sinks(g.Sink, g.Routing) {+ var order []Weighed+ out, order = sinkPlanned(out, pl.order[at:])+ pl.order = append(pl.order[:at], order...)+ }+ out, pl.order = append(out, asides...), append(pl.order, wAsides...)+ via := func(ws []Weighed) {+ for i := range ws {+ ws[i].Fallback = true+ ws[i].Via = append([]string{g.ID}, ws[i].Via...)+ }+ }+ via(pl.order[at:])+ via(pl.left[leftAt:])+ via(pl.unlistedW[unlistedAt:])+ return out+}+// planGroup is plan for a routing group: every member's keys or accounts// weighed together as the group's routing says — in order, member by// member, each as its own provider's routing orders it; else all as one,diff --git a/internal/gateway/fallback_group_test.go b/internal/gateway/fallback_group_test.gonew file mode 100644index 000000000..605598c41--- /dev/null+++ b/internal/gateway/fallback_group_test.go@@ -0,0 +1,160 @@+package gateway++import (+ "net/http/httptest"+ "strings"+ "testing"+ "time"++ "github.com/yetone/magpie/internal/provider"+)++// fallbackToGroup saves a provider "plan" whose key kp answers 429 (out of+// quota) and falls back to the routing group "backup" of members, served+// by a (key ka, model x) and b (key kb, model x).+func fallbackToGroup(t *testing.T, g provider.Group) (plan, a, b *keyed) {+ t.Helper()+ fresh(t)+ plan, a, b = &keyed{fail: map[string]int{"kp": 429}}, &keyed{}, &keyed{}+ serveOn(t, "a", "ka", []string{"x"}, a)+ serveOn(t, "b", "kb", []string{"x"}, b)+ up := httptest.NewServer(plan)+ t.Cleanup(up.Close)+ if err := provider.Save(provider.Provider{ID: "plan", Name: "Plan", Key: "kp", Models: []string{"m"}, Chat: up.URL + "/v1", Fallback: []string{"group/backup"}}); err != nil {+ t.Fatal(err)+ }+ g.ID, g.Name = "backup", "Backup"+ if err := provider.SaveGroup(g); err != nil {+ t.Fatal(err)+ }+ return plan, a, b+}++// A provider's fallback can be a routing group, not only a model+// (01huadalang on Discord): with the primary out of quota, the request+// goes through the group, its members in the group's own order.+func TestFallbackToGroupServedByMember(t *testing.T) {+ plan, a, b := fallbackToGroup(t, provider.Group{Members: []string{"a/x", "b/x"}, Routing: provider.Ordered})+ a.fail = map[string]int{"ka": 429}+ code, body := postAs(t, New(), "", `{"model":"plan/m","messages":[{"role":"user","content":"hi"}]}`)+ if code != 200 || !strings.Contains(body, "from kb") {+ t.Fatalf("plan/m out of quota, falling back to group/backup: %d %s", code, body)+ }+ if len(plan.tried) != 1 || len(a.tried) != 1 || len(b.tried) != 1 {+ t.Fatalf("each tried once, the group's order: plan %v, a %v, b %v", plan.tried, a.tried, b.tried)+ }+}++// The group's own order holds: In order with b first sends to b, a never+// asked once b answers.+func TestFallbackGroupKeepsItsOrder(t *testing.T) {+ _, a, b := fallbackToGroup(t, provider.Group{Members: []string{"b/x", "a/x"}, Routing: provider.Ordered})+ code, body := postAs(t, New(), "", `{"model":"plan/m","messages":[{"role":"user","content":"hi"}]}`)+ if code != 200 || !strings.Contains(body, "from kb") || len(a.tried) != 0 || len(b.tried) != 1 {+ t.Fatalf("group b, a: %d %s, a %v, b %v", code, body, a.tried, b.tried)+ }+}++// A group holding the provider's own model is no loop: the model is tried+// once, as the primary, and the group's other members after it.+func TestFallbackGroupWithThePrimaryTriesItOnce(t *testing.T) {+ plan, a, b := fallbackToGroup(t, provider.Group{Members: []string{"plan/m", "a/x", "b/x"}, Routing: provider.Ordered})+ a.fail = map[string]int{"ka": 500}+ b.fail = map[string]int{"kb": 500}+ if code, _ := postAs(t, New(), "", `{"model":"plan/m","messages":[{"role":"user","content":"hi"}]}`); code == 200 {+ t.Fatalf("every one failing answered 200")+ }+ // every one failing, the request is asked again as many times as+ // magpie's patience has it; each round asks each model once+ if len(plan.tried) == 0 || len(a.tried) != len(plan.tried) || len(b.tried) != len(plan.tried) {+ t.Fatalf("each tried once a round: plan %v, a %v, b %v", plan.tried, a.tried, b.tried)+ }+}++// A model named both as a fallback and in a fallback group is tried once,+// where it was named first; so is a model two fallback groups share.+func TestFallbackGroupSharedModelTriedOnce(t *testing.T) {+ plan, a, b := fallbackToGroup(t, provider.Group{Members: []string{"a/x", "b/x"}, Routing: provider.Ordered})+ if err := provider.SaveGroup(provider.Group{ID: "more", Name: "More", Members: []string{"b/x", "a/x"}, Routing: provider.Ordered}); err != nil {+ t.Fatal(err)+ }+ p, err := provider.Find("plan")+ if err != nil {+ t.Fatal(err)+ }+ p.Fallback = []string{"a/x", "group/backup", "group/more"}+ if err := provider.Save(*p); err != nil {+ t.Fatal(err)+ }+ a.fail = map[string]int{"ka": 500}+ b.fail = map[string]int{"kb": 500}+ postAs(t, New(), "", `{"model":"plan/m","messages":[{"role":"user","content":"hi"}]}`)+ // every one failing, the request is asked again as many times as+ // magpie's patience has it; each round asks each model once+ if len(plan.tried) == 0 || len(a.tried) != len(plan.tried) || len(b.tried) != len(plan.tried) {+ t.Fatalf("each tried once a round: plan %v, a %v, b %v", plan.tried, a.tried, b.tried)+ }+}++// A member the group's pause rule holds now is out of the group as a+// fallback too, as it is for a request to the group.+func TestFallbackGroupPauseHolds(t *testing.T) {+ now := time.Date(2026, 9, 29, 10, 0, 0, 0, time.Local) // a Tuesday, in peak+ ruleClock = func() time.Time { return now }+ t.Cleanup(func() { ruleClock = time.Now })+ _, a, b := fallbackToGroup(t, provider.Group{Members: []string{"a/x", "b/x"}, Routing: provider.Ordered,+ Rules: []provider.Rule{{Use: "a/x", Pause: true, Time: peak}}})+ code, body := postAs(t, New(), "", `{"model":"plan/m","messages":[{"role":"user","content":"hi"}]}`)+ if code != 200 || !strings.Contains(body, "from kb") || len(a.tried) != 0 {+ t.Fatalf("a/x paused: %d %s, a %v, b %v", code, body, a.tried, b.tried)+ }+}++// A fallback group that is gone is passed over, as a model none serves is.+func TestFallbackGroupGoneIsSkipped(t *testing.T) {+ plan, a, b := fallbackToGroup(t, provider.Group{Members: []string{"a/x"}, Routing: provider.Ordered})+ p, err := provider.Find("plan")+ if err != nil {+ t.Fatal(err)+ }+ p.Fallback = []string{"group/nothing", "b/x"}+ if err := provider.Save(*p); err != nil {+ t.Fatal(err)+ }+ code, body := postAs(t, New(), "", `{"model":"plan/m","messages":[{"role":"user","content":"hi"}]}`)+ if code != 200 || !strings.Contains(body, "from kb") || len(a.tried) != 0 || len(plan.tried) != 1 {+ t.Fatalf("group/nothing then b/x: %d %s, a %v, b %v", code, body, a.tried, b.tried)+ }+}++// A provider set to go unmasked stays masked when a routing group among+// its fallbacks may send the request to a model that isn't: the group's+// members are its fallbacks as much as a model named alone is.+func TestFallbackGroupKeepsMasking(t *testing.T) {+ fresh(t)+ for _, p := range []provider.Provider{+ {ID: "near", Name: "Near", Key: "k1", Models: []string{"m"}, Chat: "http://127.0.0.1:1/v1", Unredacted: true, Fallback: []string{"group/backup"}},+ {ID: "near2", Name: "Near2", Key: "k2", Models: []string{"m"}, Chat: "http://127.0.0.1:2/v1", Unredacted: true},+ {ID: "far", Name: "Far", Key: "k3", Models: []string{"m"}, Chat: "https://api.example.com/v1"},+ } {+ if err := provider.Save(p); err != nil {+ t.Fatal(err)+ }+ }+ if err := provider.SaveGroup(provider.Group{ID: "backup", Name: "Backup", Members: []string{"near2/m"}}); err != nil {+ t.Fatal(err)+ }+ near, err := provider.Find("near")+ if err != nil {+ t.Fatal(err)+ }+ if !unredactedRoute(*near, false, nil) {+ t.Fatal("a group of unmasked local models masked the request")+ }+ if err := provider.SaveGroup(provider.Group{ID: "backup", Name: "Backup", Members: []string{"near2/m", "far/m"}}); err != nil {+ t.Fatal(err)+ }+ if unredactedRoute(*near, false, nil) {+ t.Fatal("a fallback group with a remote member left the request unmasked")+ }+}diff --git a/internal/gateway/gateway.go b/internal/gateway/gateway.goindex da372425b..19cf25520 100644--- a/internal/gateway/gateway.go+++ b/internal/gateway/gateway.go@@ -2226,7 +2226,16 @@ func (s *Server) serve(w http.ResponseWriter, r *http.Request, from provider.Proscope += "|" + words}} else {- cands, pl = s.plan(p, model, from)+ // a routing group among the fallbacks is routed as a request to it+ // would be, its pause rules too (pausedOut's)+ cands, pl = s.planPaused(p, model, from, func(fg provider.Group, fms []provider.Member) []provider.Member {+ folder := ""+ if provider.PausesByFolder(fg, fms) {+ folder = factsOf(from, body).dir+ }+ kept, _ := provider.PausedOut(fg, fms, agent, folder, ruleClock())+ return kept+ })if handedOnOf(r) != nil {// Codex's own sign-in, asked as often as it is asked: only// the fallbacks are left (codexFallBack)diff --git a/internal/gateway/native_compaction.go b/internal/gateway/native_compaction.goindex f1f671f22..3fd564f8b 100644--- a/internal/gateway/native_compaction.go+++ b/internal/gateway/native_compaction.go@@ -116,14 +116,8 @@ func (s *Server) nativeCompactionFor(asked string) bool {if s.plannedCarrier(p, model) {return true}- seen := map[string]bool{p.ID + "/" + model: true}- for _, id := range p.Fallback {- fp, fm, ok := provider.ResolveRoute(id)- if !ok || seen[fp.ID+"/"+fm] {- continue- }- seen[fp.ID+"/"+fm] = true- if s.plannedCarrier(fp, fm) {+ for _, m := range provider.FallbackModels(p) {+ if (m.Provider.ID != p.ID || m.Model != model) && s.plannedCarrier(m.Provider, m.Model) {return true}}diff --git a/internal/gateway/redact.go b/internal/gateway/redact.goindex 55f844e40..5115e16d6 100644--- a/internal/gateway/redact.go+++ b/internal/gateway/redact.go@@ -303,9 +303,10 @@ func unredactedRoute(p provider.Provider, isGroup bool, ms []provider.Member) boif !p.SkipsRedaction() {return false}- for _, id := range p.Fallback {- // one that resolves to nothing isn't tried (plan)- if fp, _, ok := provider.ResolveRoute(id); ok && !fp.SkipsRedaction() {+ // one that resolves to nothing isn't tried (plan); a routing group+ // among them is each of its members+ for _, m := range provider.FallbackModels(p) {+ if !m.Provider.SkipsRedaction() {return false}}diff --git a/internal/gui/assets/app.css b/internal/gui/assets/app.cssindex 8a75f331b..5791c5f2f 100644--- a/internal/gui/assets/app.css+++ b/internal/gui/assets/app.css@@ -2868,6 +2868,9 @@ body.window .ag-sk-icon { width: 22px; height: 22px; border-radius: 6px; }.fbrow { display: flex; align-items: center; gap: 8px; min-height: 28px; font-size: 12.5px; }.fbrow .i { width: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }.fbrow .grow { flex: 1; }+/* a routing group among the fallbacks: its fan, then the muted word */+.fbrow .mtell { color: var(--muted); font-size: 11px; flex: none; }+.fbrow > svg { flex: none; color: var(--muted); }.fallback .mchips:empty { display: none; }.after-list { display: flex; align-items: center; gap: 8px; padding: 8px 4px 0; flex: none; }/* the Providers page's add button stays at the view's foot over a long list;diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.jsindex 61aa9158e..d9d73e2a1 100644--- a/internal/gui/assets/app.js+++ b/internal/gui/assets/app.js@@ -11849,13 +11849,16 @@ function renderFallback(p) {const box = el("div", "fallback");const list = el("div", "fbl");const sugg = el("div", "mchips");- const q = input("", t("add a model: filter, or type provider/model…"));+ const q = input("", t("add a model or routing group: filter, or type provider/model…"));const all = [];+ // a routing group too, routed as itself (01huadalang)+ for (const g of providers.gateway?.groups || []) all.push({ id: g.id, label: g.name, g: g.providers?.join(" ") || "" });for (const o of providers.providers) {if (!o.ready || o.off) continue;const tells = modelTells(o.models.filter((m) => m.on));for (const m of o.models) if (m.on) all.push({ id: o.id + "/" + m.id, label: o.name + " · " + (m.name || m.id) + (tells.has(m.id) ? " · " + tells.get(m.id) : ""), icon: o.icon });}+ const tell = () => el("span", "mtell", t("routing group"));let open = false;const add = (id) => { if (id && !draft.fallback.includes(id)) draft.fallback.push(id); q.value = ""; draw(); };const draw = () => {@@ -11863,8 +11866,9 @@ function renderFallback(p) {draft.fallback.forEach((id, i) => {const known = all.find((x) => x.id === id);const row = el("div", "fbrow");- row.append(el("span", "i", String(i + 1)), icon(known?.icon || "generic"), el("span", "n", known ? known.label : id), el("span", "grow"));- if (!known) row.title = t("No provider serves {id} now; it is skipped", { id });+ const g = id.startsWith("group/");+ row.append(el("span", "i", String(i + 1)), g ? svg(FAN, 16, 1.5) : icon(known?.icon || "generic"), el("span", "n", known ? known.label : id), ...(g ? [tell()] : []), el("span", "grow"));+ if (!known) row.title = t(g ? "No routing group {id} now; it is skipped" : "No provider serves {id} now; it is skipped", { id });if (i) {const up = el("button", "text", t("Up"));up.onclick = () => { draft.fallback.splice(i - 1, 0, draft.fallback.splice(i, 1)[0]); draw(); };@@ -11878,10 +11882,10 @@ function renderFallback(p) {sugg.replaceChildren();if (!open && !q.value.trim()) return;const f = q.value.trim().toLowerCase();- const hits = all.filter((x) => !draft.fallback.includes(x.id) && !x.id.startsWith(p.id + "/") && (x.id + " " + x.label).toLowerCase().includes(f));+ const hits = all.filter((x) => !draft.fallback.includes(x.id) && !x.id.startsWith(p.id + "/") && (x.id + " " + x.label + " " + (x.g ?? "")).toLowerCase().includes(f));for (const x of hits.slice(0, 12)) {const c = el("button", "mchip");- c.append(el("span", "", x.label));+ c.append(...(x.g != null ? [svg(FAN, 12, 1.5), el("span", "", x.label), tell()] : [el("span", "", x.label)]));c.title = x.id;c.onmousedown = (e) => e.preventDefault(); // keep the box focusedc.onclick = () => add(x.id);@@ -11889,7 +11893,7 @@ function renderFallback(p) {}// only the first dozen are drawn: the rest are said to be thereif (hits.length > 12) sugg.append(el("span", "hint", t("{n} more — type to narrow", { n: hits.length - 12 })));- if (!hits.length && f) sugg.append(el("span", "hint", f.includes("/") ? t("Enter adds {id}", { id: q.value.trim() }) : t("No model matches")));+ if (!hits.length && f) sugg.append(el("span", "hint", f.includes("/") ? t("Enter adds {id}", { id: q.value.trim() }) : t("No model or routing group matches")));};q.onfocus = () => { open = true; draw(); };q.onblur = () => { open = false; draw(); };diff --git a/internal/gui/assets/i18n.js b/internal/gui/assets/i18n.jsindex cb0b00b6a..958791073 100644--- a/internal/gui/assets/i18n.js+++ b/internal/gui/assets/i18n.js@@ -1543,14 +1543,15 @@ const I18N = {"e.g. 500k · or deepseek-v4-flash=272k, comma separated": "如 500k · 或 deepseek-v4-flash=272k,逗号分隔","Where Codex, Claude Code and Grok Build compact a long conversation on these models; empty follows Long conversations, in their settings on the Agents page (else in Settings), and a size at or above a model's window runs it to its whole window": "Codex、Claude Code 和 Grok Build 在这些模型上压缩长对话的位置;留空按 Agent 页里它们设置中的「长对话」(否则在「设置」里),大于等于模型窗口则用完整窗口","Compact at: {v} is not a number of tokens like 272k": "压缩阈值:{v} 不是 272k 这样的 token 数",- "add a model: filter, or type provider/model…": "添加模型:筛选,或输入 provider/model…",+ "add a model or routing group: filter, or type provider/model…": "添加模型或路由组:筛选,或输入 provider/model…","No provider serves {id} now; it is skipped": "现在没有供应商提供 {id},会跳过它",+ "No routing group {id} now; it is skipped": "现在没有路由组 {id},会跳过它","Up": "上移","Down": "下移","switched off": "已关闭","Move {name}": "移动 {name}","Enter adds {id}": "回车添加 {id}",- "No model matches": "没有匹配的模型",+ "No model or routing group matches": "没有匹配的模型或路由组","When {name} is out of quota, rate limited or down, a request goes to these instead, top first. It only happens before any of the reply is sent, and {name} then sits out a minute.": "{name} 额度用完、限流或不可用时,请求按从上到下的顺序改发给这些模型。仅在回复开始前切换,之后 {name} 暂停使用一分钟。","{agent} and the gateway use the one in use. Sessions already running keep theirs until restarted.": "{agent} 和网关使用标记为「使用中」的账号。已在运行的会话保持原账号,重启后切换。","The gateway uses the first. Tick more and it moves on to the next when the one before it is out of quota. {agent} itself stays signed in as it is.": "网关优先用第一个账号;勾选多个时,前一个额度用完自动换下一个。{agent} 本身的登录不变。",@@ -5593,14 +5594,15 @@ const I18N = {"e.g. 500k · or deepseek-v4-flash=272k, comma separated": "如 500k · 或 deepseek-v4-flash=272k,逗號分隔","Where Codex, Claude Code and Grok Build compact a long conversation on these models; empty follows Long conversations, in their settings on the Agents page (else in Settings), and a size at or above a model's window runs it to its whole window": "Codex、Claude Code 和 Grok Build 在這些模型上壓縮長對話的位置;留空按 Agent 頁裡它們設定中的「長對話」(否則在「設定」裡),大於等於模型視窗則用完整視窗","Compact at: {v} is not a number of tokens like 272k": "壓縮閾值:{v} 不是 272k 這樣的 token 數",- "add a model: filter, or type provider/model…": "新增模型:篩選,或輸入 provider/model…",+ "add a model or routing group: filter, or type provider/model…": "新增模型或路由組:篩選,或輸入 provider/model…","No provider serves {id} now; it is skipped": "現在沒有供應商提供 {id},會跳過它",+ "No routing group {id} now; it is skipped": "現在沒有路由組 {id},會跳過它","Up": "上移","Down": "下移","switched off": "已關閉","Move {name}": "移動 {name}","Enter adds {id}": "回車新增 {id}",- "No model matches": "沒有匹配的模型",+ "No model or routing group matches": "沒有匹配的模型或路由組","When {name} is out of quota, rate limited or down, a request goes to these instead, top first. It only happens before any of the reply is sent, and {name} then sits out a minute.": "{name} 額度用完、限流或不可用時,請求按從上到下的順序改發給這些模型。僅在回覆開始前切換,之後 {name} 暫停使用一分鐘。","{agent} and the gateway use the one in use. Sessions already running keep theirs until restarted.": "{agent} 和閘道使用標記為「使用中」的帳號。已在執行的會話保持原帳號,重啟後切換。","The gateway uses the first. Tick more and it moves on to the next when the one before it is out of quota. {agent} itself stays signed in as it is.": "閘道優先用第一個帳號;勾選多個時,前一個額度用完自動換下一個。{agent} 本身的登入不變。",@@ -9620,14 +9622,15 @@ const I18N = {"e.g. 500k · or deepseek-v4-flash=272k, comma separated": "例:500k · または deepseek-v4-flash=272k(カンマ区切り)","Where Codex, Claude Code and Grok Build compact a long conversation on these models; empty follows Long conversations, in their settings on the Agents page (else in Settings), and a size at or above a model's window runs it to its whole window": "Codex、Claude Code、Grok Build がこれらのモデルで長い会話を圧縮する位置です。空欄ならエージェントページのそれぞれの設定にある「長い会話」(なければ「設定」)に従い、モデルのウィンドウ以上ならウィンドウ全体を使います","Compact at: {v} is not a number of tokens like 272k": "圧縮しきい値:{v} は 272k のようなトークン数ではありません",- "add a model: filter, or type provider/model…": "モデルを追加:絞り込み、または provider/model を入力…",+ "add a model or routing group: filter, or type provider/model…": "モデルまたはルーティンググループを追加:絞り込み、または provider/model を入力…","No provider serves {id} now; it is skipped": "現在 {id} を提供しているプロバイダはないため、スキップされます",+ "No routing group {id} now; it is skipped": "現在ルーティンググループ {id} はないため、スキップされます","Up": "上へ","Down": "下へ","switched off": "オフ","Move {name}": "{name} を移動","Enter adds {id}": "Enter で {id} を追加",- "No model matches": "一致するモデルはありません",+ "No model or routing group matches": "一致するモデルやルーティンググループはありません","When {name} is out of quota, rate limited or down, a request goes to these instead, top first. It only happens before any of the reply is sent, and {name} then sits out a minute.": "{name} のクォータ切れ、レート制限、ダウン時には、リクエストは代わりにこれらへ上から順に送られます。応答が送られ始める前にのみ切り替わり、その後 {name} は 1 分間休止します。","{agent} and the gateway use the one in use. Sessions already running keep theirs until restarted.": "{agent} とゲートウェイは使用中のアカウントを使います。実行中のセッションは再起動するまで元のアカウントのままです。","The gateway uses the first. Tick more and it moves on to the next when the one before it is out of quota. {agent} itself stays signed in as it is.": "ゲートウェイは最初のアカウントを使います。複数にチェックを入れると、前のアカウントのクォータが切れたときに次へ移ります。{agent} 自身のサインインはそのままです。",@@ -13677,14 +13680,15 @@ const I18N = {"e.g. 500k · or deepseek-v4-flash=272k, comma separated": "z. B. 500k · oder deepseek-v4-flash=272k, durch Kommas getrennt","Where Codex, Claude Code and Grok Build compact a long conversation on these models; empty follows Long conversations, in their settings on the Agents page (else in Settings), and a size at or above a model's window runs it to its whole window": "Wo Codex, Claude Code und Grok Build eine lange Unterhaltung bei diesen Modellen komprimieren; leer folgt Lange Unterhaltungen in ihren Einstellungen auf der Seite Agenten (sonst unter Einstellungen), ein Wert ab dem Fenster des Modells nutzt das ganze Fenster","Compact at: {v} is not a number of tokens like 272k": "Komprimieren ab: {v} ist keine Token-Zahl wie 272k",- "add a model: filter, or type provider/model…": "Modell hinzufügen: filtern oder provider/model eingeben…",+ "add a model or routing group: filter, or type provider/model…": "Modell oder Weiterleitungsgruppe hinzufügen: filtern oder provider/model eingeben…","No provider serves {id} now; it is skipped": "Derzeit stellt kein Anbieter {id} bereit; es wird übersprungen",+ "No routing group {id} now; it is skipped": "Derzeit gibt es keine Weiterleitungsgruppe {id}; sie wird übersprungen","Up": "Nach oben","Down": "Nach unten","switched off": "ausgeschaltet","Move {name}": "{name} verschieben","Enter adds {id}": "Enter fügt {id} hinzu",- "No model matches": "Kein Modell passt",+ "No model or routing group matches": "Kein Modell und keine Weiterleitungsgruppe passt","When {name} is out of quota, rate limited or down, a request goes to these instead, top first. It only happens before any of the reply is sent, and {name} then sits out a minute.": "Hat {name} kein Kontingent mehr, wird gedrosselt oder fällt aus, geht eine Anfrage stattdessen an diese, von oben nach unten. Das geschieht nur, bevor ein Teil der Antwort gesendet wurde, und {name} pausiert dann eine Minute.","{agent} and the gateway use the one in use. Sessions already running keep theirs until restarted.": "{agent} und der Zugangspunkt verwenden das Konto „In Verwendung“. Laufende Sitzungen behalten ihres bis zum Neustart.","The gateway uses the first. Tick more and it moves on to the next when the one before it is out of quota. {agent} itself stays signed in as it is.": "Der Zugangspunkt verwendet das erste. Haken Sie weitere an, wechselt er zum nächsten, sobald das vorherige kein Kontingent mehr hat. {agent} selbst bleibt angemeldet wie bisher.",diff --git a/internal/gui/core_budget_test.go b/internal/gui/core_budget_test.goindex 48d165c6c..925092cb3 100644--- a/internal/gui/core_budget_test.go+++ b/internal/gui/core_budget_test.go@@ -15,8 +15,8 @@ import (// so a page can't quietly grow back into the core; a change that needs more// raises them and says why in its commit.const (- appScriptBudget = 1_311_735 // app.js: 1,198,239 after Usage left (P2); 1,218,098 with the 10-15 fixes to pages still in the core; 1,232,466 with the provider editor's Advanced fold and every dialog holding its place, the core's own (10-16); 1,250,533 with the quota refresh kept through redraws, the core's own since the tray panel draws it too, plus 1.5% (#2397); 1,269,083 with Free first's option in the provider editor's ROUTINGS, which the Routing page reads too, plus 1.5%; 1,272,726 with the Providers page drawing its last list at once (#1519), the core's page, and the Routing trace's account names read without Object.entries (#1481), plus 1.5%; a dialog growing out of the row that opened it and folding back into it, the core's own since every page's dialogs open through it (10-20); Codex's and Claude Code's own settings moved from Settings into the agent's row on the Agents page, the core's own since the tray panel and the window both draw them (10-20); 1,314,432 with Settings › Privacy's record of what was masked (its summary, the records view and the local model's controls), which belongs to Settings, the core's own, plus 1.5%; 1,336,481 with a provider's Names & levels saying Provider in model names is Settings' and opening it there (joe), and Settings' Image recognition saying where a custom provider's model is marked (nexnull), both in the core's own pages, with no room added (10-23); 1,337,633 with Settings › Models › Replies' Intent classifier timeout (#2934, reyoung), Settings' own row, drawn by waitRow, which the Image generation timeout's row now shares, with no room added; 1,337,735 with the provider editor's link naming a partner's page by its own host (siteHost) instead of usemagpie.ai's /go link, the core's own editor, with no room added (10-23); 1,338,084 with Check in now saying what the press came to (claimed +credits, already today, not available yet) where it said "refreshed" (#3326), the check-in row the tray panel draws too, the core's own, with no room added (10-23); 1,338,929 with a new partner's tile keeping a small dot until it is opened, in the add sheet, the core's own, with no room added (10-23); 1,343,324 with the sidebar's open-page row marked by one shape that moves on a spring (navTopGo), the window's own shell, which every page sits beside, with no room added (10-23); 1,343,465 with a dialog kept centred while its content comes in, until it is pressed (holdModal, every page's dialogs), the core's own, with no room added (10-24); 1,317,486 with what masking did moved out to Insights › Masking (plugins/redact), the budget lowered to it (10-24); 1,321,336 with Codex's one subagent model, its card's square saying plainly what each choice does and a row with a name in its sheet, where two squares read alike (the owner), the Agents page's, which the tray panel draws too, the core's own, with no room added (10-24); 1,321,424 with Settings › Models' Image generation MCP server row beside Image recognition's (JonahFu on X), the two drawn by one helper (mcpRow), Settings' own, with no room added (10-25); 1,321,994 with a provider of the user's set never to rest for a limit (zoecats), the provider editor's Advanced row, the core's own editor, with no room added (10-25); 1,322,289 with Settings › Privacy's Keep a key's form under Mask secrets (Charles Cao on X), Settings' own row, with no room added (10-25); 1,322,537 with no Codex squares beside its named settings rows (the owner), with no room added (10-25); 1,323,401 with the tray panel drawing its last allowances at once and asking for them beside the state (#3160, #3134), the tray panel's, the core's own, and the 4 bytes 84c50f032 added, with no room added (10-25); 1,326,105 with many releases' notes merged into one list by kind, each line with its version (the owner), in the update sheet and What's new, with no room added (10-25); 1,321,319 with Settings › Observability moved out to its plugin (plugins/otel/page.js) and its Langfuse setup there (an X user), the budget lowered to it (10-26); a quota card whose window is used but names no reset no longer saying "Not used yet" (windy on Discord) raised it to 1,321,347, and back to 1,321,319 with Settings' model pickers sharing one row helper (modelOpt) where six kept their own copy, no raise (10-26); 1,325,845 with every slow page's skeletons getting magpie's bird hopping bar to bar (skelBird, the owner after the Plugins page's README), one bird for the window over whatever page or dialog is loading, the core's own, with no room added (10-26); 1,310,129 with Settings › Network and sharing's gateway rows (its port, bare ids, local network, allowed addresses, web pages) moved out to the gateway plugin (plugins/gateway/settings.js), the budget lowered to it (10-27); 1,310,269 with Test models naming the first model that failed and its error in the status line, where it said only how many (ysm119 on Discord), the provider editor's, the core's own, with no room added (10-27); 1,310,460 with Settings › About's Website row linking usemagpie.ai (the owner), Settings' own row, with no room added (10-27); 1,309,669 with a pool's Stop at the caps and Check usage near a cap ticks under a provider's accounts (plugins#349), the core's own editor, its account rows' Remove and add rows each drawn by one helper (forgetOf, addRow), with no room added (10-28); 1,311,681 with Install another agent on the Agents page naming the agents Plugins has (More in Plugins) and opening Plugins at its Agents (the owner), the Agents page's, the core's own, with no room added (10-28); 1,311,735 with More in Plugins in sight while Install another agent is folded (the owner), with no room added (10-29)- coreScriptBudget = 1_530_861 // every core script: 1,358,034 after Usage left; 1,380,003 with them; 1,405,937 with the fold; 1,426,102 with 10-16's core work (the GitHub list loading, the move to plugins, Settings › Long conversations), plus 1.5% (#2612); 1,447,368 with loadBack, the window's one state read per return, which every page needs and so is the core's own (1,446,845 before it, 155 bytes under), plus 1.5%; OpenCode Zen's card saying OpenCode tells no key its balance adds ~390 bytes inside it; 1,472,589 with the dialog that grows out of its row and the agents' own settings in their rows, on main's 10-20 core work (the Providers page's last list, the Routing trace's names), plus 1.5% (10-20); 1,506,192 with Settings › Privacy's record of what was masked, plus 1.5%; 1,529,393 with the Intent classifier timeout row (#2934), with no room added; 1,529,495 with the editor's partner link host, with no room added; 1,529,844 with Check in now's press summary (#3326), with no room added; 1,530,689 with the new partner tile's dot, with no room added; 1,535,084 with the sidebar's spring, with no room added; 1,549,478 with the context window card's map (tiles by tokens, the default look, the block grid a switch away) and its text view showing an inline image, in context.js, which the Routing page draws as well as Usage, so the core's own, with no room added (10-24); 1,550,768 with a usage card's refresh opening after its text (#840's card, which the tray panel draws too), the Add key spinner, and a dialog kept centred while its content comes in, with no room added (10-24); 1,524,789 with what masking did moved out to Insights › Masking, lowered to it; 1,528,525 with Codex's one subagent model, with no room added (10-24); 1,528,972 with the Image generation MCP server row (JonahFu on X), with no room added (10-25); 1,529,542 with the limit-rest row (zoecats), with no room added (10-25); 1,529,837 with Keep a key's form (Charles Cao on X), with no room added (10-25); 1,530,050 with no Codex squares beside its named settings rows (the owner), with no room added (10-25); 1,530,631 with a plugin's page growing to its README on the dialog's spring instead of in one jump (the owner), the Plugins page's, in plugins.js, with no room added (10-25); 1,533,445 with the context map counting its tokens on as a live request grows, a tile pointed at keeping its tip, a tool's gathered results saying how many and the small files their folder (the owner, after flohoeller's map on X), in context.js, which the Routing page draws as well as Usage, and the 4 bytes 84c50f032 added to app.js (Settings' Version row) without a raise, with no room added (10-25); 1,534,312 with the tray panel's last allowances drawn at once (#3160, #3134), with no room added (10-25); 1,537,016 with many releases' notes merged into one list by kind (the owner), in app.js, with no room added (10-25); 1,542,244 with a plugin's README loading under magpie's bird bouncing down its lines instead of pulsing bars (the owner), the Plugins page's, in plugins.js, with no room added (10-26); 1,542,418 with a page plugin's sidebar tab coming and going as it is installed, switched on or off, or removed, instead of on the Plugins page's next load (the owner), in plugins.js, with no room added (10-26); 1,537,645 with Settings › Observability moved out to plugins/otel, lowered to it (10-26); 1,537,673 with a used window with no reset not "Not used yet" (windy on Discord), and back to 1,537,645 with Settings' model pickers sharing modelOpt (10-26); 1,541,967 with every slow page's skeletons getting magpie's bird (skelBird, the owner), in app.js, the README's bird sharing its drawing and styles, with no room added (10-26); 1,526,251 with Settings' gateway rows moved out to plugins/gateway/settings.js, lowered to it (10-27); 1,526,391 with Test models naming the first failed model and its error (ysm119 on Discord), in app.js, with no room added (10-27); 1,526,556 with About's Website row (the owner), in app.js, with no room added (10-27); 1,526,500 with a pool's cap ticks (plugins#349), in app.js, with no room added (10-28); 1,527,245 with About's Open-source licenses row and dialog (the owner), in app.js, with no room added (10-28); 1,528,076 with the Partners heading's light (the owner), in app.js, with no room added (10-28); 1,530,449 with Install another agent's More in Plugins row (the owner), in app.js, and Plugins opening at its Agents, in plugins.js, with no room added (10-28); 1,530,807 with layout.js measuring the scrollbar into --bar, which every page's right padding takes off so its sides match (the owner), the window's own shell, with no room added (10-28); 1,530,861 with More in Plugins in sight while Install another agent is folded (the owner), in app.js, with no room added (10-29)+ appScriptBudget = 1_311_922 // app.js: 1,198,239 after Usage left (P2); 1,218,098 with the 10-15 fixes to pages still in the core; 1,232,466 with the provider editor's Advanced fold and every dialog holding its place, the core's own (10-16); 1,250,533 with the quota refresh kept through redraws, the core's own since the tray panel draws it too, plus 1.5% (#2397); 1,269,083 with Free first's option in the provider editor's ROUTINGS, which the Routing page reads too, plus 1.5%; 1,272,726 with the Providers page drawing its last list at once (#1519), the core's page, and the Routing trace's account names read without Object.entries (#1481), plus 1.5%; a dialog growing out of the row that opened it and folding back into it, the core's own since every page's dialogs open through it (10-20); Codex's and Claude Code's own settings moved from Settings into the agent's row on the Agents page, the core's own since the tray panel and the window both draw them (10-20); 1,314,432 with Settings › Privacy's record of what was masked (its summary, the records view and the local model's controls), which belongs to Settings, the core's own, plus 1.5%; 1,336,481 with a provider's Names & levels saying Provider in model names is Settings' and opening it there (joe), and Settings' Image recognition saying where a custom provider's model is marked (nexnull), both in the core's own pages, with no room added (10-23); 1,337,633 with Settings › Models › Replies' Intent classifier timeout (#2934, reyoung), Settings' own row, drawn by waitRow, which the Image generation timeout's row now shares, with no room added; 1,337,735 with the provider editor's link naming a partner's page by its own host (siteHost) instead of usemagpie.ai's /go link, the core's own editor, with no room added (10-23); 1,338,084 with Check in now saying what the press came to (claimed +credits, already today, not available yet) where it said "refreshed" (#3326), the check-in row the tray panel draws too, the core's own, with no room added (10-23); 1,338,929 with a new partner's tile keeping a small dot until it is opened, in the add sheet, the core's own, with no room added (10-23); 1,343,324 with the sidebar's open-page row marked by one shape that moves on a spring (navTopGo), the window's own shell, which every page sits beside, with no room added (10-23); 1,343,465 with a dialog kept centred while its content comes in, until it is pressed (holdModal, every page's dialogs), the core's own, with no room added (10-24); 1,317,486 with what masking did moved out to Insights › Masking (plugins/redact), the budget lowered to it (10-24); 1,321,336 with Codex's one subagent model, its card's square saying plainly what each choice does and a row with a name in its sheet, where two squares read alike (the owner), the Agents page's, which the tray panel draws too, the core's own, with no room added (10-24); 1,321,424 with Settings › Models' Image generation MCP server row beside Image recognition's (JonahFu on X), the two drawn by one helper (mcpRow), Settings' own, with no room added (10-25); 1,321,994 with a provider of the user's set never to rest for a limit (zoecats), the provider editor's Advanced row, the core's own editor, with no room added (10-25); 1,322,289 with Settings › Privacy's Keep a key's form under Mask secrets (Charles Cao on X), Settings' own row, with no room added (10-25); 1,322,537 with no Codex squares beside its named settings rows (the owner), with no room added (10-25); 1,323,401 with the tray panel drawing its last allowances at once and asking for them beside the state (#3160, #3134), the tray panel's, the core's own, and the 4 bytes 84c50f032 added, with no room added (10-25); 1,326,105 with many releases' notes merged into one list by kind, each line with its version (the owner), in the update sheet and What's new, with no room added (10-25); 1,321,319 with Settings › Observability moved out to its plugin (plugins/otel/page.js) and its Langfuse setup there (an X user), the budget lowered to it (10-26); a quota card whose window is used but names no reset no longer saying "Not used yet" (windy on Discord) raised it to 1,321,347, and back to 1,321,319 with Settings' model pickers sharing one row helper (modelOpt) where six kept their own copy, no raise (10-26); 1,325,845 with every slow page's skeletons getting magpie's bird hopping bar to bar (skelBird, the owner after the Plugins page's README), one bird for the window over whatever page or dialog is loading, the core's own, with no room added (10-26); 1,310,129 with Settings › Network and sharing's gateway rows (its port, bare ids, local network, allowed addresses, web pages) moved out to the gateway plugin (plugins/gateway/settings.js), the budget lowered to it (10-27); 1,310,269 with Test models naming the first model that failed and its error in the status line, where it said only how many (ysm119 on Discord), the provider editor's, the core's own, with no room added (10-27); 1,310,460 with Settings › About's Website row linking usemagpie.ai (the owner), Settings' own row, with no room added (10-27); 1,309,669 with a pool's Stop at the caps and Check usage near a cap ticks under a provider's accounts (plugins#349), the core's own editor, its account rows' Remove and add rows each drawn by one helper (forgetOf, addRow), with no room added (10-28); 1,311,681 with Install another agent on the Agents page naming the agents Plugins has (More in Plugins) and opening Plugins at its Agents (the owner), the Agents page's, the core's own, with no room added (10-28); 1,311,735 with More in Plugins in sight while Install another agent is folded (the owner), with no room added (10-29); 1,311,922 with a provider's Fallback taking a routing group beside models, its fan and tell in the row and the picker (01huadalang on Discord), the core's own editor, with no room added (10-29)+ coreScriptBudget = 1_531_060 // every core script: 1,358,034 after Usage left; 1,380,003 with them; 1,405,937 with the fold; 1,426,102 with 10-16's core work (the GitHub list loading, the move to plugins, Settings › Long conversations), plus 1.5% (#2612); 1,447,368 with loadBack, the window's one state read per return, which every page needs and so is the core's own (1,446,845 before it, 155 bytes under), plus 1.5%; OpenCode Zen's card saying OpenCode tells no key its balance adds ~390 bytes inside it; 1,472,589 with the dialog that grows out of its row and the agents' own settings in their rows, on main's 10-20 core work (the Providers page's last list, the Routing trace's names), plus 1.5% (10-20); 1,506,192 with Settings › Privacy's record of what was masked, plus 1.5%; 1,529,393 with the Intent classifier timeout row (#2934), with no room added; 1,529,495 with the editor's partner link host, with no room added; 1,529,844 with Check in now's press summary (#3326), with no room added; 1,530,689 with the new partner tile's dot, with no room added; 1,535,084 with the sidebar's spring, with no room added; 1,549,478 with the context window card's map (tiles by tokens, the default look, the block grid a switch away) and its text view showing an inline image, in context.js, which the Routing page draws as well as Usage, so the core's own, with no room added (10-24); 1,550,768 with a usage card's refresh opening after its text (#840's card, which the tray panel draws too), the Add key spinner, and a dialog kept centred while its content comes in, with no room added (10-24); 1,524,789 with what masking did moved out to Insights › Masking, lowered to it; 1,528,525 with Codex's one subagent model, with no room added (10-24); 1,528,972 with the Image generation MCP server row (JonahFu on X), with no room added (10-25); 1,529,542 with the limit-rest row (zoecats), with no room added (10-25); 1,529,837 with Keep a key's form (Charles Cao on X), with no room added (10-25); 1,530,050 with no Codex squares beside its named settings rows (the owner), with no room added (10-25); 1,530,631 with a plugin's page growing to its README on the dialog's spring instead of in one jump (the owner), the Plugins page's, in plugins.js, with no room added (10-25); 1,533,445 with the context map counting its tokens on as a live request grows, a tile pointed at keeping its tip, a tool's gathered results saying how many and the small files their folder (the owner, after flohoeller's map on X), in context.js, which the Routing page draws as well as Usage, and the 4 bytes 84c50f032 added to app.js (Settings' Version row) without a raise, with no room added (10-25); 1,534,312 with the tray panel's last allowances drawn at once (#3160, #3134), with no room added (10-25); 1,537,016 with many releases' notes merged into one list by kind (the owner), in app.js, with no room added (10-25); 1,542,244 with a plugin's README loading under magpie's bird bouncing down its lines instead of pulsing bars (the owner), the Plugins page's, in plugins.js, with no room added (10-26); 1,542,418 with a page plugin's sidebar tab coming and going as it is installed, switched on or off, or removed, instead of on the Plugins page's next load (the owner), in plugins.js, with no room added (10-26); 1,537,645 with Settings › Observability moved out to plugins/otel, lowered to it (10-26); 1,537,673 with a used window with no reset not "Not used yet" (windy on Discord), and back to 1,537,645 with Settings' model pickers sharing modelOpt (10-26); 1,541,967 with every slow page's skeletons getting magpie's bird (skelBird, the owner), in app.js, the README's bird sharing its drawing and styles, with no room added (10-26); 1,526,251 with Settings' gateway rows moved out to plugins/gateway/settings.js, lowered to it (10-27); 1,526,391 with Test models naming the first failed model and its error (ysm119 on Discord), in app.js, with no room added (10-27); 1,526,556 with About's Website row (the owner), in app.js, with no room added (10-27); 1,526,500 with a pool's cap ticks (plugins#349), in app.js, with no room added (10-28); 1,527,245 with About's Open-source licenses row and dialog (the owner), in app.js, with no room added (10-28); 1,528,076 with the Partners heading's light (the owner), in app.js, with no room added (10-28); 1,530,449 with Install another agent's More in Plugins row (the owner), in app.js, and Plugins opening at its Agents, in plugins.js, with no room added (10-28); 1,530,807 with layout.js measuring the scrollbar into --bar, which every page's right padding takes off so its sides match (the owner), the window's own shell, with no room added (10-28); 1,530,861 with More in Plugins in sight while Install another agent is folded (the owner), in app.js, with no room added (10-29); 1,531,060 with a provider's Fallback taking a routing group (01huadalang on Discord), in app.js, with no room added (10-29))func TestCoreScriptBudget(t *testing.T) {diff --git a/internal/gui/tests/fallback-group.test.cjs b/internal/gui/tests/fallback-group.test.cjsnew file mode 100644index 000000000..a433b6b4b--- /dev/null+++ b/internal/gui/tests/fallback-group.test.cjs@@ -0,0 +1,103 @@+// Run with Node's test runner and Playwright on the module path; see README.md.+// A provider's Fallback can be a routing group, not only a model (01huadalang+// on Discord: "备用模型增加路由组的选择,现在只能选模型"). The picker lists+// the groups beside the models, each with the Routing fan and the words+// "routing group"; a group picked is a row with the same tell, and Save sends+// "group/<id>". A group that is gone says it is skipped. In English and+// Chinese; every new string has its zh, zh-TW, ja and de.+const assert = require("node:assert/strict");+const fs = require("node:fs/promises");+const path = require("node:path");+const { test } = require("node:test");+const { chromium, webkit } = require("playwright");++const assets = path.resolve(__dirname, "../assets");+const base = { chat: "", responses: "", anthropic: "", catalog: "", agents: [], fallback: [], headers: {}, keyList: [], key: { set: true }, ready: true };+const acme = { ...base, id: "acme", name: "Acme", icon: "generic", models: [{ id: "a1", name: "A1", on: true }], fallback: ["group/gone"] };+const wb = { ...base, id: "wb", name: "WorkBuddy", icon: "generic", models: [{ id: "m1", name: "WB Model 1", on: true }] };+const backup = { id: "group/backup", name: "Backup Lane", icons: ["generic"], providers: ["WorkBuddy"], members: ["wb/m1"], efforts: [] };++function serve(lang, posts) {+ const state = { agents: [], profiles: [], settings: { lang, theme: "light" } };+ const providers = { providers: [acme, wb], presets: [], excluded: [], gateway: { running: true, window: true, groups: [backup] } };+ return async (route) => {+ const url = new URL(route.request().url());+ const json = (data) => route.fulfill({ json: data });+ if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:true};` });+ if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });+ if (url.pathname === "/api/state") return json(state);+ if (url.pathname === "/api/providers") return json(providers);+ if (url.pathname === "/api/groups") return json({ groups: [] });+ if (url.pathname === "/api/plugins") return json({ plugins: [] });+ if (route.request().method() === "POST" && url.pathname.startsWith("/api/provider")) {+ posts.push({ path: url.pathname, body: route.request().postDataJSON() });+ return json(providers);+ }+ if (url.pathname.startsWith("/api/")) return json({});+ const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname);+ const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)];+ await route.fulfill({ body: await fs.readFile(file), contentType });+ };+}++const words = {+ en: { tell: "routing group", gone: "No routing group group/gone now; it is skipped", none: "No model or routing group matches", save: "Save" },+ zh: { tell: "路由组", gone: "现在没有路由组 group/gone,会跳过它", none: "没有匹配的模型或路由组", save: "保存" },+};++for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {+ for (const lang of ["en", "zh"]) {+ test(`${engine} ${lang}: a routing group can be picked as a fallback`, async (t) => {+ const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));+ t.after(() => browser.close());+ const page = await (await browser.newContext({ viewport: { width: 900, height: 760 }, reducedMotion: "reduce" })).newPage();+ page.setDefaultTimeout(5000);+ const errors = [], posts = [];+ page.on("pageerror", (e) => errors.push(e.message));+ await page.route("**/*", serve(lang, posts));+ await page.goto("http://magpie.test/?view=providers");+ const W = words[lang];+ const missing = await page.evaluate(() => {+ const keys = ["add a model or routing group: filter, or type provider/model…", "No routing group {id} now; it is skipped", "No model or routing group matches", "routing group"];+ return ["zh", "zh-TW", "ja", "de"].flatMap((l) => keys.filter((k) => !I18N[l]?.[k]).map((k) => l + ": " + k));+ });+ assert.deepEqual(missing, [], "every new string in every language");+ await page.locator(".row.provider", { hasText: "Acme" }).first().click();+ { const adv = page.locator(".editor details.advanced"); await adv.waitFor({ state: "attached" }); if (!(await adv.evaluate((d) => d.open))) await adv.locator(":scope > summary").click(); }+ const box = page.locator(".editor .fallback");+ // a group that is gone: its fan, its id, the tell, and why it is skipped+ const gone = box.locator(".fbrow").first();+ assert.equal(await gone.getAttribute("title"), W.gone);+ assert.equal((await gone.locator(".mtell").textContent()).trim(), W.tell);+ assert.equal(await gone.locator(":scope > svg").count(), 1, "the group's fan, not a provider icon");+ // the picker lists the group beside the models, with its fan and tell+ await box.locator("input").focus();+ const chip = box.locator(".mchips .mchip", { hasText: "Backup Lane" });+ await chip.waitFor();+ assert.equal(await chip.getAttribute("title"), "group/backup");+ assert.equal((await chip.locator(".mtell").textContent()).trim(), W.tell);+ assert.equal(await chip.locator("svg").count(), 1);+ assert.equal(await box.locator(".mchips .mchip", { hasText: "WB Model 1" }).count(), 1, "the models are still there");+ assert.equal(await box.locator("select").count(), 0, "never a native select");+ // a filter finds a group by its member providers too, and says when nothing matches+ await box.locator("input").fill("workbuddy");+ assert.equal(await chip.count(), 1);+ await box.locator("input").fill("zzz");+ assert.equal((await box.locator(".mchips .hint").textContent()).trim(), W.none);+ await box.locator("input").fill("");+ await box.locator("input").focus();+ await chip.click();+ const row = box.locator(".fbrow").nth(1);+ assert.equal((await row.locator(".n").textContent()).trim(), "Backup Lane");+ assert.equal((await row.locator(".mtell").textContent()).trim(), W.tell);+ assert.equal(await row.getAttribute("title"), null);+ // no coloured left-border accent on a group row+ assert.equal(await row.evaluate((e) => getComputedStyle(e).borderLeftWidth), "0px");+ const sent = page.waitForRequest((r) => r.method() === "POST" && new URL(r.url()).pathname.startsWith("/api/provider"));+ await page.getByRole("button", { name: W.save, exact: true }).click();+ await sent;+ assert.deepEqual(posts.at(-1).body.fallback, ["group/gone", "group/backup"]);+ assert.deepEqual(errors, []);+ });+ }+}diff --git a/internal/provider/group.go b/internal/provider/group.goindex 0fa2abae8..2bf3394c0 100644--- a/internal/provider/group.go+++ b/internal/provider/group.go@@ -784,6 +784,46 @@ func FindGroup(id string) (Group, []Member, bool) {return GroupFinder()(id)}+// FallbackGroup is the routing group a provider's fallback entry names+// ("group/<id>", 01huadalang on Discord), as the gateway routes it (Live),+// with its members ready now. ok is false for an entry naming a model,+// and for a group removed or switched off: such an entry is passed over.+func FallbackGroup(id string) (Group, []Member, bool) {+ if _, ok := GroupIDOf(id); !ok {+ return Group{}, nil, false+ }+ g, ms, ok := FindGroup(id)+ return g.Live(), ms, ok+}++// FallbackModels are the models p's fallbacks reach, in order: an entry+// naming a model, that model as routing reaches it (ResolveRoute); one+// naming a routing group, the group's members. An entry that reaches+// nothing is left out, as the gateway passes it over, and a model met+// again is listed where it was met first.+func FallbackModels(p Provider) []Member {+ var out []Member+ seen := map[string]bool{}+ add := func(m Member) {+ if k := m.Provider.ID + "/" + m.Model; !seen[k] {+ seen[k] = true+ out = append(out, m)+ }+ }+ for _, id := range p.Fallback {+ if _, ms, ok := FallbackGroup(id); ok {+ for _, m := range ms {+ add(m)+ }+ continue+ }+ if fp, fm, ok := ResolveRoute(id); ok {+ add(Member{ID: id, Path: []string{id}, Provider: fp, Model: fm})+ }+ }+ return out+}+// GroupFor is the group a model's id without a provider in it names, as// "group/<id>": the group of that id, else the group of that model however// a vendor spells it ("grok-4.7" is the group grok-4-7 or auto-grok-4-7).