Commit Graph
2 Commits
Author SHA1 Message Date
yetone 4042aa4d1d usage: a row keeps the strings its chunk shares once, in Shapes
The usage page holds every row of the period at once, and a packed row
was 328 bytes, 140 of them 35 string ids. On the owner's real history
(364,013 calls in 6,445 chunks) only five of those vary call by call:
the error, the request id, the archive, the response id and the message
id. The other 30 (agent, provider, model, session, endpoint, client...)
repeat for most rows of a chunk: 364k rows have 7,300 distinct sets.

So a row keeps those five ids and a Shape, an index into its chunk's
Shapes table, which holds every other set once. packedRow is 216 bytes.
A snapshot (process-private, nothing on disk) writes the table once
after the strings and per row the shape and the five ids, so archives
shrink too. block() renames and re-prices per shape, not per row.

Same output: f5b015742 and this build served byte-identical bodies on
the real history for 14 endpoints, signed in: requests.csv of every row
(94,292,195 bytes); the requests page for all, offset 20000, month,
week, day, agent=codex, agent=claude, failed=1, q=opus and
provider=anthropic; the heatmap; usage for all and for month.

Footprint (phys_footprint, what Activity Monitor shows), cold start on a
copy of the real history, two runs each, alternating:
  f5b015742  peak 483 / 541 MB  end RSS 530 / 600 MB  CPU 1:44.7 / 1:47.7
  this       peak 465 / 463 MB  end RSS 511 / 509 MB  CPU 1:45.7 / 1:47.1
At rest both settle at 188-197 MB.

Tests: TestRowsOfOneSessionShareAShape fails when packedRow grows past
216 bytes (red at 328 with 112 bytes of padding put in by hand: "a
packed row is 328 bytes"), and checks that 200 rows of two models keep
2 shapes and read back equal after pack and unpack.
go test ./... -timeout 45m at this head: 65 packages ok; agent, gateway
and library failed only with "no space left on device" (the disk filled
mid-run) and, run again once there was room, are ok (agent 208s,
gateway 342s, library 115s).
GOOS=linux and GOOS=windows go vet -tags nogui ./... clean; gofmt clean.
2026-10-21 23:21:41 +08:00
yetone 5e30d58fe4 usage: a request's row says the upstream's own stop reason on the Requests page, in /v1/magpie/usage/requests and in the CSV (#1927, Gluxggg)
What changed: the gateway has recorded why the upstream said each reply
ended (Record.Stop: a Responses reply's "completed", Chat's "stop" or
"tool_calls", Anthropic's "end_turn") since c5b57b907, and the Requests
page has a line for it ("Upstream stop reason"). But the page, and
/v1/magpie/usage/requests, read their rows from the packed row cache
(rowChunk), whose list of a row's strings (rowText) never had Stop: every
row came back with it empty, so the line never showed and the API row had
no "stop". rowText now carries it (packedRow.Text grows; the cache is in
memory only, so nothing on disk changes shape). The CSV export gets it
too, as a last column, upstream_stop, after 30869e35a's tier columns.

The same gap, a sibling: 30869e35a (#1784) added TierAsked, TierSent
and TierServed to Record, also without rowText, so the API's rows had
them empty too. They are in rowText now, and TestRowTextHoldsEveryString
sets every string of a Record (but Computer, the chunk's; Source, the
row's own; and the unlogged bodies), packs and unpacks the row, and
names any that came back empty, so the next field added can't be lost
the same way.

Why: #1927 asks whether a /v1/responses reply that ended in
response.completed with no tool call was the upstream's own end or one
magpie made up. In a Responses-to-Responses relay magpie writes no
terminal event of its own (a stream with none ends in response.failed,
#370), and the row's stop reason is the field that shows what the upstream
said; it was recorded in usage.jsonl and lost on the way to every reader.

Run: TestRequestPageKeepsUpstreamStop (the reporter's row, through
Append and QueryPage twice, cached; the packed chunk round trip; the CSV
column) fails with rowText put back ("the upstream's stop reason was
dropped from the page's row") and with the CSV cell left empty ("CSV"),
passes with the change. TestRowTextHoldsEveryString fails with
TierServed left out ("Record.TierServed comes back from the packed row
as \"\""). TestLedger* updated for the new column. go test
-tags nogui ./internal/usage/ ./internal/cli/ ok. gofmt, vets and the
gateway suite: in the series' last push record below.
2026-10-13 16:34:59 +08:00