A workflow is a function that describes a multi-step process โ like processing an order, onboarding a new user, or syncing data with an external service. What makes it special is that itโs durable: OpenWorkflow saves the progress of each step to the database. If the process crashes or the server restarts, the workflow picks up right where it left off instead of starting over.Documentation Index
Fetch the complete documentation index at: https://openworkflow.dev/llms.txt
Use this file to discover all available pages before exploring further.
Defining a Workflow
Define a workflow withdefineWorkflow:
- A spec - Configuration including the workflow name and optional version
- A function - The async function that contains your workflow logic
Running a Workflow
Start a workflow by callingow.runWorkflow() with the workflowโs spec:
ow.runWorkflow() returns a handle immediately. The actual workflow execution
happens in a worker process. This lets your application continue without waiting
for the workflow to complete.
If you define a workflow with
ow.defineWorkflow(...) instead, it returns a
runnable workflow that supports .run(...) directly.Scheduling a Workflow Run
You can schedule a workflow run for a specific time by passingavailableAt:
step.sleep:
pending until availableAt is reached, then workers can claim
it. If availableAt is in the past, the run is immediately available.
Waiting for Results
If you need to wait for a workflow to complete, use.result() on the handle:
result() polls the database periodically. Use this for workflows that
complete quickly (seconds to minutes). For long-running workflows, consider
using events or callbacks instead.Workflow Options
Name (Required)
Every workflow needs a unique name. This name is used to identify the workflow in the database and must match when workers execute the workflow.Version (Optional)
Use versioning when you need to support multiple implementations of the same workflow simultaneously. See Versioning for details.Schema (Optional)
Validate inputs before the workflow is enqueued using any Standard Schema compatible validator. See Standard Schema for details.Retry Policy (Optional)
Control backoff and retry limits for this workflow:retryPolicy fields you omit fall back to defaults. See
Retries for the full behavior and defaults.
Idempotency Key (Optional)
You can prevent duplicate run creation by providing an idempotency key, though there is a performance cost to checking for duplicates, so use this only when necessary:workflowName + idempotencyKey, OpenWorkflow returns that existing run
immediately. This dedupe window is built-in and lasts 24 hours from the original
run creation time. The same idempotencyKey used in a different namespace will
create a separate run.
Workflow Function Parameters
The workflow function receives an object with four properties:| Parameter | Type | Description |
|---|---|---|
input | Generic | The input data passed when starting the workflow |
step | StepApi | API for defining steps (step.run, step.sleep, step.runWorkflow, step.sendSignal, step.waitForSignal) |
version | string | null | The workflow version, if specified |
run | WorkflowRunMetadata | Read-only run metadata snapshot (run.id, etc.) |
Workflow Run States
A workflow run progresses through these states:| Status | Description |
|---|---|
pending | Created and waiting for a worker to claim it |
running | Actively executing, or durably parked with workerId = null until availableAt |
completed | Finished successfully |
failed | Failed after exhausting retries, hitting deadline, or step cap |
canceled | Explicitly canceled and will not continue |
Determinism
New to workflow engines? This is the most important rule to understand.
Itโs simple once you know why it exists.