kelvinjason11 on X: "图片识别好像只支持一个模型识别 没有fallback". When
the describer (Settings' Image recognition model, or AutoVision's pick)
failed, the turn failed with it, though other models that see were there.
Now describeWith asks the pick first, always. When it fails for any reason
but the client's own cancel, magpie asks the next model that sees: the
first ready one of seersRanked, AutoVision's own order (ready, then
Claude account, Codex, API key, other, then cost), leaving out each model
already tried and each one that turned an image away (sightRefused). At
most 3 models (visionTries), and all of them within visionWaitMost
together: each try gets what is left of it, not a fresh visionTimeout.
- The text header names the model that described the image
("as other/bigeye describes it"), not the pick.
- The Routing row of the stand-in carries Instead, Why and Picked
(describingInstead, the same fields web search's searchingInstead
sets), and the Routing page says in every language that the pick
couldn't describe it, why, and which model did instead.
- When none answers, the error is the first failure as before, then
"nor could X, asked in its place: why" for each other model tried.
- Spent/allowance: each try goes through serve as before, so autoSpent
and spentModel judge every stand-in the same as they judged the pick.
- vision_mcp's describe_image tool gets the same fallback.
Cache (s.sights): a description is kept under the pick and the image,
whichever model described it, with the describer's name beside it. The
same image sent again asks no one, the stand-in's text is reused, and
its header still names the stand-in. A new image asks the pick first
again, so a pick that comes back is used at once. Failures are not kept.
Settings' text ("When the model in use can't see images, this one
describes them to it") is left as it is: the pick is still asked first
for every image.
Tests (internal/gateway/vision_fallback_test.go):
- TestPickedDescriberThatFailsGivesWayToTheNextThatSees
- TestAutoDescriberThatFailsGivesWayToTheNext
- TestNoDescriberAnswersNamesEach
- TestPickedDescriberThatAnswersIsTheOnlyOneAsked
- TestCanceledDescriptionAsksNoOther
TestDescriberThatCantSeeIsntAskedToDescribe now expects the next model
that sees to describe in place of a text-only pick, not a 502.
GUI: internal/gui/tests/vision-instead.test.cjs (every language, 1100
and 520 wide).
Run on mote at 45739f15b (this tree, on origin/main 74f1df869):
- go test -tags nogui ./internal/gateway/ -count=1 -timeout 45m: ok
(542.988s). An earlier run while mote was at load ~26 failed four
Antigravity turned-away tests and TestCodexSpentGrokFailingIsTold.
None of them touches vision, and all passed in this run.
- gofmt -l: nothing.
- GOOS=linux go vet -tags nogui ./... and GOOS=windows go vet ./...: ok.
- GUI, Chromium: vision-instead, search-instead, routing-vision-why,
vision-mcp, routing-kind and i18n-keys (4/4) pass.
Broken by hand (in a worktree at 0fcb3acb3):
- The old code with the new tests: Picked, Auto and NoDescriberAnswers
go red. PickedThatAnswers and Canceled pass, as they should on code
that never falls back.
- The ctx.Err() check removed from describeWith: Canceled goes red (a
vision row for other/bigeye appears).
- describeWith made to ask the next model after a success:
PickedThatAnswers goes red ("eye asked 1 times, bigeye 1").
Not tried:
- The GUI files in WebKit. Playwright's WebKit launch timed out at 180s
while mote was at load ~25 from other suites. To be rerun.
- vision-instead against the old Routing client, to watch it go red.
- No real account: the fallback was run only against fake upstreams.
120 lines
7.9 KiB
JavaScript
120 lines
7.9 KiB
JavaScript
// Run with Node's test runner and Playwright on the module path; see README.md.
|
||
// An image described for a model that can't see, after the model asked
|
||
// first to describe it failed, says so in its Routing row: which model was
|
||
// asked first, for whom, why it couldn't, and which one described it in its
|
||
// place (kelvinjason11 on X: one describer failing failed every turn with
|
||
// an image). In every language, in both engines, at a narrow width too.
|
||
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 words = {
|
||
en: {
|
||
picked: /probe\/eye, the Image recognition model picked in Settings › Models, couldn't describe an image for Codex's zai\/glm-5\.2: 502 upstream closed\. So magpie had other\/bigeye, the next model it can use that sees, describe it in its place\. Not a turn of the conversation\.$/,
|
||
auto: /probe\/eye, the model magpie picked to describe images, couldn't describe an image for Codex's call to magpie's analyze_image MCP tool: it failed\. So magpie had other\/bigeye/,
|
||
},
|
||
zh: {
|
||
picked: /probe\/eye 是在 设置 › 模型 里选的识图模型,但它没能为 Codex 的 zai\/glm-5\.2 描述图片:502 upstream closed。所以 magpie 改让下一个可用的识图模型 other\/bigeye 来描述。不属于对话轮次。$/,
|
||
auto: /probe\/eye 是 magpie 自动选的识图模型,但它没能为 Codex 对 magpie 的 analyze_image MCP 工具的调用 描述图片:它出错了。/,
|
||
},
|
||
"zh-TW": {
|
||
picked: /probe\/eye 是在 設定 › 模型 裡選的識圖模型,但它沒能為 Codex 的 zai\/glm-5\.2 描述圖片:502 upstream closed。所以 magpie 改讓下一個可用的識圖模型 other\/bigeye 來描述。不屬於對話輪次。$/,
|
||
auto: /probe\/eye 是 magpie 自動選的識圖模型,但它沒能為 Codex 對 magpie 的 analyze_image MCP 工具的呼叫 描述圖片:它出錯了。/,
|
||
},
|
||
ja: {
|
||
picked: /設定 › モデル で選んだ画像認識モデル probe\/eye は Codex の zai\/glm-5\.2 のための画像を説明できませんでした:502 upstream closed。そのため magpie は次に使える画像を見られるモデル other\/bigeye に代わりに説明させました。会話のターンではありません。$/,
|
||
auto: /magpie が自動で選んだ画像認識モデル probe\/eye は Codex による magpie の analyze_image MCP ツールの呼び出し のための画像を説明できませんでした:エラーになりました。/,
|
||
},
|
||
de: {
|
||
picked: /probe\/eye, das unter Einstellungen › Modelle gewählte Bilderkennungsmodell, konnte kein Bild für zai\/glm-5\.2 von Codex beschreiben: 502 upstream closed\. Daher ließ magpie other\/bigeye, das nächste nutzbare Modell, das Bilder sieht, es an seiner Stelle beschreiben\. Keine Runde des Gesprächs\.$/,
|
||
auto: /probe\/eye, das von magpie gewählte Modell zum Beschreiben von Bildern, konnte kein Bild für den Aufruf von Codex an magpies MCP-Werkzeug analyze_image beschreiben: es ist fehlgeschlagen\./,
|
||
},
|
||
};
|
||
|
||
const now = new Date();
|
||
const day = [now.getFullYear(), now.getMonth() + 1, now.getDate()].map((n) => String(n).padStart(2, "0")).join("-");
|
||
const route = (id, f) => ({
|
||
id, seq: id, time: new Date(now.getTime() - id * 60e3).toISOString(), agent: "magpie", model: "other/bigeye", provider: "other",
|
||
kind: "vision", for: { agent: "codex", instead: "probe/eye", ...f },
|
||
order: [{ id: "other", provider: "other", name: "Other", who: "a@b.c", kind: "account", model: "bigeye" }],
|
||
tries: [{ id: "other", model: "bigeye", start: new Date(now.getTime() - id * 60e3).toISOString(), done: true, status: 200, ms: 900 }],
|
||
done: true, status: 200, ms: 900, tokens: 1200,
|
||
});
|
||
// newest first: the picked describer that failed, and magpie's own pick
|
||
// that failed an agent's analyze_image call with no reason kept
|
||
const routes = [route(1, { model: "zai/glm-5.2", picked: true, why: "502 upstream closed" }), route(2, { mcp: true })];
|
||
|
||
function serve(lang) {
|
||
const settings = { lang, theme: "light", vision: "probe/eye", gateway: "http://127.0.0.1:3999", port: 3999 };
|
||
const state = {
|
||
agents: [], profiles: [], settings,
|
||
clients: [{ id: "codex", name: "Codex", icon: "codex" }, { id: "magpie", name: "magpie", icon: "magpie" }],
|
||
};
|
||
return async (r) => {
|
||
const url = new URL(r.request().url());
|
||
const json = (data) => r.fulfill({ json: data });
|
||
if (url.pathname === "/boot.js") return r.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:true};` });
|
||
if (url.pathname === "/wails/runtime.js") return r.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
|
||
if (url.pathname === "/api/state") return json(state);
|
||
if (url.pathname === "/api/settings") return json(settings);
|
||
if (url.pathname === "/api/plugins") return json({ plugins: [] });
|
||
if (url.pathname === "/api/gateway/trace") {
|
||
if (url.searchParams.get("wait")) await new Promise((res) => setTimeout(res, 20e3));
|
||
return json({ mine: true, now: now.toISOString(), seq: 1, totals: { requests: 0, rerouted: 0, errors: 0 }, routes: [] });
|
||
}
|
||
if (url.pathname === "/api/gateway/history") {
|
||
return json({ cut: false, days: [{ day, requests: routes.length }], routes: url.searchParams.get("day") ? routes : [] });
|
||
}
|
||
if (url.pathname === "/api/groups") return json({ models: [], groups: [], pools: [] });
|
||
if (url.pathname === "/api/providers") return json({ providers: [], presets: [], excluded: [], gateway: { running: true, window: true, url: "http://127.0.0.1:3999" } });
|
||
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)];
|
||
try { await r.fulfill({ body: await fs.readFile(file), contentType }); } catch { await r.fulfill({ status: 404, body: "" }); }
|
||
};
|
||
}
|
||
|
||
async function open(t, engine, lang, width) {
|
||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
||
t.after(() => browser.close());
|
||
const page = await (await browser.newContext({ viewport: { width, height: 900 }, reducedMotion: "reduce" })).newPage();
|
||
page.setDefaultTimeout(5000);
|
||
const errors = [];
|
||
page.on("pageerror", (e) => errors.push(e.message));
|
||
await page.route("**/*", serve(lang));
|
||
await page.goto("http://magpie.test/?view=routing");
|
||
return { page, errors };
|
||
}
|
||
|
||
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
||
for (const lang of Object.keys(words)) {
|
||
const w = words[lang];
|
||
test(`${engine} ${lang}: an image described in place of the model asked first says which and why`, async (t) => {
|
||
for (const width of [1100, 520]) {
|
||
const { page, errors } = await open(t, engine, lang, width);
|
||
await page.locator(".rt-days .rt-day").nth(1).click();
|
||
// each row's story, read once its own is drawn
|
||
const said = [];
|
||
for (const i of [0, 1]) {
|
||
const req = page.locator(".rt-req").nth(i);
|
||
await req.waitFor();
|
||
await req.click();
|
||
const h = await page.waitForFunction((prev) => {
|
||
const s = document.querySelector(".rt-steps li.kind")?.textContent.trim();
|
||
return s && s !== prev && s;
|
||
}, said.at(-1) || "");
|
||
said.push(await h.jsonValue());
|
||
}
|
||
for (const want of [w.picked, w.auto]) {
|
||
assert(said.some((s) => want.test(s)), `${width}px: ${want} in\n${said.join("\n")}`);
|
||
}
|
||
assert(await page.evaluate(() => document.scrollingElement.scrollWidth <= innerWidth + 1), `no sideways scroll at ${width}px`);
|
||
assert.deepEqual(errors, []);
|
||
}
|
||
});
|
||
}
|
||
}
|