Commit Graph
4 Commits
Author SHA1 Message Date
yetone f1eeeb8fd5 sessions: a Codex session's window lives an hour past its last change, not five minutes (#4369)
A Codex rollout's summary and its calls each keep an index of what they
read (the Codex window) so the next lines are read on from where the last
read ended. A window was let go five minutes after its file last changed
(revisionIdle), so the turn after any longer pause (a long think, a
meeting, a review of the diff) read the whole rollout again from its
first line, for the summary and the calls alike: on #4369's real
rollouts, 21.5 MB read twice for one line.

revisionIdle is an hour, as a working Claude window's already is
(revisionWorking). What can be held is bounded as before:
revisionFiles (8) windows within revisionEntries, and revisionActiveFiles
(2) past it up to revisionActiveEntries each, so the most held is what
working sessions held already; an idle one is held longer. A session
left over an hour is read whole once on its next turn, now in one pass
for both readers (the commit before).

Run on mote (macOS 27.2):
- TestCodexSessionReadOnAfterAPause (new): a 40-call rollout last changed
  ten minutes ago is read (calls, then List), a turn appended: no scan
  of it from 0, 41 calls. With revisionIdle back at five minutes:
  "the turn after a pause read the rollout from its first line: [0 0]".
  Restored: ok.
- go test ./internal/sessions -run
  "Pause|Revision|Settled|LongCodex|PlainRollout": ok.
- go test -timeout 45m ./internal/sessions ./internal/usage
  ./internal/gateway ./internal/gui: ok for sessions (11.3s, -race 56.2s, at this tree), usage (30.2s), gateway (575.6s); internal/gui: ok but TestMainWindowCorners/macOS_26_SDK, red on macOS 27 as #3949 records (same message), untouched here
- TestIdleWindowsYieldToRecentWork's ten-minute pause was written
  -2*revisionIdle (ten minutes at five); it is ten minutes as written,
  since at an hour it was a two-hour pause, past revisionWorking.
- gofmt -l: clean.

Not measured: RSS over an hour of real Codex use with several sessions
open; the bound is the count above, not a measurement.
2026-11-02 06:11:06 +08:00
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
Fanbuz c21cd8c881 sessions: reconcile replayed Claude message usage without persisting message maps (#697)
* fix: 按消息修订校正 Claude 用量并限制缓存状态

* fix: 释放历史 Claude 索引并按字段读取请求标识

* fix: 保留大型 Claude 会话的增量读取窗口

* fix: 修正 Qoder 重计并按解析成本保留会话窗口

* fix: 避免历史会话窗口挤占活跃日志缓存
2026-10-04 10:01:52 +08:00
Fanbuz 67004a7e8f sessions: count Codex RECORD and compaction usage without a history parent (#695)
* fix: 按本地事件配对统计 Codex 响应与压缩用量

* fix: 限制用量索引内存并精简磁盘缓存

* fix: 淘汰解析索引后仍释放请求行缓存
2026-10-04 07:57:49 +08:00