diff --git a/internal/sessions/calls.go b/internal/sessions/calls.go index 915e46ce8..afd96d23a 100644 --- a/internal/sessions/calls.go +++ b/internal/sessions/calls.go @@ -286,7 +286,10 @@ func callsFor(since time.Time, session, agent string) []Call { // callFiles are the session files that hold calls: Claude Code's, Cowork's // and Desktop's own, and Codex's. -func callFiles() []file { +func callFiles() []file { return callFilesWith(codexFiles()) } + +// callFilesWith is callFiles with codex the rollouts codexFiles found. +func callFilesWith(codex []file) []file { var out []file seen := map[string]bool{} add := func(fs []file) { @@ -305,7 +308,7 @@ func callFiles() []file { add(ccFiles("claude-desktop", h)) } } - add(codexFiles()) + add(codex) add(wslFiles("claude", "codex")) return out } @@ -320,8 +323,11 @@ func callFiles() []file { // that may be packed in zstd frames, is read on from the frame it was // left in (readDshCalls). Every agent here needs an entry in // wholeCallReaders, lineCallReaders or resumeCallReaders. -func callSources() []file { - out := callFiles() +func callSources() []file { return callSourcesWith(codexFiles()) } + +// callSourcesWith is callSources with codex the rollouts codexFiles found. +func callSourcesWith(codex []file) []file { + out := callFilesWith(codex) out = append(out, openCodeCallFiles()...) out = append(out, zcodeCallFiles()...) out = append(out, dshCallFiles()...) @@ -1070,8 +1076,19 @@ type CallSource struct { Modified time.Time } -func CallSources() []CallSource { - fs := callSources() +func CallSources() []CallSource { return callSourcesOf(callSources()) } + +// CallSourcesAndCodexIdentities is CallSources and CodexIdentities from one +// walk of the Codex folders. The Requests page asks for both on every +// rebuild, and the walk lstat()s each rollout: twice over 12k rollouts was +// ~150ms of each rebuild. +func CallSourcesAndCodexIdentities() ([]CallSource, map[string]CodexIdentity) { + codex := codexFiles() + sources := callSourcesOf(callSourcesWith(codex)) + return sources, codexIdentitiesOf(codex) +} + +func callSourcesOf(fs []file) []CallSource { pruneCalls(fs) out := make([]CallSource, 0, len(fs)) for _, f := range fs { diff --git a/internal/sessions/codex.go b/internal/sessions/codex.go index 8d27e7bc0..fff986e5e 100644 --- a/internal/sessions/codex.go +++ b/internal/sessions/codex.go @@ -3,6 +3,7 @@ package sessions import ( "bytes" "encoding/json" + "slices" "strings" "time" @@ -276,14 +277,18 @@ func noteCodexIdentity(s *state, identity CodexIdentity, conflict bool) { } // CodexIdentities returns an independent snapshot of the native thread identities. -func CodexIdentities() map[string]CodexIdentity { +func CodexIdentities() map[string]CodexIdentity { return codexIdentitiesOf(codexFiles()) } + +// codexIdentitiesOf is CodexIdentities with codex the rollouts codexFiles +// found. +func codexIdentitiesOf(codex []file) map[string]CodexIdentity { storeMu.RLock() defer storeMu.RUnlock() mu.Lock() defer mu.Unlock() loadCache() defer useDBs()() - want := append(codexFiles(), wslFiles("codex")...) + want := append(slices.Clip(codex), wslFiles("codex")...) refresh(want, nil) return codexIdentitySnapshot(want) } diff --git a/internal/sessions/codex_identity_test.go b/internal/sessions/codex_identity_test.go index c87552957..e3282e8ad 100644 --- a/internal/sessions/codex_identity_test.go +++ b/internal/sessions/codex_identity_test.go @@ -94,6 +94,9 @@ func TestCodexIdentityParentChainsAndSummaryCache(t *testing.T) { if got := CodexIdentities()["main-a"]; got.Role != codexRoleMain || got.RootSession != "main-a" { t.Fatalf("identity snapshot shares its map: %+v", got) } + if sources, ids := CallSourcesAndCodexIdentities(); !reflect.DeepEqual(sources, CallSources()) || !reflect.DeepEqual(ids, CodexIdentities()) { + t.Fatalf("one walk for both differs: %d sources, %d identities", len(sources), len(ids)) + } listed := map[string]Session{} for _, s := range List(All) { diff --git a/internal/usage/request_page.go b/internal/usage/request_page.go index cec40ae06..cafa1e597 100644 --- a/internal/usage/request_page.go +++ b/internal/usage/request_page.go @@ -560,8 +560,7 @@ type requestState struct { } func readRequestState(now time.Time) requestState { - sources := sessions.CallSources() - codexIdentities := sessions.CodexIdentities() + sources, codexIdentities := sessions.CallSourcesAndCodexIdentities() slices.SortFunc(sources, func(a, b sessions.CallSource) int { if n := a.Modified.Compare(b.Modified); n != 0 { return n