.NET: Fix off-thread RunStatus race where GetStatusAsync can return Running after ResumeAsync halts#5412
Open
.NET: Fix off-thread RunStatus race where GetStatusAsync can return Running after ResumeAsync halts#5412
Conversation
… after ResumeAsync halts
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a race in the off-thread workflow run loop where RunStatus could transiently flip back to Running after a halt had already been observed, and adds a stress regression test to prevent reintroduction.
Changes:
- Update
StreamingRunEventStream.RunLoopAsyncto setRunStatus.Runningonly when there are unprocessed messages to run. - Add an off-thread stress regression test that repeatedly runs the Step9 sample to catch the previously intermittent status race.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| dotnet/src/Microsoft.Agents.AI.Workflows/Execution/StreamingRunEventStream.cs | Prevents stale input signals from transiently setting RunStatus back to Running when there is no work to process. |
| dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/SampleSmokeTest.cs | Adds a stress regression test targeting the Step9 multi-response resume scenario in off-thread execution. |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
SergeyMenshykh
approved these changes
Apr 22, 2026
westey-m
approved these changes
Apr 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation and Context
In
StreamingRunEventStream.RunLoopAsync, after every_inputWaiter.WaitForInputAsyncwake-up,_runStatuswas being flipped toRunningunconditionally. This can lead stale signal to flip status back to running after consumer already observed halt signal.Fixes #5411
Description
Only flip
RunStatustoRunningwhen there are messages to process.LockstepRunEventStreamis not affected — it runs supersteps synchronously on the consumer thread and has no comparable wake-up race.This addresses one of the intermittent workflow test failures in the pipeline.
Contribution Checklist