Problem
A task that spans several actions can fail midway, leaving a held seat with no booking, or a charge with no order. Agents cannot clean up without a defined way to undo.
Context
Use this pattern when:
- Workflows involve multiple side effects across steps or services.
- Some steps are reversible within a time window.
Recommended solution
For each reversible action, define a compensating action and reference it in the receipt. Within workflows, roll back completed steps automatically when the workflow is cancelled or a step fails irrecoverably, and report what was undone.
- 01Define compensating actions for reversible operations.
- 02Reference the undo action in receipts with its deadline.
- 03Roll back workflow steps in reverse order on failure.
- 04Report which compensations succeeded.
Interaction diagram
Example implementation
Illustrative exampleExamples use a fictional store and illustrative field names. Adapt the shape to your stack; the qualities matter more than the exact format.
{
"id": "rcpt_812",
"action": "hold_seat",
"status": "completed",
"effects": [{ "type": "created", "resource": "/holds/H-3321" }],
"undo": {
"action": "release_seat",
"input": { "holdId": "H-3321" },
"availableUntil": "2026-10-06T14:20:00Z"
}
}Accessibility and security
Accessibility
- Offer people the same undo affordance in the UI, with the same deadline.
Security
- Compensating actions need the same authorization as the original action.
Related patterns
InteractionMulti-step WorkflowsModel long tasks as named workflows with explicit steps, persistent state, and resumable progress.FeedbackAction ReceiptsReturn a durable, verifiable record of every state-changing action.RecoveryRetry StrategiesMake retries safe with idempotency keys, and tell agents when and how to retry.
Applies the principles Graceful Failure and Verifiable Outcomes.