夜松云 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.
177 lines
11 KiB
JavaScript
177 lines
11 KiB
JavaScript
// Run with Node's test runner and Playwright on the module path; see README.md.
|
|
// The speed of a call read from a session file, on the Usage page's Requests
|
|
// tab. Claude Code's session file has no first token, only when the line that
|
|
// asked for a reply and the reply's last line were written, so its rows had
|
|
// no speed at all, and each said "Not streamed", though the replies were
|
|
// streamed. A long one now tells the least it wrote at, its tokens over that
|
|
// whole time ("≥98 tok/s"); a short one says the file has no first token; a
|
|
// call magpie timed keeps its own speed. Claude Code's, Claude Desktop's
|
|
// and Codex's files tell one: a Codex call in a turn of several is timed
|
|
// from what asked for it, before its first output item, to its last
|
|
// (Fallmonkey on Discord). A narrow window shows it as a wide one does. The rows are real ledger rows read
|
|
// from Claude Code's session files of claude-opus-5-5 replies; the first,
|
|
// 2,558 tokens in 25,987 ms, measured 100.6 tok/s on Claude Code's own stream
|
|
// (--include-partial-messages) from its first thinking event to its end.
|
|
// 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 reader = require("./reader.cjs");
|
|
|
|
const assets = path.resolve(__dirname, "../assets");
|
|
const now = Date.now();
|
|
const at = (i) => new Date(now - (i + 1) * 60e3).toISOString();
|
|
|
|
const LOG = {
|
|
agent: "claude", provider: "session-unknown", model: "claude-opus-5-5", req: "claude-opus-5-5", served: "claude-opus-5-5",
|
|
in: 2, cache_read: 12380, cache_write: 20122, effort: "medium", status: 0, session: "57956f49-8830-4769-a6c3-93ff87b1fe16",
|
|
cost: 0, priced: false, source: "log", agentName: "Claude Code", icon: "claudecode-color", providerName: "Local session",
|
|
};
|
|
const GATEWAY = {
|
|
route_id: 900, agent: "claude", agentName: "Claude Code", icon: "claudecode-color", provider: "zai", providerName: "Z.ai Coding Plan",
|
|
host: "me@example.com", req: "claude-opus-4-1-20250805", model: "glm-fast", served: "glm-fast", in: 1200, cache_read: 0, cache_write: 0,
|
|
status: 200, rid: "req_900", ep: "/v1/messages", cost: 0.01, priced: true,
|
|
};
|
|
const ROWS = [
|
|
// 0: a long reply from a session file: at least 2558 / 25.987 s
|
|
{ ...LOG, t: at(0), out: 2558, ms: 25987 },
|
|
// 1: a short one: its tokens over the wait tell too little
|
|
{ ...LOG, t: at(1), out: 462, ms: 5340 },
|
|
// 2: a call magpie timed keeps its own speed: 135 tokens in 1.8 s after its first
|
|
{ ...GATEWAY, t: at(2), out: 135, ms: 2400, ttft_ms: 600 },
|
|
// 3: a gateway call not streamed is still told so, with the least it
|
|
// wrote at over its whole time: 1500 tokens in 3 s (夜松云 on Discord)
|
|
{ ...GATEWAY, route_id: 901, rid: "req_901", t: at(3), out: 1500, ms: 3000 },
|
|
// 4: a session file that timed its turn (Codex's, one call) tells its own: 1200 tokens in 8 s
|
|
{ ...LOG, agent: "codex", agentName: "Codex", icon: "codex-color", model: "gpt-6-astra", t: at(4), out: 1200, ms: 10000, ttft_ms: 2000 },
|
|
// 5: a failed call tells none
|
|
{ ...LOG, t: at(5), out: 1500, ms: 9000, err_type: "overloaded_error", err: "Overloaded" },
|
|
// 6: a long reply in under a second (lines written together) tells none
|
|
{ ...LOG, t: at(6), out: 5000, ms: 300 },
|
|
// 7: a Codex call in a turn of several, timed from what asked for it: at
|
|
// least 1500 tokens in 60 s
|
|
{ ...LOG, agent: "codex", agentName: "Codex", icon: "codex-color", model: "gpt-6-astra", t: at(7), out: 1500, ms: 60000 },
|
|
// 8: Claude Desktop's Code tab writes Claude Code's file: at least 1500 / 12 s
|
|
{ ...LOG, agent: "claude-desktop", agentName: "Claude Desktop", icon: "claude-color", t: at(8), out: 1500, ms: 12000 },
|
|
];
|
|
|
|
function ledger(period) {
|
|
return {
|
|
period, rows: ROWS, offset: 0, total: ROWS.length, calls: ROWS.length, errors: 1,
|
|
input: 1, output: 12355, cache_read: 0, cache_write: 0, cost: 0.02, unpriced: 5,
|
|
// only what magpie timed: 135 tokens in 1.8 s and 1200 in 8 s
|
|
timed: 2, ttft_ms: 2600, decode_ms: 9800, decode_out: 1335,
|
|
by: { model: [] }, bucket: "hour", series: [],
|
|
agents: [{ id: "claude", name: "Claude Code", icon: "claudecode-color" }, { id: "codex", name: "Codex", icon: "codex-color" }, { id: "claude-desktop", name: "Claude Desktop", icon: "claude-color" }],
|
|
};
|
|
}
|
|
|
|
const STATE = (lang) => ({
|
|
agents: [
|
|
{ id: "claude", name: "Claude Code", path: "/t/c.json", icon: "claudecode-color", wired: true, fields: [] },
|
|
{ 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: {
|
|
speed: "Speed", gatewayFloor: "≥500 tok/s", floor: "≥98 tok/s", desktop: "≥125 tok/s", codexFloor: "≥25 tok/s", timed: "75 tok/s", codex: "150 tok/s",
|
|
floorTip: "At least: 2,558 output tokens in 26 s, from the line that asked for it to its last. The session file has no first token, so the wait for it is counted too",
|
|
noFirst: "The session file has no first token to time a speed from", notStreamed: "Not streamed: no first token to time a speed from",
|
|
},
|
|
zh: {
|
|
speed: "速度", gatewayFloor: "≥500 token/秒", floor: "≥98 token/秒", desktop: "≥125 token/秒", codexFloor: "≥25 token/秒", timed: "75 token/秒", codex: "150 token/秒",
|
|
floorTip: "下限:从发出请求的那一行到最后一行,26 秒 输出 2,558 个 token。会话文件没有首字时间,等首字的时间也算在里面",
|
|
noFirst: "会话文件没有首字时间,算不出速度", notStreamed: "非流式:没有首字时间,算不出速度",
|
|
},
|
|
};
|
|
|
|
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
|
test(engine + ": the speed of a call read from a session file", 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());
|
|
// a wide window, and one narrow enough that the table scrolls sideways
|
|
for (const [lang, width] of [["en", 1400], ["zh", 1400], ["en", 560], ["zh", 560]]) {
|
|
const w = L[lang];
|
|
await t.test(lang + " " + width, async () => {
|
|
const errors = [];
|
|
const ctx = await browser.newContext({ viewport: { width, 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 heads = await p.locator(".led thead th").evaluateAll((ths) => ths.filter((th) => th.offsetParent).map((th) => th.textContent));
|
|
assert(heads.includes(w.speed), "a Speed column: " + heads.join(", "));
|
|
const cell = (i) => p.locator(".led tbody tr.led-row").nth(i).locator("td.speed");
|
|
const text = async (i) => (await cell(i).textContent()).trim();
|
|
const tip = (i) => cell(i).getAttribute("title");
|
|
|
|
// a long reply from a session file: the least it wrote at, and why
|
|
assert.equal(await text(0), w.floor);
|
|
assert.equal(await tip(0), w.floorTip);
|
|
assert(!(await cell(0).getAttribute("class")).includes("faint"), "a floor isn't faint");
|
|
// a short one: no speed, and not called "not streamed"
|
|
assert.equal(await text(1), "—");
|
|
assert.equal(await tip(1), w.noFirst);
|
|
// what magpie timed is as it was
|
|
assert.equal(await text(2), w.timed);
|
|
assert.equal(await text(3), w.gatewayFloor);
|
|
assert((await tip(3)).includes(w.notStreamed), await tip(3));
|
|
// a session file's own timing wins over the floor
|
|
assert.equal(await text(4), w.codex);
|
|
// a failed call, and a reply in under a second, tell none
|
|
assert.equal(await text(5), "—");
|
|
assert.equal(await text(6), "—");
|
|
// a Codex call in a turn of several tells its floor too
|
|
assert.equal(await text(7), w.codexFloor);
|
|
// Claude Desktop's file is Claude Code's
|
|
assert.equal(await text(8), w.desktop);
|
|
// the floor is read whole, at either width
|
|
const clipped = await cell(0).evaluate((td) => td.scrollWidth > td.clientWidth + 1);
|
|
assert(!clipped, "the floor fits its cell");
|
|
|
|
// the row's details say it too
|
|
// the first cell, not the time's link: at a narrow window the row is brought into sight first
|
|
await reader.click(p, p.locator(".led tbody tr.led-row").first().locator("td").nth(1));
|
|
const detail = p.locator(".led tbody tr.led-detail").first();
|
|
await detail.waitFor();
|
|
const pairs = await detail.locator("dt").evaluateAll((dts) => dts.map((dt) => [dt.textContent, dt.nextElementSibling?.textContent]));
|
|
assert.deepEqual(pairs.find(([k]) => k === w.speed), [w.speed, w.floor], JSON.stringify(pairs));
|
|
|
|
assert.deepEqual(errors, []);
|
|
await ctx.close();
|
|
});
|
|
}
|
|
});
|
|
}
|