Compensation and error handling
A workflow needs a deliberate answer when something fails after earlier work succeeded. Duna offers error routing, retries and explicit compensation steps.
Error routes and retries
An action’s onError policy can define retries or route to an error state. Long retry backoffs can park an instance durably rather than occupy a worker. Limits and timing are configured; they are not a promise that external work is executed exactly once.
The compensation log
An action can register an undo step with compensate. When a later failure routes to an error state and compensation is enabled, registered undo steps run newest first before entering that target.
The order saga sample demonstrates:
- Reserve stock and register release.
- Charge payment and capture the charge ID for refund.
- Fail shipment.
- Undo the charge, then undo the reservation.
- Enter
cancelled.
Captured context
The capture template is evaluated after the forward action. The undo step reads the stored value through compensation.capture. This keeps the undo tied to the completed action’s result.
{
"compensate": {
"type": "expression",
"assignTo": "refunded",
"capture": { "chargeId": { "$expr": "result.chargeId" } },
"config": { "$expr": "compensation.capture.chargeId" }
}
}This is a fragment from the documented saga pattern. It illustrates an expression assignment, not a real payment refund.
Limits to design for
An undo step can fail. Operations documents compensation.failed, log limits and branch-related recovery caveats. Compensation does not make independently committed systems transactional. Make forward and undo operations safe to retry and establish an operator recovery procedure.