Repository navigation
fix(harness): session mirror pins the owning call's sandbox instead of the agent-level slot (#4273) - #4447
Merged
jujn merged 2 commits intoNov 29, 2026
Conversation
…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.
This was referenced Nov 27, 2026
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
jujn
approved these changes
Nov 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.pinIfSandboxtook that sandbox from the agent-level slot of the sharedSandboxBackedFilesystemproxy. One agent bean has one such proxy and its slot is last-writer-wins: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
mirrorTargetpins the sandbox bound to the owning call on itsRuntimeContext.SessionTreealready held that context for its remote operations, andSandboxLifecycleMiddlewarebinds 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.requireSandboxstill falls back to the shared slot for callers that have no per-call context, such asWorkspaceMessageBus. That is the same slot under a different caller and is what #2849 is about.Tests
SessionTreeMirrorIsolationTest(new, 3 cases) uses the realSandboxLifecycleMiddlewarewith a proxy shared by two calls, and sandboxes that record every file transferred into them:On
2.0.xbefore 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-harnesssuite 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:Sandbox workspace root must be an absolute path) andMemoryConsolidatorCommitGateTestmaven:3.9-eclipse-temurin-17)BaseSandboxFilesystemTest.edit_*(python3: not foundin the image),MarketplaceStagerOrphanGcTest.unreadableEntryDoesNotFailStageNone 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 throughSessionTreemirroring, 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.xfailed the Windows job, at first inagentscope-core, and had its Ubuntu job cancelled. Those causes are fixed by #4454 and #4461, merged into2.0.xon 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.