sagas — State Machine Workflows

How this compiles. Each step with on: is macro-expanded at compile time into an ordinary event-triggered core rule (op: merge into state_path) — the same mechanism that executes actions and listeners. There is no separate saga execution engine at runtime. See Defining Sagas for what this means in practice (no built-in step-order guard, end: true is informational only).

Sagas are entity-attached state machines that track multi-step workflows. State is stored in an _tmp/ field on the entity.

sagas:
  purchase_flow:
    state: user
    state_path: _tmp/purchase_saga    # where saga state is stored on the entity
    steps:
      - name: idle
        set: { step: 0 }
 
      - name: pending
        on: PURCHASE_INITIATED
        set: { step: 1 }
 
      - name: payment_captured
        on: PAYMENT_CAPTURED
        set: { step: 2 }
 
      - name: complete
        on: PURCHASE_COMPLETED
        set: { step: 3 }
        end: true
 
      - name: failed
        on: PURCHASE_FAILED
        set: { step: -1 }
        end: true

Saga fields

FieldRequiredDescription
stateyesEntity type that owns this saga
state_pathyes_tmp/ path to store saga state
stepsyesList of step definitions
steps[].nameyesStep identifier
steps[].onnoEvent that triggers this step transition
steps[].setnoState to set when entering this step
steps[].endnotrue marks this as a terminal step