Skip to content

Conversation

@lokitoth
Copy link
Member

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

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

Copilot AI review requested due to automatic review settings January 26, 2026 16:57
@markwallace-microsoft markwallace-microsoft added .NET workflows Related to Workflows in agent-framework labels Jan 26, 2026
@lokitoth lokitoth force-pushed the dev/dotnet_workflow/Fix-UnorderedJsonSerialization branch from b523382 to 0eca39a Compare January 26, 2026 17:02
Copy link
Contributor

Copilot AI left a 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 JsonMarshaller to respect a new JsonCheckpointManagerOptions.AllowOutOfOrderMetadataProperties flag via its internal JsonSerializerOptions.
  • Introduce JsonCheckpointManagerOptions and thread it through CheckpointManager.CreateJson so callers can opt into relaxed metadata ordering behavior.
  • Add targeted unit tests (and a helper) to reproduce the jsonb metadata-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.

@lokitoth lokitoth force-pushed the dev/dotnet_workflow/Fix-UnorderedJsonSerialization branch from 0eca39a to e9da6ec Compare January 26, 2026 17:24
@lokitoth lokitoth force-pushed the dev/dotnet_workflow/Fix-UnorderedJsonSerialization branch from e9da6ec to b3065f8 Compare January 26, 2026 17:39
@lokitoth lokitoth force-pushed the dev/dotnet_workflow/Fix-UnorderedJsonSerialization branch from b3065f8 to 4036b04 Compare January 27, 2026 21:25
@lokitoth lokitoth force-pushed the dev/dotnet_workflow/Fix-UnorderedJsonSerialization branch from 92c9a3e to 8cf4f7d Compare January 27, 2026 23:42
@lokitoth lokitoth force-pushed the dev/dotnet_workflow/Fix-UnorderedJsonSerialization branch from 8cf4f7d to f80a0d5 Compare February 4, 2026 18:06
@lokitoth lokitoth force-pushed the dev/dotnet_workflow/Fix-UnorderedJsonSerialization branch from f80a0d5 to 2976f5a Compare February 5, 2026 15:54
@lokitoth lokitoth force-pushed the dev/dotnet_workflow/Fix-UnorderedJsonSerialization branch from 2976f5a to b5f3ddf Compare February 10, 2026 05:01
@lokitoth lokitoth added this pull request to the merge queue Feb 10, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 10, 2026
@lokitoth lokitoth added this pull request to the merge queue Feb 10, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 10, 2026
@lokitoth lokitoth added this pull request to the merge queue Feb 10, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 10, 2026
@lokitoth lokitoth added this pull request to the merge queue Feb 10, 2026
github-merge-queue bot pushed a commit that referenced this pull request Feb 10, 2026
…rties are out of order (#3442)

* Fix checkpoint JSON deserialization with out-of-order metadata properties (#2962)

* Simplify: propagate AllowOutOfOrderMetadataProperties from incoming JsonSerializerOptions
@lokitoth lokitoth removed this pull request from the merge queue due to a manual request Feb 10, 2026
@lokitoth lokitoth added this pull request to the merge queue Feb 10, 2026
@lokitoth lokitoth removed this pull request from the merge queue due to a manual request Feb 10, 2026
@lokitoth lokitoth added this pull request to the merge queue Feb 10, 2026
Merged via the queue into main with commit e489ac0 Feb 10, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

.NET workflows Related to Workflows in agent-framework

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.NET: Checkpoint JSON deserialization fails when using PostgreSQL jsonb

5 participants