Skip to content

fix(harness): enforce namespace boundary for absolute paths in ROOTED local filesystem - #3292

Merged
juruoO-o merged 11 commits into
agentscope-ai:mainfrom
chang6666:fix/3261-local-fs-namespace-boundary
Nov 11, 2026
Merged

juruoO-o merged 11 commits into
agentscope-ai:mainfrom
chang6666:fix/3261-local-fs-namespace-boundary

Conversation

@chang6666

Copy link
Copy Markdown
Contributor

Summary

With LocalFilesystemSpec and a per-session/per-user IsolationScope, absolute paths bypass the session namespace entirely: the namespace prefix only scopes relative keys (applyNamespacePrefix passes absolute keys through), and the ROOTED acceptance check treats the workspace root as an implicit allowed root. One session could therefore enumerate and read another session's directory under the shared workspace root (MEMORY.md, memory/, agents/, generated artifacts) with a plain absolute path — making IsolationScope.SESSION a path prefix rather than an access boundary.

Fixes #3261. It implements the "reject absolute keys that resolve inside another namespace" direction from the issue evaluation; happy to rework if maintainers prefer the effective-root design.

Changes

  • LocalFilesystem gains an opt-in namespaceBoundary(boolean). When enabled, in ROOTED mode an absolute path that resolves under cwd must resolve under cwd/<namespace> to be accepted; anything else is rejected with a SecurityException that names the namespace root. The leading-slash virtual form (/foo → <workspace>/foo) is covered too, since it resolves under cwd the same way.
    • Paths under PathPolicy roots that lie outside cwd (the read-only project layer, additionalRoots) are unaffected.
    • With no namespace active for the call (AGENT/GLOBAL scope, or missing user/session identifiers) the check is a no-op.
    • The boundary is off by default for direct LocalFilesystem users; LocalFilesystemSpec enables it for the workspace layer when mode == ROOTED (the spec default). SANDBOXED already re-roots absolute paths under the workspace; UNRESTRICTED is documented to pass absolute paths through.
  • Relative keys are untouched: they are prefixed into the own namespace, and .. segments are already rejected by AbstractFilesystem.validatePath.

Behavior change to be aware of

With a namespace active, absolute access to shared directories sitting at the workspace root (e.g. skills/, knowledge/) is now rejected as well — from the filesystem alone those are indistinguishable from a sibling session's directory. Shared content remains reachable through workspace-relative paths, which the overlay resolves against the read-only project layer; the injected workspace prompt already steers the model to relative paths. If maintainers would rather keep a shared-areas carve-out (e.g. a configurable allowlist of shared dir names), I'm glad to iterate.

As noted in the issue evaluation, execute() still runs host shell commands and is out of scope here — the local + shell mode is documented for trusted single-process hosts.

Testing

  • LocalFilesystemModeTest: new cases for sibling-namespace rejection, own-namespace allowance, workspace-root absolute rejection, leading-slash virtual form rejection, default-off back-compat, and the no-active-namespace no-op. The previous rooted_leadingSlashWithNamespace assertion encoded the vulnerable behavior and now asserts the refusal.
  • Full agentscope-harness suite: Tests run: 1062, Failures: 0, Errors: 0, Skipped: 14.
  • mvn spotless:check passes.

… local filesystem

With LocalFilesystemSpec and a per-session/per-user IsolationScope, the
namespace prefix only scopes RELATIVE keys: applyNamespacePrefix passes
absolute keys through unchanged, and the ROOTED acceptance check treats
the workspace root itself as an implicit allowed root. A session could
therefore read or write another session's directory under the shared
workspace root (MEMORY.md, memory/, agents/, generated artifacts) with
a plain absolute path, which turns IsolationScope.SESSION into a path
prefix rather than an access boundary (agentscope-ai#3261).

- LocalFilesystem gains an opt-in namespaceBoundary: in ROOTED mode an
  absolute path resolving under cwd must resolve under cwd/<namespace>;
  the leading-slash virtual form is covered as well. Paths under
  PathPolicy roots outside cwd (read-only project layer, additional
  roots) are unaffected, and with no namespace active the check is a
  no-op.
- LocalFilesystemSpec enables the boundary for the workspace layer in
  ROOTED mode (the spec default). SANDBOXED already re-roots absolute
  paths under the workspace; UNRESTRICTED is documented to pass
  absolute paths through.

Shared workspace-root content stays reachable through workspace-relative
paths, which the overlay read-falls-back to the project layer.
@codecov

codecov Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.36364% with 9 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...arness/agent/filesystem/local/LocalFilesystem.java 84.74% 5 Missing and 4 partials ⚠️

📢 Thoughts on this report? Let us know!

…e branch

- '/' alone reaches the same resolution as any other leading-slash virtual
  path via Path.resolve(""), so the empty-stripped special case (dead on
  real systems where the root always exists) is removed.
- cover the two no-op short-circuits of requireOwnNamespace: boundary
  enabled with no namespace factory, and a factory resolving to null.

@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

Solid, well-scoped fix for #3261: with namespaceBoundary enabled, absolute and leading-slash virtual paths under cwd must resolve inside the caller's own namespace, the opt-in default keeps direct LocalFilesystem users unaffected, and LocalFilesystemSpec turns it on for the ROOTED workspace layer. One security gap in the boundary check itself needs attention before this can land, so I'm leaving this as COMMENT rather than an approval.

Findings

  • [Critical] LocalFilesystem.java:732 — the boundary is enforced with Path.normalize() / Path.startsWith(), neither of which resolves symbolic links, so a symlink created inside one session's namespace can still reach a sibling namespace or a shared root directory.
  • [Warning] LocalFilesystem.java:720 / :733 — the javadoc assumes .. rejection makes relative keys safe, and startsWith() is case-sensitive, so a case-mismatched path escapes the boundary on Windows/APFS.
  • [Warning] LocalFilesystemModeTest.java:262 — the new cases cover direct absolute traversal but not symlink or case-insensitive escape paths.

Suggested direction

Resolve the candidate against the filesystem before comparing (toRealPath() on the existing target, falling back to the nearest existing ancestor for not-yet-created files) and compare canonical paths case-insensitively, or add a canonical-path helper next to the existing validatePath check. If symlink traversal should stay out of scope for this mode, please record that explicitly in the namespaceBoundary javadoc and the class-level docs so the security property is not over-claimed.

Good catch on splitting the shared-directory behaviour out into an explicit note — the carve-out question is worth the maintainers' input, and the new no-op behaviour when no namespace is active reads correctly.


Automated review by github-manager-bot

if (ns == null || ns.isEmpty()) {
return;
}
Path nsRoot = cwd.resolve(String.join("/", ns)).normalize();

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.

The namespace boundary is checked with Path.normalize() and Path.startsWith(), which do not resolve symbolic links. A symlink planted inside the caller's namespace directory (e.g. user-1/link -> ../user-2) lets an absolute path pass the prefix check while the filesystem operation follows the link into another namespace. Consider using Path.toRealPath() for the boundary check, or document that symlink traversal is out of scope.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 07ce9f5: the candidate is now resolved to its physical location before the comparison — Path.toRealPath() when it resolves, otherwise the nearest existing ancestor resolved to its real path with the remaining components appended lexically (components that do not exist yet cannot hide a link). Broken links are followed lexically through their recorded target (Files.readSymbolicLink), so the eventual target location is what gets compared. The namespace root is anchored at the physical cwd (cwd.toRealPath()), which also keeps both sides of the comparison consistent when cwd itself contains links (e.g. /tmp vs /private/tmp on macOS).

/**
* Rejects absolute paths that resolve under {@link #cwd} but outside the caller's own
* namespace directory when {@link #namespaceBoundary} is enabled and a namespace is active.
* Relative keys never reach this check with a foreign namespace: they are prefixed into the

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.

The javadoc asserts that relative keys never reach this check with a foreign namespace because .. is rejected. That is true for .. segments, but a relative key such as link-to-sibling/file is prefixed into the caller's namespace and can then escape via a symlink. This bypass is not covered by the new boundary logic and should at least be documented as a remaining limitation.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 07ce9f5 rather than only documented: relative keys now go through the same physical check after namespace prefixing, so link-to-sibling/file is rejected when the link leads out of the own namespace. The javadoc claim that relative keys never reach the check is removed.

return;
}
Path nsRoot = cwd.resolve(String.join("/", ns)).normalize();
if (resolved.startsWith(nsRoot)) {

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.

Path.startsWith() is case-sensitive. On case-insensitive file systems (Windows, macOS APFS), a casing mismatch between cwd/nsRoot and resolved can cause false positives, rejecting legitimate paths inside the caller's namespace. Normalize or canonicalize casing at filesystem construction, or use a real-path check that follows the host FS semantics.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 07ce9f5 as a side effect of the physical resolution: toRealPath() returns the on-disk casing, so both sides of the comparison are canonical on case-insensitive hosts. (While re-verifying this finding we concluded it is a false-reject rather than an escape — a casing mismatch fails closed at the earlier root checks — but it is fixed regardless.)

return;
}
Path nsRoot = cwd.resolve(String.join("/", ns)).normalize();
if (resolved.startsWith(nsRoot)) {

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.

The boundary check is performed on a Path object before the actual file operation, so a symlink or directory entry can change between the startsWith check and the subsequent Files.read*, Files.write*, or directory traversal. This is a general TOCTOU race inherent to path-prefix checks; resolving to a real path before the operation would narrow the window but cannot eliminate it entirely.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Acknowledged and documented as a remaining limitation in the namespaceBoundary(boolean) javadoc: the check runs before the file operation, so a component swapped in between (TOCTOU) is not covered. Closing the window entirely would need fd-level operations (openat-style), which is out of scope for a Path-based API; physical resolution narrows it.

if (ns == null || ns.isEmpty()) {
return;
}
Path nsRoot = cwd.resolve(String.join("/", ns)).normalize();

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.

nsRoot is recomputed on every call (cwd.resolve(String.join("/", ns)).normalize()). Both cwd and the namespace are effectively immutable for a given filesystem instance, so the root could be cached to avoid the repeated string join and path normalization on the hot path.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kept per-call on purpose: the namespace is derived per call from the RuntimeContext, so one filesystem instance can serve multiple sessions and a per-instance cache would be wrong. A per-namespace map would add state for a negligible gain — one string join plus one toRealPath next to the operation's own filesystem I/O.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up from the Windows CI run: anchoring the namespace root at cwd.toRealPath() with lexical namespace components turned out to break one case — when the workspace root does not exist yet (e.g. the knowledge-directory glob runs before first use) AND cwd is reached through an alias (Windows 8.3 short names like RUNNER~1, macOS /var vs /private/var), the fallback lexical form and the candidate's real-pathed ancestor disagree and legit own-namespace paths get rejected. Fixed in 391a14c: the namespace root now goes through the same physicalPath() as the candidate, so both sides agree by construction. The trade-off: a link swapped in for a namespace directory now re-anchors the boundary to its target instead of failing closed — documented in the javadoc.

}

@Test
void rooted_namespaceBlocksAbsolutePathIntoSiblingNamespace(

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.

The new tests cover direct absolute-path traversal between namespaces but do not exercise symlink-based escapes. Add tests that create a symbolic link inside user-1 pointing at user-2 and assert that both absolute and workspace-relative access through the link is blocked (or at least that the behavior is explicitly defined).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in 07ce9f5: a link into a sibling namespace is now asserted rejected via the absolute, namespace-prefixed relative, and leading-slash routes; a link pointing outside the workspace is rejected; a broken link into a sibling namespace is rejected via its recorded target; and a link that stays inside the own namespace is asserted still allowed (no false positive). All of these skip via Assumptions on platforms that cannot create links (e.g. Windows CI without symlink privilege).

The namespace boundary compared lexically normalized paths, so a symbolic
link planted inside the caller's namespace could pass the prefix check
while the file operation followed the link into a sibling namespace or a
shared root. Case-sensitive prefix matching also rejected legitimate
paths on case-insensitive hosts (Windows, APFS).

requireOwnNamespace now resolves the candidate to its on-disk location
(toRealPath, falling back to the nearest existing ancestor plus the
lexical remainder for not-yet-created paths, and following broken links
through their recorded target) before comparing against the namespace
root anchored at the physical cwd. The check now also covers
namespace-prefixed relative keys, which could escape the same way, and
normalizes casing on case-insensitive filesystems as a side effect.

Remaining limitations are documented on namespaceBoundary(boolean):
the check-then-operate TOCTOU window inherent to path-prefix checks, and
the assumption that framework-managed namespace directories are not
swapped for links (which fails closed).

New tests cover link escapes into a sibling namespace and outside the
workspace via absolute, relative, and leading-slash routes, broken-link
targets, and the no-false-positive case of links that stay inside the
own namespace (skipped where the platform cannot create links).
@chang6666

Copy link
Copy Markdown
Contributor Author

Thanks for the thorough review — all findings are addressed in 07ce9f5. Summary:

[Critical] Symlink escape — Fixed. requireOwnNamespace now compares the physical location: the candidate is resolved with Path.toRealPath(), falling back to the nearest existing ancestor resolved to its real path plus the lexical remainder for not-yet-created paths (components that don't exist yet cannot hide a link). Broken links are followed lexically via Files.readSymbolicLink, so the eventual target location is what gets compared. The namespace root is anchored at the physical cwd (cwd.toRealPath()), keeping both sides consistent when cwd itself sits behind a link (/tmp vs /private/tmp on macOS). The namespace components stay lexical on purpose: those directories are framework-managed, and a link swapped in for one of them fails closed (all access through it rejected) instead of re-anchoring the boundary.

Relative keys escaping via symlink — Fixed rather than only documented: the boundary check now also applies to namespace-prefixed relative keys, so link/file prefixed into the own namespace is rejected when the link leads out. The javadoc no longer claims relative keys never reach the check.

Case sensitivity of startsWith — Fixed as a side effect of physical resolution: toRealPath() returns the on-disk casing, so both sides compare canonically on case-insensitive hosts (Windows, APFS). (While re-verifying, we concluded this finding is a false-reject rather than an escape — a casing mismatch fails closed at the earlier root checks — but it is fixed regardless.)

TOCTOU — Documented as a remaining limitation in the namespaceBoundary(boolean) javadoc: the check runs before the file operation, so a component swapped in between is not covered. Closing it entirely would need fd-level operations (openat-style), out of scope for a Path-based API; physical resolution narrows the window.

nsRoot recomputation — Kept per-call deliberately: the namespace is derived per call from the RuntimeContext, so one instance can serve multiple sessions and a per-instance cache would be wrong; a per-namespace map would add state for negligible gain (one string join plus one toRealPath next to the operation's own I/O).

Tests — Added four cases in LocalFilesystemModeTest: link into a sibling namespace rejected via absolute, relative, and leading-slash routes; link outside the workspace rejected; broken link into a sibling rejected; and a link staying inside the own namespace still allowed (no false positive). All skip via Assumptions where the platform cannot create links (Windows CI). Full agentscope-harness suite: 1067 tests, 0 failures (14 skipped, same as baseline); spotless:check passes.

@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 07ce9f5e. All four functional findings from the previous review are properly resolved: the boundary is now checked on physical paths (symlinks inside the own namespace can no longer lead to a sibling namespace or out of the workspace), casing is normalized for case-insensitive hosts, TOCTOU and framework-managed-namespace assumptions are explicitly documented with fail-closed behavior, and symlink escape/allow tests were added (with a sane Windows assumeTrue probe). No re-review blockers from the code side — remaining inline notes are opt-out/migration, performance, and minor ergonomics.

One gate: build (ubuntu-latest) is red, but the failure is Upload coverage reports to Codecov (fail_ci_if_error: true, tokenless fork upload) — compile and all tests passed (80 tests, 0 failures before the upload step). Not a code problem; a maintainer re-run / coverage-token path should clear it.


Automated review by github-manager-bot

// path would let one session/user address another session's directory under the
// shared workspace root (#3261). SANDBOXED re-roots absolute paths under the
// workspace already, and UNRESTRICTED is documented to pass absolute paths through.
upper.namespaceBoundary(true);

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] This flips behavior for every existing ROOTED deployment built on the spec: absolute keys that legitimately addressed shared content under the workspace root (<cwd>/shared/...) now throw SecurityException. The fix is correct (it is what #3261 needs) and direct LocalFilesystem users keep the old default, but users upgrading will only discover this at runtime. Suggest (a) calling this out in the release notes / migration doc, and (b) a LocalFilesystemSpec escape hatch (e.g. namespaceBoundary(false) mirroring the opt-in) so an operator with a vetted single-tenant workspace can keep the old behavior without patching the library.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented in 3ac7058: LocalFilesystemSpec.namespaceBoundary(Boolean) now exists as the explicit opt-out/in (false keeps pre-boundary behaviour for vetted single-tenant workspaces, true forces it on in every mode, omit for the default). Migration note added to the harness filesystem docs (en+zh) with the shared-content-via-relative-paths guidance; the release-notes page currently only tracks released versions (2.0.2/2.0.3 entries do not exist yet), so I left its structure to the maintainers.

if (ns == null || ns.isEmpty()) {
return;
}
Path nsRoot = physicalCwd().resolve(String.join("/", ns)).normalize();

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] With the boundary enabled, every resolvePath in ROOTED mode now performs at least two toRealPath() calls (physicalCwd() and physicalPath(resolved)), plus resolve(tail)/normalize() walks when the target does not exist yet (the common case for write). That is fine for correctness, but it is hot for file-tool-heavy agents. Cheap wins while keeping the semantics: cache physicalCwd() after the first successful resolution (cwd is immutable), and when namespaceBoundary is on you can skip physicalPath() for the namespace-prefixed relative form if the freshly created path does not exist yet and no ancestor along cwd/<ns> is a link (the fail-closed variant: only walk the ancestor chain that already exists once, not per call).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 3ac7058: physicalPath(cwd) is cached per instance (volatile lazy field — computed on first boundary use so legacy constructors stay I/O-free), halving the guarded hot path. The per-call walks that remain are the namespace suffix and the candidate itself, which cannot be cached safely (per-call namespace, mutable filesystem).

Path tail = null;
for (int hops = 0; hops < 64; hops++) {
try {
Path real = p.toRealPath();

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] On the lexical-fallback floor of physicalPath(): when the 64-hop guard (or an unreadable link) leaves p as a relative lexical path, startsWith(nsRoot) compares a relative path against the absolute physical nsRoot, so it fails closed — good, but the resulting SecurityException message will be confusing for the user ("outside the isolated namespace" when they passed a normal relative path). Consider detecting the unresolved case and throwing a distinct "path could not be resolved" error. Minor.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 3ac7058: a candidate that floors to a relative lexical path now raises a distinct "could not be resolved to a physical location" SecurityException instead of the misleading namespace message.

* namespace directory are rejected with a {@link SecurityException} in
* {@link LocalFsMode#ROOTED} mode. Off by default; see {@link #namespaceBoundary(boolean)}.
*/
private boolean namespaceBoundary = 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.

[Info] namespaceBoundary is a non-final mutable field while LocalFilesystem is otherwise built from final config and shared across concurrent agent calls; the javadoc says it must be configured before exposure, which is not enforceable. A volatile field (or making it a constructor parameter) removes the publication hazard if any caller does set it lazily. The Spec path sets it before publishing, so today this is theoretical.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 3ac7058: the field is now volatile (constructor-parameter route would break the spec's builder call-site for marginal gain; the configure-before-expose contract stays in the javadoc).

@oss-maintainer

Copy link
Copy Markdown
Collaborator

Review summary (accompanies my inline review comments: #3292 (review))

Summary

Re-review after 07ce9f5e. All four functional findings from the previous review are properly resolved: the boundary is now checked on physical paths (symlinks inside the own namespace can no longer lead to a sibling namespace or out of the workspace), casing is normalized for case-insensitive hosts, TOCTOU and framework-managed-namespace assumptions are explicitly documented with fail-closed behavior, and symlink escape/allow tests were added (with a sane Windows assumeTrue probe). No re-review blockers from the code side — remaining inline notes are opt-out/migration, performance, and minor ergonomics.

One gate: build (ubuntu-latest) is red, but the failure is Upload coverage reports to Codecov (fail_ci_if_error: true, tokenless fork upload) — compile and all tests passed (80 tests, 0 failures before the upload step). Not a code problem; a maintainer re-run / coverage-token path should clear it.


Automated review by github-manager-bot

…solution

BuilderBootstrapSmokeTest failed on Windows: WorkspaceContextMiddleware
globs the knowledge directory before the workspace root exists, and the
boundary check then resolved the candidate up to the nearest existing
ancestor — above the workspace root — while the namespace root anchored
at cwd.toRealPath() had fallen back to the lexical form because cwd did
not exist yet. On hosts where the two forms differ (Windows 8.3 short
names like RUNNER~1, macOS /var vs /private/var) the prefix comparison
rejected paths that sit inside the caller's own namespace.

The namespace root now goes through the same physicalPath() resolution
as the candidate, so both sides walk up to the same ancestor and agree
by construction, regardless of cwd existence or path aliases. A link
swapped in for a namespace directory now re-anchors the boundary to its
target instead of failing closed; that trade-off is documented.

Adds a regression test that reads and globs through a not-yet-created
workspace root, which reproduces the aliasing mismatch locally.
@chang6666

Copy link
Copy Markdown
Contributor Author

Windows CI failure explained and fixed in 391a14c. The 4 BuilderBootstrapSmokeTest failures were a real regression introduced by the boundary fix, not infra this time: WorkspaceContextMiddleware globs the knowledge directory before the workspace root exists, and my first physical-path version then resolved the candidate up to the nearest existing ancestor (above the workspace root, in expanded runneradmin form) while the namespace root fell back to the lexical RUNNER~1 form because cwd.toRealPath() threw — the two sides of the prefix comparison no longer agreed, and legit own-namespace paths were rejected on Windows.

The namespace root now goes through the same physicalPath() resolution as the candidate, so the comparison is consistent by construction (fixed locally on macOS, which reproduces the same class of aliasing via /var → /private/var). Harness suite: 1068 tests, 0 failures; new regression test covers the not-yet-created workspace root case. The codecov 400 on the previous run was a separate, transient service-side rejection (tokenless fork upload) — the retriggered run passed it.

@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 391a14cc. The delta is exactly what the Windows failure needed: the namespace root is now anchored through the same physicalPath() walk as the candidate, so a not-yet-created workspace root and path aliases (RUNNER~1, /var → /private/var) land on the same nearest-existing-ancestor on both sides instead of one lexical / one real. The new cold-workspace test covers both affected routes (read → not found, glob → empty success). The previous round's functional findings stay resolved — physical resolution, casing, TOCTOU documentation and the symlink escape tests are all still in place.

One property moved, and it is the one thing I would like a maintainer to confirm before this lands: anchoring nsRoot physically means a symlink swapped in for the namespace directory itself now re-anchors the boundary instead of failing closed (the reworded javadoc acknowledges this). Reachability through the file API is nil — nothing in LocalFilesystem calls Files.createSymbolicLink — so it is a defence-in-depth loss, not a tenant-side escape, and I left it as a Warning with a one-loop-per-call alternative that keeps both halves.

Findings

  • [Warning] LocalFilesystem.java:762 — namespace root resolved physically ⇒ a swapped cwd/<ns> symlink re-anchors the boundary instead of failing closed; suggested Files.isSymbolicLink guard on each namespace component.
  • [Info] LocalFilesystem.java:791 — physicalPath() now runs twice per guarded resolution and climbs ancestor-by-ancestor while the workspace is missing; physicalPath(cwd) is instance-immutable and can be computed once.
  • [Info] LocalFilesystemModeTest.java:502 — the changed property itself has no test; suggested a symlinked-namespace-root case and a symlinked-ancestor alias case.

Carried over from the previous round, still open and not repeated here: LocalFilesystemSpec.java:346 (ROOTED behaviour flip with no opt-out / migration note), LocalFilesystem.java:97 (namespaceBoundary is non-final mutable on a shared instance), and the physicalPath() lexical-floor note.

Gate

CI on 391a14cc is still running (build (ubuntu-latest), build (windows-latest) and Check License pending; Check Module Sync and license/cla pass), and GitHub reports reviewDecision=REVIEW_REQUIRED. Not approving this round: the re-anchor semantics deserve an explicit maintainer call, and the Windows result is what proves the fix. Happy to re-review on request once the run is green.


Automated review by github-manager-bot

if (ns == null || ns.isEmpty()) {
return;
}
Path nsRoot = physicalPath(cwd.resolve(String.join("/", ns)));

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] Resolving nsRoot through physicalPath() fixes the false-reject (good), but it also drops the fail-closed behaviour the previous revision had for a swapped namespace directory. Before: nsRoot was physicalCwd().resolve(ns).normalize(), with the namespace components kept lexical, so if cwd/<ns> had been replaced by a link into a sibling namespace, the candidate resolved through the link while the root did not, and the check threw. Now both sides are link-resolved, so cwd/<ns> -> cwd/<siblingNs> makes the two sides agree and the cross-namespace path is accepted — the reworded javadoc states that trade-off explicitly ("re-anchors the boundary to its target rather than being detectable from here").

I'm calling it a Warning rather than a Critical because of reachability: planting that link needs write access at the workspace-root level, and a bounded tenant cannot get there through the LocalFilesystem API (its write/edit/glob/delete path never calls Files.createSymbolicLink). What is lost is defence-in-depth against an operator mistake or a framework bug that materialises a namespace directory as a symlink. One caveat worth recording: the boundary was never a control for the shell-bearing variant — LocalFilesystemWithShell.execute() runs sh -c with the namespace directory as the process working directory and no command filtering, and that class's javadoc states it provides no sandboxing or process isolation; that configuration relies on the sandbox layer, not on this check.

The cheapest way to keep both properties is to leave the comparison exactly as it is now and reject a linked namespace component up front, before the comparison:

Path nsDir = cwd;
for (String segment : ns) {
    nsDir = nsDir.resolve(segment);
    if (Files.isSymbolicLink(nsDir)) {
        throw rootAccessDenied(resolved);   // namespace dirs are framework-managed, never links
    }
}
Path nsRoot = physicalPath(nsDir);

That keeps the alias normalisation (RUNNER~1, /var → /private/var) and the on-disk casing on both sides, and restores fail-closed for the swapped-directory case. Anchoring the root lexically instead (physicalPath(cwd).resolve(ns).normalize()) also restores fail-closed, but reintroduces a casing asymmetry on case-insensitive hosts — the candidate would be fully real-pathed while the namespace suffix stays in its configured casing — so the link guard is the better half of the two. Whichever way it goes, if re-anchoring really is the intended semantics, the namespaceBoundary(boolean) javadoc at line 270 should say so in those words: today it describes the consequence in passing, and a reader who saw the previous "fails closed" wording would not learn from here that the guarantee moved.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented in 3ac7058 using exactly the sketched guard: every namespace component is checked with Files.isSymbolicLink before the comparison and a linked namespace directory is rejected outright (fail closed), while alias resolution on cwd itself (8.3 short names, /var) stays tolerated and both sides still real-path consistently. The shell caveat is now recorded in the namespaceBoundary(boolean) javadoc. This also removes the maintainer call the re-anchor question needed — the original fail-closed property is back.

* lexical form is returned as a floor: no resolvable outside location can slip through,
* and the subsequent file operation fails on its own for the unresolvable remainder.
*/
private static Path physicalPath(Path path) {

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] physicalPath() is now called twice per guarded resolution — once for the namespace root at line 762, once for the candidate at line 763 — and each call is a loop that issues a toRealPath() plus a Files.isSymbolicLink() for every ancestor it climbs. In the exact case this commit targets (the workspace root is not created yet), both calls climb the whole missing suffix before the operation fails, so a cold read/glob/ls pays roughly 2 * depth stat+realpath pairs — and keeps paying it for as long as the workspace stays empty.

My earlier note about a per-namespace cache still stands as declined: the namespace comes from RuntimeContext per call, so a cache keyed by the instance alone would be wrong. The cwd half, however, is immutable for the lifetime of the instance, so physicalPath(cwd) can be a final field computed once in the constructor and the namespace suffix joined onto it per call (the link guard sketched above fits that shape naturally). That halves the resolution cost of the boundary check on the hot path for every ROOTED-mode file operation.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 3ac7058 via the cached physical cwd — the per-call work is now one join + link guard + one toRealPath for the namespace suffix, plus the candidate resolution.

.namespaceBoundary(true);
RuntimeContext rc = RuntimeContext.builder().userId("user-1").build();

ReadResult r = fs.read(rc, "notes.md", 0, 0);

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] Right regression guard for the Windows failure, and asserting both routes is the correct choice — read must degrade to not found instead of tripping the boundary, and glob must return an empty success instead of throwing; those are the two callers that actually hit a cold workspace.

Two additions would pin the semantics this commit changed instead of leaving them to the javadoc:

  1. A case where the own-namespace directory is replaced by a link into a sibling namespace, asserting whichever behaviour the maintainers decide (fail closed, or allow-after-re-anchor). Nothing exercises that path today, and it is the one property this commit actually moved — without a test it can silently flip back in either direction.
  2. Where feasible, a case that builds the workspace under a symlinked ancestor (guarded by the existing symlinksSupported probe and skipped when unsupported). Right now the alias-normalisation property both sides rely on is only implied by whatever @TempDir happens to return on a given platform, so a future change to how the root is anchored would be caught here only by accident.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both added in 3ac7058: rooted_symlinkedNamespaceDirectoryRejected pins fail-closed via absolute and relative routes, and rooted_symlinkedWorkspaceAliasTolerated builds the workspace behind a symlinked ancestor (guarded by the same symlinksSupported probe) and asserts relative and absolute access through the alias.

Review follow-ups on the namespace boundary:

- A link swapped in for a namespace directory re-anchored the boundary
  to its target, accepting cross-namespace access. Namespace components
  are now checked with Files.isSymbolicLink before the comparison and
  rejected outright (fail closed), while path aliases on cwd itself
  (Windows 8.3 short names, macOS /var) stay tolerated.
- LocalFilesystemSpec gains namespaceBoundary(Boolean) as an explicit
  opt-out/in for operators upgrading ROOTED deployments whose absolute
  keys legitimately addressed shared content under the workspace root;
  the migration note now lives in the harness filesystem docs (en+zh).
- physicalPath(cwd) is cached per instance (cwd is immutable), halving
  the resolution cost of the guarded hot path; a fully unresolved
  candidate now raises a distinct "could not be resolved" error instead
  of a misleading namespace message; namespaceBoundary is volatile to
  make a late configuration publish safely.
- Tests pin the moved semantics: a linked namespace directory is
  rejected via absolute and relative routes, a symlinked workspace
  ancestor is tolerated, and the spec default blocks while the escape
  hatch restores legacy absolute access.
@chang6666

Copy link
Copy Markdown
Contributor Author

All open findings from the last two review rounds are addressed in 3ac7058:

  • Swapped namespace directory (Warning) — the sketched Files.isSymbolicLink guard is in: every namespace component is checked before the comparison and a linked namespace directory is rejected outright (fail closed), while cwd-level aliases (8.3 short names, /var → /private/var) stay tolerated. The namespaceBoundary(boolean) javadoc now states this in those words and records the execute() shell caveat. This also resolves the "maintainer call" the re-anchor question needed — the original property is restored.
  • Spec escape hatch + migration note (Warning) — LocalFilesystemSpec.namespaceBoundary(Boolean) (force on / force off / default), with the migration note in the harness filesystem docs (en+zh).
  • Cached physicalPath(cwd) + perf (Info) — cached in a volatile lazy field, halving the guarded hot path; per-namespace caching stays declined for the reason noted.
  • Lexical floor (Info) — a fully unresolved candidate now raises a distinct "could not be resolved" error.
  • Volatile namespaceBoundary (Info) — done.
  • Semantics tests (Info) — linked namespace directory rejected via absolute + relative routes; symlinked workspace ancestor tolerated (relative + absolute through the alias); spec default blocks while the escape hatch restores legacy absolute access.

Harness suite: 1072 tests, 0 failures (14 skipped, baseline); spotless:check clean. CI is running on 3ac7058f.

@oss-maintainer happy to take a re-review once it's green — the Windows result and these tests now pin all the moved properties.

@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 two new commits: this now addresses every outstanding point from my previous review - the linked-namespace-directory case fails closed instead of re-anchoring the boundary, the cwd physical form is cached instead of re-walked per call, the boundary flag is safely published, and LocalFilesystemSpec.namespaceBoundary(Boolean) gives deployments an explicit opt-out for the absolute-path behaviour change (documented in both the en and zh filesystem docs, with tests for the reject/allow sides and the escape hatch). LGTM, approving.

Findings

  • [Info] LocalFilesystem.java:781 - the link check covers namespace segments but not the cached cwd anchor itself; cold-workspace-then-symlink is still re-anchored onto the link target. Hardening follow-up, not blocking.

Notes

  • CI was still in flight on the merge commit at review time, and the merge of main (including the JdbcAgentStateStore changes) resolved cleanly with no boundary-logic fallout visible in the diff.
  • Heads-up for maintainers: with the default now boundary-on for ROOTED, the release notes should call out namespaceBoundary(false) for single-tenant deployments that legitimately addressed shared workspace content by absolute path.

Automated review by github-manager-bot

Path nsDir = physicalCwd();
for (String segment : ns) {
nsDir = nsDir.resolve(segment);
if (Files.isSymbolicLink(nsDir)) {

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] Nice - the fail-closed guard is exactly the shape suggested, and the cached cwd anchor removes the repeated ancestor walk. One residual edge worth a follow-up: the loop link-checks the namespace segments but never the anchor itself, and physicalCwd() is filled once and never revalidated. If the workspace root does not exist at the first guarded resolution (cold workspace) and is later created as a symlink (or under a newly symlinked component), the cached anchor keeps the stale lexical form while the per-call physicalPath(resolved) side follows the link, so nsRoot gets re-anchored onto the link target and the comparison passes against a root outside the intended workspace. Reaching it needs write access above the workspace root, so this is a hardening note rather than a blocker - a Files.isSymbolicLink(cwd) check when the cache is filled (or re-resolving when the cached anchor's lexical form no longer matches cwd) would close it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Closed in fb7c454 with the deeper of the two options: the cache is now filled only once cwd exists, so the cold-anchor state class is gone entirely — there is no stale lexical form for a later-materialised link to be followed through, and the cold workspace simply re-resolves per call until the root exists (the climb is transient by definition). A cache that goes stale after filling (root swapped or removed) can only make the candidate and the namespace root disagree, which fails closed — it can never silently re-anchor. One property is deliberately kept and now documented in the namespaceBoundary(boolean) javadoc: a root that materialises as a link before the first guarded call anchors at its target, the same way as a pre-existing path alias — distinguishing the two at fill time is not possible without breaking the alias tolerance (8.3 short names, /var → /private/var), and reaching either requires operator-level write access above the workspace root, so it stays recorded as an operator-level assumption rather than a tenant-side guarantee.

A cold anchor sits above a not-yet-existing workspace root and keeps a
stale lexical form. If the root later materialised as a symbolic link,
the namespace resolution followed it from that stale form and silently
re-anchored the boundary onto the link's target. The cache is now filled
only once cwd exists; a cache that goes stale afterwards can only make
the candidate and the namespace root disagree, which fails closed. A
root that materialises as a link is followed the same way as a
pre-existing path alias (operator-level, outside tenant reach), which
the namespaceBoundary javadoc now records.

@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-reviewed fb7c4549 ("never cache a cold physical cwd anchor") — the diff is exactly what the last review round sketched: physicalCwd() now fills the cache only once cwd exists, so a workspace root that later materialises as a symlink can no longer silently re-anchor the namespace boundary from a stale lexical form; cold paths fail closed per-call, and the javadoc + boundary-limitation notes are updated to match. The fail-closed opt-out from 3ac7058f is unchanged. CLA signed, tests updated. All my prior findings are addressed — approving on the new head; merging remains a maintainer call.


Automated review by github-manager-bot

ningmao-hlyz added a commit to ningmao-hlyz/agentscope-java that referenced this pull request Nov 8, 2026
## Description

With the default local filesystem, a blank or relative path reaches across
namespaces:

- `grep(pattern, "")` returns matches from another user's `MEMORY.md`,
  content included; `ls("")` and `glob("**/*.md", "")` list the sibling
  namespaces.
- `grep(pattern, ".")` behaves the same, because the overlay hands the same
  path to the upper (workspace) and lower (project) layers, and the default
  workspace is a subtree of the project directory: a recursive search from
  the project root walks every namespace under it.

`LocalFilesystem.resolvePath` passes a blank key to the namespace prefix
unchanged, so it resolves to `cwd`, the workspace root. The project layer
carries no namespace at all, so any recursive enumeration from there covers
the whole workspace.

### What changed

- A blank key is resolved as `.` before the namespace is applied, so an
  empty path means "the caller's root" instead of the shared workspace root.
  Deployments without a namespace resolve to the same directory as before.
- `LocalFilesystem` can exclude a subtree from `ls`/`grep`/`glob`, and
  `LocalFilesystemSpec` excludes the workspace from the project layer while
  it is namespaced — a shared workspace (`sharedLocalWorkspace(true)`)
  belongs to every caller equally and stays enumerable. The exclusion prunes
  the walk itself (directory visitors skip the subtree) instead of filtering
  results after visiting every file. Reads and writes still reach the
  workspace; only enumeration is bounded. Addressing the excluded subtree as
  an explicit search root now yields nothing rather than walking it.

Absolute paths and `..` segments are out of scope: agentscope-ai#3292 covers the former,
agentscope-ai#3378 the latter, and the shell keeps its own project-rooted working
directory (agentscope-ai#2329).

### Tests

- New: as one user, a blank, relative or glob search sees nothing under
  another user's namespace — through the workspace layer and through a
  workspace nested in the project directory, in both the default and the
  writable-project construction.
- New: a shared workspace stays enumerable through the project layer, so the
  exclusion does not over-reach into single-tenant deployments.
- `mvn -pl agentscope-harness test`: 1622 tests, 0 failures.
ningmao-hlyz added a commit to ningmao-hlyz/agentscope-java that referenced this pull request Nov 8, 2026
## Description

With the default local filesystem, the project layer reaches across
namespaces in two ways:

- Enumeration: `grep(pattern, "")` returns matches from another user's
  `MEMORY.md`, content included; `ls("")` and `glob("**/*.md", "")` list the
  sibling namespaces. The overlay hands the same path to the upper (workspace)
  and lower (project) layers, the default workspace is a subtree of the
  project directory, and the lower layer carries no namespace.
- Direct content access: `read`, `exists`, `edit` (copy-on-write),
  `downloadFiles` and `move` fall back to the lower layer too, so a relative
  path spelling the physical layout — `.agentscope/workspace/alice/MEMORY.md`
  — reads alice's file, and `edit` copies it into the caller's namespace
  before modifying it.

`LocalFilesystem.resolvePath` passes a blank key to the namespace prefix
unchanged, so it resolves to the workspace root; the physical layout is
reachable whenever the caller names it.

### What changed

- A blank key is resolved as `.` before the namespace is applied, so an
  empty path means "the caller's root" instead of the shared workspace root.
  Deployments without a namespace resolve to the same directory as before.
- `LocalFilesystem` can hide a subtree entirely: enumeration skips it while
  walking, and the content operations see nothing there — reads, edits,
  writes, downloads and existence checks answer "not found". Explicitly
  addressing a hidden subtree as a search root yields nothing rather than
  walking it.
- `LocalFilesystemSpec` hides the workspace from the project layer when the
  workspace is a proper subtree of the project and namespace scoping is on.
  A workspace equal to or outside the project has no nesting to hide, a
  shared workspace belongs to every caller equally, and the projectFs write
  route carries the namespace factory itself, so physical-layout spellings
  resolve under the caller's own prefix either way. Project files outside
  the workspace subtree stay shared, like `AGENTS.md` and `knowledge/`.

Absolute paths and `..` segments are out of scope: agentscope-ai#3292 covers the former,
agentscope-ai#3378 the latter, and the shell keeps its own project-rooted working
directory (agentscope-ai#2329).

### Tests

- New: as one user, a blank, relative or glob search sees nothing under
  another user's namespace — in both the default and the writable-project
  construction — and the content operations answer "not found" for a
  sibling namespace spelled through the physical layout, while project
  files outside the workspace and the caller's own namespace stay readable.
- New: a shared workspace stays enumerable through the project layer, so
  the boundary does not over-reach into single-tenant deployments.
- New: `memory_get` cannot fetch a sibling namespace's content by spelling
  the physical layout.
- `mvn -pl agentscope-harness test`: 1622 tests, 0 failures.
ningmao-hlyz added a commit to ningmao-hlyz/agentscope-java that referenced this pull request Nov 8, 2026
## Description

With the default local filesystem, the project layer reaches across
namespaces in two ways:

- Enumeration: `grep(pattern, "")` returns matches from another user's
  `MEMORY.md`, content included; `ls("")` and `glob("**/*.md", "")` list the
  sibling namespaces. The overlay hands the same path to the upper (workspace)
  and lower (project) layers, the default workspace is a subtree of the
  project directory, and the lower layer carries no namespace.
- Direct content access: `read`, `exists`, `edit` (copy-on-write),
  `downloadFiles` and `move` fall back to the lower layer too, so a relative
  path spelling the physical layout — `.agentscope/workspace/alice/MEMORY.md`
  — reads alice's file, and `edit` copies it into the caller's namespace
  before modifying it.

`LocalFilesystem.resolvePath` passes a blank key to the namespace prefix
unchanged, so it resolves to the workspace root; the physical layout is
reachable whenever the caller names it.

### What changed

- A blank key is resolved as `.` before the namespace is applied, so an
  empty path means "the caller's root" instead of the shared workspace root.
  Deployments without a namespace resolve to the same directory as before.
- `LocalFilesystem` can hide a subtree entirely: enumeration skips it while
  walking, and the content operations see nothing there — reads, edits,
  writes, downloads and existence checks answer "not found". Explicitly
  addressing a hidden subtree as a search root yields nothing rather than
  walking it.
- `LocalFilesystemSpec` hides the workspace from the project layer when the
  workspace is a proper subtree of the project and namespace scoping is on.
  A workspace equal to or outside the project has no nesting to hide, a
  shared workspace belongs to every caller equally, and the projectFs write
  route carries the namespace factory itself, so physical-layout spellings
  resolve under the caller's own prefix either way. Project files outside
  the workspace subtree stay shared, like `AGENTS.md` and `knowledge/`.

Absolute paths and `..` segments are out of scope: agentscope-ai#3292 covers the former,
agentscope-ai#3378 the latter, and the shell keeps its own project-rooted working
directory (agentscope-ai#2329).

### Tests

- New: as one user, a blank, relative or glob search sees nothing under
  another user's namespace — in both the default and the writable-project
  construction — and the content operations answer "not found" for a
  sibling namespace spelled through the physical layout, while project
  files outside the workspace and the caller's own namespace stay readable.
- New: a shared workspace stays enumerable through the project layer, so
  the boundary does not over-reach into single-tenant deployments.
- New: `memory_get` cannot fetch a sibling namespace's content by spelling
  the physical layout.
- `mvn -pl agentscope-harness test`: 1622 tests, 0 failures.
ningmao-hlyz added a commit to ningmao-hlyz/agentscope-java that referenced this pull request Nov 8, 2026
## Description

With the default local filesystem, the project layer reaches across
namespaces in three ways:

- Enumeration: `grep(pattern, "")` returns matches from another user's
  `MEMORY.md`, content included; `ls("")` and `glob("**/*.md", "")` list the
  sibling namespaces. The overlay hands the same path to the upper (workspace)
  and lower (project) layers, the default workspace is a subtree of the
  project directory, and the lower layer carries no namespace.
- Direct content access: `read`, `exists`, `edit` (copy-on-write),
  `downloadFiles` and `move` fall back to the lower layer too, so a relative
  path spelling the physical layout - `.agentscope/workspace/alice/MEMORY.md`
  - reads alice's file, and `edit` copies it into the caller's namespace
  before modifying it.
- Absolute paths: the namespace prefix is skipped for absolute spellings, so
  without a boundary the `projectFs` write route would run a delete or move
  against an absolute path inside the workspace subtree.

Previously `LocalFilesystem.resolvePath` passed a blank key to the namespace
prefix unchanged, so it resolved to the workspace root; the physical layout
was reachable whenever the caller named it.

### What changed

- A blank key is resolved as `.` before the namespace is applied, so an
  empty path means "the caller's root" instead of the shared workspace root.
  Deployments without a namespace resolve to the same directory as before.
- `LocalFilesystem` can hide a subtree entirely: enumeration skips it while
  walking, and the content operations - reads, edits, writes, deletes, moves,
  downloads, uploads and existence checks - see nothing there. `delete`
  treats the subtree as absent (an idempotent no-op that never walks it),
  `move` can neither move a file out of or into the subtree, and both `move`
  and recursive `delete` refuse a directory that contains it outright rather
  than partially touch it. Explicitly addressing a hidden subtree as a
  search root yields nothing rather than walking it, and a `walkFileTree`
  visitor that cannot enter a directory skips and continues instead of
  propagating.
- `LocalFilesystemSpec` hides the workspace from the project layers when the
  workspace is a proper subtree of the project and namespace scoping is on -
  both the read-only lower layer and, for the same reason, the `projectFs`
  write route, whose absolute paths skip the namespace prefix. A workspace
  equal to or outside the project has no nesting to hide, a shared workspace
  belongs to every caller equally, and project files outside the workspace
  subtree stay shared, like `AGENTS.md` and `knowledge/`.
- `relativeForGlob` compares the first path name instead of the string, so a
  legitimate directory literally named `..cache` is a descendant, not a
  traversal escape.
- `docs/v2/{zh,en}/docs/harness/filesystem.md` note the boundary in the
  Overlay filesystem section, the project-writable read behavior, and the
  mode table.

Absolute paths in the upper (workspace) layer and `..` segments are out of
scope: agentscope-ai#3292 covers the former, agentscope-ai#3378 the latter. The shell keeps its own
project-rooted working directory, so `execute` is not bound by these guards
(agentscope-ai#2329). The ripgrep `--glob` exclusions assume rg matches globs against
paths relative to the search root; where that does not hold, the boundary
still holds because the default workspace lives under a hidden directory
that rg skips by default, and the `walkFileTree` fallback applies the same
exclusions directly.

### Tests

- New: as one user, a blank, relative or glob search sees nothing under
  another user's namespace - in both the default and the writable-project
  construction - and the content operations answer "not found" for a
  sibling namespace spelled through the physical layout, while project
  files outside the workspace and the caller's own namespace stay readable.
- New: direct use of the hidden lower layer - `delete` leaves the subtree
  untouched, `move` cannot cross the boundary in either direction, writes
  cannot land inside it (the target does not exist yet, so the assertion
  cannot pass merely because the file is there), and operations that start
  at an ancestor (recursive delete, directory move) are refused outright
  instead of partially touching the hidden subtree. Each of these assertions
  was verified to fail with its guard removed.
- New: a shared workspace stays enumerable through the project layer, so
  the boundary does not over-reach into single-tenant deployments.
- New: `memory_get` cannot fetch a sibling namespace's content. This test's
  workspace is a standalone temp directory, so it pins the blank-key and
  namespace-prefix resolution end to end; the real project-layer boundary is
  exercised by the boundary tests below.
- `mvn -pl agentscope-harness test`: 1626 tests, 0 failures.

Fixes agentscope-ai#4069
ningmao-hlyz added a commit to ningmao-hlyz/agentscope-java that referenced this pull request Nov 8, 2026
## Description

With the default local filesystem, the project layer reaches across
namespaces in three ways:

- Enumeration: `grep(pattern, "")` returns matches from another user's
  `MEMORY.md`, content included; `ls("")` and `glob("**/*.md", "")` list the
  sibling namespaces. The overlay hands the same path to the upper (workspace)
  and lower (project) layers, the default workspace is a subtree of the
  project directory, and the lower layer carries no namespace.
- Direct content access: `read`, `exists`, `edit` (copy-on-write),
  `downloadFiles` and `move` fall back to the lower layer too, so a relative
  path spelling the physical layout - `.agentscope/workspace/alice/MEMORY.md`
  - reads alice's file, and `edit` copies it into the caller's namespace
  before modifying it.
- Absolute paths: the namespace prefix is skipped for absolute spellings, so
  without a boundary the `projectFs` write route would run a delete or move
  against an absolute path inside the workspace subtree.

Previously `LocalFilesystem.resolvePath` passed a blank key to the namespace
prefix unchanged, so it resolved to the workspace root; the physical layout
was reachable whenever the caller named it.

### What changed

- A blank key is resolved as `.` before the namespace is applied, so an
  empty path means "the caller's root" instead of the shared workspace root.
  Deployments without a namespace resolve to the same directory as before.
- `LocalFilesystem` can hide a subtree entirely: enumeration skips it while
  walking, and the content operations - reads, edits, writes, deletes, moves,
  downloads, uploads and existence checks - see nothing there. `delete`
  treats the subtree as absent (an idempotent no-op that never walks it),
  `move` can neither move a file out of or into the subtree, and both `move`
  and recursive `delete` refuse a directory that contains it outright rather
  than partially touch it. Explicitly addressing a hidden subtree as a
  search root yields nothing rather than walking it, and a `walkFileTree`
  visitor that cannot enter a directory skips and continues instead of
  propagating.
- `LocalFilesystemSpec` hides the workspace from the project layers when the
  workspace is a proper subtree of the project and namespace scoping is on -
  both the read-only lower layer and, for the same reason, the `projectFs`
  write route, whose absolute paths skip the namespace prefix. A workspace
  equal to or outside the project has no nesting to hide, a shared workspace
  belongs to every caller equally, and project files outside the workspace
  subtree stay shared, like `AGENTS.md` and `knowledge/`.
- The ripgrep path of `grep` runs rg with its working directory set to the
  search root: `--glob` patterns match against paths relative to the working
  directory, so the excluded-subtree globs missed whenever the parent process
  was started outside the search root. Output paths do not depend on the
  working directory, so entry-path resolution is unaffected.
- `relativeForGlob` compares the first path name instead of the string, so a
  legitimate directory literally named `..cache` is a descendant, not a
  traversal escape.
- `docs/v2/{zh,en}/docs/harness/filesystem.md` note the boundary in the
  Overlay filesystem section, the project-writable read behavior, and the
  mode table.

Absolute paths in the upper (workspace) layer and `..` segments are out of
scope: agentscope-ai#3292 covers the former, agentscope-ai#3378 the latter. The shell keeps its own
project-rooted working directory, so `execute` is not bound by these guards
(agentscope-ai#2329). The `walkFileTree` fallback of `grep` applies the same exclusions
directly.

### Tests

- New: as one user, a blank, relative or glob search sees nothing under
  another user's namespace - in both the default and the writable-project
  construction - and the content operations answer "not found" for a
  sibling namespace spelled through the physical layout, while project
  files outside the workspace and the caller's own namespace stay readable.
- New: direct use of the hidden lower layer - `delete` leaves the subtree
  untouched, `move` cannot cross the boundary in either direction, writes
  cannot land inside it (the target does not exist yet, so the assertion
  cannot pass merely because the file is there), and operations that start
  at an ancestor (recursive delete, directory move) are refused outright
  instead of partially touching the hidden subtree. Each of these assertions
  was verified to fail with its guard removed.
- New: the ripgrep path of `grep` keeps the boundary when the parent process
  cwd is unrelated to the search root - the pinned directory is deliberately
  not hidden, so ripgrep's default hidden-file skip cannot mask the result
  (verified to fail with the working-directory alignment removed). Skipped
  when ripgrep is not installed.
- New: a shared workspace stays enumerable through the project layer, so
  the boundary does not over-reach into single-tenant deployments.
- New: `memory_get` cannot fetch a sibling namespace's content. This test's
  workspace is a standalone temp directory, so it pins the blank-key and
  namespace-prefix resolution end to end; the real project-layer boundary is
  exercised by the boundary tests below.
- `mvn -pl agentscope-harness test`: 1626 tests, 0 failures.

Fixes agentscope-ai#4069
ningmao-hlyz added a commit to ningmao-hlyz/agentscope-java that referenced this pull request Nov 8, 2026
## Description

With the default local filesystem, the project layer reaches across
namespaces in three ways:

- Enumeration: `grep(pattern, "")` returns matches from another user's
  `MEMORY.md`, content included; `ls("")` and `glob("**/*.md", "")` list the
  sibling namespaces. The overlay hands the same path to the upper (workspace)
  and lower (project) layers, the default workspace is a subtree of the
  project directory, and the lower layer carries no namespace.
- Direct content access: `read`, `exists`, `edit` (copy-on-write),
  `downloadFiles` and `move` fall back to the lower layer too, so a relative
  path spelling the physical layout - `.agentscope/workspace/alice/MEMORY.md`
  - reads alice's file, and `edit` copies it into the caller's namespace
  before modifying it.
- Absolute paths: the namespace prefix is skipped for absolute spellings, so
  without a boundary the `projectFs` write route would run a delete or move
  against an absolute path inside the workspace subtree.

Previously `LocalFilesystem.resolvePath` passed a blank key to the namespace
prefix unchanged, so it resolved to the workspace root; the physical layout
was reachable whenever the caller named it.

### What changed

- A blank key is resolved as `.` before the namespace is applied, so an
  empty path means "the caller's root" instead of the shared workspace root.
  Deployments without a namespace resolve to the same directory as before.
- `LocalFilesystem` can hide a subtree entirely: enumeration skips it while
  walking, and the content operations - reads, edits, writes, deletes, moves,
  downloads, uploads and existence checks - see nothing there. `delete`
  treats the subtree as absent (an idempotent no-op that never walks it),
  `move` can neither move a file out of or into the subtree, and both `move`
  and recursive `delete` refuse a directory that contains it outright rather
  than partially touch it. Explicitly addressing a hidden subtree as a
  search root yields nothing rather than walking it, and a `walkFileTree`
  visitor that cannot enter a directory skips and continues instead of
  propagating.
- `LocalFilesystemSpec` hides the workspace from the project layers when the
  workspace is a proper subtree of the project and namespace scoping is on -
  both the read-only lower layer and, for the same reason, the `projectFs`
  write route, whose absolute paths skip the namespace prefix. A workspace
  equal to or outside the project has no nesting to hide, a shared workspace
  belongs to every caller equally, and project files outside the workspace
  subtree stay shared, like `AGENTS.md` and `knowledge/`.
- The ripgrep path of `grep` runs rg with its working directory set to the
  search root: `--glob` patterns match against paths relative to the working
  directory, so the excluded-subtree globs missed whenever the parent process
  was started outside the search root. Output paths do not depend on the
  working directory, so entry-path resolution is unaffected.
- `relativeForGlob` compares the first path name instead of the string, so a
  legitimate directory literally named `..cache` is a descendant, not a
  traversal escape.
- `docs/v2/{zh,en}/docs/harness/filesystem.md` note the boundary in the
  Overlay filesystem section, the project-writable read behavior, and the
  mode table.

Absolute paths in the upper (workspace) layer and `..` segments are out of
scope: agentscope-ai#3292 covers the former, agentscope-ai#3378 the latter. The shell keeps its own
project-rooted working directory, so `execute` is not bound by these guards
(agentscope-ai#2329). The `walkFileTree` fallback of `grep` applies the same exclusions
directly.

### Tests

- New: as one user, a blank, relative or glob search sees nothing under
  another user's namespace - in both the default and the writable-project
  construction - and the content operations answer "not found" for a
  sibling namespace spelled through the physical layout, while project
  files outside the workspace and the caller's own namespace stay readable.
- New: direct use of the hidden lower layer - `delete` leaves the subtree
  untouched, `move` cannot cross the boundary in either direction, writes
  cannot land inside it (the target does not exist yet, so the assertion
  cannot pass merely because the file is there), and operations that start
  at an ancestor (recursive delete, directory move) are refused outright
  instead of partially touching the hidden subtree. Each of these assertions
  was verified to fail with its guard removed.
- New: the ripgrep path of `grep` keeps the boundary when the parent process
  cwd is unrelated to the search root - the pinned directory is deliberately
  not hidden, so ripgrep's default hidden-file skip cannot mask the result
  (verified to fail with the working-directory alignment removed). Skipped
  when ripgrep is not installed.
- New: a shared workspace stays enumerable through the project layer, so
  the boundary does not over-reach into single-tenant deployments.
- `mvn -pl agentscope-harness test`: 1627 tests, 0 failures (one is skipped
  without ripgrep).

Fixes agentscope-ai#4069
ningmao-hlyz added a commit to ningmao-hlyz/agentscope-java that referenced this pull request Nov 10, 2026
## Description

With the default local filesystem, the project layer reaches across
namespaces in three ways:

- Enumeration: `grep(pattern, "")` returns matches from another user's
  `MEMORY.md`, content included; `ls("")` and `glob("**/*.md", "")` list the
  sibling namespaces. The overlay hands the same path to the upper (workspace)
  and lower (project) layers, the default workspace is a subtree of the
  project directory, and the lower layer carries no namespace.
- Direct content access: `read`, `exists`, `edit` (copy-on-write),
  `downloadFiles` and `move` fall back to the lower layer too, so a relative
  path spelling the physical layout - `.agentscope/workspace/alice/MEMORY.md`
  - reads alice's file, and `edit` copies it into the caller's namespace
  before modifying it.
- Absolute paths: the namespace prefix is skipped for absolute spellings, so
  without a boundary the `projectFs` write route would run a delete or move
  against an absolute path inside the workspace subtree.

Previously `LocalFilesystem.resolvePath` passed a blank key to the namespace
prefix unchanged, so it resolved to the workspace root; the physical layout
was reachable whenever the caller named it.

### What changed

- A blank key is resolved as `.` before the namespace is applied, so an
  empty path means "the caller's root" instead of the shared workspace root.
  Deployments without a namespace resolve to the same directory as before.
- `LocalFilesystem` can hide a subtree entirely: enumeration skips it while
  walking, and the content operations - reads, edits, writes, deletes, moves,
  downloads, uploads and existence checks - see nothing there. `delete`
  treats the subtree as absent (an idempotent no-op that never walks it),
  `move` can neither move a file out of or into the subtree, and both `move`
  and recursive `delete` refuse a directory that contains it outright rather
  than partially touch it. Explicitly addressing a hidden subtree as a
  search root yields nothing rather than walking it, and a `walkFileTree`
  visitor that cannot enter a directory skips and continues instead of
  propagating. The check resolves the path first, so a symbolic link that
  points into the subtree is hidden too; `delete` and `move` still act on
  the link entry itself, which never reaches the hidden target. Every
  rejection reads like a missing path, so refusing a hidden path does not
  announce that something is hidden.
- `LocalFilesystemSpec` hides the workspace from the project layers when the
  workspace is a proper subtree of the project and namespace scoping is on -
  both the read-only lower layer and, for the same reason, the `projectFs`
  write route, whose absolute paths skip the namespace prefix. A workspace
  equal to or outside the project has no nesting to hide, a shared workspace
  belongs to every caller equally, and project files outside the workspace
  subtree stay shared, like `AGENTS.md` and `knowledge/`.
- The ripgrep path of `grep` runs rg with its working directory set to the
  search root: `--glob` patterns match against paths relative to the working
  directory, so the excluded-subtree globs missed whenever the parent process
  was started outside the search root. Output paths do not depend on the
  working directory, so entry-path resolution is unaffected.
- `relativeForGlob` compares the first path name instead of the string, so a
  legitimate directory literally named `..cache` is a descendant, not a
  traversal escape.
- `docs/v2/{zh,en}/docs/harness/filesystem.md` note the boundary in the
  Overlay filesystem section, the project-writable read behavior, and the
  mode table.

Absolute paths in the upper (workspace) layer and `..` segments are out of
scope: agentscope-ai#3292 covers the former, agentscope-ai#3378 the latter. Symbolic links are covered
here - the path is resolved before the boundary is applied. The shell keeps its own
project-rooted working directory, so `execute` is not bound by these guards
(agentscope-ai#2329). The `walkFileTree` fallback of `grep` applies the same exclusions
directly.

### Tests

- New: as one user, a blank, relative or glob search sees nothing under
  another user's namespace - in both the default and the writable-project
  construction - and the content operations answer "not found" for a
  sibling namespace spelled through the physical layout, while project
  files outside the workspace and the caller's own namespace stay readable.
- New: a symbolic link planted in the project that points into the
  workspace subtree stays hidden - `read`, `ls` and `write` see nothing
  through it, and the target file is untouched. The case skips on hosts
  that cannot create links.
- New: direct use of the hidden lower layer - `delete` leaves the subtree
  untouched, `move` cannot cross the boundary in either direction, writes
  cannot land inside it (the target does not exist yet, so the assertion
  cannot pass merely because the file is there), and operations that start
  at an ancestor (recursive delete, directory move) are refused outright
  instead of partially touching the hidden subtree. Each of these assertions
  was verified to fail with its guard removed.
- New: the ripgrep path of `grep` keeps the boundary when the parent process
  cwd is unrelated to the search root - the pinned directory is deliberately
  not hidden, so ripgrep's default hidden-file skip cannot mask the result
  (verified to fail with the working-directory alignment removed). Skipped
  when ripgrep is not installed.
- New: a shared workspace stays enumerable through the project layer, so
  the boundary does not over-reach into single-tenant deployments.
- `mvn -pl agentscope-harness test`: 1628 tests, 0 failures, 37 skipped
  (Docker, ripgrep and symlink cases that this host cannot run).

Fixes agentscope-ai#4069
ningmao-hlyz added a commit to ningmao-hlyz/agentscope-java that referenced this pull request Nov 10, 2026
## Description

With the default local filesystem, the project layer reaches across
namespaces in three ways:

- Enumeration: `grep(pattern, "")` returns matches from another user's
  `MEMORY.md`, content included; `ls("")` and `glob("**/*.md", "")` list the
  sibling namespaces. The overlay hands the same path to the upper (workspace)
  and lower (project) layers, the default workspace is a subtree of the
  project directory, and the lower layer carries no namespace.
- Direct content access: `read`, `exists`, `edit` (copy-on-write),
  `downloadFiles` and `move` fall back to the lower layer too, so a relative
  path spelling the physical layout - `.agentscope/workspace/alice/MEMORY.md`
  - reads alice's file, and `edit` copies it into the caller's namespace
  before modifying it.
- Absolute paths: the namespace prefix is skipped for absolute spellings, so
  without a boundary the `projectFs` write route would run a delete or move
  against an absolute path inside the workspace subtree.

Previously `LocalFilesystem.resolvePath` passed a blank key to the namespace
prefix unchanged, so it resolved to the workspace root; the physical layout
was reachable whenever the caller named it.

### What changed

- A blank key is resolved as `.` before the namespace is applied, so an
  empty path means "the caller's root" instead of the shared workspace root.
  Deployments without a namespace resolve to the same directory as before.
- `LocalFilesystem` can hide a subtree entirely: enumeration skips it while
  walking, and the content operations - reads, edits, writes, deletes, moves,
  downloads, uploads and existence checks - see nothing there. `delete`
  treats the subtree as absent (an idempotent no-op that never walks it),
  `move` can neither move a file out of or into the subtree, and both `move`
  and recursive `delete` refuse a directory that contains it outright rather
  than partially touch it. Explicitly addressing a hidden subtree as a
  search root yields nothing rather than walking it, and a `walkFileTree`
  visitor that cannot enter a directory skips and continues instead of
  propagating. The check resolves the path first, so a symbolic link that
  points into the subtree is hidden too; `delete` and `move` still act on
  the link entry itself, which never reaches the hidden target. Every
  rejection reads like a missing path, so refusing a hidden path does not
  announce that something is hidden.
- `LocalFilesystemSpec` hides the workspace from the project layers when the
  workspace is a proper subtree of the project and namespace scoping is on -
  both the read-only lower layer and, for the same reason, the `projectFs`
  write route, whose absolute paths skip the namespace prefix. A workspace
  equal to or outside the project has no nesting to hide, a shared workspace
  belongs to every caller equally, and project files outside the workspace
  subtree stay shared, like `AGENTS.md` and `knowledge/`.
- The ripgrep path of `grep` runs rg with its working directory set to the
  search root: `--glob` patterns match against paths relative to the working
  directory, so the excluded-subtree globs missed whenever the parent process
  was started outside the search root. Output paths do not depend on the
  working directory, so entry-path resolution is unaffected.
- `relativeForGlob` compares the first path name instead of the string, so a
  legitimate directory literally named `..cache` is a descendant, not a
  traversal escape.
- `docs/v2/{zh,en}/docs/harness/filesystem.md` note the boundary in the
  Overlay filesystem section, the project-writable read behavior, and the
  mode table.

Absolute paths in the upper (workspace) layer and `..` segments are out of
scope: agentscope-ai#3292 covers the former, agentscope-ai#3378 the latter. Symbolic links are covered
here - the path is resolved before the boundary is applied. The shell keeps its own
project-rooted working directory, so `execute` is not bound by these guards
(agentscope-ai#2329). The `walkFileTree` fallback of `grep` applies the same exclusions
directly.

### Tests

- New: as one user, a blank, relative or glob search sees nothing under
  another user's namespace - in both the default and the writable-project
  construction - and the content operations answer "not found" for a
  sibling namespace spelled through the physical layout, while project
  files outside the workspace and the caller's own namespace stay readable.
- New: a symbolic link planted in the project that points into the
  workspace subtree stays hidden - `read`, `ls` and `write` see nothing
  through it, and the target file is untouched. The case skips on hosts
  that cannot create links.
- New: direct use of the hidden lower layer - `delete` leaves the subtree
  untouched, `move` cannot cross the boundary in either direction, writes
  cannot land inside it (the target does not exist yet, so the assertion
  cannot pass merely because the file is there), and operations that start
  at an ancestor (recursive delete, directory move) are refused outright
  instead of partially touching the hidden subtree. Each of these assertions
  was verified to fail with its guard removed.
- New: the ripgrep path of `grep` keeps the boundary when the parent process
  cwd is unrelated to the search root - the pinned directory is deliberately
  not hidden, so ripgrep's default hidden-file skip cannot mask the result
  (verified to fail with the working-directory alignment removed). Skipped
  when ripgrep is not installed.
- New: a shared workspace stays enumerable through the project layer, so
  the boundary does not over-reach into single-tenant deployments.
- `mvn -pl agentscope-harness test`: 1628 tests, 0 failures, 37 skipped
  (Docker, ripgrep and symlink cases that this host cannot run).

Fixes agentscope-ai#4069
ningmao-hlyz added a commit to ningmao-hlyz/agentscope-java that referenced this pull request Nov 10, 2026
## Description

With the default local filesystem, the project layer reaches across
namespaces in three ways:

- Enumeration: `grep(pattern, "")` returns matches from another user's
  `MEMORY.md`, content included; `ls("")` and `glob("**/*.md", "")` list the
  sibling namespaces. The overlay hands the same path to the upper (workspace)
  and lower (project) layers, the default workspace is a subtree of the
  project directory, and the lower layer carries no namespace.
- Direct content access: `read`, `exists`, `edit` (copy-on-write),
  `downloadFiles` and `move` fall back to the lower layer too, so a relative
  path spelling the physical layout - `.agentscope/workspace/alice/MEMORY.md`
  - reads alice's file, and `edit` copies it into the caller's namespace
  before modifying it.
- Absolute paths: the namespace prefix is skipped for absolute spellings, so
  without a boundary the `projectFs` write route would run a delete or move
  against an absolute path inside the workspace subtree.

Previously `LocalFilesystem.resolvePath` passed a blank key to the namespace
prefix unchanged, so it resolved to the workspace root; the physical layout
was reachable whenever the caller named it.

### What changed

- A blank key is resolved as `.` before the namespace is applied, so an
  empty path means "the caller's root" instead of the shared workspace root.
  Deployments without a namespace resolve to the same directory as before.
- `LocalFilesystem` can hide a subtree entirely: enumeration skips it while
  walking, and the content operations - reads, edits, writes, deletes, moves,
  downloads, uploads and existence checks - see nothing there. `delete`
  treats the subtree as absent (an idempotent no-op that never walks it),
  `move` can neither move a file out of or into the subtree, and both `move`
  and recursive `delete` refuse a directory that contains it outright rather
  than partially touch it. Explicitly addressing a hidden subtree as a
  search root yields nothing rather than walking it, and a `walkFileTree`
  visitor that cannot enter a directory skips and continues instead of
  propagating. The check resolves the path first, so a symbolic link that
  points into the subtree is hidden too; `delete` and `move` still act on
  the link entry itself, which never reaches the hidden target. Every
  rejection reads like a missing path, so refusing a hidden path does not
  announce that something is hidden.
- `LocalFilesystemSpec` hides the workspace from the project layers when the
  workspace is a proper subtree of the project and namespace scoping is on -
  both the read-only lower layer and, for the same reason, the `projectFs`
  write route, whose absolute paths skip the namespace prefix. A workspace
  equal to or outside the project has no nesting to hide, a shared workspace
  belongs to every caller equally, and project files outside the workspace
  subtree stay shared, like `AGENTS.md` and `knowledge/`.
- The ripgrep path of `grep` runs rg with its working directory set to the
  search root: `--glob` patterns match against paths relative to the working
  directory, so the excluded-subtree globs missed whenever the parent process
  was started outside the search root. Output paths do not depend on the
  working directory, so entry-path resolution is unaffected.
- `relativeForGlob` compares the first path name instead of the string, so a
  legitimate directory literally named `..cache` is a descendant, not a
  traversal escape.
- `docs/v2/{zh,en}/docs/harness/filesystem.md` note the boundary in the
  Overlay filesystem section, the project-writable read behavior, and the
  mode table.

Absolute paths in the upper (workspace) layer and `..` segments are out of
scope: agentscope-ai#3292 covers the former, agentscope-ai#3378 the latter. Symbolic links are covered
here - the path is resolved before the boundary is applied. The shell keeps its own
project-rooted working directory, so `execute` is not bound by these guards
(agentscope-ai#2329). The `walkFileTree` fallback of `grep` applies the same exclusions
directly.

### Tests

- New: as one user, a blank, relative or glob search sees nothing under
  another user's namespace - in both the default and the writable-project
  construction - and the content operations answer "not found" for a
  sibling namespace spelled through the physical layout, while project
  files outside the workspace and the caller's own namespace stay readable.
- New: a symbolic link planted in the project that points into the
  workspace subtree stays hidden - `read`, `ls` and `write` see nothing
  through it, and the target file is untouched. The case skips on hosts
  that cannot create links.
- New: direct use of the hidden lower layer - `delete` leaves the subtree
  untouched, `move` cannot cross the boundary in either direction, writes
  cannot land inside it (the target does not exist yet, so the assertion
  cannot pass merely because the file is there), and operations that start
  at an ancestor (recursive delete, directory move) are refused outright
  instead of partially touching the hidden subtree. Each of these assertions
  was verified to fail with its guard removed.
- New: the ripgrep path of `grep` keeps the boundary when the parent process
  cwd is unrelated to the search root - the pinned directory is deliberately
  not hidden, so ripgrep's default hidden-file skip cannot mask the result
  (verified to fail with the working-directory alignment removed). Skipped
  when ripgrep is not installed.
- New: a shared workspace stays enumerable through the project layer, so
  the boundary does not over-reach into single-tenant deployments.
- `mvn -pl agentscope-harness test`: 1628 tests, 0 failures, 37 skipped
  (Docker, ripgrep and symlink cases that this host cannot run).

Fixes agentscope-ai#4069
ningmao-hlyz added a commit to ningmao-hlyz/agentscope-java that referenced this pull request Nov 10, 2026
## Description

With the default local filesystem, the project layer reaches across
namespaces in three ways:

- Enumeration: `grep(pattern, "")` returns matches from another user's
  `MEMORY.md`, content included; `ls("")` and `glob("**/*.md", "")` list the
  sibling namespaces. The overlay hands the same path to the upper (workspace)
  and lower (project) layers, the default workspace is a subtree of the
  project directory, and the lower layer carries no namespace.
- Direct content access: `read`, `exists`, `edit` (copy-on-write),
  `downloadFiles` and `move` fall back to the lower layer too, so a relative
  path spelling the physical layout - `.agentscope/workspace/alice/MEMORY.md`
  - reads alice's file, and `edit` copies it into the caller's namespace
  before modifying it.
- Absolute paths: the namespace prefix is skipped for absolute spellings, so
  without a boundary the `projectFs` write route would run a delete or move
  against an absolute path inside the workspace subtree.

Previously `LocalFilesystem.resolvePath` passed a blank key to the namespace
prefix unchanged, so it resolved to the workspace root; the physical layout
was reachable whenever the caller named it.

### What changed

- A blank key is resolved as `.` before the namespace is applied, so an
  empty path means "the caller's root" instead of the shared workspace root.
  Deployments without a namespace resolve to the same directory as before.
- `LocalFilesystem` can hide a subtree entirely: enumeration skips it while
  walking, and the content operations - reads, edits, writes, deletes, moves,
  downloads, uploads and existence checks - see nothing there. `delete`
  treats the subtree as absent (an idempotent no-op that never walks it),
  `move` can neither move a file out of or into the subtree, and both `move`
  and recursive `delete` refuse a directory that contains it outright rather
  than partially touch it. Explicitly addressing a hidden subtree as a
  search root yields nothing rather than walking it, and a `walkFileTree`
  visitor that cannot enter a directory skips and continues instead of
  propagating. The check resolves the path first, so a symbolic link that
  points into the subtree is hidden too; `delete` and `move` still act on
  the link entry itself, which never reaches the hidden target. Every
  rejection reads like a missing path, so refusing a hidden path does not
  announce that something is hidden.
- `LocalFilesystemSpec` hides the workspace from the project layers when the
  workspace is a proper subtree of the project and namespace scoping is on -
  both the read-only lower layer and, for the same reason, the `projectFs`
  write route, whose absolute paths skip the namespace prefix. A workspace
  equal to or outside the project has no nesting to hide, a shared workspace
  belongs to every caller equally, and project files outside the workspace
  subtree stay shared, like `AGENTS.md` and `knowledge/`.
- The ripgrep path of `grep` runs rg with its working directory set to the
  search root: `--glob` patterns match against paths relative to the working
  directory, so the excluded-subtree globs missed whenever the parent process
  was started outside the search root. Output paths do not depend on the
  working directory, so entry-path resolution is unaffected.
- `relativeForGlob` compares the first path name instead of the string, so a
  legitimate directory literally named `..cache` is a descendant, not a
  traversal escape.
- `docs/v2/{zh,en}/docs/harness/filesystem.md` note the boundary in the
  Overlay filesystem section, the project-writable read behavior, and the
  mode table.

Absolute paths in the upper (workspace) layer and `..` segments are out of
scope: agentscope-ai#3292 covers the former, agentscope-ai#3378 the latter. Symbolic links are covered
here - the path is resolved before the boundary is applied. The shell keeps its own
project-rooted working directory, so `execute` is not bound by these guards
(agentscope-ai#2329). The `walkFileTree` fallback of `grep` applies the same exclusions
directly.

### Tests

- New: as one user, a blank, relative or glob search sees nothing under
  another user's namespace - in both the default and the writable-project
  construction - and the content operations answer "not found" for a
  sibling namespace spelled through the physical layout, while project
  files outside the workspace and the caller's own namespace stay readable.
- New: a symbolic link planted in the project that points into the
  workspace subtree stays hidden - `read`, `ls` and `write` see nothing
  through it, and the target file is untouched. The case skips on hosts
  that cannot create links.
- New: direct use of the hidden lower layer - `delete` leaves the subtree
  untouched, `move` cannot cross the boundary in either direction, writes
  cannot land inside it (the target does not exist yet, so the assertion
  cannot pass merely because the file is there), and operations that start
  at an ancestor (recursive delete, directory move) are refused outright
  instead of partially touching the hidden subtree. Each of these assertions
  was verified to fail with its guard removed.
- New: the ripgrep path of `grep` keeps the boundary when the parent process
  cwd is unrelated to the search root - the pinned directory is deliberately
  not hidden, so ripgrep's default hidden-file skip cannot mask the result
  (verified to fail with the working-directory alignment removed). Skipped
  when ripgrep is not installed.
- New: a shared workspace stays enumerable through the project layer, so
  the boundary does not over-reach into single-tenant deployments.
- `mvn -pl agentscope-harness test`: 1628 tests, 0 failures, 37 skipped
  (Docker, ripgrep and symlink cases that this host cannot run).

Fixes agentscope-ai#4069
…espace-boundary

# Conflicts:
#	agentscope-harness/src/test/java/io/agentscope/harness/agent/filesystem/LocalFilesystemModeTest.java
@mintlify

mintlify Bot commented Nov 11, 2026

Copy link
Copy Markdown

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit cca8aa1.

Approve preview

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ chang6666
❌ ”zhuzhiyu.zzy“


”zhuzhiyu.zzy“ seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@juruoO-o
juruoO-o merged commit 55498cf into agentscope-ai:main Nov 11, 2026
11 of 13 checks passed
ningmao-hlyz added a commit to ningmao-hlyz/agentscope-java that referenced this pull request Nov 11, 2026
With the default local filesystem, the project layer reaches across
namespaces in three ways:

- Enumeration: `grep(pattern, "")` returns matches from another user's
  `MEMORY.md`, content included; `ls("")` and `glob("**/*.md", "")` list the
  sibling namespaces. The overlay hands the same path to the upper (workspace)
  and lower (project) layers, the default workspace is a subtree of the
  project directory, and the lower layer carries no namespace.
- Direct content access: `read`, `exists`, `edit` (copy-on-write),
  `downloadFiles` and `move` fall back to the lower layer too, so a relative
  path spelling the physical layout - `.agentscope/workspace/alice/MEMORY.md`
  - reads alice's file, and `edit` copies it into the caller's namespace
  before modifying it.
- Absolute paths: the namespace prefix is skipped for absolute spellings, so
  without a boundary the `projectFs` write route would run a delete or move
  against an absolute path inside the workspace subtree.

Previously `LocalFilesystem.resolvePath` passed a blank key to the namespace
prefix unchanged, so it resolved to the workspace root; the physical layout
was reachable whenever the caller named it.

- A blank key is resolved as `.` before the namespace is applied, so an
  empty path means "the caller's root" instead of the shared workspace root.
  Deployments without a namespace resolve to the same directory as before.
- `LocalFilesystem` can hide a subtree entirely: enumeration skips it while
  walking, and the content operations - reads, edits, writes, deletes, moves,
  downloads, uploads and existence checks - see nothing there. `delete`
  treats the subtree as absent (an idempotent no-op that never walks it),
  `move` can neither move a file out of or into the subtree, and both `move`
  and recursive `delete` refuse a directory that contains it outright rather
  than partially touch it. Explicitly addressing a hidden subtree as a
  search root yields nothing rather than walking it, and a `walkFileTree`
  visitor that cannot enter a directory skips and continues instead of
  propagating. The check resolves the path first, so a symbolic link that
  points into the subtree is hidden too; `delete` and `move` still act on
  the link entry itself, which never reaches the hidden target. Every
  rejection reads like a missing path, so refusing a hidden path does not
  announce that something is hidden.
- `LocalFilesystemSpec` hides the workspace from the project layers when the
  workspace is a proper subtree of the project and namespace scoping is on -
  both the read-only lower layer and, for the same reason, the `projectFs`
  write route, whose absolute paths skip the namespace prefix. A workspace
  equal to or outside the project has no nesting to hide, a shared workspace
  belongs to every caller equally, and project files outside the workspace
  subtree stay shared, like `AGENTS.md` and `knowledge/`.
- The ripgrep path of `grep` runs rg with its working directory set to the
  search root: `--glob` patterns match against paths relative to the working
  directory, so the excluded-subtree globs missed whenever the parent process
  was started outside the search root. Output paths do not depend on the
  working directory, so entry-path resolution is unaffected.
- `relativeForGlob` compares the first path name instead of the string, so a
  legitimate directory literally named `..cache` is a descendant, not a
  traversal escape.
- `docs/v2/{zh,en}/docs/harness/filesystem.md` note the boundary in the
  Overlay filesystem section, the project-writable read behavior, and the
  mode table.

Absolute paths in the upper (workspace) layer and `..` segments are out of
scope: agentscope-ai#3292 covers the former, agentscope-ai#3378 the latter. Symbolic links are covered
here - the path is resolved before the boundary is applied. The shell keeps its own
project-rooted working directory, so `execute` is not bound by these guards
(agentscope-ai#2329). The `walkFileTree` fallback of `grep` applies the same exclusions
directly.

- New: as one user, a blank, relative or glob search sees nothing under
  another user's namespace - in both the default and the writable-project
  construction - and the content operations answer "not found" for a
  sibling namespace spelled through the physical layout, while project
  files outside the workspace and the caller's own namespace stay readable.
- New: a symbolic link planted in the project that points into the
  workspace subtree stays hidden - `read`, `ls` and `write` see nothing
  through it, and the target file is untouched. The case skips on hosts
  that cannot create links.
- New: direct use of the hidden lower layer - `delete` leaves the subtree
  untouched, `move` cannot cross the boundary in either direction, writes
  cannot land inside it (the target does not exist yet, so the assertion
  cannot pass merely because the file is there), and operations that start
  at an ancestor (recursive delete, directory move) are refused outright
  instead of partially touching the hidden subtree. Each of these assertions
  was verified to fail with its guard removed.
- New: the ripgrep path of `grep` keeps the boundary when the parent process
  cwd is unrelated to the search root - the pinned directory is deliberately
  not hidden, so ripgrep's default hidden-file skip cannot mask the result
  (verified to fail with the working-directory alignment removed). Skipped
  when ripgrep is not installed.
- New: a shared workspace stays enumerable through the project layer, so
  the boundary does not over-reach into single-tenant deployments.
- `mvn -pl agentscope-harness test`: 1628 tests, 0 failures, 37 skipped
  (Docker, ripgrep and symlink cases that this host cannot run).

Fixes agentscope-ai#4069
ningmao-hlyz added a commit to ningmao-hlyz/agentscope-java that referenced this pull request Nov 11, 2026
With the default local filesystem, the project layer reaches across
namespaces in three ways:

- Enumeration: `grep(pattern, "")` returns matches from another user's
  `MEMORY.md`, content included; `ls("")` and `glob("**/*.md", "")` list the
  sibling namespaces. The overlay hands the same path to the upper (workspace)
  and lower (project) layers, the default workspace is a subtree of the
  project directory, and the lower layer carries no namespace.
- Direct content access: `read`, `exists`, `edit` (copy-on-write),
  `downloadFiles` and `move` fall back to the lower layer too, so a relative
  path spelling the physical layout - `.agentscope/workspace/alice/MEMORY.md`
  - reads alice's file, and `edit` copies it into the caller's namespace
  before modifying it.
- Absolute paths: the namespace prefix is skipped for absolute spellings, so
  without a boundary the `projectFs` write route would run a delete or move
  against an absolute path inside the workspace subtree.

Previously `LocalFilesystem.resolvePath` passed a blank key to the namespace
prefix unchanged, so it resolved to the workspace root; the physical layout
was reachable whenever the caller named it.

- A blank key is resolved as `.` before the namespace is applied, so an
  empty path means "the caller's root" instead of the shared workspace root.
  Deployments without a namespace resolve to the same directory as before.
- `LocalFilesystem` can hide a subtree entirely: enumeration skips it while
  walking, and the content operations - reads, edits, writes, deletes, moves,
  downloads, uploads and existence checks - see nothing there. `delete`
  treats the subtree as absent (an idempotent no-op that never walks it),
  `move` can neither move a file out of or into the subtree, and both `move`
  and recursive `delete` refuse a directory that contains it outright rather
  than partially touch it. Explicitly addressing a hidden subtree as a
  search root yields nothing rather than walking it, and a `walkFileTree`
  visitor that cannot enter a directory skips and continues instead of
  propagating. The check resolves the path first, so a symbolic link that
  points into the subtree is hidden too; `delete` and `move` still act on
  the link entry itself, which never reaches the hidden target. Every
  rejection reads like a missing path, so refusing a hidden path does not
  announce that something is hidden.
- `LocalFilesystemSpec` hides the workspace from the project layers when the
  workspace is a proper subtree of the project and namespace scoping is on -
  both the read-only lower layer and, for the same reason, the `projectFs`
  write route, whose absolute paths skip the namespace prefix. A workspace
  equal to or outside the project has no nesting to hide, a shared workspace
  belongs to every caller equally, and project files outside the workspace
  subtree stay shared, like `AGENTS.md` and `knowledge/`.
- The ripgrep path of `grep` runs rg with its working directory set to the
  search root: `--glob` patterns match against paths relative to the working
  directory, so the excluded-subtree globs missed whenever the parent process
  was started outside the search root. Output paths do not depend on the
  working directory, so entry-path resolution is unaffected.
- `relativeForGlob` compares the first path name instead of the string, so a
  legitimate directory literally named `..cache` is a descendant, not a
  traversal escape.
- `docs/v2/{zh,en}/docs/harness/filesystem.md` note the boundary in the
  Overlay filesystem section, the project-writable read behavior, and the
  mode table.

Absolute paths in the upper (workspace) layer and `..` segments are out of
scope: agentscope-ai#3292 covers the former, agentscope-ai#3378 the latter. Symbolic links are covered
here - the path is resolved before the boundary is applied. The shell keeps its own
project-rooted working directory, so `execute` is not bound by these guards
(agentscope-ai#2329). The `walkFileTree` fallback of `grep` applies the same exclusions
directly.

- New: as one user, a blank, relative or glob search sees nothing under
  another user's namespace - in both the default and the writable-project
  construction - and the content operations answer "not found" for a
  sibling namespace spelled through the physical layout, while project
  files outside the workspace and the caller's own namespace stay readable.
- New: a symbolic link planted in the project that points into the
  workspace subtree stays hidden - `read`, `ls` and `write` see nothing
  through it, and the target file is untouched. The case skips on hosts
  that cannot create links.
- New: direct use of the hidden lower layer - `delete` leaves the subtree
  untouched, `move` cannot cross the boundary in either direction, writes
  cannot land inside it (the target does not exist yet, so the assertion
  cannot pass merely because the file is there), and operations that start
  at an ancestor (recursive delete, directory move) are refused outright
  instead of partially touching the hidden subtree. Each of these assertions
  was verified to fail with its guard removed.
- New: the ripgrep path of `grep` keeps the boundary when the parent process
  cwd is unrelated to the search root - the pinned directory is deliberately
  not hidden, so ripgrep's default hidden-file skip cannot mask the result
  (verified to fail with the working-directory alignment removed). Skipped
  when ripgrep is not installed.
- New: a shared workspace stays enumerable through the project layer, so
  the boundary does not over-reach into single-tenant deployments.
- `mvn -pl agentscope-harness test`: 1628 tests, 0 failures, 37 skipped
  (Docker, ripgrep and symlink cases that this host cannot run).

Fixes agentscope-ai#4069
chickenlj pushed a commit that referenced this pull request Nov 13, 2026
… local filesystem (#3292)

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 55498cf)
Backport-review-patch: 6570c9bec31926955fb76740547888b917d8432a
Constraint: No AgentScope Service or SDK migration
Confidence: high
Not-tested: Whole-repository verification pending after lane integration
ningmao-hlyz added a commit to ningmao-hlyz/agentscope-java that referenced this pull request Nov 14, 2026
With the default local filesystem, the project layer reaches across
namespaces in three ways:

- Enumeration: `grep(pattern, "")` returns matches from another user's
  `MEMORY.md`, content included; `ls("")` and `glob("**/*.md", "")` list the
  sibling namespaces. The overlay hands the same path to the upper (workspace)
  and lower (project) layers, the default workspace is a subtree of the
  project directory, and the lower layer carries no namespace.
- Direct content access: `read`, `exists`, `edit` (copy-on-write),
  `downloadFiles` and `move` fall back to the lower layer too, so a relative
  path spelling the physical layout - `.agentscope/workspace/alice/MEMORY.md`
  - reads alice's file, and `edit` copies it into the caller's namespace
  before modifying it.
- Absolute paths: the namespace prefix is skipped for absolute spellings, so
  without a boundary the `projectFs` write route would run a delete or move
  against an absolute path inside the workspace subtree.

Previously `LocalFilesystem.resolvePath` passed a blank key to the namespace
prefix unchanged, so it resolved to the workspace root; the physical layout
was reachable whenever the caller named it.

- A blank key is resolved as `.` before the namespace is applied, so an
  empty path means "the caller's root" instead of the shared workspace root.
  Deployments without a namespace resolve to the same directory as before.
- `LocalFilesystem` can hide a subtree entirely: enumeration skips it while
  walking, and the content operations - reads, edits, writes, deletes, moves,
  downloads, uploads and existence checks - see nothing there. `delete`
  treats the subtree as absent (an idempotent no-op that never walks it),
  `move` can neither move a file out of or into the subtree, and both `move`
  and recursive `delete` refuse a directory that contains it outright rather
  than partially touch it. Explicitly addressing a hidden subtree as a
  search root yields nothing rather than walking it, and a `walkFileTree`
  visitor that cannot enter a directory skips and continues instead of
  propagating. The check resolves the path first, so a symbolic link that
  points into the subtree is hidden too; `delete` and `move` still act on
  the link entry itself, which never reaches the hidden target. Every
  rejection reads like a missing path, so refusing a hidden path does not
  announce that something is hidden.
- `LocalFilesystemSpec` hides the workspace from the project layers when the
  workspace is a proper subtree of the project and namespace scoping is on -
  both the read-only lower layer and, for the same reason, the `projectFs`
  write route, whose absolute paths skip the namespace prefix. A workspace
  equal to or outside the project has no nesting to hide, a shared workspace
  belongs to every caller equally, and project files outside the workspace
  subtree stay shared, like `AGENTS.md` and `knowledge/`.
- The ripgrep path of `grep` runs rg with its working directory set to the
  search root: `--glob` patterns match against paths relative to the working
  directory, so the excluded-subtree globs missed whenever the parent process
  was started outside the search root. Output paths do not depend on the
  working directory, so entry-path resolution is unaffected.
- `relativeForGlob` compares the first path name instead of the string, so a
  legitimate directory literally named `..cache` is a descendant, not a
  traversal escape.
- `docs/v2/{zh,en}/docs/harness/filesystem.md` note the boundary in the
  Overlay filesystem section, the project-writable read behavior, and the
  mode table.

Absolute paths in the upper (workspace) layer and `..` segments are out of
scope: agentscope-ai#3292 covers the former, agentscope-ai#3378 the latter. Symbolic links are covered
here - the path is resolved before the boundary is applied. The shell keeps its own
project-rooted working directory, so `execute` is not bound by these guards
(agentscope-ai#2329). The `walkFileTree` fallback of `grep` applies the same exclusions
directly.

- New: as one user, a blank, relative or glob search sees nothing under
  another user's namespace - in both the default and the writable-project
  construction - and the content operations answer "not found" for a
  sibling namespace spelled through the physical layout, while project
  files outside the workspace and the caller's own namespace stay readable.
- New: a symbolic link planted in the project that points into the
  workspace subtree stays hidden - `read`, `ls` and `write` see nothing
  through it, and the target file is untouched. The case skips on hosts
  that cannot create links.
- New: direct use of the hidden lower layer - `delete` leaves the subtree
  untouched, `move` cannot cross the boundary in either direction, writes
  cannot land inside it (the target does not exist yet, so the assertion
  cannot pass merely because the file is there), and operations that start
  at an ancestor (recursive delete, directory move) are refused outright
  instead of partially touching the hidden subtree. Each of these assertions
  was verified to fail with its guard removed.
- New: the ripgrep path of `grep` keeps the boundary when the parent process
  cwd is unrelated to the search root - the pinned directory is deliberately
  not hidden, so ripgrep's default hidden-file skip cannot mask the result
  (verified to fail with the working-directory alignment removed). Skipped
  when ripgrep is not installed.
- New: a shared workspace stays enumerable through the project layer, so
  the boundary does not over-reach into single-tenant deployments.
- `mvn -pl agentscope-harness test`: 1628 tests, 0 failures, 37 skipped
  (Docker, ripgrep and symlink cases that this host cannot run).

Fixes agentscope-ai#4069
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P0 重要紧急

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]:LocalFilesystemSpec能引导agent读取不同会话窗口的产物

5 participants