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: trueSaga fields
| Field | Required | Description |
|---|---|---|
state | yes | Entity type that owns this saga |
state_path | yes | _tmp/ path to store saga state |
steps | yes | List of step definitions |
steps[].name | yes | Step identifier |
steps[].on | no | Event that triggers this step transition |
steps[].set | no | State to set when entering this step |
steps[].end | no | true marks this as a terminal step |