Skip to content

.NET: Fix to emit WorkflowStartedEvent during workflow execution#4514

Open
peibekwe wants to merge 3 commits intomainfrom
peibekwe/workflow-event-fix
Open

.NET: Fix to emit WorkflowStartedEvent during workflow execution#4514
peibekwe wants to merge 3 commits intomainfrom
peibekwe/workflow-event-fix

Conversation

@peibekwe
Copy link
Contributor

@peibekwe peibekwe commented Mar 6, 2026

Description

Fix bug to emit WorkflowStartedEvent during workflow execution.
Fixes #3789

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.

@peibekwe peibekwe self-assigned this Mar 6, 2026
@markwallace-microsoft markwallace-microsoft added .NET workflows Related to Workflows in agent-framework labels Mar 6, 2026
@github-actions github-actions bot changed the title Fix to emit WorkflowStartedEvent during workflow execution .NET: Fix to emit WorkflowStartedEvent during workflow execution Mar 6, 2026
@peibekwe peibekwe marked this pull request as ready for review March 6, 2026 18:57
Copilot AI review requested due to automatic review settings March 6, 2026 18:57
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a .NET workflows bug where WorkflowStartedEvent was not emitted to streaming consumers during workflow execution (issue #3789), and adds regression tests to verify the event is produced.

Changes:

  • Emit WorkflowStartedEvent into the streaming event stream in off-thread execution.
  • Emit WorkflowStartedEvent into the streaming event stream in lockstep execution.
  • Add unit tests validating WorkflowStartedEvent emission and relative ordering vs SuperStepStartedEvent.

Reviewed changes

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

File Description
dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/AgentEventsTests.cs Adds regression tests for WorkflowStartedEvent emission and ordering.
dotnet/src/Microsoft.Agents.AI.Workflows/Execution/StreamingRunEventStream.cs Writes WorkflowStartedEvent into the channel at the start of each run-loop iteration.
dotnet/src/Microsoft.Agents.AI.Workflows/Execution/LockstepRunEventStream.cs Enqueues WorkflowStartedEvent at the start of lockstep streaming.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

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

Comment on lines +75 to +76
// Emit WorkflowStartedEvent to the event stream for consumers
eventSink.Enqueue(new WorkflowStartedEvent());
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In lockstep mode, WorkflowStartedEvent is only enqueued into the local eventSink here, but the sink is drained/yielded only after a RunSuperStepAsync completes. If the first RunSuperStepAsync throws (or the iterator exits before draining), consumers may never observe WorkflowStartedEvent. To make the event reliable and consistent with StreamingRunEventStream, emit/yield the WorkflowStartedEvent before entering the first superstep execution (and ensure it is only emitted once per run cycle).

Suggested change
// Emit WorkflowStartedEvent to the event stream for consumers
eventSink.Enqueue(new WorkflowStartedEvent());
// Emit WorkflowStartedEvent directly so it is observed even if the first superstep fails
yield return new WorkflowStartedEvent();

Copilot uses AI. Check for mistakes.
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]: The WorkflowStartedEvent will not be triggered.

3 participants