Skip to content

Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.

providers: a key or account with no limit on requests at once shows how many run (chentuoyan on Discord)

yetone53913be7aa6e
diff --git a/docs/subsystems/gateway-routing.md b/docs/subsystems/gateway-routing.md
index f89f16f68..0211ae092 100644
--- a/docs/subsystems/gateway-routing.md
+++ b/docs/subsystems/gateway-routing.md
@@ -34,7 +34,7 @@ backfilled; see [Gateway Session Aggregation](gateway-sessions.md).
| 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) |
| 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`). `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) |
+| 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) |
| Image generation | `/v1/images/generations` and `/v1/images/edits` are translated to the selected model's image API. OpenRouter image-only models use its `/images` endpoint and send reference images as `input_references`; OpenRouter models that return images through chat stay on Chat Completions. Volcengine Ark (`isArk`: an `ark.*.volces.com` base, the preset's plans or one added by hand) is asked at `/images/generations` only, as its doc (https://www.volcengine.com/docs/82379/1541523) takes it (`drawArk`): `watermark: false`, since it marks every image otherwise; reference images as JSON `image` (a URL or data URL, an array for several), never a multipart edit; no `n`, so one request per image (`eachDrawing`); no ratio as `size`, so a ratio its doc lists is sent as that ratio's 2K size and any other is a 400 that says to put it in the prompt; no mask, no quality (JL on Discord, `TestArkDrawsWithoutWatermarkOncePerImage`). A routing group named for a drawing or a video (`drawingGroup`: `group/<id>`, or a bare id the group goes by that resolved to one of its members) is tried member by member in the order its routing plans for a chat (`drawingTries` over `planGroup`), each member over its own keys or accounts (`drawOnAccounts`, `startVideo`); the next member is asked while one fails as a chat's would move on (`retryable`: its vendor 5xx, out of quota, the model not served), never for a refusal of the request itself, and the call's `Fallback` names those tried first (#2005, tianxia3111: a group of two relays answered the first one's 502). Pause rules and a gateway key's group hold apply as for a chat. A failed drawing rests no member and no key. An account out of quota for the image model (`failure` reads `failQuota`) rests that model on it alone (`restDrawer`, keyed by `restID`), until the reset its refusal names (`resetsAt`: Antigravity's "Your quota will reset after 3h19m30s.") or `quotaRest`, so the next drawing asks the accounts that still have it first (`restLast`), and the account's text models stay in. Antigravity also tells a model's quota used up as a 200 whose stream is the error; `drawCodeAssist` gives such an error the status its words stand for (`saidStatus`: quota or rate 429, credit 402, else 502), as the images API's 200 with no image does, so a spent account hands the drawing to the next one as its 429 does (01huadalang on Discord: a 502 ended the drawing on the spent account; `TestAntigravityDrawingOutOfQuotaInsideTheReplyGoesOn`, `TestAntigravityDrawingQuotaRestsTheImageModel`). `TestImageGroupMovesOnToTheNextMember`, `TestVideoGroupMovesOnToTheNextMember`. An account's own list of models (#474) never bars a ChatGPT account's GPT Image, a Grok subscription's Grok Imagine or a WorkBuddy plan's image models (`listsCantName`): the list is picked from the editor's chat models, which they are never among, so a list kept for some chat models had every drawing refused as "set not to be served by any account" (heyiwei5 on X). A key's list, picked from models that include its image ones, still bars them. `TestCodexDrawsPastAccountModelLists`. A drawing is given Settings → Images → Image generation timeout (`imageTimeout`, 1 to 60 minutes, 5 when unset; neighbads on X: a slow image endpoint needed more) as its context's deadline (`drawTimeout`, `drawWithin`), and so is downloading an image answered as a link (`imageLongest`, never under `ImageLongest`). A drawing's request goes through a transport with no `ResponseHeaderTimeout` (`drawsApart`), since an images API sends its headers only once it has drawn, and every other request keeps `upstreamHeaderWait` (10 minutes). A video's submit, status and download calls keep 5 minutes each (`videoTimeout`). The `magpie mcp image` process, which may not read these settings (WSL), waits on a call up to `callLongest` (two hours and a minute), so it never cuts one the gateway still waits on. `TestLongImageTimeoutLetsASlowVendorFinish`, `TestImageTimeoutSettingReachesTheVendor`, `TestOnlyDrawingsWaitPastTheHeaderWait`. | [`draw.go`](../../internal/gateway/draw.go), [`draw_volcengine.go`](../../internal/gateway/draw_volcengine.go), [`video.go`](../../internal/gateway/video.go), [`catalog.go`](../../internal/catalog/catalog.go) |
| Affinity | A conversation stays with the key or account that answered it, so the vendor's prompt cache is read again. Modes: auto (""), `session`, `turn`, `off`, `strict`. Stored in `affinity.json` next to `providers.json`. A conversation is kept by its id (`conversationID`), and a Claude Code subagent's apart from its lead's by `x-claude-code-agent-id` (`stickKey`): Claude Code sends the session's id with its subagents' requests too, and a subagent's answer took the lead's stick over, so the lead's next turn was judged by the subagent's cache and moved to another account, where its whole conversation was written again (slkassinthehood on X, `TestClaudeConversationKeepsItsAccountsCache`). Behind a remote magpie, the key or account is the remote's key and the provider there that serves the model, its id's first part (`remoteUpstream`, `candidate.vendor`, `sameVendor`): the remote is one key here, but each of its providers keeps its own cache and seals, so a conversation is kept, held strictly, told its sealed reasoning was refused and given its native compaction's reader by that pair, as the same group on the remote does (fremontdango on Discord: a group of one model from two of the remote's providers kept a conversation on the second as the same account when the first was gone, and a strict one failed over to it; `TestRemoteMagpieStrictKeepsTheRemotesProvider`, `TestRemoteMagpieOtherProviderIsNotTheSameAccount`). A remote's group is one vendor by its whole id, its own routing deciding inside it; a model named without a provider is the key alone. Lanes and requests a minute still go by the key here, the limits the user set on it. | [`affinity.go`](../../internal/gateway/affinity.go) |
diff --git a/internal/gateway/concurrency.go b/internal/gateway/concurrency.go
index 0902a1e81..2de646e41 100644
--- a/internal/gateway/concurrency.go
+++ b/internal/gateway/concurrency.go
@@ -25,7 +25,8 @@ import (
// for — the vendor sees no more than that many — and what is waited is
// told in the route's try (Try.Queued).
-// lanes are the slots of each key or account with a limit.
+// lanes are the slots of each key or account with a limit, and the count
+// of those out on one without (limit 0), which take no slot and never wait.
type lanes struct {
mu sync.Mutex
m map[string]*lane
@@ -67,7 +68,7 @@ var (
// acquire waits for one of who's limit slots, in turn, with no bound on
// the queue or the wait. It answers the release, to call once the request
// is done with the vendor, and false with no slot taken when ctx ended
-// first. A limit of 0 takes no slot.
+// first. A limit of 0 never waits; the request is only counted.
func (l *lanes) acquire(ctx context.Context, who string, limit int) (release func(), ok bool) {
release, _, err := l.take(ctx, who, limit, 0, 0)
return release, err == nil
@@ -84,19 +85,20 @@ func (l *lanes) take(ctx context.Context, who string, limit, queue int, wait tim
l.m = map[string]*lane{}
}
ln := l.m[who]
- if limit <= 0 {
- if ln != nil {
- // the limit was lifted: whoever waits goes now
- ln.limit = 0
- ln.grant()
- }
- l.mu.Unlock()
- return func() {}, 0, nil
- }
if ln == nil {
ln = &lane{}
l.m[who] = ln
}
+ if limit <= 0 {
+ // the limit was lifted: whoever waits goes now. With none, the
+ // request is still counted while it is out, for the pill that
+ // says how many run (chentuoyan on Discord)
+ ln.limit = 0
+ ln.grant()
+ ln.busy++
+ l.mu.Unlock()
+ return l.releaser(who, ln), 0, nil
+ }
ln.limit = limit
ln.grant() // a limit raised lets more of those waiting go
if ln.busy < limit && len(ln.queue) == 0 {
@@ -263,8 +265,9 @@ func (s *Server) concurrency(w http.ResponseWriter, r *http.Request) {
writeJSON(w, 200, map[string]any{"object": "concurrency", "data": lanes, "requests": b.Requests, "waiting": waiting, "tools": b.Tools, "active": s.Active()})
}
-// Lanes is how each key or account with requests out or waiting under a
-// limit stands, by its who (provider, provider#key, provider@account).
+// Lanes is how each key or account with requests out or waiting stands,
+// limit or none (Limit 0), by its who (provider, provider#key,
+// provider@account).
func (s *Server) Lanes() map[string]Lane {
s.lanes.mu.Lock()
defer s.lanes.mu.Unlock()
diff --git a/internal/gateway/concurrency_test.go b/internal/gateway/concurrency_test.go
index bb8183627..665789cd7 100644
--- a/internal/gateway/concurrency_test.go
+++ b/internal/gateway/concurrency_test.go
@@ -227,7 +227,8 @@ func TestLanesLimitLifted(t *testing.T) {
defer l.mu.Unlock()
return l.m["p"] != nil && len(l.m["p"].queue) == 1
})
- if _, ok := l.acquire(context.Background(), "p", 0); !ok {
+ r3, ok := l.acquire(context.Background(), "p", 0)
+ if !ok {
t.Fatal("no limit refused")
}
select {
@@ -238,6 +239,7 @@ func TestLanesLimitLifted(t *testing.T) {
}
r1()
r1() // twice is once
+ r3()
l.mu.Lock()
defer l.mu.Unlock()
if len(l.m) != 0 {
@@ -245,6 +247,47 @@ func TestLanesLimitLifted(t *testing.T) {
}
}
+// A key with no limit on requests at once still has its requests out
+// counted (chentuoyan on Discord: the Providers page's pill says how many
+// run), as a Lane with Limit 0 and nobody waiting, gone once they are done.
+func TestLanesCountWithNoLimit(t *testing.T) {
+ fresh(t)
+ v := &slowVendor{release: map[string]chan struct{}{}, quit: make(chan struct{})}
+ up := httptest.NewServer(v)
+ t.Cleanup(up.Close)
+ if err := provider.Save(provider.Provider{ID: "slow", Name: "Slow", Key: "k", Models: []string{"m"}, Chat: up.URL + "/v1"}); err != nil {
+ t.Fatal(err)
+ }
+ s := New()
+ gw := httptest.NewServer(s.Handler())
+ t.Cleanup(gw.Close)
+ t.Cleanup(func() { close(v.quit) })
+ lane := func() Lane { return s.Lanes()["slow#"+provider.KeyID("k")] }
+ replies := make(chan error, 3)
+ for _, tag := range []string{"a", "b", "c"} {
+ body := `{"model":"slow/m","stream":true,"messages":[{"role":"user","content":"` + tag + `"}]}`
+ go func() {
+ res, err := http.Post(gw.URL+"/v1/chat/completions", "application/json", strings.NewReader(body))
+ if err == nil {
+ _, err = io.ReadAll(res.Body)
+ res.Body.Close()
+ }
+ replies <- err
+ }()
+ }
+ within(t, "three at the vendor", func() bool { return len(v.seen()) == 3 })
+ if l := lane(); l != (Lane{Busy: 3}) {
+ t.Fatalf("lane = %+v, want 3 out, none waiting, no limit", l)
+ }
+ for _, tag := range []string{"a", "b", "c"} {
+ close(v.gate(tag))
+ if err := <-replies; err != nil {
+ t.Fatal(err)
+ }
+ }
+ within(t, "every count given back", func() bool { return len(s.Lanes()) == 0 })
+}
+
// Concurrency is the user's setting, else none; 0 set is none, and a
// negative one saved is 0.
func TestProviderConcurrency(t *testing.T) {
diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js
index 1e54f1528..de395d28d 100644
--- a/internal/gui/assets/app.js
+++ b/internal/gui/assets/app.js
@@ -13829,9 +13829,10 @@ function accountCapPill(p, user, cap, direct) {
}
// An account's or key's limit on requests at once (#892): its own, else
-// the provider's Concurrency. The pill says it, and how many run and wait
-// (the lanes, read every 2s while one is in sight: refreshLanes), and opens
-// the app's menu: the provider's, none, a number, or the user's own.
+// the provider's Concurrency. The pill says it, and how many run and wait,
+// with no limit too (chentuoyan) (the lanes, read every 2s while one is in
+// sight: refreshLanes), and opens the app's menu: the provider's, none, a
+// number, or the user's own.
const LANE_LIMITS = [1, 2, 3, 5, 10];
let lanesNow = {}, lanesRead = false, lanesTick;
function laneOwnOf(p, ref) {
@@ -13849,13 +13850,11 @@ function laneText(pill) {
const own = laneOwnOf(p, pill.dataset.ref), limit = laneLimitOf(p, pill.dataset.ref);
const lane = (lanesRead ? lanesNow : providers?.gateway?.lanes || {})[pill.dataset.who];
const busy = lane?.busy || 0, waiting = lane?.waiting || 0;
- let text;
- if (limit && (busy || waiting)) text = waiting ? t("{n}/{max} running · {q} queued", { n: busy, max: limit, q: waiting }) : t("{n}/{max} running", { n: busy, max: limit });
- else if (limit) text = t("{n} at once", { n: limit });
- else text = t("No limit at once");
+ const v = { n: busy, max: limit, q: waiting };
+ const text = !limit ? t(busy ? "{n} running" : "No limit at once", v) : waiting ? t("{n}/{max} running · {q} queued", v) : t(busy ? "{n}/{max} running" : "{n} at once", busy ? v : { n: limit });
if (pill.textContent !== text) pill.textContent = text;
lanesTick ||= setInterval(refreshLanes, 2e3);
- pill.classList.toggle("set", own != null || limit > 0);
+ pill.classList.toggle("set", own != null || limit + busy > 0);
pill.classList.toggle("busy-lane", !!(limit && busy >= limit));
pill.classList.toggle("queued", !!waiting);
const whose = own != null ? t("its own") : t("the provider's");
diff --git a/internal/gui/assets/i18n.js b/internal/gui/assets/i18n.js
index 9563428a1..03ec5d07a 100644
--- a/internal/gui/assets/i18n.js
+++ b/internal/gui/assets/i18n.js
@@ -2137,6 +2137,7 @@ const I18N = {
"Requests per minute: a whole number from 0 to 10000": "每分钟请求数:0 到 10000 的整数",
"{n}/{max} running · {q} queued": "{n}/{max} 运行中 · {q} 排队",
"{n}/{max} running": "{n}/{max} 运行中",
+ "{n} running": "{n} 运行中",
"{n} at once": "并发 {n}",
"No limit at once": "并发不限",
"its own": "单独设置",
@@ -6177,6 +6178,7 @@ const I18N = {
"Requests per minute: a whole number from 0 to 10000": "每分鐘請求數:0 到 10000 的整數",
"{n}/{max} running · {q} queued": "{n}/{max} 執行中 · {q} 排隊",
"{n}/{max} running": "{n}/{max} 執行中",
+ "{n} running": "{n} 執行中",
"{n} at once": "並行 {n}",
"No limit at once": "並行不限",
"its own": "單獨設定",
@@ -10196,6 +10198,7 @@ const I18N = {
"Requests per minute: a whole number from 0 to 10000": "1 分間のリクエスト数:0〜10000 の整数",
"{n}/{max} running · {q} queued": "{n}/{max} 実行中 · {q} 待ち",
"{n}/{max} running": "{n}/{max} 実行中",
+ "{n} running": "{n} 実行中",
"{n} at once": "同時 {n}",
"No limit at once": "同時数 無制限",
"its own": "個別設定",
@@ -14245,6 +14248,7 @@ const I18N = {
"Requests per minute: a whole number from 0 to 10000": "Anfragen pro Minute: eine ganze Zahl von 0 bis 10000",
"{n}/{max} running · {q} queued": "{n}/{max} laufen · {q} warten",
"{n}/{max} running": "{n}/{max} laufen",
+ "{n} running": "{n} laufen",
"{n} at once": "{n} gleichzeitig",
"No limit at once": "Gleichzeitig unbegrenzt",
"its own": "eigene Einstellung",
diff --git a/internal/gui/tests/lane-limit.test.cjs b/internal/gui/tests/lane-limit.test.cjs
index 37d2bea69..b9922f81e 100644
--- a/internal/gui/tests/lane-limit.test.cjs
+++ b/internal/gui/tests/lane-limit.test.cjs
@@ -72,12 +72,12 @@ function serve(lang, posts, lanes) {
const words = {
en: {
- busy: "1/1 running · 2 queued", one: "1 at once", two: "2 at once", three: "3 at once", four: "4 at once", seven: "7 at once", none: "No limit at once",
+ busy: "1/1 running · 2 queued", running: "3 running", one: "1 at once", two: "2 at once", three: "3 at once", four: "4 at once", seven: "7 at once", none: "No limit at once",
menu: "Requests at once", def: "Provider's", other: "Other…", save: "Save", queue: "Queue size", wait: "Queue wait",
badQueue: "Queue size: a whole number from 0 to 10000",
},
zh: {
- busy: "1/1 运行中 · 2 排队", one: "并发 1", two: "并发 2", three: "并发 3", four: "并发 4", seven: "并发 7", none: "并发不限",
+ busy: "1/1 运行中 · 2 排队", running: "3 运行中", one: "并发 1", two: "并发 2", three: "并发 3", four: "并发 4", seven: "并发 7", none: "并发不限",
menu: "同时请求数", def: "沿用提供商", other: "其他…", save: "保存", queue: "排队上限", wait: "排队等待",
badQueue: "排队上限:0 到 10000 的整数",
},
@@ -209,6 +209,30 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
assert.deepEqual(errors, []);
});
+ test(`${engine} ${lang}: with no limit, what runs is shown, and none running says no limit again`, async (t) => {
+ // chentuoyan on Discord: an account with no limit said only "no
+ // limit", never how many of its requests were out
+ const lanes = { now: { "codex@[email protected]": { busy: 3, waiting: 0, limit: 0 } }, reads: 0 };
+ const { page, errors } = await open(t, "Codex", lanes);
+ const me = pill(page, "[email protected]");
+ for (let i = 0; i < 80 && (await me.textContent()) !== w.running; i++) await page.waitForTimeout(50);
+ assert.equal(await me.textContent(), w.running);
+ await page.mouse.move(0, 0);
+ await page.waitForTimeout(250);
+ assert.equal(await opacity(me), "1", "running: shown without a hover");
+ // the rest of the row's pill look, no colour of a full lane
+ assert.equal(await me.evaluate((e) => e.classList.contains("busy-lane") || e.classList.contains("queued")), false);
+ const el = await me.elementHandle();
+ lanes.now = {};
+ for (let i = 0; i < 80 && (await me.textContent()) !== w.none; i++) await page.waitForTimeout(50);
+ assert.equal(await me.textContent(), w.none);
+ assert.equal(await el.evaluate((e) => e.isConnected), true, "the same pill, rewritten in place");
+ await page.waitForTimeout(250);
+ assert.equal(await opacity(me), "0", "idle with no limit: on hover only again");
+ assert.equal(await pill(page, "[email protected]").textContent(), w.four);
+ assert.deepEqual(errors, []);
+ });
+
test(`${engine} ${lang}: the queue's length and wait are saved with the editor, and refused out of range`, async (t) => {
const lanes = { now: {}, reads: 0 };
const { page, errors, posts } = await open(t, "Relay", lanes);
@@ -247,7 +271,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
"How many requests may wait for each key or account; one more is turned away at once. 0 or empty is no bound",
"Seconds a request waits for a free slot before it is turned away. 0 or empty waits as long as it takes",
"Queue size: a whole number from 0 to 10000", "Queue wait: a whole number of seconds from 0 to 3600",
- "{n}/{max} running · {q} queued", "{n}/{max} running", "{n} at once", "No limit at once", "its own", "the provider's",
+ "{n}/{max} running · {q} queued", "{n}/{max} running", "{n} running", "{n} at once", "No limit at once", "its own", "the provider's",
"At most {n} requests out at once on this one, {whose}; more wait in a queue and go in order. Counted across every model, routing group and agent",
"No limit on requests at once on this one, {whose}", "{n} running, {q} queued now", "Click to change",
"{who} takes the provider's limit", "{who}: at most {n} requests at once", "{who}: no limit on requests at once",