Skip to content

Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.

sessions: a packed Codex rollout whose stamp changed is decompressed once at start, for both Sessions and Requests

yetone5466cc76041a
diff --git a/internal/sessions/call_cache.go b/internal/sessions/call_cache.go
index 04e9f759c..7b12a8dec 100644
--- a/internal/sessions/call_cache.go
+++ b/internal/sessions/call_cache.go
@@ -222,10 +222,16 @@ var lineCallReaders = map[string]lineCallReader{
"omp": {piCallsBegin, readPiCallLine, piCallsKept},
}
-func readCalls(f file) *callFile {
+// callLock is the lock a file's calls are read under, so that two readers
+// never read the same file at once.
+func callLock(path string) *sync.Mutex {
h := fnv.New32a()
- _, _ = h.Write([]byte(f.path))
- lock := &callIO[h.Sum32()%uint32(len(callIO))]
+ _, _ = h.Write([]byte(path))
+ return &callIO[h.Sum32()%uint32(len(callIO))]
+}
+
+func readCalls(f file) *callFile {
+ lock := callLock(f.path)
lock.Lock()
defer lock.Unlock()
callsMu.Lock()
@@ -334,6 +340,84 @@ func readCalls(f file) *callFile {
return st
}
+// callsRide reads a packed Codex rollout's calls on the scan that parses its
+// summary. A packed file is decompressed whole for every read, and when the
+// Codex app packs or repacks every rollout (11,591 on 10-20) the start's
+// warm-up parsed each for the Sessions page and then read each again for
+// Requests' calls: ~48 GB decompressed twice. Reading both on one pass
+// leaves readCalls a shard on disk that is already up to date.
+type callsRide struct {
+ f file
+ st *callFile
+ generation uint64
+ lock *sync.Mutex
+ sum, calls bool // what each reader's head said of the line being read
+}
+
+// callsAlong is a ride for f's calls when f is a packed Codex rollout whose
+// calls are to be read again, and nil otherwise. It holds the file's calls
+// lock until release, so a readCalls of the file meanwhile waits for what
+// the ride reads rather than read it again.
+func callsAlong(f file) *callsRide {
+ if f.agent != "codex" || !packed(f.path) || f.cold || wslCold(f.path) {
+ return nil
+ }
+ lock := callLock(f.path)
+ lock.Lock()
+ callsMu.Lock()
+ old, generation := callCache[f.path], callGeneration
+ callsMu.Unlock()
+ if old == nil {
+ old = restoreCallContinuation(loadCalls(f))
+ }
+ if old != nil && old.Size == f.size && old.Mod == f.mod.UnixNano() {
+ lock.Unlock()
+ return nil
+ }
+ return &callsRide{f: f, st: prepareCalls(f, old), generation: generation, lock: lock}
+}
+
+// ride is a scan's head and line for both readers: each head sees every
+// line, as on a scan of its own, and each line goes to the readers whose
+// head wanted it.
+func (r *callsRide) ride(head func([]byte) bool, line func([]byte, int64, int64) bool) (func([]byte) bool, func([]byte, int64, int64) bool) {
+ return func(b []byte) bool {
+ r.sum = head == nil || head(b)
+ r.calls = callHead(r.st, b)
+ return r.sum || r.calls
+ }, func(b []byte, start, end int64) bool {
+ if r.sum {
+ line(b, start, end)
+ }
+ if r.calls {
+ r.st.At, r.st.End = start, end
+ codexCallLine(r.st, b)
+ }
+ return true
+ }
+}
+
+// release lets the file's calls lock go.
+func (r *callsRide) release() { r.lock.Unlock() }
+
+// finish keeps the calls read, as readCalls would have, when the scan
+// read to its end; after a failed one readCalls reads them itself.
+func (r *callsRide) finish(off int64, err error) {
+ if err != nil {
+ return
+ }
+ st, f := r.st, r.f
+ st.Off, st.Size, st.Mod = off, f.size, f.mod.UnixNano()
+ st.ContentHash = prefixHash(f.path, off)
+ writeCalls(st, 0, false)
+ st.dirty = nil
+ callsMu.Lock()
+ if r.generation == callGeneration {
+ keepCalls(f.path, st)
+ }
+ callsMu.Unlock()
+}
+
// Common strings are stored once per append frame; File is implied by State.
type callPatch struct {
Index int
diff --git a/internal/sessions/codex_zst_warm_test.go b/internal/sessions/codex_zst_warm_test.go
new file mode 100644
index 000000000..7a4e3cafc
--- /dev/null
+++ b/internal/sessions/codex_zst_warm_test.go
@@ -0,0 +1,117 @@
+package sessions
+
+import (
+ "os"
+ "path/filepath"
+ "reflect"
+ "strings"
+ "sync"
+ "testing"
+ "time"
+)
+
+// TestPackedRolloutReadOnceForSessionsAndCalls: the start's warm-up parses
+// every changed session file for the Sessions page, then reads every
+// changed file's calls for Requests. A packed rollout is decompressed whole
+// for each read, so when the Codex app repacked all of them (11,591 on
+// 10-20) each was decompressed twice. Its calls are now read on the
+// parse's own pass, and what both pages get is what the two reads gave.
+func TestPackedRolloutReadOnceForSessionsAndCalls(t *testing.T) {
+ _, codex := setup(t)
+ writeLines(t, filepath.Join(codex, "sessions", "2026", "09", "21", "rollout-2026-09-21T10-00-00-0190aaaa-1111-7222-8333-444455556666.jsonl"), longRollout(0, 40)...)
+ for _, p := range rollouts(t, codex) {
+ pack(t, p, false)
+ }
+ // nothing kept: neither the summaries nor the calls' shards
+ forget := func() {
+ os.Remove(CachePath())
+ os.RemoveAll(callCacheDir())
+ Reset()
+ }
+
+ var mu sync.Mutex
+ scans := map[string]int{}
+ scanHook = func(p string, off int64) {
+ if strings.HasSuffix(p, zstSuffix) {
+ mu.Lock()
+ scans[p]++
+ mu.Unlock()
+ }
+ }
+ t.Cleanup(func() { scanHook = nil })
+ counted := func() map[string]int {
+ mu.Lock()
+ defer mu.Unlock()
+ out := scans
+ scans = map[string]int{}
+ return out
+ }
+ readCallsAll := func() map[string][]Call {
+ out := map[string][]Call{}
+ for _, s := range CallSources() {
+ if s.Agent == "codex" {
+ out[s.Path] = ReadCallSource(s)
+ }
+ }
+ return out
+ }
+ day := time.Date(2026, 9, 30, 0, 0, 0, 0, time.UTC)
+
+ // as before: calls read first, then the summaries, each on a scan of
+ // its own; the reference for what both pages get
+ forget()
+ counted()
+ wantCalls := readCallsAll()
+ wantList, wantStats := List(0), StatsAt(0, day)
+ before := counted()
+ n := 0
+ for p, k := range before {
+ if k != 2 {
+ t.Fatalf("calls, then sessions: %s scanned %d times, want 2", p, k)
+ }
+ n++
+ }
+ if n != 3 {
+ t.Fatalf("%d packed rollouts scanned, want 3: %v", n, before)
+ }
+ calls := 0
+ for _, cs := range wantCalls {
+ calls += len(cs)
+ }
+ if calls < 40 {
+ t.Fatalf("only %d calls read: the fixture tests nothing", calls)
+ }
+
+ check := func(name string) {
+ t.Helper()
+ list, stats := List(0), StatsAt(0, day)
+ got := readCallsAll()
+ for p, k := range counted() {
+ if k != 1 {
+ t.Errorf("%s: %s scanned %d times, want once", name, p, k)
+ }
+ }
+ if !reflect.DeepEqual(got, wantCalls) {
+ t.Errorf("%s: calls differ from their own read's", name)
+ }
+ if name == "first read" && (!reflect.DeepEqual(list, wantList) || !reflect.DeepEqual(stats, wantStats)) {
+ t.Errorf("%s: sessions differ from a read without the calls", name)
+ }
+ }
+
+ // the warm-up's order with nothing kept: sessions, then calls
+ forget()
+ counted()
+ check("first read")
+
+ // every rollout repacked: both pages' kept reads are stale
+ later := time.Now().Add(-time.Hour)
+ for p := range wantCalls {
+ if err := os.Chtimes(p, later, later); err != nil {
+ t.Fatal(err)
+ }
+ }
+ Reset()
+ counted()
+ check("after repacking")
+}
diff --git a/internal/sessions/sessions.go b/internal/sessions/sessions.go
index 1bc2efe11..ab9bce45e 100644
--- a/internal/sessions/sessions.go
+++ b/internal/sessions/sessions.go
@@ -852,12 +852,15 @@ func refresh(want, all []file) {
go func() {
for i := range ch {
j := &jobs[i]
+ // its file's calls lock is taken before a read slot, as
+ // readCalls takes them
+ calls := callsAlong(j.f)
release := readSlot()
end := readBegin()
if parseHook != nil {
parseHook()
}
- j.parsed = parse(j.f, j.old)
+ j.parsed = parseWith(j.f, j.old, calls)
end()
release()
if (j.parsed.Claude != nil && !windows[j.f.path]) || (j.parsed.Claude == nil && !recentRevision(j.parsed.Mod, j.parsed.revisionWeight(), time.Now())) {
@@ -1293,7 +1296,14 @@ func parserFor(agent string) sessionParser {
}
// parse reads a file on from where old left it, or from the start.
-func parse(f file, old *state) *state {
+func parse(f file, old *state) *state { return parseWith(f, old, nil) }
+
+// parseWith is parse with calls, when not nil, reading the file's calls on
+// the same pass.
+func parseWith(f file, old *state, calls *callsRide) *state {
+ if calls != nil {
+ defer calls.release()
+ }
// Summary caches contain aggregates only. After a restart, a changed
// Codex file rebuilds its transient response index from the source.
if f.agent == "codex" && old != nil && old.Codex == nil {
@@ -1325,13 +1335,20 @@ func parse(f file, old *state) *state {
if f.agent == "codex" {
head = func(b []byte) bool { return codexHead(s, b, f.main) }
}
- off, err := scanAt(f.path, s.Off, head, func(b []byte, _, _ int64) bool {
+ line := func(b []byte, _, _ int64) bool {
parser.line(s, b, f.main)
return true
- })
+ }
+ if calls != nil {
+ head, line = calls.ride(head, line)
+ }
+ off, err := scanAt(f.path, s.Off, head, line)
if err == nil {
s.Off = off
}
+ if calls != nil {
+ calls.finish(off, err)
+ }
if isBuddy(f.agent) && s.Cwd == "" {
workbuddyMeta(s, f.path)
}