combinedSessionStats, behind /api/sessions/stats and /overview (each
range read again in the background when its memo is over 10 s old, so
on every 15 s poll of the Sessions page), took sessions.StatsFor and then
sessions.List(All) only for the agent|id set that keeps a gateway session
the agent keeps too from counting twice: two passes over every agent's
files, each refreshing them all. sessions.StatsAndNative gives both from
StatsFor's one pass: the same set, a session List would list (one
nothing was said in still left out, as before), but with no 5000 limit,
so a gateway session whose native one is among the oldest of a long
history is no longer counted again.
Test: TestStatsAndNativeOnePass: one pass over the files (filesHook, new),
and the same keys as List(All) on the fixtures. Red with StatsAndNative
written as the old pair of calls: "2 passes over the files".
Measured on the synthetic sandbox HOME (3000 Claude Code, 1500 Codex,
2000 Hermes sessions), combinedSessionStats warm after a restart, CPU
time (load average ~250, wall times noisy), parent 8e2b1dce6 against
this change, 4 rounds each:
days=30 94-99 ms -> 57-62 ms CPU
days=0 107-130 ms -> 68-74 ms CPU
first after a restart (days=30) 558 -> 510 ms CPU
Run at this commit (the series' last; it covers 0179cef63, bbee24810
and 8e2b1dce6 too), on a machine at load average ~250-500:
- go test ./... -timeout 45m: 60 packages ok, sessions (869.8s), usage
ok. Red only under that load, all green when run again:
- internal/agent and internal/gateway timed out at 45m in tests that
don't touch sessions (TestPiOffersItsOwnOpenAICodexModels,
TestVisionSettingPicksTheDescriber). Run again with -timeout 90m:
agent ok (1394.2s), gateway ok (1546.9s).
- internal/gui TestSetAnswersWhileDevinAndProvidersHang: set took
44.6s under load; it is #1375. Alone: ok.
- internal/plugin TestGatewayHookMixedPiPackage: "starting plugins:
context deadline exceeded" after 718s (bun's install cache was slow).
Alone: ok (163.6s). No issue found for it.
- gofmt -l: clean.
- GOOS=windows go vet ./...: ok.
- GOOS=linux go vet -tags nogui ./...: ok. Without the tag, vet stops in
wails v3's own linux files (undefined: pointer, cgo off when vetting
across OSes from macOS); go.mod is untouched here.
- No GUI assets changed, so the GUI suite was not run.