-
Notifications
You must be signed in to change notification settings - Fork 1.1k
.NET: Fix: Checkpoint Deserialization breaks when JSON metadata properties are out of order #3442
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
.NET: Fix: Checkpoint Deserialization breaks when JSON metadata properties are out of order #3442
Conversation
b523382 to
0eca39a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR makes JSON checkpoint deserialization resilient to out-of-order polymorphic metadata (e.g., $type) so that checkpoints stored in PostgreSQL jsonb (and other sources that reorder properties) can be deserialized successfully.
Changes:
- Extend
JsonMarshallerto respect a newJsonCheckpointManagerOptions.AllowOutOfOrderMetadataPropertiesflag via its internalJsonSerializerOptions. - Introduce
JsonCheckpointManagerOptionsand thread it throughCheckpointManager.CreateJsonso callers can opt into relaxed metadata ordering behavior. - Add targeted unit tests (and a helper) to reproduce the
jsonbmetadata-ordering issue and validate that enabling the new option restores successful deserialization.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/JsonSerializationTests.cs |
Adds regression tests simulating out-of-order $type metadata and verifying default failure vs. success when AllowOutOfOrderMetadataProperties is enabled, plus a helper to reorder JSON properties. |
dotnet/src/Microsoft.Agents.AI.Workflows/Checkpointing/JsonMarshaller.cs |
Updates the marshaller to accept JsonCheckpointManagerOptions and configure AllowOutOfOrderMetadataProperties on its internal JsonSerializerOptions. |
dotnet/src/Microsoft.Agents.AI.Workflows/Checkpointing/JsonCheckpointManagerOptions.cs |
Introduces a public options class with a flag to allow out-of-order metadata properties during JSON deserialization, with XML documentation. |
dotnet/src/Microsoft.Agents.AI.Workflows/CheckpointManager.cs |
Extends CreateJson with an optional JsonCheckpointManagerOptions parameter and passes it to JsonMarshaller so callers can opt in to relaxed metadata ordering. |
dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/JsonSerializationTests.cs
Outdated
Show resolved
Hide resolved
0eca39a to
e9da6ec
Compare
e9da6ec to
b3065f8
Compare
b3065f8 to
4036b04
Compare
92c9a3e to
8cf4f7d
Compare
8cf4f7d to
f80a0d5
Compare
f80a0d5 to
2976f5a
Compare
2976f5a to
b5f3ddf
Compare
Motivation and Context
JSON Checkpoint serialization is currently strict in the ordering of the metadata properties, such as the polymorphic type specifier. This causes problems when deserializing checkpoints stored as JSONB in Postgres, which provides a different order on read.
Description
Create a way to let the user specify that a relaxed ordering is also allowed.
Contribution Checklist
Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.