.NET: Fix to emit WorkflowStartedEvent during workflow execution#4514
.NET: Fix to emit WorkflowStartedEvent during workflow execution#4514
Conversation
There was a problem hiding this comment.
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
WorkflowStartedEventinto the streaming event stream in off-thread execution. - Emit
WorkflowStartedEventinto the streaming event stream in lockstep execution. - Add unit tests validating
WorkflowStartedEventemission and relative ordering vsSuperStepStartedEvent.
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. |
dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/AgentEventsTests.cs
Outdated
Show resolved
Hide resolved
dotnet/src/Microsoft.Agents.AI.Workflows/Execution/StreamingRunEventStream.cs
Outdated
Show resolved
Hide resolved
| // Emit WorkflowStartedEvent to the event stream for consumers | ||
| eventSink.Enqueue(new WorkflowStartedEvent()); |
There was a problem hiding this comment.
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).
| // 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(); |
Description
Fix bug to emit
WorkflowStartedEventduring workflow execution.Fixes #3789
Contribution Checklist