Repository navigation
fix(harness): skip foreign head files during journal discovery - #4310
Merged
jujn merged 2 commits intoNov 23, 2026
Merged
Conversation
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.
This was referenced Nov 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
AgentScope-Java Version
2.1.0-SNAPSHOT (
main@2fb5400e)Description
Problem.
WorkspaceThreadJournalStore.list()discovers threads by taking every path returned byjournalStorage(...).listPaths("agents/"), splitting it on/, and then deciding whether it is a thread head:parts[2]is evaluated beforeparts.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 ahead.jsonoutside the thread layout makes the whole discovery throw:Concrete triggers for a same-directory backend: a workspace-level
head.jsonwritten 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.jsonwhose key segments are not encoded passes the shape filter and then throwsIllegalArgumentException: Invalid session keyfromdecode(...).This is a guard-ordering defect rather than an intended restriction: the
parts.length == 8check exists precisely to reject non-thread paths, andlistPathsreturns 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 aisThreadKeyPath(String[])helper. Foreignhead.jsonfiles 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
discoverySkipsForeignHeadFilesInsteadOfFailingTheListinginWorkspaceThreadJournalStoreTestfeeds a mockedlistPathsresult containing a workspace-levelhead.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.ArrayIndexOutOfBoundsException: Index 2 out of bounds for length 2(the wholelist()throws); the nine pre-existing tests in the class still 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:applythenspotless:check— passed.mvn -q -pl agentscope-harness test— the only failures are 7 pre-existing symlink tests (LocalFilesystemModeTest,AtPathExpansionMiddlewareTest) that fail identically on unmodifiedmainon this Windows host (symlink creation requires privileges). Verified by stashing the change and re-running those two classes on cleanmain.Scope is confined to one source file and one existing test file; no open PR touches either.
Checklist
mvn spotless:apply(verified viamvn spotless:check)mvn testforagentscope-harness: no regressions; the 7 symlink failures reproduce on unmodifiedmainon Windows)