agentscope-java icon indicating copy to clipboard operation
agentscope-java copied to clipboard

[Bug]: StoreSessionStorage does not override readAll, so journal replay issues one get per segment

Open chcodex opened this issue 3 weeks ago • 0 comments

Describe the bug

JournalSessionLog.scan bulk-loads committed segments through AtomicSessionStorage.readAll, which was added in #3666. StoreSessionStorage, used by remote workspace stores such as JDBC/MySQL, Redis and MongoDB, does not override readAll. It therefore falls back to the default per-path implementation, and replay of a large journal becomes one BaseStore.get round-trip per commit segment.

A journal with 2,658 commit segments performs 2,658 JdbcStore.get calls. On a remote MySQL instance this takes tens of seconds.

To Reproduce

  1. Use a remote workspace store backed by BaseStore with supportsAtomicSessionStorage() == true (for example JdbcStore over MySQL).
  2. Create a session journal with thousands of commit segments.
  3. Call scan/readAfter, or restore the session.
  4. Observe one get per segment in the SQL log and replay latency that grows linearly with the segment count.

Expected behavior

StoreSessionStorage should implement readAll by fetching the requested journal objects in bulk, so journal replay uses a bounded number of store queries instead of one per segment.

Actual behavior

The default AtomicSessionStorage.readAll calls read(path) for every path, and StoreSessionStorage.read calls store.get(namespace, path) once per segment.

Environment

  • AgentScope-Java Version: 2.1.0-SNAPSHOT
  • Java Version: 17
  • OS: Linux
  • Store: remote JDBC/MySQL (the same path applies to Redis and MongoDB through BaseStore)

Proposed fix

Add an opt-in BulkReadableStore extends BaseStore capability that declares getAll(namespace, keys), keeping BaseStore itself source-compatible:

  • InMemoryStore, JDBC, MySQL, PostgreSQL, MongoDB and Redis implement getAll;
  • JDBC/MySQL/PostgreSQL use batched IN (...) queries; MongoDB uses $in; Redis uses bounded HGETALL pipelines;
  • StoreSessionStorage.readAll uses a direct get for a single path, getAll for multiple paths when the store is bulk-readable, and otherwise keeps the paged search fallback with missing-path reads and per-key fallback when search is unsupported;
  • preserve the exact read semantics: missing paths are absent, version < 1 throws SessionLogException, values are base64-decoded, duplicate paths are deduplicated.

Tests cover parity with per-path read, more than 256 paths, fallback behavior, versions, missing paths, and the JDBC/MySQL/PostgreSQL/MongoDB/Redis implementations.

Implemented in #3996.

chcodex avatar Nov 05 '26 08:11 chcodex