Skip to content

fix(sandbox): rebind RemoteSnapshotClient on state deserialize - #2423

Open
Blue-Berrys wants to merge 2 commits into
agentscope-ai:mainfrom
Blue-Berrys:fix/2303-remote-snapshot-rebind
Open

Blue-Berrys wants to merge 2 commits into
agentscope-ai:mainfrom
Blue-Berrys:fix/2303-remote-snapshot-rebind

Conversation

@Blue-Berrys

@Blue-Berrys Blue-Berrys commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

AgentScope-Java Version

2.0.1-SNAPSHOT

Description

Fixes #2303.

RemoteSandboxSnapshot only serializes its id. After JSON round-trip, RemoteSnapshotClient is null. SandboxClient.deserializeState(json, snapshotSpec) previously ignored snapshotSpec, so only DockerSandboxClient (which overrode the two-arg method) rebound the client. AgentRun / Daytona / E2B / Kubernetes clients were affected.

Changes:

  • Move remote-snapshot rebinding into the SandboxClient interface default deserializeState(String, SandboxSnapshotSpec).
  • Remove the duplicate override from DockerSandboxClient (it now inherits the default).
  • Add SandboxClientRemoteSnapshotRebindTest covering unbound single-arg deserialize and two-arg rebind success.

Validated with:

mvn -pl agentscope-harness -am \
  -Dtest=SandboxClientRemoteSnapshotRebindTest,HarnessSandboxJacksonModuleTest \
  test

Checklist

Please check the following items before code is ready to be reviewed.

  • Code has been formatted with mvn spotless:apply
  • All tests are passing (mvn test)
  • Javadoc comments are complete and follow project conventions
  • Related documentation has been updated (e.g. links, examples, etc.) — N/A (behavioral bug fix, no doc surface)
  • Code is ready for review

Default deserializeState(json, snapshotSpec) ignored the snapshot
spec, so non-Docker sandbox clients left RemoteSandboxSnapshot unbound
after JSON round-trip. Move rebinding into the interface default and
cover it with unit tests.

Fixes agentscope-ai#2303
@gemini-code-assist

Copy link
Copy Markdown

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@CLAassistant

CLAassistant commented Jul 27, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@oss-maintainer oss-maintainer left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review — Approved ✅

Overall: Good fix for the sandbox state deserialization issue. The PR correctly moves the rebindRemoteSnapshot logic from DockerSandboxClient to the SandboxClient interface as a default method, ensuring all sandbox client implementations properly rebind the RemoteSnapshotClient after deserialization.

Key Changes:

  1. SandboxClient.deserializeState(json, snapshotSpec) now calls rebindRemoteSnapshot to re-inject the client
  2. rebindRemoteSnapshot is a static helper that checks if the snapshot is a RemoteSandboxSnapshot and re-creates it with the client from RemoteSnapshotSpec
  3. Removed the duplicate implementation from DockerSandboxClient

Code Quality:

  • ✅ Clean refactoring — eliminates code duplication
  • ✅ Proper null checks and type guards
  • ✅ Good Javadoc explaining the rebinding rationale
  • ✅ RemoteSandboxSnapshot only persists its id across serialization, so the client must be re-injected

CI Status: ✅ All checks passed

Verdict: Well-structured fix that correctly addresses the deserialization issue.

@codecov

codecov Bot commented Jul 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 70.00000% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...gentscope/harness/agent/sandbox/SandboxClient.java 70.00% 1 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@AgentScopeJavaBot AgentScopeJavaBot added bug Something isn't working area/harness agentscope-harness (test/runtime support) labels Aug 11, 2026

@AgentScopeJavaBot AgentScopeJavaBot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 AI Review

This PR fixes a latent bug where RemoteSandboxSnapshot loses its RemoteSnapshotClient after JSON deserialization for all SandboxClient implementations except DockerSandboxClient. The fix lifts rebindRemoteSnapshot from DockerSandboxClient to a static method on the SandboxClient interface, wiring it into the default two-arg method.

SandboxSnapshot snapshot = state.getSnapshot();
if (!(snapshot instanceof RemoteSandboxSnapshot) || snapshot.getId() == null) {
return;
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[suggestion] Null-id RemoteSandboxSnapshot silently skipped without logging. A RemoteSandboxSnapshot with null id after deserialization likely indicates a data integrity issue. Adding a warn-level log would make this visible.

* <p>No-op when the spec is not remote, the snapshot is missing/non-remote, or the snapshot
* id is null.
*/
static void rebindRemoteSnapshot(SandboxState state, SandboxSnapshotSpec snapshotSpec) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Static rebindRemoteSnapshot uses concrete instanceof check for RemoteSandboxSnapshot. If new remote snapshot subtypes are introduced, they will be silently skipped. Consider a marker interface if the hierarchy grows.

@AgentScopeJavaBot AgentScopeJavaBot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 AI Review

This PR fixes a latent bug where RemoteSandboxSnapshot loses its RemoteSnapshotClient after JSON deserialization for all SandboxClient implementations except DockerSandboxClient. The fix lifts rebindRemoteSnapshot from DockerSandboxClient to a static method on the SandboxClient interface, wiring it into the default two-arg method.

SandboxSnapshot snapshot = state.getSnapshot();
if (!(snapshot instanceof RemoteSandboxSnapshot) || snapshot.getId() == null) {
return;
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[suggestion] Null-id RemoteSandboxSnapshot silently skipped without logging. A RemoteSandboxSnapshot with null id after deserialization likely indicates a data integrity issue. Adding a warn-level log would make this visible.

* <p>No-op when the spec is not remote, the snapshot is missing/non-remote, or the snapshot
* id is null.
*/
static void rebindRemoteSnapshot(SandboxState state, SandboxSnapshotSpec snapshotSpec) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Static rebindRemoteSnapshot uses concrete instanceof check for RemoteSandboxSnapshot. If new remote snapshot subtypes are introduced, they will be silently skipped. Consider a marker interface if the hierarchy grows.

@AgentScopeJavaBot AgentScopeJavaBot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 AI Review

This PR fixes a latent bug where RemoteSandboxSnapshot loses its RemoteSnapshotClient after JSON deserialization for all SandboxClient implementations except DockerSandboxClient. The fix lifts rebindRemoteSnapshot from DockerSandboxClient to a static method on the SandboxClient interface, wiring it into the default two-arg method.

SandboxSnapshot snapshot = state.getSnapshot();
if (!(snapshot instanceof RemoteSandboxSnapshot) || snapshot.getId() == null) {
return;
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[suggestion] Null-id RemoteSandboxSnapshot silently skipped without logging. A RemoteSandboxSnapshot with null id after deserialization likely indicates a data integrity issue. Adding a warn-level log would make this visible.

* <p>No-op when the spec is not remote, the snapshot is missing/non-remote, or the snapshot
* id is null.
*/
static void rebindRemoteSnapshot(SandboxState state, SandboxSnapshotSpec snapshotSpec) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Static rebindRemoteSnapshot uses concrete instanceof check for RemoteSandboxSnapshot. If new remote snapshot subtypes are introduced, they will be silently skipped. Consider a marker interface if the hierarchy grows.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/harness agentscope-harness (test/runtime support) bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

4 participants