ac4af582301a4e8a29245dbba767eba31334ddf9
2
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
2140f5b935 |
sessions: a plain Codex rollout read from its start has its calls read on the summary's pass (#4369)
A start parses every changed session file for Sessions (refresh ->
parseWith), then reads every changed file's calls for Requests
(ReadCallSource -> readCalls). callsAlong already let a packed rollout
and an unread Claude session be read once for both; a plain .jsonl
rollout was read twice. On copies of the owner's real ~/.codex and
~/.claude (1.7 GB), a cold start scanned 931 times, 3.49 GB, every large
rollout x2.
callsAlong now takes a plain rollout too, when both reads start at its
first line: the summary it goes on from has no Codex window (nothing
kept, or kept on disk, which holds none), and parseWith lets the ride go
when either read goes on from an offset (calls.st.Off as well as s.Off),
so a read on from where it was is two incremental reads, as before. A
summary that still has its window is passed in so such a file's calls
shard isn't loaded only to be let go.
keepCalls names the root when none is named yet. A ride keeps a
rollout's calls (Codex window and all) during the Sessions parse, before
any Requests read has called pruneCalls; pruneCalls took the empty root
for a moved one and dropped everything kept. The shard on disk has no
window, so the next line read the rollout whole again (in the same run,
seconds after the start). TestHistoricalClaudeFilesDoNotDisplaceActive
Windows went red on exactly that ("rebuilt active call shard" for its
Codex rollout) until this.
TestWarmReadsOnlyInItsSlots' calls phase found nothing left to read,
since the index phase now reads every file's calls along; it appends a
line to each source first, so the calls have reading of their own.
Tests' forget (in the new test, claude_ride_test.go and
codex_zst_warm_test.go) calls Reset before removing the cache file:
Reset writes a save still pending, which put back the file just removed,
and the next List then went on from disk states (no window), red 1 in
~40 under -race. TestHistoricalClaudeFilesDoNotDisplaceActiveWindows
waits for the save (saved()) before writing its marker onto a cached
state the save's goroutine was encoding (a DATA RACE under -race).
Run on mote (macOS 27.2):
- TestPlainRolloutReadOnceForSessionsAndCalls (new): 3 plain rollouts.
Nothing kept: each scanned once, from 0. Read, kept on disk, the long
one grown and Reset: that one scanned once, from 0. An append in the
same run: no scan from 0 (with keepCalls' root line removed by hand:
"an append: the long rollout read again from its first line:
[213219 0]", and the Historical test red as above). Calls, List and StatsAt reflect.DeepEqual to
a calls-first read without the ride in each case. With plain rollouts
kept out of callsAlong by hand: "first read: ... scanned from [0 0],
want once from 0" for all 3. Restored: ok. -race -count=80 with
the Packed, ClaudeSessionReadOnce, CodexSessionReadOn, Historical and
WarmReads tests: ok (108.8s)
- Real data (copies of 1.7 GB of the owner's sessions, probe run
sessions.List(200), usage QueryPage Today and Week; probe not
committed): cold 931 scans / 3.49 GB -> 718 / 2.10 GB, no rollout read
twice; no change 0 / 0; the first line appended to the newest rollout
after the cold read: read whole by both readers -> read whole once
(1 scan, 10.8 MB; the before run's newest was a 21.5 MB one, read
twice). It is read whole at all because it was last changed on 10-31,
past any window's idle time: a session left that long is read whole
once on its next line, now in one pass. Later lines: 2 scans, 0 MB.
- go test -timeout 45m ./internal/sessions ./internal/usage
./internal/gateway ./internal/gui: ok for sessions (11.3s, -race 56.2s, at this tree), usage (30.2s), gateway (575.6s); internal/gui: ok but TestMainWindowCorners/macOS_26_SDK, red on macOS 27 as #3949 records (same message), untouched here
- GOOS=windows and GOOS=linux go vet ./internal/sessions: ok. gofmt -l:
clean.
Not tried: a packed rollout's path is unchanged (it rode before).
|
||
|
|
5466cc7604 |
sessions: a packed Codex rollout whose stamp changed is decompressed once at start, for both Sessions and Requests
The start's warm-up (gui warmSessions) parses every changed session file
for the Sessions page (statsFor -> refresh -> parse), then reads every
changed file's calls for Requests (usage.QueryPage -> prefetchSources ->
ReadCallSource -> readCalls). A packed rollout (.jsonl.zst) is decompressed
whole for each read, so when the Codex app repacked all 11,591 of them on
10-20 every one was decompressed and scanned twice (~48 GB of zstd read
twice; 75 GB of zstd allocation in 67 min, 37.8 GB on each path through
scanAt).
refresh's reader now takes a packed Codex rollout's calls along
(callsAlong) when their shard is stale too: one scanAt, each line shown to
both heads (codexHead, callHead) exactly as on a scan of its own, and
handed to codexBody and/or codexCallLine as each head asked. The calls
are then written and kept as readCalls would (writeCalls, keepCalls under
the generation check), so the Requests read that follows finds an
up-to-date shard. The ride holds the file's calls lock, taken before the
read slot as readCalls takes it, so a readCalls of the same file waits for
the ride rather than read it again, and no lock order is reversed. A scan
that fails leaves the calls to readCalls, as before. Plain rollouts, other
agents and a file whose calls are already current are read as before.
The warm-up already reads with a quarter of the cores (quiet.go: readSlot,
#1665) on both paths; this halves the work done under that cap, nothing
more is changed there.
Verified (sandbox HOME, Go caches pinned):
- TestPackedRolloutReadOnceForSessionsAndCalls (new): 3 packed rollouts
(the two fixtures + a 40-call one). Calls-then-sessions scans each twice
(the reference); sessions-then-calls with nothing kept, and again after
every file's mtime changes, scans each once, and the calls, List and
StatsAt are reflect.DeepEqual to the reference. With callsAlong replaced
by nil in refresh it fails: "first read: ...zst scanned 2 times, want
once" for all 3 files, and the same after repacking (6 errors). Restored:
ok. -race -count=20: ok.
- Real rollouts: copies of 120 and of 180 of ~/.codex/sessions' packed
rollouts (528 MB / 739 MB compressed), warm-up order (List, StatsAt, then
ReadCallSource with 8 readers), with nothing kept ("cold") and after every
mtime changed ("stamp"); old = callsAlong nil:
120 files, full speed: zst scans 240 -> 120; wall cold 0.84/0.90s ->
0.52/0.48s, stamp 0.99/0.70s -> 0.43/0.52s; alloc 0.45-0.48 GB ->
0.43-0.44 GB cold, 0.38-0.41 GB -> 0.38-0.39 GB stamp.
180 files, inside sessions.Warm (3 readers of 14 cores): zst scans
360 -> 180; wall cold 1.97/2.18s -> 1.48/1.59s, stamp 1.89/2.22s ->
1.35/1.63s; alloc 0.57-0.63 GB both ways.
Lists, stats and every source's calls, JSON-encoded, are byte-identical
old vs new in all four phases (cmp).
Allocation hardly moves: in a pprof of the 120-file run, 482 MB of ~800
MB is scanAt gathering lines longer than its 1 MiB buffer (the packed
rollouts' multi-MB session_meta lines), which only one of the two
readers ever gathered, and zstd's own history buffers are 120-144 MB.
What the change saves is the second decompression: CPU and disk reads.
- gofmt -l on the changed files: nothing. GOOS=linux go vet -tags nogui
./... ok; GOOS=windows go vet -tags nogui ./... ok.
- go test -timeout 45m ./internal/sessions/ ./internal/usage/
./internal/gui/: ok 13.8s / 17.1s / 81.7s. go test -race
./internal/sessions/: ok 44.5s after the next commit's test fix (red on
origin/main
|