Commit Graph
1 Commits
Author SHA1 Message Date
yetone 3b3bc359da sessions: a long Codex session being written is read on from where it was, not from its first line
yetone/magpie-releases#24 (LeiCheng42, v0.1.1280): a 30s profile while
Codex ran shows magpie at about a core, ~24% of it in
usage.prefetchSources -> sessions.ReadCallSource -> readCalls -> scanAt.
The tray's usage loop (watchTrayUsage -> usage.QueryPage(Today)), the
usage API and the Sessions page read every source whose size or mtime
changed, and an active Codex rollout changes each turn. A Codex
continuation's index weighs about six entries a call, so a session past
~1,365 calls was over the shared 8192-entry revision budget: its window
was dropped, and every append parsed the whole rollout again from offset
0, for the Requests reader and the summary (List) alike.

Now up to two (revisionActiveFiles) recently written Codex sessions keep
their window past the shared budget, each up to 16x it (131,072
entries), and only while the file changed in the last revisionIdle
(5 min). The full parse built the same index on every append anyway, so
this costs no more at its peak; an idle session still loses it.

Measured (Apple M4 Pro, BenchmarkLongCodexSessionAppend: a 2,000-call,
10.7 MB rollout, one turn appended, then ReadCallSource + List(0)):
  before: 0.87-1.09 s/op
  after:  26-60 ms/op

TestLongCodexSessionAppendReadsOnlyTheAppend (via a scanAt hook) checks
that each of three appends is read from the previous size by both
readers, and that the result DeepEquals a fresh read of the whole file
(calls and summary) after the caches are dropped. On the old code it
fails: "append 0: read from 0, not where the last read ended
(10691427)". TestRevisionEntryBudget covers the two-window cap and the
idle/oversize drops.

Run: go test -tags nogui ./internal/sessions/ ok;
go test -tags nogui -timeout 45m ./... with the redact change on top,
under a load average of 440-610 from other sessions' suites: 59 ok, and
agent and gateway (45m timeout), gui (TestSetAnswersWhileDevinAndProvidersHang,
set took 1m30s), edit (TestTOMLBigFileParsesInLinearTime, 1.0s) and
middleware (TestStream, onEvent "took too long") failed on time. edit and
middleware rerun alone: ok. agent and gateway rerun at a lower load: ok; gui rerun: ok. (The first
rerun had TestPluginStreamLargeReplies red on time again, #2551, which
passes alone in 22s, and TestDiffLines at 2.04s against its 2s bound,
filed as #2766.)
gofmt -l clean; GOOS=linux and GOOS=windows go vet -tags nogui ./... ok.
2026-10-18 02:43:03 +08:00