Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.
sessions: the stats and id lookups don't build every session's subagents
yetone42e6aee53455
diff --git a/docs/subsystems/gateway-sessions.md b/docs/subsystems/gateway-sessions.mdindex 6c415e434..21f2b28f1 100644--- a/docs/subsystems/gateway-sessions.md+++ b/docs/subsystems/gateway-sessions.md@@ -475,13 +475,17 @@ for the session) and `start`/`last`; its file is never sent.other system triggers, and any in `agents/main`, stay folded.These are read beside the parsed-session cache, not in it, so its version-is unchanged. `GET /api/sessions/transcript` takes `sub=<id>` for a+is unchanged. Only the Sessions list and a session's own lookups build+them (`assemble`); the stats, the native-session keys, `Titles` and the+id lookups use `assembleListed`, which stops before resume, transcript and+subagents, so a stats poll reads no subagent's file.+`GET /api/sessions/transcript` takes `sub=<id>` for asubagent's conversation; the id is looked up among the session's own`subagents` (`sessions.SubagentTranscript`), never used as a path, and onenot listed is an error. See `TestClaudeSubagents`, `TestQoderSubagents`,`TestOpenCodeSubagents`, `TestOpenCodeV2SubagentKind`, `TestKimiSubagents`,`TestKimiSubagentTask`, `TestSubagentTaskReadOnlyWhenTheFileChanges`,-`TestSubagentWithMetaTaskIsNotReadForIt` and+`TestSubagentWithMetaTaskIsNotReadForIt`, `TestStatsReadNoSubagentFile` and`TestSessionSubagentTranscript`.The Sessions page draws only main sessions on top. A session's subagents arediff --git a/internal/sessions/codex_provider.go b/internal/sessions/codex_provider.goindex 52ca0e870..9c276d94a 100644--- a/internal/sessions/codex_provider.go+++ b/internal/sessions/codex_provider.go@@ -214,7 +214,7 @@ func MoveCodexProvider(id, to string) (CodexMove, error) {var fs []fileprice := pricer()for _, g := range groups {- if one, _ := assemble(g, price); one.ID == id && !one.ReadOnly {+ if one, _ := assembleListed(g, price); one.ID == id && !one.ReadOnly {fs = gbreak}diff --git a/internal/sessions/manage.go b/internal/sessions/manage.goindex aa673df85..4f5e54499 100644--- a/internal/sessions/manage.go+++ b/internal/sessions/manage.go@@ -319,7 +319,7 @@ func Delete(agent, id string) (Trashed, error) {var s Sessionprice := pricer()for _, g := range groups {- if one, _ := assemble(g, price); one.ID == id {+ if one, _ := assembleListed(g, price); one.ID == id {fs, s = g, onebreak}diff --git a/internal/sessions/sessions.go b/internal/sessions/sessions.goindex 9e234b57b..01bafc4f2 100644--- a/internal/sessions/sessions.go+++ b/internal/sessions/sessions.go@@ -1144,6 +1144,26 @@ func sessionID(fs []file) string {// assemble puts a session together from its files' parses.func assemble(fs []file, price func(string) *catalog.Price) (Session, bool) {+ s, ok := assembleListed(fs, price)+ if !ok {+ return s, false+ }+ if !s.ReadOnly {+ s.Resume = resumeCommand(s.WSL, s.Agent, s.ID, s.Cwd, s.Path)+ }+ s.Carry, s.Transcript = carries(s), HasTranscript(s.Agent)+ if s.Transcript {+ s.Subagents = subagentsOf(s, fs)+ }+ return s, true+}++// assembleListed is assemble without what only a listed session's row shows (how+// to resume it, its subagents): whether List lists the session, and its+// agent, id, title and usage. The stats ask it of every session on each+// poll, and building every session's subagents there read each Claude Code+// subagent's file again (3.5 GB of a live magpie's 6.3 GB of scans).+func assembleListed(fs []file, price func(string) *catalog.Price) (Session, bool) {sortSessionFiles(fs)s := Session{Agent: fs[0].agent, Path: fs[0].path, Models: []Model{}, WSL: fs[0].wsl}for _, f := range fs {@@ -1227,13 +1247,6 @@ func assemble(fs []file, price func(string) *catalog.Price) (Session, bool) {if s.Title == "" && s.Tokens.zero() {return s, false // nothing was said in it}- if !s.ReadOnly {- s.Resume = resumeCommand(s.WSL, s.Agent, s.ID, s.Cwd, s.Path)- }- s.Carry, s.Transcript = carries(s), HasTranscript(s.Agent)- if s.Transcript {- s.Subagents = subagentsOf(s, fs)- }return s, true}@@ -1750,7 +1763,7 @@ func Titles(keys []string) map[string]string {identities := codexIdentitySnapshot(fs)price := pricer()for k, g := range groups {- if s, ok := assemble(g, price); ok {+ if s, ok := assembleListed(g, price); ok {setSessionCodexIdentity(&s, identities)setSessionCodexTaskTitle(&s, taskTitles)if s.Title == "" {diff --git a/internal/sessions/stats.go b/internal/sessions/stats.goindex 67c8a10de..dc5199e8c 100644--- a/internal/sessions/stats.go+++ b/internal/sessions/stats.go@@ -151,7 +151,7 @@ func statsIn(days int, now time.Time, native map[string]bool) Stats {price := pricer()for _, fs := range groups {// as List: a session nothing was said in is not listed- if s, ok := assemble(fs, price); ok {+ if s, ok := assembleListed(fs, price); ok {native[s.Agent+"|"+s.ID] = true}}@@ -336,7 +336,7 @@ func statsIn(days int, now time.Time, native map[string]bool) Stats {if len(sh.dates) == 0 {continue}- s, ok := assemble(groups[key], price)+ s, ok := assembleListed(groups[key], price)if !ok {continue}diff --git a/internal/sessions/stats_subagent_test.go b/internal/sessions/stats_subagent_test.gonew file mode 100644index 000000000..1e5976fb0--- /dev/null+++ b/internal/sessions/stats_subagent_test.go@@ -0,0 +1,43 @@+package sessions++import (+ "path/filepath"+ "testing"+)++// The stats, which the Sessions page and the overview poll, read no+// subagent's file to tell which sessions are listed: only the files that+// changed are read. They built every session's subagents, and each+// subagent's task was read again from its file at every start, and on+// every poll for one whose first lines name none: 3.5 GB of a live+// magpie's 6.3 GB of session scans in 48 minutes.+func TestStatsReadNoSubagentFile(t *testing.T) {+ inZone(t, 0)+ claude, _ := setup(t)+ sub := filepath.Join(claude, "projects", "-work-app", "11111111-2222-3333-4444-555555555555", "subagents", "agent-b2.jsonl")+ writeFile(t, sub, ccHookLine(0)+ccHookLine(1))+ StatsAndNative(0) // every file read once+ Saved()+ // a restart: the parses come back from the disk, nothing else kept+ Reset()+ ccTasks.Clear()+ ccMetas.Clear()+ scans := scansOf(t, sub)+ for range 3 {+ StatsAndNative(0)+ StatsAndNative(30)+ StatsFor(7)+ }+ if n := scans(); n != 0 {+ t.Fatalf("the stats read an unchanged subagent's file %d times", n)+ }+ // the Sessions list still names the subagent and reads its task+ s := find(t, List(0), "claude", "11111111-2222-3333-4444-555555555555")+ found := false+ for _, sa := range s.Subagents {+ found = found || sa.ID == "b2"+ }+ if !found {+ t.Fatalf("subagents %+v", s.Subagents)+ }+}