Cloudflare Workflows support a native rollback mechanism: when a step fails, Cloudflare can invoke a compensation function to undo or clean up work that step already completed (for example, deleting a file that was written to R2). Sideffect surfaces this feature throughDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/eersnington/sideffect/llms.txt
Use this file to discover all available pages before exploring further.
Rollback.with(), which lets you attach a typed rollback handler — and an optional rollback step configuration — to any StepDefinition without modifying the step’s core run logic.
Attaching a Rollback Handler with Rollback.with
Rollback.with(handler, config?) returns a function that accepts a StepDefinition and produces a new StepDefinition with the rollback handler attached. The original step’s name, payloadSchema, resultSchema, and run are preserved unchanged.
The optional second argument config is a Cloudflare WorkflowStepConfig that controls retry and timeout behaviour for the rollback step itself:
The pipe() Pattern
Every StepDefinition exposes a pipe(fn) method that applies a transformation and returns the result. Rollback.with(...) is designed to be used directly with pipe:
publishImageStep fails after writing to R2, Cloudflare invokes the rollback handler to delete the file that was just written.
The RollbackContext Object
The second argument to a rollback handler is a RollbackContext with the following properties:
| Property | Type | Description |
|---|---|---|
payload | Payload | The original step payload that was passed to run. |
result | Result | undefined | The step output if the step completed before failure, or undefined otherwise. |
failure | unknown | The error that caused Cloudflare to invoke rollback. |
env | Env | Worker environment bindings (R2, KV, AI, Durable Objects, etc.). |
ctx | unknown | Worker execution context from the WorkflowEntrypoint instance. |
workflowStep | NativeWorkflowStep | The raw Cloudflare WorkflowStep API for advanced native step operations. |
native | WorkflowRollbackContext<Result> | The raw Cloudflare WorkflowRollbackContext if you need direct access to the underlying object. |
Full Example — Rollback on Publish Failure
Rollback Handlers and Effect
Like steprun functions, rollback handlers may return a direct value, a Promise, or an Effect.Effect<void, unknown, never>:
Steps
Define reusable, schema-validated workflow activities.
Workflows
Compose steps into full workflow pipelines.
Step Context
Access env bindings, retry counts, and step metadata inside a step.
Error Handling
Throw NonRetryableError to stop retries immediately.