Execution
How workflows execute from trigger to completion.
Execution
When a workflow runs, flow orchestrates a multi-step process that flushes real-time state, creates run records, and executes nodes in dependency order using Vercel WDK for durable execution.
Execution overview
The execution pipeline has six steps:
- Flush Yjs state — the webapp calls
flushCollabStateto force the collab server to persist the latest Yjs document to MongoDB, ensuring the executor reads up-to-date nodes and edges - Create run records —
startWorkflowRuncreates aWorkflowRunrecord and oneNodeRunrecord per node, all withpendingstatus - Set
activeRunId— the collab server is notified to setactiveRunIdin the Yjs runtime map, which triggers UI updates on all connected clients - Execute nodes — the WDK executor processes nodes in topological order, running each node's step function with resolved inputs
- Persist outputs — each node's output is written to the
NodeRunrecord in the database, and generated assets (images, videos) are uploaded to R2 - Bump
runsVersion— after each node completes,updateCollabRuntimebumps therunsVersioncounter in Yjs, signaling clients to fetch updated run data
Topological execution
Nodes execute in topological order — a node only runs after all its upstream dependencies have completed. Nodes at the same level (no dependencies on each other) can execute concurrently.
Level 0: [Text Variable] [Image Variable]
│ │
Level 1: [Flux Schnell] ─────────┘
│
Level 2: [Upscale]
│
Level 3: [Preview]In this example:
- Level 0: Both variable nodes execute first (no upstream dependencies)
- Level 1: Flux Schnell waits for both variables, then executes
- Level 2: Upscale waits for Flux Schnell
- Level 3: Preview waits for Upscale
Nodes on independent branches execute in parallel. If a workflow has two separate chains that don't share edges, they run simultaneously.
Step functions
Each node's plugin declares a step property that maps to a server-side step function. Step functions use the "use step" directive to mark them as durable WDK steps.
Built-in step functions:
| Step | Description |
|---|---|
fal | Calls fal.ai inference API for image/video generation models |
ai-gateway | Routes text generation to Anthropic, OpenAI, Google, or Meta models |
shotstack | Submits video rendering jobs to Shotstack |
http | Makes arbitrary HTTP requests |
js | Executes user-defined JavaScript in a sandboxed environment |
r2-upload | Uploads content to Cloudflare R2 |
Step functions receive the node's resolved inputs (values from connected edges + config values) and return an output object keyed by output handle IDs.
Compute functions
Some nodes execute client-side without a server round-trip. These use compute functions instead of step functions and run instantly in the browser:
| Compute | Description |
|---|---|
router | Routes input to one of several outputs based on a condition |
filter | Passes or blocks values based on a predicate |
prompt | Interpolates variables into a prompt template |
list | Collects multiple inputs into a list |
concat | Concatenates text values |
Compute nodes are resolved by computeDerived() during the React render cycle. They do not create NodeRun records and do not appear in run history.
Error handling
When a node fails during execution:
- The failed node's
NodeRunstatus is set toerrorwith an error message - All downstream nodes (nodes that depend on the failed node's output) are set to
cancelled - Nodes on other branches of the graph that do not depend on the failed node continue executing normally
- The overall
WorkflowRunstatus is set toerroronce all branches have completed or been cancelled
[Text] ──> [Flux Schnell] ──X──> [Upscale] ──> [Preview]
error cancelled cancelled
[Image] ──> [Background Remove] ──> [Save]
success successIn this example, Flux Schnell fails, so Upscale and Preview are cancelled. But Background Remove and Save are on an independent branch and complete successfully.
Asset persistence
When a node produces media output, flow automatically persists it:
| Output type | Storage | Details |
|---|---|---|
| Images | Cloudflare R2 | Uploaded as WebP, accessible via R2 public URL with Image Transformations |
| Videos | Cloudflare R2 + Stream | Uploaded to R2 for storage, copied to Cloudflare Stream for playback |
| Audio | Cloudflare R2 | Uploaded in original format |
| Text / JSON | MongoDB | Stored directly in the NodeRun output field |
Asset URLs in the NodeRun.output object point to the persisted R2 location, not the temporary generation URL. This ensures outputs remain accessible after the run completes.
Durable execution
flow uses Vercel WDK (Workflow Development Kit) for durable execution. Each step function is a WDK step, which means:
- Automatic retries — if a step fails due to a transient error, WDK retries it
- State persistence — step results are durably stored, so a workflow can resume after a crash
- Timeout handling — long-running steps (like video rendering) are monitored and timed out gracefully
- Idempotency — steps are designed to be safely re-executed without side effects