routing: a failed try's tag over its row is whole until it fades (yuancjun)

yuancjun on Discord (#feedback, v0.1.2784, Chrome 128 on macOS): a member
row's failure tag ("504 · 迟迟未开始") showed whole for ~0.45s, then its
top half, the ~10px over the row's top edge, was cut off until it faded
at 1.8s. Their analysis was right: `.rt-accts .tag` sits at top:-10px,
`.rt-accts li:not(.hit)` has content-visibility: auto (#3164), which
always paint-contains, and rerun() takes `.hit` off on the shake's
animationend at 0.45s while `.tagged` stays 1800ms.

The row is now drawn whole by a class of its own, `lift`, put on with
`tagged` and taken off 300ms after it, once the tag's .25s fade-out is
over: with `:not(.tagged)` alone the tag's top would be cut again for
the whole fade. The CSS rule goes on `:not(.lift)`; `.hit` always came
with the tag, so it adds nothing there. A row tagged again within 1.8s
(the next try failing on it) starts the 1.8s over: the first failure's
timer used to take the second tag down early. This is the only place a
row is tagged; nothing else in .rt-accts stands over a row's edge.

Run on mote (load 70-110 from other sessions' suites):
- routing-tag-whole.test.cjs (new): Chromium and WebKit, en, zh, zh-TW,
  ja, de, 1100 and 420 wide, motion on (the shake must end for the cut
  to show): 20 of 20 ok. It plays a live request failing 504 slow,
  checks the tag's words, then at ~0.8s screenshots the band of the tag
  over the row's edge and counts the tag's red in it, checks the row's
  content-visibility while tagged and while it fades, and that rows go
  back to auto after.
- At the rebased head (on 06944e065): routing-tag-whole, i18n-keys and
  routing-held-dot, both engines: 44 of 44 ok.
- Before the rebase (on 2c214ce25), every routing-*.test.cjs and
  panel-routing*.test.cjs, i18n-keys and claude-subagent-tag, both
  engines, concurrency 6: 2301 of 2342 ok, routing-tag-whole 20 of 20.
  The 41 reds are in routing-many-keys, -order-unknown, -row-swap,
  -rule-drag, -rule-remove, -rules-line, -sign-in-again, -steady,
  -steps-cap and -story-shrinks. Those ten files again at concurrency 2:
  30 red at this change, 23 at 2c214ce25 without it, the same tests
  (row-swap, rule-drag, steady, steps-cap, story-shrinks, order-unknown
  webkit de 420 red at both; rule-remove and rules-line vary by run).
  None of them reads .rt-accts content-visibility or the tag. Filed
  already: #4585 (these files under load), #3799, #3789, #4627, #4628,
  #4629.

Broken by hand: the CSS back on `:not(.hit)`: 20 of 20 red at "a tagged
row is drawn whole"; with that check taken out, the screenshot check
alone is red in both engines with 0% of the band red (8 of 8, en and zh).

Not tried: the real app's WebKitGTK and WebView2; Chrome 128 itself
(Playwright's Chromium is newer).
This commit is contained in:
yetone
2026-11-03 14:01:55 +08:00
parent 06944e065b
commit 889767b7b3
3 changed files with 140 additions and 5 deletions
+12 -2
View File
@@ -338,6 +338,7 @@ function routingPage(part) {
e.classList.add(cls);
};
const tick = (e) => rerun(e, "tick", "rttick");
const tagFor = new WeakMap(); // a row's failure tag: the timer that takes it down
// ---------- words ----------
@@ -4598,9 +4599,18 @@ function routingPage(part) {
tick(A.node);
break;
}
rerun(row.li, "hit", "rthit"); row.li.classList.add("tagged");
// the tag stands over the row's top edge, so the row is drawn whole
// (lift, routing.css) while it shows and as it fades: the shake's
// .hit ends at .45s, and with it the tag's top was cut for the rest
// of its 1.8s (yuancjun on Discord). A failure again on the row
// starts the 1.8s over
rerun(row.li, "hit", "rthit"); row.li.classList.add("tagged", "lift");
row.tg.textContent = `${tr.status} · ${failWord(tr.fail)}`;
setTimeout(() => row.li.classList.remove("tagged"), 1800);
clearTimeout(tagFor.get(row.li));
tagFor.set(row.li, setTimeout(() => {
row.li.classList.remove("tagged");
tagFor.set(row.li, setTimeout(() => row.li.classList.remove("lift"), 300));
}, 1800));
say(tryWhy(r, i));
renderAll();
dot.classList.add("back", "err");
@@ -69,9 +69,10 @@
/* a key off screen is not laid out or painted (#3164): with hundreds of
keys open, WebKit painted every row again on each frame a magpie flew.
One not drawn yet is as tall as a key drawn is (--rt-row, client.js's
layout). A row a 429 hit keeps its tag up over its top edge, which this
would cut, so it is drawn whole */
.rt-accts li:not(.hit) { content-visibility: auto; contain-intrinsic-size: auto var(--rt-row, 38px); }
layout). A row a failure tagged keeps its tag up over its top edge,
which this would cut, so it is drawn whole until the tag has faded
(lift, client.js) */
.rt-accts li:not(.lift) { content-visibility: auto; contain-intrinsic-size: auto var(--rt-row, 38px); }
/* a run of keys far from sight, out of the list (client.js place, #3164) */
.rt-accts li.rt-gap { display: block; padding: 0; border: 0; background: none; content-visibility: visible; contain: strict; pointer-events: none; }
/* a group in the group: a heading its models hang from, set in under it */
@@ -0,0 +1,124 @@
// Run with Node's test runner and Playwright on the module path; see README.md.
// A try that fails tags its row on the Routing page's stage ("504 · slow to
// start") over the row's top edge for 1.8s. The row was drawn whole only
// while it shook (.hit, 0.45s): after that content-visibility: auto, which
// paint-contains, cut the tag's top ~10px off until it faded (yuancjun on
// Discord, Chrome 128 on macOS, v0.1.2784, who found the cause). The tag is
// whole for as long as it shows, and while it fades. Motion is on here, as
// the shake has to end for the cut to show. English, Chinese (both),
// Japanese and German; 1100 and 420 wide; 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 iso = (ms) => new Date(ms).toISOString();
const acct = { id: "relay-1", provider: "relay", name: "Relay", who: "key-1", kind: "account", model: "glm-5", known: true, used: 10 };
const other = { id: "relay-2", provider: "relay", name: "Relay", who: "key-2", kind: "account", model: "glm-5", known: true, used: 20 };
function serve(lang) {
const state = { agents: [{ id: "codex", name: "Codex", path: "/test/codex", fields: [] }], profiles: [], settings: { lang, theme: "light" } };
const t0 = Date.now();
const base = { id: 1, time: iso(t0), agent: "codex", model: acct.model, provider: acct.provider, order: [other, acct] };
// under way at the second account, then failed there: the answer, so
// no one is asked again
const going = { ...base, seq: 2, tries: [{ id: acct.id, model: acct.model, start: iso(t0) }], done: false };
const failed = { ...base, seq: 3, tries: [{ id: acct.id, model: acct.model, start: iso(t0), done: true, status: 504, ms: 1200, fail: "slow", error: "no first token" }], done: true, status: 504, error: "no first token", ms: 1200 };
return async (route) => {
const url = new URL(route.request().url());
const json = (data) => route.fulfill({ json: data }).catch(() => {});
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(state);
if (url.pathname === "/api/plugins") return json({ plugins: [] });
if (url.pathname === "/api/gateway/trace") {
const after = Number(url.searchParams.get("after") || 0);
const now = () => new Date().toISOString();
if (!url.searchParams.get("wait")) return json({ mine: true, now: now(), seq: 1, totals: { requests: 0, rerouted: 0, errors: 0 }, routes: [] });
if (after < 2) { await new Promise((r) => setTimeout(r, 300)); return json({ mine: true, now: now(), seq: 2, totals: { requests: 1, rerouted: 0, errors: 0 }, routes: [going] }); }
if (after < 3) { await new Promise((r) => setTimeout(r, 1500)); return json({ mine: true, now: now(), seq: 3, totals: { requests: 1, rerouted: 0, errors: 1 }, routes: [failed] }); }
await new Promise((r) => setTimeout(r, 20e3));
return json({ mine: true, now: now(), seq: 3, totals: { requests: 1, rerouted: 0, errors: 1 }, routes: [] });
}
if (url.pathname === "/api/gateway/history") return json({ cut: false, days: [], routes: [] });
if (url.pathname === "/api/groups") return json({ models: [], groups: [], pools: [] });
if (url.pathname === "/api/providers") return json({ providers: [], 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)];
await route.fulfill({ body: await fs.readFile(file), contentType });
};
}
// the share of the tag's band over the row's top edge that is painted in
// the tag's own red: the band is screenshotted and read back in the page
async function redOverEdge(page) {
const box = await page.evaluate(() => {
const li = document.querySelector(".rt-accts li.tagged");
const tag = li.querySelector(".tag"), t = tag.getBoundingClientRect(), l = li.getBoundingClientRect();
return { x: t.left + 3, y: t.top + 1, width: t.width - 6, height: l.top - t.top - 2, bg: getComputedStyle(tag).backgroundColor };
});
assert(box.height >= 4, `the tag stands over the row's top edge: ${JSON.stringify(box)}`);
const png = await page.screenshot({ clip: { x: box.x, y: box.y, width: box.width, height: box.height } });
return page.evaluate(async ([src, bg]) => {
const img = new Image();
img.src = src;
await img.decode();
const c = document.createElement("canvas");
c.width = img.naturalWidth; c.height = img.naturalHeight;
const g = c.getContext("2d");
g.drawImage(img, 0, 0);
// the tag's red as a canvas paints it, whatever colour space it was given in
g.fillStyle = bg; g.fillRect(0, 0, 1, 1);
const want = g.getImageData(0, 0, 1, 1).data;
g.drawImage(img, 0, 0);
const px = g.getImageData(0, 0, c.width, c.height).data;
let red = 0;
for (let i = 0; i < px.length; i += 4) if (Math.abs(px[i] - want[0]) + Math.abs(px[i + 1] - want[1]) + Math.abs(px[i + 2] - want[2]) < 60) red++;
return red / (px.length / 4);
}, ["data:image/png;base64," + png.toString("base64"), box.bg]);
}
const engines = process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"];
const langs = ["en", "zh", "zh-TW", "ja", "de"];
const widths = [1100, 420];
for (const engine of engines) for (const lang of langs) for (const width of widths) {
test(`${engine} ${lang} ${width}px: a failed try's tag over its row stays whole until it fades`, async (t) => {
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
const context = await browser.newContext({ viewport: { width, height: 800 } });
const page = await context.newPage();
page.setDefaultTimeout(8000);
page.setDefaultNavigationTimeout(60000);
const errors = [];
page.on("pageerror", (e) => errors.push(e.message));
await page.route("**/*", serve(lang));
t.after(async () => {
if (process.env.ARTIFACT_DIR) {
await fs.mkdir(process.env.ARTIFACT_DIR, { recursive: true });
await page.screenshot({ path: path.join(process.env.ARTIFACT_DIR, `${engine}-${lang}-${width}-tag-whole.png`) });
}
await browser.close();
});
await page.goto("http://magpie.test/?view=routing");
await page.locator(".rt-accts li.tagged").waitFor({ timeout: 15000 });
const word = await page.evaluate((lang) => (lang !== "en" && I18N[lang]?.["slow to start"]) || "slow to start", lang);
assert.equal(await page.locator(".rt-accts li.tagged .tag").textContent(), `504 · ${word}`);
// the shake is over (0.45s), the tag up for 1.8s: whole
await page.waitForFunction(() => document.querySelector(".rt-accts li.tagged:not(.hit)"));
await page.waitForTimeout(350);
assert(await page.locator(".rt-accts li.tagged").count(), "the tag is still up");
assert.equal(await page.locator(".rt-accts li.tagged").evaluate((li) => getComputedStyle(li).contentVisibility), "visible", "a tagged row is drawn whole");
const red = await redOverEdge(page);
assert(red > 0.5, `the tag's top over the row's edge is drawn: ${(red * 100).toFixed(0)}% of it red`);
// taken down: drawn whole while it fades, then cut back to sight
await page.waitForFunction(() => !document.querySelector(".rt-accts li.tagged"));
const fading = await page.locator(".rt-accts li.lift").evaluateAll((lis) => lis.map((li) => getComputedStyle(li).contentVisibility));
assert.deepEqual(fading, ["visible"], "the row the tag fades over is drawn whole");
await page.waitForFunction(() => !document.querySelector(".rt-accts li.lift"));
const rows = await page.locator(".rt-accts > li:not(.rt-gap)").evaluateAll((lis) => lis.map((li) => getComputedStyle(li).contentVisibility));
assert(rows.length >= 2 && rows.every((v) => v === "auto"), `rows out of sight are skipped again: ${rows}`);
assert.deepEqual(errors, []);
});
}