Skip to content

.NET: fix fan-in barrier checkpoint state#6491

Open
he-yufeng wants to merge 1 commit into
microsoft:mainfrom
he-yufeng:fix/fanin-barrier-checkpoint
Open

.NET: fix fan-in barrier checkpoint state#6491
he-yufeng wants to merge 1 commit into
microsoft:mainfrom
he-yufeng:fix/fanin-barrier-checkpoint

Conversation

@he-yufeng

Copy link
Copy Markdown
Contributor

Summary

Fixes #6372.

The in-process runner was checkpointing a runner-owned EdgeMap, while message delivery and fan-in buffering actually use the EdgeMap owned by InProcessRunnerContext. That meant a checkpoint taken after one side of a fan-in barrier had arrived could persist an empty edge state, then lose the buffered message on resume.

This changes checkpoint export/import to go through the live runner context edge map and adds a regression test that pauses with one fan-in input buffered, resumes, replies to the pending request, and verifies the barrier releases both pre-checkpoint and post-resume contributions.

Validation

  • git diff --check
  • dotnet run --project .\tests\Microsoft.Agents.AI.Workflows.UnitTests\Microsoft.Agents.AI.Workflows.UnitTests.csproj -f net10.0 -- --filter-method Microsoft.Agents.AI.Workflows.UnitTests.CheckpointResumeTests.Checkpoint_Resume_PreservesFanInBarrierBufferedMessagesAsync --no-progress
  • dotnet run --project .\tests\Microsoft.Agents.AI.Workflows.UnitTests\Microsoft.Agents.AI.Workflows.UnitTests.csproj -f net10.0 -- --filter-class Microsoft.Agents.AI.Workflows.UnitTests.CheckpointResumeTests --no-progress
  • dotnet build .\tests\Microsoft.Agents.AI.Workflows.UnitTests\Microsoft.Agents.AI.Workflows.UnitTests.csproj --no-restore --tl:off
  • dotnet format .\src\Microsoft.Agents.AI.Workflows\Microsoft.Agents.AI.Workflows.csproj --verify-no-changes --no-restore --verbosity minimal
  • dotnet format .\tests\Microsoft.Agents.AI.Workflows.UnitTests\Microsoft.Agents.AI.Workflows.UnitTests.csproj --verify-no-changes --no-restore --verbosity minimal

Copilot AI review requested due to automatic review settings June 12, 2026 05:54
@moonbox3 moonbox3 added .NET workflows Related to Workflows in agent-framework labels Jun 12, 2026

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

Note

Copilot was unable to run its full agentic suite in this review.

Adds coverage and runtime support for preserving fan-in barrier buffered edge state across checkpoint/resume in the in-process workflow runner.

Changes:

  • Added a new unit test that checkpoints with a partially satisfied fan-in barrier and verifies buffered contributions are released after resume.
  • Exposed edge-state export/import on InProcessRunnerContext.
  • Updated InProcessRunner to use RunContext for edge-state serialization during checkpoint/restore.

Reviewed changes

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

File Description
dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/CheckpointResumeTests.cs Adds a regression test and local executors/events to validate fan-in barrier buffering across resume.
dotnet/src/Microsoft.Agents.AI.Workflows/InProc/InProcessRunnerContext.cs Adds context-level methods to export/import edge state with checkpoint lifecycle checks.
dotnet/src/Microsoft.Agents.AI.Workflows/InProc/InProcessRunner.cs Routes checkpoint/restore edge-state handling through RunContext instead of a runner-owned EdgeMap.

Workflow workflow = new WorkflowBuilder(beforePause)
.AddEdge(beforePause, requestPort)
.AddEdge(requestPort, afterResume)
.AddFanInBarrierEdge([beforePause, afterResume], sink)
Comment on lines +585 to +586
private ValueTask HandleAsync(ApprovalReply reply, IWorkflowContext ctx)
=> ctx.SendMessageAsync(new BarrierContribution("after"), sinkId);
Comment on lines +414 to +426
internal ValueTask<Dictionary<EdgeId, PortableValue>> ExportEdgeStateAsync()
{
this.CheckEnded();

return this._edgeMap.ExportStateAsync();
}

internal ValueTask ImportEdgeStateAsync(Checkpoint checkpoint)
{
this.CheckEnded();

return this._edgeMap.ImportStateAsync(checkpoint);
}
@he-yufeng he-yufeng force-pushed the fix/fanin-barrier-checkpoint branch from 4ed6147 to b0bbb9f Compare June 12, 2026 11:08
@he-yufeng

Copy link
Copy Markdown
Contributor Author

Rebased onto current main; no code changes beyond replaying the existing commit.

Validated locally on Windows with the focused checkpoint regression:

dotnet test --project ./tests/Microsoft.Agents.AI.Workflows.UnitTests/Microsoft.Agents.AI.Workflows.UnitTests.csproj -f net10.0 -c Debug -v Normal --report-xunit-trx --ignore-exit-code 8 --filter-method "*Checkpoint_Resume_PreservesFanInBarrierBufferedMessagesAsync"
dotnet test --project ./tests/Microsoft.Agents.AI.Workflows.UnitTests/Microsoft.Agents.AI.Workflows.UnitTests.csproj -f net472 -c Debug -v Normal --report-xunit-trx --ignore-exit-code 8 --filter-method "*Checkpoint_Resume_PreservesFanInBarrierBufferedMessagesAsync"
git diff --check upstream/main..HEAD

Both target frameworks passed the focused test (2 theory cases each).

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: [Bug]: Fan-in barrier (AddFanInBarrierEdge) loses buffered messages across checkpoint/resume

3 participants