Repository navigation
Description
Description
On a single HarnessAgent, two concurrent calls that resolve to the same SandboxIsolationKey operate on the
same persisted sandbox state record. The sandbox acquire → resume → persist → release window runs outside
the delegate's serializeOnKey gate, and the sandbox-layer guard defaults to noop() — so there is no
serialisation.
Both calls therefore start independent containers from the same state, mutate them in parallel, and
overwrite each other on completion. Workspace changes from one call are silently lost (last write wins),
with a transient double-container in between.
Expected behaviour
Concurrent calls resolving to the same isolation key should serialise and hand off state sequentially. No
call's workspace changes should be clobbered by a concurrent peer.
Actual behaviour
Calls run fully in parallel on the shared state slot; whichever call persists last wins, and the other
call's changes are dropped.
Steps to reproduce
- Build a HarnessAgent with the default scope (or explicit GLOBAL / AGENT).
- Fire two concurrent calls that resolve to the same isolation key, each mutating the sandbox workspace
(e.g. writing a file). - Inspect the final persisted state — one call's changes have been overwritten and lost.
Affected scopes
Any two concurrent calls that resolve to the same persisted state slot:
- SESSION — same sessionId
- USER (default) — same userId
- AGENT — same agentId (fixed at build time)
- GLOBAL — constant key "global", shared by all calls (easiest to hit)
Notes
- This is not covered by [Bug]: Concurrent calls on one agent corrupt each other's sandbox binding (single-slot
SandboxBackedFilesystem/SandboxLifecycleMiddleware) #2490. That fix isolates the in-memory live binding for different-key concurrent
calls; it does not prevent same-key calls from racing on the persisted state. - serializeOnKey does not help here: its gate key (userId, sessionId) protects ReActAgent's session state
and runs inside the delegate, whereas the sandbox lifecycle is wrapped outside it.
Possible direction (non-binding)
Serialise same-key concurrent calls at the sandbox layer — e.g. a JVM-local default guard keyed by
SandboxIsolationKey. Multi-instance deployments would need a distributed guard (Redis SET NX, etc.).
Implementation details TBD in the PR.
Activity
oss-maintainer commentedon Sep 24, 2026
Issue Evaluation
Category:
bug(area/harness, sandbox lifecycle) | Status: Confirmed | Severity: high (silent data loss)Verified against
main@3c1c29c01by engine-assisted static review (paths underagentscope-harness/src/main/java/io/agentscope/harness/).Claim-by-claim check
agent/sandbox/SessionSandboxStateStore.java:44-92(slotSessionIdmaps SESSION/USER/AGENT/GLOBAL);SandboxManager.java:214-252persists after each callagent/sandbox/SandboxExecutionGuard.java:78-93(noop()default); wired only when aDistributedStore/explicit guard is configured (HarnessAgent.java:2470-2473,:2396-2399)serializeOnKeygateHarnessAgent.java:942-957wrapsdelegate.callinMono.using; the gate lives insideAgentBase.java:256-262,291,374-397and is keyed on(userId, sessionId)(ReActAgent.java:727-737) — coarser sandbox keys (USER/AGENT/GLOBAL) are not protected even in one instanceSandboxManager.java:100-121(no compare-on-load);SessionSandboxStateStore.java:58-65→ plain full-replacementsave(AgentStateStore.java:69-79);saveIfVersionCAS exists atAgentStateStore.java:87but is unused here; workspace snapshot likewise overwritten onstop()(AbstractBaseSandbox.java:65-96,132-141)agent/middleware/SandboxLifecycleMiddleware.java:54,114-121,155-164— per-call binding + compare-and-clear, i.e. the different-key live-binding race onlymain; only external-store guards (Redis/JDBC/Mongo/ControlPlane). Default configuration is reproducibleRoot cause. The only per-sandbox-key serialization seam (
SandboxExecutionGuard) is optional and defaults to noop, while state persistence is a blind full replacement — so two same-key calls hydrate from one record and lose one set of changes (last write wins).On the linked PR. @larry-zy #2846 (
OPEN, +1159/−84, 11 files) already implements exactly this shape — an in-process guard keyed bySandboxIsolationKeyplusSandboxLifecycleMiddleware/HarnessAgentwiring — so no automated PR from us; a second generated patch would duplicate it. It will get reviewed on the scheduled PR rotation.Two review points worth carrying into #2846:
tryEnterblocks a thread inside ReactorMono.using— the default-on question should be an explicit, documented design decision.saveIfVersionCAS (AgentStateStore.java:87) to detect/reject lost updates even when a guard is bypassed (e.g. multi-instance without a distributed guard). Note that moving acquire/persist inside the delegate gate would not suffice, since USER/AGENT/GLOBAL keys are coarser than the gate's(userId, sessionId)key.Caveats. Static review only — the race was not reproduced at runtime; interleaving is inferred from eager
Mono.usingacquisition semantics and plain-save writes.Automated evaluation by github-manager-bot