Skip to content

Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.

usage: every request on the Requests tab says its speed, or why it has none (夜松云 on Discord)

yetonef050818f71f8
diff --git a/internal/gui/assets/plugins/usage/i18n.js b/internal/gui/assets/plugins/usage/i18n.js
index d08e6a5c9..4c6455899 100644
--- a/internal/gui/assets/plugins/usage/i18n.js
+++ b/internal/gui/assets/plugins/usage/i18n.js
@@ -186,6 +186,14 @@ magpie.strings({
"The session file has no first token to time a speed from": "会话文件没有首字时间,算不出速度",
"{n} answer tokens in {ms} after the first text, the {r} reasoning tokens before it left out": "首个正文后 {ms} 输出 {n} 个正文 token,之前的 {r} 个推理 token 不计",
"Not streamed: no first token to time a speed from": "非流式:没有首字时间,算不出速度",
+ "A failed request tells no speed": "失败的请求没有速度",
+ "No duration was recorded to time a speed from": "没有记录耗时,算不出速度",
+ "No output tokens to time a speed from": "没有输出 token,算不出速度",
+ "All its output was reasoning: no answer after it to time a speed from": "输出全是推理,之后没有正文,算不出速度",
+ "Too little came after the first token to time a speed by: {n} tokens in {ms}": "首字后内容太少,测不出速度:{ms} 输出 {n} 个 token",
+ "It came in one burst at its end, not as it was written, so how fast it was written isn't seen": "内容在最后一次性到达,不是边写边发,看不出写得多快",
+ "At least: {n} answer tokens in {ms} after the first token, the {r} reasoning tokens left out. No first text was recorded, so reasoning after the first token is counted too": "下限:首字后 {ms} 输出 {n} 个正文 token,{r} 个推理 token 不计。没有记录首个正文的时间,首字后的推理时间也算在里面",
+ "At least: {n} output tokens in {ms}, from the request to its last token, the wait for the first one counted too": "下限:从收到请求到最后一个 token,{ms} 输出 {n} 个 token,等首字的时间也算在里面",
"{i} in · {o} out · {r} cache read · {w} cache creation": "输入 {i} · 输出 {o} · 缓存读取 {r} · 缓存创建 {w}",
"Upstream provider": "上游",
"The agent spoke {from}; sent upstream as {to}": "agent 用 {from} 协议请求;以 {to} 协议发往上游",
@@ -376,6 +384,14 @@ magpie.strings({
"The session file has no first token to time a speed from": "會話檔案沒有首字時間,算不出速度",
"{n} answer tokens in {ms} after the first text, the {r} reasoning tokens before it left out": "首個正文後 {ms} 輸出 {n} 個正文 token,之前的 {r} 個推理 token 不計",
"Not streamed: no first token to time a speed from": "非流式:沒有首字時間,算不出速度",
+ "A failed request tells no speed": "失敗的請求沒有速度",
+ "No duration was recorded to time a speed from": "沒有記錄耗時,算不出速度",
+ "No output tokens to time a speed from": "沒有輸出 token,算不出速度",
+ "All its output was reasoning: no answer after it to time a speed from": "輸出全是推理,之後沒有正文,算不出速度",
+ "Too little came after the first token to time a speed by: {n} tokens in {ms}": "首字後內容太少,測不出速度:{ms} 輸出 {n} 個 token",
+ "It came in one burst at its end, not as it was written, so how fast it was written isn't seen": "內容在最後一次性到達,不是邊寫邊發,看不出寫得多快",
+ "At least: {n} answer tokens in {ms} after the first token, the {r} reasoning tokens left out. No first text was recorded, so reasoning after the first token is counted too": "下限:首字後 {ms} 輸出 {n} 個正文 token,{r} 個推理 token 不計。沒有記錄首個正文的時間,首字後的推理時間也算在裡面",
+ "At least: {n} output tokens in {ms}, from the request to its last token, the wait for the first one counted too": "下限:從收到請求到最後一個 token,{ms} 輸出 {n} 個 token,等首字的時間也算在裡面",
"{i} in · {o} out · {r} cache read · {w} cache creation": "輸入 {i} · 輸出 {o} · 快取讀取 {r} · 快取建立 {w}",
"Upstream provider": "上游",
"The agent spoke {from}; sent upstream as {to}": "agent 用 {from} 協議請求;以 {to} 協議發往上游",
@@ -566,6 +582,14 @@ magpie.strings({
"The session file has no first token to time a speed from": "セッションファイルには、速度を計れる最初のトークンの時刻がありません",
"{n} answer tokens in {ms} after the first text, the {r} reasoning tokens before it left out": "最初の本文後 {ms} で回答 {n} トークン(その前の推論 {r} トークンは含めず)",
"Not streamed: no first token to time a speed from": "ストリーミングではないため、速度を計れる最初のトークンの時刻がありません",
+ "A failed request tells no speed": "失敗したリクエストには速度がありません",
+ "No duration was recorded to time a speed from": "所要時間が記録されていないため、速度を計れません",
+ "No output tokens to time a speed from": "出力トークンがないため、速度を計れません",
+ "All its output was reasoning: no answer after it to time a speed from": "出力はすべて推論で、その後に回答がないため、速度を計れません",
+ "Too little came after the first token to time a speed by: {n} tokens in {ms}": "最初のトークンの後が少なすぎて速度を計れません:{ms} で {n} トークン",
+ "It came in one burst at its end, not as it was written, so how fast it was written isn't seen": "最後に一度に届き、書かれたとおりに届いていないため、書く速さはわかりません",
+ "At least: {n} answer tokens in {ms} after the first token, the {r} reasoning tokens left out. No first text was recorded, so reasoning after the first token is counted too": "下限:最初のトークン後 {ms} で回答 {n} トークン(推論 {r} トークンは含めず)。最初の本文の時刻が記録されていないため、最初のトークン後の推論の時間も含まれます",
+ "At least: {n} output tokens in {ms}, from the request to its last token, the wait for the first one counted too": "下限:リクエストを受けてから最後のトークンまで {ms} で {n} トークンを出力。最初のトークンを待つ時間も含まれます",
"{i} in · {o} out · {r} cache read · {w} cache creation": "入力 {i} · 出力 {o} · キャッシュ読み取り {r} · キャッシュ作成 {w}",
"Upstream provider": "上流プロバイダー",
"The agent spoke {from}; sent upstream as {to}": "エージェントは {from} で要求し、上流へは {to} で送信",
@@ -756,6 +780,14 @@ magpie.strings({
"The session file has no first token to time a speed from": "Die Sitzungsdatei hat kein erstes Token, an dem sich ein Tempo messen ließe",
"{n} answer tokens in {ms} after the first text, the {r} reasoning tokens before it left out": "{n} Antwort-Token in {ms} nach dem ersten Text, ohne die {r} Reasoning-Token davor",
"Not streamed: no first token to time a speed from": "Nicht gestreamt: kein erstes Token, an dem sich ein Tempo messen ließe",
+ "A failed request tells no speed": "Eine fehlgeschlagene Anfrage hat kein Tempo",
+ "No duration was recorded to time a speed from": "Keine Dauer aufgezeichnet, an der sich ein Tempo messen ließe",
+ "No output tokens to time a speed from": "Keine Ausgabe-Token, an denen sich ein Tempo messen ließe",
+ "All its output was reasoning: no answer after it to time a speed from": "Die ganze Ausgabe war Reasoning: keine Antwort danach, an der sich ein Tempo messen ließe",
+ "Too little came after the first token to time a speed by: {n} tokens in {ms}": "Nach dem ersten Token kam zu wenig für ein Tempo: {n} Token in {ms}",
+ "It came in one burst at its end, not as it was written, so how fast it was written isn't seen": "Sie kam am Ende in einem Schwung, nicht so, wie sie geschrieben wurde, also ist nicht zu sehen, wie schnell sie geschrieben wurde",
+ "At least: {n} answer tokens in {ms} after the first token, the {r} reasoning tokens left out. No first text was recorded, so reasoning after the first token is counted too": "Mindestens: {n} Antwort-Token in {ms} nach dem ersten Token, ohne die {r} Reasoning-Token. Kein erster Text aufgezeichnet, also zählt Reasoning nach dem ersten Token mit",
+ "At least: {n} output tokens in {ms}, from the request to its last token, the wait for the first one counted too": "Mindestens: {n} Ausgabe-Token in {ms}, von der Anfrage bis zu ihrem letzten Token, das Warten auf das erste mitgezählt",
"{i} in · {o} out · {r} cache read · {w} cache creation": "{i} Eingabe · {o} Ausgabe · {r} Cache-Lesen · {w} Cache-Erstellung",
"Upstream provider": "Upstream-Anbieter",
"The agent spoke {from}; sent upstream as {to}": "Der Agent sprach {from}; an den Upstream als {to} gesendet",
diff --git a/internal/gui/assets/plugins/usage/page.js b/internal/gui/assets/plugins/usage/page.js
index 957589f6a..6e538ddd2 100644
--- a/internal/gui/assets/plugins/usage/page.js
+++ b/internal/gui/assets/plugins/usage/page.js
@@ -1426,7 +1426,8 @@ const ledRowSpeed = (r) => { const d = ledDecode(r); return d ? d.n / (d.w / 100
// stream it read 2–5% under for a reply of 1,400 tokens or more, 11–33% for
// a shorter one or one asked with a tool's result, so only a reply of 1,000
// or more is told. 0 when it tells none, and a call magpie timed tells its
-// own (ledDecode). Only the row's: the period's speed counts timed calls.
+// own (ledDecode). Only the row's: the period's speed counts timed calls
+// and session files' floors (usage.Row.Floor), not a gateway row's below.
// Claude Code's, Claude Desktop's and Codex's files only (usage.FloorAgents):
// a call's time is from what asked for it, never from inside it. OpenCode's
// isn't checked against real sessions, and tells none.
@@ -1437,17 +1438,46 @@ const ledRowSpeed = (r) => { const d = ledDecode(r); return d ? d.n / (d.w / 100
// more and the answer 100 tokens or more, as a measured one is. A Codex turn
// of one call that tells neither tells its output over the whole turn, the
// wait in it, by the same 1,000-token rule as any whole-time floor (Fallmonkey
-// on Discord: 11 tokens in 2.75 s read ≥4 tok/s). ledFloor_ says the tokens,
-// the ms, and which it is (answer, turn).
+// on Discord: 11 tokens in 2.75 s read ≥4 tok/s).
+// A gateway call that tells no speed of its own (夜松云 on Discord: the
+// Requests tab's speed was blank for some rows) has the same two floors, as
+// its time is from when it came to its last token: one that reasoned with no
+// first text recorded (a tool call after hidden reasoning), its answer after
+// the first token, unless its content came in a burst; else one not streamed,
+// or not timed, its output over its whole time, by the 1,000-token rule.
+// ledFloor_ says the tokens, the ms, and which it is (answer, turn, gateway).
const LED_FLOOR_AGENTS = new Set(["claude", "claude-desktop", "codex"]);
+const ledWhole_ = (r) => r.out >= 1000 && r.ms >= 1000 && r.out * 1000 <= 10000 * r.ms;
const ledFloor_ = (r) => {
- if (r.source !== "log" || !LED_FLOOR_AGENTS.has(r.agent) || ledFailed_(r) || ledRowSpeed(r)) return null;
+ if (ledFailed_(r) || ledRowSpeed(r)) return null;
+ if (r.source !== "log") {
+ const n = r.out - (r.reasoning || 0), w = r.ms - r.ttft_ms;
+ if (r.ttft_ms > 0 && r.reasoning > 0 && !(r.first_text_ms > 0) && n >= LED_CODEX_BODY && w >= LED_CODEX_WINDOW_MS && n * 1000 <= 10000 * w && !(r.flow_ms > 0 && r.flow_ms * 4 < w)) return { n, w, answer: true, gateway: true };
+ return ledWhole_(r) ? { n: r.out, w: r.ms, gateway: true } : null;
+ }
+ if (!LED_FLOOR_AGENTS.has(r.agent)) return null;
if (ledCodexTurn(r)) {
const n = r.out - (r.reasoning || 0), w = r.ms - r.ttft_ms;
if (r.reasoning > 0 && n >= LED_CODEX_BODY && w >= LED_CODEX_WINDOW_MS && n * 1000 <= 10000 * w) return { n, w, answer: true };
- return r.out >= 1000 && r.ms >= 1000 && r.out * 1000 <= 10000 * r.ms ? { n: r.out, w: r.ms, turn: true } : null;
+ return ledWhole_(r) ? { n: r.out, w: r.ms, turn: true } : null;
}
- return r.out >= 1000 && r.ms >= 1000 && r.out * 1000 <= 10000 * r.ms ? { n: r.out, w: r.ms } : null;
+ return ledWhole_(r) ? { n: r.out, w: r.ms } : null;
+};
+// why a row tells no speed of its own, in words for its tooltip, so a dash
+// is never left unexplained: ledDecode's reasons, in its order
+const ledNoSpeed_ = (r) => {
+ if (ledFailed_(r)) return t("A failed request tells no speed");
+ if (!(r.ms > 0)) return t("No duration was recorded to time a speed from");
+ if (!(r.out > 0)) return t("No output tokens to time a speed from");
+ if (!(r.ttft_ms > 0)) return r.source === "log" ? t("The session file has no first token to time a speed from") : t("Not streamed: no first token to time a speed from");
+ const think = r.reasoning > 0, visible = think && !(r.first_text_ms > 0) && r.first_reasoning_ms >= r.ttft_ms && r.flow_ms > 0 && r.reasoning <= r.out;
+ const n = think && !visible ? r.out - r.reasoning : r.out;
+ if (!(n > 0)) return t("All its output was reasoning: no answer after it to time a speed from");
+ const from = visible ? r.first_reasoning_ms : think && r.first_text_ms > 0 ? r.first_text_ms : r.ttft_ms, w = r.ms - from;
+ const little = t("Too little came after the first token to time a speed by: {n} tokens in {ms}", { n: ledNum(n), ms: ledTook(Math.max(0, w)) });
+ if (w < 100) return little;
+ if (n * 1000 > 10000 * w || r.flow_ms > 0 && r.flow_ms * 4 < w || think && r.first_text_ms > 0 && n * (r.first_text_ms - r.ttft_ms) > 20 * r.reasoning * w) return t("It came in one burst at its end, not as it was written, so how fast it was written isn't seen");
+ return little;
};
const ledFloorSpeed = (r) => { const f = ledFloor_(r); return f ? f.n / (f.w / 1000) : 0; };
@@ -1741,14 +1771,17 @@ function renderLedger() {
td(untimed ? "—" : (timed ? "≈" : "") + ledTook(r.ms), "n duration " + (untimed ? "faint" : "duration-" + durationBand),
[!untimed ? t("{n} ms", { n: ledNum(r.ms) }) : "", !untimed ? t("Duration colors: ≤10 s green · 10–30 s amber · >30 s red") : "", timed && !untimed ? t("About: told from the session file's times, a little more or less than it took") : "", r.ttft_ms ? t("TTFT {ms}", { ms: ledTook(r.ttft_ms) }) : ""].filter(Boolean).join(" · "));
// how fast it wrote once it began, as CC Switch's log has it (#860)
- const v = ledRowSpeed(r), floor = ledFloorSpeed(r);
+ const v = ledRowSpeed(r), floor = ledFloorSpeed(r), f = ledFloor_(r);
+ const ttft = r.ttft_ms > 0 ? " · " + t("TTFT {ms}", { ms: ledTook(r.ttft_ms) }) : "";
td(v ? t("{n} tok/s", { n: ledNum(Math.round(v)) }) : floor ? "≥" + t("{n} tok/s", { n: ledNum(Math.round(floor)) }) : "—", "n speed" + (v || floor ? "" : " faint"),
v ? (r.reasoning > 0 && r.first_text_ms > 0 ? t("{n} answer tokens in {ms} after the first text, the {r} reasoning tokens before it left out", { n: ledNum(ledDecode(r).n), ms: ledTook(ledDecode(r).w), r: ledNum(r.reasoning) })
- : t("{n} output tokens in {ms} after the first", { n: ledNum(ledDecode(r).n), ms: ledTook(ledDecode(r).w) })) + " · " + t("TTFT {ms}", { ms: ledTook(r.ttft_ms) })
- : floor && ledFloor_(r).answer ? t("At least: {n} answer tokens in {ms} after the first token, the {r} reasoning tokens left out. The session file has no first text, so reasoning after the first token is counted too", { n: ledNum(ledFloor_(r).n), ms: ledTook(ledFloor_(r).w), r: ledNum(r.reasoning) }) + " · " + t("TTFT {ms}", { ms: ledTook(r.ttft_ms) })
- : floor && ledFloor_(r).turn ? t("At least: {n} output tokens in {ms}, the whole turn. What came after the first token ({after}) is too little to time a speed by: under a second or under 100 tokens, so the wait for it is counted too", { n: ledNum(r.out), ms: ledTook(r.ms), after: ledTook(r.ms - r.ttft_ms) }) + " · " + t("TTFT {ms}", { ms: ledTook(r.ttft_ms) })
+ : t("{n} output tokens in {ms} after the first", { n: ledNum(ledDecode(r).n), ms: ledTook(ledDecode(r).w) })) + ttft
+ : floor && f.gateway && f.answer ? t("At least: {n} answer tokens in {ms} after the first token, the {r} reasoning tokens left out. No first text was recorded, so reasoning after the first token is counted too", { n: ledNum(f.n), ms: ledTook(f.w), r: ledNum(r.reasoning) }) + ttft
+ : floor && f.gateway ? t("At least: {n} output tokens in {ms}, from the request to its last token, the wait for the first one counted too", { n: ledNum(r.out), ms: ledTook(r.ms) }) + ". " + ledNoSpeed_(r) + ttft
+ : floor && f.answer ? t("At least: {n} answer tokens in {ms} after the first token, the {r} reasoning tokens left out. The session file has no first text, so reasoning after the first token is counted too", { n: ledNum(f.n), ms: ledTook(f.w), r: ledNum(r.reasoning) }) + ttft
+ : floor && f.turn ? t("At least: {n} output tokens in {ms}, the whole turn. What came after the first token ({after}) is too little to time a speed by: under a second or under 100 tokens, so the wait for it is counted too", { n: ledNum(r.out), ms: ledTook(r.ms), after: ledTook(r.ms - r.ttft_ms) }) + ttft
: floor ? t("At least: {n} output tokens in {ms}, 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", { n: ledNum(r.out), ms: ledTook(r.ms) })
- : r.ttft_ms || untimed || ledFailed_(r) ? "" : timed ? t("The session file has no first token to time a speed from") : t("Not streamed: no first token to time a speed from"));
+ : ledNoSpeed_(r));
const st = el("span", "st");
// a status when the gateway logged the call; a session file has none,
// and says only whether it went well
diff --git a/internal/gui/tests/reasoning-speed.test.cjs b/internal/gui/tests/reasoning-speed.test.cjs
index 2a9c95c9b..2907532c9 100644
--- a/internal/gui/tests/reasoning-speed.test.cjs
+++ b/internal/gui/tests/reasoning-speed.test.cjs
@@ -5,7 +5,8 @@
// over the 1.5 s after counted 2200 tokens in 1.5 s, 1,467 tok/s; it is 200
// in 1.5 s, 133. An older route without its own reasoning count takes its
// served try's; a reply that reasoned and wrote only tool calls tells no
-// speed; one that didn't reason is timed as before. The Routing page's rows,
+// speed of its own (the Usage page's row tells the least its answer wrote
+// at); one that didn't reason is timed as before. The Routing page's rows,
// a session's average and the Usage page's rows and their tooltip all say
// it, in English, Chinese, Japanese and German; no backend, the API is faked.
const assert = require("node:assert/strict");
@@ -23,10 +24,10 @@ const at = (i) => new Date(now.getTime() - (i + 1) * 60e3).toISOString();
const timing = [
[2200, 2000, 0, 15500, 14000, 14000], // the turn: 200 in 1.5 s, 133 tok/s
[1300, 0, 1000, 9000, 6000, 6000], // an older route: 300 in 3 s, 100 tok/s
- [1500, 1400, 0, 9000, 8000, 0], // reasoning, then tool calls only: none
+ [1500, 1400, 0, 9000, 8000, 0], // reasoning, then tool calls only: none measured, ≥100 on the Usage row
[500, 0, 0, 7000, 2000, 2000], // no reasoning: 500 in 5 s, 100 tok/s
[1500, 1400, 0, 15000, 1000, 0], // paced visible reasoning: 107 tok/s
- [1500, 1400, 0, 9000, 8000, 0], // a late summary stays untimed
+ [1500, 1400, 0, 9000, 8000, 0], // a late summary stays untimed, ≥100 on the Usage row
[120, 0, 0, 9000, 1000, 0], // mixed redacted thinking without a reasoning count
];
const routes = timing.map(([out, reasoning, usageReasoning, ms, ttft, firstText], i) => ({
@@ -135,10 +136,12 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
assert.equal((await cell(0).textContent()).trim(), w.s(133));
assert.match(await cell(0).getAttribute("title"), w.note);
assert.equal((await cell(1).textContent()).trim(), w.s(100));
- assert.equal((await cell(2).textContent()).trim(), "—");
+ // no speed of its own, but its 100 answer tokens all came in the 1 s
+ // after its first token: at least 100 tok/s (夜松云 on Discord)
+ assert.equal((await cell(2).textContent()).trim(), "≥" + w.s(100));
assert.equal((await cell(3).textContent()).trim(), w.s(100));
assert.equal((await cell(4).textContent()).trim(), w.s(107));
- assert.equal((await cell(5).textContent()).trim(), "—");
+ assert.equal((await cell(5).textContent()).trim(), "≥" + w.s(100));
assert.equal((await cell(6).textContent()).trim(), "—");
const kpi = page.locator("#ledKpi .blk").nth(4);
assert.equal((await kpi.locator(".v").textContent()).trim(), w.s(106));
diff --git a/internal/gui/tests/usage-session-speed.test.cjs b/internal/gui/tests/usage-session-speed.test.cjs
index da6610067..05dc6706a 100644
--- a/internal/gui/tests/usage-session-speed.test.cjs
+++ b/internal/gui/tests/usage-session-speed.test.cjs
@@ -41,7 +41,8 @@ const ROWS = [
{ ...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
+ // 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 },
@@ -98,12 +99,12 @@ function server(lang) {
const L = {
en: {
- speed: "Speed", floor: "≥98 tok/s", desktop: "≥125 tok/s", codexFloor: "≥25 tok/s", timed: "75 tok/s", codex: "150 tok/s",
+ 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: "速度", floor: "≥98 token/秒", desktop: "≥125 token/秒", codexFloor: "≥25 token/秒", timed: "75 token/秒", codex: "150 token/秒",
+ 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: "非流式:没有首字时间,算不出速度",
},
@@ -144,8 +145,8 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
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), "—");
- assert.equal(await tip(3), w.notStreamed);
+ 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
diff --git a/internal/gui/tests/usage-speed-every-row.test.cjs b/internal/gui/tests/usage-speed-every-row.test.cjs
new file mode 100644
index 000000000..7be094eb1
--- /dev/null
+++ b/internal/gui/tests/usage-speed-every-row.test.cjs
@@ -0,0 +1,170 @@
+// 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: "[email protected]",
+ 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();
+ });
+ }
+ });
+}