Skip to content

.NET: fix(dotnet): reset compiled workflow state between runs - #9540

Merged
Vincent Biret (baywet) merged 6 commits into
mainfrom
fix/compiled-workflow-session-reset
Oct 19, 2026
Merged

Vincent Biret (baywet) merged 6 commits into
mainfrom
fix/compiled-workflow-session-reset

Conversation

@baywet

@baywet Vincent Biret (baywet) commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

Motivation & Context

Compiled declarative workflows should restore their initial formula state when reset and resolve their backend conversation consistently with the declarative interpreter.

Description & Review Guide

  • What are the major changes? Capture the initialized formula state, restore it in the root executor's reset hook, and resolve the conversation from current workflow state before falling back to the configured conversation or creating one. Restore the compiled formula session through registered callbacks before invoking subclass checkpoint post-load hooks, and copy the conversation record before updating its ID. Shared-session registrations are coordinated once per checkpoint load, including subsequent live restores. Cache a newly created conversation within the run so a failed state write can be retried without another allocation; clear that cache on reset. Restore checkpointed environment values and their sensitivity metadata only for names in the compiled workflow's current allowlist.
  • What is the impact of these changes? Reused workflows start with their initial state, including the nested conversation ID. Checkpoint resume and live restore reload persisted formula values, metadata, and conversation state, including allowed environment bindings for both reused and newly built compiled workflows. Restoration completes before subclass hooks run, even when existing overrides do not call base. Named scopes continue sharing action-written values across executors. Interpreter initialization and environment restoration are unchanged. Ordinary restoration callbacks retain per-executor registration order. Explicitly configured conversations remain supported, and repeated inputs within one run reuse its conversation. The new protected Executor.RegisterCheckpointRestoringCallback overloads are recorded in every target framework's API baseline; existing virtual hook signatures and subclass overrides remain unchanged.
  • What do you want reviewers to focus on? Reset lifecycle behavior, initialized system values, and preservation of configured and within-run conversation behavior.

Container validation with .NET SDK 10.0.402, from dotnet:

  • dotnet run --project tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests -f net10.0 --no-build --no-restore -- --filter-class '*RootExecutorTests': before the initial fix, 5 failed and 2 passed; afterward, all 8 passed.
  • dotnet run --project tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests -f net10.0 --no-restore -- --filter-class '*RootExecutorTests': checkpoint/reset, retry, environment, and subclass-hook regressions failed before their respective fixes. The live-restore follow-up reproduced two failures before its fix (18 passed); all 20 focused cases passed afterward. The action-writer/reader cases with base chaining already passed before the subclass-hook follow-up.
  • dotnet run --project tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests -f net10.0 --no-restore: all 1,159 passed, including current-allowlist filtering, cross-action values, and live restoration of values, metadata, conversation state, and expression results.
  • dotnet run --project tests/Microsoft.Agents.AI.Workflows.UnitTests -f net10.0 --no-restore -- --filter-class '*CheckpointResumeTests': all 27 passed, including asynchronous restoration barriers and once-per-load shared callbacks in off-thread and lockstep execution.
  • dotnet run --project tests/Microsoft.Agents.AI.Workflows.UnitTests -f net10.0 --no-restore: all 865 passed.
  • dotnet format src/Microsoft.Agents.AI.Workflows --no-restore --include /repo/dotnet/src/Microsoft.Agents.AI.Workflows/Executor.cs /repo/dotnet/src/Microsoft.Agents.AI.Workflows/InProc/InProcessRunnerContext.cs: passed.
  • dotnet format src/Microsoft.Agents.AI.Workflows.Declarative --no-restore --include /repo/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/Kit/RootExecutor.cs /repo/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/Kit/ActionExecutor.cs /repo/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/PowerFx/WorkflowFormulaState.cs: passed.
  • dotnet format tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests --no-restore --include /repo/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/Kit/RootExecutorTests.cs: passed.
  • dotnet format tests/Microsoft.Agents.AI.Workflows.UnitTests --no-restore --include /repo/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/CheckpointResumeTests.cs: passed.
  • dotnet build src/Microsoft.Agents.AI.Workflows.Declarative --no-restore --tl:off: passed for net10.0, net9.0, net8.0, netstandard2.0, and net472, with 40 container SourceLink/repository-location warnings.

Packages were restored from an existing local cache because the container could not connect to NuGet. Online package auditing and the full repository test suite were not run locally.

Related Issue

N/A - maintainer-directed bugfix; no public issue linked. Open pull requests were checked for competing changes.

AI Assistance

  • No material AI assistance was used.
  • This is an AI-assisted contribution. I reviewed, understood, and verified all submitted content and accept responsibility for it.

AI assistance details: Implementation, regression tests, validation, and this PR description.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR links to an agreed issue with no competing open PR, or the Related Issue section documents a trivial-change or repository-automation exception.
  • This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 12f29503-c7ae-410b-a598-d0ba4e8e937b
Copilot AI balanced review requested due to automatic review settings October 19, 2026 15:11
@agent-framework-automation agent-framework-automation Bot added .NET Usage: [Issues, PRs], Target: .Net workflows Usage: [Issues, PRs], Target: Workflows labels Oct 19, 2026
@github-actions github-actions Bot changed the title fix(dotnet): reset compiled workflow state between runs .NET: fix(dotnet): reset compiled workflow state between runs Oct 19, 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.

🟡 Changes recommended

Checkpoint restoration and mutable snapshot isolation remain unresolved.

2 open issues
What changed in this PR

Updates compiled declarative workflows to reset formula state between runs and resolve conversations consistently with the interpreter.

Changes:

  • Captures initialized state and restores it on reset.
  • Resolves conversations from current state before configured or newly created conversations.
  • Adds reset and conversation-reuse regression tests.
File Description
dotnet/​tests/​Microsoft.Agents.AI.Workflows.Declarative.UnitTests/​Kit/​RootExecutorTests.cs Adds state-reset and conversation lifecycle tests.
dotnet/​src/​Microsoft.Agents.AI.Workflows.Declarative/​Kit/​RootExecutor.cs Implements state reset and per-run conversation resolution.

Review effort: Balanced

@github-code-quality

github-code-quality Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Code coverage overview

Languages: C#

C# / code-coverage/dotnet

main c01db29 fix/compiled-workflo... 0944a48 +/-
86% 86% 0%
View coverage of the 6 most impacted files.
File main c01db29 fix/compiled-workflo... 0944a48 +/-
/home/runner/wo...SessionStore.cs 100% 53% -47%
/home/runner/wo...unnerContext.cs 92% 92% 0%
/home/runner/wo...ows/Executor.cs 100% 100% 0%
/home/runner/wo...FormulaState.cs 96% 97% +1%
/home/runner/wo...tionExecutor.cs 36% 58% +22%
/home/runner/wo...RootExecutor.cs 67% 92% +25%

ℹ️ Calculations represent line coverage. Results may change as calculations are updated.


Updated October 19, 2026 18:10 UTC

@github-actions github-actions Bot 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.

MAF Automated Review — Iteration 1

Result: Findings reported
Scope: full PR (1 commit(s)): 642b85e46e8f
Model: gpt-5.6-sol

Overview

The PR captures initialized formula state, restores it when a workflow releases ownership, and resolves conversations from current run state before falling back to configuration or allocation. The reset lifecycle and added tests provide strong coverage for scalar values, sensitivities, configured conversations, and within-run reuse. Residual risks remain around checkpoint restoration, unreclaimed per-run backend conversations, and failed persistence immediately after conversation creation.

Reviewed the supplied pull-request change set across correctness, security/reliability, architecture, and failure behavior.
3 verified findings remained after source verification (2 high, 1 medium) across 1 file. Details are attached to the affected lines below.

Affected areas: dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/Kit/RootExecutor.cs

Comment thread dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/Kit/RootExecutor.cs Outdated
Comment thread dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/Kit/RootExecutor.cs Outdated
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 12f29503-c7ae-410b-a598-d0ba4e8e937b

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.

🟡 Changes recommended

Checkpoint resume after disposal still loses initialized environment formula values and their sensitivity metadata.

1 open issue
2 resolved since last review

Review effort: Balanced

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 12f29503-c7ae-410b-a598-d0ba4e8e937b
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 12f29503-c7ae-410b-a598-d0ba4e8e937b

@github-actions github-actions Bot 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.

MAF Automated Review — Iteration 2

Result: Findings reported
Scope: 3 net-new commit(s): 9cbb89b49952, f9ed58b4242d, 5c63547718f3
Model: gpt-5.6-sol

Overview

The change adds initial-state reset, checkpoint restoration, current-allowlist filtering for environment values, and per-run conversation reuse, with focused tests for each behavior. Copying the conversation record and caching a newly allocated ID provide concrete guards against snapshot aliasing and retry leaks. However, checkpoint state is stored per executor while the shared formula session admits only one nondeterministic restore callback, and existing subclasses can bypass the new restoration by overriding the previously no-op lifecycle hook.

Reviewed the supplied incremental change set across correctness, security/reliability, architecture, and failure behavior.
2 verified findings remained after source verification (1 high, 1 medium) across 2 files. Details are attached to the affected lines below.

Affected areas: dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/Kit/ActionExecutor.cs, dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/Kit/RootExecutor.cs

Comment thread dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/Kit/ActionExecutor.cs Outdated
Comment thread dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/Kit/RootExecutor.cs Outdated
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 12f29503-c7ae-410b-a598-d0ba4e8e937b

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.

🟡 Changes recommended

Subsequent live checkpoint restores skip formula-session restoration, leaving expressions and hooks with stale state.

1 open issue

Review effort: Balanced

Comment thread dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/Kit/RootExecutor.cs Outdated
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 12f29503-c7ae-410b-a598-d0ba4e8e937b

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.

🔵 Needs a closer look

New protected lifecycle APIs and cross-executor checkpoint restoration ordering warrant final maintainer review.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@baywet
Vincent Biret (baywet) added this pull request to the merge queue Oct 19, 2026
Merged via the queue into main with commit 809cc04 Oct 19, 2026
38 checks passed
@baywet
Vincent Biret (baywet) deleted the fix/compiled-workflow-session-reset branch October 19, 2026 20:17

This branch was successfully deployed

2 active deployments
integration — 0944a48b Deployed Oct 19, 2026 by baywet via dotnet-foundry-hosted-it #30714
github-app-auth — 0944a48b Deployed Oct 19, 2026 by baywet via add_label #25766
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

None yet

Development

Successfully merging this pull request may close these issues.

3 participants