Skip to content

Conversation

@mclift
Copy link
Member

@mclift mclift commented Sep 8, 2025

This PR is for issue #629 in which a parent state transition is ignored when:

  • the child state has a transition configured with the same trigger;
  • the child state's transition has an unmet guard condition;
  • the parent state's transition does not have unmet guard conditions;
  • the child state is the current state;
  • the trigger is fired using FireAsync.

When the synchronous call to Fire is used instead, it selects the nearest ancestor that has a transition with no unmet guard conditions.

This PR also includes some housekeeping changes:

  • Removed unused #if TASKS directives.
  • Changed test method signatures in AsyncFiringModesFixture from void to async Task.
  • Split TransitionTests into sync and async test classes.

@mclift mclift requested a review from Copilot September 8, 2025 21:26
Copy link

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

This PR fixes an issue where async superstate transitions are ignored when a child state has an unmet guard condition, ensuring consistent behavior between synchronous and asynchronous state machine firing.

  • Fixes the async transition handler logic to properly check for unmet guard conditions before falling back to parent state transitions
  • Removes unused #if TASKS preprocessor directives throughout the codebase
  • Restructures tests by splitting sync and async transition tests into separate classes

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
test/Stateless.Tests/TransitionTests.cs Removes async test method and adds comprehensive sync guard condition tests
test/Stateless.Tests/AsyncTransitionTests.cs New file containing async versions of transition tests to verify the fix
test/Stateless.Tests/AsyncFiringModesFixture.cs Updates method signatures to async Task and removes unused preprocessor directive
test/Stateless.Tests/AsyncActionsFixture.cs Removes unused #if TASKS preprocessor directives
src/Stateless/StateRepresentation.Async.cs Core fix: improves guard condition checking logic in async transition handling
src/Stateless/StateMachine.Async.cs Removes preprocessor directives and adds missing braces for parameter validation
src/Stateless/StateConfiguration.Async.cs Removes unused #if TASKS preprocessor directives
src/Stateless/OnTransitionedEvent.cs Removes unused #if TASKS preprocessor directives

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@mclift
Copy link
Member Author

mclift commented Sep 8, 2025

@MattVane @RedOrc review comments welcomed!

Copy link
Contributor

@RedOrc RedOrc left a comment

Choose a reason for hiding this comment

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

Looks good to me :-)

@mclift
Copy link
Member Author

mclift commented Sep 10, 2025

I'll get this merged to dev so a pre-release package gets generated.

@mclift mclift merged commit 58afa5e into dotnet-state-machine:dev Sep 10, 2025
1 check passed
@mclift mclift deleted the bugfix/629-async-superstate-transition-ignored branch September 10, 2025 17:10
@mclift mclift mentioned this pull request Sep 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants