Pi's and omp's calls (#1951) were read by a whole-file reader: every
time a session file grew by one line, Usage's ledger decoded the whole
file again, its header and every message, and rewrote its disk shard.
Pi and omp only append to a session file, a line an entry, as Kimi
Code's wire file is.
Pi and omp are now line readers (lineCallReaders): a file that only grew
is read on from the last whole line, and only the calls it adds are
appended to the shard. What a later line's call is read with is carried
in piCarry on the callFile: the header's cwd, a fork's start (what came
before it is its parent's), and the provider and model in use for a
compaction's or tool result's usage. That carry is kept in the shard's
state too, flat (callDiskState.Pi*), as the in-memory read is let go
after packing: a carry that lived only in memory made every append read
from 0 again. A shard written before has no carry (piCallsKept false)
and its file is read whole once more. Cut shorter, written over, or
grown at a changed head: read whole again (prepareCalls' head and
prefix hashes, as for Kimi).
Measured (CPU, getrusage; one 50 MB Pi session, ~3500 calls, a call
appended between reads; the old reader measured from a worktree at
432a2ba5e with the same harness; machine at load ~500):
before: 112-153 ms CPU, 1.0-2.5 s wall per read after an append
after: 1.1-3.1 ms CPU, 5-57 ms wall per read after an append;
first read ~95 ms CPU, as before
Test: TestPiCallsReadOnlyWhatWasAppended (a fork, its model set once at
the top, compaction usage) checks where each read starts (scanHook) and
the calls it gives: an append with a half line after reads from the old
end and leaves the half line; finished, it is read; a line older than
the fork's start is left out after a resume as on a whole read; the
model, provider and cwd stay right on calls read on; after resetCalls()
the read resumes from the disk shard; cut shorter and written over read
from 0.
Broken by hand: piCallsKept always false -> red ("read from 0, want
686"); the carry not written to the shard -> red (same); begin run on
every read, the carry lost -> red ("calls [1 2], want [1 2 3]").
Run: go test ./internal/sessions -run 'Pi|Omp|OMP|Call|Usage' -count=1
ok; gofmt -l and go vet ./internal/sessions clean. The full-suite record
is in the last commit of this series.