Documentation 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 is used to attach compensation logic to a step definition. When Cloudflare Workflows determines that a workflow must be rolled back, it calls each registered rollback handler in reverse order. Sideffect forwards your handler and the optional rollback step config to Cloudflare’s native step rollback mechanism — Cloudflare owns the execution and ordering. Import Rollback directly from sideffect.
Rollback.with(handler, config?)
Returns a function (step: StepDefinition) => StepDefinition that attaches a rollback handler to a step definition. It is designed to be used with the .pipe() method on StepDefinition.
The compensation function called by Cloudflare when rollback is triggered for
this step. Receives:
result: Result | undefined— the step’s output value, orundefinedif no output was recorded before the failure.context: RollbackContext<Payload, Result, Env>— contextual data including the original payload, the failure, and env bindings. See RollbackContext properties below.
async function, or return an
Effect.Effect.Optional Cloudflare step configuration for the rollback step itself. Accepts
the same
WorkflowStepConfig type from cloudflare:workers that controls
retries and timeout for the rollback execution.(step: StepDefinition<Payload, Result, Env>) => StepDefinition<Payload, Result, Env> — the same step definition with the rollback handler attached.
RollbackContext properties
The second argument to every rollback handler.
The original decoded payload that was passed to the step when it ran.
The step output value, as decoded by the step’s
result schema. May be
undefined if Cloudflare did not record an output before the failure
occurred.The error or value that caused Cloudflare to invoke rollback for this step.
Worker environment bindings from the
WorkflowEntrypoint instance. Typed
from your project’s Cloudflare.Env.Worker execution context from the
WorkflowEntrypoint instance.The raw Cloudflare
WorkflowStep API object. Available for advanced use
cases that require calling the native step API directly inside a rollback
handler.The raw
WorkflowRollbackContext provided by Cloudflare. Use this to access
any Cloudflare-native rollback fields that Sideffect does not surface
directly.Usage with .pipe()
The idiomatic way to attach a rollback handler is with the .pipe() method on any StepDefinition. This keeps the step logic and its compensation logic co-located:
publishImageStep has already run, Cloudflare will call the rollback handler and delete the previously uploaded object.
Rollback with step config
You can pass aWorkflowStepConfig as the second argument to configure how Cloudflare executes the rollback step itself (retries, timeout):
Composing Rollback.with manually
Rollback.with returns a plain function, so you can also call it independently of .pipe() when you need to apply rollback programmatically:
A step that uses
.pipe(Rollback.with(...)) is a new StepDefinition value.
The original step definition is not mutated. This means you can safely define
a base step and create rollback variants of it for different workflows.