From 50eec4994a4dfa3e85e187ded2bfdc94fbac3cf9 Mon Sep 17 00:00:00 2001 From: yetone Date: Sun, 8 Nov 2026 21:53:44 +0800 Subject: [PATCH] routing: with motion reduced, a request in flight fades instead of standing still MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit vantiboolean (Discord, v0.1.3327, Windows app): the Routing page "lost its animation". The screenshot: Codex, round-robin, two accounts both "answering another request…", the wires dotted and nothing moving, no bird. That is the page with motion reduced. WebView2 reports prefers-reduced-motion when Windows' "Animation effects" is off, and Settings' Reduce motion does the same in the page. Then the flowing wires' dashes, the held dot's fade and the bird all stood still, so a request in flight looked the same as one that was over. This was so before 83d9ee892 too (its CSS turned the same animations off under reduce); the timer that commit added kept that. Without reduced motion the page moves in Playwright Chromium on mote and on xiaomi-gpu, and in the msedge channel (Edg/156) there, in the reporter's state (two requests in flight, the request shown another one), after a page switch, a blur and a focus. Now the 15/s timer also runs with motion reduced, without moving anything: the flows layer fades to .45 and back each 1.2s (--rt-fade, opacity on its own composited layer) while the dashes stay put, and the dot held at an answering account fades as it does with motion on. No bird flies. When nothing is in flight the timer stops and both properties go, as before. Run: - routing-calm-in-flight.test.cjs (new): Chromium and WebKit, the system's reduce and Settings' Reduce motion, 1100 and 420px, on mote: 8 of 8 ok. On xiaomi-gpu (Windows 11, Chromium): 4 of 4 ok. - routing-answered-still.test.cjs, both engines: ok (with the new file, 28 of 28). - Broken by hand: the new test on the old client.js and routing.css is red in all 8 ("the flowing wires fade: 1.00"). - GUI on mote, at this tree with the balance commit after it: the 293 routing-*, usage-*, balance-*, quota-*, panel-usage, tray-usage*, key-balance*, key-own-balance, i18n-keys, old-webkit and click-scroll files, Chromium and WebKit, concurrency 4 beside other sessions' suites: 4846 of 4900 ok. The 54 reds are in routing-intent-entry (#5392), routing-context-fold WebKit (#5586), i18n-keys "a plugin's words are its own" (#5327), routing-row-swap (#3799), routing-story-shrinks WebKit (#3954), usage-agents-hide (#3414), usage-fold (#3415), usage-ledger (#5048) and, under load only, usage-computers and remote-group-served. Each of the first eight is red the same at origin/main b684308c6 run alone (32 files compared, identical lists, serial for the six usage/routing ones). - go vet (darwin, GOOS=linux -tags nogui, GOOS=windows) of internal/gui and internal/provider, gofmt -l clean, go test -tags nogui -count=1 ./internal/provider ./internal/gui under mote's suite lock: ok. Not tried: the whole GUI suite (1287 files; the run above covers the files that reach Routing and Usage); WebView2 inside the real Wails app on Windows with Animation effects off (xiaomi-gpu is shared, its system setting was left alone); the reporter has not said which reduce is on. The tray panel's own small stage still stands still with motion reduced (#5708). Reported-by: vantiboolean (Discord) --- internal/gui/assets/plugins/routing/client.js | 22 +++- .../gui/assets/plugins/routing/routing.css | 5 +- .../gui/tests/routing-calm-in-flight.test.cjs | 114 ++++++++++++++++++ 3 files changed, 133 insertions(+), 8 deletions(-) create mode 100644 internal/gui/tests/routing-calm-in-flight.test.cjs diff --git a/internal/gui/assets/plugins/routing/client.js b/internal/gui/assets/plugins/routing/client.js index d7f20bceb..ccb9044b9 100644 --- a/internal/gui/assets/plugins/routing/client.js +++ b/internal/gui/assets/plugins/routing/client.js @@ -1952,20 +1952,30 @@ function routingPage(part) { // and each flowing wire spans the stage. With five requests in flight // the Routing page took a quarter of a core and more in WebView2 // (chenxiang, #5467). The timer runs only while a wire flows or a dot - // is held, in sight and with motion on. + // is held and in sight. With motion reduced (the system's or Settings') + // nothing moves, but what is in flight still shows: the flowing wires + // fade to .45 and back each 1.2s instead (--rt-fade on flows), and the + // held dot fades as it does with motion on. Standing still, a request + // in flight read as one over, and the Windows app's Routing page as + // having lost its animation (vantiboolean). const SLOW_EVERY = 1000 / 15; let slowTimer = 0; - const slowNeeded = () => (flowing.size > 0 || holds.size > 0) && shown() && !still(); + const slowNeeded = () => (flowing.size > 0 || holds.size > 0) && shown(); function slowTick() { if (!slowNeeded()) { // stopped where it was, a dot held on would stay faded and still clearInterval(slowTimer); slowTimer = 0; - flows.style.removeProperty("--rt-dash"); sky.style.removeProperty("--rt-held"); + for (const k of ["--rt-dash", "--rt-fade"]) flows.style.removeProperty(k); + sky.style.removeProperty("--rt-held"); return; } - const now_ = performance.now(); - if (flowing.size) flows.style.setProperty("--rt-dash", (-(now_ % 700) / 700 * 8).toFixed(2) + "px"); - if (holds.size) sky.style.setProperty("--rt-held", (1 - .55 * (1 - Math.cos(2 * Math.PI * (now_ % 1200) / 1200)) / 2).toFixed(3)); + const now_ = performance.now(), fade = (1 - .55 * (1 - Math.cos(2 * Math.PI * (now_ % 1200) / 1200)) / 2).toFixed(3); + if (flowing.size) { + const calm_ = still(); + flows.style.setProperty(calm_ ? "--rt-fade" : "--rt-dash", calm_ ? fade : (-(now_ % 700) / 700 * 8).toFixed(2) + "px"); + flows.style.removeProperty(calm_ ? "--rt-dash" : "--rt-fade"); + } + if (holds.size) sky.style.setProperty("--rt-held", fade); } function slowMove() { if (slowTimer || !slowNeeded()) return; diff --git a/internal/gui/assets/plugins/routing/routing.css b/internal/gui/assets/plugins/routing/routing.css index 4a1e839af..10b388b15 100644 --- a/internal/gui/assets/plugins/routing/routing.css +++ b/internal/gui/assets/plugins/routing/routing.css @@ -21,9 +21,10 @@ /* a flowing wire is drawn by its copy in .rt-flows, a layer of its own, so the wires that don't move aren't drawn again each frame (#3164) */ .rt-wires path.flown { visibility: hidden; animation: none; } -.rt-flows { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; will-change: transform; } +.rt-flows { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; will-change: transform; opacity: var(--rt-fade, 1); } /* its dashes move by --rt-dash, which a timer sets 15 times a second - (slowTick): an animated offset was drawn again every frame */ + (slowTick): an animated offset was drawn again every frame. With motion + reduced they stand still and the layer fades by --rt-fade instead */ .rt-flows path { fill: none; stroke: var(--agent, var(--muted)); stroke-width: 1.5; stroke-dasharray: 3 5; stroke-dashoffset: var(--rt-dash, 0); } @keyframes rtflow { to { stroke-dashoffset: -8; } } /* the magpies: one carries each request out, another brings its answer diff --git a/internal/gui/tests/routing-calm-in-flight.test.cjs b/internal/gui/tests/routing-calm-in-flight.test.cjs new file mode 100644 index 000000000..c1debb2b3 --- /dev/null +++ b/internal/gui/tests/routing-calm-in-flight.test.cjs @@ -0,0 +1,114 @@ +// Run with Node's test runner and Playwright on the module path; see README.md. +// With motion reduced, a request in flight still shows on the Routing page +// (vantiboolean on Discord: the Windows app's Routing page had "lost its +// animation", every wire dotted and still while two accounts answered). +// Reduced motion is the system's (Windows' "Animation effects" off, which +// WebView2 reports as prefers-reduced-motion) or Settings' Reduce motion. +// Nothing moves along a wire then, but the flowing wires fade and come +// back, and so does the dot held at the account answering. Once the +// request is over nothing fades. 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 M = "gpt-5.5"; +// the reporter's: one provider's two accounts, round-robin +const order = [1, 2].map((i) => ({ id: `codex#a${i}`, provider: "codex", name: "Codex", who: `codex-${i}`, kind: "account", model: M })); +const route = (id, tries) => ({ id, seq: id, time: ago(60 - id), agent: "codex", model: M, provider: "codex", done: tries.every((x) => x.done), + status: 200, ms: 900, tokens: 1200, order, tries }); +const at = (n, done) => ({ id: `codex#a${n}`, model: M, start: ago(5), done, ...(done ? { status: 200, ms: 900 } : {}) }); + +function serve(lang, settingsCalm, live) { + 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,reduceMotion:${settingsCalm}};` }); + 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", reduceMotion: settingsCalm } }); + if (url.pathname === "/api/gateway/trace") { + if (url.searchParams.get("wait")) { + if (live.queued.length) return json(live.queued.shift()); + live.pending.push(request); + return; + } + return json({ mine: true, now: now.toISOString(), seq: 1, totals: { requests: 1, rerouted: 0, errors: 0 }, routes: [route(1, [at(1, true)])] }); + } + 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 calm of ["system", "settings"]) { + for (const width of [1100, 420]) { + test(`${engine} ${calm} reduced motion ${width}px: a request in flight fades, nothing moves`, 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: calm === "system" ? "reduce" : "no-preference" }); + page.setDefaultTimeout(5000); + page.setDefaultNavigationTimeout(60000); + const errors = []; + page.on("pageerror", (error) => errors.push(error.message)); + const live = { pending: [], queued: [], seq: 1 }; + await page.route("**/*", serve("en", calm === "settings", live)); + const send = (...routes) => { + const d = { mine: true, now: new Date().toISOString(), seq: ++live.seq, totals: { requests: live.seq }, routes }; + const r = live.pending.shift(); + if (r) r.fulfill({ json: d }); else live.queued.push(d); + }; + await page.goto("http://magpie.test/?view=routing"); + await page.waitForFunction(() => document.querySelector(".rt-accts li.on em")?.textContent.trim()); + assert.equal(await page.evaluate(() => calm()), true, "motion is reduced"); + + // two requests at once, one at each account: the reporter's two + // rows "answering another request…" + send(route(2, [at(1, false)]), route(3, [at(2, false)])); + await page.waitForFunction(() => document.querySelectorAll(".rt-accts li.now").length === 2); + await page.waitForFunction(() => document.querySelectorAll(".rt-flows path[d]").length >= 2); + // the wires' dashes stand still: no animation and no offset + const dashes = () => page.evaluate(() => [...document.querySelectorAll(".rt-flows path[d]")].map((p) => getComputedStyle(p).animationName + "|" + getComputedStyle(p).strokeDashoffset).join()); + const first = await dashes(); + assert.doesNotMatch(first, /rtflow/); + // but the layer they are on fades and comes back + const layer = () => page.evaluate(() => Number(getComputedStyle(document.querySelector(".rt-flows")).opacity)); + const seen = new Set(); + for (let i = 0; i < 40 && seen.size < 3; i++) { seen.add((await layer()).toFixed(2)); await page.waitForTimeout(60); } + assert(seen.size >= 3, `the flowing wires fade: ${[...seen]}`); + assert(Math.min(...[...seen].map(Number)) < .95, `they fade below full: ${[...seen]}`); + assert.equal(await dashes(), first, "the dashes stood still"); + // the dot held at each account fades too + await page.waitForFunction(() => document.querySelector(".rt-sky .pkt.held"), null, { timeout: 15000 }); + const held = () => page.evaluate(() => getComputedStyle(document.querySelector(".rt-sky .pkt.held")).opacity); + const heldWas = await held(); + await page.waitForFunction((was) => getComputedStyle(document.querySelector(".rt-sky .pkt.held")).opacity !== was, heldWas); + // no bird flies with motion reduced + assert.equal(await page.locator(".rt-flier").count(), 0); + + // both are answered: nothing fades any more, the layer is whole + send(route(2, [at(1, true)]), route(3, [at(2, true)])); + await page.waitForFunction(() => !document.querySelector(".rt-accts li.now")); + await page.waitForFunction(() => !document.querySelector(".rt-flows path")); + await page.waitForFunction(() => !document.querySelector(".rt-flows").style.getPropertyValue("--rt-fade")); + assert.equal(await layer(), 1); + assert.equal(await page.evaluate(() => new Promise((res) => { + let n = 0; + const o = new MutationObserver(() => n++); + o.observe(document.querySelector(".rt-flows"), { attributes: true, attributeFilter: ["style"] }); + o.observe(document.querySelector(".rt-sky"), { attributes: true, attributeFilter: ["style"] }); + setTimeout(() => { o.disconnect(); res(n); }, 400); + })), 0, "the timer stopped"); + assert.deepEqual(errors, []); + }); + } + } +}