Skip to main content

Execute Failure Recovery

Recover automatically when an Execute method still fails after its retry policy is exhausted.

Definition graph

FailureRecoveryFlow

Valid

python · examples/python/dex_examples/patterns/recovery/failure_recovery_flow.py

ExecuteFailureRecoveryFlow starts FailingStep. Its Execute method can fail, and its ExecuteFailure policy sends the Flow to RecoveryStep after retries are exhausted. RecoveryStep performs the compensating action and completes the Flow.

Use this pattern when the Flow can recover without a person. Keep the recovery Step idempotent because it may be retried independently.

Core implementation

The failed FailingStep owns both its retry policy and the movement to RecoveryStep. RecoveryStep receives the same input and performs the compensating action before it completes or fails the Flow.

class FailingStep(Step[str]):
def get_step_options(self) -> StepOptions:
return StepOptions(
execute_retry=RetryPolicy(maximum_attempts=3)
).on_execute_failure_proceed_to(RecoveryStep)

def execute(self, context: Context, input: str) -> StepDecision:
raise RuntimeError("planned Execute failure")

class RecoveryStep(Step[str]):
def execute(self, context: Context, input: str) -> StepDecision:
return graceful_complete(f"recovered {input}")

Example: examples/python/dex_examples/patterns/recovery/failure_recovery_flow.py