Skip to content

fix(harness): classify sandbox-backed overlays for skill shell paths - #2567

Open
jaideeppyne wants to merge 8 commits into
agentscope-ai:mainfrom
jaideeppyne:fix/sandbox-compaction-offload-path
Open

jaideeppyne wants to merge 8 commits into
agentscope-ai:mainfrom
jaideeppyne:fix/sandbox-compaction-offload-path

Conversation

@jaideeppyne

@jaideeppyne jaideeppyne commented Aug 5, 2026 •

Copy link
Copy Markdown

Summary

Main has since removed the transcript-offload path entirely (the compaction redesign now references a logical session_history(...) instead of a host file path), which independently resolves the host-path leak from #2566. After merging main, this PR is narrowed to the remaining sandbox-classification fix:

  • add FilesystemUtils.isSandboxBacked(...), which classifies a filesystem by where new files land (overlay upper layer, routed primary/prefix backend), unwrapping at most eight wrappers and failing closed for deeper chains
  • extract HarnessAgent.Builder.selectShellPathPolicy(...) and use isSandboxBacked so overlays with a sandbox upper layer get ShellPathPolicy.sandbox(...) instead of falling through to noShell()
  • add HarnessAgentShellPathPolicyTest and FilesystemUtilsTest coverage

Related: #2566.

Validation

  • mvn -pl agentscope-harness -am test on the harness filesystem/agent test classes: 107 tests, 0 failures (including HarnessAgentShellPathPolicyTest, FilesystemUtilsTest, CompositeFilesystemTest, HarnessAgentTest)
  • mvn -q -pl agentscope-harness spotless:check: passed

Risk and rollback

Behaviour changes only for sandbox-backed overlay/routed filesystems when choosing the skill shell-path policy. Local filesystems keep localWithShell. No public API or persisted format changes; reverting restores the previous policy selection.

Since the scope changed after approval, a quick re-look would be appreciated.

I used a coding agent to help write and verify this change.

@CLAassistant

CLAassistant commented Aug 5, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@codecov

codecov Bot commented Aug 5, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 78.57143% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...harness/agent/filesystem/util/FilesystemUtils.java 75.00% 1 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@jaideeppyne

Copy link
Copy Markdown
Author

Rebase complete (conflict resolved)

Rebased onto latest main after upstream refactored resolveOffloadPath to delegate to SessionTranscriptWriter#resolveContextPath.

Resolution

  • Keep sandbox guard: if filesystem is AbstractSandboxFilesystem, return "" (do not advertise host path).
  • Otherwise delegate to SessionTranscriptWriter (matches current main).
  • Local-path test now expects the workspace-relative path returned by SessionTranscriptWriter (agents/agent-a/sessions/session-1.jsonl).

Evidence

  • mvn -pl agentscope-harness -am -Dtest=MemoryFlushManagerOffloadTest -Dsurefire.failIfNoSpecifiedTests=false test → 5 tests, 0 failures
  • mvn -q -pl agentscope-harness spotless:check → passed

@jaideeppyne
jaideeppyne force-pushed the fix/sandbox-compaction-offload-path branch 2 times, most recently from aab9675 to 69f07a8 Compare August 6, 2026 10:41
@jaideeppyne

Copy link
Copy Markdown
Author

Conflict resolution status

Conflict with main is real: resolveOffloadPath was refactored on main to delegate to SessionTranscriptWriter#resolveContextPath.

A rebased fix is ready locally and validated:

mvn -pl agentscope-harness -am -Dtest=MemoryFlushManagerOffloadTest \
  -Dsurefire.failIfNoSpecifiedTests=false test
# Tests run: 5, Failures: 0
mvn -q -pl agentscope-harness spotless:check  # passed

Resolution shape (on top of current main):

public String resolveOffloadPath(RuntimeContext rc, String agentId, String sessionId) {
    if (workspaceManager.getFilesystem() instanceof AbstractSandboxFilesystem) {
        return "";
    }
    return new SessionTranscriptWriter(workspaceManager)
            .resolveContextPath(rc, agentId, sessionId);
}

Local-path test expects workspace-relative path agents/agent-a/sessions/session-1.jsonl.

Push blocked: OAuth token lacks workflow scope, and rebasing onto main updates .github/workflows/*, which GitHub rejects without that scope. Branch tip remains the last green commit until a token with workflow can force-push the rebase (or conflict is resolved in the GitHub UI).

@jaideeppyne
jaideeppyne force-pushed the fix/sandbox-compaction-offload-path branch from 69f07a8 to 2ea4891 Compare August 6, 2026 11:15
@jaideeppyne

Copy link
Copy Markdown
Author

Rebased and force-pushed

Conflict with main resolved and branch updated.

Resolution

  • Sandbox filesystems: resolveOffloadPath returns "" (do not advertise host path)
  • Local filesystems: delegate to SessionTranscriptWriter#resolveContextPath (workspace-relative path)

Local validation

  • mvn -pl agentscope-harness -am -Dtest=MemoryFlushManagerOffloadTest -Dsurefire.failIfNoSpecifiedTests=false test → 5 tests, 0 failures
  • mvn -q -pl agentscope-harness spotless:check → passed

@jaideeppyne
jaideeppyne marked this pull request as ready for review August 6, 2026 11:20

@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

This PR modifies 2 files with 74 lines of diff.

Observations

  • Files changed: 2
  • Test coverage: ✅ Tests included
  • CLA: ✅ Signed

Suggestions

  • Please ensure all public API changes are backward compatible
  • Consider adding unit tests for new logic paths

Automated review by github-manager-bot

@AgentScopeJavaBot AgentScopeJavaBot added bug Something isn't working area/harness agentscope-harness (test/runtime support) labels Aug 11, 2026
@jaideeppyne

Copy link
Copy Markdown
Author

Thanks for the review. To confirm on the two suggestions: the change is backward compatible — resolveOffloadPath keeps its signature and only changes what it returns for sandbox filesystems (an empty string, so no host path is advertised) while local filesystems delegate to the existing SessionTranscriptWriter#resolveContextPath; no public API changes. Unit coverage for the new logic paths is included (MemoryFlushManagerOffloadTest, covering both the sandbox and local cases). Glad to expand it further if you'd like additional cases.

@AgentScopeJavaBot AgentScopeJavaBot 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.

🤖 AI Review

This PR adds a sandbox-aware guard to the deprecated MemoryFlushManager.resolveOffloadPath method, returning an empty string when the workspace filesystem is backed by a sandbox. The intent is correct: sandboxed agents cannot resolve host-side workspace paths, so advertising them in the compaction summary prompt is misleading. The fix is minimal, well-commented, and includes two unit tests covering both the sandbox and local-filesystem paths. However, the guard is applied only to the deprecated method — the recommended replacement (SessionTranscriptWriter.resolveContextPath) has no equivalent protection, creating a migration hazard.

@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

Delta re-review after 42e8ba7b (propagate the guard into SessionTranscriptWriter). The direction is right — a host-side archive path is not resolvable from inside a container, and advertising it in the compaction summary sends sandboxed agents chasing a file they cannot open. But the chosen predicate, getFilesystem() instanceof AbstractSandboxFilesystem, is a shell-capability marker rather than an isolation marker, so it also matches the plain local-with-shell workspace (LocalFilesystemSpec → ShellAwareOverlay/ProjectAwareOverlay), where the path is host-readable. That is flagged inline as the one blocking point; two smaller ones follow.

Verdict

COMMENT — one over-match to settle before merge (SessionTranscriptWriter.java:175); the rest is non-blocking. CLA signed, tests included for both branches of the new rule.

@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

Delta re-review after 42e8ba7b → 851d9ff7 (distinguish sandbox storage from local shell overlays). The motivation is correct and my previous blocking point is fixed: LocalFilesystemWithShell implements AbstractSandboxFilesystem purely as a shell-capability marker, so the old interface check hid a host-readable path from local-dev workspaces that can resolve it fine, and the two new OverlayFilesystem.of(...) test cases pin that behaviour properly. Removing the duplicated guard from the deprecated MemoryFlushManager.resolveOffloadPath in favour of the single delegate is also the right consolidation.

One issue holds this back: the replacement predicate is now too narrow in the opposite direction. RoutedSandboxFilesystem implements AbstractSandboxFilesystem without extending BaseSandboxFilesystem, and HarnessAgent uses it as the workspace filesystem for any sandboxed agent that declares file routes — so for sandbox + filesystemRoutes the host-side archive path is advertised to the agent again, which is the leak this PR was written to plug. The repo already solves this shape twice (HarnessAgent shell-policy selection and WorkspaceManager.taskRecordsRouteToLiveSandbox both unwrap RoutedSandboxFilesystem.primary() / .backendFor(...)), so I have suggested a shared sandboxBacked(...) predicate instead of a fourth hand-rolled instanceof chain.

Findings

  • [Warning] SessionTranscriptWriter.java:174 — instanceof BaseSandboxFilesystem misses RoutedSandboxFilesystem (and OverlayFilesystem.ShellAwareOverlay), re-advertising the host path for sandboxed agents with file routes; suggest one shared unwrapping predicate
  • [Info] MemoryFlushManagerOffloadTest.java:62 — the local-overlay branch is now covered, but the routed-sandbox branch (the case that regressed) has no test, which is why the narrowing is green

Verdict

COMMENT — non-blocking on its own if you can confirm filesystemRoutes + sandbox is not a supported combination for HarnessAgent; if it is, the unwrapping helper is a small change and the missing test would have caught it. CLA signed (license/cla=success on 851d9ff7), CI green on this head (ubuntu + windows + codecov/patch).


Automated review by github-manager-bot

@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

Delta re-review after 851d9ff7 → 389685ce ("classify wrapped sandbox filesystems consistently"). The blocking point from the previous round is resolved: FilesystemUtils.isSandboxBacked now unwraps RoutedSandboxFilesystem.primary() and OverlayFilesystem.getUpper(), so a routed sandbox with file routes is no longer classified as host-readable, and the predicate is shared with the HarnessAgent shell-policy branch instead of being re-derived per call site. The routed case is also pinned by resolveOffloadPath_omitsHostPathForRoutedSandboxFilesystem. CI is green on ubuntu + windows and CLA is signed.

What is left is a scope question rather than a correctness bug: the guard suppresses the pointer for the common case too. resolveContextPath returns a workspace-relative path whenever the archive is under the workspace, and SessionTree.scheduleMirror() uploads exactly that relative path into the live (sandbox) filesystem — so a sandboxed agent can open it, while only the absolute-path fallback is genuinely unresolvable. Flagged inline with two ways to settle it. Two smaller points follow: route-awareness of primary() versus backendFor(relPath), and the HarnessAgent branch, which is a behavior change that arrives without a test.

Verdict

COMMENT — no blocking defect found; the four inline points are about narrowing the suppression and covering the HarnessAgent classification change. CLA signed, so this stays a comment rather than an approval only because the first point is a real behavior question for the author to answer.


Automated review by github-manager-bot

@jaideeppyne

Copy link
Copy Markdown
Author

Follow-up on the 2026-09-19 review, in 74e077b:

  1. Offload-path suppression is only the absolute host fallback. A workspace-relative archive is still returned for sandbox-backed filesystems, because SessionTree mirrors that path into the sandbox.
  2. FilesystemUtils.isSandboxBacked(fs, relPath) resolves RoutedSandboxFilesystem.backendFor(relPath) before unwrapping overlays. SessionTranscriptWriter passes the session-relative path, so an agents/ route onto a non-sandbox backend keeps the pointer.
  3. The unwrap loop is capped at 8 and returns false if the cap is hit. Javadoc records that the overlay upper layer decides where new files land.
  4. HarnessAgent.Builder.selectShellPathPolicy is covered by HarnessAgentShellPathPolicyTest. OverlayFilesystem.of(sandboxUpper, localLower) selects ShellPathPolicy.sandbox(wsPrefix) instead of the old trailing noShell branch.

Focused Maven run: SessionTranscriptWriterTest, MemoryFlushManagerOffloadTest, HarnessAgentShellPathPolicyTest — 22 tests, 0 failures. Spotless check passed.

jaideeppyne and others added 5 commits September 30, 2026 07:31
…lveContextPath

The deprecated MemoryFlushManager.resolveOffloadPath now hides the
host-side offload path from sandboxed agents, but its recommended
replacement, SessionTranscriptWriter.resolveContextPath, still resolved
and returned that host path unconditionally. Callers migrating to the
recommended method would lose the protection.

Propagate the same AbstractSandboxFilesystem guard to
resolveContextPath so it returns an empty string for sandbox-backed
filesystems, and add parallel SessionTranscriptWriterTest coverage for
both the sandbox (empty) and local (reachable path) cases.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Hide only the absolute host fallback from sandboxed agents. Classify a
session path by the backend that serves it, and test overlay-sandbox
shell-policy selection directly.
@jaideeppyne

Copy link
Copy Markdown
Author

Rebased onto current main after the review follow-up conflicted in HarnessAgent shell-policy selection. The tool-filter gate from main is kept (ShellExecuteTool must be allowed), and the filesystem classification still goes through selectShellPathPolicy. Also dropped a duplicated CompositeFilesystem.filesystemFor that the rebase had auto-merged twice.

mvn -pl agentscope-harness -am -Dtest=SessionTranscriptWriterTest,MemoryFlushManagerOffloadTest,HarnessAgentShellPathPolicyTest test passes. HEAD is 3a8b8b60a8ffb96f5d068d73deef2ff5464b44e6.

@jaideeppyne
jaideeppyne force-pushed the fix/sandbox-compaction-offload-path branch from 74e077b to 3a8b8b6 Compare September 30, 2026 02:06

@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

Delta re-review of 389685ce → 3a8b8b60a8 (commits 3ac00709, ad0c3be0, 4839310b, 5ea4a20b, 3a8b8b60). All three inline points from the previous round are settled. 3a8b8b60a resolves the main scope question: SessionTranscriptWriter.resolveContextPath now keeps the workspace-relative pointer whenever the archive sits under the workspace (which SessionTree.scheduleMirror() uploads into the live filesystem, so a sandboxed agent can open it) and hides only the absolute host fallback, and only when the backend that serves the session path is sandbox-backed — exactly the narrower guard the previous review asked for. The same commit adds a route-aware FilesystemUtils.isSandboxBacked(filesystem, relPath) overload that resolves backendFor(relPath) for routed filesystems, and extracts HarnessAgent.Builder.selectShellPathPolicy with direct coverage in the new HarnessAgentShellPathPolicyTest, which also pins the previously untested behavior change (overlay with sandbox upper now selects ShellPathPolicy.sandbox instead of falling through to noShell — correct, since ShellAwareOverlay runs execute on the sandbox). No blocking defect found in this delta; one info-level note remains on the depth-cap fail-open in the classifier.

Delta vs previous review

  • Resolved — common-case pointer suppression. resolveContextPath (SessionTranscriptWriter.java:175-198) returns the relative path when file is under the workspace before any sandbox classification, and suppresses only the absolute file.toString() fallback. The mirror claim is verified in code: SessionTree.scheduleMirror() uploads the context file at its workspace-relative path via uploadFiles into the live filesystem, and the un-namespaced relative path built by the new sessionContextRelativePath helper matches the convention already used in SessionTranscriptWriter.appendMessages (lines 94-102), so the advertised pointer is the path the mirror actually writes. Downstream is safe too: ConversationCompactor maps a blank result to null (no file reference).
  • Resolved — primary() vs backendFor(relPath). The transcript guard uses the route-aware overload; the HarnessAgent shell-policy branch intentionally keeps the non-route-aware form, which is consistent because RoutedSandboxFilesystem.execute always delegates to primary().
  • Resolved — untested HarnessAgent classification change. selectShellPathPolicy is a faithful extraction (the literal false at the call site is safe because shellToolAvailable already implies !disableShellTool), and HarnessAgentShellPathPolicyTest covers sandbox overlay, routed primary, local-shell overlay, and disabled-shell cases against ShellPathPolicy.resolve's actual formats.
  • Non-blocking note: the relative pointer can dangle transiently if the fire-and-forget mirror upload has not completed when the agent follows the reference — that race is inherited from the pre-existing async mirror design, not introduced by this round.

Findings

  • agentscope-harness/src/main/java/io/agentscope/harness/agent/filesystem/util/FilesystemUtils.java:73 (info) — Depth cap fails open: >8 wrappers (or a cycle) classify as not sandbox-backed, which would re-expose the absolute host fallback to a sandboxed agent; documented and unreachable at current wrap depths, but the cap's outcome is untested.

Verification

  • Read at HEAD: FilesystemUtils, SessionTranscriptWriter (+ appendMessages convention), MemoryFlushManager (net diff vs base 9b611928e is empty — the interim guard was added then removed cleanly), RoutedSandboxFilesystem (primary/backendFor), CompositeFilesystem (the delta there is pure code motion of RouteEntry/RouteResult below filesystemFor), OverlayFilesystem.of/ShellAwareOverlay, HarnessAgent builder region (extracted policy + call site), ShellPathPolicy, ConversationCompactor (blank → null handling), SessionTree.scheduleMirror/mirrorToFilesystem, WorkspaceManager.resolveSessionContextFile/getSessionDir, and WorkspaceConstants.
  • Type hierarchy confirmed: SandboxBackedFilesystem extends BaseSandboxFilesystem; RoutedSandboxFilesystem implements AbstractSandboxFilesystem but not BaseSandboxFilesystem, so the unwrap in isSandboxBacked is required and present.
  • Ran mvn -T1 -pl agentscope-harness -am test -Dtest='MemoryFlushManagerOffloadTest,SessionTranscriptWriterTest,HarnessAgentShellPathPolicyTest': 22 tests, 0 failures, BUILD SUCCESS. Did not run the full module suite or spotless:check.

Automated review by github-manager-bot

@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

Delta re-review of 3a8b8b60 → d54aeb84 (single commit "fail closed at filesystem depth limit", FilesystemUtils.java +3/-3 plus a new FilesystemUtilsTest).

The last open finding from the previous round is resolved exactly as suggested: isSandboxBacked() now returns true when the unwrap loop exceeds the 8-wrapper depth cap, so a cyclic or unexpectedly deep filesystem composition can no longer be misclassified as host-readable and leak an absolute host offload path into a sandbox agent's context. The javadoc was updated to match, and the new test pins both sides of the boundary (7-deep overlay chain → not sandbox-backed; 8th overlay → sandbox-backed).

Trade-off acknowledged: a genuinely deep non-sandbox chain (>8) will now be classified as sandbox-backed and lose the host archive-path hint — a fail-closed default that is clearly the right way round for a path-exposure guard.

All earlier inline points (depth-bound, wrapped-sandbox classification, resolveContextPath scope) were already settled in prior rounds. CLA: signed per CLAassistant ("All committers have signed the CLA"); the license/cla status is simply re-pending on the new commit. CI green on head (license, module-sync, ubuntu/windows builds, codecov).

LGTM — approved.


Automated review by github-manager-bot

…fload-path

# Conflicts:
#	agentscope-harness/src/main/java/io/agentscope/harness/agent/HarnessAgent.java
#	agentscope-harness/src/main/java/io/agentscope/harness/agent/memory/session/SessionTranscriptWriter.java
#	agentscope-harness/src/test/java/io/agentscope/harness/agent/memory/MemoryFlushManagerOffloadTest.java
#	agentscope-harness/src/test/java/io/agentscope/harness/agent/memory/session/SessionTranscriptWriterTest.java
@jaideeppyne jaideeppyne changed the title fix(harness): hide host offload path from sandbox agents fix(harness): classify sandbox-backed overlays for skill shell paths Oct 11, 2026
Keep sandbox-backed overlay classification on the current skill shell
policy. isSandboxBacked still walks overlays and routes, and a chain
deeper than eight wrappers fails closed.
@jaideeppyne

Copy link
Copy Markdown
Author

Updated this branch onto the latest main.

skillShellPolicy now classifies sandbox-backed overlays through FilesystemUtils.isSandboxBacked, including the depth-limit fail-closed walk. Host-shell overlays stay on the local shell policy.

FilesystemUtilsTest, HarnessAgentShellPathPolicyTest, and HarnessAgentFilesystemRoutesShellTest passed (39 tests).

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

area/harness agentscope-harness (test/runtime support) bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants