Skip to content

.NET: Add error checking to workflow samples#5175

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/add-error-checking-workflow-samples
Draft

.NET: Add error checking to workflow samples#5175
Copilot wants to merge 3 commits intomainfrom
copilot/add-error-checking-workflow-samples

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 8, 2026

Motivation and Context

Workflow samples silently swallow WorkflowErrorEvent and ExecutorFailedEvent events — if an agent or executor fails mid-workflow, the sample loop exits cleanly with no indication of what went wrong. Fixes #[issue].

Description

Added WorkflowErrorEvent and ExecutorFailedEvent handling to all 20 workflow samples in dotnet/samples/03-workflows/ that lacked it. This covers both streaming (WatchStreamAsync) and non-streaming (NewEvents) loops, across switch and if/else if patterns.

Error output pattern applied consistently:

else if (evt is WorkflowErrorEvent workflowError)
{
    Console.ForegroundColor = ConsoleColor.Red;
    Console.Error.WriteLine(workflowError.Exception?.ToString() ?? "Unknown workflow error occurred.");
    Console.ResetColor();
}
else if (evt is ExecutorFailedEvent executorFailed)
{
    Console.ForegroundColor = ConsoleColor.Red;
    Console.Error.WriteLine($"Executor '{executorFailed.ExecutorId}' failed with {(executorFailed.Data == null ? "unknown error" : $"exception {executorFailed.Data}")}.");
    Console.ResetColor();
}

Consistent with the existing pattern already used in Concurrent/Concurrent and Agents/CustomAgentExecutors.

Files updated (20): _StartHere/01–03, 05–07, Agents/FoundryAgent, Agents/GroupChatToolApproval, Checkpoint/CheckpointAndRehydrate, Checkpoint/CheckpointAndResume, Checkpoint/CheckpointWithHumanInTheLoop, Concurrent/MapReduce, ConditionalEdges/01–03, HumanInTheLoop/HumanInTheLoopBasic, Loop, Observability/ApplicationInsights, Observability/AspireDashboard, SharedStates.

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 changed the title [WIP] Fix silent failure in AgentsInWorkflow sample by adding error checking .NET: Add error checking to workflow samples Apr 8, 2026
Copilot AI requested a review from lokitoth April 8, 2026 19:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.NET: [Bug]: Workflow Foundational Sample 03_AgentsInWorkflow will fail silently if the agent fails

2 participants