Repository navigation
Conversation
This was referenced Nov 9, 2026
JournalSessionLog.scan unconditionally called loadCommitSegments(), so every incremental read (after > 0, e.g. the AG-UI connect poll every 200ms) listed and read every commit segment in the journal even though only the head -> after suffix is needed. Bulk pre-read is now limited to a full replay (after == 0); incremental reads fall back to per-segment reads via committedSegment(id, null). The commit walk and event filtering are unchanged. Tests: add a counting AtomicSessionStorage and assert incremental scans never call listPaths/readAll, full replays still do, and both paths return the same event sequence.
chcodex
force-pushed
the
fix/session-log-bulk-load
branch
from
November 9, 2026 11:47
9eddef6 to
194ae14
Compare
chcodex
marked this pull request as draft
November 10, 2026 02:26
This was referenced Nov 10, 2026
…ded batches Commit segments are named <20-digit firstSeq>.json, so the lexicographic key order of commits/ equals the sequence order. scan(after, through) lists the session's commit keys once, binary-searches the segment covering after, and validates only the boundary segments; the iterator then reads 256 segments at a time and checks firstSeq/lastSeq/parent while streaming, so heap use no longer grows with the journal size. after == 0 takes the same path instead of bulk-loading every segment, and journals with legacy <sha256>.json keys still fall back to the parent-chain walk.
chcodex
force-pushed
the
fix/session-log-bulk-load
branch
from
November 10, 2026 10:40
2a32525 to
b1ce0d5
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
JournalSessionLog.scan(after, through)always walked the parent chain fromheaddown toafter, and fetched commit segments one by one. The cost grew with session length: on a 445-segment journal, an AG-UI replay from an arbitraryafterSequencespent 1.6–10 s just locating the range, and memory use grew with the number of segments touched.Change
commits/<20-digit zero-padded firstSeq>.json, so lexicographic key order is sequence order.scan(after, through)lists the journal's commit keys once, binary-searches the segment coveringafter, and reads only the first, last, and one anchor segment to validate the boundaries. Segment contents are not bulk-read just to find the range.readAllbatches of at most 256, validatesfirstSeq,lastSeq, andparentper segment as it streams, and keeps memory bounded to one batch instead of the whole journal.after == 0also goes through key locating instead of bulk-loading every segment. The old bulk load remains only as a fallback when locating is impossible.<sha256(batchId)>.jsonsegments fall back to the previous parent-chain walk. Any key that cannot be parsed as a sequence name triggers the same fallback.Measured on a 445-segment session:
after=01.78 s,after=10001.65 s,after=50000.68 s; locating takes ~30 ms and peak memory is bounded to 256 segments.Tests
JournalSessionLogTestcovers sequence-named locating, mid-segment cursors, boundaries (0,head.seq(),> head.seq()), mixed legacy/sequence journals, unparseable keys, and the bounded batch path.Spotless:
mvn -o -pl agentscope-core spotless:check— clean.Fixes #4083
Merge order
listKeyswithout loading values): locating a segment lists journal keys, so the prefix query must not projectvalue_json.