Skip to content

perf(harness): list session journal keys without loading values - #4051

Draft
chcodex wants to merge 1 commit into
agentscope-ai:mainfrom
chcodex:perf/session-log-list-prefix
Draft

chcodex wants to merge 1 commit into
agentscope-ai:mainfrom
chcodex:perf/session-log-list-prefix

Conversation

@chcodex

@chcodex chcodex commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #4050

Problem

StoreSessionStorage.listPaths(prefix) discovered journal paths by paging BaseStore.search(namespace, 256, offset) and filtering startsWith(prefix) in the client. For JDBC stores, storeSearch projects item_key, value_json, version, so every listing transferred the values of the entire namespace.

In a shared workspace namespace with 9,140 commit segments (~395.8 MB), one chat-history export retry therefore pulled the full namespace before loading any segment:

ChatHistoryService.retryPendingExports
  → drainPendingExports
  → JournalSessionLog.scan
  → loadCommitSegments
  → StoreSessionStorage.listPaths
  → JdbcStore.search

Change

  • Add BaseStore.listKeys(namespace, keyPrefix) with a default paged search + startsWith fallback, returning sorted keys so every existing backend stays compatible.
  • StoreSessionStorage.listPaths(prefix) now delegates to store.listKeys(namespace, prefix).
  • Add JdbcStore.listKeys, backed by a new StoreDialect.storeListKeys:
    • SELECT item_key FROM <store> WHERE namespace_path = ? AND item_key LIKE ? ESCAPE '!' ORDER BY item_key
    • does not project value_json;
    • reuses the existing LIKE escaping helper, including literal %, _ and the escape character itself.
  • Preserve readAll / batch-read and listPaths semantics, including empty prefix handling.

After the change, listPaths transfers only the matching keys instead of every value in the namespace.

Relationship to #3996

This is an independent optimization and does not replace or modify the batch-read work in #3996:

Both can land independently; neither changes the other's behavior.

Tests

  • BaseStoreContractTest: prefix filtering, ordering, empty prefix, and pagination beyond one search page (300 keys).
  • StoreSessionStorageListPathsTest: listPaths delegates to listKeys, and falls back to paged search for stores without an override.
  • JdbcStoreH2Test: key-only listing order, LIKE wildcard escaping, empty prefix, and exact-namespace filtering.
  • DialectSqlTests: storeListKeys SQL projects only item_key.

Verified with:

mvn -o -q -pl agentscope-harness,agentscope-extensions/agentscope-extensions-jdbc -am -DskipTests -Dmaven.javadoc.skip=true install
mvn -o -q -pl agentscope-harness,agentscope-extensions/agentscope-extensions-jdbc spotless:check
mvn -o -pl agentscope-harness,agentscope-extensions/agentscope-extensions-jdbc test

Harness: 1,623 tests, 0 failures (12 skipped). JDBC: 181 tests, 0 failures. No production MySQL was used; JDBC coverage runs on H2.

Merge order

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 重要不紧急

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf(harness): list session journal keys without loading values

2 participants