Commit Graph
20 Commits
Author SHA1 Message Date
Flandern1211 a39b63e886 sessions: a ZCode session is listed once, and its draft folders are one group
A ZCode request names its session by the id its database gives with a
prefix stripped (sess_…, a subagent's sess_subagent_agent_…: zcodeBareID,
which Titles already used for names), while GatewayKeys kept only the
prefixed id. MergeExternal therefore matched no native session for any
ZCode session sent through magpie's gateway, and each was a row under its
folder and again a row under "Seen through the gateway" with no files
behind it. On this computer's database (1,105 sessions, 3,536 gateway
records) that was 70 of 70 gateway rows: 38 top-level sessions, 9 forks,
23 subagents. A group already holds its forks' and subagents' files
(ocRoots), and assembleListed counts every file's calls in the row, so
each of the 70 counted the same calls a second time.

GatewayKeys now gives the bare id of a ZCode session and of its forks and
subagents; externalAdded reads GatewayKeys instead of keeping its own copy
of the keys in pairs; idInFile names ZCode, so subIDs collects the ids
their own rows give (their files are in the group, no row lists them
apart). The Sessions page draws a ZCode session whose folder ZCode made
for that one session (~/.zcode/workspace/<draft|time>-<uuid>, one for
each session started without a project) in one "Scratch sessions" group
after the projects: 42 of them here were 40 folders of one session under
Other folders, and they are no projects of the reader's. cwd, files and
usage are untouched; a row's tooltip gives the folder it ran in.

The list went from 1,286 rows to 1,216 over the same 1,213 native ones;
the 70 gateway rows had 34.3M input and 2.59M output tokens and $125.66
of the ledger's cost on top of the rows that already counted those calls.
A ZCode row now prices its own calls from the catalog like every other
agent's, and Usage keeps the ledger's figures.

Run:
- go test ./internal/sessions -run 'TestZCode' -count=1: ok.
- go test ./internal/gui -run 'Session|Gateway' -count=1: ok.
- go build ./...; go vet ./internal/sessions: ok.
- gofmt -l; git diff --check; node --check on client.js and i18n.js: clean.
- go test ./internal/sessions -count=1: the same failures as without this
  change (TestAgySessions, TestAgyRowOnly, TestAntigravityAppFolder,
  TestCCListingKeepsItsNames: path separators and allocation counts on
  this Windows box).
- go test ./internal/gui -count=1: the same failures as without this
  change (lody's %AppData%, pageservice's symlink privilege here).

Broken by hand:
- dropping the bare key puts the 70 rows back under Seen through the
  gateway (TestZCodeGatewayRowIsTheSessionItself fails);
- leaving ZCode out of idInFile keeps a fork's and a subagent's own rows
  as gateway rows while the group already counts their calls.

Not changed: the scratch group is worked out on the page (client.js), so
Usage's folder filter still lists the draft folders by their paths; the
group is ZCode's only, and other agents' per-session folders are left as
they were.
2026-11-09 18:49:15 +08:00
yetone 371b2b63a0 sessions: gateway mode lists the sessions the gateway counted
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
2026-11-08 02:37:09 +08:00
yetone 1829cd52ff sessions: a poll while a session grows makes only the rows it shows
VeryBTC on X (tweet 2117104179454091396) reported RSS that rises and
stays up while the window is open and a long-context session is active.
In that case every Sessions poll sees a changed file and rebuilds the
list. That rebuild copied every gateway-only session three times
(GatewaySessions, listedGateway, gatewayListed) and made each one a
Session row before EachMerged stopped at its 5000-row limit. It also
made every Claude Code file's path and key again.

- usage.EachGatewaySession walks the projection without copying it.
  gui's listedExternal stops at the list's limit and skips hidden
  sessions and sessions without an agent or id, as listedGateway did.
- sessions.EachMerged sorts indexes and makes a row only when the merge
  reaches it. The order is unchanged: newest first, stable on ties.
- listCCFiles reuses the last listing's path and key strings while a
  folder lists the same names. One file new or gone is stepped over.
  This holds ~32 B per file (~480 KB at 15k files), and the strings are
  shared with the listing it already held.
- page_memory.go's ~330 MB comment now has current numbers.
  gateway-sessions.md describes the lazy rows.

Per poll, on mote (go test probe through the real /api/sessions
handler, TotalAlloc):
  15k sessions x 10 turns, 400k ledger rows
    after a session file grows  150.6 MB, 201 ms -> 109.9 MB, 170 ms
    unchanged (warm)             17.2 MB         ->  12.0 MB
  3k sessions x 40 turns, 150k rows (no gateway-only rows past the cap)
    after a session file grows   31.3 MB         ->  29.6 MB
    unchanged (warm)              4.5 MB         ->   3.4 MB
  /api/usage is unchanged at 0.4 MB.

Tests:
- TestSessionsListMakesOnlyTheGatewayRowsItShows (gui) uses 3 natives,
  6000 gateway sessions in tied pairs, one hidden and one carrying a
  native's id. At limits 5, 40 and 6010, and with no limit, the rows
  equal the old pipeline's (listedGateway + gatewayListed +
  MergeExternal) after the JSON round trip. A grown native comes first
  with its new Last. The poll's allocation stays under 6000 rows' size.
- TestEachMergedMakesOnlyTheRowsItReaches (sessions): 15000 externals
  and 20 rows give MergeExternal's first 20, with allocation under a
  tenth of the rows.
- TestCCListingKeepsItsNames (sessions): a second listing of 3000 files
  is equal to the first, in at most 3n mallocs. A file added, files
  removed, and a folder gone with another new each list as a fresh
  listing does. Another agent's keys keep their own prefix.

Broken by hand, each red:
- EachMerged building every row first: 8.8 MB, the sessions test fails.
- The GUI handler back on the listedGateway(GatewaySessions) loop, with
  the lazy merge kept: 13.7 MB, the gui test fails.
- The gui test on origin/main's code: 23 MB, fails.
- The ccNames reuse turned off: 12197 mallocs, the listing test fails.

Run on mote (mote-run) at 73a1b8769, rebased on origin/main 07f4d46c5:
gofmt -l internal (empty), go vet ./..., GOOS=linux go vet -tags nogui
./..., GOOS=windows go vet ./... all clean. go test -count=1 -timeout
45m ./internal/sessions ./internal/usage ./internal/gui: sessions ok,
usage ok. gui is ok except TestMainWindowCorners/macOS_26_SDK, which is
#3949 (red on mote's macOS 27, an AppKit title bar test this change
doesn't reach). It was red the same way in the run before the rebase.

Not tried:
- A real app window with RSS measured over time. The numbers are
  allocation per poll from a probe.
- The rest of a changed poll: statsKept re-sums every session (~26 MB at
  15k), listing (~24 MB) and byKey (~9 MB). None was a cheap, safe
  change.
- Windows and Linux test runs (vet only).
- A gateway title store in the fixture. GatewayTitler's ReadDirs now run
  only for the rows shown.
2026-11-02 17:19:23 +08:00
yetone f506638690 sessions: the Sessions poll makes its rows as the gateway's sessions merge
/api/sessions copied every one of ~17k sessions into MergeExternal's
merged list, and MergeExternal made a set of every native session's
keys again to leave natives out of the gateway's, though
GatewaySessions had already left them out by the same keys. The rows
were then copied from that list.

EachMerged hands each session to the caller in MergeExternal's order
(newest first, a native before an external of the same moment) from
the list as List gives it and the gateway's sessions sorted alone, so
the handler copies each session once, into its row. MergeExternal
keeps its own copy and dedupe for its other callers; both share
externalSessions.

TestEachMergedListsWhatMergeExternalDid: same rows, field for field, as
MergeExternal for a sorted list, an unsorted one (sorted in a copy, the
caller's left as it was) and none; with and without externals; ties;
stops at false. TestEachMergedCopiesNoList: 5000 natives merge in under
a twentieth of the list's bytes. Broken by hand, each red:
  EachMerged over MergeExternal's list: 5,437,624 bytes for a
    2,480,000-byte list
  EachMerged making the native key set again: 394,352 bytes

Measured on mote's build against the real ~17k sessions (sandbox HOME,
APFS clones), 30 polls, against v0.1.2554's build:
  heap diff alloc_space   726 MB -> 701 MB (MergeExternal's 107 MB
                          gone; externalSessions 51 MB left, the
                          gateway's own sessions)
  CPU over 30 polls       4.44s -> 4.24s
  /api/sessions median    73ms -> 71ms

Run on mote: go vet ./internal/sessions ./internal/gui ok;
go test ./internal/sessions ok; ./internal/gui red only in
TestSettingsSaveKeepsWhatItDoesNotSend (#4739) and
TestMainWindowCorners (#3949), both red on origin/main 788057340.
Not run: the full suite, the GUI suite (the answer's rows are the same).
Then rebased onto 1e6a27d4f (gui: an icon's image URL; none of the four commits touch sessions or the Sessions handler); not rerun.
Then rebased onto 994cd4fb6 (gui: Rex switches to the tab magpie opens, through the app's); not rerun.
2026-11-01 14:39:38 +08:00
yetone e55bab72df sessions: the gateway's sessions are merged beside the native ones, not into a copy of them (#2278)
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.
2026-10-31 09:41:13 +08:00
yetone bcf0cfa232 sessions: usage counts a session Claude Desktop's Code tab ran under Desktop
CyberCaius on Discord: Usage's Claude Code filter listed Claude Desktop's
sessions. Desktop's Code tab runs Claude Code, which keeps the session in
~/.claude/projects like a terminal one; only each line's `entrypoint`
(claude-desktop, claude-desktop-3p) tells them apart. The calls were
counted under Desktop already (desktopEntrypoint), but the session, its
stats rows and its summary were Claude Code's, and the gateway's own
record of the session ("claude-desktop|<id>") wasn't matched with it, so
it could be listed twice.

The parse now keeps the entrypoint (state.Entry, on both the ccWhere fast
path and the full parse; cacheVersion 29) and a Code tab session gets
Session.App "claude-desktop". Its Agent, key claude:<id>, resume and
transcript stay Claude Code's. Stats rows and the summary use the app,
GatewayKeys and MergeExternal know the claude-desktop|<id> pair, the GUI
names it Claude Desktop, and Usage › Sessions filters by app || agent.

Run at the pushed tip (the AnySearch commit after this one, on
e8d42c02d): go test ./internal/sessions ./internal/library ok (mote);
go vet darwin, linux -tags nogui, windows over ./internal/... VET-OK;
i18n-keys ok; usage-sessions-desktop-app.test.cjs (new) 4/4 chromium +
webkit, en + zh, on the Linux box (on mote its webkit.launch timed out at
load ~40, before any page code).
This commit alone, before the last rebase (8bd8f50d5 on 1534474c8):
go test ./internal/sessions ok and the new GUI test 4/4 (mote).
Run at 7ec95b5dd (both commits on 1534474c8):
- gofmt -l clean; go vet darwin, GOOS=linux -tags nogui, GOOS=windows
  (mote): VET-OK.
- Full go test -tags nogui ./... -timeout 45m on the Linux box (wsl-run).
  Red only where origin/main eadeb89c4 is red on the same box, each filed:
  internal/agent install detection (#4033, #3548), internal/gateway
  Antigravity turned-away and TestCodexSpentGrokFailingIsTold (#4362);
  internal/cli TestAgentFieldNameShowsIt and
  TestEveryAgentFieldNameWritesNothing red in the full run, ok alone at
  this tip (#4247).
- GUI: i18n-keys and gui-de/ja/zh-tw ok on mote; the other sessions-*
  and usage-* files hadn't finished on mote when pushed.
- The whole GUI suite has not finished: a WSL run at the tip was about
  half way (2226 ok) when this was pushed, with reds only in files these
  changes don't reach (routing key models, panel name width, LAN
  addresses, Codex composer, Copilot GHE, gateway key limits, ...);
  they'll be checked against origin/main and filed on their own.
Earlier, before the rebase (da5f1e5bd on ffa07395e): full go test
-tags nogui ./... on mote, 80 packages ok.

Broken by hand, each red: stats not using appsOf (usage agent stays
claude); the Entry in claudeFull; the Entry in ccWhere (the test's first
line is an attachment so the fast path is taken); MergeExternal without
the App pair (3 sessions become 4); page.js's byAgent on agent only (GUI
test times out).

Not tried: a real Code tab transcript (none on this machine; fixtures are
written from the field names only). A Code tab that sends the plain
magpie key through settings.json env would be recorded by the gateway as
claude, not looked at. NativeIDs for claude-desktop doesn't read Claude
Code's files yet: #4333.
2026-10-30 14:38:22 +08:00
yetone 37527c7ad3 sessions: omp's subagents and advisor are their session's to the gateway, not counted again (Jumy on Discord)
omp's task subagent (Kid.jsonl) and advisor (__advisor.jsonl) each have
a header id of their own, and omp sends that id, not the main
session's, in x-session-affinity (seen in a real omp 18.9.1 run through
a fake upstream: the main session's requests carried 01a18ae4-555c-…,
the subagent's 01a18ae4-5671-…). magpie counts those files in the main
session, but the gateway's native keys held only omp|<main id>, so the
gateway's records of the subagent's and advisor's calls were added
again as sessions of their own: in Usage › Sessions' totals
(MergeExternalStats), in the Sessions list (MergeExternal) and in
NativeIDs.

Session.Subs (subIDs) now holds those ids, and GatewayKeys,
MergeExternal and nativeIDsWith take them as the session's own.
GatewayKeys takes Claude Code's Copies too, which the GUI list added
by hand beside it; the stats' native map already had each copy's own
group, so nothing counts differently there.

This is at most a second count of the subagent's and advisor's share,
not a ~1000x: it may not explain the whole ~900M Jumy saw. Not found
in the reader: omp's usage is per call (assistant messages only;
toolResult and compaction carry none), re-reads continue from the
offset only when the head and sampled prefix hashes match.

Tests: TestOmpSubagentsAreTheSessionsToTheGateway (sessions, the
existing omp fixture, whose sub headers match omp 18.9.1's) and
TestOmpSubagentCountedOnceWithTheGateway (gui, /api/sessions/overview
and /api/sessions, from omp 18.9.1's own lines). Broken by hand
(subIDs returning nil): both red, the overview showing the Kid id as a
second gateway session with 5000 input beside the native one.

Run on mote: go test ./internal/sessions -run 'TestOmp|TestRaft',
./internal/gui -run 'TestOmpSubagent|TestTopSessions'; gofmt -l;
go vet, GOOS=linux go vet -tags nogui, GOOS=windows go vet on the two
packages; go build for darwin, linux (nogui), windows.
go test -timeout 45m ./internal/sessions ./internal/gui ./internal/usage:
sessions and usage ok; gui red only in TestMainWindowCorners/macOS_26_SDK,
#3949 (mote's macOS 27, titlebar code this change doesn't reach). The
full ./... was not run before the push: mote had other sessions' full
suites running at load ~180.

Not tried: Jumy's own session files or ledger (not available), so the
rest of the 900M is unexplained; Kimi Code's subagents (it sends no
session header magpie knows, so its gateway rows aren't sessions);
the GUI Playwright suite (no asset changed).
2026-10-30 11:54:46 +08:00
yetone 7db0810b03 sessions: stats asked again unchanged are not encoded again; lists made at their size (#2278)
The Sessions page asks for /api/sessions/stats (7, 30 and every day) and
the list every poll. On a full history (52G Codex + 13G Claude) the
stats for every day are ~6 MB of JSON, encoded and hashed again on each
ask even when the page already had them, because the read behind every
10s replaced the kept stats with an equal copy.

- statsKept has a gen, kept when the read behind finds the same stats
  (sameStats: From, To, Keys, Days, what is sent). The handler keeps the
  tag last sent per ?days with its gen and agent names, and an ask with
  that tag is answered X-Magpie-Same without encoding. Only the 32-char
  tag is kept, no body.
- MergeExternalStats grows Sessions once for every external session; a
  Clip and then an append a session copied the whole list over and over.
- listSessions makes its page and its latest map at their size.

Run on mote at this head (rebased on 484bdca7c, run again after):
- go test ./internal/gui/ ./internal/sessions/: sessions ok; gui ok but
  TestMainWindowCorners/macOS_26_SDK, red on mote's macOS 27 the same
  without this change (#3949).
- GOOS=linux/windows/darwin go vet -tags nogui on both packages, gofmt.
- Broken by hand: the read behind always taking a new gen makes
  TestStatsTagKeptWhileTheSame red ("gen 2, want 1 kept").
- Real full history on mote, magpie web polled with the page's
  X-Magpie-Had, 10 endpoints every 5s, cur = cdf8151a2:
  alloc in 60s 1755 MB -> 1342 MB; bytes.growSlice 393 -> 105 MB;
  CPU in 60s 4.25s -> 3.60s, GC mark 1.28s -> 0.88s.
Not tried: the Windows and Linux apps; the encoding is the same code.
2026-10-30 08:32:57 +08:00
yetone 68b31ce236 sessions: a poll's file lists, merges and copy groups are made once (#2278)
Each Sessions or Usage poll listed every agent's files several times and
copied the Claude Code and Codex lists twice: callFilesWith made a
deduplicated slice and set, then callSourcesWith and allFiles appended to
it and deduplicated it again. Now callFileLists hands out the lists, and
distinctOf builds one slice and one set at their combined size.

More cuts on the same poll path:
- allowed (the read-consent gate, af8f3a939) gives back its list as it is
  when every file's agent may be read. Before, it copied every file on
  each of the poll's passes.
- MergeExternal keys its set by an {agent, id} pair, not a string built
  for each of ~5000 sessions, and sizes the output once. It keeps the
  pairs GatewayKeys names, Raft's Pi id included.
- codexSubagentTaskTitles skips the four parent maps for a thread that
  spawns no agent, which is most of them.
- ccFamily holds each file by its index instead of copying ~200 bytes,
  and builds groups only for roots with two or more files. A singleton's
  uuid memo is still let go, as before.

Allocation on mote's bench (ab19, 80s of polls over ~34k sessions):
before this, callFilesWith was 250 MB, MergeExternal 200 MB, ccCopies
180 MB and codexSubagentTaskTitles 145 MB.

A/B on idle mote (ab21; polls every 5s over 10 endpoints while the ledger
and a Codex rollout are written; v0.1.1981 / the two commits before this
/ all three #2278 commits):
- mean poll 0.35s / 0.25s / 0.25s
- /api/sessions 0.87s / 0.73s / 0.47s
- /api/sessions/stats 0.33s / 0.26s / 0.15s
- /api/usage/heatmap 0.94s / 0.79s / 0.54s
- CPU 27.9% / 26.9% / 24.3%
ab20, run under load ~30 from other runs, showed the stats endpoints
slower in the order g25-last. Its CPU profile had less sessions work,
and run idle the gap goes the other way, so ab20's latency was load.
RSS stays the same (1014 / 1036 / 1045 MiB average, footprint peak 871
/ 884 / 869M). GOGC 25 still sets the GC share (~22-26%).

Rebased onto origin/main f982e46f2. calls.go, sessions.go, external.go
and cc_copies.go conflicted with the read-consent gate (af8f3a939),
Raft's sessions (9474eaf9c) and ccFamily's branches (f594b452e). Each
cut was made again on main's code.

Run at this head, on mote:
- GOOS=linux, windows and darwin go vet -tags nogui ./internal/sessions/
  ./internal/usage/ ./internal/gui/: ok.
- go test -timeout 45m ./internal/sessions/ ./internal/usage/
  ./internal/gui/: sessions and usage ok. gui red only on
  TestMainWindowCorners/macOS_26_SDK (#3949, open, red on macOS 27); this
  touches no GUI file.
2026-10-30 06:00:55 +08:00
yetone 9474eaf9cb sessions: Raft's Pi agents' sessions are listed as Raft's, with their prompts, calls and delete
Raft (slock's raft-computer) runs its agents on Pi and keeps each one's
Pi SDK session files in that agent's folder: <slock>/agents/<id>/
.pi-sessions/<ts>_<id>.jsonl, or .builtin-sessions/ for its built-in
runtime. <slock> is $SLOCK_HOME or ~/.slock (%USERPROFILE%\.slock on
Windows, the distro's ~/.slock under WSL). Read from raft-computer
1.0.14's PiDriver (buildPiSessionDir), BuiltInDriver and
resolveSlockHome, and a read-only listing of ~/.slock here.
runtime-sessions/ holds handoff notes, no sessions, and is not read.

- The Sessions page lists them as Raft's (agent "raft", in agent.Clients'
  others), titled and opened with their prompts as Pi's are.
- Their calls count on the Usage page as Raft's; calls through magpie
  stay the gateway's, as Pi's do.
- Raft's Pi uses the user's own ~/.pi/agent, so a request it sends
  through magpie reaches the gateway as Pi's under the same session id.
  sessions.GatewayKeys gives a Raft session both "raft|ID" and "pi|ID",
  so the gateway's copy is not listed twice nor counted twice (Merge,
  stats, NativeIDs, the GUI's Via).
- Delete and restore work as Pi's: the one file goes to the trash, and a
  folder beside it is left (the agent's workspace is not the session's).
  A session written in the last minutes is refused as active.
- No resume command, no carry and no trace export: Raft starts its own
  agents, and nothing outside it can resume one.
- SLOCK_HOME is passed through agentenv like the other agents' homes.

Run (at 958ad9f10 on e61e10535):
- mote (macOS): -run 'Raft|TestPi|TestDirs|TestVars|TestFolderVars' in
  sessions and agentenv: ok, and red for each break below. A full
  go test ./... was started there; at load ~300 from other sessions'
  suites it printed only magpie and internal/access (ok) before mote
  stopped answering (host down), so no full macOS record exists.
- mote (macOS), rebased on 5d24bc6cc: go test -count=1 ./internal/sessions/
  ./internal/agentenv/: ok (sessions 495s, agentenv 1.1s). agent and gui
  were not run in full on macOS.
- mote: GOOS=windows go vet of sessions, agent, agentenv, gui; GOOS=linux
  go vet of sessions, agent, agentenv: ok.
- Windows (win-run): agentenv ok; -run 'Raft|TestPi|TestDirs' in
  sessions ok. The full sessions package hit its 30m timeout after
  TestOneListing's red (#4114) and the Agy reds (#4115, #4177). agent
  and gui reds (Hermes, WorkBuddy, Lody, Qoder/Copilot plugin folders,
  Codex keychain, ClaudeDesktop language, Aside, InstallWithoutNode,
  DesktopExec, AionUi, ImportStatus, UpdateThatWontStart,
  GatewayHeldByAContainer, GatewaySessionHistoryAndCalendar): each run
  again at origin/main c1660481c on Windows and red there too, except
  TestHermesProfilesFollowMagpieModel which passed there alone; it is
  #1388's Hermes model rewrite, which this change does not reach.
- Linux (wsl-run): sessions ok, agentenv ok. agent's TestInstalledVersion,
  TestGrokInstalled, TestCursorFolderFromTheEditorIsNotTheCLI and
  TestOmpDetectedWithPiDir are red at origin/main c1660481c too (#4033,
  #3548). gui does not build there (no gtk4/webkitgtk-6.0 in the distro).

Broken by hand, each red, then restored: Raft's listing removed; the
"pi|ID" key dropped from GatewayKeys; the folder-beside check reverted to
Pi's absence; $SLOCK_HOME ignored; Raft's calls left out of piCallFiles;
NativeIDs without Raft; stats' native keys without "pi|ID".

Not tried: with real Raft. No agent on this machine has run on Pi, so
the fixtures are Pi 1.1.0's own files (testdata/pi-calls, testdata/pi)
placed in Raft's folders. The GUI was not run in a browser: no JS
changed, Raft's name and icon come from agent.Clients. Raft's icon is the
generic one.
2026-10-29 15:29:30 +08:00
yetone 536a98316d sessions: a poll over unchanged files gets the stats the last one read (#2278)
The Usage page asks for its range every 10 s and the Sessions page for
7, 30 and every day every 15 s. Each read put every session of every
range together again, though between two polls the files mostly
haven't changed: statsReadAll allocated ~1.1 GB per 80 s of polling,
a fifth of all magpie allocated.

statsKept keeps each range's Stats (at most 8 ranges) and the native
keys, with what they were read from: every listed file's path, key,
agent, size, mod time, main/read-only, WSL distro and its parse pointer
(a published parse is never written; a changed file gets a new one),
today, and the cache generation. It also keeps the answers the read
got from the prices, Codex's thread names and Claude Desktop's names,
and asks them again before it hands anything out. When any of these
differ, everything is read again. The listing and the refresh of
changed files still run on every poll.

MergeExternalStats wrote into the Stats it was given (a day's usage
rows, an append into spare room in Sessions, sorts in place). It now
copies whatever it changes, so a kept range is never written.

What this doesn't help: while an agent is writing a session, every
poll sees a changed file and reads everything again. Reading only the
changed sessions is the next change.

Run at the pushed head on mote:
- GOOS=linux/windows/darwin go vet -tags nogui ./internal/sessions/
  ./internal/gui/: ok.
- go test -count=1 -timeout 45m ./internal/sessions/ ./internal/gui/
  ./internal/usage/: sessions ok, usage ok, gui red only
  TestMainWindowCorners/macOS_26_SDK (#3949, open, same as main).
- New tests: TestStatsKeptBetweenPolls (the same backing array on an
  unchanged poll; a grown file and a price change are read in),
  TestStatsKeptNewDay, TestStatsKeptRangesBounded,
  TestMergeExternalStatsWritesNoInput. TestStatsAllRangesOnePass now
  forgets the kept ranges before each single read.
- Broken by hand, each red: keptFor always missing
  (TestStatsKeptBetweenPolls, "put together again"); the price check
  dropped (repriced cost unchanged); MergeExternalStats without its
  copies (TestMergeExternalStatsWritesNoInput).
- Real data (a copy of the owner's history, ~34k sessions), v0.1.1978
  against this: /api/sessions/stats?days=0/7/30 and both overviews
  asked 4 times 12 s apart, each pair byte-identical (1.97 MB for
  days=0).
- A/B, 80 s of GUI polling, v0.1.1978 against this: allocated 5512 to
  4480 MB, statsReadAll's share 1108 to 261 MB (the listing);
  GC 3.90 to 3.42 s, madvise 1.05 to 0.61 s, CPU 28.6 to 25.3%, avg
  RSS 1061 to 1019 MiB. mote's load was 20-40, so latencies aren't
  compared. The A/B binary was built before the 8-range bound was added.
- Rebased onto b9f1fcddd (redact only), then again: vet on the three
  systems over sessions, gui and redact, and go test of sessions, usage
  and redact: ok.
- Rebased again onto a4e929212 (GUI context map only), then at this
  head: the same vet and tests ok. TestCoreScriptBudget is red at
  a4e929212 itself (#4133); this commit touches no GUI file.
2026-10-29 08:52:32 +08:00
yetone f4762e9217 sessions: a Claude conversation Claude Code copied into another file is one row
Neo (Discord #feedback): one Claude conversation was listed as ~11 rows
with the same title, message count and size, each under its own id.

Claude Code 2.1.312 copies a conversation into a new <id>.jsonl when it
forks one (--resume --fork-session, /branch) or moves it to a background
session: every message again, under the same uuids, with the new
sessionId. magpie keyed each file as a session, so each copy was a row,
and the copies' tokens were counted again in usage.

Each main Claude-format file (Claude Code, Qoder, Qoder CN) now records
the uuids of its first and last message (state Root/Leaf, cacheVersion
23, so every file is read once more and old copies fold in too). Of the
files of one agent that start with the same message, one whose last
message another holds is a copy (cc_copies.go). Only a random (v4) uuid counts, as Claude Code
writes them: files whose writer reuses ids like "u" stay apart. A copy
is not listed
(List, ListAgent, Agents), not counted in stats, and Delete trashes it
with the session that holds it (Restore brings it back). A fork that
went on with a turn of its own has a last message no other file holds
and stays its own row, as Claude Code's /resume shows it. The gateway's
session rows and the GUI's native keys know the copies' ids, so a
gateway-only row doesn't stand in for one.

Fixtures: testdata/claude-forks is Claude Code 2.1.312's own files from
a sandbox HOME with a fake API (a session, a --fork-session of it with a
third prompt, another fork with a different one), trimmed of request
records and attachment text. Pure copies are that session with its
sessionId rewritten, as /branch leaves one.

Run (mote) at 2b7ce2967 on d8c70504d: go test -tags nogui -timeout 45m
./... all 76 packages ok; gofmt -l
clean; GOOS=linux and GOOS=windows go vet -tags nogui ./internal/sessions
./internal/gui ok; go build ./... ok.
Broken by hand, each red: ccCopies returning nil (all four row tests),
stats counting copies (110 in / 55 out, want 30 / 15), Delete not taking
copies (a copy came back as the row), MergeExternal ignoring Copies (a
gateway row came back). Without the v4 check, five tests whose
fixtures share "uuid":"u" went red (cli, gui x2, sessions, tui).
GUI: no file reaches it; the GUI tests fake the API and the JSON a page
gets is unchanged (Copies is json:"-").
Not tried: Neo's own files, and the opened view showing only "session
start" and one line in the second screenshot; that was not reproduced.
The calls ledger (FindCall) still holds a copy's calls.
2026-10-28 10:40:28 +08:00
yetone 3393e61d00 sessions: a summary's tools, skills and days are sorted slices, not maps
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.
2026-10-27 04:15:48 +08:00
yetone 6e17d58ebf usage: a top session only the gateway saw says "Gateway session", not "(no prompt)" with no folder (#2285)
The reporter's Usage › Sessions card listed seven Pi sessions on
deepseek-v4-pro as "(no prompt)" with no folder, and their routing group
has no DeepSeek. Those rows were gateway projections: Pi asked magpie for
deepseek/deepseek-v4-pro (every served model is in Pi's models.json), most
likely through a pi-subagents child, whose session file is in a temp folder
magpie never reads. The card gave no sign of that, so it read as Pi's own
sessions with an empty prompt, and our first reply took it that way.

The overview's summaries from MergeExternalStats now carry gateway: true,
as MergeExternal's list rows already did. The card shows "Gateway session"
where the folder would be, "(prompt not recorded)" as the title when no
text was kept, and a tooltip pointing to Record gateway conversations.
Strings in zh, zh-TW, ja and de. gateway-sessions.md says it.

Run in this worktree (a1f7b8c13 base):
- go test -tags nogui -p 1 -count=1 -run 'TestTopSessionsMarkWhatOnlyTheGatewaySaw|TestGatewaySession|Overview|Session' ./internal/gui/: ok
- go test -tags nogui -p 1 -count=1 -run 'External|Overview|Stats|Gateway' ./internal/sessions/: ok
- Gateway: true removed by hand: TestTopSessionsMarkWhatOnlyTheGatewaySaw red
  (the Pi record, provider deepseek, came back with cwd "" and title "",
  no gateway field), green with it back.
- sessions-overview.test.cjs: 28/28 in chromium and webkit; with the
  page.js change undone by hand, red in en and zh ("(no prompt)").
- i18n-keys, gui-zh-tw, gui-de, gui-ja (chromium): pass.
- gofmt -l clean; go vet -tags nogui for darwin, linux, windows on
  internal/sessions and internal/gui: ok.
Not run: the full Go suite and the full GUI suite.

Full suite: SUITE_LINE
2026-10-15 23:08:05 +08:00
yetone cdb7b5ff7e sessions: a PI-Desktop chat goes by the title PI-Desktop gave it, not its id (#1967)
PI-Desktop (vastsa/PI-Desktop) sends its chats through magpie with
X-Magpie-Session set to its own session id. Those are gateway sessions
with no file magpie reads, so Sessions and the context page listed them
by id. PI-Desktop keeps the name only in its index database, pi.sqlite's
sessions table (id, title, deleted_at).

PIDesktopTitles reads that table from $PI_DESKTOP_DATA_DIR or
~/.pi-desktop. It opens the database only through openCursorStore:
immutable when there is no write-ahead log, or from a temp copy when
there is one (a running PI-Desktop keeps one). It is re-read when the
database or its log changes, at most once a second. Deleted and untitled
rows are skipped. A database that can't be read leaves the names last
read standing. MergeExternal, MergeExternalStats and the GUI's context
page use it for sessions attributed to pi-desktop (aec6908c6) or pi,
which PI-Desktop was counted as before.

Run:
- TestPIDesktopTitlesNameGatewaySessions builds pi.sqlite with
  PI-Desktop's schema in WAL mode with checkpoints off. It checks that
  pi and pi-desktop sessions get the title, a claude session with the
  same id doesn't, deleted and untitled rows don't, a rename shows up on
  the next read, and the folder's files are unchanged.
- Broken by hand: isPIDesktop returning false made it red (titles
  stayed the id), and so did dropping `deleted_at IS NULL` (the deleted
  row got its title).
- go test -tags nogui ./internal/sessions/ ./internal/gui/ passes.
- gofmt -l is clean. go vet passes on darwin, linux (nogui) and windows.

Not tried: a real PI-Desktop install. The schema is from its source. A
data folder the user picked in PI-Desktop's own settings, other than
$PI_DESKTOP_DATA_DIR, isn't followed.
2026-10-13 17:10:25 +08:00
yetoneandKoohoko 067f39f406 sessions: Desktop titles read once per second, from every handle Desktop keeps, and reach stats and Context (#1675)
Follow-up to Koohoko's 3d6f8b8e, after review.

- Cost: assemble asks DesktopTitles once per native Claude Desktop
  session, and each call globbed and stat'ed every local_*.json, so a
  list of N Cowork sessions looked at the metadata N times. The names
  are now one index, rebuilt at most once a second (desktopTitlesHeld);
  a rename in Desktop shows within that second. Files are read through
  filememo, the shared reader the usage resolver already uses for these
  same files, which also catches a same-size rewrite inside one mtime
  tick (the patch's own size+mtime cache didn't).
- A record that is there but doesn't parse (Desktop midway through a
  write) keeps its last parse instead of dropping to the bare id; a
  record gone still takes its names with it.
- Handles: Claude.app 2.7032's LocalSessionManager (app.asar, read-only)
  counts unarchivedCliSessionId as a live handle beside cliSessionId and
  preClearCliSessionId as lineage beside priorCliSessionIds, and runs a
  record with no cliSessionId under its sessionId without "local_".
  All are named now; the raw "local_..." id no longer is (no usage
  record carries it).
- Siblings: MergeExternalStats (the Sessions page's stats summaries)
  and the Context page named gateway-only Desktop sessions by the
  recorded prompt or nothing; both use the Desktop name now.
- docs/subsystems/gateway-sessions.md says all of the above.

Real layout: no Desktop session records exist on this Mac or the
Windows box (only claude_desktop_config.json), so field names and types
were checked against Claude.app 2.7032's own reader/writer code: a
string title, string cliSessionId/unarchivedCliSessionId/
preClearCliSessionId, an array priorCliSessionIds, files
<account>/<org>/local_*.json under claude-code-sessions and
local-agent-mode-sessions. Dirs come from desktopdir.Everywhere, the
resolver the other Desktop session readers use (Windows %APPDATA% and
MSIX LocalCache, Linux ~/.config); Windows/Linux not run.

Run: new tests TestDesktopSessionTitleHandles, TestDesktopSessionTitleInStats,
TestDesktopTitlesReadOncePerList, and context checks in
TestDesktopSessionTitlesOnPages. Each broken by hand went red:
rescan per call -> "metadata looked at 12 times, want once"; no
last-good -> "a half-written file lost its names"; no unarchived/stem ->
missing ids; stats without the name -> "stats titles map[cli-s:Recorded
prompt ...]"; Context without it -> "context titles map[...: ...]".
go test -race -count=20 -run TestDesktop ./internal/sessions;
go test -tags nogui ./... (sandbox HOME, pinned caches): all ok but
internal/plugin's TestPiPackage (pi-codemode export missing; passes
alone, doesn't import sessions or gui), filed as #1879; gofmt -l;
go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet
./...; go build, GOOS=linux go build -tags nogui, GOOS=windows go build.
GUI: routing-sessions, session-identity, sessions-overview,
sessions-bar-names, sessions-gateway-delete, sessions-manage,
context-window in Chromium and WebKit (84/84 each).
Real binary: magpie web under a sandbox HOME with Claude-3p Code and
Claude Cowork fixture records and five claude-desktop usage records;
the Sessions page (Chromium, WebKit) showed both titles on current,
prior and unarchived ids and the bare id on the unmatched one;
/api/gateway/session-titles named them; a rename showed after 1.3s;
a half-written file kept the name; deleting the record went back to
the id.

Co-authored-by: Koohoko <koohoko@gmail.com>
2026-10-13 07:14:22 +08:00
Haogao Gu d46a5635c0 sessions: Claude Desktop uses its saved conversation titles (#1675)
Read Code and Cowork metadata when native CLI transcripts are absent,
including current/prior CLI IDs and renames. Keep gateway identity,
accounting and capabilities. Desktop titles take precedence over the
recorded first-prompt fallback added upstream; unknown names keep it.

Rebased onto 751e05d8. All three new regressions fail on that unmodified
base and pass with the patch. Full Go suite, targeted race checks repeated
20 times, and macOS/Linux/Windows vet/builds pass. Baseline and patched
binaries reproduce UUID/title display in Chromium and WebKit with the
same synthetic Code/Cowork metadata and recording off. The patch applies
cleanly to newer origin/main 84cd8153. Linux/Windows runtime UI was not
executed. No live gateway or agent files were modified.
2026-10-13 07:14:22 +08:00
yetone 260ded9af4 sessions: the Sessions page's search finds a session by what was said in it, and a gateway session is titled by what it was first asked (YOU on Discord)
Why: the filter matched only titles, folders, ids and models, and a
session the gateway recorded was listed under its bare ses_… id, so one
couldn't be found by anything a person remembers about it.

What changed:
- sessions.GatewayTitle: the first user text of a recorded session (not
  a <…> context tag, # AGENTS.md or an image), made one line. It reads at
  most 8 complete turns of the oldest file of it, caches a finished
  file's answer by path, and costs one stat when nothing is recorded.
  gatewayListed applies it in every list (/api/sessions, /manage, /one,
  the stats summaries); ExternalSession gained Title.
- GET /api/sessions/search?agent=&q= (searchSessions): an agent's
  sessions, newest first, read by up to 4 workers, each only to its
  first match. Native files go through a byte prefilter (mayHold: the
  query's longest word, ASCII case folded without a copy, 1 MiB chunks,
  skipped for zstd and for queries JSON may escape), and of a Claude or
  Codex file only the lines holding every word are decoded
  (readTranscriptOf; claudeContentOf/codexContentOf take an optional
  line test, nil for every other caller); gateway sessions, and an
  unreadable agent's sessions (unread: true), through their recorded
  transcript. System prompts, tool definitions and images never match.
  It stops at 200 hits or 8s (cut, searched of total) and when the
  request's context ends. Each hit carries the match with 36 runes
  before and 120 after.
- sessions.js: the field says "Search sessions"; title/folder/id/model
  matches show at once, the server is asked 300ms after the last
  keystroke, a new query aborts the request in flight and its answer is
  dropped, under 2 letters asks nothing. A session found shows a line of
  the words round its match with the match in <mark> (text nodes, no
  innerHTML). A note says when it is searching, cut short, failed, or
  limited to recorded text. New strings in zh, zh-TW, ja and de.
- docs/subsystems/gateway-sessions.md describes both.

Run:
- Go: TestSearchSession* (snippet, case and line breaks, said text
  preferred over a tool call, cut ends, cancelled context, a Codex file,
  only matching lines decoded: 1 part of 3), TestContainsFold,
  TestMayHoldSkipsAFileWithoutTheWords (incl. a match across chunks),
  TestGatewayTitleAndSearch (context tag and system prompt skipped),
  TestSessionsSearchFindsGatewaySessionsByWhatWasSaid (endpoint + manage
  titles), TestSessionsSearchStopsWhenItsRequestEnds. Without the
  endpoint/title they fail (404, id as title).
- GUI: new sessions-search.test.cjs in chromium and webkit, en/zh at
  1100, zh-TW/ja at 560, de at 420: title shown, one letter no request,
  one debounced request, snippet mark, cancelled earlier request never
  shown, cut note, empty state, Escape, every language's strings, no
  overflow; 12/12, and 0/12 with the old sessions.js. The sessions-*,
  sess-*, session-* and i18n-keys tests pass in both engines
  (sessions-manage's placeholder updated to "Search sessions").
- gofmt -l, go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./..., the builds: clean. go test -tags nogui
  ./... at load ~25-60 (other sessions' runs): every package passed but
  internal/agent and internal/gateway, which hit the 30m timeout; run
  again alone, agent passed and gateway's only red was
  TestOTelWaterfallIncludesUnbilledFallback, filed as #1794 (passes
  alone, -count=3).
- Real data, read-only (a temporary probe, not committed, pointed at
  the owner's ~/.claude and ~/.codex; one worker, 8s, load ~50):
  Claude, 58 sessions / 3 GB: before the line filter one 1.3 GB session
  took the whole 8s ("redis": 1 of 58); after, all 58 in 4.7s ("redis",
  13 hits), 7.4s ("gateway session"), 2.8s (no match). Codex, 11534
  sessions / 65 GB: 245-656 sessions in 8s either way, which is what
  the cut note ("latest n of total") is for.

Not verified: the endpoint and page against a real recorded gateway
store (only fixtures and temp homes); the timings above were taken on
a machine at load ~50 and vary run to run.
2026-10-12 22:29:46 +08:00
yetone eb035e29e1 sessions: a session seen only through the gateway can be deleted: its row and recorded conversation go to magpie's trash, and Restore brings them back (lc on Discord)
lc ("只可列出?不可删除?agent claude code") saw Claude Code sessions named by
uuid under "No folder" at "0 B", with "These Claude Code sessions are read
only; magpie can list them, but cannot resume or delete them." Those rows are
gateway projections from the usage ledger: Claude Code ran with its own files
somewhere magpie can't see (another computer, a container, another config
folder), so nothing native won on the same agent+id. An agent with only such
rows was sent as not deletable, and every row was read_only, so the page had
no Delete at all.

What changed:
- sessions.DeleteGateway moves the session's recorded text folders
  (gateway-conversations/<date>/<identity hash>) into
  trash/sessions/gateway/<ts>-<hash>/files/<date> with a note marked gateway,
  and records {agent, id, last} in gateway-sessions-hidden.json.
  /api/sessions and /api/sessions/manage leave it out up to that last
  request; a newer request lists it again. The usage ledger is untouched, so
  Usage, /api/sessions/one and stats keep what it spent. A session with a
  request in the last minute is refused as active.
- Restore moves the text back (skipping what expired or was cleared, refusing
  rather than overwriting a same-day re-recording), checks each item is this
  session's identity folder inside the store, and unhides it. Delete forever
  keeps it hidden.
- The recording's promises hold in the trash: the hourly prune erases
  trashed gateway text past 7 days, "Delete saved conversations…" erases it
  too, and HasGatewayConversations counts it.
- The manage route marks an agent with gateway rows deletable and sends
  those rows deletable, with gateway: true and the size of their recorded
  text; the delete route sends gateway ids to DeleteGateway and native ones
  to Delete as before.
- Sessions page: gateway rows group under "Seen through the gateway"
  instead of "No folder", show "{size} recorded" only when something was
  recorded (no "0 B"), and the note says why they can't be resumed and what
  Delete takes and keeps. The delete dialog says the same for gateway rows
  instead of "Their files are moved…"; the Trash marks them and notes the
  7-day expiry. New strings in zh, zh-TW, ja and de.
- docs/subsystems/gateway-sessions.md describes the delete, hidden list,
  restore, expiry and clear.

Verified:
- go test -tags nogui ./... (sandbox HOME) green; gofmt -l clean; go vet
  ./...; GOOS=linux and GOOS=windows go vet -tags nogui ./internal/sessions
  ./internal/gui; go build, GOOS=linux -tags nogui and GOOS=windows builds.
- TestSessionsDeleteGatewaySession fails on the old code with "Claude Code
  with only gateway sessions isn't deletable: [{Agent:claude
  Deletable:false}]"; sessions-gateway-delete.test.cjs fails there too.
  TestGatewayDeleteTrashExpires, TestGatewayPurgeKeepsItHidden,
  TestGatewayDeleteNothingRecorded and TestGatewayRestoreRefusesForeignItems
  cover expiry, purge, an unrecorded session and a forged note.
- GUI: sessions-gateway-delete.test.cjs in Chromium and WebKit, en, zh,
  zh-TW, ja, de, at 1000 and 390px (in-app dialog, Cancel sends nothing,
  click doesn't scroll, no left-border accents, no page overflow); all
  sessions-*, gateway-conversations, checkbox-look, old-webkit,
  sess-agent-strip, i18n-keys, gui-ja, gui-de and gui-zh-tw tests pass.
- Real try: magpie web from this tree on a sandbox HOME seeded with three
  gateway-only Claude Code sessions (two recorded): deleted a recorded and an
  unrecorded one, checked the store, trash and hidden list on disk, restored
  the recorded one (its transcript reads again), purged the other (stays
  hidden). That try found the Trash page breaking on an unrecorded session's
  null items; DeleteGateway now writes [] (TestGatewayDeleteNothingRecorded
  fails without it) and the page reads a missing list as empty.
2026-10-10 09:53:38 +08:00
木子不是木子狸 c9b8263378 sessions, gateway: Sessions lists gateway sessions, and can keep their text on this computer when turned on (#1355, mu-zi-lee)
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.
2026-10-10 04:24:18 +08:00