Usage › Sessions lists only the stats' keys, and the keys named only the
agent files this computer reads. A Docker magpie in gateway mode reads none,
so the sessions that came through the gateway were counted and not listed.
MergeExternalStats now puts them in the keys too, in the list's order.
Run (mote): go test ./internal/sessions ./internal/gui -run
'TestGatewayStats|TestGatewayMode' ok; GOOS=linux go vet -tags nogui ./...
and GOOS=windows go vet ./... clean, gofmt -l clean.
Broken by hand: on the old code the unit test's keys are [claude:a] and the
gui test's [] (gateway mode off, days=0).
Not tried: a real Docker magpie; the full suite (mote rebooted mid-run).
Reported-by: linkaww on Discord
MergeExternalStats grew a copy of every native Summary to append the
gateway-only sessions, and cloned them all again, with their days, when
the gateway's history began before the session files. Each range the
Sessions page keeps (7, 30, every day) held that copy beside the
Summaries it was copied from: ~10 MB over the full history, made again on
every 10 s refresh.
Stats now keeps the gateway's Summaries in their own slice, sorted by
Last, and a day shift instead of rewritten days. Overview walks both in
the order the merged list had (the most recent first, a native session
first of two as recent), adds the shift to each day, gives toolUse the
shifted first day, and shifts the Top copies it hands out. AllSessions
gives the merged list as one copy for the tests that read it.
Overview is the only reader of the merged sessions outside tests:
aliasStats and keepDesktop run before the merge, and the stats answer
doesn't encode Sessions.
Run on mote at 86e19b9b7 plus this change:
- go vet ./internal/sessions ./internal/gui ./internal/cli: ok;
GOOS=linux and GOOS=windows go vet ./internal/sessions: ok.
- go test ./internal/sessions ./internal/cli: ok.
- go test ./internal/gui: ok except TestCoveredWindowStaysUp, killed at
30s. It fails alone too, at load ~21. #4125 covers it: on mote every
AppKit test hangs while launchd throttles it. This change doesn't touch
window code.
- TestGatewayStatsMergedBesideNative (new) goes red three ways by hand.
With Sessions cloned in the merge: "the native sessions were copied".
With a gateway session first of two as recent: "merged [g2 a g1 b]".
With Top and toolUse unshifted: the overview differs from a merged
list's.
Real history on mote (advov.sh, the full-history HOME, v0.1.2287 =
rel2 against this change):
- cold peak phys_footprint: 355/352/362 MB against 358/355/358 (noise:
the cold peak is the requests warm-up, not this);
- warm start: 249/262 MB against 258/274;
- /api/sessions/overview and /api/sessions/stats for days 0, 7 and 30
are byte-identical between the two builds in both warm runs.
Rebased on origin/main after the run. The 9 commits it brought in
(gateway, usage window_holds, gui Long conversations, workbuddy min)
touch nothing under internal/sessions. After the rebase, internal/sessions
and the gui gateway-session tests were run again (below).
- At the rebased head on c272e5582: go vet ./internal/sessions
./internal/gui ok; go test ./internal/sessions ok; go test
./internal/gui -run 'Gateway|Stats|Overview|Desktop|Budget' ok.
Each range statsFor keeps (all days, and 30, warmed at start) holds a
Summary for every session, and each had four maps (tools, skills,
skillLast, perDay) plus a tools map in every day. Most hold one or two
names, and a Go map of one is a few hundred bytes. They are now
counts (name, calls, a skill's last date) in the names' order, and
perDay a slice of days in order; the build still sums into maps and
hands those over once.
Run at this head (8ab4fd612 + this change), in a sandbox HOME with the
real ~/.codex and ~/.claude sessions (15,921 files), warm start, two
alternating runs each, 40 s after settling:
before: footprint 174 / 178 MB, live heap 104 / 104 MB
after: footprint 165 / 170 MB, live heap 97 / 96 MB
Both builds side by side on the same files, /api/sessions/overview at
days 30, 0, 30&agent=codex and 0&agent=claude, and /api/sessions/stats
at 30: stats identical; the overviews differ only in the title length
8ab4fd612 changed and in today's counts of the Claude sessions being
written between the two reads (codex-only: titles alone).
go test ./internal/sessions ./internal/gui ok; ./internal/usage red
once on TestUsageReadAfterAppendHashesNothingOnAFineClock's whole-second
case (#3511, #3551, untouched here), 5 of 5 ok rerun. gofmt clean;
GOOS=linux and GOOS=windows go vet -tags nogui ./internal/sessions ok.
What changed: the Sessions page lists sessions seen only through the
gateway (from the usage ledger, read-only, a native session of the same id
wins), and shows in gateway mode. A Sessions switch, off by default and
confirmed before it turns on, records each gateway exchange's text under
the config dir (scrubbed, at most 7 days and 256 MiB, cleaned hourly).
Settings sync and restore can't turn it on; POST /api/sessions/recording
turns it on or off and can clear what was kept.
Why: users of magpie as a gateway (gateway mode, LAN clients) had no way
to see their conversations; the owner chose this design on the PR.
Squashed from PR head 6a343ba1 onto origin/main. Conflicts: gui-shell.md
(kept main's placeMenu text, took the PR's Sessions in gateway mode) and
settings_keep_test.go (main's fields plus GatewayConversations).
Run: go build ./..., go vet on gateway, gui, sessions, settings, usage;
go test -race -timeout 900s on those five packages: all ok.