mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
.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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user