perf(core): avoid bulk-loading every journal segment on incremental session-log reads
Problem
JournalSessionLog.scan(after, through) always calls loadCommitSegments(), which lists every commits/* object and bulk-reads all of their values. This happens for every readAfter(...) call.
AG-UI /agui/connect follows the session log and calls readAfter(cursor, 256) every 200 ms. When the cursor is near the head only a few events are new, but the current code still reads the whole journal's commit payloads from the store (on the JDBC store: SELECT item_key, value_json, version ... WHERE item_key IN (...)).
On long conversations this turns a small tail read into repeated full-journal reads.
Expected
Bulk loading is only worth it when replaying from the beginning. For incremental reads (after > 0), only the segments between head and after are needed; committedSegment(id, null) already falls back to a per-segment read.
Proposed change
// Only a full replay (after == 0) is worth a bulk load; incremental reads
// should read segments on demand so polling does not re-read the whole journal.
Map<String, AtomicSessionStorage.Value> loadedSegments =
after == 0 ? loadCommitSegments() : null;
Acceptance
scan(after > 0, through)does not calllistPaths/readAll.scan(0, through)keeps the bulk path.- The emitted event sequence is identical on both paths.
- Covered by
JournalSessionLogTest.
Implementation proposed in #4085: bulk pre-read is now limited to after == 0, and incremental reads use the existing per-segment read fallback. Tests cover the no-list/no-readAll assertion, the bulk path, and identical event sequences.