9f0c9593 caps the memo at 8 ranges and stamps each with time.Now() when
asked. Its test only checked the count and that the newest range stays,
which passes with the eviction reversed (k.used.After) or with a hit that
doesn't restamp. TestStatsMemoKeepsTheRangeAskedAgain fills the memo, asks
range 1 again, adds one more and checks 1 is kept and 2 let go.
The stamp is now the memo's ask count: Windows' clock can read the same
for two asks in a row, so with time stamps the range asked again could
tie with one asked once and either could go.
Run (macOS, go1.26.8, sandbox HOME, private caches):
- reversed comparison (> for <): the new test fails, "the range asked
again was let go before one asked once"; a hit that doesn't restamp:
the same failure. Both pass with the change.
- go test -tags nogui -count=1 ./internal/gui ./internal/plugin: ok.
- gofmt -l clean; go vet on both packages for darwin, linux (nogui) and
windows/amd64; go build for darwin, linux nogui and windows.
Not run: the whole suite (machine loaded), the new test on Windows.
statsFor keeps a whole sessions.Stats per distinct ?days= value, and
only forgetStats ever emptied the map. Each new number a caller sent
added a snapshot that stayed until a session was deleted, restored or
purged. Now the memo keeps the 8 most recently used ranges.
Run before this commit (Linux, WSL2 Ubuntu 24.04, official go1.26.8):
the new test fails with the fix reverted and passes with it;
go test -tags nogui ./internal/gui ./internal/plugin is ok. Both
builds were compared with magpie web on a sandbox copy of a real
~/.codex/sessions: all 10 stats/overview answers byte-identical, and
300 distinct ?days values left HEAD's memory up 21-25 MB against 6 MB
for this change.
macOS was not run here; CI's macOS job runs the new test.
Reviewed for magpie (CaramelizedCUDA/magpie pr/stats-memo-cap at 05f0afa4, cherry-picked onto f340aecab, then rebased onto 6ccf23efa and run again there): on macOS, go1.26.8, sandbox HOME, TestStatsMemoKeepsAFewDays fails with the cap turned off ("the memo holds 64, want at most 8") and passes with it. The next commits add a test for which range goes and stamp by ask count.
Co-Authored-By: Claude Code <noreply@anthropic.com>