Fix/kubernetes jdbc snapshot deserialization
Summary
RemoteSandboxSnapshot had no @JsonCreator, causing Jackson to use _deserializeUsingPropertyBased and treat the @JsonTypeInfo type discriminator field "type" as an unrecognised bean property, throwing UnrecognizedPropertyException on every second call when using KubernetesFilesystemSpec + JdbcSnapshotSpec. This PR fixes deserialization for all snapshot implementations and ensures the live RemoteSnapshotClient is re-injected at resume time.
Fixes / Relates to: #1710
Description
Background & Purpose
SandboxSnapshot declares @JsonTypeInfo(As.PROPERTY, property = "type"). When a concrete subtype has no @JsonCreator and no no-arg constructor, Jackson falls through to _deserializeUsingPropertyBased, which buffers all token stream properties — including the "type" discriminator — before constructing the object. Since none of the snapshot classes had a constructor parameter named "type", Jackson threw UnrecognizedPropertyException.
A second issue existed downstream: even if deserialization succeeded, RemoteSandboxSnapshot.client would be null after deserialization (the client is a runtime object, not serializable). SandboxManager never re-injected it before calling client.resume(state), so the subsequent isRestorable() call in AbstractBaseSandbox.start() would NPE.
Changes Made
- RemoteSandboxSnapshot: Added @JsonCreator constructor accepting only @JsonProperty("id"); added @JsonIgnore on client field, getType(), isRestorable(), and restore(); added null-guards in persist(), restore(), and isRestorable() (returns false when client is null, causing safe degradation to cold start); added @JsonIgnoreProperties(ignoreUnknown = true)
- LocalSandboxSnapshot: Added @JsonCreator + @JsonProperty on existing constructor; added @JsonIgnore on getType() and isRestorable(); added @JsonIgnoreProperties(ignoreUnknown = true)
- NoopSandboxSnapshot: Added @JsonIgnore on getType() and isPersistenceEnabled(); added @JsonIgnoreProperties(ignoreUnknown = true)
- SandboxManager: In Priority 3 (resume from persisted state), re-injects the live snapshot client by calling snapshotSpec.build(snapshotId) immediately after deserializeState, before client.resume(state)
- Tests: Added snapshot round-trip tests for all three types in HarnessSandboxJacksonModuleTest; added regression test roundTripKubernetesStateWithRemoteSnapshot in KubernetesSandboxStateSerdeTest
How to Test
- Run mvn test -pl agentscope-harness -Dtest="HarnessSandboxJacksonModuleTest,SandboxManagerIsolationTest,SessionSandboxStateStoreTest" — all tests should pass
- Run mvn test -pl agentscope-extensions/agentscope-extensions-sandbox/agentscope-extensions-sandbox-kubernetes -Dtest="KubernetesSandboxStateSerdeTest" — both tests including roundTripKubernetesStateWithRemoteSnapshot should pass
- To reproduce the original bug before this fix: configure KubernetesFilesystemSpec + JdbcSnapshotSpec, make two consecutive calls to the same session — the second call would throw UnrecognizedPropertyException: "type" on RemoteSandboxSnapshot
Checklist
- [x] Code has been formatted according to project guidelines
- [x] All automated tests are passing
- [x] Documentation / inline comments have been updated accordingly
- [x] Code is ready for review
Codecov Report
:x: Patch coverage is 57.14286% with 9 lines in your changes missing coverage. Please review.
:loudspeaker: Thoughts on this report? Let us know!