Skip to content

fix(harness): skip foreign head files during journal discovery - #4310

Merged
jujn merged 2 commits into
agentscope-ai:mainfrom
c020627:fix-journal-list-skip-foreign-head
Nov 23, 2026
Merged

jujn merged 2 commits into
agentscope-ai:mainfrom
c020627:fix-journal-list-skip-foreign-head

Conversation

@c020627

@c020627 c020627 commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

AgentScope-Java Version

2.1.0-SNAPSHOT (main @ 2fb5400e)

Description

Problem. WorkspaceThreadJournalStore.list() discovers threads by taking every path returned by journalStorage(...).listPaths("agents/"), splitting it on /, and then deciding whether it is a thread head:

.map(path -> path.split("/"))
.filter(parts -> parts[2].equals("sessions")
        && parts.length == 8
        && parts[5].equals("threads"))

parts[2] is evaluated before parts.length == 8, so the length guard cannot protect it. The listing therefore only works when every listed path happens to have at least three segments. Any storage backend that also lists a head.json outside the thread layout makes the whole discovery throw:

java.lang.ArrayIndexOutOfBoundsException: Index 2 out of bounds for length 2

Concrete triggers for a same-directory backend: a workspace-level head.json written by another component, a truncated or partially-written tree, or a foreign tenant sharing the bucket. The failure is total — one unrelated file aborts discovery for all users and sessions in that filesystem.

Eight-segment paths fail the other way. A path like agents/<agent>/sessions/<user>/<session>/threads/<thread>/head.json whose key segments are not encoded passes the shape filter and then throws IllegalArgumentException: Invalid session key from decode(...).

This is a guard-ordering defect rather than an intended restriction: the parts.length == 8 check exists precisely to reject non-thread paths, and listPaths returns a backend-defined superset that the store cannot assume is clean.

Change. Validate the path shape — including that the three key segments carry their s_/u_/t_ prefixes and the user segment decodes — before indexing the array or decoding anything, via a isThreadKeyPath(String[]) helper. Foreign head.json files are now skipped instead of failing the listing, so discovery stays total. No behavior change for well-formed paths; no new dependencies; no API changes.

Regression evidence. New test discoverySkipsForeignHeadFilesInsteadOfFailingTheListing in WorkspaceThreadJournalStoreTest feeds a mocked listPaths result containing a workspace-level head.json, a two-segment path, an eight-segment path with unencoded key segments, and one valid thread head, then asserts only the valid one is discovered.

  • On unmodified source: fails with ArrayIndexOutOfBoundsException: Index 2 out of bounds for length 2 (the whole list() throws); the nine pre-existing tests in the class still pass.
  • After the fix: passes, and all 10 tests in the class pass.

Verification (module agentscope-harness):

  • mvn -q -pl agentscope-harness -Dtest=WorkspaceThreadJournalStoreTest test — before fix: 1 failed / 9 passed; after fix: 10 passed.
  • mvn -q -pl agentscope-harness spotless:apply then spotless:check — passed.
  • mvn -q -pl agentscope-harness test — the only failures are 7 pre-existing symlink tests (LocalFilesystemModeTest, AtPathExpansionMiddlewareTest) that fail identically on unmodified main on this Windows host (symlink creation requires privileges). Verified by stashing the change and re-running those two classes on clean main.

Scope is confined to one source file and one existing test file; no open PR touches either.

Checklist

  • Code has been formatted with mvn spotless:apply (verified via mvn spotless:check)
  • All tests are passing (mvn test for agentscope-harness: no regressions; the 7 symlink failures reproduce on unmodified main on Windows)
  • Javadoc comments are complete and follow project conventions (no new public API; the new helper is private and documented)
  • Related documentation has been updated (not needed — no documented behavior changes)
  • Code is ready for review

c020627 and others added 2 commits November 21, 2026 15:47
WorkspaceThreadJournalStore.list() split each listed path and read parts[2] before
checking the segment count. A storage backend that also lists a head.json outside
the thread layout (agents/head.json, a truncated tree, a foreign tenant, a longer
path) therefore made the whole discovery throw
ArrayIndexOutOfBoundsException: Index 2 out of bounds for length 2 instead of
skipping that entry.

Eight-segment paths whose key segments are not encoded (e.g. agents/agent/sessions/u/
session/threads/main/head.json) failed the other way: they passed the shape filter and
then threw IllegalArgumentException from base64 decoding.

Validate the path shape, including the encoded-key segments, before indexing or
decoding anything, so foreign head files are skipped and discovery stays total.

@zouyx zouyx left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jujn
jujn merged commit 05679c5 into agentscope-ai:main Nov 23, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants