5bfa57e3d37baad0900a7039a5645366c8e2dc3c
24
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
dbbb2f26b1 |
groups: free: takes the models a catalog marks free (#5903)
A routing group's pattern may now start with free: (provider.FreePrefix): free:workbuddy/* is, of the models workbuddy/* matches, those whose catalog entry says free (Entry.Free, the vendor's or plugin's own flag as the catalog was last read). The rest after free: is a glob, a re: pattern or an id, matched as on its own, so free:re:workbuddy/hy.* works too. It is expanded where every pattern is (matchesIn, PatternHits) each time the groups are read, from the catalog magpie already keeps: no request to a vendor, and a model the next list marks free joins without a save. Only the flag decides. A $0 price (PricedFree), a rate of 0, an account named Free or "free" in an id never counts; the test holds a deepseek-v4-free id with no flag, a rate-0 model and an or/y priced at $0 out. Existing patterns read as before: openrouter/*:free still means ids ending in :free (that is why the rule is a prefix, not a :free suffix), and a provider's AutoInclude takes no free: (isIDPattern). GUI: the Routing editor's pattern box counts and lists a free: rule live as it does any pattern (patternTest in plugins/routing/client.js, from groups.models' free), refuses "free:" alone, and one hint line says the flag is the last catalog's, not a promise of no charge, in en, zh, zh-TW, ja and de. CLI help, docs/subsystems/providers-accounts.md and the site's routing-groups page (en, zh, ja) say the same. routing-levels.test.cjs: the Advanced hint line made the editor taller, so the second group's Levels row opened under the editor's sticky foot and the click landed on the foot (webkit en). The test already wheels to that row for its first group; it now does for the second too. Run: - TestGroupFreeRule, TestFreeRuleSyntax and the existing pattern tests pass. Broken by hand: with groupmatch.go and autolist.go from origin/main both are red (no members for free:workbuddy/*, IsPattern); with takes() ignoring the flag, TestGroupFreeRule is red (all six WorkBuddy models matched). - group-free-rule.test.cjs (new): chromium and webkit, en and zh, green; red with origin/main's client.js. - go vet ./... (darwin, mica), GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./...: clean. gofmt -l: nothing. - Full suite go test -tags nogui -timeout 45m ./... on Linux (WSL magpie-desktop) at 1e180c630 (this change on |
||
|
|
c2a1d80fc2 |
routing: In turn says each message you send goes round, and draws it (Wing8Aqua on X)
"Each turn of a conversation goes to the next one" read as every message
of a session moving to another account, when a reader expects a new
session to be the unit, and the line was long. What the gateway does
(affinity.go affine): under In turn with Stays on Auto or Within a turn,
each message the user sends ("new-turn") goes to the next account, round
the list; the agent's tool calls for that message stay ("turn"); a new
conversation goes to the one holding fewest. Session and Strict keep a
whole conversation on one, so In turn goes round per conversation; Off
moves every request. Routing is unchanged.
The words now name the unit and the cost: each message you send goes to
the next one, round the list; its tool calls stay; a move costs some
prompt cache; Stays on Session keeps a whole conversation on one. Same
in the provider editor, a group's editor, the Routing plugin's mode
line, the CLI's groups help and the docs (en, zh, ja; llms-full.txt
rebuilt), in en, zh, zh-TW, ja and de.
Under the words, while In turn is picked, a small figure: two
conversations of three messages, a pill naming the account (A, B, C)
each message went to and dots for its tool calls in that account's
shade, drawn as Stays has it now (Auto moves each message, Session one
account a conversation, Off every request). Theme tokens only (--fg-2,
--muted, --faint, --card-2, --line), no colour. The figure lives in
rotfig.js, imported when In turn is first shown; the core keeps a
one-line hook, and its budget goes up 333 for that and the words.
Run (mote, at this tree): rotate-figure.test.cjs, new, provider editor
and group editor, en zh zh-TW ja de, 900px light and 420px dark,
chromium and webkit, 40/40; stays-strict, routing-group-strategy,
routing-save, routing-advanced, rate-limited-sink, group-template,
group-editor-fits, group-editor-align, routing-affinity-order,
routing-affinity-lead, routing-affinity-cache-write,
routing-pool-tooltip, routing-rows-fit, routing-weight-chip,
group-patience, group-defaults, builtins, search-keys, i18n-keys,
i18n-en-no-cjk, text-size, routing-editor-foot, gateway-key-own-rotate,
routing-accounts-narrow all ok; site worker.test.mjs 41/41;
TestCoreScriptBudget ok; go test ./internal/cli ok; gofmt clean; go vet
./internal/cli ./internal/gui darwin, linux -tags nogui, windows ok.
Red, the same on origin/main
|
||
|
|
e18aca1038 |
agents: an agent's own context window, and a routing group's own Compact at (ul3140773077392, NovaStudiosss on X)
ul3140773077392 on X: dsh compacts earlier than other harnesses at the same
window, so one global size per model fits none. An agent's sheet (Agents,
the agent's Settings line) now holds "Context window": a size for every
model, or model=size pairs (provider/model, group/<id>, provider/*, a bare
model id, *). Empty follows each model's own window. It is applied in
provider.CatalogFor, the choke point every agent's model list goes through,
so dsh's contextWindow, Codex's catalog and Claude Code's window all read
it, and a window set this way makes Codex/Claude compact at that window
(Entry.WindowSet). Stored in settings.AgentContexts, kept by a general
save (settingsapi); POST /api/settings/agent-contexts and
`magpie model window <agent> [model=size...|off]`.
NovaStudiosss on X: Routing, a group's Edit, Advanced already had "Context"
(the window agents are told). It now has "Compact at" beside it
(Group.Compact; compactSet reads it before the members' smallest), also
`magpie group ... compact=`.
GUI: agentwindow.js, loaded on demand through agentcompact.js so app.js
stays inside its budget (TestCoreScriptBudget passes; the "Context window
in {agent}" label reuses the existing "Context window" key). Every agent
with fields now has a sheet; agent-prefs' Pi expectation says so.
Run at the pushed head, on mote: go vet (darwin; linux -tags nogui;
windows) on provider, agent, cli, gui, settings, settingsapi; gofmt clean;
go test provider, cli, settings, settingsapi, gui (TestCoreScriptBudget
and cli's route table fixed here), agent -run Dsh; node --test agent-window
and group-compact (chromium and webkit, en zh zh-TW ja de, 900 and 420px),
agent-compact, agent-prefs, compact-at. Reds seen identically on a
detached origin/main
|
||
|
|
a5e805f574 |
Codex: Ultrafast beside Fast in a group member, and a Fast/Ultrafast setting per model (kdajenks on X)
kdajenks (magpie 0.1.3739, Codex on ChatGPT Pro) could set Fast only from a
routing group's member row and had no Ultrafast there, and no way to set the
speed in the model's own settings. Ultrafast exists: Codex's catalog lists
the `ultrafast` service tier, the code already sent it for agent picks and
Codex's service-tier row, and the live account's service_tiers hold it.
- Group member: the button steps Standard speed, Fast, Ultrafast (where an
account offers it, `ultraOK`), back to Standard. `Group.Ultra` is a subset of
`Fast`, kept through rename, fold, share, gone-filter and the CLI
(`magpie group ... ultra=`). The gateway marks the candidate `ultra`.
- Per model: `settings.ModelTiers` ("<provider>/<model>" to priority or
ultrafast), `provider.SetModelTier` (refused where CanFast/CanUltra say no),
`ModelPref.Tier` in Model settings (Standard speed / Fast / Ultrafast, in
modellimits.js), and `magpie model tier <provider/model> [fast|ultrafast|usual]`.
The gateway sends it on a direct pick for an agent with no fast pick of its
own, through fastPick, so an account without Ultrafast gets priority. A group
member goes as the group says.
- Docs: gateway-routing, providers-accounts, reference.
Run (mica, at the rebased head over
|
||
|
|
208b89422d |
routing: a group carries a note of its own (ConatusMoon2222 on X)
ConatusMoon2222 asked whether a routing group can have a note. It couldn't: a group had an id and a name, nothing else of the user's. A group now has an optional one-line note (provider.Group.Note, "note" in providers.json). SaveGroup cleans it: whitespace and newlines run together, cut at 200 characters (in runes), and an empty one is no note. It is the user's own word and is never sent to an agent or a vendor. - Routing page: the note shows under the group's name as one muted, ellipsized line, the whole of it on hover, and only when there is one. The group editor has a Note field under Name (Enter saves, as in Name). Every save of the group sends it: the editor, a manual group's pick and a routing picked from the row, so none of them wipes it. - CLI: `magpie group set <id> note=...` (note= clears it), `magpie group add ... note=...`; `magpie group <id>` and the list print it. - TUI: N in a group's view edits it; the view shows it under the head. - A copy, a shared group, a backup (StoredGroups/RestoreGroups) and sync (Mirror) carry it: they move whole Group structs. TestGroupNote checks each. Two existing GUI tests clicked rows that the extra editor row pushed under the view's foot bar at 420px in WebKit, which doesn't scroll the page's own scroller to a click: group-defaults' reach() now counts in sight as above the foot bar, and group-unlists' openAdvanced wheels the summary into view as its other helpers do. Both passed on origin/main and failed on this change before the fix. Run (on mote, at this head rebased on origin/main): - go test ./internal/provider ./internal/cli ./internal/tui ./internal/gui: ok - gofmt -l: clean; go vet ./... darwin, GOOS=linux -tags nogui, GOOS=windows: ok - GUI, chromium + webkit: group-note (en, zh, zh-TW, ja, de, and 390px), every group-*, routing-group-*, routing-groups-*, settings-groups, routing-manual, routing-save*, routing-tag-whole, fallback-group and i18n-* file: 752 tests, 752 pass Broken by hand, each red: - SaveGroup without CleanNote, and the CLI's note= without it: TestGroupNote and TestGroupNoteCLI fail on the uncleaned note. - the editor's Save body without note: group-note fails (the typed note never posted). - the pick and route-tag bodies without note: group-note fails (the note wiped by a pick). Not tried: the real TUI by hand, the real app in Linux WebKitGTK, and Windows (the change has no OS-specific code; windows vet ran). |
||
|
|
65f93ac27d |
routing: a group's member may be pinned to one account, tried in the group's order (EastonXvii on X)
EastonXvii asked for a group like Codex/Astra on account A, then Astra on B, then Sol on C, tried strictly in that order, with the same model on two accounts as two members. Before this, Group.Accounts held the whole group to a set of accounts with no order among one provider's accounts, so the only way was one group per account. A member id may now end with the account: provider/model[:effort][:fast]#<account> (provider.MemberAccount, groupaccount.go). - Every list keyed by a member's spelling (rules, Fast, Off, Weights, Placed, EffortMaps, Pick) and membersFound's dedup key include it, so the same model on two accounts is two members. The vendor is still asked for the model's own id. A group saved before has no "#" and reads as it did. - SaveGroup stores the account's stable id (a typed name is resolved by ResolveAccount). It refuses an account on group/ and auto/ members, and a new account magpie doesn't have. One the stored group had already that is gone since stays, matching nothing. - Gateway: planLevel's keys() leaves the provider's other accounts out for such a member (memberHeld; Held rows with HeldOwn in the trace). Fallback goes to the next member, never to another account under the same member. count_tokens counts on the resolved member's account (heldByGroupAt). Images and videos: drawingTries keeps one try per member account, and each try runs on a request held to that account (memberOn). - Sharing and importing a group drop members' accounts. - GUI: Routing → edit a group → each model row has an account chip (openPicker menu): "Any account", each account, and "Also on another account…", which adds the model on a free account as a member of its own after the row. Strings in en, zh, zh-TW, ja, de. - CLI: models=relay/m#B,relay/m#A,other/m (by name or id); show prints "on <name> alone". TUI effort cycling keeps the account. Run (mote, at the pushed head after rebasing on |
||
|
|
7e5a54147f |
gateway: a routing group's intent sureness is its own, intent-sure= (#5101)
Jev's sure of an intent had to reach jevSure, a fixed 0.4, for every
group. zminds measured 39 of 237 turns in one day (16.5%) refused at sure
0.153 to 0.395, and those turns went by the group's routing as if it had
no intent rules. A group can now set its own threshold: intentSure, from
0 (take Jev's likeliest intent however unsure) to 1. Missing keeps 0.4.
readJev keeps Jev's likeliest intent, its sure and Topic (an answer of
intents rather than levels). ruleFor applies the group's own sure through
intentOf, so two groups sharing one classifier and its cached answer each
judge it at their own. "none of these" is never an intent, at 0 too.
Levels and effort are as before.
Set from a terminal: magpie group set <group> intent-sure=0.25, empty to
unset. SaveGroup and the CLI refuse a value outside 0 to 1, NaN too: the
patch's `v < 0 || v > 1` let intent-sure=NaN through the CLI, which
SaveGroup then failed on as "json: unsupported value". cloneGroups copies
the new pointer, since TestCloneGroupsSharesNothing went red on it.
Changed from ggbdpq's patch on #5101:
- The group editor's "Intent sure" row is left out. Its hints were long
secondary text, it showed for every classifier when only Jev answers
with a sure, and it had no GUI test. The Routing page instead carries
intentSure through each save it makes of a group (the editor's Save,
the routing menu, the manual pick), so a value set from the CLI isn't
wiped by the next GUI save.
- Its i18n strings and site/public/docs/intent.html are left out. A
site/ change waits for the maintainer (docs/contributors.md). The site
diff was documentation text only: a paragraph id="sure", a sentence
in "Match the rules" and one table row. It had no links or scripts.
- docs/subsystems/gateway-routing.md has a bullet for IntentSure.
Run on mote (mote-run):
- gofmt -l internal/: clean.
- go vet -tags nogui, also with GOOS=linux and GOOS=windows, on
internal/gateway, internal/cli and internal/provider: clean.
- go test -tags nogui -run 'TestGroupIntentSure|TestJev|Rule|Classif|Decide'
./internal/gateway: ok.
- -run 'Group|Apply' ./internal/cli: ok.
- -run 'Group|Save|Clone' ./internal/provider: ok.
- go test -run Budget ./internal/gui: ok.
- node --test group-intent-sure (new), routing-group-strategy and
group-first-token, in Chromium and WebKit: 42 pass, 0 fail.
- i18n-keys has one red, "a plugin's words are its own". It fails the
same on origin/main
|
||
|
|
00d8aac596 |
routing: Free quota by expiry spends the soonest-lapsing free quota first (wowbbs)
wowbbs (and shamen_xiaohong) keep check-in free accounts in one group:
WorkBuddy CN x2, MiniMax Code, TraeCode CN and Qoder CN. They asked that
the group spend the free quota that lapses soonest first, go on to the next
when one is used up or has lapsed, and use a paid account only when no free
quota is left.
This adds `expiring` (provider.FreeExpiring, routes.FreeExpiring). It is a
group's only, picked in the Routing page's group menu, with
`magpie group set <g> routing=expiring` or in the TUI. Nothing changes for a
group or provider that doesn't pick it. A provider keeps refusing it, as it
refuses `cheap`.
- routes: Seat.FreePlan and Strategy.ByPlan. FreeExpiring has three tiers:
- free seats (Free, a model at no cost, or FreePlan) by Expires, the
earliest of the window renewals and Lapse, to the hour; an unknown
expiry goes last and ties keep their listed order;
- then the paid seats, as Smart orders them;
- then the spent and resting seats, by when they come back.
- provider.FreePlan reads an account's plan word: free, trial, 免费, 试用,
体验, 體驗.
- gateway: weighRouted fills FreePlan when the strategy asks. The trace's
Weighed rows gain `expires`, so the Routing page's story can say "its free
quota is lost soonest, in 1d 2h". There are also lines for "a free one with
no expiry told" and "no free quota left, so the paid one".
- GUI: an option in the group menu, the mode line, the story lines, and
i18n in zh, zh-TW, ja and de. app.js only adds `expiring` to ROTATION,
paid for by a shorter comment beside it, so the core is 11 bytes smaller
than at its base.
- docs: gateway-routing.md (order of keys and accounts) and
plugin-runtime.md (Seat and Strategies).
Plugins whose usage doesn't say when their free quota lapses got issues
rather than edits:
- magpie-community/plugins#718: Trae sums its packs; the soonest end comes
from any pack, spent or past, and there is no runsOutAt.
- magpie-community/plugins#719: Qoder's plan is the raw userType
personal_standard, which doesn't read as free, and its add-on, shared and
dedicated pools have no expiry.
WorkBuddy (Free plan, resetsAt and runsOutAt) and MiniMax (Free, runsOutAt
on credits) already report what this needs.
Run, all on mote via mote-run at this tree (base
|
||
|
|
339ff564e6 |
fix(gateway): skip a nested group's effort classifier when the group above picked (#4358)
A group reached through a parent group runs its own classifier when it is effort=auto, even after the parent's classifier already picked the turn's reasoning: the request goes out at the parent's pick (the outermost pick stands, gateway.go), so the group in it pays for an answer the turn throws away. On one reporter's day the group in it answered 27 of 28 such turns, 2-8 s each, and 14 of the 28 parent picks discarded the answer. ruleFor now takes the pick a group above it already made: with one standing, the classifier is not asked for the effort again. The intents, when the group's rules have them, are still asked — they are the group's own routing. The trace says why nothing was asked. The fallback keeps working: the group in it is asked as before whenever the group above gave no pick. Generated-by: GLM-5.3-Flash (ZCode) |
||
|
|
9162277b91 |
routing: Until used up stays on the next account once the first is used up (dzxx0496)
dzxx0496 on Discord: with free accounts one after another, the first used
up, requests went to the second; when the first renewed they went back to
it ("如果第一个恢复了,它又优先用第一个了"). No routing did what they asked:
In order and Smart both put the first back first.
A new routing, Until used up (drain, 用完再换): requests stay on one seat
until its quota is used up, then go on to the next in the list and stay
there. A seat counts as used up when its known allowance is at 100% or
it was refused for quota or credit (failQuota / failCredit, routes.Drained
called where the rest is recorded, so a failover inside one request moves
the pool too). A rate limit or other failure only passes it over while
it rests, as In order does. Each pool (a provider, a group/<id>) keeps its
own place; routes.Forget clears it.
Offered wherever a routing is picked: the provider editor, a group's row
menu and editor (app menu, no native select), the TUI, `magpie group set
<id> routing=drain` and a provider's routing=drain. Nothing defaults to
it, so no saved setting changes. SpentShareOf is 100 for it, as for In
order. Words in en, zh, zh-TW, ja and de (i18n.js and the routing
plugin's own), docs/subsystems and the site's start page (en, zh, ja).
Tests:
- internal/routes/drain_test.go: stays on the next when the first renews,
through a rate limit, all used up, a seat gone, per pool, Forget,
Drained after a renewal.
- internal/gateway/drain_test.go: a real request path with a fake upstream;
k1 refused for quota, k2 takes over, k1 renews: drain stays on k2,
In order goes back to k1. Red without the Drained hook (request 3 went
to k1). A rate limit comes back to k1; drain is saved on a provider and
a group.
- routing-drain.test.cjs: the Routing page's why and mode line in 5
languages, 1100px and 420px, Chromium and WebKit; red on the old assets
(20 of 20).
- routing-group-strategy, routing-save, builtins: the menu has 11 routings.
Run on mote (macOS) at origin/main
|
||
|
|
0621e70fb9 |
routing: leave a provider out of the groups magpie finds
chenxiang0010 on Discord asked to keep a provider or a model out of the auto-created routing groups. A model could already be kept out (remove its found group; magpie keeps it removed), but a provider could only be turned off per group or everywhere. Now Routing -> Groups, under "Find groups on their own", has "Leave out a provider..." (app menu, saved when it closes) and `magpie group auto skip <provider>...|none`. The providers chosen (providers.json autoGroupSkip) join no found group; a group the user made or changed keeps them, a found group left with one provider goes away, and a request for it is served by AutoStandIn from a provider still in, and agents on it are reseated (agent.Reseat). A rename carries the id along. en, zh, zh-TW, ja, de. Run at 383947fce (this change on origin/main |
||
|
|
4f2d5fc7e0 |
routing: a group can put its cheapest member first, by each one's price at that hour
liyuanzheng (#general) and lam_em (#feedback) both asked for the same thing. Off-peak, DeepSeek's own API should come first for deepseek-flash. At DeepSeek's peak (weekdays 01-04 and 06-10 UTC, billed 2x since v0.1.2173), another provider should come first, Ollama say. A schedule editor would make the user copy DeepSeek's hours into magpie. Instead, a group gets one more routing, "Cheapest first" (`cheap`). Each request sorts the members by what they cost right then: input + output price per million, at the peak rate when it is peak hours. A tie goes to the lower cache-read price. Free models count as 0. A member with no known price keeps its listed place after the priced ones. Prices come from the same priceOf the usage ledger bills with, so the user's own ModelPrices, list prices and maker prices all count, and so does a provider's rate windows. - routes: Seat carries Priced/Cost/CacheCost; Strategy.ByPrice; Cheapest is a stable sort, so equal prices keep the user's order. - gateway: weighRouted prices each seat at priceClock() (time.Now; a test holds it) through the new provider.PriceAt. The trace's Weighed row gets a price (input/output/cacheRead/peak) so Routing can say why. - It is a group's alone, like Manual. A provider saved with it drops it, and `magpie provider set … routing=cheap` refuses it. Groups take it in the GUI menu (one more item, no new controls), the TUI and `magpie group set <id> routing=cheap` (aliases cheapest, price, cost). - Routing's mode line says why the first one is first, e.g. "Cheapest first: deepseek-v4-flash costs least on ollama-cloud now — $0.150 in, $0.600 out a million tokens.", with peak and unpriced variants. en/zh/zh-TW/ja/de. - Docs: gateway-routing, plugin-runtime, reference (it also points at Time window and Pause rules for a fixed schedule) and the site's start pages (en/zh/ja). Run, at |
||
|
|
df9376592d |
routing: a group's member may offer several reasoning levels for the agent to pick among
Garydesu on X: "能不能让路由组里的模型设置多个可选推理强度,现在只能选一个或者整个 路由组的". A member was one fixed `:effort` or followed the group's levels. A member's suffix may now join several levels with "+", `provider/model:low+xhigh`, kept lowest first, each once. provider.MemberLevels splits it into Member.Levels and leaves Effort empty, so the member isn't fixed; one level is a fixed effort as before. The whole stays the member's id, so rules, fast, off, weights, share and the CLI key it as any member. The gateway fits the agent's ask to the member's own levels (groupLevels returns the candidate's levels first; ofMember, the quiet check and the trace see them), and the group lists them to agents (buildGroupEntries), intersected with the other members' as usual. In the Routing page's group editor the member's reasoning menu has "Several levels…", a menu that stays open with each level ticked or not; a fixed level picked from the first menu replaces the old one as before. i18n in zh, zh-TW, ja, de; CLI help and docs/subsystems/gateway-routing.md say it. Run on mote (mote-run). Rebased on |
||
|
|
ca8a6f346a |
agent: a renamed routing group moves its agents, and the Codex app reloads a changed catalog
lucis0116 on X: renaming a provider or a group in magpie didn't reach
every agent.
Display names already reached the agents' files: store and SaveGroup
drop the catalog, and SyncCatalog writes the new "<model> · <name>" and
"<group> · routing group" labels into Codex's model_catalog_json, Claude
Code's picker, OpenCode and Pi (checked in a sandbox HOME). Two gaps
were left:
- A routing group given another id (Routing page, `magpie groups
rename`, TUI) left every agent on group/<old>, which magpie no longer
has. The CLI even said "agents set to group/from need group/to now".
agent.RenameGroup now moves each agent field on group/<old> to
group/<new>, spelled as the agent spells it. It goes through
renameRefs, the move RenameProvider already made, now shared by both,
then SyncCatalog. The GUI, CLI and TUI call it in place of
provider.RenameGroup.
- The Codex app's own app-server reads model_catalog_json only as it
starts, and KeepCodexAppOnItsProvider restarts it only when
codexAppRoute changes. The route named the catalog's path, not what
the file holds, so a renamed provider or group, or a model added,
stayed on the old list until the user quit the app. The route now
carries a hash of the catalog's bytes (codexCatalogTag, read again
only when the file's size or time changes). The restart goes through
the existing idle gate: no Codex request in flight, 10s idle, no turn
open. A write of the same bytes is no change.
Run, in a sandbox HOME only:
- TestRenameGroupMovesTheAgentsOnIt (new): Codex, Claude Code, OpenCode
and Pi on group/smart, renamed to clever: each said moved and each
file on group/clever, none naming group/smart.
- TestCodexAppRouteFollowsTheCatalog (new): the route changes when a
renamed provider rewrites the catalog, and stays put when the same
bytes are written again.
- Broken by hand: RenameGroup's match turned off makes the first test
red (no agent moved, every file on group/smart). The catalog line
dropped from codexAppRoute makes the second red ("a provider renamed
left the Codex app's route as it was").
- At aded9beea (base
|
||
|
|
d9a8148d7c |
routing: Speed first sends a request to the provider or key that answered the model fastest lately
joeliu96872540 on X: when one model is reachable through several API
channels, they want an option that sends each request to whichever has
been answering fastest, because they compare channel speeds by hand
today. Speed first (`fast`; `fastest` and `speed` also work) is a new
routing beside Free first. It applies to a provider's keys and accounts
(provider editor › Routing) and to a group of one model on several
providers (Routing page › group › Routing).
How it decides. When a streamed answer ends, gateway/speed.go records two
numbers for that account or key and model (restID): the time to first
token and the output tokens per second, as usage.DecodeOf computes them
for the Requests page. Each is a decayed average with a 20m half-life.
After an hour with no answer the record goes stale, and the store holds
at most 4096 records. This is O(1) at the answer choke point, beside
servedCandidate. For a pool routed by BySpeed, weighRouted reads one map
entry per candidate, and only for that pool. The usage history is never
read on a request.
routes.Fastest ranks each awake seat by its estimated time to a
200-token reply: TTFT + 200/TPS. A seat that reported no TPS gets the
median TPS of the others. Seats within 10% of the fastest in their band
keep their listed order, so near-ties don't swap on every request.
Seats with no recent measurement go after the measured ones. One request
in five, counted per pool, goes first to an unmeasured seat, rotating
among them, so each gets measured again. Resting seats go behind the
awake ones, and used-up seats behind those. Rests and failover are the
same as for every other routing.
The request trace gets lateTtft and lateTps, and the row-story sentence
says "answered m fastest lately: first token in 0.8s, 60 tokens a
second". It has a variant for a probe turn and one for when no seat has
been measured yet. i18n covers zh, zh-TW, ja and de. Also updated: the
CLI (`magpie group|provider set <id> routing=fast`, plus a new
`routing=` pair on provider set that refuses manual), the TUI name, the
rotation plugin's Sub, docs/subsystems/gateway-routing.md,
plugin-runtime.md, docs/reference.md and site start.html (en, zh, ja).
There is no new layout: it is one more item in the existing pickers.
app.js stays under its budget with no raise.
Tests:
- routes/fastest_test.go:
- ordering: fastest first, slow writer loses, alike keep order,
resting and used-up, median pace, none measured;
- the probe turn at 5, 10, 15 and 20, rotating between seats;
- a resting seat never gets a probe turn.
- gateway/speed_test.go:
- decay, staleness and per-model records, with an injected clock;
- a group of slowv and fastv routed fast: after the speeds are
measured and seeded, the request goes to fastv with lateTtft set;
- the same group routed in order still goes to slowv.
- cli: parseRouting and the provider routing= pair.
- GUI routing-speed-first.test.cjs: the row story for measured,
no-pace, probe and none, in en, zh, zh-TW, ja and de, in chromium and
webkit: 40/40.
Broken by hand:
- Fastest returning the listed order: the routes tests and the gateway
group test go red.
- noteTrySpeed removed: "the streamed answer wasn't measured".
- The client.js case renamed: routing-speed-first 0/20 in chromium.
Run at b5a5caff2 (base
|
||
|
|
a3b45eb91e |
provider: a re: pattern matches in any case, as a glob does (usrname1833 on Discord)
A routing group's patterns (Group.Match) and a provider's auto-include rules both compile through compilePattern. A glob compiled with (?i) and a re: pattern without it, so re:gpt-.* missed GPT-5.5 while gpt-* took it. A re: pattern now compiles as (?i)^(?:…)$; (?-i) inside it makes case matter again from there on (re:(?-i)gpt-.*). The Routing page's editor works out a pattern's models in JS (patternRe in plugins/routing/client.js) and refused what JS can't read. It now reads re: with the i flag too, and takes Go's leading flag group ((?-i), (?s), ...) as JS flags, so re:(?-i)OR/B is taken and matches as the gateway will. A flag group further in is still refused there (JS has no bare (?-i)); the CLI takes it. Said in groupmatch.go's comments, magpie group's and magpie provider auto-include's help, and providers-accounts.md (Routing groups, List schedule and rules). No GUI hint said a pattern's case, so none changed and no string was added. Run: - TestRegexpPatternIgnoresCase (new): ok. With compilePattern's (?i) taken off by hand: FAIL, "re:GPT-.* ~ gpt-5.5: false, want true" and three more cases. - group-patterns.test.cjs, chromium and webkit, en and zh: 4 of 4 ok. With patternRe put back to the old re: line by hand: 4 of 4 red, "(?-i) keeps case 0 !== 1" (old JS refused re:(?-i)OR/B). - gofmt -l: nothing. go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./...: clean. - go test -tags nogui -timeout 45m ./internal/provider ./internal/cli ./internal/gateway under a sandbox HOME at 1a956129c's tree: ok, ok, ok (380s). go build for darwin, linux (nogui) and windows: ok. - A full ./... run was started and stopped: the machine's disk was full (1GB free), and internal/agent's tests failed on "no space left on device" in TempDir, not on this change. No full suite ran. Not tried: the full suite (above); a real provider's auto-include fetch with mixed-case ids; the Linux app's WebKitGTK; a (?-i) further into a re: in the GUI. |
||
|
|
75e769a9f9 |
routing: Free first spends the models that cost nothing before the ones that spend (#3054)
A provider or group can be routed `free`. Seats whose model the vendor serves at no cost to the allowance or credits go first, in listed order. The rest follow, also in listed order. Free means the vendor's own catalog.Model.Free word, or else a $0 list price on every count (provider.FreeModel). A pool with no free model behaves as In order. routes.Seat gains Free and Strategy gains ByFree. weighRouted works Free out only for a strategy that weighs by it, so other routings never read a model list for it. It is wired through every list a routing appears in: - both save whitelists; - plugins/rotation's Builtin; - app.js's ROUTINGS (appScriptBudget 1,269,000 → 1,271,000 for the description) and the Routing page's options, hints and trace text; - zh-TW, ja and de strings; - the TUI's routings; - the CLI's aliases (free, free-first). Written by keeuu (issue #3054, three commits), squashed onto |
||
|
|
81a24cf8fe |
groups: a found group is listed as auto/<model id as the vendor spells it>
ZeroClover asked on X: Auto Group ids group/auto-<slug> can't be looked
up on models.dev. A found group is now listed and written as
auto/<model>, e.g. auto/claude-opus-5.5: /v1/models, the catalog, agent
configs, the GUI's Routing page and the CLI. Context and output limits
come from the model's metadata as before.
What stays the same:
- The internal id is still group/auto-<slug> (Group.Ref() gives the
public one). Every old form is still accepted as input forever:
provider.CanonicalRef turns auto/<model>[:level][[1m]] into it at the
gateway (validateModel), keys, stats, affinity and usage, so both ids
route to the same group and count as one.
- A key's model list allows a model by either id, group/* included
(allows() in key_models.go).
- Hand-made groups stay group/<id>.
- A provider whose stored id is "auto" keeps its models: while one
exists, found groups are listed by their old id (AutoRefsOn) and
auto/<x> means that provider's model. Documented in
docs/subsystems/gateway-routing.md.
Agent configs: SyncCatalog rewrites a field that holds a found group's
old id (renameFoundGroups), but only while the value is still what
applied.json says magpie wrote; a value the user set stays. A pick by
the old id written now is written as auto/<model> (Apply). Hidden,
picked and ordered model lists saved by the old id hold for the new one
(visible.go), and a bare model id still reaches its found group (bare.go).
Claude Code is given a dotted Claude version dashed (ClaudeSpelled), so
auto/claude-sonnet-4.5 sits in its settings as auto/claude-sonnet-4-5.
That routes to the same group, but with found groups off nothing reads
it back dotted, and Reseat took the field for changed and left the agent
on a group that was gone. Reseat now compares a group pick by its
canonical id (samePick). The old ids had no dots, so this is new with
auto/<model>.
Run at this tree (sandbox HOME, caches pinned):
- gofmt -l: clean. go vet ./...: clean on darwin, GOOS=linux -tags
nogui, GOOS=windows.
- go test -p 4 -timeout 45m ./...: every package ok except agent and
gateway, whose failures were the tests' expected ids (updated here)
and two regressions now fixed (bare ids; desktop models hiding groups
by prefix). Every failing test passes on rerun. Load average was
~210-290 from other sessions throughout.
- Reruns: provider, cli, codexcat ok. internal/gui: only
TestSetAnswersWhileDevinAndProvidersHang fails (set slow/slow-1 took
10.19s), and it fails the same in a git-archive export of
|
||
|
|
3f913b3de6 |
plugins: a JS gateway plugin serves routings (strategies) and watches usage rows (onUsage); plugins/middleware is "JS gateway plugins" (P4)
A plugin's gateway module (magpie.middleware, or its alias magpie.gateway,
or a *.gateway.js file) may now export, besides onRequest/onEvent/onResponse:
- strategies: {name: (pool, seats, options) => order}. Each is a routing
"<short name>/<name>", registered with routes.Register while the plugin is
on and loaded and removed when it goes off or reloads. Seats are
routes.Seat in camelCase JSON. 20ms each; it fails open: a throw, a timeout
or a result that isn't an order of the seats means the listed order. The
failure is counted and logged, rate-limited. A file's name is made into a
routing-safe prefix.
- onUsage(row, options): gets an allow-listed usage row (no bodies, prompts,
error text, sessions or request ids). The rows come from a bounded queue
(1024) with one worker, off the request path; a full queue drops the row
and counts it, and a request never waits. 250ms each.
plugins/middleware is renamed "JS gateway plugins", with a new Sub
(en/zh/zh-TW/ja/de). It registers usage.Observe(middleware.Points()). Off,
no JS hook, strategy or onUsage runs. InUse is unchanged.
providers.json keeps a routing of the form <plugin>/<name> as saved
(provider.PluginRouting) in provider and group Save, whether or not a
plugin serves it now. Before this, `group set g routing=pick/last`
stored nothing.
GUI: the settings state carries jsRoutings. Provider and group routing
pickers offer the served ones, marked data-feature=middleware. A saved
routing that no plugin serves now shows as it is, with a hint. The
Plugins page's line shows routings, how often they were asked, onUsage
rows and dropped rows. The CLI accepts `group set <id> routing=<plugin>/<name>`.
`magpie plugin` lists a module's routings and onUsage; a strategy-only
module had printed nothing after "gateway middleware".
Docs: docs/subsystems/gateway-middleware.md (Routings and usage rows,
limits, verification) and plugin-runtime.md (P4: community plugins at
every point). site/public/docs plugins.html in en, zh and ja has an
example: internal/middleware/testdata/spread.gateway.js, which
TestDocsExample runs.
What was run (worktree on 4df1ba0c6, -p 2):
- gofmt -l: clean. go vet on internal/{middleware,cli,gui,plugin,provider}
and plugins/...: darwin, GOOS=linux -tags nogui, GOOS=windows; all
clean, run after the last Go change.
- go test, after the last Go change: internal/middleware ok,
plugins/middleware ok, internal/provider ok (210s), internal/cli ok
(203s). Earlier in the work: internal/plugin ok (385s), internal/pluginrt
ok, internal/gui (Go) ok (320s), and plugins/... ok. The first
plugins/... run printed a bare FAIL line that `tail` cut off before its
cause showed. The rerun was all ok; the cause is unknown.
- GUI, both engines (routing-*, group-*, builtins, i18n-keys, gui-de/ja/zh-tw,
plugin-middleware): 1220 tests, 1204 pass, 16 fail.
- routing-manual (4): mine. A group's own "manual" was offered a second
time as a routing no plugin serves. Fixed in client.js withJS. The
coordinator is rerunning routing-manual, keys-fold, group-fold,
intent-entry and routing-js alone in both engines, so that rerun is
not recorded here.
- routing-model-rest: red alone too, and red on untouched 4df1ba0c6
(3/20). It is #2115; I commented there with the webkit cases.
- group-member-weight webkit de 420 is #2387.
- group-from-model-add webkit zh: it passes alone 2 of 2. Under load it
waits a fixed 2s for the save post. Filed as #2388.
- routing-keys-fold (webkit zh/ja/de), routing-group-fold (goto timeout)
and routing-intent-entry (browser launch timeout 180s) are load
timeouts. The coordinator is rerunning them alone.
- routing-js.test.cjs (new) passed in chromium en and zh, before the full run.
Broken by hand, each test went red, then restored:
- the permutation check: TestStrategyFailsOpen;
- the queue's non-blocking send: TestOnUsageNeverBlocks ("Ledger waited
2.04s");
- the allow-list: TestUsageRowAllowList;
- unregister on off: TestStrategiesServedWhileOn and
TestStrategiesStopWithServe;
- the CLI pattern: TestParseRoutingStays;
- Observe in plugins/middleware: TestOnServesStrategies;
- PluginRouting in provider.go and in group.go: TestPluginRoutingKept;
- the prefix sanitizing: TestRoutingFromFileName;
- the CLI list line: TestPluginListSaysMiddleware;
- the GUI's data-feature mark and its unserved-saved entry: routing-js.
Real use: a sandbox HOME, the gateway served on 127.0.0.1:3682 by a
-tags nogui build, a fake vendor on 3681, and providers fa (key ka) and
fb (key kb) in group g. pick.gateway.js has strategy last (reverse) and an
onUsage that logs.
- `group set g routing=pick/last` stored it.
- A request to group/g reached the vendor with Bearer kb, and the
"usage-row fb m in=5 keys=17" line was logged.
- `plugin off pick.gateway.js`: Bearer ka (listed order), no onUsage,
routing still pick/last.
- `plugin on`: Bearer kb and onUsage again.
- `plugin builtin off middleware` says "in use and stays on", as InUse
should.
- Not tried: the GUI against that gateway, or a real vendor account.
|
||
|
|
8ef14be3e6 |
gateway: an effort=auto group leaves a turn the agent sent with reasoning none alone and asks no classifier, so its pick and what went out agree (#2247, sryimnoob123)
The classifier's pick was recorded but never applied when the agent asked for none, costing a classifier call per turn. The outer effort in the routing record is what the agent asked; the effort sent is tries[].effort on the try marked picked:true, which the groups help now says. Thanks to ggbdpq for the reproduction. Run at this head (on 6485056e1, with the #2245/#2246/#2247 fixes together): gofmt -l clean; go vet ./... for darwin and windows, and linux -tags nogui; the full go test ./... in a sandbox HOME, all green. The new test fails on the old code and passes with the fix. |
||
|
|
c4e6abf3cc |
gui, cli: a model id typed with a space in it stays one model, "Opus 5.5" not Opus and 5.5 (#1976)
elonnzhang on #1976: on a Baidu OneAPI relay, typing `Opus 5.5` in the provider editor's add box (or the add form's Models field) and pressing Enter added two models, `Opus` and `5.5`. Both read the box with split(/[,\s]+/), while their hints say "comma separated". - app.js: one typedIds() for both, split at commas (and line breaks) with each id trimmed. chosenIds() (the add box, and an id left in it at Save) and the add form's Models field use it. - CLI siblings, which split the same way: `magpie provider set models=` now splits at commas only. A group's models=, models-=, fast= and weight= split at commas, and an item with a space that names no model the group can have is still split at its spaces, so `models=m,b/x a/m` (TestApplyGroupPairs) still works. levels= and `magpie visible` (effort levels and family names) are unchanged. - Tests: the reporter's two GUI assertions in models-add-and-icons (from their fork branch). A new model-id-space.test.cjs covers both boxes in en, zh, zh-TW, ja and de, Chromium and WebKit, at 1100 and 420 wide. TestModelIDsKeepTheirSpace covers the CLI. The fork's change to provider-add-models.test.cjs is not taken: filling the Models field there replaces the picks it holds, so it failed on its own terms. Run: on the old split, model-id-space fails (4/4 for en and de at 420 in Chromium) and TestModelIDsKeepTheirSpace fails (models = ["Opus" "5.5" ...]). With the whole-item check forced off, it fails on members. With the fix: model-id-space 40/40, models-add-and-icons 4/4 and provider-add-models 4/4 pass. `go test -tags nogui ./internal/cli` is ok. gofmt is clean, and go vet passes for darwin, linux (-tags nogui) and windows. Not tried: a real relay with a spaced model id served end to end. |
||
|
|
eba7187368 |
gateway, provider, cli, gui: a group can route By weight, each member's share set beside it (#1910, DD on Discord)
DD asked for weighted round robin as a group routing, next to In turn.
A provider's keys could already route by weight (#841). Groups could not.
What changes:
- provider: Group.Weights maps a member's spelling to its weight, 1 to
1000. A member left out, or set to 0, weighs 1. SaveGroup accepts
routing "weight". It also cleans weights the way it cleans fast and
off: it strips :fast, drops weights of members that are gone and of
members weighing 1, and refuses a weight below 0 or above 1000.
Weights follow a member when it is renamed (RenameMember, Rename,
RenameGroup) and survive Share/Import.
- gateway: planLevel treats each member of a weight-routed group as one
unit: a model with its keys in its provider's order, or a nested group
routed its own way. weightedUnits orders the units by smooth WRR on a
round per group ("group/<id>"), sharing wrrPick with the keys. The
round's pick goes first and the rest stay in member order for
failover. A unit whose head is resting leaves the round. When a
conversation is kept on another member (session/turn/cache/strict),
the charge moves to that member (wrrSeat, wrrMove).
- cli: routing=weight (also weighted, wrr). weight=<model>=<n>[,...]
sets weights and keeps the rest; weight= on its own clears them. The
group view shows "· weight N" for each member.
- tui: By weight is in the group routing list.
- gui: the group editor offers By weight. Each member then shows
"Weight N · S%", its share among the members that are on. Clicking it
edits the number in place: Enter or blur keeps it, Escape cancels,
and a value outside 1 to 1000 shows a warning. The trace header uses
group wording for a weight-routed group. Strings are added in zh,
zh-TW, ja and de.
- docs: reference.md, gateway-routing.md, and site start pages in en,
zh and ja.
Run:
- go test -tags nogui ./internal/provider ./internal/cli ./internal/tui:
ok.
- ./internal/gateway: ok in 988s with -timeout 45m. The first run hit
the default 10m timeout at load average ~170. The test running at
that moment had been running for 2s; it was not a hang.
- go vet -tags nogui on those packages, for darwin, GOOS=linux and
GOOS=windows: clean. gofmt -l: clean.
- New group-member-weight.test.cjs: 8/8 in Chromium and WebKit, en and
zh at 1100, en and de at 420. The WebKit de 420 case also passed six
runs at once.
- gui-zh-tw, gui-ja, gui-de, i18n-keys, routing-*, group-*,
panel-routing*, settings-groups and agent-model-groups: all green
except two.
- routing-steady (WebKit) is #1804. It is red 2/3 alone on origin/main
|
||
|
|
908c910931 |
gateway, gui: Stays: Strict keeps a conversation on the account or key that answered it, even past its cap, and passes its error on rather than moving it (#1797)
miniers asked that a conversation never move to another account: a
move changes the account a vendor sees mid-conversation and loses its
prompt cache. Session affinity keeps the account while it can answer,
then moves on.
The new affinity mode "strict" (Stays: Strict) does what session does
for a new conversation. Once one has an account, strictKeep asks that
account alone (its other models too) and no other account, key or
provider:
- one resting or spent is still asked, and its error (429, 402, 5xx)
goes to the agent rather than to the next candidate;
- one over a user cap is asked past it (plan's capped candidates,
capHeldOnly);
- one held for credits answers 429 naming Stays: Strict rather than
moving;
- one removed, turned off, barred or not allowed for the key counts as
gone, and the conversation is routed as usual.
A last try that fails verification is not rested for a strict
conversation that had nowhere else to go.
Set in the provider editor and the Routing page's pool row (GUI, all
five languages), `magpie groups ... stays=strict` (strict-session,
never-move), and the TUI ("stays strictly"). Documented in
gateway-routing.md, reference.md and the site's start pages (en, zh,
ja).
Run:
- go test -tags nogui ./internal/gateway (-timeout 30m under load ~150),
./internal/provider ./internal/tui ./internal/cli: ok. The three
TestStrictAffinity* tests fail on the code before this commit (200
where 429 was expected, acct-2 answering).
- GUI: stays-strict.test.cjs, chromium and webkit, 900 and 560px, en,
zh, zh-TW, ja, de: 30 of 30. On the assets before this commit it
fails 15 of 15 in chromium. routing-*.test.cjs pass but for
routing-steady's webkit 1.69px shift, which fails on the old assets
too: filed as #1804.
- gofmt -l, go vet (darwin, linux, windows), full go test ./... before
the push.
Not tried: a real agent conversation held on a real rate-limited
account.
Known and left: planLevel doesn't merge a nested group's sub.held, as
before this commit.
|
||
|
|
23e764d0e0 |
cli: magpie's commands move from the root into internal/cli; the root keeps only main.go
The root held 89 .go files (30 commands, 59 tests). They move as they are to internal/cli (package cli), with git mv so history follows them. The only code change is main() becoming cli.Main(version): the root's new main.go keeps `var version` in package main, so -ldflags "-X main.version=…" in the Makefile, the Dockerfile and magpie-releases, and every workflow, work unchanged. go-winres's rsrc_windows_*.syso still land next to package main in the root. Tests that read testdata by a root-relative path now go up one level (../plugin/testdata/fake, ../sessions/testdata). Five subsystem doc links point at internal/cli/. Run: - go build ./..., gofmt -l, go vet on darwin, linux and windows (nogui) - builds with tags production, dev, "production nogui"; windows -H windowsgui; linux CGO_ENABLED=0 - make release-cli TARGETS="darwin/arm64 linux/amd64 windows/amd64 android/arm64" VERSION=9.9.9-tidy: all four built, binary prints "magpie 9.9.9-tidy" - docker build --build-arg VERSION=7.7.7-tidy: container prints "magpie 7.7.7-tidy" - go test ./internal/cli (default and nogui): 152 tests, the same count as the root on main - go test ./...: all packages pass (agent, gateway, library, provider timed out at 10m under other sessions' load and passed rerun alone with -timeout 40m; none of them changed) - the built binary in a sandbox HOME: version, help, ls, providers, claude, and an unknown command's error |