Skip to content

fix(harness): keep projected sandbox definitions host-authoritative - #3417

Open
lzyruc wants to merge 2 commits into
agentscope-ai:mainfrom
lzyruc:fix/sandbox-host-authoritative-definitions
Open

lzyruc wants to merge 2 commits into
agentscope-ai:mainfrom
lzyruc:fix/sandbox-host-authoritative-definitions

Conversation

@lzyruc

@lzyruc lzyruc commented Oct 4, 2026 •

Copy link
Copy Markdown

AgentScope-Java Version

2.0.4-SNAPSHOT, based on main at 9e43ed8.

Description

Fixes #3388.

Sandbox modifications to projected definitions could persist in snapshots and enter the next call's system prompt or skill catalog. Projection also skipped hydration when the host hash was unchanged, without checking whether the sandbox copy had been modified.

This PR makes configured projection roots host-authoritative for workspace context, skills and their resources, and subagent declarations. Before skipping hydration, projection now verifies the current sandbox files. Divergence or failed verification triggers rehydration from the host.

Default projection roots remain unchanged. Default MEMORY.md retains its existing runtime reads, writes, and persistence. Explicitly projected MEMORY.md receives the same protection as other projected definitions. Ordinary sandbox files and shell execution remain writable.

Adds .hostAuthoritativeDefinitions(false) to restore legacy behavior, with matching English and Chinese documentation.

Host-authored user skill overrides retain the configured isolation namespace and take precedence over shared host skills; sandbox-authored overrides beneath owned roots remain excluded. This namespace view is limited to skill repositories, including skill management. Host reads validate paths, and failed definition globs retain their error status.

Unsupported hashing utilities are detected and warned about once per sandbox instance; verification remains fail-closed with hydration on each start. Verification interruptions restore the interrupt flag. Migration and explicitly projected MEMORY.md behavior are clarified in EN/ZH documentation, and projected memory emits a configuration warning.

Validation:

  • Regression tests failed on unmodified main before the fix.
  • Focused regression classes in the final full run: 32 passed (9 added in the review follow-up).
  • Full Harness test run: 1114 tests, 0 failures, 0 errors, 18 skipped (1096 passed).
  • Spotless and git diff --check: passed.
  • Documentation tests: 12 passed.
  • Documentation static checks and Mintlify build validation: passed.

Cross-call regression tests use a local fake sandbox backend with actual Harness calls and tar snapshot persistence/restoration, covering USER, AGENT, and GLOBAL isolation. No live model or container backend was used.

Full repository clean verify was attempted but stopped in two unchanged Core tests because this Windows environment lacks symlink privileges. Mintlify's local broken-links check also fails on unmodified main; the four additional anchor links in this PR pass the repository static checker and build validation.

Checklist

Please check the following items before code is ready to be reviewed.

  • Code has been formatted with mvn spotless:apply
  • All tests are passing (mvn test) — the published commit passed Ubuntu and Windows CI. This follow-up passes the full Harness suite locally; local full-repository verification is still blocked by the two existing Windows symlink cases. CI for the follow-up is pending.
  • Javadoc comments are complete and follow project conventions
  • Related documentation has been updated (e.g. links, examples, etc.)
  • Code is ready for review

@CLAassistant

CLAassistant commented Oct 4, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@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

Nice, well-documented fix for #3388 — making projected definitions host-authoritative and verifying the live sandbox copy before skipping hydration closes both halves of the problem (sandbox edits entering the trusted catalog, and host-hash-only checks trusting a stale copy). The opt-out flag, the EN/ZH doc updates and the cross-call tamper regression tests (USER/AGENT/GLOBAL, real tar snapshot round-trips) are all in good shape, and CI is green on ubuntu + windows with CLA signed.

I am leaving this as a COMMENT (not an approval) because of a few questions around the verification fast path, path normalization in the new host branch, and how the new default interacts with the documented per-user skills/ precedence — none of them look like blockers, but they are worth confirming before merge.

What reads well

  • Fail-closed verification: any exec/parse/timeout failure forces rehydration instead of trusting the recorded hash.
  • hostAuthoritativeDefinitions(false) + narrowing workspaceProjectionRoots(...) give a clean migration path, and WorkspaceProjectionEntry keeps secure-by-default deserialization for legacy persisted specs (covered by the new round-trip test).
  • Explicit .filesystem(prefix, backend) routes are kept ahead of host ownership, which preserves existing multi-backend setups.
  • Default MEMORY.md semantics are untouched; the 4-branch workspace start logic is not restructured.

Main points (details inline)

  1. WorkspaceProjectionApplier.matchesSandbox — images without sha256sum/test (distroless, Windows containers) can never pass verification, which silently turns "skip transfer" into "re-hydrate every start"; distinguishing "unsupported" from "diverged" (plus a single WARN) would keep the security default without the hidden performance cliff. Batching also puts N sequential exec() calls on the start path.
  2. WorkspaceManager.readWithOverride — the host branch resolves the raw relativePath while owns() compares a normalized form, and skips the containment guard that the rest of the class uses (readManagedWorkspaceFileUtf8, appendLocalFile). Reusing requireSafeRelativePath(...) would keep the two in sync.
  3. WorkspaceDefinitionAuthority — the host LocalFilesystem is created without a NamespaceFactory, so an owned root like skills answers reads for the Layer-4 <userId>/skills/ logical path from the shared host directory. If that is intended, skill.md's "whichever mode you run, <userId>/skills/ overrides the shared version" (EN + ZH) should carry the sandbox-mode exception. maxFileSizeMb/virtualMode are also hardcoded here rather than inherited from the primary filesystem.
  4. WorkspaceDefinitionAuthority.glob always returns success; when both sources fail the catalog looks empty rather than errored.
  5. Minor: double host-tree walk in build(), and catch (Exception) swallowing interrupt status/absence of the diverging file in the log.

Questions

  • Is the loss of per-user (<userId>/skills/) overrides under an owned root a deliberate part of this security change, and should it be called out in the release notes alongside the new default?
  • Should MEMORY.md be rejected (or warned about) when a caller adds it to workspaceProjectionRoots while host authority is on, given memory writes still go to the runtime filesystem?

Author validation notes are thorough and honest (noting the mvn test checklist item and the Windows symlink limitation). Since CI passes on both ubuntu and windows, could you tick or annotate the "All tests are passing" checklist item so the state of the full suite is unambiguous for the next reviewer?

Thanks for the contribution, @lzyruc — this is a substantial hardening change and the regression coverage around it is already strong.


Automated review by github-manager-bot

}

Map<String, Path> projectedFiles = collectProjectedFiles(entries);
var authoritativePaths =

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] collectProjectedFiles(...) is now invoked twice per projection build (once for all entries, once filtered by isHostAuthoritativeDefinitions), which walks the host tree twice on every start. Consider collecting once and tagging each entry with its authority flag (e.g. return Map<String, AuthoritativePath> or collect per-entry in the existing loop) — same result, half the traversal, and it keeps authoritativePaths and projectedFiles from drifting if the two calls ever diverge in ordering/dedup rules.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks for the suggestion. I’ve left the two traversals unchanged in this update to keep the review follow-up focused on correctness and diagnostics. Collecting once would be a useful optimization, but hasn’t been implemented here.

@lzyruc

lzyruc commented Oct 4, 2026

Copy link
Copy Markdown
Author

Thanks for the detailed review. I’ll check the path normalization and per-user namespace handling, tighten the error propagation, and improve diagnostics when live verification is unavailable while keeping the fail-closed behavior. I’ll also clarify the projected MEMORY.md behavior and update the EN/ZH documentation and test checklist to reflect the passing CI runs.

@lzyruc

lzyruc commented Oct 4, 2026

Copy link
Copy Markdown
Author

Thanks for the detailed review! I’ve pushed the follow-up changes and replied to the individual threads. The full Harness suite passed locally: 1,096 passed and 18 skipped. Spotless and documentation validation also passed. I’ve left the double-traversal optimization unchanged for now. Please take another look when you have time.

@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 the delta since c2530a3c (8f614141). All five points from my previous round are addressed, and the fixes are the ones I would have written:

  1. Unsupported vs. diverged — WorkspaceProjectionApplier now probes for sha256sum/test on the first batch and raises UnsupportedVerificationException; AbstractBaseSandbox latches projectionVerificationUnsupported so an image without the tools rehydrates once per sandbox lifetime with a single WARN instead of failing verification on every start. Fail-closed behaviour is preserved.
  2. Path handling — readWithOverride now goes through requireSafeRelativePath(...) plus the explicit startsWith(workspace) containment check, so the host branch can no longer drift from the rest of the class.
  3. Per-user overrides under owned roots — WorkspaceDefinitionAuthority.withNamespace(...) + OverlayFilesystem (namespaced LocalFilesystem upper, shared host lower) keeps host-authored <userId>/skills/ ahead of the shared copy while still excluding sandbox-written definitions, and skill.md (EN + ZH) now states the sandbox-mode exception instead of claiming uniform precedence. That closes the doc/behaviour mismatch I asked about.
  4. Error surfacing — glob() returns a failure when both the host and the runtime enumeration fail, so an unavailable backend no longer looks like an empty catalog. FileInfo paths are also normalized before being returned, which keeps the map keys and the reported paths consistent.
  5. Interrupt status — InterruptedException is caught separately and the interrupt flag is restored instead of being swallowed by the generic handler.

The new MEMORY.md warning also answers the second question from the last round: the projection now tells the operator that memory writes stay on the runtime filesystem, rather than silently pretending host authority covers it.

Two Info notes inline; neither affects correctness. Verified locally against the branch: withNamespace/OverlayFilesystem.of(upper, lower) arity matches the existing APIs, LocalFsMode/PathPolicy resolve from the same package, and GlobResult.fail(String) exists, so this compiles without new plumbing. CLA signed (license/cla: success); validate, Check License, Check Module Sync and build (ubuntu-latest) are green — build (windows-latest) was still in flight at review time, which is a merge gate rather than a review blocker.

Thanks for the thorough turnaround, @lzyruc — approving.


Automated review by github-manager-bot

protected abstract String getWorkspaceRoot();

private boolean projectionMatchesSandbox(WorkspaceProjectionApplier.ProjectionPayload payload) {
if (payload.fileHashes().isEmpty()) return 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.

[Info] fileHashes().isEmpty() -> return true is correct (the aggregate payload.hash() still gates the skip), but the condition reads like 'no authoritative files means no verification was possible'. A one-line comment — nothing host-authoritative to verify, the tar hash alone decides — would save the next reader the detour through build().

List<Map.Entry<String, String>> batch =
files.subList(start, Math.min(start + 64, files.size()));
StringBuilder command = new StringBuilder();
if (start == 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] The probe runs only on the first batch (start == 0), so an image that has sha256sum but is missing test on a later batch would still be reported as a plain mismatch instead of unsupported. Both usually come from the same coreutils/shell, so this is fine — noting it only so the asymmetry reads as deliberate.

This branch has not been deployed

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

Labels

P2 重要不紧急

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: In sandbox mode, shell writes to AGENTS.md / skills/ / MEMORY.md override host definitions and persist across calls

4 participants