Repository navigation
Description
Describe the bug
With the stock KubernetesSandboxClient (Mode 2 filesystem(SandboxFilesystemSpec), a SandboxSnapshotSpec and a state store configured), workspace contents are silently lost at the end of every call, and each call orphans the previous snapshot archive.
Trigger chain:
KubernetesSandboxClient.create()setsclaimOwned = true.HarnessAgentauto-registersSandboxLifecycleMiddleware, which releases the sandbox after every call:SandboxManager.release()(self-managed path) →stop()(uploads the workspace archive undersnapshot.getId()) →shutdown().KubernetesSandbox.shutdown()seesclaimOwned == trueand callsterminate(), deleting the claim and the pod — every call.- On the next call,
SandboxManager.acquire()Priority 3 loads the persisted state and callsKubernetesSandboxClient.resume()→getSandbox(claimName, namespace), which throws because the claim was terminated in step 1.acquire()catches this, logs a warn, and falls through to Priority 4 fresh create. - Priority 4 creates a sandbox with a new sessionId, so
snapshotSpec.build(newSessionId)produces a new snapshot id. The previous archive is never referenced again (orphaned), andstart()runs the fresh-init branch (workspace rebuilt from spec only) — all files written in previous calls are gone. The only trace is the Priority 3 fallback warn log; the agent call itself succeeds.
This contradicts the documented 4-branch workspace-start logic in AbstractBaseSandbox.start(), whose Branch B/C exist precisely to restore the workspace from the snapshot once the container is gone. On Docker this works: DockerSandboxClient.resume() does not require a live container, so the next call reaches Branch B and restores the workspace. On Kubernetes, the per-call claim termination in step 1 makes those restore branches unreachable, and the Priority 4 fallback drops the persisted snapshot id.
To Reproduce
- Build a
HarnessAgentwithfilesystem(new KubernetesFilesystemSpec(...).snapshotSpec(new RemoteSnapshotSpec(client)) ...)and a distributed state store. - First call: write a file into the sandbox workspace. Observe the archive uploaded to remote storage and the claim/pod terminated at release.
- Second call with the same scope: observe in the logs
Failed to load persisted state for scope ..., falling through to fresh create, a new pod with a new sessionId, an empty workspace, and the previous archive orphaned in remote storage.
Expected behavior
The workspace persists across calls via the snapshot mechanism, matching the Docker behavior. Either:
resume()should not hard-fail when the claim is gone, lettingstart()degrade to the Branch B restore path, or- the fresh-create fallback should seed the new sandbox's snapshot with the persisted snapshot id so the workspace is restored from the previous archive.
Error messages
[sandbox] Failed to load persisted state for scope ..., falling through to fresh create: ...
Then a silent workspace reset — no further error.
Environment (please complete the following information:)
- AgentScope-Java Version: 2.0.1 (also verified on current main
bf7b7dae) - Java Version: 21
- OS: any
- Module: agentscope-extensions-sandbox-kubernetes
Additional context
Workaround in use locally: subclass KubernetesSandboxClient and flip claimOwned to false right after create(), so the per-call shutdown() only closes the connection and the pod survives across calls; eviction deletes the pod explicitly. This confirms the trigger chain above but is fragile — it depends on overriding lifecycle ownership semantics that the harness assumes it controls.
Activity