Skip to content

.NET: Fix InMemoryCheckpointManager serialization - #1639

Merged
lokitoth merged 1 commit into
mainfrom
dev/dotnet_workflow/fix_workflow_thread_serialization
Oct 23, 2025
Merged

.NET: Fix InMemoryCheckpointManager serialization#1639
lokitoth merged 1 commit into
mainfrom
dev/dotnet_workflow/fix_workflow_thread_serialization

Conversation

@lokitoth

@lokitoth lokitoth commented Oct 22, 2025

Copy link
Copy Markdown
Contributor

Motivation and Context

Checkpointing is used by the WorkflowHostAgent to be able to support resume from a provided thread. When a CheckpointManager is not specified, we use the InMemoryCheckpointManager and serialize its state into the thread's Serialize()ed JsonElement.

At some point InMemoryCheckpointManager became not serializable, breaking this behaviour. This change restores serializability and adds a test.

Closes #1629

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 October 22, 2025 20:47
@markwallace-microsoft markwallace-microsoft added .NET Usage: [Issues, PRs], Target: .Net workflows Usage: [Issues, PRs], Target: Workflows labels Oct 22, 2025

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 fixes a serialization issue with InMemoryCheckpointManager that was preventing checkpoint state from being properly persisted and restored. The changes refactor internal fields to use public properties with [JsonInclude] attributes, add a new CheckpointInfoConverter for dictionary key serialization, and relocate shared escape/unescape utility methods to a base class.

Key changes:

  • Made InMemoryCheckpointManager and RunCheckpointCache serializable by converting private fields to internal properties with JSON attributes
  • Created CheckpointInfoConverter to handle CheckpointInfo as dictionary keys during serialization
  • Moved escape/unescape helper methods from ScopeKeyConverter to the base class JsonConverterDictionarySupportBase

Reviewed Changes

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

Show a summary per file
File Description
JsonSerializationTests.cs Added test to verify InMemoryCheckpointManager serialization round-trip and refactored existing checkpoint validation logic
InMemoryCheckpointManager.cs Changed private _store field to public Store property with [JsonInclude] for JSON serialization
RunCheckpointCache.cs Changed private _checkpointIndex and _cache fields to public properties with [JsonInclude]
CheckpointInfoConverter.cs New converter enabling CheckpointInfo to be used as dictionary keys in JSON
JsonMarshaller.cs Registered CheckpointInfoConverter in the internal serialization options
JsonConverterDictionarySupportBase.cs Added shared Escape and Unescape methods with configurable escape character
ScopeKeyConverter.cs Removed Escape and Unescape methods (moved to base class) and unused import
ExecutorIdentityConverter.cs Added missing imports for updated converter implementation

Comment thread dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/JsonSerializationTests.cs Outdated
@lokitoth
lokitoth force-pushed the dev/dotnet_workflow/fix_workflow_thread_serialization branch from 74b2f28 to 67e8bbf Compare October 22, 2025 21:00
@lokitoth
lokitoth force-pushed the dev/dotnet_workflow/fix_workflow_thread_serialization branch from 67e8bbf to a3a12c6 Compare October 22, 2025 21:08
@crickman crickman moved this to In Review in Agent Framework Oct 22, 2025
@lokitoth
lokitoth force-pushed the dev/dotnet_workflow/fix_workflow_thread_serialization branch from a3a12c6 to e1674c3 Compare October 22, 2025 21:43
Checkpointing is used by the WorkflowHostAgent to be able to support resume from a provided thread. When a CheckpointManager is not specified, we use the InMemoryCheckpointManager and serialize its state into the thread's Serialize()ed JsonElement.

At some point InMemoryCheckpointManager became not serializable, breaking this behaviour. This change restores serializability, and adds a test.
@lokitoth
lokitoth force-pushed the dev/dotnet_workflow/fix_workflow_thread_serialization branch from c1d2879 to 95a6acb Compare October 23, 2025 15:42
@lokitoth
lokitoth added this pull request to the merge queue Oct 23, 2025
Merged via the queue into main with commit b2246ef Oct 23, 2025
14 checks passed
@github-project-automation github-project-automation Bot moved this from In Review to Done in Agent Framework Oct 23, 2025
@crickman
crickman deleted the dev/dotnet_workflow/fix_workflow_thread_serialization branch October 23, 2025 19:49
ReubenBond pushed a commit to ReubenBond/agent-framework that referenced this pull request Oct 28, 2025
Checkpointing is used by the WorkflowHostAgent to be able to support resume from a provided thread. When a CheckpointManager is not specified, we use the InMemoryCheckpointManager and serialize its state into the thread's Serialize()ed JsonElement.

At some point InMemoryCheckpointManager became not serializable, breaking this behaviour. This change restores serializability, and adds a test.
arisng pushed a commit to arisng/agent-framework that referenced this pull request Feb 2, 2026
Checkpointing is used by the WorkflowHostAgent to be able to support resume from a provided thread. When a CheckpointManager is not specified, we use the InMemoryCheckpointManager and serialize its state into the thread's Serialize()ed JsonElement.

At some point InMemoryCheckpointManager became not serializable, breaking this behaviour. This change restores serializability, and adds a test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

.NET Usage: [Issues, PRs], Target: .Net workflows Usage: [Issues, PRs], Target: Workflows

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

.NET: AgentThread deserialization - Checkpoint error

5 participants