Skip to content

.NET: fix: JSON Serialization issue with MultiPartyConversation#5653

Merged
lokitoth merged 1 commit intomainfrom
dev/dotnet_workflow/fix_handoff_serialization
May 5, 2026
Merged

.NET: fix: JSON Serialization issue with MultiPartyConversation#5653
lokitoth merged 1 commit intomainfrom
dev/dotnet_workflow/fix_handoff_serialization

Conversation

@lokitoth
Copy link
Copy Markdown
Member

@lokitoth lokitoth commented May 5, 2026

Motivation and Context

When MultiPartyConversation gets saved during checkpointing, the data for the chat history is not persisted, resulting in failures to deserialize after.

Huge thanks to @alex-bush for finding and root-causing the issue!

Description

The fix is to make the history visible to the source generated serialization code.

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 May 5, 2026 13:09
@lokitoth lokitoth self-assigned this May 5, 2026
@moonbox3 moonbox3 added .NET workflows Related to Workflows in agent-framework labels May 5, 2026
@lokitoth lokitoth moved this to In Review in Agent Framework May 5, 2026
@github-actions github-actions Bot changed the title fix: JSON Serialization issue with MultiPartyConversation .NET: fix: JSON Serialization issue with MultiPartyConversation May 5, 2026
Copy link
Copy Markdown
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 aims to fix .NET workflow checkpoint/session round-tripping for handoff workflows by making handoff-specific state types available to the workflows JSON source generator and by exposing MultiPartyConversation history for serialization.

Changes:

  • Added source-generated JSON metadata for HandoffSharedState and HandoffAgentHostState.
  • Updated MultiPartyConversation with JSON serialization attributes and a deserialization constructor for chat history.
  • Added JSON round-trip unit tests covering handoff shared/host state serialization.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/JsonSerializationTests.cs Adds regression tests for handoff state JSON round-tripping.
dotnet/src/Microsoft.Agents.AI.Workflows/WorkflowsJsonUtilities.cs Registers handoff state types in the workflows JSON source-generation context.
dotnet/src/Microsoft.Agents.AI.Workflows/Specialized/MultiPartyConversation.cs Exposes conversation history to STJ and adds constructor-based deserialization.

Comment thread dotnet/src/Microsoft.Agents.AI.Workflows/Specialized/MultiPartyConversation.cs Outdated
Comment thread dotnet/src/Microsoft.Agents.AI.Workflows/Specialized/MultiPartyConversation.cs Outdated
Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

Automated Code Review

Reviewers: 4 | Confidence: 77%

✗ Correctness

The MultiPartyConversation JSON constructor has a parameter name mismatch that will break deserialization. The constructor parameter history doesn't match the field name _history (case-insensitive), so System.Text.Json cannot bind the serialized _history JSON property to the constructor parameter. The existing SessionCheckpointCache in this codebase correctly uses matching names (e.g., property CheckpointIndex ↔ parameter checkpointIndex). Additionally, HandoffSharedState.Conversation is a get-only property of a non-collection type with no [JsonConstructor], so it cannot be deserialized without JsonObjectCreationHandling.Populate.

✓ Security Reliability

The PR adds JSON serialization support for MultiPartyConversation, HandoffSharedState, and HandoffAgentHostState types. The main reliability concern is the lack of null-guard in the new JsonConstructor for MultiPartyConversation — if deserialized with a null history (from corrupted checkpoint data or a serializer naming mismatch), all methods will throw NullReferenceException. The change is otherwise straightforward and well-tested.

✓ Test Coverage

The PR adds JSON serialization support for MultiPartyConversation, HandoffSharedState, and HandoffAgentHostState, with four new roundtrip tests. Test coverage is adequate: it covers empty and populated HandoffSharedState, plus HandoffAgentHostState with and without IncomingState (taking-turn vs not-taking-turn). The tests implicitly verify that the [JsonConstructor] on MultiPartyConversation works correctly and that _mutex is initialized post-deserialization (via CloneAllMessages which locks). No significant test coverage gaps were found.

✗ Design Approach

I found one blocking design issue. The change adds source-generated JSON metadata and a serializable wrapper for MultiPartyConversation, but it still does not give System.Text.Json a supported way to restore the Conversation object inside HandoffSharedState, so the checkpointing fix is likely aimed at the symptom rather than the actual deserialization contract.

Flagged Issues

  • HandoffSharedState.Conversation is a getter-only property (HandoffStartExecutor.cs:24-28) of a non-collection custom type, with no [JsonConstructor] on HandoffSharedState and no JsonObjectCreationHandling.Populate configured. Registering the types in WorkflowsJsonUtilities does not actually make the shared conversation round-trip. A more durable fix is to give HandoffSharedState a settable/init-only serialized shape or explicitly enable populate semantics.

Automated review by lokitoth's agents

Comment thread dotnet/src/Microsoft.Agents.AI.Workflows/WorkflowsJsonUtilities.cs
@lokitoth lokitoth moved this from In Review to In Progress in Agent Framework May 5, 2026
When MultiPartyConversation gets saved during checkpointing, the data for the chat history is not persisted, resulting in failures to deserialize after. The fix is to make the history visible to the source generated serialization code.
@lokitoth lokitoth moved this from In Progress to In Review in Agent Framework May 5, 2026
@lokitoth lokitoth force-pushed the dev/dotnet_workflow/fix_handoff_serialization branch from 5d9eb8e to 8383e05 Compare May 5, 2026 13:53
@lokitoth lokitoth enabled auto-merge May 5, 2026 14:43
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

Status: Done

Development

Successfully merging this pull request may close these issues.

.NET: [Bug]: MultiPartyConversation._history is dropped during workflow-as-agent session round-trip → "Bookmark value too large" on next turn (1.3)

5 participants