Repository navigation
Description
Describe the bug
SandboxBackedFilesystem.uploadFiles handles uploads that supportsFileTransfer rejects by building a single-entry tar and pushing it through Sandbox.hydrateWorkspace. On the Kubernetes backend that hydrate stages a temp archive whose name is derived from the sandbox session id alone (KubernetesSandbox.java:177):
String tmpRel = TMP_DIR_REL + "/ws-hydrate-" + sessionHash() + ".tar";sessionHash() depends only on the sandbox session id, and the upload → extract → cleanup path is not synchronized. Two concurrent uploads on the same sandbox therefore share one tar path, and this interleaving fails one of them:
writer A: files().write(tar) OK
writer B: files().write(tar) OK (overwrites the same name)
writer A: tar -xf OK
writer A: rm -f tar OK (finally cleanup)
writer B: tar -xf FAILS -> "Cannot open: No such file or directory"
The losing writer's exception is caught in uploadFiles (SandboxBackedFilesystem.java:142-145) and downgraded to FileUploadResponse.fail + WARN, so the file silently never lands in the sandbox.
The window is hit in practice by transcript persistence: at every agent-call teardown, the transcript segment .jsonl (mirrored asynchronously by the static single-thread MIRROR_EXECUTOR, SessionTree.java:90) and the sessions.json session index (written immediately after flush() returns, WorkspaceManager.updateSessionIndex, WorkspaceManager.java:404) both call uploadFiles on the same sandbox session.
These writes take the hydrate fallback at all because uploadFiles probes supportsFileTransfer with the raw path (SandboxBackedFilesystem.java:110-111), but WorkspaceManager.writeUtf8WorkspaceRelative passes workspace-relative paths, which never match KubernetesSandbox.toFileApiRelative — it only accepts absolute paths under fileApiBaseDir (KubernetesSandbox.java:291). So each single-file workspace write rides the racy temp tar instead of the native uploadFile channel.
To Reproduce
- Configure an agent with a sandbox filesystem backed by
KubernetesSandbox(file API enabled) and transcript persistence on the workspace filesystem. - Run a multi-turn conversation — each call teardown runs the segment mirror and the session-index write in the same window.
- Observe intermittent WARNs (frequency depends on thread scheduling):
WARN ... SandboxBackedFilesystem - [sandbox-fs] uploadFiles failed for path: agents/<agentId>/sessions/sessions.json
io.agentscope.harness.agent.sandbox.SandboxException$SandboxRuntimeException: tar extract failed (exit=2): tar: /workspace/.agentscope-tmp/ws-hydrate-<hash>.tar: Cannot open: No such file or directory
at io.agentscope.extensions.sandbox.kubernetes.KubernetesSandbox.extractArchive(KubernetesSandbox.java:214)
...
- The file is absent under
/workspacein the sandbox (and missing from the persisted snapshot) even though the run itself succeeded.
Expected behavior
Concurrent uploads to the same sandbox must not interfere with each other — every successful uploadFiles response should correspond to a file that actually landed.
Error messages
See the WARN block above.
Environment (please complete the following information:)
- AgentScope-Java Version: main @ 2.0.3-SNAPSHOT (since fix(harness): 使用 tar 流修复 Windows Docker 沙箱会话文件上传失败 #2557, merged 2026-08-06; no tagged release carries it yet)
- Java Version: 21
- OS: Windows 11 client against Kubernetes sandbox pods (same deterministic name is also used by the exec fallback when the file API is disabled:
/tmp/ws-hydrate-<hash>.tar,KubernetesSandbox.java:189)
Additional context
Fix proposal in #2762, two parts: resolve workspace-relative paths against the workspace root so ordinary writes go through SandboxFileTransfer.uploadFile instead of the hydrate fallback, and give each staged archive a unique name so concurrent hydrate calls cannot collide.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
fix(sandbox): make concurrent sandbox uploads safe (unique hydrate te…