diff --git a/docs/reference.md b/docs/reference.md index 18776a7fb..10bed64c6 100644 --- a/docs/reference.md +++ b/docs/reference.md @@ -350,8 +350,10 @@ from the first token to its end, held to the same second and 100 tokens. Its whole output over that time would count reasoning written before the first token and read high. A Codex turn of one call that tells neither shows the least it wrote at over the whole turn, the wait for the first token in it -(`≥54 tok/s` for 380 tokens in 7 s), of any size, as everything it wrote -was written in that time. Gateway rows and other agents' keep their own +(`≥120 tok/s` for 1,200 tokens in 10 s), by the same rule as any floor over +a whole time: 1,000 tokens or more over a second or more. Under that the +wait is too much of the time to tell anything, so an 11-token answer in +2.75 s shows none, as an 815-token Claude Code reply does. Gateway rows and other agents' keep their own speed. A floor never mixes into a measured speed: the Speed trend and `magpie usage` count timed calls only. diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js index 4ada19d81..05158c6f9 100644 --- a/internal/gui/assets/app.js +++ b/internal/gui/assets/app.js @@ -18530,7 +18530,8 @@ const ledRowSpeed = (r) => { const d = ledDecode(r); return d ? d.n / (d.w / 100 // after it is a floor of the answer's speed, when that time is a second or // 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: all of it was written in that time. ledFloor_ says the tokens, +// 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). const LED_FLOOR_AGENTS = new Set(["claude", "claude-desktop", "codex"]); const ledFloor_ = (r) => { @@ -18538,7 +18539,7 @@ const ledFloor_ = (r) => { 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 > 0 && r.ms >= 100 && r.out * 1000 <= 10000 * r.ms ? { 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, turn: true } : null; } return r.out >= 1000 && r.ms >= 1000 && r.out * 1000 <= 10000 * r.ms ? { n: r.out, w: r.ms } : null; }; diff --git a/internal/gui/tests/usage-speed-count.test.cjs b/internal/gui/tests/usage-speed-count.test.cjs index a79ab5c54..7ea5fe1e7 100644 --- a/internal/gui/tests/usage-speed-count.test.cjs +++ b/internal/gui/tests/usage-speed-count.test.cjs @@ -18,7 +18,10 @@ // its answer's floor told, only over a second or more after its first token // and 100 tokens or more; else it tells the least it wrote at over the whole // turn (Fallmonkey on Discord: a first token at 6.8 s, the model working, -// and the rest 0.2 s later in one push, read as 1,900 tok/s). Every +// and the rest 0.2 s later in one push, read as 1,900 tok/s), by the same +// 1,000-token rule as Claude Code's whole-time floor (Fallmonkey again: an +// 11-token astra answer in 2.75 s read ≥4 tok/s, while an 815-token Claude +// Code reply said nothing). Every // language, a wide window and a narrow one; no backend, the API is faked. const assert = require("node:assert/strict"); const fs = require("node:fs/promises"); @@ -44,15 +47,20 @@ const ROWS = [ // a short one tells nothing { ...CC, t: at(3), out: 300, ms: 20000 }, // a sol turn of one call that reasoned: its 272 answer tokens came in the - // 827 ms after its first token, under a second, so the whole turn: at - // least 496 tokens in 11,055 ms, 45 tok/s (not 329 from the answer alone) + // 827 ms after its first token, under a second, so the whole turn, and + // its 496 tokens are under 1,000: nothing (not 329 from the answer alone) { ...SOL, t: at(4), out: 496, reasoning: 224, ms: 11055, ttft_ms: 10228 }, // one that reasoned and wrote its 1,000-token answer over the 10 s after // its first token: at least 100 tok/s (not its 1,200 tokens, 120) { ...SOL, t: at(5), out: 1200, reasoning: 200, ms: 12000, ttft_ms: 2000 }, // Fallmonkey's: a first token at 6.8 s and its 380 tokens 0.2 s later, one - // push, not 1,900 tok/s: at least 380 in the whole 7 s, 54 tok/s + // push, not 1,900 tok/s, and under 1,000 over the whole turn: nothing { ...SOL, t: at(6), out: 380, ms: 7000, ttft_ms: 6800 }, + // Fallmonkey's astra answer: 11 tokens in 2.75 s, not ≥4 tok/s + { ...SOL, t: at(7), model: "gpt-6-astra", req: "gpt-6-astra", served: "gpt-6-astra", out: 11, ms: 2750, ttft_ms: 2600 }, + // 1,200 tokens 0.5 s after a 9.5 s first token, one push: at least 1,200 + // in the whole 10 s, 120 tok/s + { ...SOL, t: at(8), out: 1200, ms: 10000, ttft_ms: 9500 }, ]; // the groups as usage.Breakdown sums them (TestGroupSpeedSaysHowManyRepliesItIsOf) const G = { @@ -116,27 +124,27 @@ const L = { m: (n, k) => `${n} tok/s · ${k} timed ${k === 1 ? "reply" : "replies"}`, f: (n, k) => `≥${n} tok/s · ${k} replies`, join: "; ", timed: (k) => ` · ${k} timed replies`, measured: (k, others) => (k === 1 ? `Measured on ${k} reply, from its first token to its end` : `Measured on ${k} replies, from their first token to their end`) + (others ? "; the others tell no speed" : ""), floorTip: (k) => `At least: ${k} replies read from session files, which don't say when their answers began, so time before that is counted too`, row: "125 tok/s", rowFloor: "≥100 tok/s", - cx: "≥50 tok/s", luna: "≥45 tok/s", answer: "≥100 tok/s", fall: "≥54 tok/s", turnTip: "the whole turn. What came after the first token (", answerTip: "At least: 1,000 answer tokens in " }, + cx: "≥50 tok/s", answer: "≥100 tok/s", push: "≥120 tok/s", n1200: "1,200", turnTip: "the whole turn. What came after the first token (", answerTip: "At least: 1,000 answer tokens in " }, zh: { speed: "速度", kpi: "输出速度", m: (n, k) => `${n} token/秒 · ${k} 次计时`, f: (n, k) => `≥${n} token/秒 · ${k} 次回复`, join: ";", timed: (k) => ` · ${k} 次计时`, measured: (k, others) => `实测 ${k} 次回复:从首字到结束` + (others ? ";其余请求测不出速度" : ""), floorTip: (k) => `下限:${k} 次读自会话文件的回复。会话文件不记录正文何时开始,之前的时间也算在里面`, row: "125 token/秒", rowFloor: "≥100 token/秒", - cx: "≥50 token/秒", luna: "≥45 token/秒", answer: "≥100 token/秒", fall: "≥54 token/秒", turnTip: "首字后只有 ", answerTip: "输出 1,000 个正文 token,200 个推理 token 不计" }, + cx: "≥50 token/秒", answer: "≥100 token/秒", push: "≥120 token/秒", n1200: "1,200", turnTip: "首字后只有 ", answerTip: "输出 1,000 个正文 token,200 个推理 token 不计" }, "zh-TW": { speed: "速度", kpi: null, m: (n, k) => `${n} token/秒 · ${k} 次計時`, f: (n, k) => `≥${n} token/秒 · ${k} 次回覆`, join: ";", timed: (k) => ` · ${k} 次計時`, measured: (k, others) => `實測 ${k} 次回覆:從首字到結束` + (others ? ";其餘請求測不出速度" : ""), floorTip: (k) => `下限:${k} 次讀自會話檔案的回覆。會話檔案不記錄正文何時開始,之前的時間也算在裡面`, row: "125 token/秒", rowFloor: "≥100 token/秒", - cx: "≥50 token/秒", luna: "≥45 token/秒", answer: "≥100 token/秒", fall: "≥54 token/秒", turnTip: "首字後只有 ", answerTip: "輸出 1,000 個正文 token,200 個推理 token 不計" }, + cx: "≥50 token/秒", answer: "≥100 token/秒", push: "≥120 token/秒", n1200: "1,200", turnTip: "首字後只有 ", answerTip: "輸出 1,000 個正文 token,200 個推理 token 不計" }, ja: { speed: null, kpi: null, m: (n, k) => `${n} トークン/秒 · 計測 ${k} 件`, f: (n, k) => `≥${n} トークン/秒 · 応答 ${k} 件`, join: "/", timed: (k) => ` · 計測 ${k} 件`, measured: (k, others) => `${k} 件の応答で実測:最初のトークンから終わりまで` + (others ? "。ほかのリクエストは速度を計れません" : ""), floorTip: (k) => `下限:セッションファイルから読んだ ${k} 件の応答。回答が始まった時刻がないため、その前の時間も含まれます`, row: "125 トークン/秒", rowFloor: "≥100 トークン/秒", - cx: "≥50 トークン/秒", luna: "≥45 トークン/秒", answer: "≥100 トークン/秒", fall: "≥54 トークン/秒", turnTip: "最初のトークン後は ", answerTip: "で回答 1,000 トークン(推論 200 トークンは含めず)" }, + cx: "≥50 トークン/秒", answer: "≥100 トークン/秒", push: "≥120 トークン/秒", n1200: "1,200", turnTip: "最初のトークン後は ", answerTip: "で回答 1,000 トークン(推論 200 トークンは含めず)" }, de: { speed: null, kpi: null, m: (n, k) => `${n} Token/s · ${k} gemessene ${k === 1 ? "Antwort" : "Antworten"}`, f: (n, k) => `≥${n} Token/s · ${k} Antworten`, join: "; ", timed: (k) => ` · ${k} gemessene Antworten`, measured: (k, others) => `Gemessen an ${k} ${k === 1 ? "Antwort" : "Antworten"}, vom ersten Token bis zum Ende` + (others ? "; die übrigen Anfragen zeigen kein Tempo" : ""), floorTip: (k) => `Mindestens: ${k} Antworten aus Sitzungsdateien. Sie sagen nicht, wann die Antworten begannen, also zählt die Zeit davor mit`, row: "125 Token/s", rowFloor: "≥100 Token/s", - cx: "≥50 Token/s", luna: "≥45 Token/s", answer: "≥100 Token/s", fall: "≥54 Token/s", turnTip: "der ganze Turn. Nach dem ersten Token kam nur ", answerTip: "Mindestens: 1.000 Antwort-Token in " }, + cx: "≥50 Token/s", answer: "≥100 Token/s", push: "≥120 Token/s", n1200: "1.200", turnTip: "der ganze Turn. Nach dem ersten Token kam nur ", answerTip: "Mindestens: 1.000 Antwort-Token in " }, }; for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) { @@ -182,13 +190,14 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", assert.equal((await cell(1).textContent()).trim(), w.cx); assert.equal((await cell(2).textContent()).trim(), w.rowFloor); assert.equal((await cell(3).textContent()).trim(), "—"); - assert.equal((await cell(4).textContent()).trim(), w.luna); - assert((await cell(4).getAttribute("title")).includes(w.turnTip), "the whole turn's floor says so: " + (await cell(4).getAttribute("title"))); + assert.equal((await cell(4).textContent()).trim(), "—", "496 tokens over the whole turn tell nothing"); assert.equal((await cell(5).textContent()).trim(), w.answer); assert((await cell(5).getAttribute("title")).includes(w.answerTip), "the answer's floor says so: " + (await cell(5).getAttribute("title"))); - assert.equal((await cell(6).textContent()).trim(), w.fall); - const fallTip = await cell(6).getAttribute("title"); - assert(fallTip.includes(w.turnTip) && fallTip.includes("380"), "Fallmonkey's says it is the whole turn: " + fallTip); + assert.equal((await cell(6).textContent()).trim(), "—", "Fallmonkey's 380 tokens over the whole turn tell nothing"); + assert.equal((await cell(7).textContent()).trim(), "—", "Fallmonkey's 11-token astra answer tells nothing"); + assert.equal((await cell(8).textContent()).trim(), w.push); + const pushTip = await cell(8).getAttribute("title"); + assert(pushTip.includes(w.turnTip) && pushTip.includes(w.n1200), "the whole turn's floor says so: " + pushTip); // the ranking, by tokens: each group's speed beside its requests const rk = (id) => p.locator("#ledRank .rk").filter({ has: p.locator(".rk-nm", { hasText: id }) }); diff --git a/internal/usage/ledger.go b/internal/usage/ledger.go index 18f891e26..61fe2409d 100644 --- a/internal/usage/ledger.go +++ b/internal/usage/ledger.go @@ -725,8 +725,11 @@ func (r Row) Decode() (tokens int, w int64) { // // A Codex turn of one call that tells neither, its window after the first // token too short or its body too small, tells its output over the whole -// turn, the wait for the first token in it: everything it wrote, reasoning -// too, was written in that time, so it is a true floor of any size. +// turn, the wait for the first token in it, by the same rule as any other +// such floor: 1,000 tokens or more over a second or more. It is the same +// formula, so it has the same gate: under 1,000 tokens the wait is too much +// of the time to tell anything (Fallmonkey on Discord: 11 tokens in 2.75 s +// read ≥4 tok/s while an 815-token Claude Code reply told nothing). func (r Row) Floor() (tokens int, ms int64) { if r.Source != "log" || !FloorAgents[r.Agent] || r.Failed() { return 0, 0 @@ -740,10 +743,6 @@ func (r Row) Floor() (tokens int, ms int64) { return n, w } } - if r.Output <= 0 || r.Millis < MinDecodeMs || int64(r.Output)*1000 > MaxDecodeSpeed*r.Millis { - return 0, 0 - } - return r.Output, r.Millis } if r.Output < 1000 || r.Millis < 1000 || int64(r.Output)*1000 > MaxDecodeSpeed*r.Millis { return 0, 0 diff --git a/internal/usage/speed_count_test.go b/internal/usage/speed_count_test.go index f305c209f..9d29928a9 100644 --- a/internal/usage/speed_count_test.go +++ b/internal/usage/speed_count_test.go @@ -82,7 +82,8 @@ func TestGroupSpeedSaysHowManyRepliesItIsOf(t *testing.T) { // a turn of one call that reasoned, whose first text isn't in the file, by // its answer over the time after its first token, never its whole output // over it, which counts reasoning written before the first token, when that -// is a second or more and 100 tokens or more; else over the whole turn. +// is a second or more and 100 tokens or more; else over the whole turn, by +// the same 1,000-token rule as Claude Code's whole-time floor. func TestCodexRowsTellAFloor(t *testing.T) { row := func(out, reasoning int, ms, ttft int64) Row { return Row{Source: "log", Record: Record{Agent: "codex", Model: "gpt-6-luna", Output: out, Reasoning: reasoning, Millis: ms, TTFT: ttft}} @@ -94,13 +95,17 @@ func TestCodexRowsTellAFloor(t *testing.T) { ms int64 }{ // 272 answer tokens 827 ms after a 10.2 s first token could be one - // push: the whole turn, 496 over 11,055 ms, 45 tok/s - {"one call that reasoned, its answer under a second", row(496, 224, 11055, 10228), 496, 11055}, + // push, and the whole turn, 496 tokens, is under 1,000: none + {"one call that reasoned, its answer under a second", row(496, 224, 11055, 10228), 0, 0}, + // 1,100 answer tokens 500 ms after an 11 s first token: the whole + // turn, 1,300 over 11.5 s + {"one call that reasoned, a long answer in one push", row(1300, 200, 11500, 11000), 1300, 11500}, {"one call that reasoned, all of it after its first token", row(1200, 200, 12000, 2000), 1000, 10000}, - {"one call that reasoned, an answer of 60 over 3 s", row(260, 200, 5000, 2000), 260, 5000}, + {"one call that reasoned, an answer of 60 over 3 s", row(260, 200, 5000, 2000), 0, 0}, {"one call that didn't reason tells its own speed", row(500, 0, 5000, 1000), 0, 0}, - {"one call whose answer came too fast to tell", row(500, 100, 2050, 2000), 500, 2050}, - {"one call that only reasoned", row(300, 300, 9000, 2000), 300, 9000}, + {"one call whose answer came too fast to tell", row(500, 100, 2050, 2000), 0, 0}, + {"one call that only reasoned", row(300, 300, 9000, 2000), 0, 0}, + {"one call that only reasoned, 1,000 tokens", row(1000, 1000, 9000, 2000), 1000, 9000}, {"a call of several, 1,500 over 30 s", row(1500, 600, 30000, 0), 1500, 30000}, {"a call of several too short to tell", row(800, 100, 20000, 0), 0, 0}, } { @@ -117,12 +122,37 @@ func TestCodexRowsTellAFloor(t *testing.T) { } } +// Fallmonkey on Discord: an 11-token astra answer over 2.75 s, its window +// after the first token too short, read ≥4 tok/s over the whole turn, while +// an 815-token Claude Code reply, the same formula, told nothing. A Codex +// whole-turn floor has the same 1,000-token gate. +func TestCodexWholeTurnFloorNeedsAThousandTokens(t *testing.T) { + astra := Row{Source: "log", Record: Record{Agent: "codex", Model: "gpt-6-astra", Output: 11, Millis: 2750, TTFT: 2600}} + if n, ms := astra.Floor(); n != 0 || ms != 0 { + t.Errorf("astra's 11 tokens over 2.75 s: floor %d/%d ms, want none", n, ms) + } + claude := Row{Source: "log", Record: Record{Agent: "claude", Model: "claude-opus-5-5", Output: 815, Millis: 18000}} + if n, ms := claude.Floor(); n != 0 || ms != 0 { + t.Errorf("Claude Code's 815 tokens over 18 s: floor %d/%d ms, want none", n, ms) + } + for _, r := range []Row{ + {Source: "log", Record: Record{Agent: "codex", Model: "gpt-6-astra", Output: 1000, Millis: 12000, TTFT: 11800}}, + {Source: "log", Record: Record{Agent: "claude", Model: "claude-opus-5-5", Output: 1000, Millis: 12000}}, + } { + if n, ms := r.Floor(); n != 1000 || ms != 12000 { + t.Errorf("%s's 1,000 tokens over 12 s: floor %d/%d ms, want 1000/12000", r.Agent, n, ms) + } + } +} + // Fallmonkey on Discord: a Codex turn of one call whose first token came at // 6.8 s, the model working, and its 380 tokens 0.2 s later in one push read // 1,900 tok/s. A Codex turn of one call from its session file is measured // only when the window after its first token is a second or more and its // body 100 tokens or more; else it tells the least it wrote at over the -// whole turn. The gateway's own rows, and other agents', keep their speed. +// whole turn, when that is 1,000 tokens or more over a second or more, as +// Claude Code's whole-time floor is. The gateway's own rows, and other +// agents', keep their speed. func TestCodexTurnMeasuredOnlyOverASecondAndAHundredTokens(t *testing.T) { row := func(out int, ms, ttft int64) Row { return Row{Source: "log", Record: Record{Agent: "codex", Model: "gpt-6.1-sol", Output: out, Millis: ms, TTFT: ttft}} @@ -135,12 +165,14 @@ func TestCodexTurnMeasuredOnlyOverASecondAndAHundredTokens(t *testing.T) { floorN int floorMs int64 }{ - {"one push 0.2 s after a 6.8 s first token", row(380, 7000, 6800), 0, 0, 380, 7000}, - {"60 tokens over 2 s", row(60, 3000, 1000), 0, 0, 60, 3000}, + {"one push 0.2 s after a 6.8 s first token", row(380, 7000, 6800), 0, 0, 0, 0}, + {"1,200 tokens in one push 0.5 s after a 9.5 s first token", row(1200, 10000, 9500), 0, 0, 1200, 10000}, + {"60 tokens over 2 s", row(60, 3000, 1000), 0, 0, 0, 0}, {"500 tokens over 4 s", row(500, 5000, 1000), 500, 4000, 0, 0}, {"100 tokens over exactly a second", row(100, 7800, 6800), 100, 1000, 0, 0}, - {"99 tokens over a second", row(99, 7800, 6800), 0, 0, 99, 7800}, - {"400 tokens over 999 ms", row(400, 7799, 6800), 0, 0, 400, 7799}, + {"99 tokens over a second", row(99, 7800, 6800), 0, 0, 0, 0}, + {"400 tokens over 999 ms", row(400, 7799, 6800), 0, 0, 0, 0}, + {"1,000 tokens over 999 ms", row(1000, 7799, 6800), 0, 0, 1000, 7799}, } { if n, w := c.r.Decode(); n != c.dn || w != c.dw { t.Errorf("%s: measured %d/%d ms, want %d/%d", c.name, n, w, c.dn, c.dw) @@ -161,8 +193,9 @@ func TestCodexTurnMeasuredOnlyOverASecondAndAHundredTokens(t *testing.T) { // a group and the ledger's sum count it as a floor, not 1,900 tok/s var g Totals g.addRow(row(380, 7000, 6800)) + g.addRow(row(1200, 10000, 9500)) g.addRow(row(500, 5000, 1000)) - if g.DecodeN != 1 || g.Speed() != 125 || g.FloorN != 1 || g.FloorOut != 380 || g.FloorMs != 7000 { + if g.DecodeN != 1 || g.Speed() != 125 || g.FloorN != 1 || g.FloorOut != 1200 || g.FloorMs != 10000 { t.Fatalf("group: %+v", g) } at := time.Date(2026, 10, 11, 9, 0, 0, 0, time.UTC)