Skip to content

Fix SCXML state action ordering - #31

Merged
JovaniPink merged 1 commit into
masterfrom
scxml-action-ordering
Jul 21, 2026
Merged

Fix SCXML state action ordering#31
JovaniPink merged 1 commit into
masterfrom
scxml-action-ordering

Conversation

@JovaniPink

Copy link
Copy Markdown
Owner

Summary

  • execute state entry actions in parser document order
  • execute state exit actions in reverse document order
  • remove the two unresolved ordering TODOs from the SCXML algorithm core
  • add observable regressions for nested transitions and parallel regions declared in both orders
  • record the correctness fix in the existing untagged 0.7.0 changelog entry

Why

The entry and exit sets are intentionally represented as sets while they are computed. Iterating those sets directly made side-effect ordering depend on Python object iteration rather than statechart document order.

SCXML requires deterministic ordering: ancestors and earlier document states enter first, while descendants and later document states exit first. This is observable whenever states declare entry or exit actions, especially across parallel regions.

Behavior covered

  • nested external transition: child exit, parent exit, transition action, target entry
  • parallel entry: enclosing state, first declared region and leaf, then second declared region and leaf
  • parallel exit: second declared region and leaf exit before the first, then enclosing state
  • both parallel region declaration orders produce the corresponding deterministic trace

Scope

This changes only state action ordering inside the existing microstep algorithm. Transition selection, transition domains, context updates, handler adaptation, snapshots, and public APIs are unchanged.

Validation

  • poetry run python -m pytest tests/test_action_ordering.py -q (5 passed)
  • poetry run python -m pytest tests/ --ignore=tests/test_scxml.py (402 passed)
  • poetry run python -m pytest tests/test_scxml.py (54 passed)
  • poetry run mypy src/xstate/
  • poetry run ruff format --check src/ tests/ docs/examples/
  • poetry run ruff check src/ tests/ docs/examples/
  • git diff --check

@JovaniPink
JovaniPink merged commit 53fd7a3 into master Jul 21, 2026
4 checks passed
@JovaniPink
JovaniPink deleted the scxml-action-ordering branch July 21, 2026 15:47

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request ensures that state entry actions run in document order and exit actions run in reverse document order, including nested and parallel configurations. This is achieved by sorting the states to enter and exit by their order attribute in src/xstate/algorithm.py. Additionally, a new test file tests/test_action_ordering.py has been added to verify these ordering behaviors. No review comments were provided, and the implementation is clean and well-tested.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

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.

1 participant