Skip to content

fix(harness): session mirror pins the owning call's sandbox instead of the agent-level slot (#4273) - #4447

Merged
jujn merged 2 commits into
agentscope-ai:2.0.xfrom
aiyili:fix/session-mirror-pin-own-sandbox
Nov 29, 2026
Merged

jujn merged 2 commits into
agentscope-ai:2.0.xfrom
aiyili:fix/session-mirror-pin-own-sandbox

Conversation

@aiyili

@aiyili aiyili commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #4273

Problem

In sandbox mode the session log and context files are mirrored into the agent's filesystem, and so are transcript segments. The mirror is scheduled while the call runs and performed afterwards on a separate thread, which means the sandbox it writes to has to be decided at scheduling time.

SessionTree.pinIfSandbox took that sandbox from the agent-level slot of the shared SandboxBackedFilesystem proxy. One agent bean has one such proxy and its slot is last-writer-wins:

  1. Alice's call acquires its sandbox.
  2. Bob's call acquires; the slot now names bob's sandbox.
  3. Alice's call writes its session log and schedules the mirror. The fallback slot is read, so bob's sandbox is pinned.
  4. Alice's call releases.
  5. The mirror runs and writes alice's files into bob's sandbox.

Bob can then read alice's session log from inside his own sandbox, and with snapshots enabled the file is persisted with bob's. Alice's own copy is missing the update.

Fix

mirrorTarget pins the sandbox bound to the owning call on its RuntimeContext. SessionTree already held that context for its remote operations, and SandboxLifecycleMiddleware binds the call's sandbox on it, so no new plumbing is needed. The pin keeps its purpose — the upload still reaches the call's sandbox after the call has released — and now addresses the right sandbox.

When the owning call has no sandbox bound there is no target and the mirror is skipped. The alternative, falling back to the shared slot, is exactly the path that writes into another user's sandbox. The mirror is best-effort already: before this change that case ended in a failed upload or in another user's sandbox.

Transcript segments are only affected when the store is an ObjectStoreTranscriptStore, since only that store writes through the filesystem.

What this does not change

SandboxBackedFilesystem.requireSandbox still falls back to the shared slot for callers that have no per-call context, such as WorkspaceMessageBus. That is the same slot under a different caller and is what #2849 is about.

Tests

SessionTreeMirrorIsolationTest (new, 3 cases) uses the real SandboxLifecycleMiddleware with a proxy shared by two calls, and sandboxes that record every file transferred into them:

  • alice's session files reach alice's sandbox and none reach bob's, when bob acquires after alice;
  • the same for alice's transcript segment;
  • a call that has no sandbox of its own mirrors nowhere, while another call's sandbox is the one the shared slot points at.

On 2.0.x before the change all three fail, with alice's files listed under /ws-bob/. With a variant that still falls back to the shared slot when no sandbox is bound, only the third fails.

Verification

SessionTreeMirrorTest (7), SessionTranscriptWriterTest (4) and the new test (3) pass on Windows and on Linux; Spotless is clean.

The full agentscope-harness suite was run before and after the change in the same environment. The failing list is identical, and the three added cases are the only difference:

Environment Before After Failing in both
Windows host 1619 run, 5 F + 12 E 1622 run, 5 F + 12 E Windows path checks (Sandbox workspace root must be an absolute path) and MemoryConsolidatorCommitGateTest
Linux container (maven:3.9-eclipse-temurin-17) 1619 run, 3 F + 1 E 1622 run, 3 F + 1 E 3 × BaseSandboxFilesystemTest.edit_* (python3: not found in the image), MarketplaceStagerOrphanGcTest.unreadableEntryDoesNotFailStage

None of the pre-existing failures involves session mirroring.

One of three Windows runs of the fixed tree also failed HarnessAgentTest.sandboxWithArtifactDeliveryTargetAndDisabledFilesystemTools_promptOmitsDeliverTool. It checks the sandbox workspace root on Windows, does not go through SessionTree mirroring, and passed in the Linux run and in the other two Windows runs.

CI. The first run of this PR was red for reasons that lay in the base branch: since the backports of 2026-11-13, every PR against 2.0.x failed the Windows job, at first in agentscope-core, and had its Ubuntu job cancelled. Those causes are fixed by #4454 and #4461, merged into 2.0.x on 2026-11-27; the harness part went in with #4461. The current run of this PR, on top of them, is green on both systems. The local before/after runs recorded above were made before the fixes existed, which is why the "before" column lists failures that the branch no longer has.

…f the agent-level slot (agentscope-ai#4273)

The asynchronous session mirror is scheduled while a call runs and performed after it, so the sandbox it writes to is decided at scheduling time. `SessionTree.pinIfSandbox` took that sandbox from the agent-level slot of the shared sandbox proxy. One agent bean has one such proxy and its slot is last-writer-wins: as soon as a second user acquires, the slot names that user's sandbox, and the first user's session files and transcript segments were written into it.

`mirrorTarget` now pins the sandbox bound to the owning call on its `RuntimeContext`, which the tree already holds. The upload keeps using that call's sandbox after the call has released, as before — only now it is the right one.

A call that has no sandbox bound gets no mirror target. The mirror is best-effort, so it is skipped rather than sent wherever the shared slot points. Transcript stores other than `ObjectStoreTranscriptStore` never go through the sandbox and are not affected.

Regression: `SessionTreeMirrorIsolationTest` drives the real `SandboxLifecycleMiddleware` with two concurrent calls on one proxy. Before the change, alice's session files and transcript segment ended up under bob's sandbox root, and a call without a sandbox of its own wrote into bob's. With a variant that still falls back to the shared slot when no sandbox is bound, only the last of the three cases fails.
@codecov

codecov Bot commented Nov 27, 2026

Copy link
Copy Markdown

Codecov Report

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

Files with missing lines Patch % Lines
...cope/harness/agent/memory/session/SessionTree.java 80.00% 1 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@jujn
jujn merged commit 0279528 into agentscope-ai:2.0.x Nov 29, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants