Repository navigation
fix(sandbox): rebind RemoteSnapshotClient on state deserialize - #2423
Blue-Berrys wants to merge 2 commits into
Conversation
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
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
oss-maintainer
left a comment
There was a problem hiding this comment.
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:
SandboxClient.deserializeState(json, snapshotSpec)now callsrebindRemoteSnapshotto re-inject the clientrebindRemoteSnapshotis a static helper that checks if the snapshot is aRemoteSandboxSnapshotand re-creates it with the client fromRemoteSnapshotSpec- 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
- ✅
RemoteSandboxSnapshotonly persists itsidacross serialization, so the client must be re-injected
CI Status: ✅ All checks passed
Verdict: Well-structured fix that correctly addresses the deserialization issue.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
AgentScopeJavaBot
left a comment
There was a problem hiding this comment.
🤖 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; | ||
| } |
There was a problem hiding this comment.
[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) { |
There was a problem hiding this comment.
[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
left a comment
There was a problem hiding this comment.
🤖 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; | ||
| } |
There was a problem hiding this comment.
[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) { |
There was a problem hiding this comment.
[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
left a comment
There was a problem hiding this comment.
🤖 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; | ||
| } |
There was a problem hiding this comment.
[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) { |
There was a problem hiding this comment.
[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.
AgentScope-Java Version
2.0.1-SNAPSHOT
Description
Fixes #2303.
RemoteSandboxSnapshotonly serializes itsid. After JSON round-trip,RemoteSnapshotClientis null.SandboxClient.deserializeState(json, snapshotSpec)previously ignoredsnapshotSpec, so onlyDockerSandboxClient(which overrode the two-arg method) rebound the client. AgentRun / Daytona / E2B / Kubernetes clients were affected.Changes:
SandboxClientinterface defaultdeserializeState(String, SandboxSnapshotSpec).DockerSandboxClient(it now inherits the default).SandboxClientRemoteSnapshotRebindTestcovering unbound single-arg deserialize and two-arg rebind success.Validated with:
mvn -pl agentscope-harness -am \ -Dtest=SandboxClientRemoteSnapshotRebindTest,HarnessSandboxJacksonModuleTest \ testChecklist
Please check the following items before code is ready to be reviewed.
mvn spotless:applymvn test)