Skip to content

.NET: fix: mcp workflow isolation - #9545

Open
Vincent Biret (baywet) wants to merge 4 commits into
mainfrom
fix/mcp-workflow-session-isolation-dotnet
Open

Vincent Biret (baywet) wants to merge 4 commits into
mainfrom
fix/mcp-workflow-session-isolation-dotnet

Conversation

@baywet

Copy link
Copy Markdown
Member

dotnet part of the #8662 PR

Copilot AI balanced review requested due to automatic review settings October 19, 2026 19:20
@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: mcp workflow isolation .NET: fix: mcp workflow isolation 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

Cache eviction can terminate unfinished workflows’ MCP sessions, breaking continuity and disrupting pending callers.

1 open issue
What changed in this PR

Implements the .NET portion of #8662, isolating declarative MCP sessions by workflow while preserving compatibility with existing handlers.

Changes:

  • Propagates workflow identity through execution contexts and subworkflows.
  • Adds workflow-scoped MCP caching, capacity limits, and coordinated cleanup.
  • Adds isolation, continuation, cancellation, and lifetime tests.
File Description
dotnet/​tests/​Microsoft.Agents.AI.Workflows.UnitTests/​RepresentationTests.cs Tests subworkflow identity and checkpoint compatibility.
dotnet/​tests/​Microsoft.Agents.AI.Workflows.Declarative.UnitTests/​PowerFx/​WorkflowFormulaStateTests.cs Tests persisted fallback identity.
dotnet/​tests/​Microsoft.Agents.AI.Workflows.Declarative.UnitTests/​ObjectModel/​InvokeMcpToolExecutorTest.cs Tests scoped invocation and approval handling.
dotnet/​tests/​Microsoft.Agents.AI.Workflows.Declarative.UnitTests/​Kit/​RootExecutorTests.cs Updates context setup.
dotnet/​tests/​Microsoft.Agents.AI.Workflows.Declarative.UnitTests/​Kit/​IWorkflowContextExtensionsTests.cs Updates context creation helpers.
dotnet/​tests/​Microsoft.Agents.AI.Workflows.Declarative.Mcp.UnitTests/​DefaultMcpToolHandlerTests.cs Tests workflow-aware cache keys.
dotnet/​tests/​Microsoft.Agents.AI.Workflows.Declarative.Mcp.UnitTests/​DefaultMcpToolHandlerLifetimeTests.cs Tests cache capacity, concurrency, and cleanup.
dotnet/​src/​Microsoft.Agents.AI.Workflows/​SubworkflowBinding.cs Derives hierarchical session identifiers.
dotnet/​src/​Microsoft.Agents.AI.Workflows/​Specialized/​WorkflowHostExecutor.cs Propagates child workflow identity.
dotnet/​src/​Microsoft.Agents.AI.Workflows/​PublicAPI/​netstandard2.0/​PublicAPI.Unshipped.txt Records session-context API.
dotnet/​src/​Microsoft.Agents.AI.Workflows/​PublicAPI/​net9.0/​PublicAPI.Unshipped.txt Records session-context API.
dotnet/​src/​Microsoft.Agents.AI.Workflows/​PublicAPI/​net8.0/​PublicAPI.Unshipped.txt Records session-context API.
dotnet/​src/​Microsoft.Agents.AI.Workflows/​PublicAPI/​net472/​PublicAPI.Unshipped.txt Records session-context API.
dotnet/​src/​Microsoft.Agents.AI.Workflows/​PublicAPI/​net10.0/​PublicAPI.Unshipped.txt Records session-context API.
dotnet/​src/​Microsoft.Agents.AI.Workflows/​IWorkflowContext.cs Defines optional session identity contract.
dotnet/​src/​Microsoft.Agents.AI.Workflows/​InProc/​InProcessRunnerContext.cs Exposes identity through bound contexts.
dotnet/​src/​Microsoft.Agents.AI.Workflows/​InProc/​InProcessRunner.cs Separates workflow and checkpoint identities.
dotnet/​src/​Microsoft.Agents.AI.Workflows/​GroupChatManager.cs Preserves identity through context wrappers.
dotnet/​src/​Microsoft.Agents.AI.Workflows.Declarative/​PublicAPI/​netstandard2.0/​PublicAPI.Unshipped.txt Records scoped handler contract.
dotnet/​src/​Microsoft.Agents.AI.Workflows.Declarative/​PublicAPI/​net9.0/​PublicAPI.Unshipped.txt Records scoped handler contract.
dotnet/​src/​Microsoft.Agents.AI.Workflows.Declarative/​PublicAPI/​net8.0/​PublicAPI.Unshipped.txt Records scoped handler contract.
dotnet/​src/​Microsoft.Agents.AI.Workflows.Declarative/​PublicAPI/​net472/​PublicAPI.Unshipped.txt Records scoped handler contract.
dotnet/​src/​Microsoft.Agents.AI.Workflows.Declarative/​PublicAPI/​net10.0/​PublicAPI.Unshipped.txt Records scoped handler contract.
dotnet/​src/​Microsoft.Agents.AI.Workflows.Declarative/​ObjectModel/​InvokeMcpToolExecutor.cs Dispatches calls with workflow scope.
dotnet/​src/​Microsoft.Agents.AI.Workflows.Declarative/​Kit/​RootExecutor.cs Creates session-aware contexts.
dotnet/​src/​Microsoft.Agents.AI.Workflows.Declarative/​Kit/​ActionExecutor.cs Creates session-aware contexts.
dotnet/​src/​Microsoft.Agents.AI.Workflows.Declarative/​Interpreter/​DelegateActionExecutor.cs Creates session-aware contexts.
dotnet/​src/​Microsoft.Agents.AI.Workflows.Declarative/​Interpreter/​DeclarativeWorkflowExecutor.cs Creates session-aware contexts.
dotnet/​src/​Microsoft.Agents.AI.Workflows.Declarative/​Interpreter/​DeclarativeWorkflowContext.cs Resolves and persists workflow identity.
dotnet/​src/​Microsoft.Agents.AI.Workflows.Declarative/​Interpreter/​DeclarativeActionExecutor.cs Creates session-aware contexts.
dotnet/​src/​Microsoft.Agents.AI.Workflows.Declarative/​IMcpToolHandler.cs Adds compatible scoped handler interface.
dotnet/​src/​Microsoft.Agents.AI.Workflows.Declarative.Mcp/​PublicAPI/​netstandard2.0/​PublicAPI.Unshipped.txt Records scoped invocation API.
dotnet/​src/​Microsoft.Agents.AI.Workflows.Declarative.Mcp/​PublicAPI/​net9.0/​PublicAPI.Unshipped.txt Records scoped invocation API.
dotnet/​src/​Microsoft.Agents.AI.Workflows.Declarative.Mcp/​PublicAPI/​net8.0/​PublicAPI.Unshipped.txt Records scoped invocation API.
dotnet/​src/​Microsoft.Agents.AI.Workflows.Declarative.Mcp/​PublicAPI/​net472/​PublicAPI.Unshipped.txt Records scoped invocation API.
dotnet/​src/​Microsoft.Agents.AI.Workflows.Declarative.Mcp/​PublicAPI/​net10.0/​PublicAPI.Unshipped.txt Records scoped invocation API.
dotnet/​src/​Microsoft.Agents.AI.Workflows.Declarative.Mcp/​DefaultMcpToolHandler.cs Implements scoped caching and resource lifetimes.

Review effort: Balanced

Comment thread dotnet/src/Microsoft.Agents.AI.Workflows.Declarative.Mcp/DefaultMcpToolHandler.cs Outdated
@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 f7c6928 fix/mcp-workflow-ses... 4236f34 +/-
86% 86% 0%
View coverage of the 10 most impacted files.
File main f7c6928 fix/mcp-workflow-ses... 4236f34 +/-
/home/runner/wo...SessionStore.cs 100% 53% -47%
/home/runner/wo...pToolHandler.cs 88% 83% -5%
/home/runner/wo...rocessRunner.cs 91% 94% +3%
/home/runner/wo...pChatManager.cs 61% 64% +3%
/home/runner/wo...HostExecutor.cs 83% 86% +3%
/home/runner/wo...kflowBinding.cs 90% 93% +3%
/home/runner/wo...pClientCache.cs 0% 98% +98%
/home/runner/wo...lientFactory.cs 0% 100% +100%
/home/runner/wo...ientLifetime.cs 0% 100% +100%
/home/runner/wo...ntConnection.cs 0% 100% +100%

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


Updated October 20, 2026 15:37 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)): 96cbf3c5c41f
Model: gpt-5.6-sol

Overview

The PR propagates a framework-owned workflow session identifier into MCP caching and adds substantial concurrency, cancellation, disposal, provider-isolation, and credential-origin guardrails. The new bounded cache coalesces same-key creation and carefully drains active and retired clients. Residual risks remain for legacy workflow contexts that initialize identity through queued state, for stateful sessions evicted while their workflows are still live, and for unrelated tenants sharing the fixed active-session limit.

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

Affected areas: dotnet/src/Microsoft.Agents.AI.Workflows.Declarative.Mcp/DefaultMcpToolHandler.cs, dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/Interpreter/DeclarativeWorkflowContext.cs

Comment thread dotnet/src/Microsoft.Agents.AI.Workflows.Declarative.Mcp/DefaultMcpToolHandler.cs Outdated
Comment thread dotnet/src/Microsoft.Agents.AI.Workflows.Declarative.Mcp/DefaultMcpToolHandler.cs Outdated
Extract workflow-scoped caching, connection creation, provider lifetime coordination, and resource cleanup from DefaultMcpToolHandler without changing session behavior.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 94e932cb-8d65-4169-8c8b-3b5ceff9d09d
Preserve both workflow session and checkpoint callback API entries. Adapt the merged checkpoint test to the session-aware context factory.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 94e932cb-8d65-4169-8c8b-3b5ceff9d09d
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 94e932cb-8d65-4169-8c8b-3b5ceff9d09d
@baywet

Copy link
Copy Markdown
Member Author

Added proposed ADR 0047 in 2c89515. It documents workflow-owned MCP sessions, factory-managed HTTP handler reuse, caller-owned HTTP clients, active-call draining, approval/checkpoint behavior, examples, alternatives, trade-offs, and potential compatibility and user-experience changes. The proposal is not implemented; this commit adds only the ADR. westey (@westey-m): review requested as a listed decider alongside Vincent Biret (@baywet). Ryan Hurey (@rhurey): informing you for architecture/EM review of the proposed direction.

@agent-framework-automation agent-framework-automation Bot added the documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs label Oct 20, 2026

This branch was successfully deployed

2 active deployments
integration — 2c895157 Deployed Oct 20, 2026 by baywet via dotnet-foundry-hosted-it #30766
github-app-auth — 2c895157 Deployed Oct 20, 2026 by baywet via add_label #25820
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs .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