Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.
routing: an In order group's later members aren't said to go after a known allowance (bitssly on X)
yetone48194bbee098
diff --git a/docs/reference.md b/docs/reference.mdindex be0f99693..ad7d47038 100644--- a/docs/reference.md+++ b/docs/reference.md@@ -1521,7 +1521,8 @@ each of these groups ordered by the share used.left end first goes first. The daily Free Plan credits aren't counted,since they end at the same midnight on every account. A Claude accountmagpie knows nothing of yet goes first once, to learn what it has left- from the answer; any other unknown account goes after those known.+ from the answer; any other unknown account goes after those known,+ and is still tried when they fail, ahead of any at 90% or more.An account with a month beside its week (Factory) goes by its month:when the month holds less than its weeks add up to (Factory's, byone user's readings, about two weeks' worth), what a week leaves isn't@@ -1530,7 +1531,12 @@ each of these groups ordered by the share used.on the Routing page says the fullest window's share with when thatwindow renews: "32% used · renews in 3 days" is the week's.- **In order**: the accounts in their order. The first takes every request- until it is used up (100%) or fails.+ until it is used up (100%) or fails. A routing group set In order tries+ its members in the order given, whatever is known of what each has+ left: a member whose allowance isn't known isn't moved behind one whose+ is. Each member's own accounts go as its provider routes them, and the+ Routing page says an account went after those known only of one+ weighed against a known account of the same member.- **In turn**: each turn of a conversation goes to the next account. A newconversation goes to the account the fewest other conversations of thelast 30 minutes are on.diff --git a/internal/gui/assets/plugins/routing/client.js b/internal/gui/assets/plugins/routing/client.jsindex 9aed852ee..99ee15ee0 100644--- a/internal/gui/assets/plugins/routing/client.js+++ b/internal/gui/assets/plugins/routing/client.js@@ -582,6 +582,29 @@ function routingPage(part) {// an agent's subagents that magpie put a subagent on in its placeconst wentOn = (r) => (r.subagent && !r.subagent.kept ? r.subagent.to : r.model);+ // the routing of the group x's place is in: the innermost group in the+ // group (via), else the group asked for; "" when no group was+ const placeRouting = (r, x) => {+ const via = x.via || [];+ return via.length ? r.group?.subs?.find((s) => s.id === via[via.length - 1])?.routing || "" : r.group?.routing || "";+ };+ // a group routed in order or by weight tries each member whole, in its+ // place, over its own accounts or keys as its provider routes them+ // (planLevel): its members aren't weighed against each other+ const wholeMembers = (r, x) => !!r.group && ["order", "weight"].includes(placeRouting(r, x));+ // weighedWith is the rows x was weighed against, x among them: in a+ // group routed in order or by weight, its own member's; else every one+ // in its place (the group's own, or one group in it). A fallback is+ // weighed with its own provider's alone (plan). bitssly on X: an In+ // order group said its later members, whose allowance isn't known, went+ // after the first because the first's was+ function weighedWith(r, x) {+ const via = (y) => (y.via || []).join(">");+ const whole = wholeMembers(r, x);+ return r.order.filter((y) => !!y.fallback === !!x.fallback && via(y) === via(x)+ && (!(x.fallback || whole) || (y.provider === x.provider && y.model === x.model && (y.fixed || "") === (x.fixed || "") && !!y.fast === !!x.fast)));+ }+// why routing put the first where it didfunction firstWhy(r) {const f = r.order[0];@@ -599,6 +622,17 @@ function routingPage(part) {const name = r.order.find((x) => !x.fallback)?.name || r.provider;return t("{name} is resting, so its fallback {fb} goes first.", { name, fb: `${f.provider}/${f.model}` });}+ if (wholeMembers(r, f)) {+ // first as the group's member: by its place, or the round's pick;+ // weighed only against its own member's others, if any+ const own = weighedWith(r, f);+ if (own.length > 1) return firstWhy({ ...r, order: own, group: null });+ if (placeRouting(r, f) === "weight") return t("By weight: it's {who}'s share — each model takes requests as the weight set beside it says.", { who: w });+ const ahead = r.order.filter((x) => x !== f && x.rest).map(who);+ return ahead.length+ ? t("In order: with {rested} resting after a failure, {who} is the first that can answer.", { rested: ahead.join(", "), who: w })+ : t("In order: {who} is first, and answers everything while it can.", { who: w });+ }const peers = r.order.filter((x) => x !== f && !x.fallback && !x.rest);const someKnown = r.order.some((x) => x.known);const rested = r.order.filter((x) => x !== f && !x.fallback && x.rest).map(who);@@ -707,14 +741,15 @@ function routingPage(part) {if (p.byFolder) out[out.length - 1] += " " + (p.folder ? t("The agent works in {folder}.", { folder: p.folder }) : t("The agent didn't say which folder it works in."));}const smart = (x) => !x.routing && (x.kind === "account" || x.known);- const someKnown = r.order.some((x) => x.known);+ // weighed with one known: its place among them is what Smart says+ const someKnown = (x) => weighedWith(r, x).some((y) => y !== x && y.known);const f0 = r.order[0];for (const x of r.order.slice(1)) {// behind the first by a group's weights or its order, which take// each member whole: not by what x has left (Creat.wu: a group in// a group by weight, its accounts at 91%, read as passed over)const by = !x.rest && !x.sunk && f0 ? memberSplit(r, f0, x) : null;- if (by && smart(x) && (x.known ? group(x) === "low" : someKnown)) {+ if (by && smart(x) && (x.known ? group(x) === "low" : someKnown(x))) {if (!told.has(by.member)) {told.add(by.member);out.push(by.routing === "weight"@@ -726,10 +761,10 @@ function routingPage(part) {if (x.sunk && !x.rest) out.push(t("{who} was rate limited at {time} while it had quota left, so it went to the back: it comes round again once those ahead of it are rate limited in turn.", { who: who(x), time: clock(x.sunk) }));else if (x.rest) out.push(t("{who} is resting — {why}, {when} — so it waits at the back.", { who: who(x), why: `${x.rest.status} · ${failWord(x.rest.why)}`, when: restWhen(x.rest, at(r.time)) }));else if (smart(x) && x.known && group(x) === "spent" && x.credits) out.push(t("{who} is at {n} of its allowance but goes on on its credits — ahead of those used up with nothing to go on with, after those with allowance left.", { who: who(x), n: pct(x.used) }));- else if (smart(x) && x.known && group(x) === "spent") out.push(t("{who} is at {n} — all but used up, it answers only when nothing else can.", { who: who(x), n: pct(x.used) }));- else if (smart(x) && x.known && group(x) === "low") out.push(t("{who} is at {n} — kept for when the others can't.", { who: who(x), n: pct(x.used) }));- else if (smart(x) && x.learns && someKnown) out.push(t("{who}: what it has left isn't known yet, and its answer tells, so it goes before those known.", { who: who(x) }));- else if (smart(x) && !x.known && someKnown) out.push(t("{who}: what it has left isn't known yet, so it goes after those known.", { who: who(x) }));+ else if (smart(x) && x.known && group(x) === "spent" && weighedWith(r, x).length > 1) out.push(t("{who} is at {n} — all but used up, it answers only when nothing else can.", { who: who(x), n: pct(x.used) }));+ else if (smart(x) && x.known && group(x) === "low" && weighedWith(r, x).length > 1) out.push(t("{who} is at {n} — kept for when the others can't.", { who: who(x), n: pct(x.used) }));+ else if (smart(x) && x.learns && someKnown(x)) out.push(t("{who}: what it has left isn't known yet, and its answer tells, so it goes before those known.", { who: who(x) }));+ else if (smart(x) && !x.known && someKnown(x)) out.push(t("{who}: what it has left isn't known yet, so it goes after those known.", { who: who(x) }));}const pooled = r.order.find((x) => !x.aside && x.kind === "key");for (const x of r.order.filter((x) => x.aside)) out.push(t("{who} is made for {api}, not {other} as the keys routed over are, so it isn't one of them: it's tried after them.", { who: who(x), api: API[x.speaks] || x.speaks || t("any API"), other: API[pooled?.speaks] || pooled?.speaks || t("any API") }));diff --git a/internal/gui/assets/plugins/routing/i18n.js b/internal/gui/assets/plugins/routing/i18n.jsindex 5dc4bffad..f4b33f56d 100644--- a/internal/gui/assets/plugins/routing/i18n.js+++ b/internal/gui/assets/plugins/routing/i18n.js@@ -36,6 +36,7 @@ magpie.strings({"{name} switched off": "已关闭 {name}","in {groups}": "已在 {groups}","By weight: it's {who}'s share \u2014 each key takes requests as its weight says.": "按权重:轮到 {who} 的份额——每个密钥按自己的权重接请求。",+ "By weight: it's {who}'s share — each model takes requests as the weight set beside it says.": "按权重:轮到 {who} 的份额——每个模型按旁边设置的权重接请求。","By weight: each model takes its share of the requests by the weight set beside it — one weighing 3 three for every one a model weighing 1 takes, spread out rather than in bursts. One resting after a failure leaves the round and the others share its requests; the next model is the fallback when one fails.": "按权重:每个模型按旁边设置的权重分得请求——权重 3 的模型每接 3 个,权重 1 的接 1 个,均匀穿插而不是成批连发。失败后休息中的模型退出这一轮,其余模型分担它的请求;某个模型失败时,由下一个模型接替。","Its share of the requests: a model weighing 3 takes three for every one a model weighing 1 takes": "它在请求中的份额:权重 3 的模型每接 3 个请求,权重 1 的接 1 个","Weight of {name}": "{name} 的权重",@@ -589,6 +590,7 @@ magpie.strings({"{name} switched off": "已關閉 {name}","in {groups}": "已在 {groups}","By weight: it's {who}'s share — each key takes requests as its weight says.": "按權重:輪到 {who} 的份額——每個金鑰按自己的權重接請求。",+ "By weight: it's {who}'s share — each model takes requests as the weight set beside it says.": "按權重:輪到 {who} 的份額——每個模型按旁邊設定的權重接請求。","By weight: each model takes its share of the requests by the weight set beside it — one weighing 3 three for every one a model weighing 1 takes, spread out rather than in bursts. One resting after a failure leaves the round and the others share its requests; the next model is the fallback when one fails.": "按權重:每個模型按旁邊設定的權重分得請求——權重 3 的模型每接 3 個,權重 1 的接 1 個,均勻穿插而不是成批連發。失敗後休息中的模型退出這一輪,其餘模型分擔它的請求;某個模型失敗時,由下一個模型接替。","Its share of the requests: a model weighing 3 takes three for every one a model weighing 1 takes": "它在請求中的份額:權重 3 的模型每接 3 個請求,權重 1 的接 1 個","Weight of {name}": "{name} 的權重",@@ -1122,6 +1124,7 @@ magpie.strings({"{name} switched off": "{name} をオフにしました","in {groups}": "{groups} に追加済み","By weight: it's {who}'s share \u2014 each key takes requests as its weight says.": "重み付け:{who} の取り分です——各キーは重みどおりにリクエストを受けます。",+ "By weight: it's {who}'s share — each model takes requests as the weight set beside it says.": "重み付け:{who} の取り分です——各モデルは横に設定した重みどおりにリクエストを受けます。","By weight: each model takes its share of the requests by the weight set beside it — one weighing 3 three for every one a model weighing 1 takes, spread out rather than in bursts. One resting after a failure leaves the round and the others share its requests; the next model is the fallback when one fails.": "重み付け:各モデルは横に設定した重みに応じてリクエストを受けます。重み 3 のモデルは、重み 1 のモデルが 1 件受けるごとに 3 件受け、まとめてではなく分散して届きます。失敗して休止中のモデルは巡回から外れ、残りがその分を分け合います。あるモデルが失敗したときは次のモデルが引き継ぎます。","Its share of the requests: a model weighing 3 takes three for every one a model weighing 1 takes": "リクエストの取り分:重み 3 のモデルは、重み 1 のモデルが 1 件受けるごとに 3 件受けます","Weight of {name}": "{name} の重み",@@ -1666,6 +1669,7 @@ magpie.strings({"{name} switched off": "{name} ausgeschaltet","in {groups}": "in {groups}","By weight: it's {who}'s share \u2014 each key takes requests as its weight says.": "Nach Gewicht: {who} ist mit seinem Anteil dran — jeder Schlüssel bekommt Anfragen nach seinem Gewicht.",+ "By weight: it's {who}'s share — each model takes requests as the weight set beside it says.": "Nach Gewicht: {who} ist mit seinem Anteil dran — jedes Modell bekommt Anfragen nach dem Gewicht, das daneben eingestellt ist.","By weight: each model takes its share of the requests by the weight set beside it — one weighing 3 three for every one a model weighing 1 takes, spread out rather than in bursts. One resting after a failure leaves the round and the others share its requests; the next model is the fallback when one fails.": "Nach Gewicht: Jedes Modell bekommt seinen Anteil an den Anfragen nach dem Gewicht daneben – eines mit Gewicht 3 drei für jede, die ein Modell mit Gewicht 1 bekommt, verteilt statt in Schüben. Eines, das nach einem Fehler pausiert, setzt aus, und die anderen teilen sich seine Anfragen; scheitert eines, springt das nächste Modell ein.","Its share of the requests: a model weighing 3 takes three for every one a model weighing 1 takes": "Sein Anteil an den Anfragen: Ein Modell mit Gewicht 3 bekommt drei für jede, die eines mit Gewicht 1 bekommt","Weight of {name}": "Gewicht von {name}",diff --git a/internal/gui/tests/routing-order-unknown.test.cjs b/internal/gui/tests/routing-order-unknown.test.cjsnew file mode 100644index 000000000..e1f00ad67--- /dev/null+++ b/internal/gui/tests/routing-order-unknown.test.cjs@@ -0,0 +1,123 @@+// Run with Node's test runner and Playwright on the module path; see README.md.+// A routing group set In order tries its members in the order the user+// gave, each over its own accounts as its provider routes them+// (planLevel): an account whose allowance isn't known doesn't go after+// another member's known one. The Routing page said it did (bitssly on+// X: "opencode:剩余额度未知,排在已知的之后。" under an In order group),+// as if magpie had moved the member the user put there. Now an In order+// group's first says In order, and the unknown-allowance line is said+// only of an account weighed against a known one of its own member, as+// a Smart group still says it of each; a group By weight says the+// round picked its first. English, Chinese (both),+// Japanese and German; 1100 and 420 wide; no backend, the API is faked+// here.+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 now = new Date();+const ago = (s) => new Date(now.getTime() - s * 1e3).toISOString();+const ahead = (h) => new Date(Date.now() + h * 3600e3).toISOString();+const acct = (p, name, user, model, extra = {}) => ({ id: `${p}@${user}`, provider: p, name, who: user, kind: "account", agent: p, model, routing: "", ...extra });++const codex = acct("codex", "Codex", "[email protected]", "gpt-5.5", { plan: "Plus", known: true, used: 30, renews: [ahead(50)] });+const zen = acct("opencode-zen-free", "OpenCode Zen Free", "opencode", "big-pickle");+const wbKnown = acct("workbuddy-ai", "WorkBuddy AI", "[email protected]", "glm-5", { known: true, used: 20, renews: [ahead(100)] });+const wbUnknown = acct("workbuddy-ai", "WorkBuddy AI", "腾讯-国际", "glm-5");++const members = ["codex/gpt-5.5", "opencode-zen-free/big-pickle", "workbuddy-ai/glm-5"];+const routeOf = (id, group, order) => ({+ id, seq: id, time: ago(60 - id), agent: "codex", model: group.id, provider: "codex", done: true, status: 200, ms: 900, tokens: 1200, group, order,+ tries: [{ id: order[0].id, model: order[0].model, start: ago(60 - id), done: true, status: 200, ms: 900 }],+});+// In order: Codex first as the user put it; WorkBuddy AI's two accounts,+// one member, Smart between themselves: the known one first+const ordered = routeOf(1, { id: "coding", name: "coding", routing: "order", members }, [codex, zen, wbKnown, wbUnknown]);+// Smart: every member's accounts weighed as one, the unknown after+const smart = routeOf(2, { id: "mix", name: "mix", routing: "", members }, [codex, wbKnown, zen, wbUnknown]);+// By weight: the round's pick first, each member whole after it+const weighted = routeOf(3, { id: "spread", name: "spread", routing: "weight", members }, [zen, codex, wbKnown, wbUnknown]);++function serve(lang) {+ return async (request) => {+ const url = new URL(request.request().url());+ const json = (data) => request.fulfill({ json: data });+ if (url.pathname === "/boot.js") return request.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:true};` });+ if (url.pathname === "/wails/runtime.js") return request.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });+ if (url.pathname === "/api/state") return json({ agents: [{ id: "codex", name: "Codex", path: "/test/config.toml", fields: [] }], profiles: [], settings: { lang, theme: "light" } });+ if (url.pathname === "/api/gateway/trace") {+ if (url.searchParams.get("wait")) { await new Promise((r) => setTimeout(r, 20e3)); return json({}); }+ return json({ mine: true, now: now.toISOString(), seq: 3, totals: { requests: 3, rerouted: 0, errors: 0 }, routes: [ordered, smart, weighted] });+ }+ if (url.pathname === "/api/gateway/history") return json({ cut: false, days: [], routes: [] });+ if (url.pathname === "/api/groups") return json({ groups: [], pools: [] });+ if (url.pathname === "/api/providers") return json({ providers: [], excluded: [], gateway: { running: true, window: true } });+ 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 request.fulfill({ body: await fs.readFile(file), contentType });+ };+}++for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {+ for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) {+ for (const width of [1100, 420]) {+ test(`${engine} ${lang} ${width}: an In order group's later members aren't said to go after a known allowance`, async (t) => {+ const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));+ t.after(() => browser.close());+ const page = await browser.newPage({ viewport: { width, height: 900 }, reducedMotion: "reduce" });+ page.setDefaultTimeout(5000);+ const errors = [];+ page.on("pageerror", (error) => errors.push(error.message));+ await page.route("**/*", serve(lang));+ await page.goto("http://magpie.test/?view=routing");+ const say = (key, vars = {}) => page.evaluate(([lang, key, vars]) => {+ const s = (lang !== "en" && I18N[lang]?.[key]) || key;+ return s.replace(/\{(\w+)\}/g, (_, k) => vars[k] ?? `{${k}}`);+ }, [lang, key, vars]);+ const unknown = (who) => say("{who}: what it has left isn't known yet, so it goes after those known.", { who });+ // the story of the request with the group named+ const story = async (name) => {+ const row = page.locator(".rt-req", { hasText: name }).first();+ await row.waitFor();+ await row.dispatchEvent("click"); // the list may run past a narrow window+ await page.locator(".rt-steps li").first().waitFor();+ await page.waitForFunction((name) => document.querySelector(".rt-steps")?.textContent.includes(name), name);+ return page.locator(".rt-steps li").evaluateAll((ls) => ls.map((l) => [l.className, l.textContent.trim()]));+ };++ let got = await story("coding");+ const why = got.filter(([c]) => c === "why").map(([, s]) => s);+ assert.deepEqual(why, [await say("In order: {who} is first, and answers everything while it can.", { who: "[email protected]" })], JSON.stringify(got));+ const asides = got.filter(([c]) => c === "aside").map(([, s]) => s);+ // OpenCode Zen Free is its own member, after Codex by the order given+ assert(!asides.includes(await unknown("opencode")), JSON.stringify(asides));+ // WorkBuddy AI's unknown account, weighed against its own known one,+ // is told with its member: after Codex by the order given+ assert(asides.includes(await say("{member} isn't passed over for being near its limit: it comes after {first} in {group}'s order.", { member: "WorkBuddy AI", first: "Codex", group: "coding" })), JSON.stringify(asides));+ assert(!asides.some((s) => s.startsWith("OpenCode Zen Free")), JSON.stringify(asides));++ got = await story("mix");+ const smartAsides = got.filter(([c]) => c === "aside").map(([, s]) => s);+ assert(smartAsides.includes(await unknown("opencode")), JSON.stringify(smartAsides));+ assert(smartAsides.includes(await unknown("腾讯-国际")), JSON.stringify(smartAsides));++ // by weight: the first is the round's pick, not one weighed by+ // its allowance against Codex's+ got = await story("spread");+ assert.deepEqual(got.filter(([c]) => c === "why").map(([, s]) => s), [await say("By weight: it's {who}'s share — each model takes requests as the weight set beside it says.", { who: "opencode" })], JSON.stringify(got));+ const wAsides = got.filter(([c]) => c === "aside").map(([, s]) => s);+ assert(!wAsides.some((s) => s.startsWith("[email protected]")), JSON.stringify(wAsides));+ assert(!wAsides.includes(await unknown("opencode")), JSON.stringify(wAsides));+ assert(wAsides.includes(await unknown("腾讯-国际")), JSON.stringify(wAsides));++ const spills = await page.locator(".rt-steps li").evaluateAll((els) => els.filter((e) => e.getBoundingClientRect().right > document.documentElement.clientWidth + 0.5).map((e) => e.textContent.slice(0, 40)));+ assert.deepEqual(spills, []);+ assert.deepEqual(errors, []);+ });+ }+ }+}