Skip to content

[Bug]: Concurrent sandbox file uploads race on the deterministic hydrate temp tar — sessions.json / transcript uploads fail intermittently with "tar extract failed (exit=2)" #2761

Closed

Description

@Buktal

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

  1. Configure an agent with a sandbox filesystem backed by KubernetesSandbox (file API enabled) and transcript persistence on the workspace filesystem.
  2. Run a multi-turn conversation — each call teardown runs the segment mirror and the session-index write in the same window.
  3. 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)
    ...
  1. The file is absent under /workspace in 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:)

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.

Activity

  1. moved this from Backlog to In progress in AgentScope Javaon Aug 18, 2026
  2. added
    bug
    area/harness
    on Aug 19, 2026
  3. moved this from In progress to Done in AgentScope Javaon Aug 21, 2026
  4. added a commit that references this issue on Aug 21, 2026
    de4d1d6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/harnessbug

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions