[Bug] JournalSessionLog.scan bulk-loads the whole journal on incremental reads
Summary
JournalSessionLog.scan(after, through) always calls loadCommitSegments() before walking the commit chain. That helper runs listPaths() plus readAll() over every commit segment in the journal, even when after > 0 and only the head -> after suffix is needed.
Impact
Any incremental reader pays a full-journal scan on every poll. The AG-UI connect path polls readAfter about every 200 ms, so a long journal turns each poll into a listing plus a batch read of its entire commit history. Cost grows with session length and the read amplification is unbounded relative to the events actually requested.
Root cause
agentscope-core/.../session/JournalSessionLog.java, scan:
Map<String, AtomicSessionStorage.Value> loadedSegments = loadCommitSegments();
Bulk loading was introduced to make full replay one round-trip, but it is applied unconditionally, including incremental reads.
Proposed fix
Only bulk-load for a full replay (after == 0). Incremental reads pass null here, so committedSegment(id, null) keeps its existing per-segment storage.read(path) fallback and only reads the segments the chain walk touches:
Map<String, AtomicSessionStorage.Value> loadedSegments =
after == 0 ? loadCommitSegments() : null;
No change to commit-chain validation, event filtering, or the bulk path for full replay.
Tests
Added to JournalSessionLogTest with a counting AtomicSessionStorage:
scan(after > 0, ...)never callslistPaths/readAll.scan(0, ...)still bulk-loads.- Bulk and incremental replay return the same event sequence.
mvn -o -pl agentscope-core test -Dtest=JournalSessionLogTest — 11 tests, 0 failures.
Duplicate of #4083, which already tracks this issue. Implementation is in #4085.