Skip to content

[Bug]: RemoteSandboxSnapshot loses RemoteSnapshotClient after JSON deserialization, only DockerSandboxClient handles the re-binding #2303

Open

Description

@Peng-io

Describe the bug

When using a RemoteSnapshotSpec (or a subclass such as MinioSnapshotSpec), the RemoteSandboxSnapshot is serialized into SandboxState and persisted via the state store. On the next agent call, the state is deserialized from JSON via Jackson's @JsonCreator, which only reconstructs the id field but leaves the RemoteSnapshotClient field null. This causes RemoteSandboxSnapshot.isRestorable() to throw "RemoteSnapshotClient is not bound to snapshot id: ...", preventing the sandbox from starting.

Root cause

The SandboxClient interface provides a two-parameter deserializeState(String json, SandboxSnapshotSpec snapshotSpec) default method that simply delegates to the single-parameter version, ignoring the snapshotSpec:

default SandboxState deserializeState(String json, SandboxSnapshotSpec snapshotSpec) {
    return deserializeState(json);
}

Only DockerSandboxClient overrides this method to re-bind the snapshot client via rebindRemoteSnapshot(). All other implementations that use RemoteSnapshotSpec are affected.

Affected clients

  • AgentRunSandboxClient
  • DaytonaSandboxClient
  • E2bSandboxClient
  • KubernetesSandboxClient
  • InMemorySandboxClient (theoretically, but in-memory state is not persisted across restarts)

To Reproduce

  1. Configure a sandbox with a RemoteSnapshotSpec (e.g. MinioSnapshotSpec)
  2. Configure a state store (e.g. PgSqlAgentStateStore or JsonFileAgentStateStore)
  3. Send an agent message that triggers sandbox usage (first call succeeds)
  4. Send a second agent message with the same session scope (second call fails)

Expected behavior

All SandboxClient implementations that use RemoteSnapshotSpec should re-bind the RemoteSnapshotClient from the spec when deserializing state, matching the approach already in DockerSandboxClient.rebindRemoteSnapshot().

Fix reference

DockerSandboxClient already has the correct implementation:

private static void rebindRemoteSnapshot(SandboxState state, SandboxSnapshotSpec snapshotSpec) {
    if (!(snapshotSpec instanceof RemoteSnapshotSpec remoteSnapshotSpec)) {
        return;
    }
    SandboxSnapshot snapshot = state.getSnapshot();
    if (!(snapshot instanceof RemoteSandboxSnapshot)) {
        return;
    }
    state.setSnapshot(
            new RemoteSandboxSnapshot(remoteSnapshotSpec.getClient(), snapshot.getId()));
}

The same pattern should be applied to the affected SandboxClient implementations, or the default method in SandboxClient should be updated to perform this re-binding generically.

Environment

  • AgentScope-Java Version: 2.0.1-SNAPSHOT (also present in 2.0.0)
  • Java Version: 21
  • OS: any

Activity

  1. Peng-io commented on Jul 19, 2026

    @Peng-io
    ContributorAuthor

    Fix approaches:

    Approach A: Fix each affected SandboxClient individually

    Override deserializeState(String, SandboxSnapshotSpec) in each client, mirroring DockerSandboxClient:

    AgentRunSandboxClient

    @Override
    public SandboxState deserializeState(String json, SandboxSnapshotSpec snapshotSpec) {
        SandboxState state = deserializeState(json);
        if (snapshotSpec instanceof RemoteSnapshotSpec rs) {
            SandboxSnapshot snapshot = state.getSnapshot();
            if (snapshot instanceof RemoteSandboxSnapshot && snapshot.getId() != null) {
                state.setSnapshot(snapshotSpec.build(snapshot.getId()));
            }
        }
        return state;
    }

    DaytonaSandboxClient, E2bSandboxClient, KubernetesSandboxClient

    Apply the same rebindRemoteSnapshot() pattern from DockerSandboxClient.

    Approach B: Fix in the SandboxClient interface default method (recommended)

    Move rebindRemoteSnapshot() into the interface default so all implementations benefit automatically:

    default SandboxState deserializeState(String json, SandboxSnapshotSpec snapshotSpec) {
        SandboxState state = deserializeState(json);
        rebindRemoteSnapshot(state, snapshotSpec);
        return state;
    }
    
    static void rebindRemoteSnapshot(SandboxState state, SandboxSnapshotSpec snapshotSpec) {
        if (!(snapshotSpec instanceof RemoteSnapshotSpec rs)) {
            return;
        }
        SandboxSnapshot snapshot = state.getSnapshot();
        if (!(snapshot instanceof RemoteSandboxSnapshot) || snapshot.getId() == null) {
            return;
        }
        state.setSnapshot(new RemoteSandboxSnapshot(rs.getClient(), snapshot.getId()));
    }

    This way all existing and future SandboxClient implementations get the fix automatically, and individual overrides are only needed for custom behavior.

  2. added
    bug
    area/core/agent
    on Jul 20, 2026
  3. moved this from Backlog to In progress in AgentScope Javaon Jul 27, 2026
  4. oss-maintainer commented on Jul 28, 2026

    @oss-maintainer
  5. added a commit that references this issue on Aug 10, 2026
    77fc8c3
  6. Peng-io commented on Oct 16, 2026

    @Peng-io
    ContributorAuthor

    Hi @jujn, could you take a look when you get a chance?

    This is still reproducible on current main (c416c37) with an E2B sandbox using a MinIO-backed RemoteSnapshotSpec in the harness:

    1. First agent call: sandbox starts fine.
    2. Second call (same user scope): fails with RemoteSnapshotClient is not bound to snapshot id: ... at RemoteSandboxSnapshot.isRestorable() → AbstractBaseSandbox.start().

    We also found the same missing re-binding silently breaks snapshot persistence in the other direction: at stop(), RemoteSandboxSnapshot.persist() throws the same "not bound" error, so the workspace archive is never uploaded. This may share a root cause with the backup-on-destroy path reported in #2538.

    Root cause is unchanged from the report: SandboxClient.deserializeState(json, snapshotSpec)'s default method drops the spec, and only DockerSandboxClient re-binds the client.

    It looks like #2423 already implements this fix (Approach B) — approved with green CI and no merge conflicts. Could it be merged when you get a chance?

  7. added a commit that references this issue on Oct 16, 2026
    850a448
  8. chcodex commented on Oct 20, 2026

    @chcodex
    Contributor

    Additional evidence on current main: E2B is still affected.

    • E2bSandboxClient does not override deserializeState(String, SandboxSnapshotSpec), so the default method drops the spec.
    • A persisted E2bSandboxState holding a RemoteSandboxSnapshot deserializes with only its id; RemoteSnapshotClient is null, and isRestorable() / restore() / persist() then throw RemoteSnapshotClient is not bound to snapshot id: ....
    • KubernetesSandboxClient already has a local rebind override (deserializeState(json, snapshotSpec)), and DockerSandboxClient has rebindRemoteSnapshot(). E2bSandboxClient has neither.
    • All E2B serde tests call the single-argument deserializeState(json), so CI cannot catch this.

    Repro: E2B + RemoteSnapshotSpec (or a subclass) + a state store. The first call succeeds; the second call for the same scope fails while restoring the workspace.

    PR #2423 (rebind in the interface default) looks like the right general fix and would cover E2B. I am preparing an E2B-specific regression test and, if #2423 is not merged soon, a focused E2B override. Please let me know if you prefer to wait for #2423 instead of a separate E2B PR.

  9. Peng-io commented on Nov 11, 2026

    @Peng-io
    ContributorAuthor

    Status update against current main:

    • E2bSandboxClient and AgentRunSandboxClient now override deserializeState(String, SandboxSnapshotSpec) and rebind the client from RemoteSnapshotSpec — commit c887528, which closed [Bug] E2B sandbox ignores WorkspaceSpec.root and does not rebind RemoteSnapshotClient #4080.
    • DockerSandboxClient and KubernetesSandboxClient already had the override.
    • DaytonaSandboxClient still implements only the single-argument deserializeState(String), so it inherits the default method that drops the spec. A persisted RemoteSandboxSnapshot under Daytona still deserializes with client == null and fails at isRestorable() / persist().

    The E2B and AgentRun paths are fixed; this issue is not fully closed for all RemoteSnapshotSpec users.

    Two options:

    1. Merge fix(sandbox): rebind RemoteSnapshotClient on state deserialize #2423 (fix/2303-remote-snapshot-rebind). It moves the rebind into the SandboxClient default method and covers every implementation, Daytona included.
    2. Add a focused DaytonaSandboxClient override mirroring E2bSandboxClient.

    @chcodex which do you prefer?

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/core/agentbug

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions