Repository navigation
fix(sessions): scope transcript byte stats to the active reset window - #120059
ayaangazali wants to merge 2 commits into
Conversation
48a899e to
bccd904
Compare
|
CI status on this branch, since the red marks are not from this change.
Same patch, different base, different result, so the cause is in
This PR touches three files under |
|
Codex review: needs real behavior proof before merge. Reviewed August 6, 2026, 10:39 PM ET / August 7, 2026, 02:39 UTC. ClawSweeper reviewWhat this changesThe PR makes session transcript byte statistics count only the logical messages visible after Merge readiness⛔ Blocked until real behavior proof from a real setup is added - 4 items remain Keep this PR open: current main still counts the whole reset-retained projection, while the patch fixes that at the canonical visibility owner and resolves the prior retained-tool-result finding. It still needs an after-fix runtime trace, and the repository’s required direct Codex-source inspection was unavailable in this checkout. Priority: P1 Review scores
Verification
How this fits togetherSQLite transcript storage retains historical events across reset boundaries, while reset-window readers determine the logical transcript visible to the next agent turn. The byte statistic feeds compaction and memory-flush safeguards before an agent runs. flowchart LR
A[Stored transcript events] --> B[Reset boundary]
B --> C[Visible message window]
C --> D[Transcript byte statistics]
D --> E[Compaction safeguards]
E --> F[Next agent turn]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +36, Tests +76. Total +112 across 3 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep one reset-window-owned byte-stat path, then attach a redacted after-fix gateway trace proving Do we have a high-confidence way to reproduce the issue? Yes in source: current main retains pre-reset rows but its byte aggregate ignores the reset window, and the resulting byte value reaches both compaction safeguards. The contributor has not supplied an after-fix runtime trace. Is this the best way to solve the issue? Yes for the OpenClaw-owned defect: the reset-window reader owns logical transcript visibility, so correcting its shared statistic repairs both consumers without a fuse-side workaround. Direct Codex contract inspection is still required before a final merge recommendation. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 21e9634f1084. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
bccd904 to
120ccb7
Compare
|
Thanks, the P1 was right and I have fixed it at The retained-tail predicate did use the contiguous active-position range from It now counts the window's own eb.and([
eb("active.active_position", "<", window.boundaryActivePosition),
eb("active.message_position", "in", keptMessagePositions),
])Those positions are already filtered to user and assistant roles by New regression covers exactly your case: a reset carrying
On the real-behavior proof: I have not produced one and I am not going to claim otherwise. The tests above are reader-level. If a runtime session trace showing a post- The remaining red checks are not from this branch. |
|
ClawSweeper status: review started. I am starting a fresh review of this pull request: fix(sessions): scope transcript byte stats to the active reset window This is item 1/1 in the current shard. Shard 21/44. This placeholder means the worker is alive and reading the current context. I will edit this same comment with the actual review when the claws are done clicking. Crustacean status: shell secured, claws on keyboard, evidence pebbles being sorted. |
|
Thank you, @ayaangazali — this PR identified the canonical reset-window owner and established the right repair direction. Since this head was authored, current |
What Problem This Solves
Fixes #119984.
After
/new, a fresh session can fail on every single turn with:The advice in that message is the thing that does not work.
/newis exactly what the user already did.The cause is that
/newdoes not shrink what the byte fuse measures. A reset writes a boundary event into the transcript, but it does not delete the events before it; the projection keeps them and readers are expected to apply the reset window at read time. That is how the message readers behave:resolveVisibleMessagePositionsandreadVisibleMessageRangeinsrc/config/sessions/session-accessor.sqlite-reset-window.tsboth honor the latest reset boundary.readSessionTranscriptActiveStatswas the one reader that skipped that step. It summedLENGTH(event_json)over every row in the active projection with no boundary filter, so the bytes dropped by/newkept counting. Everything downstream inherits that number: it is the only source ofsnapshot.byteSize, which becomestranscriptByteSize, which drives bothshouldCompactByTranscriptBytesand the force flush check insrc/auto-reply/reply/agent-runner-memory.ts. Once the total sits abovemaxActiveTranscriptBytesit stays there, so preflight compaction fires on a session that has nothing left to compact, fails, and prints the message above. Next turn, same thing.Why This Change Was Made
The fix belongs in the reader, not in the fuse. The fuse is asking a reasonable question, "how many bytes is this session carrying," and it was being handed the wrong answer. Guarding at the call site would have left the same wrong number available to the force flush path next to it.
Rather than add a second boundary-aware reader, I moved the aggregate into
session-accessor.sqlite-reset-window.ts, which already owns boundary discovery and already caches the resolved window per generation. The consumer insession-accessor.sqlite-active-events.tscollapses to a single delegation and its duplicate copy of the query is deleted, so there is one byte-stats path instead of two.The retained pre-boundary span is counted using the window's own
keptMessagePositionsrather than a contiguous active-position range. That matters because a reset retains only the user and assistant messages named by the window; an interveningtoolResultis dropped from the next turn. Counting the whole span would have kept discarded tool-result bytes on the fuse, which is the exact latch this PR is trying to remove. Thanks to ClawSweeper for catching that on the first revision.Scope is narrow by construction. Boundary discovery returns no window unless the latest boundary is a
reset, so sessions with no reset, and sessions whose latest boundary is acompaction, sum the whole projection exactly as before. This only changes the case the issue is about.I did not touch the projection writer. Keeping dropped events on disk and windowing at read time is the existing design, the message readers depend on it, and changing it would be a much larger change than this bug needs.
User Impact
/newnow actually clears the byte fuse. A fresh session starts from the bytes it really carries instead of inheriting the ones the reset dropped, so the "Context is too large" loop ends and the advice in that error message works.No config, schema, or default surface changes.
readSessionTranscriptActiveStatskeeps its name, signature, and return shape.Evidence
Two regression tests in
src/config/sessions/session-accessor.sqlite-active-events.test.ts:resetwith no retained history, then a short turn, asserting the reader reports one visible event and drops back under a kilobyte;firstKeptEntryIdwith a 20 KBtoolResultsitting between the retained user and assistant messages, asserting the reader reports two events and stays under a kilobyte. The test also assertsreadSessionTranscriptMessageEventById(scope, "kept-tool")isundefined, so the fixture is pinned to the same visibility rule the message readers use.Both were confirmed to pin the fix by breaking the code and rerunning against the final shape:
then restored for 13/13.
Surrounding surfaces stay green on current
main:src/config/sessions57 files / 771 tests, and the fuse ownersrc/auto-reply/reply/agent-runner-memory2 files / 67 tests.tsgo -p tsconfig.core.jsonandtsgo -p test/tsconfig/tsconfig.core.test.jsonare both clean, oxlint is clean on the changed files, andgit diff --checkis clean.One gap stated plainly rather than buried: I proved this at the reader and through the suites above, not by driving a live provider into the compaction loop and watching a post-
/newturn succeed. The reader is the single source of every byte number both fuses use, which is why I am confident in the mechanism, but I have not produced a runtime session trace. If that trace is required before merge, say so and I will set up a gateway and capture it rather than guess at what it would show.AI-assisted: written with AI assistance. I read the reset-window module, the active-events reader, and the fuse call sites myself, traced every consumer of the byte number, and ran the tests and gates locally.