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.
HoGee_xxl wants their own usage app to read magpie over the gateway,
which had no /api/usage counterpart, and asked for subagents' parent ids.
- GET /v1/magpie/usage (the /api/usage summary, ?period=) and
GET /v1/magpie/usage/requests (the /api/usage/requests ledger page, same
filters, offset/limit) on the gateway. The builders moved out of gui into
internal/usageapi so both serve the same JSON; gui keeps aliases and sets
usageapi.Clients for agent names (gateway can't import agent). Guard as
/v1/magpie/quotas: this machine, or another with an enabled gateway key,
behind the same Host check. A key held to a budget, models or accounts is
refused the summary (403) and gets the ledger filtered to its own
CallerKey, with callerKeys/agents/providers/accounts cut to its own rows
(usageapi.OwnPage): those facets are drawn from every call in the period.
`path` is left out for another machine.
- usage.Record gains subagent and parent_agent; session stays the parent
conversation. Gateway rows take them from x-claude-code-agent-id and
x-claude-code-parent-agent-id; session-file rows from the file name
(<session>/subagents[/workflows/<run>]/agent-<id>.jsonl, no cache version
bump) and the parentAgentId of the agent-<id>.meta.json beside it. Both
packed into the request page's text columns (now 29, msg at 29).
Codex sub-threads: only kind, as before; no spawned thread on disk to
take a parent shape from.
Run: real Claude Code 2.1.296 under a sandbox CLAUDE_CONFIG_DIR against a
local fake Anthropic endpoint that made it spawn a subagent from a
subagent: the nested request carried X-Claude-Code-Agent-Id=a143287ac46b82a96
and X-Claude-Code-Parent-Agent-Id=a99ca20c03d1813d8, the first-level one
the agent id only, Session-Id the parent's throughout; the nested meta.json
had parentAgentId. Tests use those bytes. TestUsageOverGateway goes red
with OwnPage, the CallerKey pin, or the header read removed (each tried).
gofmt -l clean; go vet ./...; GOOS=linux go vet -tags nogui ./...;
GOOS=windows go vet ./...; set -o pipefail; go test ./... green.