Repository navigation
Allow several initial steps - #171
Merged
Merged
Conversation
More than one step can now set `initial true`. AddStateMachine passes every initial step to `initial_states` and keeps the first as `default_initial_state`, so a create action starts a record in another initial step with `change transition_state(:step)`. ValidateWorkflow checks reachability from every initial step, and Info.initial_steps/1, workflow_graph/1, the charts and the Clarity overview mark each one.
…-steps # Conflicts: # CHANGELOG.md
C-Sinclair
marked this pull request as ready for review
November 16, 2026 15:25
ValidateWorkflow now rejects a create whose transition_state names a step that is not initial, an initial step after the first that no create names, and an upserting create that calls transition_state. ash_state_machine only lets an upsert move to a state that a transition declares for that action, and a workflow declares none for creates. The unreachable-step error suggests `initial true` for a step that no other step leads into.
The verifier only read transition_state, so it rejected resources that start a record with set_attribute, accept or a custom change. ValidateWorkflow now checks an upserting create before exempting a non-literal target, so transition_state(arg(:start)) on an upsert is also rejected.
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.
initial truecan now be set on more than one step.ValidateWorkflowno longer rejects a second initial step. It still rejects a terminal step marked initial.AddStateMachinepasses every initial step to ash_state_machine'sinitial_statesand setsdefault_initial_stateto the first by declaration order. A create action that sets no state starts in that default step. Any other create names its start withchange transition_state(:step), and ash_state_machine rejects a step that is not marked initial.ValidateWorkflowstarts from every initial step. A step reached only from a second initial step now compiles.Info.initial_steps/1andStep.find_initials/1list the initial steps.Info.initial_step/1andStep.find_initial/1keep their names and return the default initial step, so existing callers do not change.ValidateWorkflowchecks the create actions at compile time. It rejects a create whosetransition_statenames a step that is not initial.transition_state, andValidateWorkflowrejects one that does. ash_state_machine only lets an upsert move to a state that a transition declares for that action, and a workflow declares none for creates. An upsert onto an existing record keeps its current step.Info.workflow_graph/1setsinitial: trueon every initial step. Mermaid and DOT charts draw a start edge to each one, and the Clarity workflow overview lists them all.stateDiagram-v2 [*] --> self_service_intake [*] --> staff_intake self_service_intake --> review: submit staff_intake --> review: submit review --> done: approve done --> [*]The unreachable-step error now reads "not reachable from the initial step :review" in place of "the first step". With several initial steps it lists them: "not reachable from any initial step [:a, :b]". The error also suggests
initial truefor an unreachable step that no other step leads into.