Compensation times out
Detect: The ledger remains pending while the external service reports an uncertain result.
Recover: Query by operation key before retrying compensation.
Restore a coherent workflow checkpoint while explicitly compensating business effects that a database rollback cannot undo.
State rollback returns an agent workflow to a previously valid logical state after an incorrect plan, failed validation, or operator intervention. The rollback boundary must distinguish local transactional data, durable workflow history, and effects already committed in external systems. Rewinding the conversation does not cancel a shipment or reverse a payment.
A useful architecture treats recovery as a new, auditable transition. Snapshots provide a starting point; an event history explains changes; compensating commands repair reversible effects. Irreversible actions create a forward-recovery boundary requiring reconciliation or human judgment. Deterministic replay is possible only for recorded inputs and outcomes, not by asking a stochastic model to repeat its earlier reasoning.
A prototype can reset an in-memory state object, but it should already label every tool as read-only, reversible, or irreversible.
Production records checkpoint versions, effect identifiers, and compensation status before exposing a recovery command to operators.
Enterprise workflows need retention policies, schema migration of old checkpoints, concurrent-writer fencing, and recovery drills covering several external owners.
Persists versioned workflow snapshots with the last committed event position.
Records requested operations, external receipts, idempotency keys, and compensation eligibility.
Acquires workflow ownership and constructs an ordered recovery plan.
Implement domain-specific undo operations with independent retries and verification.
Preserves the original execution and the reason for every recovery decision.
flowchart TD
A["Failed fulfillment plan"] --> B["Fence active worker"]
B --> C["Read checkpoint and effect ledger"]
C --> D["Release stock reservation"]
C --> E["Shipment already dispatched"]
D --> F["Create recovered revision"]
E --> G["Human reconciliation"]
G --> FstateDiagram-v2
[*] --> Running
Running --> Frozen: Recovery requested
Frozen --> Compensating: Reversible effects exist
Frozen --> Reconciliation: Irreversible or unknown effect
Compensating --> Reconciliation: Compensation unresolved
Compensating --> Recovered: Invariants verified
Reconciliation --> Recovered: Business resolution recorded
Recovered --> Running: New revision resumesFence the current workflow owner so that a late worker cannot continue committing changes.
Choose a validated checkpoint and enumerate all later local mutations and external effects.
Separate reversible reservations from irreversible actions and ambiguous timeouts requiring external lookup.
Undo dependent reversible operations in reverse dependency order, recording each result durably.
Create a new workflow revision based on the checkpoint after compensation invariants pass.
Continue from the recovery revision or route unresolved effects to an operator with the full ledger.
Retail · Illustrative enterprise scenario, not a reported customer outcome.
An order agent reserves stock, books a carrier, and requests payment capture across separate services.
A warehouse exception arrives after the carrier booking but before the workflow reaches its completion checkpoint.
Recover the order without losing receipts or booking the same carrier twice.
A versioned order workflow uses a reservation ledger and explicit carrier-cancellation adapter.
If the carrier already collected the parcel, the workflow enters reconciliation instead of claiming that rollback succeeded.
Track unresolved effects, compensation age, and recovery completion time; the target is a verifiably consistent order, not a clean-looking transcript.
| Decision | Benefit | Cost |
|---|---|---|
| Frequent checkpoints | Reduce replay distance and recovery work. | Increase storage writes and schema-management burden. |
| Automatic compensation | Restores reversible workflows without operator delay. | Requires business-specific semantics and may itself fail. |
| Immutable history | Supports investigation and trustworthy reconciliation. | Retains sensitive operational evidence that needs access and retention controls. |
Detect: The ledger remains pending while the external service reports an uncertain result.
Recover: Query by operation key before retrying compensation.
Detect: A revision mismatch or fencing-token violation appears in the commit log.
Recover: Reject the stale write and stop the superseded worker.
Append a recovery revision and preserve the original evidence.
Document irreversible boundaries and provide forward-recovery procedures.
Replay stored decisions and tool receipts; explicitly generate a new plan when needed.