Skip to content

Allow several initial steps - #171

Merged
C-Sinclair merged 9 commits into
mainfrom
feat/multiple-initial-steps
Nov 20, 2026
Merged

C-Sinclair merged 9 commits into
mainfrom
feat/multiple-initial-steps

Conversation

@C-Sinclair

@C-Sinclair C-Sinclair commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor
  • initial true can now be set on more than one step. ValidateWorkflow no longer rejects a second initial step. It still rejects a terminal step marked initial.
  • AddStateMachine passes every initial step to ash_state_machine's initial_states and sets default_initial_state to the first by declaration order. A create action that sets no state starts in that default step. Any other create names its start with change transition_state(:step), and ash_state_machine rejects a step that is not marked initial.
  • The reachability check in ValidateWorkflow starts from every initial step. A step reached only from a second initial step now compiles.
  • Info.initial_steps/1 and Step.find_initials/1 list the initial steps. Info.initial_step/1 and Step.find_initial/1 keep their names and return the default initial step, so existing callers do not change.
  • ValidateWorkflow checks the create actions at compile time. It rejects a create whose transition_state names a step that is not initial.
  • An upserting create cannot call transition_state, and ValidateWorkflow rejects 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/1 sets initial: true on every initial step. Mermaid and DOT charts draw a start edge to each one, and the Clarity workflow overview lists them all.
workflow do
  step :self_service_intake do
    initial true
    transition :submit, to: :review
  end

  step :staff_intake do
    initial true
    transition :submit, to: :review
  end

  step :review do
    transition :approve, to: :done
  end

  step :done, terminal: true
end

actions do
  # Starts in :self_service_intake, the first initial step.
  create :open do
    accept [:title]
  end

  create :open_by_staff do
    accept [:title]
    change transition_state(:staff_intake)
  end
end
stateDiagram-v2
    [*] --> self_service_intake
    [*] --> staff_intake
    self_service_intake --> review: submit
    staff_intake --> review: submit
    review --> done: approve
    done --> [*]
Loading

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 true for an unreachable step that no other step leads into.

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.
@C-Sinclair
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.
@C-Sinclair
C-Sinclair merged commit a5ae126 into main Nov 20, 2026
10 checks passed
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