shangyuan0818 on X, on the latest Windows build: after using an agent,
Sessions took 18 s to load. They had ~100 Claude Code sessions of 30 to
100 MB and read Claude Code only, and guessed it was dedup, since
ccusage is slow on the same files.
Cause: older `claude --resume` wrote each resume as a whole copy of the
session under a new sessionId. ccFamily judges such a group by every
file's message uuids (ccUUIDsOf), and ccRest reads each copy for what
its keeper doesn't hold. Both were kept in memory only. cc-rest.json
kept the rests, but without the uuids they were read from (ids nil).
After a start, the first turn of the session the copies are kept in
changed the group's signature and its size, so every file of the chain
was read whole twice: gigabytes before Sessions showed. Codex is not
read with Claude-only reads (the cold load is the same with its folder
empty).
Fix: the uuids of each file of a group are kept on disk, one file each
in cc-uuids/ (named by a hash of the path), with the size, mtime, the
offset read to and a prefixHash of the bytes up to it. A start reads
them back and goes on from the offset only while the hash still
matches the file's start; otherwise the file is read from its start.
The rest ids are kept in cc-rest-ids.bin under the rest's key, so a
keeper that only grew leaves its copies unread after a start too.
Entries whose session file is gone are pruned once a start. Trash
drops an entry. Reset forgets the in-memory uuids, like a real start.
Not changed: a first start (no cache) still reads each copy three
times (parse, ccUUIDsOf, ccRest), filed as #7143.
Windows (xiaomi-gpu, Windows 11, CGO_ENABLED=0 builds, Claude-only
reads, sandbox HOME). The fixture is 5 resume chains of 20 files, 30 to
107 MB each, 6.9 GB. Time is for the page's three requests together.
origin/main this change
cold, no cache 20.2 s 17.6 s
warm restart 0.30 s 0.30 s
restart after 1 keeper's turn 3.29/3.14 s 0.38/0.25 s
1 keeper's turn while running 1.60 s 0.11 s
restart after 5 keepers' turns 7.25 s 0.92 s
5 keepers' turns while running 3.32 s 0.78 s
The profile of a restart after a turn on origin/main was ccFamily →
ccUUIDsOf (1.23 s) and ccCopyStates → ccRest (1.14 s) in scanThin.
The kept uuids take 2.4 MB for the fixture's 100 files.
Tests (internal/sessions/cc_copies_test.go):
- TestClaudeKeeperTurnAfterAStartReadsNoCopy: a turn, then Reset, reads
no file from its start, and the turn is counted.
- TestClaudeKeeperTurnTheBranchHeldAfterAStart: a keeper that grows,
after a start, with a message the branch held on its own counts it
once.
- TestClaudeKeptUUIDsOfAFileWrittenOver: an entry whose file was
written over doesn't stand.
- TestClaudeKeptUUIDsRoundTrip.
Run at this tree:
- go test ./... -count=1 -timeout 45m on mote: 102 packages ok, 2
red, both filed: internal/cli's TestHealthcheckFindsTheRunningGateway
WithoutMagpieAddr, TestUpdateRestartsTheGatewayItFindsWithoutMagpieAddr
and TestUpdateFindsAMagpieThatWroteNoRecord (#6471, #6223: they ask
whatever serves 127.0.0.1:3425 on mote), and internal/gateway's
TestOpenCodeGoOwnFreeModelGetsNothingOfOpenCodes (#7117, red on main).
- go test ./internal/sessions -race -count=1 -run TestClaude -timeout
25m on mica: every new test passes; 2 reds, both data races filed and
outside this change: TestClaudeCdKeptParseReadAgain (#6213, red the
same at 0e3d09361 on mica) and the claude-desktop-3p subtest of
TestClaudeTraceSubagentsShareSessionWithoutIDCollisions, failed by
testenv.Zone's cleanup against provider's sweepStale timer (#4360).
A first try at -count=3 hit go test's default 10m timeout mid-run
(3 x ~240s under -race), not a hang.
- go vet ./internal/sessions on darwin, GOOS=linux and GOOS=windows
(mote): clean. gofmt -l: clean.
- win-run go test ./internal/sessions: 4 reds, TestAgySessions,
TestAgyRowOnly, TestAntigravityAppFolder and
TestCCListingKeepsItsNames. The same 4 are red at origin/main
0e3d09361 on the same box, filed as #6071.
- No GUI test reaches this: the GUI tests fake the API, and no asset
changed.
Broken by hand:
- kept uuids not read back (ccUUIDKept ignored):
TestClaudeKeeperTurnAfterAStartReadsNoCopy red, all three files read
whole on each turn.
- rest ids not read back: that test red, the two copies read whole.
- rest ids read back as empty: TestClaudeKeeperTurnTheBranchHeldAfterAStart
red, 90 tokens in where 80 are wanted.
Not tried: the reporter's own files, or a real Claude Code --resume
chain (the fixture is generated in that shape). Not tried on a slow
disk or with Defender scanning, which the reporter's 18 s may include.