Skip to content

feat(harness): opt-in sharedLocalWorkspace on the filesystem specs (host-app workspace-root asymmetry) - #3247

Merged
jujn merged 3 commits into
agentscope-ai:mainfrom
aiyili:fix/shared-local-workspace
Sep 24, 2026
Merged

jujn merged 3 commits into
agentscope-ai:mainfrom
aiyili:fix/shared-local-workspace

Conversation

@aiyili

@aiyili aiyili commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #3245

Problem

When the host application writes to the workspace root with plain java.nio (e.g. uploads/{sessionId}/result.md), the agent tools cannot read the files back: the default backend is built UNRESTRICTED with a per-user namespace factory, so relative paths resolve to {workspace}/{userId}/... while the host writes {workspace}/... — a silent read/write asymmetry that makes the model burn dozens of turns trying path variants. Both remote and local modes are affected, Windows and Linux alike. UNRESTRICTED additionally lets list_files walk up to the drive root.

Fix (suggested option 1, extended to the local mode per point 6 of the report)

  • RemoteFilesystemSpec.sharedLocalWorkspace(true) — opt-in, default false preserves current behavior. The default backend becomes new LocalFilesystem(workspace, true /sandboxed/, 10, null), the exact construction already used for the workspace-template layer: shared workspace root, no namespace prefix, traversal blocked (absolute paths re-rooted under the workspace, .. rejected with SecurityException). Shared routes (memory/, skills/, ...) keep their per-user store namespaces.
  • LocalFilesystemSpec.sharedLocalWorkspace(true) — the report shows local mode has the identical asymmetry; pass a null namespace factory to the upper/project layers when enabled.
  • No changes to HarnessAgentBuilderSupport: the switch lives inside the specs.

Tests (+5)

  • RemoteFilesystemSpecTest.sharedLocalWorkspaceSeesHostWrittenFiles — host-written file readable, uploads/ listable, agent writes land at the workspace root with no {userId}/ directory created
  • RemoteFilesystemSpecTest.sharedLocalWorkspaceBlocksTraversal — ../ rejected with SecurityException
  • RemoteFilesystemSpecTest.sharedRoutesKeepStoreNamespaceWithSharedLocalWorkspace — shared routes stay per-user isolated
  • LocalFilesystemSpecSharedWorkspaceTest.sharedLocalWorkspaceResolvesWorkspaceRootWithoutUserPrefix — local mode round-trip
  • LocalFilesystemSpecSharedWorkspaceTest.defaultKeepsPerUserPrefix — regression guard for the default namespaced behavior

Module suite: 1048/1048 green (BUILD SUCCESS); Spotless clean.

…录读不到的不对称

宿主应用用原生 java.nio 往工作区根目录写文件(如 uploads/{sessionId}/
result.md)时,agent 的 read_file/list_files/grep_files 读不到:默认
backend 是 UNRESTRICTED + 用户命名空间工厂,相对路径被解析到
{workspace}/{userId}/... 而应用写的是 {workspace}/...——写入侧与
读取侧对物理位置的认知不一致,模型会在路径变体上空转数十轮。
UNRESTRICTED 还允许 list_files 一路向上遍历到盘根。

按 issue 建议方案 1(扩展到本地模式):

- RemoteFilesystemSpec.sharedLocalWorkspace(true)(opt-in,默认 false
  保持现状):default backend 改为 new LocalFilesystem(workspace,
  true/*sandboxed*/, 10, null)——与 workspace 模板层完全相同的构造。
  共享根、无命名空间前缀、阻止遍历;共享路由(memory/、skills/ 等)
  的 per-user store 命名空间不变
- LocalFilesystemSpec.sharedLocalWorkspace(true):upper 与 project 层
  传 null 命名空间工厂,本地模式的相同不对称一并修复
- 测试:应用侧写入的文件 read/ls 可见、agent 写落在共享根且不产生
  {userId}/ 目录、../ 遍历抛 SecurityException、共享路由保持
  per-user 隔离、默认关闭时命名空间行为不变(回归保护)

Fixes agentscope-ai#3245
@codecov

codecov Bot commented Sep 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@oss-maintainer oss-maintainer 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.

Summary

Adds an opt-in sharedLocalWorkspace flag to LocalFilesystemSpec / RemoteFilesystemSpec so the default backend resolves against the shared workspace root (sandboxed, no per-user prefix), fixing the host-app write / agent-read asymmetry from #3245. Clean, well-motivated change: null-namespace plumbing is safe in ProjectAwareOverlay and LocalFilesystem, shared mode correctly upgrades the local backend to SANDBOXED (traversal blocked), shared prefix routes keep their store namespaces, and test coverage is good (host-file visibility, default prefix preserved, traversal blocked, shared-route isolation).

Two non-blocking items: a field placement that orphans toFilesystem's existing javadoc block, and a missing test for the projectWritable + sharedLocalWorkspace overlay branch. Not approved yet pending those — both are quick fixes.


Automated review by github-manager-bot

private String anonymousUserId = "_default";
private IsolationScope isolationScope = IsolationScope.USER;
private WorkspaceIndex workspaceIndex = null;
private boolean sharedLocalWorkspace = false;

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.

[Warning] The sharedLocalWorkspace field added here ends up directly above the pre-existing javadoc block of toFilesystem(...), which starts with an empty description line (/** + newline + * + <ul>). After this change javadoc tools will associate that block with the field, not the method, and the method loses its route-documentation. Please add a short description line to that javadoc (or move the field above the block) so the <ul> documentation stays attached to toFilesystem.

projectFs,
workspace,
localNamespaceFactory);
effectiveNamespaceFactory);

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.

[Warning] The new tests cover the default (OverlayFilesystem.of) path and the remote shared mode + traversal, but there is no test for projectWritable=true combined with sharedLocalWorkspace=true — i.e. the ProjectAwareOverlay branch where effectiveNamespaceFactory (null) is now threaded into both projectFs and the overlay constructor. Since stripNamespacePrefix treats a null factory as a no-op this is likely correct, but a small regression test pinning project-routed writes under shared mode would make the opt-in fully covered.

// sharedLocalWorkspace: drop the per-user prefix so host-app writes at the workspace
// root and agent reads/writes agree on physical locations (#3245).
NamespaceFactory effectiveNamespaceFactory =
sharedLocalWorkspace ? null : localNamespaceFactory;

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.

[Info] Worth stating explicitly in this method's javadoc (and the remote counterpart) that shared mode disables per-user namespace isolation at the workspace root: two users/sessions configured on the same workspace directory will read and overwrite each other's files under workspaceRoot (agent writes land in the shared root instead of {workspace}/{userId}/). The option is documented as opt-in, but a one-line "not safe for multi-tenant workspaces" warning would help host-app integrators choose correctly.

…le+shared 组合测试、多租户警示

- RemoteFilesystemSpec.toFilesystem 的 javadoc 原以空描述行开头(/** +
  空 + <ul>),紧邻新增的 sharedLocalWorkspace 方法后易被 javadoc 工具
  错误关联;补上描述行,路由文档明确归属方法
- 两处 sharedLocalWorkspace 文档增加显式警示:共享模式关闭工作区根的
  per-user 命名空间隔离,同一工作区目录下的多用户/会话会互相可见并
  覆盖文件——面向单租户宿主集成,不适合多租户工作区
- 新增 projectWritableWithSharedLocalWorkspaceRoutesWritesWithoutUserPrefix:
  钉住 ProjectAwareOverlay 分支(effectiveNamespaceFactory=null 传入
  projectFs 与 overlay 构造器),非工作区写路由到 project 根且无
  {userId}/ 前缀,MEMORY.md 仍落在共享工作区根
@aiyili

aiyili commented Sep 22, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review — all three items addressed in 169eed8:

  1. Javadoc anchoring: added a description line ("Builds the composite filesystem described by this spec.") to toFilesystem's javadoc so the route documentation stays attached to the method.
  2. projectWritable + sharedLocalWorkspace test: added projectWritableWithSharedLocalWorkspaceRoutesWritesWithoutUserPrefix — pins the ProjectAwareOverlay branch (effective null namespace factory threaded into projectFs and the overlay constructor): a non-workspace write lands at {project}/docs/report.md with no {userId}/ directory, and a workspace-metadata write (MEMORY.md) still lands at the shared workspace root.
  3. Multi-tenant warning: both sharedLocalWorkspace docs now carry an explicit "Not safe for multi-tenant workspaces" note — shared mode disables per-user namespace isolation at the workspace root, intended for single-tenant host-app integrations.

Spec tests 9/9 green.

@oss-maintainer oss-maintainer 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.

Summary

Re-review after the follow-up commit 169eed830b: all three points from my previous review are addressed — the toFilesystem javadoc no longer dangles on the new sharedLocalWorkspace field (description line restored, field back in the field block), both specs now carry an explicit "not safe for multi-tenant workspaces" warning, and the projectWritable=true + sharedLocalWorkspace=true (ProjectAwareOverlay) branch is pinned by projectWritableWithSharedLocalWorkspaceRoutesWritesWithoutUserPrefix.

No new issues found: the opt-in defaults to false on both specs so existing namespaced behaviour is untouched, shared prefix routes keep their per-user store namespaces, traversal is rejected via the sandboxed LocalFilesystem(workspace, true, 10, null) construction, and the test imports (Map, assertThrows, LsResult/ReadResult) are all properly anchored. License / Module Sync / ubuntu + windows builds / patch coverage are green and license/cla has passed.

LGTM, approved.


Automated review by github-manager-bot

@wxh2010zd

Copy link
Copy Markdown

@jujn 希望能尽快审查合并

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.

[Bug]:read_file/list_files 无法读取应用服务写入工作区根目录的文件:default backend 命名空间前缀导致读写不对称

4 participants