pluviophile714 on Discord: a gpt-6.1-sol row on Routing read 1,539 tok/s (input 21,617, output 392, first token 8.2 s, total 8.3 s), where another monitor measures ~70. The reply came whole about 255 ms after an 8.2 s wait. Its content was spread over that short window (flow 230 ms), so the HeldShare flow check passed, and so did the 100 ms floor, and 392/0.255 s read as 1,539 tok/s. New rule, usage.HeldWindowMs: a window under 1,000 ms whose start (first token, first text or first reasoning) is more than HeldShare (4) times the window tells no speed. One rule in every place that computes one: - usage.DecodeOf: the Usage page's speed and totals, the CLI, the GUI's model speeds, and the gateway's Speed first pacing (noteTrySpeed); - routing/client.js decodeOf: the Routing row's speed and its story line; - usage/page.js ledDecode, plus a ledNoSpeed_ reason for the dash's tooltip, in en, zh, zh-TW, ja and de. docs/reference.md and docs/subsystems/gateway-sessions.md say so. On the owner's usage.jsonl (read only), 103 of the 106 rows over 600 tok/s were such windows (e.g. 448 tokens in 107 ms after 8.1 s) and are dropped. The 3 that stay have windows of 2 to 5 s. The overall speed goes from 103.8 to 97.9 tok/s. What it costs: a short reply that really streamed after a long wait tells no speed either. The live visible-reasoning fixture (76 tokens over 731 ms after 6.8 s, ~104 tok/s) and #2637's grok record (307 tokens 403 ms after a 4.6 s first token, 531 tok/s) now read "—". Their tests keep their guarantees with the same timings after a short wait, and also check the long-wait case. Tests: - New: internal/usage TestShortWindowAfterLongWaitTellsNoSpeed (the reporter's numbers, a reasoned row from the ledger, the boundary, a second after a long wait, Totals) and internal/gateway TestShortWindowAfterLongWaitNotesNoPace. - GUI: usage-speed-every-row has the reporter's row (dash, and the tooltip in all five languages); routing-burst-speed has it (first token 8.2 s, no tok/s). - Updated to the new rule: TestVisibleReasoningSpeed's decode-minimum and max-speed cases (short wait now), TestCodexTurnMeasured...'s gateway/Claude rows, TestLiveVisibleReasoningFixture and TestUsageIngestTellsSpeed. Run on mote at this tree (rebased one41ef6288): - go test -timeout 45m: internal/usage ok, internal/tui ok. - internal/gateway: red only in TestCompactionOverByteCapEveryTime (#4862, full package run; passes 3 of 3 alone). - internal/gui: red only in TestMainWindowCorners (#3949, macOS 27). - internal/cli: red only in TestEveryRouteHasACommandOrIsNamed (#5026, red on main since0872bc2a0). - The two speed fixtures that failed in the gateway run pass on rerun. - GUI, chromium and webkit: 36 files (every speed, ledger, i18n, routing-request and burst file), 609 tests, 603 pass. The 6 reds are usage-ledger's "newest live route needs no return-to-live button" (#5048, #4078, #3104 on main). - Rebased on1af868a15(f0e0385a0changed routing/client.js), then run again at the pushed head: internal/usage ok; the gateway speed tests (-run ...Speed|Pace|Decode|TTFT...) ok; 8 GUI files (both speed files, routing-request-metrics/-model, routing-speed-first, i18n-keys, reasoning-speed, usage-speed-tip) 94 of 94 in both engines. - gofmt -l clean. GOOS=windows go vet of usage, gateway, gui and cli ok. GOOS=linux go vet of usage and gateway ok; gui and cli need cgo/GTK for Linux, the same on main. Broken by hand: with the check off in usage.go, client.js and page.js, the new Go tests, TestCodexTurnMeasured..., TestLiveVisibleReasoningFixture, TestUsageIngestTellsSpeed and both GUI files (1537 tok/s shown) go red. Not tried: - the reporter's own request; - a real GPT stream, to confirm that a 255 ms window after 8.2 s is a held reply from this vendor; - the whole GUI suite (no new API call or layout change); - the Linux and Windows app.
162 lines
6.3 KiB
Go
162 lines
6.3 KiB
Go
package usage
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/yetone/magpie/internal/catalog"
|
|
"github.com/yetone/magpie/internal/provider"
|
|
)
|
|
|
|
func TestVisibleReasoningSpeed(t *testing.T) {
|
|
visible := Record{Time: time.Now(), Output: 1500, Reasoning: 1400, Millis: 15000, TTFT: 1000, FirstReasoning: 1000, Flow: 12000, Status: 200}
|
|
for _, c := range []struct {
|
|
name string
|
|
r Record
|
|
n int
|
|
w int64
|
|
}{
|
|
{"visible tool turn", visible, 1500, 14000},
|
|
{"answer remains separate", func() Record { r := visible; r.FirstText = 14000; r.Flow = 1000; return r }(), 100, 1000},
|
|
{"hidden and old records", func() Record { r := visible; r.FirstReasoning = 0; return r }(), 0, 0},
|
|
{"unknown flow", func() Record { r := visible; r.Flow = 0; return r }(), 0, 0},
|
|
{"held reasoning at quarter boundary", func() Record { r := visible; r.Flow = 3500; return r }(), 1500, 14000},
|
|
{"held reasoning just below quarter", func() Record { r := visible; r.Flow = 3499; return r }(), 0, 0},
|
|
{"held reasoning", func() Record { r := visible; r.Flow = 1000; return r }(), 0, 0},
|
|
{"invalid count", func() Record { r := visible; r.Reasoning = 1600; return r }(), 0, 0},
|
|
{"below decode minimum", Record{Output: 10, Reasoning: 5, Millis: 119, TTFT: 20, FirstReasoning: 20, Flow: 99}, 0, 0},
|
|
{"at decode minimum", Record{Output: 10, Reasoning: 5, Millis: 120, TTFT: 20, FirstReasoning: 20, Flow: 100}, 10, 100},
|
|
{"above max speed", Record{Output: 1001, Reasoning: 5, Millis: 120, TTFT: 20, FirstReasoning: 20, Flow: 100}, 0, 0},
|
|
{"at max speed", Record{Output: 1000, Reasoning: 5, Millis: 120, TTFT: 20, FirstReasoning: 20, Flow: 100}, 1000, 100},
|
|
{"redacted with no reasoning count", Record{Output: 120, Millis: 9000, TTFT: 1000, Flow: 7000, ReasoningHidden: true}, 0, 0},
|
|
{"late hidden think", Record{Output: 1500, Reasoning: 1400, Millis: 9000, TTFT: 8000, Flow: 900}, 0, 0},
|
|
} {
|
|
t.Run(c.name, func(t *testing.T) {
|
|
if n, w := c.r.Decode(); n != c.n || w != c.w {
|
|
t.Fatalf("speed counted %d tokens/%d ms; want %d/%d", n, w, c.n, c.w)
|
|
}
|
|
})
|
|
}
|
|
var chunk rowChunk
|
|
for i := 0; i < 80; i++ {
|
|
chunk.add(Row{Record: visible}, "", int64(i), false)
|
|
}
|
|
packed := chunk.pack()
|
|
if len(packed.Archive) == 0 {
|
|
t.Fatal("snapshot not compressed")
|
|
}
|
|
for _, c := range []*rowChunk{&chunk, packed.unpack()} {
|
|
row := c.row(0)
|
|
if n, w := row.Decode(); row.FirstReasoning != 1000 || n != 1500 || w != 14000 {
|
|
t.Fatalf("cache lost streamed reasoning: %+v", row)
|
|
}
|
|
}
|
|
sealed := visible
|
|
sealed.ReasoningHidden = true
|
|
var hiddenChunk rowChunk
|
|
for i := 0; i < 80; i++ {
|
|
hiddenChunk.add(Row{Record: sealed}, "", int64(i), false)
|
|
}
|
|
for _, c := range []*rowChunk{&hiddenChunk, hiddenChunk.pack().unpack()} {
|
|
row := c.row(0)
|
|
n, w := row.Decode()
|
|
if !row.ReasoningHidden || n != 0 || w != 0 {
|
|
t.Fatal("cache lost hidden reasoning flag")
|
|
}
|
|
}
|
|
var sum Totals
|
|
sum.addRow(Row{Record: visible})
|
|
hidden := visible
|
|
hidden.FirstReasoning = 0
|
|
sum.addRow(Row{Record: hidden})
|
|
if sum.DecodeOut != 1500 || sum.DecodeMs != 14000 {
|
|
t.Fatalf("hidden reasoning lifted aggregate: %+v", sum)
|
|
}
|
|
}
|
|
|
|
// A row the Requests page reads back has been priced, and pricing sets
|
|
// swapKnown on it: that bit is not ReasoningHidden's, or every priced reply
|
|
// with no answer text would lose its speed (#1463).
|
|
func TestPricedRowKeepsReasoningEvidence(t *testing.T) {
|
|
visible := Record{Time: time.Now(), Provider: "deepseek", Model: "deepseek-chat", Output: 1500, Reasoning: 1400, Millis: 15000, TTFT: 1000, FirstReasoning: 1000, Flow: 12000, Status: 200}
|
|
toolOnly := Record{Time: time.Now(), Provider: "deepseek", Model: "deepseek-chat", Output: 120, Millis: 9000, TTFT: 1000, Flow: 7000, Status: 200}
|
|
sealed := visible
|
|
sealed.ReasoningHidden = true
|
|
for _, c := range []struct {
|
|
name string
|
|
r Record
|
|
hidden bool
|
|
n int
|
|
w int64
|
|
}{
|
|
{"visible reasoning", visible, false, 1500, 14000},
|
|
{"tool call without reasoning", toolOnly, false, 120, 8000},
|
|
{"hidden reasoning", sealed, true, 0, 0},
|
|
} {
|
|
t.Run(c.name, func(t *testing.T) {
|
|
var chunk rowChunk
|
|
for i := 0; i < 80; i++ {
|
|
chunk.add(Row{Record: c.r}, "", int64(i), false)
|
|
}
|
|
b := newBlockPricer(provider.Renames{}, nil, func(Record) *catalog.Price { return nil })
|
|
defer b.release()
|
|
for _, from := range []*rowChunk{&chunk, chunk.pack()} {
|
|
priced := b.block(from)
|
|
if priced.Rows[0].Flags&swapKnown == 0 {
|
|
t.Fatal("the row wasn't priced")
|
|
}
|
|
row := priced.row(0)
|
|
if n, w := row.Decode(); row.ReasoningHidden != c.hidden || n != c.n || w != c.w {
|
|
t.Fatalf("priced row: hidden %v, %d tokens/%d ms; want %v, %d/%d", row.ReasoningHidden, n, w, c.hidden, c.n, c.w)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
// A row's Flags bits are each its own: a reported call's own cost isn't
|
|
// read back as hidden reasoning, nor hidden reasoning as an own cost
|
|
// (rowOwnCost and rowReasoningHidden both took 256 when #1463 and #1874
|
|
// landed apart).
|
|
func TestRowFlagsApart(t *testing.T) {
|
|
cost := 0.5
|
|
own := Record{Time: time.Now(), Source: SourceReported, OwnCost: &cost, Provider: "deepseek", Model: "deepseek-chat", Output: 1500, Reasoning: 1400, Millis: 15000, TTFT: 1000, FirstReasoning: 1000, Flow: 12000, Status: 200}
|
|
hidden := own
|
|
hidden.OwnCost, hidden.ReasoningHidden = nil, true
|
|
for _, c := range []struct {
|
|
name string
|
|
r Record
|
|
hidden bool
|
|
own bool
|
|
}{
|
|
{"own cost", own, false, true},
|
|
{"hidden reasoning", hidden, true, false},
|
|
} {
|
|
t.Run(c.name, func(t *testing.T) {
|
|
made := func() *rowChunk {
|
|
var chunk rowChunk
|
|
for i := 0; i < 80; i++ {
|
|
chunk.add(Row{Record: c.r, Source: SourceReported}, "", int64(i), false)
|
|
}
|
|
return &chunk
|
|
}
|
|
b := newBlockPricer(provider.Renames{}, nil, func(Record) *catalog.Price { return nil })
|
|
defer b.release()
|
|
raw := made()
|
|
for _, row := range []Row{raw.row(0), b.block(raw).row(0), b.block(made().pack()).row(0)} {
|
|
if row.ReasoningHidden != c.hidden || (row.OwnCost != nil) != c.own {
|
|
t.Fatalf("hidden %v, own cost %v; want %v, %v", row.ReasoningHidden, row.OwnCost, c.hidden, c.own)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
bits := []uint16{1, 2, 4, 8, 16, 32, swapKnown, rowHandedOn, rowReasoningHidden, rowOwnCost, rowCompactionKnown, rowCompaction, rowCredits, rowCacheUnknown}
|
|
var all uint16
|
|
for _, b := range bits {
|
|
if all&b != 0 {
|
|
t.Fatalf("Flags bit %d is taken twice", b)
|
|
}
|
|
all |= b
|
|
}
|
|
}
|