Every Requests page lists every session file again
(CallSourcesAndCodexIdentities), and on a busy machine that listing was
most of a warm page after the pairing memo (#3493): ~130ms for 15.6k
Codex rollouts and the Claude Code transcripts, of which the lstat of
each rollout was half, stat()ing each Claude file a sixth, and
pruneCalls a sixth: it read the ~16k-shard cache folder and sha256'd
every path on each call.
- statFiles stats the files a walk found on up to 8 goroutines (from 512
files), keeping the walk's order and leaving out what is gone or no
regular file, as before. Codex's still take their info from the walk's
entry (free on Windows), Claude Code's from os.Stat.
- pruneCalls still drops the in-memory entries of gone files each call,
but looks over the shard folder (and hashes the paths for it) at most
once a minute, and at once when the cache folder moved. Temps already
waited an hour; an orphan shard waits up to a minute more.
Run at 4982ded8a (origin/main, fetched):
go test -timeout 45m of agent (363s), cli (77.7s), davsync (78.4s),
gateway (533s), gui (150s), otlp (20.4s), tui (33.6s), tune (2.9s), usage
(51.4s), usageapi (14.8s): ok. sessions was red at first:
TestRequestShardsAreBoundedAndIndependent found a removed session's shard
still there, since the sweep waited its minute. pruneCalls now sweeps at
once when a file it had read is gone; sessions ok (19.2s) after, and
usage (18.6s) and usageapi (4.6s) again. gofmt clean; GOOS=linux and
GOOS=windows go vet -tags nogui ./internal/sessions/ clean.
Real data (sandbox HOME with the live ~/.codex/sessions and
~/.claude/projects symlinked, read only): the old and new listings,
dumped as path, key, agent, size and mtime, are the same 15,601 sources
in the same order with the same 12,077 Codex identities. Mean of 20
listings after a first one, load ~160: old 142 / 132 ms, new 56 / 66 ms.
Tests: TestCodexFilesStatInOrder (new; 1500 rollouts with folders,
links and files of every size in one day, -race -count=3) is red when
statFiles keeps what failed to stat and when a worker skips half its
batch. TestCallShardsSweptOnceAMinute (new) is red with the gate taken
out. TestAbandonedCallTempsAndLRU now clears the gate before the call
that must sweep.
53 lines
1.5 KiB
Go
53 lines
1.5 KiB
Go
package sessions
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"runtime"
|
|
"testing"
|
|
)
|
|
|
|
// The rollouts of a busy Codex folder are stat()ed on several goroutines,
|
|
// and the list comes back as one walk gave it: in the walk's order, each
|
|
// with its own size, and without what is gone, a folder or a link.
|
|
func TestCodexFilesStatInOrder(t *testing.T) {
|
|
dir := t.TempDir()
|
|
day := filepath.Join(dir, "sessions", "2026", "09", "30")
|
|
if err := os.MkdirAll(day, 0700); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var want []string
|
|
for i := range 1500 {
|
|
name := fmt.Sprintf("rollout-2026-09-30T10-00-00-t%04d.jsonl", i)
|
|
p := filepath.Join(day, name)
|
|
switch {
|
|
case i%97 == 5:
|
|
if err := os.Mkdir(p, 0700); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
continue
|
|
case i%89 == 7 && runtime.GOOS != "windows":
|
|
if err := os.Symlink(filepath.Join(day, "rollout-2026-09-30T10-00-00-t0000.jsonl"), p); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
continue
|
|
}
|
|
if err := os.WriteFile(p, make([]byte, i), 0600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
want = append(want, p)
|
|
}
|
|
got := codexFilesIn(dir)
|
|
if len(got) != len(want) {
|
|
t.Fatalf("%d rollouts, want %d", len(got), len(want))
|
|
}
|
|
for i, f := range got {
|
|
var n int
|
|
fmt.Sscanf(filepath.Base(f.path), "rollout-2026-09-30T10-00-00-t%04d.jsonl", &n)
|
|
if f.path != want[i] || f.size != int64(n) || f.mod.IsZero() || f.key != fmt.Sprintf("codex:t%04d", n) {
|
|
t.Fatalf("rollout %d: %s size %d key %s, want %s size %d", i, f.path, f.size, f.key, want[i], n)
|
|
}
|
|
}
|
|
}
|