Workflow.sleep() pauses a workflow for a specified duration. Unlike Effect.sleep, the pause is fully durable — if your server restarts or a new deployment happens while the workflow is sleeping, it resumes automatically when the scheduled time arrives.
Duration formats
Both string and millisecond formats are accepted. String format:Workflow.sleepUntil()
To sleep until a specific point in time, pass a Unix timestamp in milliseconds:
sleepUntil returns immediately without pausing.
Common patterns
How sleep works internally
WhenWorkflow.sleep() is called for the first time at a given pause point, it:
- Records the
resumeAttimestamp in Durable Object storage - Throws a
PauseSignalwithreason: "sleep"— this is caught by the executor, not propagated as an error - The orchestrator transitions the workflow to
Pausedand schedules a Cloudflare Durable Object alarm forresumeAt
Running and re-executes it in resume mode. On replay, all previously completed steps return their cached results, and the sleep point is skipped because its pause index has already been recorded as completed.
Sleeps are tracked by index, not by duration. If you add or reorder sleep calls between a workflow being paused and resumed, behavior may be undefined. Treat the sequence of
Workflow.sleep() calls in a workflow as immutable once instances are running.