Compensating Actions
Category: Action Execution | Level: intermediate | Stability: experimental | Version: v1
Description
Some operations cannot be wrapped in a transaction: money moves between systems, messages leave, external state changes. When one step in a chain fails, earlier effects must be reversed — and that reversal needs to be designed, not improvised. This skill maps each step of a multi-system workflow to its compensating action and records what happens when compensation itself fails.
When to Use
Use when a workflow spans multiple systems without a shared transaction — order plus payment plus shipping, provision plus notify — and partial failure must leave a coherent state.
Do not assume every step can be undone; some can only be acknowledged and corrected, and that difference belongs in the design.
Inputs
| Input | Type | Required | Description |
|---|---|---|---|
workflow |
list |
Yes | Ordered steps with their side effects |
compensations |
map |
Yes | Reverse action per step, or explicit not-compensable |
policy |
map |
No | Forward-recovery and manual-intervention rules |
Procedure
- List the workflow steps with their side effects before writing any of them; compensation design needs the full picture.
- For each step, define its compensating action — the reverse operation, an acknowledge-and-correct path, or explicit not-compensable.
- Define failure handling as a saga: on failure at a given step, run compensations for all earlier steps in reverse order.
- Record semantic invariants — what the compensations must restore in meaning, not just mechanics — and check them after recovery.
- Plan for compensation failure: retry the compensation, then fall back to a recorded manual-intervention path.
- Log forward progress for steps that cannot be reversed, so operators see what was done rather than guessing.
Outputs
| Output | Type | Description |
|---|---|---|
compensation_plan |
map |
Per-step reverse actions and their order |
invariants |
list |
What the recovery must restore |
recovery_log |
list |
Compensations attempted, with outcomes |
Runnable Example
def run_saga(steps, compensations):
done = []
for step in steps:
try:
step["action"]()
done.append(step["name"])
except Exception as err:
log = [f"failed at {step['name']}: {err}"]
for prev in reversed(done):
compensations[prev]()
log.append(f"compensated {prev}")
return {"status": "rolled-back", "log": log}
return {"status": "completed", "steps": done}
def charge():
raise RuntimeError("payment gateway down")
steps = [
{"name": "reserve", "action": lambda: print("reserved")},
{"name": "charge", "action": charge},
{"name": "ship", "action": lambda: print("shipped")},
]
compensations = {"reserve": lambda: print("released reservation")}
print(run_saga(steps, compensations))
Failure Modes
| Failure Mode | Cause | Mitigation |
|---|---|---|
| Improvised undo | Reversal is invented during the incident | Design compensations before the chain runs |
| Uncompensable silence | Irreversible steps are not marked | Mark not-compensable steps explicitly |
| Compensation failure | Undo itself fails with no fallback | Retry, then route to a recorded manual path |
| Lost invariants | Recovery restores mechanics but not meaning | Check semantic invariants after recovery |
| Phantom success | A step is reported done but never landed | Verify each compensation effect instead of assuming |
Security and Authority Boundary
Compensating actions carry the same authority as the actions they reverse — a refund moves money, an unprovision removes access. Scope compensation credentials narrowly, log every compensation in an operator-visible record, and treat unexpected compensation triggers as an audit event.
Evidence
This skill is grounded in dated public implementation references:
- The saga pattern description for distributed transactions (https://microservices.io/patterns/data/saga.html).
- Wikipedia's overview of compensating transactions (https://en.wikipedia.org/wiki/Compensating_transaction).
Honest boundary: these are implementation references, not adoption or demand evidence; this entry was added under the owner-directed corpus expansion recorded in meta/memory/DECISIONS.md, and no demand signal is claimed for it.
Related Skills
- Database Write — the local transactional path that chains try to emulate.
- File Delete — the destructive primitive often used as a compensation.
Changelog
| Date | Version | Change |
|---|---|---|
2026-10 |
v1 | Initial entry added under the owner-directed corpus expansion |