Files
magpie/internal/usage/speed_count_test.go
T
yetone e5b82cf38a usage, gui: Codex rows tell the least they wrote at: a call in a turn of several over its whole time, a turn of one call that reasoned by its answer after the first token (Fallmonkey on Discord)
Codex's session rows told no floor. A call in a turn of several could be
timed from inside itself; the commit before this one times it from what
asked for it, before its first output item, to its last, as Claude Code's
is. So Codex joins usage.FloorAgents and app.js's LED_FLOOR_AGENTS, and
such a call tells its output over its whole time, by the same 1,000-token
rule. On 622 stripped recent rollouts only 4 of 1,367 such calls have
1,000 tokens or more, so the floors will be few, but they are true.

A Codex turn of one call that reasoned has its first token (the turn's
time_to_first_token_ms) but not its first text, so DecodeOf tells no
speed. Fallmonkey asked for its whole output, reasoning too, over the
time after the first token. That reads high: OpenAI's reasoning is
written before the first content, so it isn't in that time. On a gateway
reply of 496 tokens, 224 of them reasoning, 827 ms after a 10.2 s first
token, that is 600 tok/s against a measured answer speed of 415 (the
bug e6dd5d20b fixed). Instead the answer, its output less the reasoning,
which all came after the first token, over that time: 329, a true floor
of the answer's speed. Any size tells one, as the wait isn't in it;
DecodeWindow's bounds still hold. The Requests row's tooltip says so, and
a group's floor tooltip now says the file doesn't say when the answer
began, true of both kinds, in en, zh, zh-TW, ja and de.

The 1,000-token rule stays (Fallmonkey asked for 5 s instead): it bounds
the share of the time the wait for the first token can be, which a
duration doesn't (a 5 s reply can be 4 s of wait). On the owner's
gateway rows, where both are known, a floor of 1,000 tokens or more read
0.40 of the measured speed (n=25), one of 5 s or more 0.18 (n=550). The
reason is in Row.Floor's comment and docs/reference.md.

Tests: TestCodexRowsTellAFloor (new) and TestGroupSpeedSaysHowManyRepliesItIsOf
(sol's 259 calls in turns of several now tell 259 floors at 50) fail on
the old ledger.go. usage-speed-count.test.cjs gains a turn-of-several row
(≥50) and the 496/224 row (≥329, its tooltip) and fails on the old app.js;
usage-session-speed.test.cjs's Codex row now tells its floor.

Ran: go test ./internal/usage ./internal/gui; usage-speed-count,
usage-session-speed, usage-ledger-detail, usage-speed, reasoning-speed,
usage-ledger-fit, usage-model-at-provider, routing-request-metrics,
gui-ja, gui-de, gui-zh-tw and i18n-keys in Chromium and WebKit, at 1400
and 560 px; gofmt -l; GOOS=linux/windows go vet.
2026-10-11 12:49:27 +08:00

114 lines
5.1 KiB
Go

package usage
import (
"testing"
"time"
)
// A group's speed says how many replies it is of, and a group none of whose
// replies was measured says the least they wrote at (Fallmonkey on Discord:
// gpt-6.1-sol showed a tok/s from the one reply of 260 that called no tool,
// beside "260 requests", while Claude Code, with dozens of floors on the
// Requests tab, showed none). Breakdown and the sums count the measured
// replies (DecodeN) and the floors (FloorOut over FloorMs, FloorN) apart.
func TestGroupSpeedSaysHowManyRepliesItIsOf(t *testing.T) {
at := time.Date(2026, 10, 11, 9, 0, 0, 0, time.UTC)
var rows []Row
// sol: 260 Codex calls read from its session files; only a turn of one
// call is timed, 500 tokens over the 4 s after the first, 125 tok/s; the
// rest, calls in turns of several, wrote 1,500 tokens over 30 s each, a
// floor of 50 tok/s
for i := 0; i < 260; i++ {
r := Row{Source: "log", Record: Record{Time: at, Agent: "codex", Model: "gpt-6.1-sol", Input: 9000, Output: 1500, Millis: 30000}}
if i == 0 {
r.Output, r.Millis, r.TTFT = 500, 5000, 1000
}
rows = append(rows, r)
}
// Claude Code: 40 calls from its session file, none timed; 30 wrote
// 2,000 tokens over 20 s (a floor of 100 tok/s), 10 are too short to tell
for i := 0; i < 40; i++ {
r := Row{Source: "log", Record: Record{Time: at, Agent: "claude", Model: "claude-opus-5-5", Input: 5000, Output: 2000, Millis: 20000}}
if i >= 30 {
r.Output = 300
}
rows = append(rows, r)
}
// a failed Claude Code call and one through the gateway tell no floor
rows = append(rows,
Row{Source: "log", Record: Record{Time: at, Agent: "claude", Model: "claude-opus-5-5", Output: 2000, Millis: 20000, Error: "overloaded"}},
Row{Record: Record{Time: at, Agent: "claude", Model: "claude-opus-5-5", Output: 2000, Millis: 20000, Status: 200}},
)
by := map[string]Share{}
for _, s := range Breakdown(rows, "agent") {
by[s.ID] = s
}
sol := by["codex"]
if sol.Calls != 260 || sol.DecodeN != 1 || sol.Speed() != 125 || sol.FloorN != 259 || sol.Floor() != 50 {
t.Fatalf("sol: %d calls, %d measured at %v tok/s, %d floors at %v; want 260, 1 at 125, 259 at 50", sol.Calls, sol.DecodeN, sol.Speed(), sol.FloorN, sol.Floor())
}
cc := by["claude"]
if cc.Calls != 42 || cc.DecodeN != 0 || cc.Speed() != 0 || cc.FloorN != 30 || cc.FloorOut != 60000 || cc.FloorMs != 600000 || cc.Floor() != 100 {
t.Fatalf("Claude Code: %d calls, %d measured at %v, %d floors %d/%d ms at %v; want 42, none, 30 at 100", cc.Calls, cc.DecodeN, cc.Speed(), cc.FloorN, cc.FloorOut, cc.FloorMs, cc.Floor())
}
// the page's own sums count both the same way
var sum Totals
for _, r := range rows {
sum.addRow(r)
}
if sum.DecodeN != 1 || sum.FloorN != 289 || sum.Speed() != 125 {
t.Fatalf("sum: %+v", sum)
}
// a timed Claude Code row tells its own speed, not a floor
timed := Row{Source: "log", Record: Record{Agent: "claude", Output: 2000, Millis: 20000, TTFT: 4000}}
if n, ms := timed.Floor(); ms != 0 || n != 0 {
t.Fatalf("timed row's floor %d/%d", n, ms)
}
// records through the gateway count their measured replies too
recs := []Record{
{Time: at, Provider: "openai", Model: "gpt-6.1-sol", Output: 1200, Millis: 15000, TTFT: 3000, Status: 200},
{Time: at, Provider: "openai", Model: "gpt-6.1-sol", Output: 1200, Millis: 15000, Status: 200},
}
m := summarize(Today, at.Add(time.Hour), recs).Models[0]
if m.Calls != 2 || m.DecodeN != 1 || m.Speed() != 100 {
t.Fatalf("summarized: %+v", m.Totals)
}
}
// Codex rows tell a floor too (Fallmonkey on Discord): a call in a turn of
// several, timed from what asked for it, by the same rule as Claude Code's;
// 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.
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}}
}
for _, c := range []struct {
name string
r Row
n int
ms int64
}{
// the gateway measured 415 tok/s on this one's answer; 272 over 827 ms is 329
{"one call that reasoned", row(496, 224, 11055, 10228), 272, 827},
{"one call that reasoned, all of it after its first token", row(1200, 200, 12000, 2000), 1000, 10000},
{"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), 0, 0},
{"one call that only reasoned", row(300, 300, 9000, 2000), 0, 0},
{"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},
} {
n, ms := c.r.Floor()
if n != c.n || ms != c.ms {
t.Errorf("%s: floor %d/%d ms, want %d/%d", c.name, n, ms, c.n, c.ms)
}
}
// through the gateway a Codex row is measured, never a floor
gw := row(496, 224, 11055, 10228)
gw.Source = ""
if n, ms := gw.Floor(); n != 0 || ms != 0 {
t.Errorf("gateway row: floor %d/%d", n, ms)
}
}