Lifecycle and Transitions
This page describes the transition pipeline from event dispatch to settled state.
Event Pipeline
For each send(event) call:
- Event is queued (serialized execution).
- Candidate transitions are scanned in array order.
- First transition whose
from+eventmatch is selected. whenexecutes (if present).effectexecutes (if present).- Snapshot is committed and subscribers are notified.
Selection Rules
- First match wins.
- Guards (
when) can reject movement (false). - No match returns
{ transitioned: false }.
Terminal Lifecycle
When target is terminal:
JOURNEY_TERMINAL.COMPLETE=>status = "complete"JOURNEY_TERMINAL.CLOSE=>status = "closed"
After terminal status, send(...) does not transition until reset().
Reset Lifecycle
reset() restores:
current = initialcontext = initial contexthistory = []visited = [initial]- all async phases to
idle
Error Lifecycle
If when/effect throws:
send(...)rejects- current step async phase becomes
error - captured error is exposed at
snapshot.async.byStep[current].error
Recovery:
machine.clearStepError();
Queue Resilience
A failed event does not poison the queue; future sends continue processing.
This is critical for UX flows with intermittent network/validation failures.