Repository navigation
Description
Summary
When a sandboxed HarnessAgent spawns a declared subagent (subagents/*.md, default WorkspaceMode.ISOLATED) synchronously via agent_spawn, the subagent acquires its own sandbox and blocks forever on SandboxExecutionGuard.tryEnter(). The parent holds the guard for the whole call window, and the child - spawned inside that window - asks for the same key.
Why this is a bug
SandboxExecutionGuard's javadoc defines its purpose as serializing callers that could "race on the same persistent state slot (last write wins)". Parent and child do not share a state slot:
SessionSandboxStateStore#slotSessionIdforUSERscope issandbox/user/{agentId}/{userId}- so parent and child use different slots (differentagentId);- but
SandboxIsolationKey.resolve(USER, ctx, agentId)returns onlyuserId- so both map to the same guard key.
The guard therefore serializes two executions that the state layer treats as independent. Combined with the documented lifecycle ("the guard covers the full call window: acquire -> start -> (call) -> stop -> release"), a nested subagent can never proceed.
The default guard is noop(), so a plain HarnessAgent.builder().filesystem(spec) does not deadlock. It deadlocks with any serializing guard - including the recommended production setup distributedStore(...): RedisDistributedStore, JdbcDistributedStore (MySQL/PostgreSQL), MongoDistributedStore and the control-plane store each override sandboxExecutionGuard() with a real implementation.
To Reproduce
- Sandboxed agent with a distributed store (default
IsolationScope.USER):
HarnessAgent agent = HarnessAgent.builder()
.name("parent")
.model(model)
.workspace(workspace)
.stateStore(redisAgentStateStore)
.distributedStore(redisDistributedStore) // injects RedisSandboxExecutionGuard
.filesystem(new DockerFilesystemSpec()
.image("ubuntu:24.04")
.isolationScope(IsolationScope.USER)) // default
.build();- A declaration without
workspace.mode(ISOLATED is the default):
<!-- workspace/subagents/worker.md -->
---
name: worker
description: does one focused task
---
You are a focused worker.-
Ask the model to
agent_spawn(name="worker", ...)withtimeout_seconds > 0(synchronous, the default). -
The parent call hangs before the subagent runs. No exception is thrown.
With timeout_seconds = 0 (background) the child stalls until the parent call ends (the lease is still held) instead of deadlocking forever.
Expected behavior
At least one of:
- the guard key should follow the state-slot granularity, so a nested subagent (different
agentId) is not serialized against its ancestor; - or declared subagents should share the parent's sandbox in sandbox mode (opt-in builder flag), so no second acquisition happens;
- or the combination should fail fast / be documented as unsupported.
Root cause (v2.0.5)
HarnessAgentBuilderSupport#buildDeclaredFactory gives an ISOLATED declared subagent the parent's sandbox spec (same code in main):
if (decl.getWorkspaceMode() == WorkspaceMode.SHARED && capturedSharedBackend != null) {
sub.abstractFilesystem(capturedSharedBackend);
} else if (capturedSandboxSpec != null) {
sub.filesystem(capturedSandboxSpec); // same spec, but the child acquires its own sandbox
}The child build() then creates its own SandboxBackedFilesystem, SandboxLifecycleMiddleware and SandboxManager, and acquires at call entry. SandboxManager.acquire resolves the key and blocks:
Optional<SandboxIsolationKey> scopeKey =
SandboxIsolationKey.resolve(scope, runtimeContext, agentId);
lease = executionGuard.tryEnter(scopeKey.get());Key vs slot granularity:
| IsolationScope | guard key | persisted slot |
|---|---|---|
USER (default) |
userId (agentId dropped) |
sandbox/user/{agentId}/{userId} |
GLOBAL |
__global__ |
sandbox/global |
SESSION |
sessionId |
sandbox/session/{sessionId} |
AGENT |
agentId |
sandbox/agent/{agentId} |
SESSION / AGENT scopes do not deadlock (parent and child keys differ), but they change isolation semantics - e.g. AGENT shares one slot across all users.
Environment
- AgentScope-Java: 2.0.5 (also present in v2.1.0-BETA1 and
main;SandboxManager,SandboxIsolationKey,SessionSandboxStateStoreandSandboxExecutionGuardare byte-identical between 2.0.4 and 2.1.0-BETA1) - Java: 21
- Backend: Docker sandbox (
DockerFilesystemSpec) + distributed store with a real execution guard
Suggested fixes
- Derive a guard-specific key that includes
agentId(leave the state-slot key unchanged). Sibling calls of the same agent still serialize; a nested subagent no longer collides. - Or force declared subagents to
SHAREDwhen a sandbox spec is present, behind an opt-in builder flag. - At minimum: build-time validation (sandbox + subagents +
USER/GLOBAL+ non-noop guard -> ERROR) and documentation of theSESSIONworkaround.
Related
- [Bug]:Same-isolation-key concurrent calls race on sandbox state slot #2845 / fix(sandbox): serialize same-key concurrent calls to prevent persisted state races #2846 discuss same-key sibling concurrency and propose changing the default guard from
noop()to an in-process guard with a 30-minute wait bound. That change would turn this nested case from "hangs forever" into "fails after 30 minutes"; the nesting case still needs the key fix. - Docs: neither
harness/subagent.mdnorharness/sandbox.mdmentions subagents + sandbox. The documented way to share a sandbox between agents isexternalSandbox(Priority 1 inSandboxManager.acquire, bypasses the guard), but nothing equivalent exists for parent -> declared-subagent execution.
Activity
Ernest-L commentedon Nov 26, 2026
Implemented a fix in #4441.
SandboxIsolationKey#forExecutionGuard(agentId)gives the execution guard the same granularity as the persisted slot (USER->{agentId}/{userId}), so a declared subagent spawned inside a sandboxed call no longer blocks on the lease its parent holds for the whole call window. Persisted slot keys are unchanged (no migration);GLOBALscope remains serialised by design.