β‘ Workflows
Saga (Compensating Transactions)
Execute a multi-step workflow that modifies distributed state, ensuring consistency by defining a compensation action for every step. If any step fails, all prior steps are undone in reverse order, leaving the system in its original state.
Bundle files
πORCHESTRATION.mdβ Orchestration
1# ORCHESTRATION.md
2
3## Diagram
4
5 ββββββββββββ ββββββββββββ ββββββββββββ ββββββββββββ
6 β Step 1 βββ>β Step 2 βββ>β Step 3 βββ>β Step N β
7 β Agent β β Agent β β Agent β β Agent β
8 ββββββ¬ββββββ ββββββ¬ββββββ ββββββ¬ββββββ ββββββ¬ββββββ
9 β fail β fail β fail β
10 β β β β
11 βΌ βΌ βΌ βΌ
12 ββββββββββββ ββββββββββββ ββββββββββββ
13 βComp-1 β<βββComp-2 β<βββComp-3 β
14 β(undo S1) β β(undo S2) β β(undo S3) β
15 ββββββββββββ ββββββββββββ ββββββββββββ
16 β
17 βΌ
18 ββββββββββββββββββββββββββββββββββββ
19 β Saga Log (event audit trail) β
20 ββββββββββββββββββββββββββββββββββββ
21
22
23## Workflow
24Saga (Compensating Transactions)
25
26## Objective
27Execute a multi-step workflow that modifies distributed state, ensuring consistency by defining a compensation action for every step. If any step fails, all prior steps are undone in reverse order, leaving the system in its original state.
28
29## Roles
30- **Step Agents:** each executes one logical step and emits a success/failure event.
31- **Compensation Agents:** one per step; each knows exactly how to undo that step's changes.
32- **Saga Orchestrator:** owns the execution state machine, triggers steps and compensations, writes the event log.
33- **Saga Log:** append-only audit trail of every event (step executed, step failed, compensation executed, saga completed/aborted).
34
35## When to use
36- Workflows that write to multiple external systems and must stay consistent.
37- Long-running operations where distributed transactions are impractical.
38- Any multi-step process where partial completion is worse than full failure.
39- Order processing, payment flows, multi-service provisioning, data migrations.
40
41## Protocol
421. Orchestrator initializes saga with a unique saga ID and logs start.
432. Execute Step 1 Agent. On success: log and proceed to step 2.
443. On any step failure:
45 a. Log the failure with step ID, error, and timestamp.
46 b. Trigger Compensation Agent for the failed step (if step partially succeeded).
47 c. Work backwards: trigger Compensation Agent for each previously completed step.
48 d. Log each compensation result.
494. If all compensations succeed β log saga aborted cleanly; surface clear error to caller.
505. If a compensation fails β log compensation failure; escalate to human immediately.
516. If all steps complete successfully β log saga committed.
52
53## Compensation rules
54- Compensation actions must be idempotent: safe to retry if they fail once.
55- Each compensation must be registered before its step executes β no retroactive compensations.
56- Compensation order is strictly reverse: step N undone before step N-1.
57- Compensations must never call downstream steps β only undo their own step's changes.
58
59## Rules
60- Every step must have a registered compensation before the saga starts.
61- Saga IDs must be globally unique and included in every log event.
62- No step may proceed if the previous step's log event is missing.
63- Timeouts count as failures and trigger compensation.
64- Retry a failed compensation once before escalating to human.
65
66## Deliverables
67- Saga result: `committed` | `aborted` | `escalated`.
68- Full event log with saga ID, timestamps, and per-step status.
69- Compensation log for all aborted sagas.
70- Alert to responsible owner if any saga lands in `escalated` state.
71
Lines: 71 | Words: 496
Install
Copy bundle to your OpenClaw workspace.
curl -fsSL https://raw.githubusercontent.com/cerealskill/openclaw-agents/main/install.sh | bash -s workflow saga ENRate this agent
Loading...
Sign in to rate this agent
Includes
- β ORCHESTRATION.md
Info
- Slug
- saga
- Lines
- 71
- Words
- 496
