Skip to content

[Bug]:Redis 模式下 glob 和 ls 操作被本地索引误导,无法正确发现 Redis 中实际存储的记忆文件。 #3197

Open

Description

@insStyle

问题出在 RemoteFilesystem.glob() / ls() 的 index fallback 逻辑
看 RemoteFilesystem.glob()(ls 同理):
public GlobResult glob(RuntimeContext runtimeContext, String pattern, String path) {
String normalizedPath = normalizePath(path);
...
// Fast path: index has entries for this prefix
if (index != null && index.hasPrefix(normalizedPath)) {
List candidates = index.listByPrefix(normalizedPath);
List results = new ArrayList<>();
for (String key : candidates) {
...
}
results.sort(Comparator.comparing(FileInfo::path));
return GlobResult.success(results); // ← 直接返回,不检查是否为空
}

// Fallback: full remote scan  ← 这行代码永远执行不到(当 hasPrefix=true 时)
List<StoreItem> items = searchAllItems(runtimeContext);
...

}
致命缺陷:
RemoteFilesystem 被配置了一个 本地 SQLite 的 WorkspaceIndex(在 HarnessAgent.build() 中自动创建)
这个 index 只扫描本地磁盘文件,完全不知道 Redis 中存储了什么
当记忆文件通过 MemoryFlushMiddleware 写入时,数据进了 Redis(upper 层),但 本地 index 没有同步更新
下次跨会话搜索时,MemorySearchTool 调用 listMemoryFilePaths() → filesystem.glob() → RemoteFilesystem.glob()
index.hasPrefix("/memory") 返回 true(因为本地磁盘模板目录 workspace/memory/ 存在)
index.listByPrefix("/memory") 返回空列表(本地磁盘模板目录下没有用户实际产生的记忆文件)
代码直接返回空结果,永远不会 fallback 到 store.search() 去查 Redis
对比 RemoteFilesystem.grep() 的实现就正确得多:
if (index != null) {
...
// Index returned matches — return them. Otherwise fall through to the authoritative store scan
if (!matches.isEmpty()) {
return GrepResult.success(matches);
}
}
// Fallback: full remote scan
grep() 在 index 返回空时会 fall through,但 glob() 和 ls() 没有这个逻辑。
为什么本地模式能工作
本地模式(不配置 RemoteFilesystemSpec)下:
文件系统直接使用 本地磁盘
WorkspaceIndex 索引的就是实际存储位置
文件写入本地磁盘后,index 能正确发现
所以跨会话搜索正常
Redis 模式下:
文件实际存储在 Redis
WorkspaceIndex 索引的是本地磁盘模板目录(一个空壳)
glob 被本地索引欺骗,以为没有文件
永远不会去 Redis 里查

Activity

  1. added
    bug
    on Sep 18, 2026
  2. oss-maintainer commented on Sep 18, 2026

    @oss-maintainer
    Collaborator

    Issue Evaluation

    Category: bug | Status: Confirmed (partial) — the glob()/ls() index fast-path flaw is real on current main; the specific Redis memory-search causal chain in the report does not match today's path normalization.

    Verified against main @ dc15ff42c by reading the code (agentscope-harness/src/main/java/io/agentscope/harness/agent/filesystem/remote/RemoteFilesystem.java, .../workspace/WorkspaceIndex.java):

    Confirmed

    1. glob() (RemoteFilesystem.java:442-462) enters the index fast path whenever index.hasPrefix(normalizedPath) is true and then return GlobResult.success(results) unconditionally — including when results is empty after pattern filtering. The authoritative fallback (searchAllItems(), :465-491) is unreachable on that path, exactly as the report describes.
    2. ls() (:153-175) has the same unconditional return LsResult.success(infos) inside the fast path.
    3. grep() is the correct contrast (:343-380): it returns index hits only when !matches.isEmpty() and otherwise falls through to the full remote scan. The comment there even names this reason — on a multi-node deployment this node's index may not know about files written by another node. glob()/ls() never got that guard.
    4. RemoteFilesystem itself does not maintain the index on its write path — uploadFiles() (:495), write() (:261) and edit() (:280) never touch it, while delete() does (index.remove, :587+). WorkspaceManager.writeUtf8WorkspaceRelative compensates with a best-effort index.upsert(...) (WorkspaceManager.java:725-727), but only for its own relative-path writes and only with the size of the uploaded content — no local file backs the entry, and present_local=1 is set anyway. So a locally-built index can drift from the authoritative store.

    Not established as described
    5. Key shapes do not line up on the default mounting: normalizePath() (:711-720) forces a leading slash (memory → /memory), while WorkspaceIndex stores workspace-relative keys under agents/ and memory/ (WorkspaceIndex.java:64-65,316-330, matched with path LIKE '<prefix>%'). So glob()'s hasPrefix("/memory") does not hit relative keys and the call falls through to the authoritative remote scan. The glob() fast path is effectively unreachable for the standard WorkspaceManager.listMemoryFilePaths() → glob("*.md", "memory") chain (WorkspaceManager.java:939-972), which also unions the filesystem result with a direct local-disk listing.
    6. ls() is the reachable variant, because it does not call normalizePath() — it only appends a trailing slash (:153-158). A caller passing a relative dir (e.g. fs.ls(rc, "memory")) does match index keys, and the returned listing is then derived purely from the local index (with entries marked present_local=1 even when written by WorkspaceManager.writeUtf8WorkspaceRelative best-effort upsert), so files that exist only in Redis and were never indexed on this node are omitted. Whether the result is empty (the reported symptom) additionally requires a concurrent index change between hasPrefix() and listByPrefix(), since both use the same predicate.

    Impact: ls() on a RemoteFilesystem with an injected index reports a local-index-derived listing and never consults the store, so in a multi-node / Redis deployment a node that did not write a memory file will not list it. glob() carries the same unconditional-return shape (its pattern filter can empty a non-empty candidate set), currently masked by the key-shape mismatch above — which is exactly the kind of thing that breaks when a route is mounted differently or the normalization is touched. Both are silent wrong-result paths rather than data corruption, and the default Redis memory search is not shown to be broken, which is why this is not rated higher.
    Severity: low-medium. Correctness gap in a shared fast path, trivial fix, no data loss.

    Suggested direction (mirror grep()): guard both returns — in glob() return only when !results.isEmpty(), in ls() only when !infos.isEmpty(), otherwise continue into the existing searchAllItems() scan. The two methods do not share a fast-path helper today, so both need the guard.

    Needs info: @insStyle please share (a) your RemoteFilesystemSpec / route mounting, (b) the exact pattern + path arguments that return empty, and (c) whether you are on a multi-node deployment where another node wrote the files. With that we can pin the branch you hit. A regression test would also be welcome: index prefix matches + filtered result empty + store contains matching items → glob()/ls() must return the store items (cf. RemoteFilesystemGrepTest.java:44-80, which already covers this shape for grep()).

    Community: reply /approve to have an automated fix proposal (spec) posted for this issue, /revise <note> to steer the analysis, or /reject to stop here.


    Automated evaluation by github-manager-bot

  3. added
    area/harness
    on Sep 18, 2026
  4. gmjneko commented on Sep 19, 2026

    @gmjneko
    Contributor

    Hi, I wasn’t able to reproduce this bug based on your description. Could you provide reproduction code so we can identify the root cause? Until more complete information is provided, I don’t think we should proceed with the PR related to this bug.

  5. oss-maintainer commented on Sep 21, 2026

    @oss-maintainer
    Collaborator

    Status: 72 h feedback window expired — no automated PR will be generated, the proposal window here is closed

    The evaluation CTA above (5726627511, posted 2026-09-18T07:22:18Z) reached its 72-hour
    feedback limit at 2026-09-21T07:22:18Z without an own-line /approve, /revise, or
    /reject reply, so per our workflow we skip PR generation and no competing PR will be
    filed from this proposal window. No action is needed from anyone.

    What the thread actually contains: one reply, from gmjneko on 2026-09-19T14:54:16Z, saying
    the reproduction did not work and asking the reporter for reproduction code. That reply is
    a request for information, not a directive: it has no line starting with a slash command,
    so nothing was actionable here.

    The fix path stays community-owned. PR #3201 by philo-x
    (fix(harness): fall through to remote store in glob and ls when index yields no matches)
    is the carrier for this issue. As of this check it is still OPEN and unmerged at head
    f87db37b23 (mergeable_state=clean, last updated 2026-09-18T14:04:31Z), so the fix ships
    through it rather than through a bot-generated duplicate.

    Closing this proposal window is not a judgement on the issue. The confirmed part of the
    report — glob() at RemoteFilesystem.java:442-462 and ls() at :153-175 returning
    index-derived results unconditionally, while grep() at :343-380 has the fall-through
    guard — is still a real gap, and #3197 remains open for the community to continue.

    If a maintainer would still prefer an independent, bot-generated PR for this fix despite
    #3201, reply on this issue and we will re-evaluate.

    Automated by github-manager-bot

  6. philo-x commented on Sep 24, 2026

    @philo-x

    I re-checked the complete path against current main, including WorkspaceManager, CompositeFilesystem, RemoteFilesystemSpec, WorkspaceIndex, and RemoteFilesystem.

    The original Redis memory-search causal chain does not appear to hold for the standard RemoteFilesystemSpec configuration: the memory/ route is remapped by CompositeFilesystem to backend path /, while WorkspaceIndex stores workspace-relative keys such as memory/foo.md. As a result, the remote glob() call does not hit the index fast path described in the issue and falls through to the store scan.

    There is still an independent RemoteFilesystem.glob() / ls() correctness gap where an empty result from an entered index fast path is returned as authoritative, unlike grep(), but I have closed #3201 because that is not a demonstrated reproduction of the Redis memory-search failure reported here.

  7. juruoO-o commented on Nov 12, 2026

    @juruoO-o
    Collaborator

    Status update: #3875 (merged) makes index prefixes match literally instead of as LIKE patterns — related but a different root cause. The Redis fast path returning no rows and never falling back (this issue and #3201) remains open.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/harnessbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions