Repository navigation
Description
问题概述
当宿主应用直接往工作区根目录写文件时(例如通过原生 java.nio 写入 {workspace}/uploads/{sessionId}/result.md),agent 的文件系统工具(read_file、list_files、grep_files)读不到这些文件:相对路径被解析到了 per-user 命名空间目录({workspace}/{userId}/uploads/...),而不是共享的工作区根目录。模型会因此浪费几十轮尝试各种路径变体,最终任务失败。远程模式(RemoteFilesystemSpec)和本地模式(LocalFilesystemSpec)都会中招,Windows 和 Linux 表现一致。
环境
-
io.agentscope:agentscope-harness:2.0.3-SNAPSHOT -
本地模式,Windows 11(已复现);远程模式 + Redis 存储,Linux(同一代码路径)
-
默认隔离范围(本地模式未覆盖时默认为 USER)
观测到的现象(来自真实运行日志)
工作区根:C:\opt\.agentscope\workspace-business
应用侧工具将识别结果写入 {workspace}\uploads\ff17dbe6\扫描0090.md(724 字节,磁盘上确认存在,且 glob_files 能看到):
-
read_file("uploads/ff17dbe6/扫描0090.md")→ not found -
read_file("C:\opt\.agentscope\workspace-business\uploads\ff17dbe6\扫描0090.md")→ not found -
list_files("uploads")→ "Path does not exist" -
glob_files(path="C:\opt")→ 返回uploads/ff17dbe6/扫描0090.md
随后模型循环尝试了 10 多种路径变体(相对路径、绝对路径、正斜杠、./、../)——全部失败。
根因分析
-
RemoteFilesystemSpec.toFilesystem(...)构建 default backend(即所有不匹配共享路由的路径——包括uploads/——都由它服务)时:new LocalFilesystem(workspace, false /*sandboxed*/, 10, localNamespaceFactory)
即 UNRESTRICTED 模式 + 用户命名空间工厂(
IsolationScope.USER→[userId])。 -
LocalFilesystem.applyNamespacePrefix会给相对路径加命名空间前缀(uploads/x.md→{userId}/uploads/x.md);绝对路径则原样放行。 -
宿主应用用原生
java.nio写入{workspace}/uploads/...(无命名空间),而工具把同一个逻辑路径解析为{workspace}/{userId}/uploads/...→ 文件不存在。写入侧和读取侧对物理位置的认知不一致。 -
WorkspacePathNormalizer.normalize会把绝对路径中的工作区前缀剥掉,使其变成相对路径,随后同样被加上命名空间前缀——所以绝对路径变体也失败。 -
工作区之外的绝对路径(例如
C:\opt)既不经过 normalizer 剥离、也不加命名空间前缀——这就是glob_files(path="C:\opt")能看到文件而read_file看不到的原因。另外注意:glob 的返回结果是相对于固定虚拟根(工作区)的,而不是相对于path参数的,因此 glob 与 read/list 的根基准彼此也不一致。 -
本地模式存在同样的不对称:
LocalFilesystemSpec.toFilesystem把命名空间工厂传给了 upper 文件系统层,因此默认本地配置下工具看到的是{workspace}/{userId}/...,而应用写的是{workspace}/...(工作区内出现default-user/目录可佐证)。
综合影响:任何"应用写入工作区根 → agent 读取"形态的集成(用户文件上传是最典型的场景)都会无声失效,且失败模式是模型在路径变体上空转、大量消耗 token。
安全附带问题
由于 default backend 是 UNRESTESTRICTED 模式,本地配置下 list_files(".") 可以一路向上遍历到盘根(实测会列出 C:\)。如果把共享目录的 backend 换成 SANDBOXED 模式,可以同时解决可见性不对称和这个路径遍历问题。
建议修复方案(任选其一)
-
在
RemoteFilesystemSpec上增加一个可选开关,例如sharedLocalWorkspace(true),将 default backend 构建为new LocalFilesystem(workspace, true /*sandboxed*/, 10, null)——共享工作区根、不加命名空间前缀、工作区外的绝对路径抛SecurityException。共享路由(memory/、skills/、agents/{id}/sessions|tasks/等)的 per-user 命名空间语义保持不变。 -
或者在
LocalFilesystem.applyNamespacePrefix中支持命名空间排除前缀列表(例如uploads/),让指定子树解析到共享工作区根,其余路径保持命名空间隔离。
Activity
aiyili commentedon Sep 22, 2026
Hi, I'd like to work on this issue, following suggested fix 1 (extended to the local mode, per point 6):
RemoteFilesystemSpec.sharedLocalWorkspace(true)(opt-in, defaultfalsepreserves current behavior): the default backend becomesnew LocalFilesystem(workspace, true /*sandboxed*/, 10, null)— the same construction already used for the workspace-template layer. Host-app files written to the workspace root with plainjava.nio(e.g.uploads/) become visible to read_file/list_files/grep_files, and absolute paths outside the workspace are rejected instead of traversing up to the drive root (the security side-note). Shared routes (memory/, skills/, ...) keep their per-user store namespaces.LocalFilesystemSpec(the report shows local mode has the identical read/write asymmetry): pass a null namespace factory to the upper/project layers when enabled.PR coming shortly.
oss-maintainer commentedon Sep 22, 2026
Issue Evaluation
Category:
bug| Module:agentscope-harness| Status: Confirmed (verified againstmain@ed77530a4)Root cause — each claim in the report was checked against the code:
RemoteFilesystemSpec.toFilesystembuilds the default backend asnew LocalFilesystem(workspace, false, 10, localNamespaceFactory)(.../filesystem/spec/RemoteFilesystemSpec.java:212), wherefalseselects the UNRESTRICTED mode (LocalFilesystem.java:149-155). Confirmed.LocalFilesystem.applyNamespacePrefix(LocalFilesystem.java:689-707) prefixes relative paths only —isAbsolutePathString(:714-727) passes absolute paths through, andWorkspacePathNormalizer.normalize(WorkspacePathNormalizer.java:119-144) strips the workspace prefix before resolution, which turns an absolute path back into a relative one that then receives the prefix. Confirmed — this is exactly why the absolute-path variants in the log also fail.IsolationScope.USERmapping (IsolationScope.java:102-126,USER -> [userId]),read_file("uploads/x.md")resolves to{workspace}/{userId}/uploads/x.mdwhile a hostjava.niowrite lands at{workspace}/uploads/x.md. There is no code path under default settings where a host write to the workspace root is readable by the tools (the two coincide only when the namespace is empty, i.e.AGENT/GLOBALor a blank user/session key). Confirmed.glob_filesvsread_file/list_filesroot mismatch:LocalFilesystem.globresolves againstcwd/resolvePath(".")(LocalFilesystem.java:421-425) whileCompositeFilesystem.lsmaps"."todefaultBackend.ls("/")(CompositeFilesystem.java:199-201), which UNRESTRICTED mode passes through unchanged (LocalFilesystem.java:681-687). Confirmed — and it also confirms the security side-effect:list_files(".")can enumerate outside the workspace (drive root), since no containment check exists on that path.LocalFilesystemSpec.toFilesystempasses the same namespace factory toLocalFilesystemWithShell(LocalFilesystemSpec.java:288-320), so the asymmetry is identical there. Confirmed.Impact: any "host application writes into the workspace root → agent reads it" integration (file uploads being the canonical case) fails silently, and the failure mode is expensive: the model burns dozens of turns on path variants. The unrestricted default listing path additionally weakens workspace containment.
Severity: high.
Fix direction — needs a design decision before any PR. Two variants are on the table:
sharedLocalWorkspace(true)on the specs so the default backend becomesnew LocalFilesystem(workspace, true, 10, null);LocalFilesystem.applyNamespacePrefix(e.g.uploads/), so only selected subtrees resolve to the shared root.The second option has the smaller change surface and keeps per-user isolation for every non-excluded path; the first makes the shared-root behaviour all-or-nothing. Whichever is chosen, these must not regress: shared routes (
memory/,skills/,agents/<id>/sessions|tasks/) keep their per-user namespaces, and per-user isolation for ordinary workspace files stays the default.Note for the reporter: PR #3247 (opened 2026-09-22T03:56Z,
Fixes #3245) already implements the first option. This comment is not an endorsement of that PR; the module-maintainer API choice above should be settled first, and any fix should also cover the traversal containment in point 4, which is out of scope of #3247 as written.Automated evaluation by github-manager-bot
aiyili commentedon Sep 22, 2026
Thanks for the thorough evaluation. On the two open points:
PR #3247 status (option 1) — opt-in
sharedLocalWorkspace(true)on both specs, default behavior unchanged (namespaced, UNRESTRICTED), shared routes keep their per-user store namespaces, traversal blocked when enabled (sandboxed backend). The review items on the PR have been addressed. If the module maintainer prefers option 2 (namespace-exclusion prefix list inapplyNamespacePrefix), I'm happy to rework the PR in that direction — the tests would transfer mostly as-is.Point 4 containment gap (option-independent) — agreed this needs fixing regardless of the API choice. Concrete mechanism, verified against the code:
CompositeFilesystem.lsroutes"/"/"."todefaultBackend.ls(rc, "/")(CompositeFilesystem.java:199-203), and the UNRESTRICTED resolver passes absolute paths through unchanged (LocalFilesystem.java:681-687), so the listing enumerates from the OS root. A minimal fix that works under both options: anchor the composite's root listing to the backend's own root — pass a blank path (whichresolvePathalready resolves to the backend cwd,LocalFilesystem.java:598-600) instead of"/"— or equivalently teachLocalFilesystemthat"/"means the backend root rather than the OS root in every mode. The first is a one-line change inCompositeFilesystemplus a regression test; the second is broader but makes/-semantics consistent everywhere.Happy to push the containment fix into #3247 or as a separate PR, whichever the maintainer prefers — awaiting the API decision.
oss-maintainer commentedon Sep 22, 2026
Issue Evaluation — follow-up (design question resolved; no action needed from the bot)
Category:
bug| Module:agentscope-harness| Status: Confirmed earlier; the open API decision is now settled — leaving implementation to PR #3247 (re-checked againstmain@ed77530a4)sharedLocalWorkspace(true)) has been reviewed and approved by a maintainer (approval recorded2026-09-22T05:39Z,mergeable, non-draft), and the reporter is asking for a merge. The option-2 alternative raised above is therefore superseded — the bot will not generate a competing patch for this issue and will not re-open the design question.main. Verified again at HEAD:CompositeFilesystem.lsstill routes the root listing to the backend with an absolute"/"—if ("/".equals(path) || ".".equals(path)) { ... defaultBackend.ls(runtimeContext, "/"); ... }(agentscope-harness/src/main/java/io/agentscope/harness/agent/filesystem/CompositeFilesystem.java:199-201), and the UNRESTRICTED resolver passes absolute paths through unchanged (LocalFilesystem.java:681-687). @aiyili's proposed minimal fix (pass a blank path soresolvePathanchors at the backend root,LocalFilesystem.java:598-600) is consistent with the code as it stands; note the same branch also feeds.listings for shared routes, so whichever way it lands it needs a regression test that a.//listing cannot escape the workspace in both spec modes, and that per-user namespace isolation for ordinary paths is unchanged.LocalFilesystemSpec.java(+37/-3),RemoteFilesystemSpec.java(+36/-1), plusLocalFilesystemSpecSharedWorkspaceTest.java(+96) andRemoteFilesystemSpecTest.java(+64). Only the point-4 containment fix above remains outside its scope.Action taken this tick: none on GitHub beyond this status update — no new label, no bot PR, no comment that would add noise to an approved-and-awaiting-merge thread. If #3247 merges, this issue can be closed by the maintainers with the containment follow-up tracked separately.
Automated evaluation by github-manager-bot
gmjneko commentedon Sep 22, 2026
refer #1775
oss-maintainer commentedon Sep 22, 2026
Issue Evaluation — follow-up: the "#1775" reference is not a duplicate
Category:
bug| Module:agentscope-harness| Status: unchanged (Confirmed; fix tracked in #3247) — evaluated the cross-reference raised above againstmain@ed77530a4Checked #1775 and it is a separate defect, not an earlier report of this one — see the full analysis in #1775. Short version: #1775 lives in the local project overlay, where
LocalFilesystemSpecbuilds the writable project layer with the namespace factory (.../filesystem/spec/LocalFilesystemSpec.java:309-311) but the read-fallback layer without it (:307,new LocalFilesystem(effectiveProject, true, 10, null)), so a framework write and the matching read resolve to different physical paths. This issue is about the remote default backend namespacing tool reads while a hostjava.niowrite lands un-namespaced (.../filesystem/spec/RemoteFilesystemSpec.java:212).Consequence for this thread: PR #3247 will not close #1775, and #1775 should stay open. No change to the status of this issue, and no bot action here beyond this note.
Automated evaluation by github-manager-bot
feat(harness): opt-in sharedLocalWorkspace on the filesystem specs (h…