Fixed: Workflow must only consist of cross-run share-capable or factory-created executors
I switched a Microsoft Agent Framework workflow to InProcessExecution.Concurrent so three requests could share it, and all three runs failed at once with InvalidOperationException: Workflow must only consist of cross-run share-capable or factory-created executors. Executors not supporting concurrent: Greet. Concurrent runs need every executor declared shareable or created by a factory, and one constructor argument fixed it.
What I Was Doing
ConcurrentGreetings is a small console app that runs one workflow for three requests at the same time, for Ana, Ben and Chen. The workflow has one step, Greet, a class-based executor that waits one second, as a call to a model or another service would, and returns a greeting. With the default InProcessExecution.RunAsync, only the first of the three runs could use the workflow: the other two were refused because the first run owned it.
Microsoft's Workflow Execution Modes page describes an environment for exactly this case: OffThread also supports a concurrent variant that allows multiple runs to share the same workflow instance simultaneously. So I changed the line that starts each run to InProcessExecution.Concurrent.RunAsync, and left the executor as it was:
using System.Diagnostics;
using Microsoft.Agents.AI.Workflows;
GreetExecutor greet = new();
Workflow workflow = new WorkflowBuilder(greet).WithOutputFrom(greet).Build();
string[] names = ["Ana", "Ben", "Chen"];
Stopwatch stopwatch = Stopwatch.StartNew();
// Three requests arrive at the same time, and all three run the one workflow.
await Task.WhenAll(names.Select(async name =>
{
try
{
await using Run run = await InProcessExecution.Concurrent.RunAsync(workflow, name);
foreach (WorkflowEvent workflowEvent in run.OutgoingEvents)
{
if (workflowEvent is WorkflowOutputEvent output)
{
Console.WriteLine($"{stopwatch.Elapsed.TotalSeconds:0.00} s {output.Data}");
}
}
}
catch (Exception exception)
{
Console.WriteLine($"{stopwatch.Elapsed.TotalSeconds:0.00} s {name}: {exception.GetType().Name}: {exception.Message}");
}
}));
// A step that takes a second, like a call to a model or another service.
internal sealed partial class GreetExecutor() : Executor("Greet")
{
[MessageHandler]
private async ValueTask<string> HandleAsync(string name, IWorkflowContext context, CancellationToken cancellationToken)
{
await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken);
return $"Hello, {name}!";
}
}
The app prints how many seconds after the start each result, or each exception, arrived.
What I Expected
Three greetings about one second after the start, now that the runs could share the workflow.
What I Got
dotnet run
0.01 s Ana: InvalidOperationException: Workflow must only consist of cross-run share-capable or factory-created executors. Executors not supporting concurrent: Greet
0.02 s Ben: InvalidOperationException: Workflow must only consist of cross-run share-capable or factory-created executors. Executors not supporting concurrent: Greet
0.02 s Chen: InvalidOperationException: Workflow must only consist of cross-run share-capable or factory-created executors. Executors not supporting concurrent: Greet

This time no run worked, not even Ana's. All three failed within 0.02 seconds of the start, before any greeting, and every message ends with the same executor: Greet.
What I Checked
The executor the message names. Greet is the only executor in the workflow, and its class passes nothing to the base constructor except its id: Executor("Greet").
The Executor constructor. In Agent Framework 1.28 it's Executor(string id, ExecutorOptions? options = null, bool declareCrossRunShareable = false). Its documentation describes the third parameter: Declare that this executor may be used simultaneously by multiple runs safely. Left at its default, false, it means Greet wasn't declared shareable.
What the concurrent environment requires. The Workflow Execution Modes page says it in a note: Concurrent execution requires that all executors in the workflow be declared crossRunShareable (on the constructor) or be provided as factory methods. Greet was neither.
Whether Greet can be shared. Its handler uses only the name it receives and keeps nothing in fields, so one instance can serve several runs at once. The declaration would be true for it.
Why It Happens
InProcessExecution.Concurrent lets several runs use one workflow instance at the same time, and with it the same executor instances. It allows that only for executors declared shareable, or created by a factory. Greet was neither, so every run was refused before its step could finish, and the message lists the executor that blocked it.
The Fix
Declare the executor shareable, with declareCrossRunShareable: true in the call to the base constructor:
// A step that takes a second, like a call to a model or another service. It keeps nothing
// in its fields, so one instance can serve several runs at the same time.
internal sealed partial class GreetExecutor() : Executor("Greet", declareCrossRunShareable: true)
{
[MessageHandler]
private async ValueTask<string> HandleAsync(string name, IWorkflowContext context, CancellationToken cancellationToken)
{
await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken);
return $"Hello, {name}!";
}
}
The run line stays InProcessExecution.Concurrent.RunAsync(workflow, name).
When an executor does keep data in fields, don't declare it shareable. Give each run its own instance with a factory instead, the other option the note names: the guide to running one workflow for many requests at once shows both.
After the Fix
dotnet run
1.05 s Hello, Ana!
1.05 s Hello, Ben!
1.05 s Hello, Chen!

All three greetings arrived 1.05 seconds after the start. The three runs used the one workflow, and its one Greet instance, at the same time.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Switching to InProcessExecution.Concurrent with executors left at the default | Every run throws this exception | Pass declareCrossRunShareable: true, or create the executor with a factory |
| Declaring only some of the workflow's executors | The requirement covers all of them, so the runs are still refused | Declare, or create with a factory, every executor in the workflow |
| Declaring an executor shareable while it keeps data in fields | Every run uses the same instance, and with it the same fields | Create it with a factory, so each run gets its own |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
Every run fails at once, and the message names an executor after Executors not supporting concurrent: | That executor isn't declared shareable or created by a factory | Declare it with declareCrossRunShareable: true, or create it with a factory |
| Only the first of several simultaneous runs works | The runs use InProcessExecution.RunAsync, the default mode | Use InProcessExecution.Concurrent |
FAQ
What about executors made from functions?
BindAsExecutor, which turns a function into an executor, has a threadsafe parameter for the same purpose. Its documentation: Declare that the message handler may be used simultaneously by multiple runs concurrently.
Why didn't even the first run work this time?
Because the message is about the workflow, not about which run came first. In the concurrent environment, a workflow with an executor that can't be shared was refused for every run, Ana's included.
Conclusion
Workflow must only consist of cross-run share-capable or factory-created executors. comes from InProcessExecution.Concurrent when an executor in the workflow is neither declared shareable nor created by a factory, and the message names that executor after Executors not supporting concurrent:. Pass declareCrossRunShareable: true to the executor's base constructor when it keeps nothing in fields, or create it with a factory when it does.
Additional Resources
- Workflow Execution Modes — the concurrent variant, and its requirement for shareable or factory-created executors.
- Resettable Executors — when an executor needs resetting, with the cross-run shareable and factory cases.
