Files
magpie/internal
yetone e979553ba1 sessions: a start doesn't read Claude Code forks' uuids again to judge them (#2278)
Each start judged every group of Claude Code files that start alike
(ccFamily), then read what each copy or branch holds that its keeper
doesn't (ccRest). Both read every file's message uuids through
scanThin, and what they found was kept in memory only: ~0.2-0.25 s of
CPU on each start for a real history with forks, and a uuid set held
for each file.

What a group came to depends only on its files, so it is kept in
cc-families.json next to sessions.json, by a hash of each member's key,
path, size, change time, first and last message and start; a group none
of whose files changed is not read. A copy's or branch's rest is kept
in cc-rest.json by both files' path, size and change time, encoded the
way the parses are (encodeCache), so another time zone, cache version
or parser version reads it again. Both are written behind mu through a
temp file renamed over the last, in order; Saved and Reset wait for
them. Groups unused for 30 days are dropped.

Run (mote, at this tree):
- go test ./internal/sessions ./internal/usage ./internal/gui: ok
  (128 s, 64 s, 151 s); GOOS=windows and linux go vet
  ./internal/sessions: ok; gofmt clean.
- New TestClaudeFamilyKeptAcrossStarts: a start after one that judged
  the group reads no file's uuids, and a copy that went on with a turn
  is judged again (a branch). TestClaudeBranchRestKeptAcrossStarts: two
  starts count the same 80 tokens in and read no uuids.
- Broken by hand: ccFamilyKept always nil -> the first test red ("read
  the uuids of 3 files"); ccRestLoad never reading -> the second red
  ("start 0 read the uuids of 1 files"). Dropping size and mod from the
  group's hash left the first test green: the changed copy's last
  message changes the hash anyway; size and mod are there for a file
  rewritten in the middle.
- Real accounts (acctp sandbox, pprof of the first 40 s of a start with
  the page open): sessions.Warm 0.78/0.79 s -> 0.52/0.57 s, statsKept
  0.39/0.43 -> 0.18/0.21 s, ccFamily/ccUUIDsOf gone from the profile;
  pageheap: CPU at mark 2.84 -> 2.65 s, Footprint 132 -> 127 MB,
  liveHeap 80.2 -> 78.4 MB. The first start of the new build reads and
  writes them once (2.70 s at 40 s, as before).

Not tried: Windows and Linux real starts; the files are plain JSON in
the cache folder.
2026-11-13 11:18:30 +08:00
..
…
…
…
…
…
…
…
…
…
…
…
…