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

* Fix bug to emit WorkflowStartedEvent during workflow execution

* Updated based on PR comments
This commit is contained in:
Peter Ibekwe
2026-03-12 15:45:17 +00:00
committed by GitHub
parent bcb55b4a98
commit aa2ff672fb
3 changed files with 79 additions and 2 deletions
@@ -72,6 +72,9 @@ internal sealed class LockstepRunEventStream : IRunEventStream
this.RunStatus = RunStatus.Running;
runActivity?.AddEvent(new ActivityEvent(EventNames.WorkflowStarted));
// Emit WorkflowStartedEvent to the event stream for consumers
eventSink.Enqueue(new WorkflowStartedEvent());
do
{
while (this._stepRunner.HasUnprocessedMessages &&
@@ -88,9 +88,16 @@ internal sealed class StreamingRunEventStream : IRunEventStream
// Run all available supersteps continuously
// Events are streamed out in real-time as they happen via the event handler
while (this._stepRunner.HasUnprocessedMessages && !linkedSource.Token.IsCancellationRequested)
if (this._stepRunner.HasUnprocessedMessages)
{
await this._stepRunner.RunSuperStepAsync(linkedSource.Token).ConfigureAwait(false);
// Emit WorkflowStartedEvent only when there's actual work to process
// This avoids spurious events on timeout-only loop iterations
await this._eventChannel.Writer.WriteAsync(new WorkflowStartedEvent(), linkedSource.Token).ConfigureAwait(false);
while (this._stepRunner.HasUnprocessedMessages && !linkedSource.Token.IsCancellationRequested)
{
await this._stepRunner.RunSuperStepAsync(linkedSource.Token).ConfigureAwait(false);
}
}
// Update status based on what's waiting