Compensation
Undo reversible work when an operation succeeds only partway, such as a payment followed by a failed stock reservation.
Configure a Compensated Step
Implement a reversal endpoint, such as a refund for a charge or a release for a stock reservation, so Argyll can request cleanup when the Flow fails.
Set handling to compensated, configure the compensation endpoint, and select the Attributes it receives:
{
"id": "charge-card",
"name": "Charge Card",
"type": "service",
"handling": "compensated",
"http": {
"invoke": {
"endpoint": "https://payment.example.com/charge",
"timeout": 1000,
"mode": "sync"
},
"compensate": {
"method": "DELETE",
"endpoint": "https://payment.example.com/charges/{charge_id}",
"timeout": 3000,
"mode": "async"
}
},
"attributes": {
"amount": {"role": "required"},
"charge_id": {
"role": "output",
"compensated": true
}
}
}
compensated: true selects the data sent to the endpoint. Each selected Attribute uses its invocation name. When an input and output share that name, select the value the compensation operation consumes.
The compensation method defaults to POST. Its timeout defaults to the invocation timeout when omitted. Invocation and compensation modes are independent, and each defaults to sync.
The compensation endpoint section of Service Steps covers the request body, headers, idempotency, and async callbacks.
Automatic Rollback
When a compensated Step fails, Argyll compensates its succeeded Work Items, including any already-running items that report success after the Step failed.
If the Flow fails, Argyll automatically compensates every succeeded Work Item whose Step uses compensated handling. Starting a Flow requires no compensation option:
{
"id": "checkout-123",
"goals": {"steps": ["ship-order"]},
"init": {
"order_id": ["ord-abc"]
}
}
The same rule applies inside child Flows. Declaring a compensator on a Step establishes its rollback contract for every Flow.
Roll Back Abandoned Fallbacks
When a Goal set fails and the Flow moves on to its else set, Argyll automatically compensates succeeded Work Items from Steps with compensated handling that no remaining Goal set can use, while the fallback runs. Work a remaining set can still consume stays in place, including dependencies the sets share. Once a set completes, compensated Steps that only the later sets could have used are rolled back too.
goals: {"steps": ["notify-customer"], "else": {"steps": ["notify-later"]}}
load-order → reserve-stock → notify-customer (fails)
load-order → notify-later (succeeds)
Compensated: reserve-stock
Kept: load-order
Here reserve-stock is compensated as soon as notify-customer fails, while notify-later runs. This rollback follows the same reverse dependency order as a failed Flow, and a Step from the abandoned branch that is still running holds back its providers until it settles. A Flow that completes keeps its completed status and deactivates after the rollback settles.
Ordering
Flow rollback follows reverse dependency order. Steps that ran in parallel compensate in parallel. The preceding dependency wave starts after the current wave settles.
For a dependency chain reserve-stock → charge-card → ship-order, rollback starts with shipment, then payment, then stock reservation, where those operations have configured compensators.
Work Items within one Step compensate independently. A succeeded Work Item with a declared compensator that finishes after Flow failure joins the appropriate rollback wave. A failed Step’s own late successes also receive the Step-level cleanup described above. The Flow deactivates after all active and compensating work settles.
Child Flows keep their own rollback boundary and automatically compensate their reversible work when they fail.
Retries and Recovery
Compensation uses the Step’s work_config retry and backoff settings and continues the Work Item’s retry count from invocation, so retries spent on invocation draw down the same max_retries budget. Retryable failures resume after engine restart, and permanent or exhausted failures finish as compensate_failed. See Retries for configuration and WebSocket API for event names.
A settled rollback can include compensate_failed Work Items. Inspect those failures and arrange any manual recovery your business requires.