workflow 5.7.2 → 5.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/dist/internal/errors.d.ts +1 -1
  2. package/dist/internal/errors.js +2 -2
  3. package/docs/advanced/quickjs-runtime.mdx +4 -4
  4. package/docs/ai/sleep-and-delays.mdx +1 -1
  5. package/docs/api-reference/workflow/fetch.mdx +1 -1
  6. package/docs/api-reference/workflow/index.mdx +3 -0
  7. package/docs/api-reference/workflow/rate-limit.mdx +114 -0
  8. package/docs/api-reference/workflow-errors/in-band-superseded-error.mdx +5 -1
  9. package/docs/api-reference/workflow-errors/precondition-failed-error.mdx +6 -4
  10. package/docs/api-reference/workflow-errors/throttle-error.mdx +1 -1
  11. package/docs/api-reference/workflow-runtime/world/queue.mdx +5 -1
  12. package/docs/comparisons/workflow-sdk-vs-aws-step-functions.mdx +1 -1
  13. package/docs/comparisons/workflow-sdk-vs-inngest.mdx +49 -5
  14. package/docs/comparisons/workflow-sdk-vs-temporal.mdx +1 -0
  15. package/docs/comparisons/workflow-sdk-vs-trigger-dev.mdx +3 -1
  16. package/docs/configuration/runtime-tuning.mdx +478 -168
  17. package/docs/cookbook/common-patterns/batching.mdx +2 -2
  18. package/docs/cookbook/common-patterns/rate-limiting.mdx +27 -2
  19. package/docs/cookbook/index.mdx +1 -1
  20. package/docs/cookbook/integrations/chat-sdk.mdx +1 -1
  21. package/docs/errors/max-events-exceeded.mdx +1 -0
  22. package/docs/errors/rate-limit-max-wait.mdx +31 -0
  23. package/docs/foundations/errors-and-retries.mdx +2 -0
  24. package/docs/foundations/meta.json +1 -0
  25. package/docs/foundations/rate-limits.mdx +181 -0
  26. package/docs/performance.mdx +93 -59
  27. package/docs/worlds/building-a-world.mdx +6 -3
  28. package/docs/worlds/local.mdx +6 -2
  29. package/docs/worlds/postgres.mdx +9 -3
  30. package/docs/worlds/upgrading-to-v5.mdx +2 -2
  31. package/docs/worlds/vercel.mdx +2 -2
  32. package/package.json +11 -11
@@ -12,274 +12,496 @@ The runtime reads these variables where workflows execute. Set them on the deplo
12
12
 
13
13
  ## Client polling
14
14
 
15
+ | Variable | Default | What it does |
16
+ | --- | --- | --- |
17
+ | [`WORKFLOW_RETURN_VALUE_POLL_INTERVAL_MS`](#workflow_return_value_poll_interval_ms) | `1000` ms | Delay between `Run.returnValue` status requests |
18
+ | [`WORKFLOW_RETURN_VALUE_WAIT_MS`](#workflow_return_value_wait_ms) | `50000` ms | Longest a single wait for a terminal run status may block |
19
+ | [`WORKFLOW_RETURN_VALUE_MAX_LONG_POLLS`](#workflow_return_value_max_long_polls) | `10` | Waits before `Run.returnValue` falls back to interval polling |
20
+ | [`WORKFLOW_CHILD_RUN_COMPLETION_HOOK`](#workflow_child_run_completion_hook) | enabled | Parent waits on a child run through a hook instead of polling |
21
+
15
22
  ### `WORKFLOW_RETURN_VALUE_POLL_INTERVAL_MS`
16
23
 
17
24
  - Default: `1000`
18
- - Minimum: `1`
19
- - Delay between status requests made by [`Run.returnValue`](/docs/api-reference/workflow-api/get-run) while a workflow run is not yet complete.
20
- - Increase it to reduce polling traffic at the cost of noticing completion later.
21
- - This variable is read by the process awaiting `Run.returnValue`, such as an E2E test runner, rather than by the workflow deployment.
22
- - Applies whenever the World cannot hold a read open. When it can, the wait below replaces most of this polling and the interval only paces retries.
25
+
26
+ Delay, in milliseconds, between status requests made by [`Run.returnValue`](/docs/api-reference/workflow-api/get-run) while a workflow run is not yet complete. Minimum `1`.
27
+
28
+ Change it when: you want less polling traffic. Increase it, at the cost of noticing completion later.
29
+
30
+ This variable is read by the process awaiting `Run.returnValue`, such as an E2E test runner, rather than by the workflow deployment.
31
+
32
+ Applies whenever the World cannot hold a read open. When it can, the wait below replaces most of this polling and the interval only paces retries.
33
+
34
+ It is also the first delay after a status read fails with a transient World error (a timeout, a 5xx, or a 429). The delay doubles with each consecutive failure up to 30 seconds (or this interval, if longer), and a `Retry-After` from the World raises it, up to 5 minutes. After 10 failures in a row, `Run.returnValue` rejects with the last error. When `Run.returnValue` is awaited inside a step, these retries run within one attempt of that step, which can therefore keep running for about three minutes at the default interval before the step's own retries start.
23
35
 
24
36
  ### `WORKFLOW_RETURN_VALUE_WAIT_MS`
25
37
 
26
38
  - Default: `50000`
27
- - Minimum: `1`
28
- - How long a single wait for a terminal run status may block, when the World supports waiting (`world.runs.waitForTerminalStatus()`). `Run.returnValue` re-issues the wait until the run finishes, so this bounds one request rather than the total wait.
29
- - `50000` is the largest value the Vercel World can actually request: it clamps the ask to its 60s per-request HTTP timeout minus 10s of headroom, so the budget always expires as a response carrying the run's current status rather than as a client-side timeout. Raising this alone has no effect; raise `WORKFLOW_REQUEST_TIMEOUT_MS` as well.
30
- - Read by the process awaiting `Run.returnValue`, like the interval above.
39
+
40
+ How long, in milliseconds, a single wait for a terminal run status may block, when the World supports waiting (`world.runs.waitForTerminalStatus()`). Minimum `1`.
41
+
42
+ `Run.returnValue` re-issues the wait until the run finishes, so this bounds one request rather than the total wait.
43
+
44
+ `50000` is the largest value the Vercel World can actually request: it clamps the ask to its 60s per-request HTTP timeout minus 10s of headroom, so the budget always expires as a response carrying the run's current status rather than as a client-side timeout. Raising this alone has no effect; raise [`WORKFLOW_REQUEST_TIMEOUT_MS`](/worlds/vercel#workflow_request_timeout_ms) as well.
45
+
46
+ Read by the process awaiting `Run.returnValue`, like the interval above.
31
47
 
32
48
  ### `WORKFLOW_RETURN_VALUE_MAX_LONG_POLLS`
33
49
 
34
50
  - Default: `10`
35
- - Minimum: `1`
36
- - How many consecutive waits `Run.returnValue` issues before falling back to interval polling for the rest of the await.
37
- - It never ends the await. A run that outlives the cap continues waiting on `WORKFLOW_RETURN_VALUE_POLL_INTERVAL_MS` instead.
38
- - Runs longer than roughly `WORKFLOW_RETURN_VALUE_MAX_LONG_POLLS` x `WORKFLOW_RETURN_VALUE_WAIT_MS` therefore spend most of their life interval polling, which costs more requests than continuing to wait would. Raise it if you routinely await long runs.
39
- - Read by the process awaiting `Run.returnValue`, like the interval above.
51
+
52
+ How many consecutive waits `Run.returnValue` issues before falling back to interval polling for the rest of the await. A wait that fails with a transient World error does not count. Minimum `1`.
53
+
54
+ Change it when: you routinely await long runs. Raise it.
55
+
56
+ It never ends the await. A run that outlives the cap continues waiting on `WORKFLOW_RETURN_VALUE_POLL_INTERVAL_MS` instead. Runs longer than roughly `WORKFLOW_RETURN_VALUE_MAX_LONG_POLLS` x `WORKFLOW_RETURN_VALUE_WAIT_MS` therefore spend most of their life interval polling, which costs more requests than continuing to wait would.
57
+
58
+ Read by the process awaiting `Run.returnValue`, like the interval above.
40
59
 
41
60
  ### `WORKFLOW_CHILD_RUN_COMPLETION_HOOK`
42
61
 
43
62
  - Default: enabled
44
- - Inside a workflow, awaiting `returnValue` of a run that workflow started suspends the parent on a system hook the child resumes when it finishes, instead of polling. See [Child Workflows](/cookbook/advanced/child-workflows#how-the-parent-waits).
45
- - Set to `0` or `false` to stop `start()` from marking new child runs for the hook, so their parents poll `returnValue` inside a step on the variables above.
46
- - Read by the deployment calling `start()` from a workflow. A child already marked keeps resuming its parent, so a parent waiting on it is never stranded.
63
+
64
+ Whether, inside a workflow, awaiting `returnValue` of a run that workflow started suspends the parent on a system hook the child resumes when it finishes, instead of polling. See [Child Workflows](/cookbook/advanced/child-workflows#how-the-parent-waits).
65
+
66
+ Set to `0` or `false` to stop `start()` from marking new child runs for the hook, so their parents poll `returnValue` inside a step on the variables above.
67
+
68
+ Read by the deployment calling `start()` from a workflow. A child already marked keeps resuming its parent, so a parent waiting on it is never stranded.
47
69
 
48
70
  ## Replay and queue delivery
49
71
 
72
+ | Variable | Default | What it does |
73
+ | --- | --- | --- |
74
+ | [`WORKFLOW_REPLAY_TIMEOUT_MS`](#workflow_replay_timeout_ms) | `240000` ms | Replay and orchestration time budget per handler invocation |
75
+ | [`WORKFLOW_REPLAY_TIMEOUT_MAX_RETRIES`](#workflow_replay_timeout_max_retries) | `3` | Replay timeouts before the run fails with `REPLAY_TIMEOUT` |
76
+ | [`WORKFLOW_MAX_QUEUE_DELIVERIES`](#workflow_max_queue_deliveries) | `48` | Orchestrator delivery attempts before a run fails |
77
+ | [`WORKFLOW_QUEUE_AUTH`](#workflow_queue_auth) | `on` | Local and loopback Worlds only: flow route accepts only the app's own deliveries |
78
+ | [`WORKFLOW_MAX_EVENTS`](#workflow_max_events) | `25000` | Local World event limit and default `events.list()` page size |
79
+ | [`WORKFLOW_REPLAY_DIVERGENCE_MAX_RETRIES`](#workflow_replay_divergence_max_retries) | `3` | Recovery replays before replay divergence is recorded as corruption |
80
+ | [`WORKFLOW_DEPLOYMENT_MISMATCH_MAX_RETRIES`](#workflow_deployment_mismatch_max_retries) | `3` | Re-routes to a run's pinned deployment before the run fails |
81
+ | [`WORKFLOW_OPEN_WAIT_CLOCK_SKEW_MS`](#workflow_open_wait_clock_skew_ms) | `30000` ms | Clock-skew allowance when a pending wait decides whether the orchestrator runs ahead |
82
+ | [`WORKFLOW_PRECONDITION_MAX_INPROCESS_RESTARTS`](#workflow_precondition_max_inprocess_restarts) | `3` | In-process replay restarts after a rejected event creation |
83
+ | [`WORKFLOW_PRECONDITION_MAX_REINVOCATIONS`](#workflow_precondition_max_reinvocations) | `5` | Re-invocations per run after rejected event creations |
84
+ | [`WORKFLOW_PRECONDITION_REINVOKE_DELAY_SECONDS`](#workflow_precondition_reinvoke_delay_seconds) | `2` s | Delay before such a re-invocation |
85
+
50
86
  ### `WORKFLOW_REPLAY_TIMEOUT_MS`
51
87
 
52
88
  - Default: `240000`
53
- - Clamp: `30000` to `780000`
54
- - Charged time budget for replay and orchestration work in one handler invocation.
55
- - Covers loading events, re-running the workflow function, resolving suspensions, and scheduling follow-up work.
56
- - Does not include time spent inside inline `"use step"` bodies. Steps are bounded by the platform function duration instead.
57
89
 
58
- For example, a workflow can run a 10-minute inline step even with `WORKFLOW_REPLAY_TIMEOUT_MS=300000`, because the replay budget is paused while the step body runs.
90
+ Charged time budget, in milliseconds, for replay and orchestration work in one handler invocation. Clamped to `30000`-`780000`.
91
+
92
+ Covers loading events, re-running the workflow function, resolving suspensions, and scheduling follow-up work.
93
+
94
+ Does not include time spent inside inline `"use step"` bodies. Steps are bounded by the platform function duration instead. For example, a workflow can run a 10-minute inline step even with `WORKFLOW_REPLAY_TIMEOUT_MS=300000`, because the replay budget is paused while the step body runs.
59
95
 
60
96
  ### `WORKFLOW_REPLAY_TIMEOUT_MAX_RETRIES`
61
97
 
62
98
  - Default: `3`
63
- - Queue deliveries that may hit the replay timeout before the run is failed with `REPLAY_TIMEOUT`.
99
+
100
+ Queue deliveries that may hit the replay timeout before the run is failed with `REPLAY_TIMEOUT`.
64
101
 
65
102
  ### `WORKFLOW_MAX_QUEUE_DELIVERIES`
66
103
 
67
104
  - Default: `48`
68
- - Delivery attempts before a run or step is failed gracefully.
69
- - Can only be lowered. Workflow calibrates the default to record failure before the queue expires the message.
105
+
106
+ Delivery attempts of a run's [orchestrator](#orchestrator) messages before the run is failed gracefully.
107
+
108
+ A delivery the [in-band fence](/docs/api-reference/workflow-errors/in-band-superseded-error) refuses counts, so a run whose every write is refused fails instead of looping. A step's queue message retries in place and is bounded by the step's `maxRetries` instead. Past this cap, a step that shows no activity for an hour (every delivery fails before the step starts, for example because its input cannot be read) fails with a catchable `FatalError` naming `MAX_DELIVERIES_EXCEEDED`.
109
+
110
+ Can only be lowered. Workflow calibrates the default to record failure before the queue expires the message.
111
+
112
+ <Spec8Note>
113
+ every delivery of a run's or a step's queue message counts, and the run or step is failed gracefully once it reaches the cap.
114
+ </Spec8Note>
70
115
 
71
116
  ### `WORKFLOW_QUEUE_AUTH`
72
117
 
73
118
  - Default: `on`
74
- - Applies to the [Local World](/worlds/local), and to any World that declares `queueAuthMode: 'loopback'`. A World that declares nothing is not checked; the runtime logs a warning when its flow route starts (once, then at most once a minute when routes restart). With `on`, the Workflow SDK's flow route (`POST /.well-known/workflow/v1/flow`) accepts only deliveries sent by the app's own processes. A queue consumer's own route (built with `world.createQueueHandler()` and registered with `registerRoute()`) is not checked; it must authenticate deliveries itself, or sit behind the network edge.
75
- - Every delivery the Local World sends carries the app's queue key. The route refuses a request that does not carry the key with a `401`, before it reads the body, and does not touch any run. A request from outside the app therefore cannot start a run, fail a running one, re-trigger a step, or replay a delivery.
76
- - The key is a random value in the file `queue-auth-key` in the Local World's data directory, readable only by its owner (Windows does not enforce that the same way). The app writes a new key each time it starts, before it sends any delivery, and the data directory gets a `.gitignore` that keeps the key out of git. See [the Local World's data directory](/worlds/local#data-directory-layout).
77
- - The usual setups need nothing: the app's own queue, the CLI, the web UI, a script calling `start()` or `resumeHook()`, and several app processes all use the same data directory, so they send a key the app accepts. Point the CLI and the web UI at the app's data directory (`WORKFLOW_LOCAL_DATA_DIR`). Set `off` on the app only when a delivery comes from a process that cannot read that directory.
78
- - `off` accepts unauthenticated deliveries. Use it only for local development or on a trusted network. The runtime logs a warning when a route starts with `off`.
79
- - `off` is refused while [dynamic workflows](/docs/advanced/dynamic-workflows) are enabled (`WORKFLOW_EXPERIMENTAL_DYNAMIC_WORKFLOWS`). Both variables are read on every delivery, so the check comes back on as soon as dynamic workflows are enabled.
80
- - The `401` is marked as the runtime's own refusal (an `x-workflow-auth-refused: 1` header). The Local World's queue then reads the key file again: if another process wrote a new key, it retries at once with that key. Otherwise it retries a few times with its short backoff, then logs one line and gives the message up. A refused delivery reaches no handler and touches no run, so retrying it is safe and it does not count as an attempt. A given-up message's run is left as it was. A `401` without the marker, for example from a proxy, gets the queue's normal retries.
81
- - Each refusal increments the OpenTelemetry counter `workflow.queue.delivery.refused` (when a meter provider is registered). Its attributes are `workflow.world`, `http.route`, and `workflow.queue.refusal_reason` (`no-key` or `wrong-key`). A refusal right after the app, the CLI or a script starts is expected: it wrote a new key, and the sender reloads it and retries on its own. Alert on refusals that persist, which mean forged requests or a sender that cannot get the app's key. The refusal log is rate-limited to one line a minute per process; the counter counts every refusal.
82
- - Any value other than `off` leaves the check on. Worlds that declare `queueAuthMode: 'skip'` are not checked and are not affected. The [Vercel World](/worlds/vercel) delivers to a route only Vercel Queues can trigger (see its [security section](/worlds/vercel#security)). The [Postgres World](/worlds/postgres) relies on its database credentials to control who can enqueue, and its flow route accepts any well-formed request, so protect that route at the network edge, as its [security section](/worlds/postgres#protect-the-queue-route) describes.
119
+
120
+ On the [Local World](/worlds/local) and any World that declares `queueAuthMode: 'loopback'`, whether the Workflow SDK's flow route (`POST /.well-known/workflow/v1/flow`) accepts only deliveries sent by the app's own processes. Other Worlds are not protected by it. Any value other than `off` leaves the check on.
121
+
122
+ A World that declares nothing is not checked; the runtime logs a warning when its flow route starts (once, then at most once a minute when routes restart). Worlds that declare `queueAuthMode: 'skip'` are not checked and are not affected. A queue consumer's own route (built with `world.createQueueHandler()` and registered with `registerRoute()`) is not checked; it must authenticate deliveries itself, or sit behind the network edge.
123
+
124
+ The [Vercel World](/worlds/vercel) delivers to a route only Vercel Queues can trigger (see its [security section](/worlds/vercel#security)). The [Postgres World](/worlds/postgres) relies on its database credentials to control who can enqueue, and its flow route accepts any well-formed request, so protect that route at the network edge, as its [security section](/worlds/postgres#protect-the-queue-route) describes.
125
+
126
+ Change it when: a process that cannot read the app's data directory has to send deliveries. If the sender is the CLI or the web UI, point it at the app's data directory (`WORKFLOW_LOCAL_DATA_DIR`) instead. Set `off` on the app only when that isn't possible. `off` accepts unauthenticated deliveries, so use it only for local development or on a trusted network. The runtime logs a warning when a route starts with `off`.
127
+
128
+ `off` is refused while [dynamic workflows](/docs/advanced/dynamic-workflows) are enabled (`WORKFLOW_EXPERIMENTAL_DYNAMIC_WORKFLOWS`). Both variables are read on every delivery, so the check comes back on as soon as dynamic workflows are enabled.
129
+
130
+ Every delivery the Local World sends carries the app's queue key. The route refuses a request that does not carry the key with a `401`, before it reads the body, and does not touch any run. A request from outside the app therefore cannot start a run, fail a running one, re-trigger a step, or replay a delivery.
131
+
132
+ The key is a random value in the file `queue-auth-key` in the Local World's data directory, readable only by its owner (Windows does not enforce that the same way). The app writes a new key each time it starts, before it sends any delivery, and the data directory gets a `.gitignore` that keeps the key out of git. See [the Local World's data directory](/worlds/local#data-directory-layout).
133
+
134
+ The usual setups need nothing: the app's own queue, the CLI, the web UI, a script calling `start()` or `resumeHook()`, and several app processes all use the same data directory, so they send a key the app accepts. Point the CLI and the web UI at the app's data directory (`WORKFLOW_LOCAL_DATA_DIR`).
135
+
136
+ The `401` is marked as the runtime's own refusal (an `x-workflow-auth-refused: 1` header). The Local World's queue then reads the key file again: if another process wrote a new key, it retries at once with that key. Otherwise it retries a few times with its short backoff, then logs one line and gives the message up. A refused delivery reaches no handler and touches no run, so retrying it is safe and it does not count as an attempt. A given-up message's run is left as it was. A `401` without the marker, for example from a proxy, gets the queue's normal retries.
137
+
138
+ Each refusal increments the OpenTelemetry counter `workflow.queue.delivery.refused` (when a meter provider is registered). Its attributes are `workflow.world`, `http.route`, and `workflow.queue.refusal_reason` (`no-key` or `wrong-key`). A refusal right after the app, the CLI or a script starts is expected: it wrote a new key, and the sender reloads it and retries on its own. Alert on refusals that persist, which mean forged requests or a sender that cannot get the app's key. The refusal log is rate-limited to one line a minute per process; the counter counts every refusal.
83
139
 
84
140
  ### `WORKFLOW_MAX_EVENTS`
85
141
 
86
142
  - Default: `25000`
87
- - Positive-integer event limit reported by the Local World and enforced by the runtime as `MAX_EVENTS_EXCEEDED`.
88
- - The Local and Postgres Worlds also use it as the maximum number of events returned when `events.list()` is called without a limit. If more events exist, the response includes `hasMore: true` and a continuation cursor.
89
- - The Vercel World receives its event limit from the service; this environment variable does not override that service-owned value. See [Vercel World limits](/worlds/vercel#per-run-limits).
90
- - Runs started on the QuickJS engine with snapshotting enabled (see [`WORKFLOW_SNAPSHOT_THRESHOLD`](#workflow_snapshot_threshold)) are exempt from this limit on the Local and Vercel Worlds. See [max-events-exceeded](/docs/errors/max-events-exceeded).
91
- - Invalid or non-positive values fall back to the default.
143
+
144
+ Positive-integer event limit reported by the Local World and enforced by the runtime as `MAX_EVENTS_EXCEEDED`. Invalid or non-positive values fall back to the default.
145
+
146
+ The Local and Postgres Worlds also use it as the maximum number of events returned when `events.list()` is called without a limit. If more events exist, the response includes `hasMore: true` and a continuation cursor.
147
+
148
+ The Vercel World receives its event limit from the service; this environment variable does not override that service-owned value. See [Vercel World limits](/worlds/vercel#per-run-limits).
149
+
150
+ Runs started on the QuickJS engine with snapshotting enabled (see [`WORKFLOW_SNAPSHOT_THRESHOLD`](#workflow_snapshot_threshold)) are exempt from this limit on the Local and Vercel Worlds. See [max-events-exceeded](/docs/errors/max-events-exceeded).
92
151
 
93
152
  ### `WORKFLOW_REPLAY_DIVERGENCE_MAX_RETRIES`
94
153
 
95
154
  - Default: `3`
96
- - Recovery replays before replay divergence is recorded as corruption.
155
+
156
+ Recovery replays before replay divergence is recorded as corruption.
157
+
158
+ On the Node.js VM engine, a recovery replay reloads the event log and replays from scratch in a fresh VM in the same delivery. Once the budget is spent, the run fails with [`CORRUPTED_EVENT_LOG`](/docs/errors/corrupted-event-log). A redelivery starts the count again, and `WORKFLOW_MAX_QUEUE_DELIVERIES` bounds it.
159
+
160
+ <Spec8Note>
161
+ each recovery replay is queued as a new delivery of the run.
162
+ </Spec8Note>
97
163
 
98
164
  ### `WORKFLOW_DEPLOYMENT_MISMATCH_MAX_RETRIES`
99
165
 
100
166
  - Default: `3`
101
- - Times a delivery that reached a deployment other than the one its run is pinned to is re-routed to that deployment before the run is failed with [`DEPLOYMENT_MISMATCH`](/docs/errors/deployment-mismatch).
102
- - Re-routed deliveries back off exponentially (1s, 2s, 4s). Set to `0` to fail the run on the first misrouted delivery.
103
- - Only applies to Worlds with atomic, immutable deployments (the Vercel World). A run whose pinned deployment cannot be reached at all fails immediately regardless of this value.
104
- - Transient or unknown queue publishing failures use normal queue redelivery and do not consume this budget.
167
+
168
+ Times a delivery that reached a deployment other than the one its run is pinned to is re-routed to that deployment before the run is failed with [`DEPLOYMENT_MISMATCH`](/docs/errors/deployment-mismatch). Set to `0` to fail the run on the first misrouted delivery.
169
+
170
+ Re-routed deliveries back off exponentially (1s, 2s, 4s).
171
+
172
+ Only applies to Worlds with atomic, immutable deployments (the Vercel World). A run whose pinned deployment cannot be reached at all fails immediately regardless of this value.
173
+
174
+ Transient or unknown queue publishing failures use normal queue redelivery and do not consume this budget.
105
175
 
106
176
  ### `WORKFLOW_OPEN_WAIT_CLOCK_SKEW_MS`
107
177
 
108
178
  - Default: `30000` (30 seconds)
109
- - A pending wait (a `sleep()` whose timer has not fired, including one that lost a `Promise.race()` against a hook) keeps the per-step event-log delta optimization off only if it can fire while the current invocation is still running steps inline: its target time must fall before the end of the invocation's inline window ([`WORKFLOW_V2_TIMEOUT_MS`](#workflow_v2_timeout_ms), which is otherwise derived from the platform's function deadline and tops out at 10 minutes) plus this allowance for clock skew between the runtime and the wait timer. A wait due later than that does not cost the extra `events.list()` per step. A `wait_created` whose target time cannot be read is treated as due now.
110
- - Before an invocation parks on a wait over a log it last extended from a step's inline delta, it re-reads the log once, so a wait completed early through `run.wakeUp()` (the dashboard's "cancel sleeps" action) is acted on then rather than when the wait's own timer would have fired.
111
- - Turbo's forced optimistic start is unaffected: any open wait keeps it off, whatever the target time.
112
- - Must be a finite integer. `31536000000` (one year) restores the older behavior of gating on any pending wait; `Infinity` is rejected and falls back to the default. Open hooks are unaffected: they gate regardless of this setting.
179
+
180
+ Allowance for clock skew between the runtime and the wait timer, used when deciding whether a pending wait stops the orchestrator from [running ahead](#workflow_run_ahead_depth) of its writes. Must be a finite integer; `Infinity` is rejected and falls back to the default.
181
+
182
+ A pending wait (a `sleep()` whose timer has not fired, including one that lost a `Promise.race()` against a hook) stops run-ahead at a boundary only if its target time falls within this allowance of now (at least 1 second), and before the end of the invocation's inline window ([`WORKFLOW_V2_TIMEOUT_MS`](#workflow_v2_timeout_ms), which is otherwise derived from the platform's function deadline and tops out at 10 minutes) plus this allowance. A wait due later still completes on time; its `wait_completed` is written after the writes in flight. A `wait_created` whose target time cannot be read is treated as due now.
183
+
184
+ Turbo's forced optimistic start is unaffected: any open wait keeps it off, whatever the target time.
185
+
186
+ <Spec8Note>
187
+ a pending wait whose target time falls before the end of the inline window plus this allowance keeps the per-step event-log delta optimization off instead, and a wait due later does not cost the extra `events.list()` per step. Before an invocation parks on a wait over a log it last extended from a step's inline delta, it re-reads the log once, so a wait completed early through `run.wakeUp()` (the dashboard's "cancel sleeps" action) is acted on then rather than when the wait's own timer would have fired. `31536000000` (one year) gates on any pending wait. Open hooks gate regardless of this setting.
188
+ </Spec8Note>
113
189
 
114
190
  ### Stale reads, and why nothing has to be rejected
115
191
 
116
192
  - Not a variable: this is how a replay working from an out-of-date event log stays correct, and why no World needs a precondition guard to make it so.
117
193
  - Three properties work together. A reader's log is always a **prefix** of the run's log, never a prefix with a hole in it. The World allocates positions at commit, so nothing lands behind a position a reader has already passed. Replay is **deterministic on a prefix**: the same prefix always yields the same decisions, so a shorter log does not mean a different run, only a run that has not caught up. Every write **reports what it missed**: a creation names the position it replayed from (`eventCount`), and the World returns the events occupying the positions it was pushed past. The replay merges those and continues, correcting itself on the write rather than on a read.
118
194
  - So a stale replay costs a merge, not a rejection. None of the shipped Worlds refuses a write for being stale.
119
- - A World *may* refuse instead, with 412 ([`PreconditionFailedError`](/docs/api-reference/workflow-errors/precondition-failed-error)). This is appropriate when it allocates positions somewhere other than the commit and cannot report a gap reliably. The runtime restarts the replay in the same invocation from a corrected event log and falls back to a re-invocation with a fresh replay after spending the restart budget. It never retries the rejected write as-is because a replay working from a corrected log derives different events.
120
- - A World that does refuse should only ever do so on evidence, and accept the write in every other case. A rejection then always means the position was stale, while the absence of one proves nothing about currency.
121
- - Two runtime behaviors follow from the properties above rather than from any fence. The per-step event-log delta optimization (consuming the delta returned by a step's terminal write instead of issuing an extra `events.list` per step) stays active while the run has an open hook. A `hook_received` event missed by the delta window is observed one iteration later, and the next write brings it back. While a hook is open, inline steps take the await-then-run path even when optimistic inline start is enabled. Several invocations race for one step's claim there, and awaiting it means the body runs only for the writer that won.
195
+ - One orchestrator invocation at a time writes a run's decisions. The World refuses a write only from an invocation another one has superseded, with [`InBandSupersededError`](/docs/api-reference/workflow-errors/in-band-superseded-error), and the runtime handles that refusal itself.
196
+
197
+ <Spec8Note>
198
+ every queue delivery replays the run and writes its own decisions, and a World *may* refuse a stale write with 412 ([`PreconditionFailedError`](/docs/api-reference/workflow-errors/precondition-failed-error)). This is appropriate when it allocates positions somewhere other than the commit and cannot report a gap reliably. A World that does refuse should only ever do so on evidence, and accept the write in every other case: a rejection then always means the position was stale, while the absence of one proves nothing about currency. The runtime restarts the replay in the same invocation from a corrected event log, and falls back to a re-invocation with a fresh replay after spending the restart budget below. It never retries the rejected write as-is, because a replay working from a corrected log derives different events.
199
+
200
+ Two runtime behaviors follow from the properties above rather than from any fence. The per-step event-log delta optimization (consuming the delta returned by a step's terminal write instead of issuing an extra `events.list` per step) stays active while the run has an open hook: a `hook_received` event missed by the delta window is observed one iteration later, and the next write brings it back. While a hook is open, inline steps take the await-then-run path even when optimistic inline start is enabled. Several invocations race for one step's claim there, and awaiting it means the body runs only for the writer that won.
201
+ </Spec8Note>
202
+
203
+ The `WORKFLOW_PRECONDITION_*` settings below have no effect on runs that use the in-band fence.
204
+
205
+ <Spec8Note>
206
+ the runtime reads the `WORKFLOW_PRECONDITION_*` settings when a World refuses a stale write.
207
+ </Spec8Note>
122
208
 
123
209
  ### `WORKFLOW_PRECONDITION_MAX_INPROCESS_RESTARTS`
124
210
 
125
211
  - Default: `3`
126
- - How many times a single invocation restarts its replay in-process after an event creation is [rejected as stale](#stale-reads-and-why-nothing-has-to-be-rejected) before it falls back to a re-invocation. No shipped World rejects one, so this budget is reserved for a World that chooses to.
127
- - A restart reloads the event log and rebuilds the workflow from scratch, so it costs a replay but no queue round trip. A World may attach the missing events to its rejection, in which case the first restart needs no event-log request at all.
212
+
213
+ How many times a single invocation restarts its replay in-process after an event creation is [rejected as stale](#stale-reads-and-why-nothing-has-to-be-rejected) before it falls back to a re-invocation. No shipped World rejects one, so this budget is reserved for a World that chooses to.
214
+
215
+ A restart reloads the event log and rebuilds the workflow from scratch, so it costs a replay but no queue round trip. A World may attach the missing events to its rejection, in which case the first restart needs no event-log request at all.
128
216
 
129
217
  ### `WORKFLOW_PRECONDITION_MAX_REINVOCATIONS`
130
218
 
131
219
  - Default: `5`
132
- - How many re-invocations one run may spend on rejected event creations before it is failed with `RUNTIME_ERROR`.
133
- - Counted on the run's queue messages rather than per invocation, because a re-invocation enqueues a fresh message and so restarts the ordinary delivery count. Without this budget a run whose event log keeps growing faster than it can be read would cycle indefinitely.
220
+
221
+ How many re-invocations one run may spend on rejected event creations before it is failed with `RUNTIME_ERROR`.
222
+
223
+ Counted on the run's queue messages rather than per invocation, because a re-invocation enqueues a fresh message and so restarts the ordinary delivery count. Without this budget a run whose event log keeps growing faster than it can be read would cycle indefinitely.
134
224
 
135
225
  ### `WORKFLOW_PRECONDITION_REINVOKE_DELAY_SECONDS`
136
226
 
137
227
  - Default: `2`
138
- - Delay before a re-invocation caused by a rejected event creation.
139
- - Unlike an in-process restart, which re-reads immediately, a re-invocation only happens after the in-process budget fails to catch up. The delay gives the other writers time to quiesce.
228
+
229
+ Delay, in seconds, before a re-invocation caused by a rejected event creation.
230
+
231
+ Unlike an in-process restart, which re-reads immediately, a re-invocation only happens after the in-process budget fails to catch up. The delay gives the other writers time to quiesce.
140
232
 
141
233
  ## Inline execution
142
234
 
235
+ | Variable | Default | What it does |
236
+ | --- | --- | --- |
237
+ | [`WORKFLOW_V2_TIMEOUT_MS`](#workflow_v2_timeout_ms) | derived from the runtime deadline (`120000`-`600000` ms) | Wall-clock guard for the inline replay loop |
238
+ | [`WORKFLOW_MAX_INLINE_STEPS`](#workflow_max_inline_steps) | `3` | New steps one invocation runs inline in parallel |
239
+ | [`WORKFLOW_TURBO`](#workflow_turbo) | enabled | Fast path for a run's first delivery |
240
+ | [`WORKFLOW_OPTIMISTIC_INLINE_START`](#workflow_optimistic_inline_start) | unset | `0` makes first-delivery and run-ahead step bodies wait for their start to commit |
241
+ | [`WORKFLOW_OPTIMISTIC_BACKGROUND_START`](#workflow_optimistic_background_start) | unset | Starts background step bodies before `step_started` commits |
242
+ | [`WORKFLOW_INLINE_STEP_DEADLINE_MARGIN_MS`](#workflow_inline_step_deadline_margin_ms) | `60000` ms | When the orchestrator stops starting inline steps |
243
+ | [`WORKFLOW_RUN_AHEAD_DEPTH`](#workflow_run_ahead_depth) | `10` | Unconfirmed inline step outcomes allowed at once |
244
+ | [`WORKFLOW_RETAINED_VM`](#workflow_retained_vm) | enabled | Keeps the Node.js workflow VM alive across inline steps |
245
+ | [`WORKFLOW_INLINE_OWNERSHIP_LEASE_SECONDS`](#workflow_inline_ownership_lease_seconds) | `860` s | How long an inline step's owner is assumed to still be running it |
246
+
143
247
  ### `WORKFLOW_V2_TIMEOUT_MS`
144
248
 
145
249
  - Default: derived from the runtime deadline. The value is `600000` when the invocation has 25 minutes or more left, `300000` when it has 10 minutes or more, and `120000` otherwise.
146
- - Wall-clock guard for the inline replay loop.
147
- - Once elapsed, the handler requeues the workflow instead of continuing to run more inline work in the same invocation.
148
- - The default comes from `World.getRuntimeDeadline()`, so raising a function's `maxDuration` widens the inline budget without configuration. Worlds that do not report a deadline get the flat `120000`. Setting this variable to a finite positive number overrides the tiering entirely.
250
+
251
+ Wall-clock guard, in milliseconds, for the inline replay loop. Once elapsed, the handler requeues the workflow instead of continuing to run more inline work in the same invocation.
252
+
253
+ The default comes from `World.getRuntimeDeadline()`, so raising a function's `maxDuration` widens the inline budget without configuration. Worlds that do not report a deadline get the flat `120000`. Setting this variable to a finite positive number overrides the tiering entirely.
149
254
 
150
255
  ### `WORKFLOW_MAX_INLINE_STEPS`
151
256
 
152
257
  - Default: `3`
153
- - Clamp: `1` to `16`
154
- - Number of newly-created steps one invocation runs inline in parallel before queueing the rest.
155
- - Steps started beside an awaited hook registration (`hook.getConflict()`) count against the same cap. They are held for the pass that observes the registration and then run inline on it, so the registration still precedes them; only the steps past the cap are queued.
258
+
259
+ Number of newly-created steps one invocation runs inline in parallel before queueing the rest. Inline steps already open or running count against it. Values above `16` are clamped to `16`; a negative value or a non-integer uses the default. `0` queues every step.
260
+
261
+ Steps created while a new hook waits on its registration (`hook.getConflict()`), or within [`WORKFLOW_INLINE_STEP_DEADLINE_MARGIN_MS`](#workflow_inline_step_deadline_margin_ms) of the end of the inline window, are queued. A step runs inline at most once: its retry runs from its own queue message.
262
+
263
+ <Spec8Note>
264
+ the runtime treats `0` as unset and uses the default. Steps started beside an awaited hook registration count against the same cap. They are held for the pass that observes the registration and then run inline on it, so the registration still precedes them; only the steps past the cap are queued.
265
+ </Spec8Note>
156
266
 
157
267
  ### `WORKFLOW_TURBO`
158
268
 
159
269
  - Default: enabled
160
- - Fast path for a run's first delivery.
161
- - Applies only while that delivery's queue message is at most 15 seconds old. An older one, such as a platform re-running a crashed invocation, loads the event log first.
162
- - Stops forcing optimistic inline step start once the run creates a hook or wait.
163
- - A run started with `start({ experimental_hook })` never runs steps before `run_started` returns, but its first delivery still writes `run_started` without loading the event log first.
164
- - Set `0` or `false` to disable, including for such runs.
270
+
271
+ Fast path for a run's first delivery. Set `0` or `false` to disable, including for runs started with `start({ experimental_hook })`.
272
+
273
+ Applies only while that delivery's queue message is at most 15 seconds old. An older one, such as a platform re-running a crashed invocation, loads the event log first.
274
+
275
+ It stops forcing optimistic inline step start once the run creates a hook or wait.
276
+
277
+ A run started with `start({ experimental_hook })` never runs steps before `run_started` returns, but its first delivery still writes `run_started` without loading the event log first.
278
+
279
+ <Spec8Note>
280
+ the queue message's age is not checked.
281
+ </Spec8Note>
165
282
 
166
283
  ### `WORKFLOW_OPTIMISTIC_INLINE_START`
167
284
 
168
- - Default: disabled
169
- - Starts inline step bodies before their `step_started` event is confirmed.
170
- - Use only when step side effects are idempotent.
171
- - Set `0` or `false` to force it off, including the first-delivery fast path used by `WORKFLOW_TURBO`.
285
+ - Default: unset
286
+
287
+ Inline step bodies start before their `step_started` event is confirmed only on a run's first delivery under `WORKFLOW_TURBO`, and while the orchestrator [runs ahead](#workflow_run_ahead_depth) of its writes. Set `0` or `false` to make those bodies wait for their start to commit, and to override [`WORKFLOW_OPTIMISTIC_BACKGROUND_START`](#workflow_optimistic_background_start). No other value has an effect.
288
+
289
+ Those are the only cases where the runtime knows no other writer can change the run.
290
+
291
+ <Spec8Note>
292
+ `1` or `true` starts every inline step body before its `step_started` is confirmed. Use it only when step side effects are idempotent.
293
+ </Spec8Note>
294
+
295
+ ### `WORKFLOW_OPTIMISTIC_BACKGROUND_START`
296
+
297
+ - Default: unset
298
+
299
+ Starts a background step's body before its `step_started` commits, on its message's first delivery, saving one round trip. Set `1` or `true` to enable it. Use only when background step bodies are idempotent.
300
+
301
+ A step queued before `run.cancel()` then still runs its body. Steps with `maxRetries: 0` and redeliveries always wait for their start to commit.
302
+
303
+ <Spec8Note>
304
+ the runtime ignores this setting.
305
+ </Spec8Note>
306
+
307
+ ### `WORKFLOW_INLINE_STEP_DEADLINE_MARGIN_MS`
308
+
309
+ - Default: `60000`
310
+
311
+ How long, in milliseconds, before the inline window ([`WORKFLOW_V2_TIMEOUT_MS`](#workflow_v2_timeout_ms)) ends the orchestrator stops starting inline steps. Steps created inside the margin are queued.
312
+
313
+ <Spec8Note>
314
+ the runtime ignores this setting.
315
+ </Spec8Note>
316
+
317
+ ### `WORKFLOW_RUN_AHEAD_DEPTH`
318
+
319
+ - Default: `10`
320
+
321
+ Maximum number of inline step outcomes that may be unconfirmed at once while the orchestrator runs ahead of its writes. Clamped to `0`-`16`; `0` disables run-ahead. Node.js VM engine only.
322
+
323
+ When no other writer could change what the workflow does next (no awaited hook, no `AbortController`, no step running elsewhere, no wait due), an inline step's outcome reaches the workflow when its body returns, before its write commits. Writes still land in order.
324
+
325
+ <Spec8Note>
326
+ the orchestrator never runs ahead of its writes, and the runtime ignores this setting.
327
+ </Spec8Note>
172
328
 
173
329
  ### `WORKFLOW_RETAINED_VM`
174
330
 
175
331
  - Default: enabled
176
- - Node.js VM engine only. Keeps the suspended workflow VM alive across inline steps within one invocation, so each iteration of the inline loop appends only the newly written events instead of replaying the whole event log in a fresh VM. QuickJS manages its own retained inline loop independently of this setting.
177
- - A step- or attribute-driven suspension can keep the VM retained even when hooks or waits are open or created at the same boundary. Hook- or wait-only suspensions park the invocation because nothing in the current delivery can advance them, with one exception: when the hook's own create is what the workflow is waiting on (a `hook.getConflict()` awaiter, or a create whose token is already claimed), the invocation resumes the retained VM over the committed `hook_created` or `hook_conflict` instead of re-invoking through the queue, and runs the steps started at that same boundary on the pass after it. Any replay divergence falls back to a full replay.
178
- - Step inputs made of plain data (objects, arrays, primitives) and standard built-ins (`Map`, `Set`, `Date`, `RegExp`, typed arrays, `ArrayBuffer`, `URL`, `Headers`) keep the VM retained. Patching or polyfilling built-in prototypes doesn't change that because serialization never calls them. A boundary falls back to a full replay only when serializing its arguments runs code the workflow controls, such as a getter, a proxy, or a custom class serializer, or computes an `Error`'s stack trace.
179
- - Set `0` or `false` to replay the Node.js workflow from scratch in a fresh VM on every iteration.
332
+
333
+ Node.js VM engine only. Keeps the suspended workflow VM alive across inline steps within one invocation, so each iteration of the inline loop appends only the newly written events instead of replaying the whole event log in a fresh VM. Set `0` or `false` to replay the Node.js workflow from scratch in a fresh VM on every iteration.
334
+
335
+ QuickJS manages its own retained inline loop independently of this setting.
336
+
337
+ A step- or attribute-driven suspension can keep the VM retained even when hooks or waits are open or created at the same boundary. Hook- or wait-only suspensions park the invocation because nothing in the current delivery can advance them, with one exception: when the hook's own create is what the workflow is waiting on (a `hook.getConflict()` awaiter, or a create whose token is already claimed), the invocation resumes the retained VM over the committed `hook_created` or `hook_conflict` instead of re-invoking through the queue. Any replay divergence falls back to a full replay.
338
+
339
+ Step inputs made of plain data (objects, arrays, primitives) and standard built-ins (`Map`, `Set`, `Date`, `RegExp`, typed arrays, `ArrayBuffer`, `URL`, `Headers`) keep the VM retained. Patching or polyfilling built-in prototypes doesn't change that because serialization never calls them. A boundary falls back to a full replay only when serializing its arguments runs code the workflow controls, such as a getter, a proxy, or a custom class serializer, or computes an `Error`'s stack trace.
180
340
 
181
341
  ### `WORKFLOW_INLINE_OWNERSHIP_LEASE_SECONDS`
182
342
 
183
343
  - Default: `860`
184
- - Clamp: `1` to `900`
185
- - How long after an inline step's latest `step_started` other invocations assume its owner may still be executing the body. Within the lease they defer the step's backstop message; past it they enqueue immediately.
186
- - Raise this on self-hosted multi-instance deployments whose inline steps run longer than the default (the default is sized for Vercel's function duration ceiling).
344
+
345
+ How long, in seconds, after an inline step's latest `step_started` other invocations assume its owner may still be executing the body. Clamped to `1`-`900`.
346
+
347
+ Change it when: your self-hosted multi-instance deployment runs inline steps longer than the default. Raise it. The default is sized for Vercel's function duration ceiling.
348
+
349
+ Within the lease, other invocations defer the step's backstop message; past it they enqueue immediately.
350
+
351
+ <Spec8Note>
352
+ the runtime reads this setting only for these runs. Runs that use the in-band fence have no backstop messages, because an inline step belongs to the orchestrator invocation that created it.
353
+ </Spec8Note>
187
354
 
188
355
  ## Workflow VM engine
189
356
 
357
+ | Variable | Default | What it does |
358
+ | --- | --- | --- |
359
+ | [`WORKFLOW_VM`](#workflow_vm) | `node` | Engine that runs workflow functions: `node` or `quickjs` |
360
+ | [`WORKFLOW_QUICKJS_BASELINE_SNAPSHOT`](#workflow_quickjs_baseline_snapshot) | enabled | Restores a snapshot of the evaluated bundle instead of re-evaluating it |
361
+ | [`WORKFLOW_SNAPSHOT_THRESHOLD`](#workflow_snapshot_threshold) | `1000` with QuickJS | Events between QuickJS VM-memory snapshots; `0` disables |
362
+ | [`WORKFLOW_SNAPSHOT_ALLOW_UNENCRYPTED`](#workflow_snapshot_allow_unencrypted) | disabled | Snapshots runs without an encryption key |
363
+
190
364
  ### `WORKFLOW_VM`
191
365
 
192
366
  - Default: `node`
193
- - Values: `node` or `quickjs`
194
- - Selects the sandboxed VM engine that executes workflow functions (`"use workflow"`). Step functions are unaffected and always run with full Node.js access.
195
- - `node` (default) runs workflow code in a [`node:vm`](https://nodejs.org/api/vm.html) context. Every resume replays the run's full event log, so resume cost grows with the log, and runs are subject to the World's default [per-run event limit](/docs/errors/max-events-exceeded).
196
- - `quickjs` runs workflow code in a [QuickJS](https://github.com/quickjs-ng/quickjs) VM compiled to WebAssembly (via [`quickjs-wasi`](https://github.com/vercel-labs/quickjs-wasi)). **Use it for long-running workflows**: agents, chat sessions, and loops that wait on hooks or sleeps, or any run with many steps. With snapshotting (on by default, see [`WORKFLOW_SNAPSHOT_THRESHOLD`](#workflow_snapshot_threshold)), a run resumes from a VM-memory snapshot and replays only the events recorded since, so resume cost stays roughly flat as the log grows, and the run is exempt from the default per-run event limit on the Local and Vercel Worlds. It also runs on platforms that do not implement `node:vm`.
197
- - Both engines implement the same event-replay execution model (seeded PRNG, deterministic clock, and correlation-ID sequences are identical), so workflow code that sticks to plain JavaScript and the Workflow APIs runs unchanged. To switch, set `WORKFLOW_VM=quickjs` in the environment that starts runs, and runs started after that use QuickJS. The few globals QuickJS does not provide in workflow functions are listed below.
198
- - Global-surface differences under `quickjs` apply to workflow functions only. Step functions always have full Node.js, so the fix for each is to move that call into a step:
199
- - `crypto.getRandomValues()` and `crypto.randomUUID()` are provided and deterministic (seeded like the node engine's). All `crypto.subtle.*` methods, including `digest`, throw with guidance to move to a step function. The node engine supports `digest`.
200
- - `Intl` is not available (QuickJS has no ICU). The `Intl.*` constructors throw, and `toLocaleString`-family methods (including `localeCompare`) throw when called **with an explicit locale**. Calling them without arguments keeps the engine default. Perform locale-sensitive formatting in a step function.
201
- - `WebAssembly` and `Atomics` are not available.
202
- - `process` exposes only a frozen copy of `env`, matching the node engine.
203
- - The engine choice is stamped into the run's `executionContext` when the run starts, so a run keeps executing on the engine it started on even if the deployment's `WORKFLOW_VM` changes. Runs without a stamped engine use the handler's `WORKFLOW_VM` value.
204
- - Unknown values throw at startup.
367
+
368
+ Selects the sandboxed VM engine that executes workflow functions (`"use workflow"`): `node` or `quickjs`. An unknown value throws when `start()` creates a run, or when the workflow handler picks the engine for a run that has none stamped. Step functions are unaffected and always run with full Node.js access.
369
+
370
+ Change it when: you run long-running workflows. Use `quickjs` for agents, chat sessions, and loops that wait on hooks or sleeps, or any run with many steps. To switch, set `WORKFLOW_VM=quickjs` in the environment that starts runs, and runs started after that use QuickJS.
371
+
372
+ `node` (default) runs workflow code in a [`node:vm`](https://nodejs.org/api/vm.html) context. Every resume replays the run's full event log, so resume cost grows with the log, and runs are subject to the World's default [per-run event limit](/docs/errors/max-events-exceeded).
373
+
374
+ `quickjs` runs workflow code in a [QuickJS](https://github.com/quickjs-ng/quickjs) VM compiled to WebAssembly (via [`quickjs-wasi`](https://github.com/vercel-labs/quickjs-wasi)). With snapshotting (on by default for encrypted runs, see [`WORKFLOW_SNAPSHOT_THRESHOLD`](#workflow_snapshot_threshold); on world-local and world-postgres also set [`WORKFLOW_SNAPSHOT_ALLOW_UNENCRYPTED`](#workflow_snapshot_allow_unencrypted)), a run resumes from a VM-memory snapshot and replays only the events recorded since, so resume cost stays roughly flat as the log grows, and the run is exempt from the default per-run event limit on the Local and Vercel Worlds. It also runs on platforms that do not implement `node:vm`.
375
+
376
+ Both engines implement the same event-replay execution model (seeded PRNG, deterministic clock, and correlation-ID sequences are identical), so workflow code that sticks to plain JavaScript and the Workflow APIs runs unchanged. The few globals QuickJS does not provide in workflow functions are listed below.
377
+
378
+ Global-surface differences under `quickjs` apply to workflow functions only. Step functions always have full Node.js, so the fix for each is to move that call into a step:
379
+
380
+ - `crypto.getRandomValues()` and `crypto.randomUUID()` are provided and deterministic (seeded like the node engine's). All `crypto.subtle.*` methods, including `digest`, throw with guidance to move to a step function. The node engine supports `digest`.
381
+ - `Intl` is not available (QuickJS has no ICU). The `Intl.*` constructors throw, and `toLocaleString`-family methods (including `localeCompare`) throw when called **with an explicit locale**. Calling them without arguments keeps the engine default. Perform locale-sensitive formatting in a step function.
382
+ - `WebAssembly` and `Atomics` are not available.
383
+ - `process` exposes only a frozen copy of `env`, matching the node engine.
384
+
385
+ The engine choice is stamped into the run's `executionContext` when the run starts, so a run keeps executing on the engine it started on even if the deployment's `WORKFLOW_VM` changes. Runs without a stamped engine use the handler's `WORKFLOW_VM` value.
205
386
 
206
387
  ### `WORKFLOW_QUICKJS_BASELINE_SNAPSHOT`
207
388
 
208
389
  - Default: enabled
209
- - Only read when `WORKFLOW_VM=quickjs`.
210
- - Evaluates the workflow bundle once per function instance, snapshots the resulting VM, and restores that snapshot at the start of every invocation instead of re-evaluating the bundle. This is the dominant share of QuickJS VM startup: roughly 77 ms to 3 ms to first suspension for a 1.3 MB bundle.
211
- - A bundle whose module scope consumes randomness, reads the clock, or replaces a serialization intrinsic cannot be snapshotted safely. The runtime detects these cases when preparing the snapshot and falls back to per-invocation evaluation.
212
- - Set `0` or `false` to always evaluate the bundle per invocation.
390
+
391
+ Evaluates the workflow bundle once per function instance, snapshots the resulting VM, and restores that snapshot at the start of every invocation instead of re-evaluating the bundle. Only read when `WORKFLOW_VM=quickjs`. Set `0` or `false` to always evaluate the bundle per invocation.
392
+
393
+ This is the dominant share of QuickJS VM startup: roughly 77 ms to 3 ms to first suspension for a 1.3 MB bundle.
394
+
395
+ A bundle whose module scope consumes randomness, reads the clock, or replaces a serialization intrinsic cannot be snapshotted safely. The runtime detects these cases when preparing the snapshot and falls back to per-invocation evaluation.
213
396
 
214
397
  ### `WORKFLOW_SNAPSHOT_THRESHOLD`
215
398
 
216
399
  - Default: `1000` when the QuickJS engine is selected
217
- - Values: non-negative integer. `0` disables snapshotting.
218
- - Only used by the QuickJS engine (`WORKFLOW_VM=quickjs`), and only with a World that provides snapshot storage (world-local, world-postgres, and world-vercel do).
219
- - When above `0`, the runtime persists a **VM-memory snapshot** at a suspension once at least this many events have been processed since the last snapshot. Subsequent invocations restore the VM from the snapshot and replay only the events recorded since, instead of re-executing the workflow from the top against the full event log.
220
- - Short-lived runs below the threshold never pay the snapshot cost; long-running or unbounded runs stop scaling their resume cost with total event-log length. `1` snapshots at every qualifying suspension.
221
- - Choosing a value: a restore costs roughly the same regardless of log length (tens of milliseconds to decompress and restore the heap, plus fetching the snapshot), while a full replay grows with the log (tens of milliseconds at a few hundred events, seconds at several thousand). Restoring starts to pay off at a few hundred events, so values in the hundreds suit most long-running workflows. Very low values mostly add snapshot saves to runs that replay quickly anyway.
222
- - Snapshots are an optimization, not a source of truth: the event log remains authoritative, and a missing, corrupt, oversized, or incompatible snapshot automatically falls back to a full replay. Snapshots over 32 MB uncompressed are not saved.
223
- - Set `0` to opt out and always replay the full event log.
224
- - Like `WORKFLOW_VM`, the policy is stamped into the run's `executionContext` at start, so a run keeps the snapshot policy it started with. Runs started with `WORKFLOW_VM=quickjs` are stamped with this value, or the default when unset. Runs without a stamped policy use the handler's value, or the default. `start()` rejects an invalid value. An invalid value on the workflow handler disables snapshotting with a warning.
225
- - Runs stamped with `workflowVm: "quickjs"` and a positive threshold are exempt from the default [per-run event limit](/docs/errors/max-events-exceeded) on the Local and Vercel Worlds.
226
- - A snapshot can only be restored by the exact QuickJS engine build that captured it. On Vercel, runs keep executing on the deployment they started on, so deploys don't affect in-flight snapshots. If your deployment serves in-flight runs from new code (for example, a self-hosted rolling update), an upgrade that changes the embedded engine or the snapshot format makes every in-flight run fall back to a full replay at its next resume, all at once, before re-snapshotting at its next qualifying suspension. Plan for that one-time replay load when upgrading.
400
+
401
+ When above `0`, the runtime persists a **VM-memory snapshot** at a suspension once at least this many events have been processed since the last snapshot. A non-negative integer; `0` disables snapshotting, and `1` snapshots at every qualifying suspension.
402
+
403
+ Change it when: you want to opt out and always replay the full event log. Set `0`. To tune the threshold instead, see *Choosing a value* below.
404
+
405
+ Only used by the QuickJS engine (`WORKFLOW_VM=quickjs`), and only with a World that provides snapshot storage (world-local, world-postgres, and world-vercel do).
406
+
407
+ Subsequent invocations restore the VM from the snapshot and replay only the events recorded since, instead of re-executing the workflow from the top against the full event log. Short-lived runs below the threshold never pay the snapshot cost; long-running or unbounded runs stop scaling their resume cost with total event-log length.
408
+
409
+ Choosing a value: a restore costs roughly the same regardless of log length (tens of milliseconds to decompress and restore the heap, plus fetching the snapshot), while a full replay grows with the log (tens of milliseconds at a few hundred events, seconds at several thousand). Restoring starts to pay off at a few hundred events, so values in the hundreds suit most long-running workflows. Very low values mostly add snapshot saves to runs that replay quickly anyway.
410
+
411
+ Snapshots are an optimization, not a source of truth: the event log remains authoritative, and a missing, corrupt, oversized, or incompatible snapshot automatically falls back to a full replay. Snapshots over 32 MB uncompressed are not saved.
412
+
413
+ Like `WORKFLOW_VM`, the policy is stamped into the run's `executionContext` at start, so a run keeps the snapshot policy it started with. Runs started with `WORKFLOW_VM=quickjs` are stamped with this value, or the default when unset. Runs without a stamped policy use the handler's value, or the default. `start()` rejects an invalid value. An invalid value on the workflow handler disables snapshotting with a warning.
414
+
415
+ Runs stamped with `workflowVm: "quickjs"` and a positive threshold are exempt from the default [per-run event limit](/docs/errors/max-events-exceeded) on the Local and Vercel Worlds.
416
+
417
+ A snapshot can only be restored by the exact QuickJS engine build that captured it. On Vercel, runs keep executing on the deployment they started on, so deploys don't affect in-flight snapshots. If your deployment serves in-flight runs from new code (for example, a self-hosted rolling update), an upgrade that changes the embedded engine or the snapshot format makes every in-flight run fall back to a full replay at its next resume, all at once, before re-snapshotting at its next qualifying suspension. Plan for that one-time replay load when upgrading.
227
418
 
228
419
  What a snapshot contains, and how it is protected:
229
420
 
230
421
  - A snapshot is the workflow VM's memory: the workflow's code and in-memory state, including step results and hook payloads it holds, and the copy of `process.env` the VM exposes. It is executable state, so write access to snapshot storage is equivalent to running code in the workflow VM.
231
- - When the run has an encryption key, its snapshots are compressed and then encrypted with that key. The encryption also authenticates the snapshot: on restore, the runtime rejects any snapshot that isn't encrypted with the run's key, or whose stored metadata doesn't match the metadata sealed inside it.
232
- - Runs without an encryption key (world-local, world-postgres, and any World that doesn't implement `getEncryptionKeyForRun()`) are snapshotted in plaintext, the same as their event log and payloads (in `.workflow-data/snapshots/` or the `workflow_snapshots` table). Those snapshots are not authenticated, so snapshot storage needs the same protection as the rest of the World's storage.
422
+ - Snapshots are compressed and then encrypted with the run's encryption key. The encryption also authenticates the snapshot: on restore, the runtime rejects any snapshot that isn't encrypted with the run's key, or whose stored metadata doesn't match the metadata sealed inside it.
423
+ - By default, runs without an encryption key are never snapshotted. world-local and world-postgres provide no run encryption keys. Set `WORKFLOW_SNAPSHOT_ALLOW_UNENCRYPTED=1` on the workflow handler to snapshot those runs anyway. Their snapshots are stored in plaintext (in `.workflow-data/snapshots/` or the `workflow_snapshots` table) and are not authenticated. Because a snapshot holds the VM's copy of `process.env`, anyone who can read snapshot storage can read the handler's environment variables, including credentials your workflows never use. Only enable this where snapshot storage is as trusted as the deployment's environment.
233
424
  - A restored run sees `process.env` as of the current invocation, the same as a full replay.
234
425
  - Snapshots are deleted after the run reaches a terminal state. world-local and world-postgres have no separate retention for them, so a snapshot of a run that ends without any invocation observing it (for example, one cancelled externally) stays until you remove it.
235
426
 
427
+ ### `WORKFLOW_SNAPSHOT_ALLOW_UNENCRYPTED`
428
+
429
+ - Default: disabled
430
+
431
+ Whether the QuickJS engine persists VM snapshots for runs without an encryption key. Set `1` or `true` on the workflow handler to allow it. Those snapshots include the handler's environment variables in plaintext.
432
+
433
+ See [`WORKFLOW_SNAPSHOT_THRESHOLD`](#workflow_snapshot_threshold) for what that stores.
434
+
236
435
  ## Dynamic workflows
237
436
 
437
+ | Variable | Default | What it does |
438
+ | --- | --- | --- |
439
+ | [`WORKFLOW_EXPERIMENTAL_DYNAMIC_WORKFLOWS`](#workflow_experimental_dynamic_workflows) | disabled | Lets this deployment start and execute dynamic workflows |
440
+
238
441
  ### `WORKFLOW_EXPERIMENTAL_DYNAMIC_WORKFLOWS`
239
442
 
240
443
  - Default: disabled
241
- - Set `1` or `true` (case-insensitive) to let this deployment start [dynamic workflows](/docs/advanced/dynamic-workflows), execute their stored code on delivery, and advertise dynamic support in its health check. Any other value leaves it disabled.
242
- - Dynamic source runs with the full privileges of the deployment's functions. Enable it only on deployments whose dynamic source you trust as much as your own code.
243
- - When disabled, `start()` with source throws before writing anything, and a delivered dynamic run fails instead of executing.
444
+
445
+ Whether this deployment may start [dynamic workflows](/docs/advanced/dynamic-workflows), execute their stored code on delivery, and advertise dynamic support in its health check. Set `1` or `true` (case-insensitive) to enable it. Any other value leaves it disabled.
446
+
447
+ Dynamic source runs with the full privileges of the deployment's functions. Enable it only on deployments whose dynamic source you trust as much as your own code.
448
+
449
+ When disabled, `start()` with source throws before writing anything, and a delivered dynamic run fails instead of executing.
244
450
 
245
451
  ## Compression and tracing
246
452
 
453
+ | Variable | Default | What it does |
454
+ | --- | --- | --- |
455
+ | [`WORKFLOW_DISABLE_COMPRESSION`](#workflow_disable_compression) | compression enabled | Turns off compression when writing payloads |
456
+ | [`WORKFLOW_COMPRESSION_CODEC`](#workflow_compression_codec) | automatic | Forces the write-side codec to `zstd` or `gzip` |
457
+ | [`WORKFLOW_TRACE_MODE`](#workflow_trace_mode) | `linked` | OpenTelemetry span topology for runs |
458
+ | [`DEBUG`](#debug) | unset | Debug log filter |
459
+
247
460
  ### `WORKFLOW_DISABLE_COMPRESSION`
248
461
 
249
462
  - Default: compression enabled
250
- - Set `1` to disable compression when writing payloads.
251
- - Reads still decompress existing payloads.
252
- - To skip compression only for one run's arguments, pass `compressArguments: false` to [`start()`](/docs/api-reference/workflow-api/start) instead.
463
+
464
+ Set `1` to disable compression when writing payloads. Reads still decompress existing payloads.
465
+
466
+ To skip compression only for one run's arguments, pass `compressArguments: false` to [`start()`](/docs/api-reference/workflow-api/start) instead.
253
467
 
254
468
  ### `WORKFLOW_COMPRESSION_CODEC`
255
469
 
256
470
  - Default: automatic
257
- - Forces the write-side codec to `zstd` or `gzip`.
258
- - Invalid values are ignored. Automatic mode prefers `zstd` when the current Node.js runtime supports it, otherwise it falls back to `gzip`.
259
- - Writes for a run on another deployment (for example `resumeHook()` reaching a run that started before the project moved to a newer Node.js version) use `zstd` only when that run's deployment runs Node.js 22.15+ (or 23.8+), and `gzip` otherwise, since older Node.js versions cannot decode `zstd`. Runs created before `@workflow/core` recorded the Node.js version always receive `gzip`. Setting this to `zstd` does not override that check.
471
+
472
+ Forces the write-side codec to `zstd` or `gzip`. Invalid values are ignored.
473
+
474
+ Automatic mode prefers `zstd` when the current Node.js runtime supports it, otherwise it falls back to `gzip`.
475
+
476
+ Writes for a run on another deployment (for example `resumeHook()` reaching a run that started before the project moved to a newer Node.js version) use `zstd` only when that run's deployment runs Node.js 22.15+ (or 23.8+), and `gzip` otherwise, since older Node.js versions cannot decode `zstd`. Runs created before `@workflow/core` recorded the Node.js version always receive `gzip`. Setting this to `zstd` does not override that check.
260
477
 
261
478
  ### `WORKFLOW_TRACE_MODE`
262
479
 
263
480
  - Default: `linked`
264
- - OpenTelemetry span topology for runs.
265
- - Accepts `linked` or `continuous`.
481
+
482
+ OpenTelemetry span topology for runs. Accepts `linked` or `continuous`.
266
483
 
267
484
  ### `DEBUG`
268
485
 
269
486
  - Default: unset
270
- - Debug log filter with wildcards and negation.
271
- - Examples: `workflow:*`, `workflow:*,-workflow:telemetry:*`.
487
+
488
+ Debug log filter with wildcards and negation. Examples: `workflow:*`, `workflow:*,-workflow:telemetry:*`.
272
489
 
273
490
  ## Transport
274
491
 
275
492
  The Vercel World's own transport settings (HTTP/2 multiplexing and the queue client's deadline and connection pool) are listed under [Vercel World](/docs/configuration/worlds#vercel-world).
276
493
 
494
+ | Variable | Default | What it does |
495
+ | --- | --- | --- |
496
+ | [`WORKFLOW_NODE_HTTP`](#workflow_node_http) | disabled | Vercel and Local World requests through Node's built-in HTTP modules |
497
+
277
498
  ### `WORKFLOW_NODE_HTTP`
278
499
 
279
500
  - Default: disabled
280
- - Makes the Vercel and Local Worlds issue their HTTP requests through Node's built-in `node:http` and `node:https` modules, instead of the HTTP client library those Worlds normally use.
281
- - Set `1` to switch to Node's modules. Read the trade-offs below first: they cost throughput on every deployment, which is why this is opt-in.
282
- - Use it when that library is not an option: a bundler that mangles it, a runtime that does not ship a working copy of it, or a transport-level fault you want to rule out. It is not reached by way of `fetch()` either, so a runtime whose `fetch()` is built on the same library is still covered.
501
+
502
+ Makes the Vercel and Local Worlds issue their HTTP requests through Node's built-in `node:http` and `node:https` modules, instead of the HTTP client library those Worlds normally use. Set `1` to switch to Node's modules.
503
+
504
+ Change it when: that library is not an option, such as with a bundler that mangles it, a runtime that does not ship a working copy of it, or a transport-level fault you want to rule out. It is not reached by way of `fetch()` either, so a runtime whose `fetch()` is built on the same library is still covered. Read the trade-offs below first: they cost throughput on every deployment, which is why this is opt-in.
283
505
 
284
506
  Node's own modules do less than the client they replace, so enabling this drops the per-call-site tuning the Worlds configure:
285
507
 
@@ -293,143 +515,231 @@ A `dispatcher` passed to `createWorld()` still wins over this variable. The vari
293
515
 
294
516
  ## Queue namespace
295
517
 
518
+ | Variable | Default | What it does |
519
+ | --- | --- | --- |
520
+ | [`WORKFLOW_QUEUE_NAMESPACE`](#workflow_queue_namespace) | none | Queue topic namespace shared by build output and Worlds |
521
+
296
522
  ### `WORKFLOW_QUEUE_NAMESPACE`
297
523
 
298
524
  - Default: none
299
- - Queue topic namespace shared by build output and Worlds.
300
- - Must match `^[a-z][a-z0-9]*$`.
301
- - Set it consistently at build and runtime.
525
+
526
+ Queue topic namespace shared by build output and Worlds. Must match `^[a-z][a-z0-9]*$`.
527
+
528
+ Set it consistently at build and runtime.
302
529
 
303
530
  ## Streams and waits
304
531
 
305
532
  These variables are primarily for tests, debugging, or unusual deployments.
306
533
 
534
+ | Variable | Default | What it does |
535
+ | --- | --- | --- |
536
+ | [`WORKFLOW_STREAM_FLUSH_INTERVAL_MS`](#workflow_stream_flush_interval_ms) | `0` ms | Group-commit window for the leading chunk of an idle stream |
537
+ | [`WORKFLOW_STEP_STREAM_DRAIN_TIMEOUT_MS`](#workflow_step_stream_drain_timeout_ms) | `30000` ms | Wait for released stream writes before `step_completed` |
538
+ | [`WORKFLOW_STREAM_MAX_INFLIGHT_CHUNKS`](#workflow_stream_max_inflight_chunks) | `1000` | Chunks read but not yet durably written before the producer pauses |
539
+ | [`WORKFLOW_STREAM_MAX_CHUNKS_PER_BATCH`](#workflow_stream_max_chunks_per_batch) | `1000` | Chunks per coalesced multi-write request |
540
+ | [`WORKFLOW_STREAM_MAX_BYTES_PER_BATCH`](#workflow_stream_max_bytes_per_batch) | `1048576` bytes (1 MiB) | Bytes per coalesced multi-write request |
541
+ | [`WORKFLOW_STREAM_MAX_BUFFERED_BYTES`](#workflow_stream_max_buffered_bytes) | `8388608` bytes (8 MiB) | Bytes buffered before `write()` applies backpressure |
542
+ | [`WORKFLOW_FRAMED_STREAM_MAX_RECONNECTS`](#workflow_framed_stream_max_reconnects) | `50` | Consecutive reconnects for framed stream readers |
543
+ | [`WORKFLOW_FRAMED_STREAM_MAX_TOTAL_RECONNECTS`](#workflow_framed_stream_max_total_reconnects) | `1000` | Total reconnects per stream session |
544
+ | [`WORKFLOW_WAIT_CONTINUATION_MAX_DELAY_SECONDS`](#workflow_wait_continuation_max_delay_seconds) | `82800` s (23 hours) | Longest single queue delay for `sleep()` continuations |
545
+ | [`WORKFLOW_NEAR_ELAPSED_WAIT_THRESHOLD_SECONDS`](#workflow_near_elapsed_wait_threshold_seconds) | `2` s | Clock-skew tolerance for wait continuations |
546
+ | [`WORKFLOW_DEFERRED_CHECK_DELAY_MS`](#workflow_deferred_check_delay_ms) | `100` ms | Delay before the unconsumed-event check |
547
+ | [`WORKFLOW_LOCK_POLL_INTERVAL_MS`](#workflow_lock_poll_interval_ms) | `10` ms | Poll interval for stream lock release |
548
+
307
549
  ### `WORKFLOW_STREAM_FLUSH_INTERVAL_MS`
308
550
 
309
551
  - Default: `0` (dispatch the first chunk of an idle stream immediately)
310
- - Group-commit window for the *leading* chunk of an idle stream. `0` sends it at once; a positive value holds it up to that many milliseconds to collect a group. This opt-in setting trades first-chunk latency for larger batches and can benefit slow-but-steady producers. Chunks arriving while a request is already in flight always coalesce into the next group regardless of this setting.
311
- - Also available as `streamFlushIntervalMs` on Worlds that expose it (the env var, when set, takes precedence over the World option).
552
+
553
+ Group-commit window, in milliseconds, for the *leading* chunk of an idle stream. `0` sends it at once; a positive value holds it up to that many milliseconds to collect a group.
554
+
555
+ This opt-in setting trades first-chunk latency for larger batches and can benefit slow-but-steady producers. Chunks arriving while a request is already in flight always coalesce into the next group regardless of this setting.
556
+
557
+ Also available as `streamFlushIntervalMs` on Worlds that expose it (the env var, when set, takes precedence over the World option).
312
558
 
313
559
  ### `WORKFLOW_STEP_STREAM_DRAIN_TIMEOUT_MS`
314
560
 
315
561
  - Default: `30000` (30 seconds)
316
- - Maximum time a step waits for writes queued by a released workflow stream writer to be acknowledged by the Workflow server before recording `step_completed`. A timeout fails the step instead of exposing a completion while released-writer data remains client-side. A writer intentionally kept locked does not trigger this durability wait.
562
+
563
+ Maximum time a step waits for writes queued by a released workflow stream writer to be acknowledged by the Workflow server before recording `step_completed`.
564
+
565
+ A timeout fails the step instead of exposing a completion while released-writer data remains client-side. A writer intentionally kept locked does not trigger this durability wait.
317
566
 
318
567
  ### `WORKFLOW_STREAM_MAX_INFLIGHT_CHUNKS`
319
568
 
320
569
  - Default: `1000`
321
- - Flow-control bound: how many stream chunks may be read-but-not-yet-durably-written while writes are coalesced. Once this many are outstanding, the producer pauses reading until a batch is written. Bounds in-memory buffering; distinct from the per-request batch caps below.
570
+
571
+ Flow-control bound: how many stream chunks may be read-but-not-yet-durably-written while writes are coalesced.
572
+
573
+ Once this many are outstanding, the producer pauses reading until a batch is written. Bounds in-memory buffering; distinct from the per-request batch caps below.
322
574
 
323
575
  ### `WORKFLOW_STREAM_MAX_CHUNKS_PER_BATCH`
324
576
 
325
577
  - Default: `1000`
326
- - Wire limit: maximum number of chunks sent in a single coalesced multi-write. Larger bursts are split across requests so one request can't exceed the server's per-multi-write chunk cap.
578
+
579
+ Wire limit: maximum number of chunks sent in a single coalesced multi-write.
580
+
581
+ Larger bursts are split across requests so one request can't exceed the server's per-multi-write chunk cap.
327
582
 
328
583
  ### `WORKFLOW_STREAM_MAX_BYTES_PER_BATCH`
329
584
 
330
585
  - Default: `1048576` (1 MiB)
331
- - Wire limit: maximum cumulative bytes in a single coalesced multi-write, so large chunks don't produce a request body that platform limits reject. A single chunk larger than this is still sent on its own.
586
+
587
+ Wire limit: maximum cumulative bytes in a single coalesced multi-write, so large chunks don't produce a request body that platform limits reject.
588
+
589
+ A single chunk larger than this is still sent on its own.
332
590
 
333
591
  ### `WORKFLOW_STREAM_MAX_BUFFERED_BYTES`
334
592
 
335
593
  - Default: `8388608` (8 MiB)
336
- - Flow-control bound: maximum cumulative bytes accepted into the stream writer's group-commit buffer before `write()` applies backpressure. The byte-denominated counterpart of `WORKFLOW_STREAM_MAX_INFLIGHT_CHUNKS`; distinct from `WORKFLOW_STREAM_MAX_BYTES_PER_BATCH`, which only splits how much goes out in one request.
594
+
595
+ Flow-control bound: maximum cumulative bytes accepted into the stream writer's group-commit buffer before `write()` applies backpressure.
596
+
597
+ The byte-denominated counterpart of `WORKFLOW_STREAM_MAX_INFLIGHT_CHUNKS`; distinct from `WORKFLOW_STREAM_MAX_BYTES_PER_BATCH`, which only splits how much goes out in one request.
337
598
 
338
599
  ### `WORKFLOW_FRAMED_STREAM_MAX_RECONNECTS`
339
600
 
340
601
  - Default: `50`
341
- - Consecutive reconnect cap for framed stream readers.
602
+
603
+ Consecutive reconnect cap for framed stream readers.
342
604
 
343
605
  ### `WORKFLOW_FRAMED_STREAM_MAX_TOTAL_RECONNECTS`
344
606
 
345
607
  - Default: `1000`
346
- - Total reconnect cap per stream session.
608
+
609
+ Total reconnect cap per stream session.
347
610
 
348
611
  ### `WORKFLOW_WAIT_CONTINUATION_MAX_DELAY_SECONDS`
349
612
 
350
613
  - Default: `82800` (23 hours)
351
- - Longest single queue delay used for `sleep()` continuations.
352
- - If a wait is longer than this, Workflow queues one continuation for the maximum delay, then queues another continuation after that message fires, repeating until the wait's target time is reached.
614
+
615
+ Longest single queue delay, in seconds, used for `sleep()` continuations.
616
+
617
+ If a wait is longer than this, Workflow queues one continuation for the maximum delay, then queues another continuation after that message fires, repeating until the wait's target time is reached.
353
618
 
354
619
  ### `WORKFLOW_NEAR_ELAPSED_WAIT_THRESHOLD_SECONDS`
355
620
 
356
621
  - Default: `2`
357
- - Clock-skew tolerance for wait continuations that arrive near their target time.
622
+
623
+ Clock-skew tolerance, in seconds, for wait continuations that arrive near their target time.
358
624
 
359
625
  ### `WORKFLOW_DEFERRED_CHECK_DELAY_MS`
360
626
 
361
627
  - Default: `100`
362
- - Delay before the unconsumed-event check fires.
363
- - Minimum: `10`.
628
+
629
+ Delay, in milliseconds, before the unconsumed-event check fires. Minimum `10`.
364
630
 
365
631
  ### `WORKFLOW_LOCK_POLL_INTERVAL_MS`
366
632
 
367
633
  - Default: `10`
368
- - Poll interval for detecting stream lock release.
634
+
635
+ Poll interval, in milliseconds, for detecting stream lock release.
369
636
 
370
637
  ## Limits
371
638
 
639
+ | Variable | Default | What it does |
640
+ | --- | --- | --- |
641
+ | [`WORKFLOW_MAX_EVENTS_OVERRIDE`](#workflow_max_events_override) | unset | Lowers the World's per-run event ceiling |
642
+
372
643
  ### `WORKFLOW_MAX_EVENTS_OVERRIDE`
373
644
 
374
645
  - Default: unset
375
- - Lowers the per-run event ceiling supplied by the World. A run whose event log reaches the ceiling fails with `MAX_EVENTS_EXCEEDED`, which stops a runaway loop from growing its log without bound.
376
- - Clamp-down only: it never raises the World's limit, and it applies even when the World supplies none. With no World limit and no override, nothing is enforced.
377
- - The Local and Vercel Worlds both supply a limit; the Local World defaults to 25,000 and is configurable with [`WORKFLOW_MAX_EVENTS`](/docs/configuration/worlds#workflow_max_events). The Vercel World's ceiling is documented under [Workflow run limits](https://vercel.com/docs/workflows/pricing#workflow-run-limits).
378
- - QuickJS runs with snapshotting are exempt from the World's default limit, but this override still applies to them.
379
646
 
380
- ## Spec 9 (experimental)
647
+ Lowers the per-run event ceiling supplied by the World. A run whose event log reaches the ceiling fails with `MAX_EVENTS_EXCEEDED`, which stops a runaway loop from growing its log without bound.
381
648
 
382
- Everything above describes spec 8 runs, the default. The experimental spec 9 runtime is opt-in with `WORKFLOW_SPEC_VERSION=9`, reads some of the settings above differently, and adds the settings below.
649
+ Clamp-down only: it never raises the World's limit, and it applies even when the World supplies none. With no World limit and no override, nothing is enforced.
383
650
 
384
- ### `WORKFLOW_SPEC_VERSION`
651
+ The Local and Vercel Worlds both supply a limit; the Local World defaults to 25,000 and is configurable with [`WORKFLOW_MAX_EVENTS`](/docs/configuration/worlds#workflow_max_events). The Vercel World's ceiling is documented under [Workflow run limits](https://vercel.com/docs/workflows/pricing#workflow-run-limits).
652
+
653
+ QuickJS runs with snapshotting are exempt from the World's default limit, but this override still applies to them.
654
+
655
+ ## Orchestrator
656
+
657
+ One orchestrator invocation at a time drives each run: it replays the run, runs inline steps, and writes every decision. A background step's own invocation only runs its body and reports the outcome. These settings tune how the orchestrator picks up events that other writers commit, and how long it stays live waiting for them.
658
+
659
+ <Spec8Note>
660
+ the runtime ignores the settings in this section, because every queue delivery replays the run and writes its own decisions.
661
+ </Spec8Note>
662
+
663
+ | Variable | Default | What it does |
664
+ | --- | --- | --- |
665
+ | [`WORKFLOW_ORCHESTRATOR_RATE_WAIT_MS`](#workflow_orchestrator_rate_wait_ms) | `5000` ms | How far ahead of a rate limit slot the orchestrator waits in the same invocation |
666
+ | [`WORKFLOW_ORCHESTRATOR_POLL_INTERVAL_MS`](#workflow_orchestrator_poll_interval_ms) | `2000` ms | Log-tail poll interval without a live event feed |
667
+ | [`WORKFLOW_ORCHESTRATOR_FEED_POLL_INTERVAL_MS`](#workflow_orchestrator_feed_poll_interval_ms) | `10000` ms | Log-tail poll interval while the live event feed is up |
668
+ | [`WORKFLOW_ORCHESTRATOR_LINGER_MS`](#workflow_orchestrator_linger_ms) | `5000` ms | How long an idle orchestrator stays live while a background step runs |
669
+ | [`WORKFLOW_ORCHESTRATOR_HOOK_LINGER_MS`](#workflow_orchestrator_hook_linger_ms) | `5000` ms, capped at `WORKFLOW_ORCHESTRATOR_LINGER_MS` | How long an idle orchestrator stays live on open hooks only |
670
+ | [`WORKFLOW_ORCHESTRATOR_WAIT_LINGER_MS`](#workflow_orchestrator_wait_linger_ms) | `WORKFLOW_ORCHESTRATOR_LINGER_MS` (`5000` ms), capped at it | How far ahead a `sleep()` may end for an idle orchestrator to stay live until it does |
671
+ | [`WORKFLOW_ORCHESTRATOR_READ_TIMEOUT_MS`](#workflow_orchestrator_read_timeout_ms) | `5000` ms | Deadline for one incremental event-log read |
385
672
 
386
- - Default: unset. New runs use spec version 8.
387
- - `9` creates spec 9 runs on a World that declares the in-band fence (the Vercel, Local and Postgres Worlds do). `6` to `8` select that version. A run keeps the version it was created with.
388
- - `6` creates new runs on the scheme from before the [sealed log](/docs/how-it-works/event-sourcing), where each event position is allocated by the write that occupies it. Use it in an environment shared with a runtime that cannot read sealed logs yet, such as one that pins its own accepted spec range (the Python runtime). Runs below `8` cannot have their hook tokens taken over with [`experimental_force`](/docs/api-reference/workflow/create-hook#take-over-a-token-another-run-holds): a forced hook in another run gets `HookConflictError` instead.
389
- - Upgrade every deployment and process that shares the World before setting it, and do not roll back below this release once spec 9 runs exist.
673
+ ### `WORKFLOW_ORCHESTRATOR_RATE_WAIT_MS`
674
+
675
+ - Default: `5000`
676
+
677
+ How far ahead, in milliseconds, of an [`experimental_rateLimit()`](/docs/api-reference/workflow/rate-limit) call's slot the orchestrator waits for it in the same invocation. `0` turns it off, and a waiting call is woken by the queue at its slot.
678
+
679
+ A call whose slot is further out is woken this far before it and waits the rest the same way, so it goes ahead at its slot instead of a second or more after. A queued wake for the slot itself is still scheduled, in case the invocation ends first. Each wait can keep an invocation idle for up to this long.
390
680
 
391
681
  ### `WORKFLOW_ORCHESTRATOR_POLL_INTERVAL_MS`
392
682
 
393
683
  - Default: `2000`
394
- - Log-tail poll interval of a busy orchestrator while no live event feed covers the run. `0` turns polling off.
684
+
685
+ Log-tail poll interval, in milliseconds, of a busy orchestrator while no live event feed covers the run. `0` turns polling off.
395
686
 
396
687
  ### `WORKFLOW_ORCHESTRATOR_FEED_POLL_INTERVAL_MS`
397
688
 
398
689
  - Default: `10000`
399
- - Log-tail poll interval while the World's live event feed is up.
690
+
691
+ Log-tail poll interval, in milliseconds, while the World's live event feed is up.
400
692
 
401
693
  ### `WORKFLOW_ORCHESTRATOR_LINGER_MS`
402
694
 
403
695
  - Default: `5000`
404
- - How long an orchestrator with nothing left to run stays live on the event feed while the run waits on a background step. A step that takes longer ends the invocation, and its outcome starts a new one. `0` turns it off, for hooks and sleeps too.
696
+
697
+ How long, in milliseconds, an orchestrator with nothing left to run stays live on the event feed while the run waits on a background step. `0` turns it off, for hooks and sleeps too.
698
+
699
+ A step that takes longer ends the invocation, and its outcome starts a new one.
405
700
 
406
701
  ### `WORKFLOW_ORCHESTRATOR_HOOK_LINGER_MS`
407
702
 
408
703
  - Default: `5000`, and never more than [`WORKFLOW_ORCHESTRATOR_LINGER_MS`](#workflow_orchestrator_linger_ms)
409
- - How long an orchestrator with nothing left to run stays live on the event feed while the run waits only on open hooks. Set it below `WORKFLOW_ORCHESTRATOR_LINGER_MS` to keep background steps on a longer window than hooks. Any hook that is created and not disposed counts, however rarely it is resumed. `0` turns it off.
704
+
705
+ How long, in milliseconds, an orchestrator with nothing left to run stays live on the event feed while the run waits only on open hooks. `0` turns it off.
706
+
707
+ Change it when: you want background steps on a longer window than hooks. Set it below `WORKFLOW_ORCHESTRATOR_LINGER_MS`.
708
+
709
+ Any hook that is created and not disposed counts, however rarely it is resumed.
410
710
 
411
711
  ### `WORKFLOW_ORCHESTRATOR_WAIT_LINGER_MS`
412
712
 
413
713
  - Default: [`WORKFLOW_ORCHESTRATOR_LINGER_MS`](#workflow_orchestrator_linger_ms) (`5000`), and never more than it
414
- - How far ahead a `sleep()` may end for an orchestrator with nothing left to run to stay live on the event feed until it does, instead of ending the invocation and starting a new one when the sleep's timer fires. A sleep up to 1 second longer than this still counts, so a sleep as long as the window lingers despite small clock differences. Only for a sleep that ends before the invocation's inline window less [`WORKFLOW_INLINE_STEP_DEADLINE_MARGIN_MS`](#workflow_inline_step_deadline_margin_ms), and only on a World with a live event feed (such as world-vercel and world-postgres; world-local has none, so it never lingers). On those Worlds, a `run.wakeUp()` sent during such a sleep is not applied, so the sleep runs its full length. `0` turns it off.
714
+
715
+ How far ahead, in milliseconds, a `sleep()` may end for an orchestrator with nothing left to run to stay live on the event feed until it does, instead of ending the invocation and starting a new one when the sleep's timer fires. `0` turns it off.
716
+
717
+ A sleep up to 1 second longer than this still counts, so a sleep as long as the window lingers despite small clock differences. Only for a sleep that ends before the invocation's inline window less [`WORKFLOW_INLINE_STEP_DEADLINE_MARGIN_MS`](#workflow_inline_step_deadline_margin_ms), and only on a World with a live event feed (such as world-vercel and world-postgres; world-local has none, so it never lingers). On those Worlds, a `run.wakeUp()` sent during such a sleep is not applied, so the sleep runs its full length.
415
718
 
416
719
  ### `WORKFLOW_ORCHESTRATOR_READ_TIMEOUT_MS`
417
720
 
418
721
  - Default: `5000`
419
- - Deadline for one incremental read of the event log before the orchestrator sends it again. `0` turns the deadline off.
420
722
 
421
- ### `WORKFLOW_INLINE_STEP_DEADLINE_MARGIN_MS`
723
+ Deadline, in milliseconds, for one incremental read of the event log before the orchestrator sends it again. `0` turns the deadline off.
422
724
 
423
- - Default: `60000`
424
- - How long before the inline window ends the orchestrator stops starting inline steps.
725
+ ## Spec version
425
726
 
426
- ### `WORKFLOW_OPTIMISTIC_BACKGROUND_START`
727
+ | Variable | Default | What it does |
728
+ | --- | --- | --- |
729
+ | [`WORKFLOW_SPEC_VERSION`](#workflow_spec_version) | unset (newest the World supports) | Spec version of new runs |
427
730
 
428
- - Default: unset
429
- - `1` or `true` starts a background step's body before its `step_started` commits. Use only when background step bodies are idempotent.
731
+ ### `WORKFLOW_SPEC_VERSION`
430
732
 
431
- ### `WORKFLOW_RUN_AHEAD_DEPTH`
733
+ - Default: unset. New runs use the newest spec version the World supports: 10 on the Vercel, Local and Postgres Worlds.
432
734
 
433
- - Default: `10`
434
- - Clamp: `0` to `16`
435
- - How many inline step outcomes may be unconfirmed at once while the orchestrator runs ahead of its writes. `0` disables run-ahead.
735
+ Spec version of runs created by this process. `8` opts out: new runs use the earlier execution model, where every queue delivery replays the run and writes its own decisions. Pages that describe a difference for such runs say so in a note.
736
+
737
+ A third-party World creates spec 9 runs if it implements the [in-band fence](/worlds/building-a-world#optional-the-in-band-writer-fence) but not [rate limits](/docs/api-reference/workflow/rate-limit), and spec 8 runs if it implements neither (see [Supporting spec 9 runs](/worlds/building-a-world#supporting-spec-9-runs)).
738
+
739
+ `6` to `10` select that version, but never one above what the World supports: `9` or `10` on a World without the fence creates spec 8 runs, and `10` on a World without rate limits creates spec 9 runs. Any other value is ignored with a one-time warning and creates spec 8 runs, so a typo in an opt-out never opts in.
740
+
741
+ `6` creates new runs on the scheme from before the [sealed log](/docs/how-it-works/event-sourcing), where each event position is allocated by the write that occupies it. Use it in an environment shared with a runtime that cannot read sealed logs yet, such as one that pins its own accepted spec range (the Python runtime). Runs below `8` cannot have their hook tokens taken over with [`experimental_force`](/docs/api-reference/workflow/create-hook#take-over-a-token-another-run-holds): a forced hook in another run gets `HookConflictError` instead.
742
+
743
+ A run keeps the version it was created with.
744
+
745
+ Upgrade every deployment and process that shares the World together, setting `8` on the upgraded ones until all of them run v5.8.0 or later. Do not roll back below v5.8.0 once runs at spec 9 or later exist: an older release fails writes to them.