loggedAnswers, which leadFirst falls back to when affinity has lost a
Codex subagent's lead, read thirty days of the log into a Record a row
and kept the rows of one conversation. usage.VisitSessions reads only
those rows: a block whose Session and NativeSession strings don't name
the conversation is skipped, a row of another session is passed over by
its shape's string ids without becoming a Record, and a matched row's
strings are cloned out of the lent decode buffer. Each packed block's
sessions are kept once it is decoded (blockSessions, by weak pointer, so
no block the log let go is held), so a lookup decodes only the blocks the
conversation is in and the open tail. A page's copy with Codex
identities (which rewrite Session as a row is read) is read whole and
filtered on its records.
Run on mote (macOS 27.2), at load ~70:
- BenchmarkLeadLookup (40 blocks of 3000 rows, one conversation of 300):
visit+filter 39-56ms and 2.9MB an op; VisitSessions 0.38-0.52ms and
12KB.
- A copy of the owner's real usage.jsonl (8,853 rows, 1,270 sessions,
18 blocks): every session looked up both ways gives the same records;
6.9ms a lookup before, 3.4ms for the first and 0.39ms after, 14us for
a conversation that isn't there.
- TestVisitSessionsIsVisitOfThoseSessions, red with the shape filter's
session ids taken out; TestVisitSessionsRecordsKeepTheirStrings, red
with the clone taken out; TestVisitSessionsSkipsBlocksOfOtherSessions,
red with the known-sessions skip taken out.
- GOOS=windows go vet; GOOS=linux -tags nogui go vet: ok. gofmt -l: clean.
- go test -race of the new tests and the gateway tests of a lead's
answers, in internal/usage and internal/gateway: ok (4.4s, 31.3s).
- go test ./internal/usage ./internal/gateway (whole packages) was
still running on mote at load ~190 when this was pushed; its result
goes on #4370.
Not tried: a real Codex subagent whose lead lost affinity; the lookup's
callers and filters are as they were, and the gateway's loggedAnswers
tests cover them.