Repository navigation
fix(harness): match index prefixes literally, not as LIKE patterns - #3875
Conversation
listByPrefix/hasPrefix interpolated the caller's prefix straight into a SQL LIKE pattern. Agent, session and file names arrive verbatim, so '_' and '%' inside them acted as wildcards: a lookup under agents/bot_1/sessions/s_1/ also returned agents/bot21/sessions/s21/. hasPrefix reporting a false positive is the worse half because it decides whether RemoteFilesystem may use the index fast path, so the authoritative store scan was skipped; ls does not re-check the rows the way glob does, so a foreign file could be listed as a child of the queried directory. Escape the metacharacters and declare ESCAPE on both statements. hasPrefix(null) now returns false instead of building the pattern "null%". Tests: new WorkspaceIndexPrefixMatchTest with four cases, three of which fail when the production change is reverted. Full harness module: 1570 tests, 0 failures, 34 skipped.
|
@jujn gentle ping on this one. CI is green on all four checks ( For context, what it fixes: the prefix was interpolated straight into a Happy to rework the approach if escaping does not fit the surrounding code, or to split / close it if you would rather handle it another way. |
|
Thanks for the review and the merge, and for picking it up after my ping. |
…3875) Backport the verified fix to the 2.0.x implementation and retain its existing public contracts where the upstream kernel differs. (cherry picked from commit 4399f75) Backport-review-patch: 340acd49331636940faf7d898805165e70045f21 Constraint: No AgentScope Service or SDK migration Confidence: high Not-tested: Whole-repository verification pending after lane integration
Problem
WorkspaceIndexanswers prefix lookups by interpolating the prefix straight into a SQLLIKEpattern:
_and%are LIKE metacharacters, and agent / session / file names reach this class verbatimfrom configuration and API callers, so the pattern is not a literal prefix match:
hasPrefixhas the same false positives, which is the more damaging half: it decides whetherRemoteFilesystemmay take the index fast path at all, so a look-alike directory reports "I haveentries" and the authoritative store scan is skipped.
lsthen trusts the rows it gets back — it does not re-check them the wayglobdoes withmatchesPathPrefix— and returns each matched path as an entry of the directory being listed:So listing
agents/bot_1/sessions/s_1/can return a file that belongs to another agent's sessiondirectory, and the relative names it derives for sub-directories are shifted for the same reason.
%behaves identically: a URL-derived session id such assess%2F1also matchessess2F1.Change
%,_and the escape character itself in the prefix, and declareESCAPE '\'on bothprefix statements. The prefix is now matched literally, as its callers assume.
hasPrefix(null)returns false instead of building the pattern"null%".No behaviour change for ordinary prefixes; the lookups are still a single indexed query.
Verification
WorkspaceIndexPrefixMatchTest(4 cases): underscore in both the agent and the sessionsegment,
hasPrefixfalse positive,%literal, plus an ordinary-prefix regression case.WorkspaceIndexmakes 3 of the 4 fail, e.g.expected: <[agents/bot_1/sessions/s_1/report.md]> but was: <[agents/bot_1/sessions/s_1/report.md, agents/bot21/sessions/s21/report.md]>,while the ordinary-prefix case keeps passing — the tests pin the defect, not the implementation.
mvn -pl agentscope-harness test: 1570 tests, 0 failures, 0 errors, 34 skipped, BUILDSUCCESS (1566 on the same commit without this change).
mvn spotless:checkpasses.Related but different root cause: #3197 / #3201 cover the fast path returning no rows and never
falling back to the store. This change covers the case where the fast path returns the wrong
rows.