夜松云 on Discord: the Requests tab's Speed column was blank for some rows
and not others, with nothing saying why.
What changed (internal/gui/assets/plugins/usage/page.js, i18n.js):
- A gateway call with no speed of its own now tells the least it wrote at,
as a "≥" floor, the way a session file's call already did: one that
reasoned with no first text recorded (a tool call after hidden
reasoning) its answer tokens over the time after its first token,
unless the content came in a burst; else one not streamed or not timed,
its output over its whole time, by the same 1,000-token rule. The
tooltip says which floor it is and why it is only a floor. The
request's detail sheet (the other caller of ledFloorSpeed) shows the
same floor. The period's speed KPI is unchanged: it never counts a
gateway floor.
- A dash that is left always has a tooltip saying why (ledNoSpeed_):
failed, no duration, no output, not streamed / no first token, all
reasoning, too little after the first token, or let go in one burst.
- Eight new strings with zh, zh-TW, ja and de.
- reasoning-speed and usage-session-speed now expect the floor on the
rows that showed a dash before (reasoning then tool calls only: ≥100;
not streamed: ≥500).
Guarded by internal/gui/tests/usage-speed-every-row.test.cjs (rows shaped
as real usage.jsonl gateway rows, en and zh, both engines).
Broken by hand:
- page.js put back to its base: usage-speed-every-row 0/6 pass ("row 2's
dash says why").
- Only the gateway floors off (ledFloor_ returns null for a gateway row):
0/3 in Chromium.
Record for this push: 13 commits on origin/main ca4a1cde0, head tree
539c84e92. Go 1.26.8, sandbox HOME, GOMODCACHE/GOCACHE pinned. The full Go
run and vet were at tree d6393dfc8, the same Go code as this head: only
app.js comments (cut under the core script budget) and one ja string
changed after it.
- gofmt -l: nothing. go build ./...; go vet ./... (darwin), GOOS=linux
go vet -tags nogui ./..., GOOS=windows go vet ./...: clean.
- go test -timeout 45m ./..., through tee, one suite on the machine:
68 packages ok. The one red was internal/gui's
TestCoreScriptBudget: app.js 1,335,314 > 1,335,000, since main grew
app.js under the stack. The autoscroll commit's own comments were cut
(to 1,334,629) rather than the budget raised, and go test -count=1
./internal/gui is ok at this head (113s). Packages the run took from
Go's test cache had the same inputs.
- GUI: the 18 files this stack touches or names, both engines,
202 of 204 pass (tree 068acf128, this push less the last commit). The
two reds: gui-ja, red on main since c2636b7b5 and fixed by this push's
last commit (gui-ja and i18n-keys 6 of 6 there), and usage-fold's
chromium "several accounts" (#2163, red on main the same way).
- usage-speed-every-row, reasoning-speed and usage-session-speed pass,
both engines; i18n-keys and gui-zh-tw/ja/de too.
- The Requests tab's other file, usage-ledger, is red alone on main the
same way (#3104, the return-to-live button).
The whole GUI suite ran at 1c1fc7183 (this stack's first 12 commits on
0ddcf28a1): 11713 of 11769 pass. Each of the 21 red files was then run
alone at the stack and at origin/main 8278fd9b0. Eight are red the same
way on main: plugin-card-update (#3079), quota-count-wrap and
quota-name-translated (#2228), s3-sync (#2448), usage-agents-hide
(#2276), usage-checkin (#3091), usage-fold's chromium "several
accounts" (#2163), usage-ledger (#3104). The other 13 pass alone on both
and were red only under that run's load (50 to 335): currency #3101,
plugin-github #3218, provider-fetch-again #3292, rest-try-now #2564,
routing-auto-reset #3293, routing-keys-fold #1612, routing-steady #1804,
routing-wb-restricted #1905, sessions-folder-delete #2218,
sessions-manage #3294, switch-only #3295, text-size #1866, usage-pack
#3296.
Not tried: the real app against a real usage.jsonl with such rows; only
the faked API in the tests.
171 lines
10 KiB
JavaScript
171 lines
10 KiB
JavaScript
// Run with Node's test runner and Playwright on the module path; see README.md.
|
||
// Every row of the Usage page's Requests tab says a speed, or says why it
|
||
// has none (夜松云 on Discord: "the speed shows for some rows and not for
|
||
// others"). A gateway call with no speed of its own tells the least it wrote
|
||
// at when that is known: one not streamed, its output over its whole time
|
||
// (1,000 tokens or more over a second or more), and one that reasoned with
|
||
// no first text recorded, its answer over the time after its first token.
|
||
// A dash left has a tooltip that says why: failed, no output, not streamed,
|
||
// all reasoning, too little after the first token, or let go in a burst.
|
||
// The rows are shaped as real gateway ledger rows (usage.jsonl). English and
|
||
// Chinese; no backend, the API is faked.
|
||
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 = Date.now();
|
||
const at = (i) => new Date(now - (i + 1) * 60e3).toISOString();
|
||
|
||
const GW = {
|
||
agent: "codex", agentName: "Codex", icon: "codex-color", provider: "codex", providerName: "Codex", host: "me@example.com",
|
||
req: "codex/gpt-6-sol", model: "gpt-6-sol", served: "gpt-6-sol", in: 2653, cache_read: 31232, cache_write: 0,
|
||
status: 200, ep: "/backend-api/codex/responses", stop: "completed", cost: 0.01, priced: true,
|
||
};
|
||
const ROWS = [
|
||
// 0: a chat call not streamed to the agent: 3,832 tokens in 31 s
|
||
{ ...GW, route_id: 1, t: at(0), provider: "antigravity", model: "gemini-3.8-flash-tiered", served: "gemini-3.8-flash-tiered", req: "antigravity/gemini-3.8-flash-tiered", out: 3832, reasoning: 3830, ms: 31006, ep: "/v1/chat/completions → /v1internal:streamGenerateContent?alt=sse" },
|
||
// 1: a short one not streamed: too little over its whole time
|
||
{ ...GW, route_id: 2, t: at(1), provider: "deepseek", model: "deepseek-flash", served: "deepseek-flash", req: "deepseek/deepseek-flash", out: 105, reasoning: 103, ms: 6683, ep: "/v1/chat/completions" },
|
||
// 2: hidden reasoning then a 6-token tool call 87 ms after the first token
|
||
{ ...GW, route_id: 3, t: at(2), out: 47, reasoning: 41, ms: 6788, ttft_ms: 6701, reasoning_hidden: true, flow_ms: 1 },
|
||
// 3: its answer let go in one burst at its end
|
||
{ ...GW, route_id: 4, t: at(3), out: 61, reasoning: 16, ms: 5606, ttft_ms: 5436, first_text_ms: 5467, reasoning_hidden: true, flow_ms: 1 },
|
||
// 4: the agent went away
|
||
{ ...GW, route_id: 5, t: at(4), out: 0, ms: 13748, ttft_ms: 5851, first_text_ms: 5858, status: 499, err: "the agent canceled the request", cost: 0, priced: false },
|
||
// 5: answered with no tokens
|
||
{ ...GW, route_id: 6, t: at(5), provider: "qoder", model: "efficient", served: "efficient", req: "qoder/efficient", in: 0, out: 0, ms: 5388, ep: "/v1/chat/completions" },
|
||
// 6: hidden reasoning, then a 1,000-token tool call over the 10 s after the first token
|
||
{ ...GW, route_id: 7, t: at(6), out: 1300, reasoning: 300, ms: 16000, ttft_ms: 6000, reasoning_hidden: true, flow_ms: 9000 },
|
||
// 7: reasoning and nothing after it
|
||
{ ...GW, route_id: 8, t: at(7), out: 41, reasoning: 41, ms: 6000, ttft_ms: 5000, reasoning_hidden: true, flow_ms: 1 },
|
||
// 8: measured: 500 tokens in the 5 s after its first
|
||
{ ...GW, route_id: 9, t: at(8), out: 500, ms: 7000, ttft_ms: 2000, first_text_ms: 2000, flow_ms: 5000 },
|
||
];
|
||
|
||
function ledger(period) {
|
||
return {
|
||
period, rows: ROWS, offset: 0, total: ROWS.length, calls: ROWS.length, errors: 1,
|
||
input: 1, output: 1, cache_read: 0, cache_write: 0, cost: 0.02, unpriced: 0,
|
||
timed: 1, ttft_ms: 2000, decode_ms: 5000, decode_out: 500, decode_n: 1,
|
||
by: { model: [] }, bucket: "hour", series: [],
|
||
agents: [{ id: "codex", name: "Codex", icon: "codex-color" }],
|
||
};
|
||
}
|
||
|
||
const STATE = (lang) => ({
|
||
agents: [{ id: "codex", name: "Codex", path: "/t/c.toml", icon: "codex-color", wired: true, fields: [] }],
|
||
profiles: [], settings: { lang, theme: "light" }, fx: { rate: 7.2, at: new Date().toISOString() },
|
||
});
|
||
|
||
function server(lang) {
|
||
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:false};` });
|
||
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
|
||
if (url.pathname === "/api/state") return json(STATE(lang));
|
||
if (url.pathname === "/api/usage/requests") return json(ledger(url.searchParams.get("period")));
|
||
if (url.pathname === "/api/usage/quotas") return json([]);
|
||
if (url.pathname === "/api/usage") return json({ calls: 0, errors: 0, input: 0, output: 0, reasoning: 0, unpriced: 0, cost: 0, bucket: "day", series: [], agents: [], models: [], path: "" });
|
||
if (url.pathname === "/api/providers") return json({ providers: [], presets: [], excluded: [], models: [], gateway: { running: false } });
|
||
if (url.pathname === "/api/sessions") return json({ sessions: [], dirs: [] });
|
||
if (url.pathname === "/api/sessions/stats") return json({ from: "", to: "", days: [], agents: {} });
|
||
if (url.pathname === "/api/groups") return json({ groups: [], models: [] });
|
||
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 });
|
||
};
|
||
}
|
||
|
||
const L = {
|
||
en: {
|
||
whole: "≥124 tok/s", answer: "≥100 tok/s", measured: "100 tok/s",
|
||
wholeTip: "At least: 3,832 output tokens in 31 s, from the request to its last token, the wait for the first one counted too",
|
||
notStreamed: "Not streamed: no first token to time a speed from",
|
||
answerTip: "At least: 1,000 answer tokens in 10 s after the first token, the 300 reasoning tokens left out. No first text was recorded",
|
||
little: "Too little came after the first token to time a speed by: 6 tokens in 87 ms",
|
||
burst: "It came in one burst at its end, not as it was written, so how fast it was written isn't seen",
|
||
failed: "A failed request tells no speed",
|
||
noOut: "No output tokens to time a speed from",
|
||
allReasoning: "All its output was reasoning: no answer after it to time a speed from",
|
||
},
|
||
zh: {
|
||
whole: "≥124 token/秒", answer: "≥100 token/秒", measured: "100 token/秒",
|
||
wholeTip: "下限:从收到请求到最后一个 token,31 秒 输出 3,832 个 token,等首字的时间也算在里面",
|
||
notStreamed: "非流式:没有首字时间,算不出速度",
|
||
answerTip: "下限:首字后 10 秒 输出 1,000 个正文 token,300 个推理 token 不计。没有记录首个正文的时间",
|
||
little: "首字后内容太少,测不出速度:87 毫秒 输出 6 个 token",
|
||
burst: "内容在最后一次性到达,不是边写边发,看不出写得多快",
|
||
failed: "失败的请求没有速度",
|
||
noOut: "没有输出 token,算不出速度",
|
||
allReasoning: "输出全是推理,之后没有正文,算不出速度",
|
||
},
|
||
};
|
||
|
||
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
||
test(engine + ": every request says its speed or why it has none", async (t) => {
|
||
assert(["chromium", "webkit"].includes(engine), "BROWSER must be chromium or webkit");
|
||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
||
t.after(() => browser.close());
|
||
for (const lang of ["en", "zh"]) {
|
||
const w = L[lang];
|
||
await t.test(lang, async () => {
|
||
const errors = [];
|
||
const ctx = await browser.newContext({ viewport: { width: 1400, height: 900 }, reducedMotion: "reduce" });
|
||
const p = await ctx.newPage();
|
||
p.setDefaultTimeout(5000);
|
||
p.on("pageerror", (e) => errors.push(e.message));
|
||
await p.route("**/*", server(lang));
|
||
await p.goto("http://magpie.test/");
|
||
await p.locator('[data-view="usage"]').first().click();
|
||
await p.locator(":is(#usageTab .opt, .nav-s):visible").nth(1).click();
|
||
await p.locator("#ledWrap .led tbody tr").first().waitFor();
|
||
|
||
const cells = p.locator(".led tbody tr.led-row td.speed");
|
||
assert.equal(await cells.count(), ROWS.length);
|
||
const text = async (i) => (await cells.nth(i).textContent()).trim();
|
||
const tip = async (i) => (await cells.nth(i).getAttribute("title")) || "";
|
||
|
||
// no row is left blank: a figure, or a dash that says why
|
||
for (let i = 0; i < ROWS.length; i++) {
|
||
const s = await text(i);
|
||
assert(s, "row " + i + " has a speed or a dash");
|
||
if (s === "—") assert((await tip(i)).length > 0, "row " + i + "'s dash says why");
|
||
}
|
||
|
||
// not streamed, long enough: the least it wrote at, and why it's a floor
|
||
assert.equal(await text(0), w.whole);
|
||
assert((await tip(0)).startsWith(w.wholeTip), await tip(0));
|
||
assert((await tip(0)).includes(w.notStreamed), await tip(0));
|
||
// not streamed, too short for a floor
|
||
assert.equal(await text(1), "—");
|
||
assert.equal(await tip(1), w.notStreamed);
|
||
// 6 tokens 87 ms after the first
|
||
assert.equal(await text(2), "—");
|
||
assert.equal(await tip(2), w.little);
|
||
// a burst
|
||
assert.equal(await text(3), "—");
|
||
assert.equal(await tip(3), w.burst);
|
||
// failed, and no output
|
||
assert.equal(await tip(4), w.failed);
|
||
assert.equal(await tip(5), w.noOut);
|
||
// the answer after hidden reasoning, no first text recorded
|
||
assert.equal(await text(6), w.answer);
|
||
assert((await tip(6)).startsWith(w.answerTip), await tip(6));
|
||
// reasoning only
|
||
assert.equal(await text(7), "—");
|
||
assert.equal(await tip(7), w.allReasoning);
|
||
// what was measured is as it was
|
||
assert.equal(await text(8), w.measured);
|
||
|
||
assert.deepEqual(errors, []);
|
||
await ctx.close();
|
||
});
|
||
}
|
||
});
|
||
}
|