01huadalang on Discord, after76e4494db: Codex on several accounts in a group with mimo2.6pro as the backup, Stays on Auto. Once Codex had quota again, requests kept going to mimo. The cause: when Codex couldn't answer, the turn fell over to mimo and the session was stuck to mimo. On the next turns affine kept it there by "cache", because only In order had a way back (backToFirst, Why "order"). A Smart group (and the other routings) never gave the conversation back to the member ahead, however long Codex had been ready. The fix: at the answer, the gateway records whether the member that answered stood in for one listed ahead of it in the group: one that was resting, or known all but used up (Used >= SpentShareOf). planGroup now gives each candidate its member and its place in the group (placed), and standsInFor reads the plan made before the tries. The flag is the stick's stoodIn, inherited while the same who and model keep answering, and saved in affinity.json (stoodIn). With Stays on Auto, a stick that stood in goes back to the group's first member once that one is ready and not set aside (backFromStandIn), with the new Why "back" and its Routing page line in all five languages. A member put first on its merits (not a stand-in) keeps its cache as before; Off, Session, Strict, Turn and In order keep their own rules. Not changed, by design: Smart and Least used count a key with unknown usage (mimo) as unused, so with every Codex account at 90% or more of a window a new session can go to mimo first. In order keeps a backup last; the routing doc says so. Tests (internal/gateway/group_stand_in_test.go, new): - TestGroupBackupGivesTheConversationBack: smart auto with usage known and unknown go back ("back"); in order auto "order"; in turn and smart turn "new-turn"; smart off "off"; smart session, smart strict and in order session stay on mimo. - TestGroupBackupStandingInWhileTheFirstIsBackAndBehind, TestGroupMemberPutFirstOnItsMeritsKeepsItsCache, TestGroupStandInStaysWithinATurn, TestGroupStandInSurvivesARestart. - affinity_fallback_test's TestGroupMemberKeepsTheConversationOnceAnother IsBack pinned the old behaviour; it is now TestGroupMemberGivesTheConversationBackOnceTheOneAheadIsBack. - routing-affinity-order.test.cjs gains the "back" line. Run, all on mote: - With the non-test changes stashed (old code): both smart auto cases, StandingInWhileTheFirstIsBackAndBehind, SurvivesARestart and GivesTheConversationBackOnceTheOneAheadIsBack are red. Green with the fix. - Broken by hand, each red: the "back" case off (smart cases, StandingInWhileBehind); no inherit (StandingInWhileBehind); rest/spent check off (usage-known case, StandingInWhileBehind); stoodIn check dropped from the back case (PutFirstOnItsMerits); StoodIn not loaded (SurvivesARestart). A check of failed tries stayed green when turned off, since a failed try rests what failed, so it was removed. - go test -tags nogui -count=1 -timeout 45m ./... at80bcef18f+ this: every package ok except internal/gui, whose two reds are red on origin/maind714c4216too: TestSettingsSaveKeepsWhatItDoesNotSend (#4514) and TestColdTurnsTaken (#4510). - Rebased on5a56bc7d7: internal/gateway, internal/provider and internal/catalog ok; internal/gui has only the same two reds (#4514, #4510). Main then moved three provider-only commits; at the pushed parentf856d381a, internal/provider ok and internal/gateway -run 'Group|Affinity|Fallback|Ordered|Strict|Rotating|Stick' ok. - gofmt -l clean; go vet, GOOS=linux and GOOS=windows go vet -tags nogui ./internal/gateway ok. - GUI (Chromium and WebKit): routing-affinity-order, routing-js, i18n-keys, gui-zh-tw and gui-de pass; gui-ja's one red is #4580 (a7b47d57e's string, not this one). - Every routing-*.test.cjs file on mote (2050 tests, both engines, five languages) at load 140 to 200 from other sessions' suites: 35 red in 10 files, all timeouts or moves under load. The same 10 files run alone, serially, at this head and at origin/main41b5c0f19are red in the same tests (27 and 30, differing only in which language flaked). All filed: #4585, #3789, #3096, #3094, #3799, #3412, #1804, #4560, #3593, #4082, #4627, #4628, #3954, #4629. Not tried: no real Codex or MiMo account; the case was reproduced with a fake upstream only. A stick saved before this change has no stoodIn, so a conversation already stuck to the backup stays there until it goes cold (5 minutes idle) or a new session starts.
92 lines
6.2 KiB
JavaScript
92 lines
6.2 KiB
JavaScript
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");
|
|
|
|
// A conversation a later member of a group routed In order answered goes
|
|
// back to the first member at its next turn, once that one is ready
|
|
// (yyhhyyyyyy on Discord: an API key first, a Claude subscription second,
|
|
// 8 of 10 requests on the subscription). The Routing page says why it
|
|
// moved, as it does for a provider's fallback giving one back ("main"),
|
|
// which said nothing before. A conversation Stays: Strict keeps on the
|
|
// fallback, the provider ready again, says that too ("strict" with main;
|
|
// 01huadalang on Discord, 10-31). A member of a group routed any other
|
|
// way that stood in for one listed ahead of it gives the conversation back
|
|
// too, and says so ("back"; 01huadalang, 11-01: a MiMo backup kept a Codex
|
|
// session by its cache).
|
|
const words = {
|
|
en: { back: ["listed ahead of it in the group", "turn 2 goes back"], order: ["goes in order", "turn 2 goes back"], main: ["a fallback", "turn 2 goes back"], strict: ["a fallback", "Strict", "new conversations go to"] },
|
|
zh: { back: ["排在它前面", "第 2 轮回到它"], order: ["按顺序路由", "第 2 轮回到"], main: ["备用", "第 2 轮回到它"], strict: ["备用", "严格", "新会话会走"] },
|
|
"zh-TW": { back: ["排在它前面", "第 2 輪回到它"], order: ["按順序路由", "第 2 輪回到"], main: ["備用", "第 2 輪回到它"], strict: ["備用", "嚴格", "新會話會走"] },
|
|
ja: { back: ["受けられなかった", "ターン 2 は"], order: ["順番どおり", "ターン 2 は"], main: ["代替", "ターン 2 は"], strict: ["代替", "厳格", "新しい会話は"] },
|
|
de: { back: ["in der Gruppe davor", "Runde 2 dorthin zurück"], order: ["der Reihe nach", "Runde 2 zurück"], main: ["ein Ersatz", "Runde 2 dorthin zurück"], strict: ["ein Ersatz", "Strikt", "neue Unterhaltungen gehen an"] },
|
|
};
|
|
|
|
function routes(now, why) {
|
|
const time = new Date(now.getTime() - 5000).toISOString();
|
|
const at = new Date(now.getTime() - 65000).toISOString();
|
|
const k1 = { id: "cw#k1", provider: "cw", name: "CW", kind: "key", who: "k1", model: "m" };
|
|
const k2 = { id: "cw#k2", provider: "cw", name: "CW", kind: "key", who: "k2", model: "m", fallback: why !== "order" && why !== "back" };
|
|
// Strict leaves the plan the one it keeps, and names the main beside it
|
|
const order = why === "strict" ? [k2] : [k1, k2];
|
|
return [{ id: 1, seq: 1, time, agent: "claude", model: "cw/m", provider: "cw", order, done: true, status: 200, ms: 20,
|
|
group: why === "order" ? { id: "g", name: "G", routing: "order" } : why === "back" ? { id: "g", name: "G", routing: "" } : undefined,
|
|
affinity: { mode: why === "strict" ? "strict" : "", turn: 2, last: "cw#k2", lastTurn: 1, at, cacheRead: 20000, cacheWrite: 3000, why, main: why === "strict" ? k1 : undefined },
|
|
tries: [{ id: order[0].id, model: "m", start: time, done: true, status: 200, ms: 20 }] }];
|
|
}
|
|
|
|
function serve(lang, getRoutes, now) {
|
|
const assets = path.resolve(__dirname, "../assets");
|
|
return async (route) => {
|
|
const url = new URL(route.request().url());
|
|
const json = (data) => route.fulfill({ json: data });
|
|
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs={lang:"${lang}",theme:"light",web:true};` });
|
|
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window={};" });
|
|
if (url.pathname === "/api/state") return json({ agents: [], profiles: [], settings: { lang, theme: "light" } });
|
|
if (url.pathname === "/api/gateway/trace") {
|
|
if (url.searchParams.has("wait")) return;
|
|
return json({ mine: true, now: now.toISOString(), seq: 1, totals: { requests: 1, rerouted: 0, errors: 0 }, routes: getRoutes() });
|
|
}
|
|
if (url.pathname === "/api/gateway/history") return json({ cut: false, days: [], routes: [] });
|
|
if (url.pathname === "/api/groups") return json({ groups: [] });
|
|
if (url.pathname === "/api/providers") return json({ providers: [], presets: [], 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" }[path.extname(file)];
|
|
await route.fulfill({ body: await fs.readFile(file).catch(() => ""), contentType });
|
|
};
|
|
}
|
|
|
|
for (const engine of process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"]) {
|
|
for (const width of [1100, 420]) {
|
|
for (const lang of Object.keys(words)) {
|
|
test(`${engine} ${width} ${lang}: affinity says a conversation went back to the first`, 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 } });
|
|
page.setDefaultTimeout(5000);
|
|
page.setDefaultNavigationTimeout(60000);
|
|
const errors = [];
|
|
page.on("pageerror", (e) => errors.push(e.message));
|
|
const now = new Date();
|
|
let rs;
|
|
await page.route("**/*", serve(lang, () => rs, now));
|
|
const story = async () => {
|
|
await page.goto("http://magpie.test/?view=routing");
|
|
await page.waitForFunction(() => /\d/.test(document.body.innerText) && document.querySelector(".rt-cap")?.textContent);
|
|
return page.evaluate(() => document.body.innerText + "\n" + document.querySelector(".rt-cap").textContent);
|
|
};
|
|
for (const why of ["back", "order", "main", "strict"]) {
|
|
rs = routes(now, why);
|
|
const text = await story();
|
|
for (const w of words[lang][why]) assert.ok(text.includes(w), `${why}: ${w} not in\n${text}`);
|
|
assert.doesNotMatch(text, /\{(who|first|n)\}/);
|
|
assert.equal(await page.evaluate(() => document.documentElement.scrollWidth <= window.innerWidth), true, "no sideways scroll");
|
|
}
|
|
assert.deepEqual(errors, []);
|
|
});
|
|
}
|
|
}
|
|
}
|