ac4af582301a4e8a29245dbba767eba31334ddf9
6
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
b8270850df |
sessions: a kept parse's rarely set fields live in a StateMore made only when one is set (#2278)
Each of the ~18k files the Sessions cache keeps had a 760-byte state, and ~330 bytes of it were fields almost no file sets: the Codex spawn and agent maps, Named/Custom/First, the dsh and Claude conversation lists, Root/Leaf, Compacts, and the six per-agent tails (Grok, Droid, Kimi, Agy, Dsh, Cline). On the owner's real cache (18,331 files) Root and Leaf are set in 150, Named in 117, Compacts in 78, First in 35. They move to an embedded *StateMore, nil unless something is in it: reads go through more() (a shared empty one when nil), writes through own(). The JSON is the same (embedded fields are inlined), so the cache version stays. - parseWith drops an extra that only had empty values written to it, and share() drops one the decode made empty. - clone() deep-copies the extra, so growing a clone leaves the kept state alone. Copies that never write (withoutRevisions, the Agent rename) share it, as they shared the maps before. Run on mote at this tree: - gofmt -l internal/sessions: clean. go vet ./internal/sessions/ on darwin, GOOS=linux and GOOS=windows: ok. - go test -count=1 ./internal/sessions/: ok (26s). - Every selector was checked by renaming the embedding to a named field and compiling with -gcflags=-e until only the struct literals were left, so no field is reached through a nil *StateMore. - New tests in state_more_test.go: zero() knows every field (reflect), a read makes no extra and a write never reaches the shared empty one, a clone owns its extra, and a cache round trip keeps no empty extra. Broken by hand: dropping Cline from zero() and sharing the extra in clone() each turn their test red; restored. - Real-account idle heap (copy of the owner's config and 24.6MB sessions cache, gateway idle 180s, heap after GC): decodeCache's retained heap 35.0MB -> 22.5MB, reflect.unsafe_New 20.0MB -> 10.5MB. The total (128.7MB -> 133.6MB) moves by more than that between runs of one binary (118-140MB), from late passes that happened to be live. Not tried: the full ./... suite (state is unexported; only internal/sessions uses it, and the whole binary builds). |
||
|
|
af8f3a9399 |
sessions: a new install reads no agent's session history until the user allows it (RustCats on X)
RustCats on X: a fresh magpie showed every agent's session history on
the Sessions page before anyone agreed to it, and asked for a per-agent
choice instead.
- sessions.Reads(agent) (internal/sessions/access.go) is the one gate,
from settings.SessionReads {Asked, All, Agents}. Every lister asks it,
the aggregators (allFiles, callFilesWith, callSourcesWith,
traceLineFiles, wslFiles, DesktopDataDirs) filter by it again, and
readers of an already-listed session (TranscriptOf, ContentOf,
SearchSession, SubagentTranscript, CarryOver, ReadCallSource) return
ErrNotRead, so a cache from before a switch was turned off goes no
further. The Sessions list, stats, /api/sessions/overview, the call and
trace indexes, Usage's agent-file calls and the Codex/Pi title readers
all pass it.
- SettleReads decides once and saves: an install with sessions.json or
a calls-v* cache read sessions before and keeps all on; a fresh one
reads none, not asked. A saved value is never replaced; save, sync and
restore keep it (KeepOwn); only SetSessionReads writes it. An
unwritable settings.json reads nothing this run.
- GUI: GET/POST /api/sessions/reads. While not asked, the Sessions page
shows a consent card: each agent found (by a stat of its folder only)
with a switch, Allow selected and Allow all. Settings > Privacy >
Agents' session history has "Agents found later" and a row per agent.
Strings in en, zh, zh-TW, ja, de.
- CLI: magpie sessions read [on|off all|<agent>...]; magpie sessions
says on stderr when nothing is allowed yet; the TUI's empty Sessions
page says how.
Read either way, because none of it lists or shows a session: the
gateway's own usage ledger, its projections and the conversations it
recorded (magpie's own records, so usage and cost keep working); the
agents' config and sign-in files; Claude Code's and Codex's
history.jsonl last-used time and a session file's mtime for a quota's
first use; Codex's newest rollout's last line before magpie restarts
Codex (codexTurnOpen).
Tests: TestFreshInstallReadsNoAgentUntilAllowed,
TestSettleReadsKeepsWhatWasThere, TestSessionReadsRoutes,
TestSessionsRead, TestSessionsNotAskedSaysHow, sessions-reads.test.cjs
(26 cases: consent and Settings in 5 languages, Chromium and WebKit,
390 to 900 wide).
Run on mote:
- full Go suite (gofmt -l, go vet ./..., GOOS=linux go vet -tags nogui,
GOOS=windows go vet, go build, go test -timeout 45m ./...) at this
change on
|
||
|
|
11dcc743f4 |
sessions: a listed file is 96 bytes, what only some agents' files have kept behind one pointer
A Sessions poll copies every agent's list of ~20k files several times (listedRollouts, heldFiles' clone, callFilesWith, allFiles, byKey, statsRead). Each file was 232 bytes, most of it fields only OpenCode, ZCode, Hermes, Alma, agy, Cursor's editor or WSL files fill. Those move into fileMore behind file.more (nil when a file has none); reads go through m(), writes through w(), which copies first, so copies of a file never see each other's writes, as before. A/B with the real ~/.codex and ~/.claude data (ab5.sh, 8 polls 15s apart, alloc_space between heap-0 and heap-1), base |
||
|
|
a23fbaeadf |
sessions: a subagent's file is read for its task only when its meta names none, once per change
Why: a 48-minute heap profile of the user's magpie allocated 6.3 GB
in sessions.scanAt, 3.5 GB of it from ccTask. The user has 3,174
Claude Code subagent files, 1,798 of them over 1 MB. Two things
caused it:
- subagentsOf titled each one `cmp.Or(m.Description,
ccTask(f.path))`. Go evaluates both arguments, so every subagent's
file was read for a first user line that was then thrown away
whenever the meta file had a description, which is nearly always.
- ccTask kept only a found task. A file whose first 16 lines name
none was read again on every ask.
What changed:
- Claude Code and Kimi subagent titles read the file only when the
meta (or the spawn record) gives no description.
- ccTask keeps what it read, a task or none, with the file's size and
mtime from before the read. An unchanged file isn't read again. A
grown, rewritten (even at the same size), or touched file is read
again from its first lines.
- A read that fails keeps the last good result, and a deleted file
gives "".
- A line appended while the file is being read changes the size, so
the next ask reads it.
- The docs/subsystems/gateway-sessions.md subagent section says so.
Tests:
- TestSubagentTaskReadOnlyWhenTheFileChanges counts scans through
scanHook for these cases:
- first ask: 1 scan;
- unchanged: 0;
- grown with a task: 1, then 0 once found;
- grown after the task: 1;
- rewritten shorter: 1;
- rewritten with no task: 1;
- same size with a new mtime: 1;
- a task appended past line 16: 1 scan, still "";
- appended during the read: found on the next ask;
- deleted: "", 0 scans.
- TestSubagentWithMetaTaskIsNotReadForIt lists a session after a
simulated restart (Saved, Reset, memos cleared) and expects 0 scans
of a subagent whose meta names its task.
- Broken by hand:
- ccTask back to keeping only a found task (`t.task != ""`) makes
the first test go red: "unchanged, no task yet: 1 scans, want 0".
- The title back to cmp.Or makes the second go red: "the list read
a subagent's file 1 times for a task its meta names".
- Both green again once restored.
Measured on a read-only APFS clone of the user's ~/.claude/projects
and ~/.codex/sessions/2026/10, in a sandbox HOME, at load ~500 from
other sessions. Times are noisy; allocations are not. Restart, then
List(All):
| Code | Allocated | Allocations |
| --- | --- | --- |
| ccTask keep, title still cmp.Or | 153.9 MB | 270,838 |
| this commit too | 25.8 MB | 109,854 |
| origin/main
|
||
|
|
f15542d2ea |
sessions: OpenCode 2 subagents show their type, and a Kimi Code subagent opens on its task, not a context chip (#2290, infinitr0us)
OpenCode 2.0.29 keeps a child session's agent in session_v2.agent and
titles it with the task alone, so ocSubagentTitle found no kind and every
OpenCode subagent row showed only its title and time. The kind now comes
from session_v2.agent when set (ocV2DB.agent, kept once found; a missing
column or NULL reads as none and isn't kept), and the "(@agent subagent)"
title split stays the fallback for older versions.
A Kimi Code subagent's own wire.jsonl starts with the task its parent
gave it, a turn.prompt whose origin is {kind: system_trigger, name:
subagent}; the transcript folded every system_trigger as context. In a
subagent's own wire (not agents/main) that prompt now opens as its first
user message (kimiTask). Other system triggers, and a "subagent" one in
the session's main wire, stay folded.
Fixtures follow the reporter's described shapes: ocMakeV2's real
session_v2 schema with agent 'explore' and a task-only title beside a
child with no agent and an older suffixed title; a 1.5-shaped subagent
wire (agentId, promptId, turnId) with the subagent trigger, a reply and a
background_task trigger, plus a subagent trigger appended to main.
No real OpenCode child sessions or Kimi Code subagents on this machine.
No GUI change: the Sessions client already draws a subagent's kind.
Run: TestOpenCodeV2SubagentKind and TestKimiSubagentTask fail on the old
subagents.go/transcript_kimi.go (no kind; user/context first), and
TestKimiSubagentTask fails with the agents/main scope check dropped.
go test -p 1 -tags nogui ./internal/sessions/ ok at the rebased head;
gofmt -l clean; go vet -tags nogui ./internal/sessions/ for darwin,
GOOS=linux and GOOS=windows.
Full suite: SUITE_LINE
|
||
|
|
c516841e46 |
sessions: a Claude Code, Qoder, OpenCode or Kimi Code session lists its subagents, and the transcript route reads one by sub= (#2261, infinitr0us)
What changes:
- A session's subagents are now on the session, as Session.Subagents (subagentsOf in the new internal/sessions/subagents.go). Each one has its id, title, kind, parent subagent, start and last.
- Claude Code and Qoder: subagents/agent-<id>.jsonl. The type, description and parentAgentId come from agent-<id>.meta.json, through ccMeta, which SubagentParent also uses now. With no meta file, the title is the first user line. A compaction's own run (agent-acompact-*) is left out.
- OpenCode: child sessions found through ocRoots, which now records each file's parent. The title is split from "<description> (@<agent> subagent)"; "Child session - <time>" counts as no title.
- Kimi Code: agents/agent-<n>/wire.jsonl. The title is the first turn.prompt. Kimi 1.5's subagent.spawned record adds the description, type and parent agent.
- GET /api/sessions/transcript takes sub=. It is resolved only among the subagents the session lists (SubagentTranscript; ErrNoSubagent otherwise), never as a path. A subagent's file path is not sent (Path is json:"-").
- Codex is unchanged: its subagents are sessions of their own, with parent_session.
Fixtures:
- Claude Code: the meta and line shapes are copied from real files under ~/.claude/projects, with their words and ids replaced.
- OpenCode: titles of both the 1.x and 2.x forms.
- Kimi 1.4: the existing redacted reporter fixture.
- Kimi 1.5: the record is built from Kimi Code's schema (agent-core-v2 SubagentSpawned), not from a real file.
What was run:
- go test ./internal/sessions ./internal/gui. TestClaudeSubagents, TestQoderSubagents, TestOpenCodeSubagents (JSON and db), TestKimiSubagents and TestSessionSubagentTranscript are new.
- Broken by hand: with the subagentsOf call removed from assemble, 4 sessions tests and the gui test fail. Restored afterwards.
- gofmt -l is clean. go vet passes for darwin, linux (-tags nogui) and windows.
- The full suite (go test -p 4 ./...) under a temp HOME, at
|