Documentation Index
Fetch the complete documentation index at: https://mintlify.com/backpine/durable-effect/llms.txt
Use this file to discover all available pages before exploring further.
The fundamental insight
Interruption is inevitable. Servers restart, deployments roll out, processes crash. Traditional code loses all in-flight state when any of this happens. Durable execution treats interruption as a first-class concern: every meaningful result is persisted before the workflow continues, so when execution resumes it picks up exactly where it left off.Workflow.step() and Workflow.sleep(). Code inside a step runs non-durably — no step or sleep calls belong inside a step’s execute effect.
Step caching
EveryWorkflow.step() call persists its result to Durable Object storage before returning. On any subsequent execution of the same workflow instance, completed steps check the cache first:
- Cache miss — the effect runs, the result is stored, and the value is returned.
- Cache hit — the effect is skipped entirely and the stored value is returned.
Sleep and the pause signal
Workflow.sleep() does not block a thread. Instead, it throws a PauseSignal that propagates up to the executor:
- Records the pause state in the state machine
- Schedules a Durable Object alarm for
resumeAt - Returns
{ _tag: "Paused", reason: "sleep", resumeAt: ... }
resume mode, replaying all cached steps and continuing past the sleep point.
retry config throws a PauseSignal with reason: "retry", schedules an alarm, and resumes when the delay expires.
Three execution modes
When the executor runs a workflow definition, it operates in one of three modes:| Mode | When used | Behavior |
|---|---|---|
fresh | First execution of an instance | No cached data; execute everything |
resume | After a scheduled pause (sleep or retry delay) | Replay cached steps; continue from the pause point |
recover | After an infrastructure failure | Same as resume, but triggered by the recovery system |
resume and recover modes the workflow function runs from the top, but every completed step returns its cached result immediately without executing the underlying effect.
The workflow state machine
Every workflow instance moves through a defined set of states. The valid transitions are:Completed, Failed, and Cancelled are terminal — no further transitions are possible.
WorkflowStatus type
WorkflowStatus type
The full discriminated union for workflow status:
Recovery after infrastructure failure
When a Durable Object restarts (process crash, deployment, eviction) any workflow that wasRunning did not get a chance to record a Completed or Paused transition. The recovery system detects this on startup:
- The engine’s constructor runs
RecoveryManager.checkAndScheduleRecovery(). - The recovery manager reads the current status. If it is
RunningandlastUpdatedis older than the stale threshold (default: 30 s), the workflow is considered stale. - A short-delay alarm is scheduled. When it fires, the orchestrator re-executes the workflow in
recovermode. - Because all completed steps are cached in DO storage, replay is safe and the workflow continues from the last incomplete step.
Recovery attempt count is bounded by
maxRecoveryAttempts (configurable in createDurableWorkflows). If the limit is exceeded the workflow transitions to Failed.Durability boundaries
OnlyWorkflow.step() and Workflow.sleep() create durability checkpoints. Code written directly in the workflow body between steps runs non-durably on each execution:
