workflow 5.5.0 → 5.6.0

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 (88) hide show
  1. package/dist/api-workflow.js +1 -1
  2. package/dist/api.js +1 -1
  3. package/dist/astro.js +1 -1
  4. package/dist/index.js +1 -1
  5. package/dist/internal/builtins.js +1 -1
  6. package/dist/internal/class-serialization.js +1 -1
  7. package/dist/internal/errors.js +1 -1
  8. package/dist/nest-builder.js +1 -1
  9. package/dist/nest-vercel-builder.js +1 -1
  10. package/dist/nest.js +1 -1
  11. package/dist/next.cjs +1 -1
  12. package/dist/nitro.js +1 -1
  13. package/dist/nuxt.js +1 -1
  14. package/dist/observability.js +1 -1
  15. package/dist/runtime.js +1 -1
  16. package/dist/stdlib.js +1 -1
  17. package/dist/sveltekit.js +1 -1
  18. package/dist/typescript-plugin.cjs +1 -1
  19. package/dist/vite.js +1 -1
  20. package/dist/workflow.js +1 -1
  21. package/docs/api-reference/workflow-api/get-run.mdx +0 -4
  22. package/docs/api-reference/workflow-api/resume-hook.mdx +1 -1
  23. package/docs/api-reference/workflow-api/start.mdx +1 -1
  24. package/docs/api-reference/workflow-errors/in-band-superseded-error.mdx +0 -3
  25. package/docs/api-reference/workflow-errors/index.mdx +1 -1
  26. package/docs/api-reference/workflow-errors/precondition-failed-error.mdx +0 -2
  27. package/docs/api-reference/workflow-errors/workflow-not-registered-error.mdx +1 -1
  28. package/docs/api-reference/workflow-runtime/world/queue.mdx +70 -3
  29. package/docs/comparisons/index.mdx +4 -1
  30. package/docs/comparisons/workflow-sdk-vs-aws-step-functions.mdx +3 -1
  31. package/docs/comparisons/workflow-sdk-vs-cloudflare-workflows.mdx +4 -1
  32. package/docs/comparisons/workflow-sdk-vs-inngest.mdx +271 -28
  33. package/docs/comparisons/workflow-sdk-vs-temporal.mdx +6 -2
  34. package/docs/comparisons/workflow-sdk-vs-trigger-dev.mdx +2 -0
  35. package/docs/configuration/cli-and-web-ui.mdx +31 -1
  36. package/docs/configuration/runtime-tuning.mdx +9 -8
  37. package/docs/configuration/worlds.mdx +18 -21
  38. package/docs/cookbook/advanced/child-workflows.mdx +1 -1
  39. package/docs/cookbook/common-patterns/batching.mdx +1 -1
  40. package/docs/errors/index.mdx +1 -0
  41. package/docs/errors/max-events-exceeded.mdx +2 -2
  42. package/docs/errors/replay-timeout.mdx +2 -2
  43. package/docs/errors/workflow-not-registered.mdx +1 -1
  44. package/docs/foundations/errors-and-retries.mdx +1 -4
  45. package/docs/how-it-works/event-sourcing.mdx +2 -5
  46. package/docs/how-it-works/framework-integrations.mdx +2 -2
  47. package/docs/internal/index.mdx +1 -0
  48. package/docs/internal/nitro-native-build.mdx +1 -0
  49. package/docs/internal/nitro-web-ui.mdx +1 -0
  50. package/docs/internal/serializable-abort-controller.mdx +1 -0
  51. package/docs/observability/index.mdx +2 -0
  52. package/docs/whats-new.mdx +3 -3
  53. package/docs/worlds/building-a-world.mdx +46 -4
  54. package/docs/worlds/local.mdx +110 -25
  55. package/docs/worlds/postgres.mdx +107 -27
  56. package/docs/worlds/upgrading-to-v5.mdx +4 -4
  57. package/docs/worlds/vercel.mdx +190 -82
  58. package/package.json +14 -12
  59. package/dist/api-workflow.d.ts.map +0 -1
  60. package/dist/api.d.ts.map +0 -1
  61. package/dist/astro.d.ts.map +0 -1
  62. package/dist/index.d.ts.map +0 -1
  63. package/dist/internal/builtins.d.ts.map +0 -1
  64. package/dist/internal/class-serialization.d.ts.map +0 -1
  65. package/dist/internal/errors.d.ts.map +0 -1
  66. package/dist/nest-builder.d.ts.map +0 -1
  67. package/dist/nest-vercel-builder.d.ts.map +0 -1
  68. package/dist/nest.d.ts.map +0 -1
  69. package/dist/nitro.d.ts.map +0 -1
  70. package/dist/nuxt.d.ts.map +0 -1
  71. package/dist/observability.d.ts.map +0 -1
  72. package/dist/runtime.d.ts.map +0 -1
  73. package/dist/stdlib.d.ts.map +0 -1
  74. package/dist/sveltekit.d.ts.map +0 -1
  75. package/dist/vite.d.ts.map +0 -1
  76. package/dist/workflow.d.ts.map +0 -1
  77. package/docs/changelog/attributes-mvp.mdx +0 -380
  78. package/docs/changelog/batched-event-writes.mdx +0 -77
  79. package/docs/changelog/eager-processing.mdx +0 -273
  80. package/docs/changelog/index.mdx +0 -19
  81. package/docs/changelog/lazy-event-creation.md +0 -127
  82. package/docs/changelog/lazy-hook-resume.mdx +0 -78
  83. package/docs/changelog/meta.json +0 -16
  84. package/docs/changelog/resilient-resume.mdx +0 -32
  85. package/docs/changelog/resilient-start.mdx +0 -77
  86. package/docs/changelog/spec-9.mdx +0 -4167
  87. package/docs/changelog/step-message-ownership.mdx +0 -355
  88. package/docs/changelog/turbo-mode.md +0 -91
@@ -107,6 +107,13 @@ The Local World is the default outside Vercel and is intended for development.
107
107
  - Default: `true`
108
108
  - Re-enqueues pending and running local runs when the World starts. Set the environment variable to `0` or `false` to skip recovery; the factory option wins when both are set.
109
109
 
110
+ ### `WORKFLOW_LOCAL_SQLITE_KEEP_CONNECTIONS`
111
+
112
+ - Factory option: none
113
+ - Default: `1`, except on Windows, where it is `brief`
114
+ - How long a process keeps its connection to the Local World's SQLite database (`world.db`) open between operations.
115
+ - `1` keeps the connection until it has been idle for a few seconds. `brief` closes it once a burst of operations ends, so the data directory stays removable while the app runs. `0` opens and closes a connection for every operation, which is slower. Any other value uses the default.
116
+
110
117
  ### `WORKFLOW_LOCAL_HOOK_RETENTION_LIMIT_DAYS`
111
118
 
112
119
  - Factory option: none
@@ -181,8 +188,8 @@ The Postgres World is a self-hosted durable backend for long-running server proc
181
188
  ### `jobLockStaleSeconds`
182
189
 
183
190
  - Environment variable: `WORKFLOW_POSTGRES_JOB_LOCK_STALE_SECONDS`
184
- - Default: unset. Every delivery renews its job lock, and a job in a spec 9 run's named queue whose process died is redelivered after 300 seconds unrenewed, if its holder registered as renewing. Other jobs keep Graphile Worker's fixed 4 hour reset.
185
- - Seconds a running delivery's job lock may go unrenewed before another process releases any of this World's jobs for redelivery. Setting it extends the release from spec 9 named queues to every job, whoever holds it.
191
+ - Default: unset. Every delivery renews its job lock, and jobs keep Graphile Worker's fixed 4 hour reset.
192
+ - Seconds a running delivery's job lock may go unrenewed before another process releases any of this World's jobs for redelivery, whoever holds it.
186
193
  - `30` is a good value when more than one process shares the database. Use the same value on every process, and keep it well above the longest a process can block its event loop.
187
194
  - `0` turns renewal and release off, and leaves recovery to Graphile Worker's fixed 4 hour reset and to restarts.
188
195
  - Set it only once every process that shares the database runs a version that includes this option. A process on an earlier version neither renews its locks nor fences its acknowledgement on the lock holder, so while it shares the database with a process that has this set, its deliveries that run longer than the window are redelivered, and finishing one can delete the redelivered job. The default is safe for this: it never releases the job of a holder that did not register as renewing. See [Postgres World: `WORKFLOW_POSTGRES_JOB_LOCK_STALE_SECONDS`](/worlds/postgres#workflow_postgres_job_lock_stale_seconds).
@@ -243,8 +250,8 @@ Platform-provided values such as `VERCEL_DEPLOYMENT_ID`, `VERCEL_PROJECT_ID`, an
243
250
 
244
251
  ### `token`
245
252
 
246
- - Environment variable: `WORKFLOW_VERCEL_AUTH_TOKEN`, then `VERCEL_TOKEN`, then Vercel CLI login
247
- - CLI flag: `--authToken`
253
+ - Environment variable: `WORKFLOW_VERCEL_AUTH_TOKEN` (the `workflow` CLI falls back to your Vercel CLI login)
254
+ - CLI flag: `--authToken` or `-a`
248
255
  - Default: inferred when possible
249
256
  - Vercel API token for external tooling. Keep it secret.
250
257
  - Only meaningful alongside `projectConfig.projectId` and `projectConfig.teamId` — set all three together. Supplying both IDs but no token throws rather than failing later with a `401`.
@@ -255,6 +262,7 @@ Platform-provided values such as `VERCEL_DEPLOYMENT_ID`, `VERCEL_PROJECT_ID`, an
255
262
  - CLI flag: `--env` or `-e`
256
263
  - Default: `production`
257
264
  - Vercel environment targeted by tooling. Accepts `production`, `preview`, or a custom environment's **slug** — configure the slug, not the environment's ID.
265
+ - The CLI accepts only `production` or `preview`; see [Environment variables](/worlds/vercel#environment-variables) for what other values do.
258
266
 
259
267
  ### `projectConfig.projectId`
260
268
 
@@ -272,7 +280,7 @@ Platform-provided values such as `VERCEL_DEPLOYMENT_ID`, `VERCEL_PROJECT_ID`, an
272
280
 
273
281
  ### `WORKFLOW_VERCEL_PROJECT_NAME`
274
282
 
275
- - Factory option: none
283
+ - Factory option: `projectConfig.projectName`
276
284
  - CLI flag: none
277
285
  - Default: inferred when possible
278
286
  - Project slug used for dashboard links.
@@ -285,13 +293,6 @@ Platform-provided values such as `VERCEL_DEPLOYMENT_ID`, `VERCEL_PROJECT_ID`, an
285
293
  - Workflow API proxy URL for external tooling.
286
294
  - The Vercel World doesn't follow HTTP redirects, so the URL must answer directly. A `3xx` response fails the request.
287
295
 
288
- ### `WORKFLOW_SEQUENTIAL_REPLAYS`
289
-
290
- - Default: disabled
291
- - Set `1` to serialize orchestrator (flow) invocations per run: each run's replays get their own queue topic and the flow trigger is generated with `maxConcurrency: 1`. Inline step executions get per-step topics and keep full parallelism.
292
- - Read at **both build time and runtime**: set it as a project-level environment variable so the generated trigger and the runtime queue routing agree.
293
- - Routing each run through a dedicated `maxConcurrency: 1` topic might lead to higher queue performance overhead. See [Vercel World](/worlds/vercel#workflow_sequential_replays) for details.
294
-
295
296
  ### `VERCEL_WORKFLOW_SERVER_URL`
296
297
 
297
298
  - Factory option: none
@@ -330,19 +331,12 @@ Platform-provided values such as `VERCEL_DEPLOYMENT_ID`, `VERCEL_PROJECT_ID`, an
330
331
  - Each WebSocket message is at most `WORKFLOW_WS_MAX_MESSAGE_BYTES`. Larger write groups are sent as several ordered requests, and a single chunk too large for one message is written over HTTP.
331
332
  - A throttled (429) socket write or close is retried after the server's `Retry-After`, as over HTTP. It moves to HTTP if the connection ends during the wait or the cumulative wait passes 30 seconds.
332
333
 
333
- ### `WORKFLOW_DISABLE_ANALYTICS_READS`
334
-
335
- - Factory option: none
336
- - CLI flag: none
337
- - Default: disabled
338
- - Set `1` to turn off the World's metadata-only `analytics` read namespace, forcing `workflow inspect` and web UI list views onto strongly consistent primary storage. Intended for tests and tooling that read entities immediately after writing them.
339
-
340
334
  ### `WORKFLOW_EVENTS_TRANSPORT`
341
335
 
342
336
  - Factory option: none
343
337
  - CLI flag: none
344
338
  - Default: `ws`
345
- - Ships workflow run events to the Vercel World over a WebSocket instead of one HTTP request each. Set to exactly `http` to opt out; any other value, including unset or empty, uses the WebSocket.
339
+ - Ships workflow run events to the Vercel World over a WebSocket instead of one HTTP request each. Set to `http` (case-insensitive, surrounding whitespace ignored) to opt out; any other value, including unset or empty, uses the WebSocket.
346
340
  - Ignored when the World is configured with `projectConfig` and routes through the `api-workflow` proxy: that endpoint is an HTTP-only REST gateway and does not forward a WebSocket upgrade, so events stay on HTTP.
347
341
 
348
342
  ### `WORKFLOW_EVENTS_TRANSPORT_WS_OVERRIDE_WORKFLOWS`
@@ -371,7 +365,8 @@ Platform-provided values such as `VERCEL_DEPLOYMENT_ID`, `VERCEL_PROJECT_ID`, an
371
365
  - Default: enabled
372
366
  - On the Vercel World, lets concurrent event-log requests share one HTTP/2 connection instead of one connection per in-flight request.
373
367
  - Set `0` to take the event-log requests off HTTP/2 entirely, back to one request per HTTP/1.1 connection. Use this as the kill switch if HTTP/2 turns out to be at fault for event delivery problems.
374
- - Has no effect when [`WORKFLOW_NODE_HTTP`](/docs/configuration/runtime-tuning#workflow_node_http) is enabled, which takes the whole HTTP/2 path away.
368
+ - Only `0` turns it off; other values, including `false`, are ignored.
369
+ - Has no effect when [`WORKFLOW_NODE_HTTP`](/docs/configuration/runtime-tuning#workflow_node_http) is enabled (which takes the whole HTTP/2 path away) or when a custom `dispatcher` is passed to `createWorld()` (its own settings apply).
375
370
 
376
371
  ### `WORKFLOW_VERCEL_QUEUE_TIMEOUT_MS`
377
372
 
@@ -382,6 +377,7 @@ Platform-provided values such as `VERCEL_DEPLOYMENT_ID`, `VERCEL_PROJECT_ID`, an
382
377
  - Clamped to `[5000, 120000]`.
383
378
  - This is the only request path the World cannot bound with `WORKFLOW_REQUEST_TIMEOUT_MS`, because the queue client makes its own calls and accepts no override for them. Without a deadline here, a queue acknowledgement that never completes holds the invocation until the platform kills it, and a killed invocation never acknowledges, so the message is redelivered.
384
379
  - Keep it below the queue's visibility-renewal interval (60 seconds) so a failed call has room to surface and be retried before the message lease lapses.
380
+ - Has no effect when [`WORKFLOW_NODE_HTTP`](/docs/configuration/runtime-tuning#workflow_node_http) is enabled (only undici's default 300-second timeouts apply) or when a custom `dispatcher` is passed to `createWorld()` (its own limits apply).
385
381
 
386
382
  ### `WORKFLOW_VERCEL_QUEUE_CONNECTIONS`
387
383
 
@@ -391,3 +387,4 @@ Platform-provided values such as `VERCEL_DEPLOYMENT_ID`, `VERCEL_PROJECT_ID`, an
391
387
  - Connections the Vercel World's queue client may open to the queue service.
392
388
  - Clamped to `[1, 1024]`.
393
389
  - Sized much higher than the World's other connection pools on purpose. The queue client makes roughly two small requests per invocation, so its concurrency tracks how many invocations a compute instance is serving at once rather than any per-request fan-out. Lower it only if you have a reason to cap sockets; too low turns invocation concurrency into the limit on how fast messages can be acknowledged.
390
+ - Has no effect when [`WORKFLOW_NODE_HTTP`](/docs/configuration/runtime-tuning#workflow_node_http) is enabled (only undici's default 300-second timeouts apply) or when a custom `dispatcher` is passed to `createWorld()` (its own limits apply).
@@ -69,7 +69,7 @@ Awaiting `returnValue` of a run the workflow started does not poll. The SDK wait
69
69
  1. `start()` records the parent's run ID on the child, and remembers the parent on the returned `Run`.
70
70
  2. When the parent first awaits a child, it registers its completion hook (a system hook whose token is derived from the parent's run ID), which stays open for the rest of the run. Reading `run.returnValue` without awaiting it does nothing yet: the wait starts at the first `await`, `then`, `catch` or `finally`. On each await the parent reads every child it started waiting on since its last read, in one step. A child that already finished is answered from that read.
71
71
  3. Otherwise the parent suspends on the hook. When a child completes, fails, or is canceled, its runtime resumes the parent's hook with that child's run ID, and the parent reads that child's result.
72
- 4. Between waits the hook stays open but the parent does not listen on it, so it does not hold up run-ahead on the single-orchestrator runtime. A child the parent never awaits still resumes the hook when it finishes, which wakes the parent briefly without changing what it does.
72
+ 4. Between waits the hook stays open but the parent does not listen on it. A child the parent never awaits still resumes the hook when it finishes, which wakes the parent briefly without changing what it does.
73
73
 
74
74
  This gives you:
75
75
 
@@ -100,7 +100,7 @@ async function processRecord(record: Record): Promise<string> {
100
100
  - **Use `Promise.allSettled` instead of `Promise.all`**: Use this pattern when you want to continue even if some items fail. `Promise.all` rejects on the first failure, while `allSettled` waits for everything and identifies failures.
101
101
  - **Tune batch size to your downstream API limits**: If the API allows 10 concurrent requests, use `batchSize: 10`.
102
102
  - **Batching bounds concurrency, not total event count**: Every record processed in its own step adds events to the same [event log](/docs/how-it-works/event-sourcing#how-fast-a-log-grows), regardless of batch size.
103
- - **Consider using the QuickJS engine for long-running batches**: [Set `WORKFLOW_VM=quickjs`](/docs/configuration/runtime-tuning#workflow_vm) to use the experimental QuickJS runtime, which compresses and snapshots the event log and only loads events since the last snapshot on resume. This reduces replay overhead as the log grows and exempts eligible runs from the default [per-run event limit](/worlds/vercel#per-run-limits) ([`MAX_EVENTS_EXCEEDED`](/docs/errors/max-events-exceeded)). It does not reduce event count or speed up the work inside each step.
103
+ - **Use the QuickJS engine for long-running batches**: [Set `WORKFLOW_VM=quickjs`](/docs/configuration/runtime-tuning#workflow_vm) to run the workflow on QuickJS, which snapshots the workflow VM and replays only the events recorded since the last snapshot on resume. This reduces replay overhead as the log grows and exempts eligible runs from the default [per-run event limit](/worlds/vercel#per-run-limits) ([`MAX_EVENTS_EXCEEDED`](/docs/errors/max-events-exceeded)). It does not reduce event count or speed up the work inside each step.
104
104
  - **Choose the retry and run boundaries you need**: Keep one step per record when independent retries and visibility matter. To write fewer events, process multiple records within each step and make the grouped work idempotent, since a retry can repeat the whole group. Use a [child workflow](/cookbook/advanced/child-workflows) per batch when you need separate run histories and failure boundaries.
105
105
  - **Add pacing with `sleep()`**: Add a delay between batches to respect rate limits. The sleep is durable and survives cold starts.
106
106
  - **Treat each `processRecord` call as an independent step**: If one call fails, it retries up to three times without affecting other items in the batch.
@@ -25,6 +25,7 @@ When a workflow run fails, its `errorCode` identifies the failure category. You
25
25
  | `STREAM_ERROR` | Workflow stream infrastructure failed while reading or writing data. This is an SDK or backend failure rather than an error in workflow code. |
26
26
  | `WORLD_CONTRACT_ERROR` | A World returned data that violated the SDK contract and could not be retried safely. This usually indicates a World implementation bug. |
27
27
  | [`DEPLOYMENT_MISMATCH`](/docs/errors/deployment-mismatch) | A run was delivered to a deployment other than the one it is pinned to, and automatic re-routing did not recover it. |
28
+ | [`WORKFLOW_NOT_REGISTERED`](/docs/errors/workflow-not-registered) | The deployment executing the run does not have the run's workflow registered, usually because the run targeted a deployment where the workflow was renamed, moved, or removed, or the build did not bundle it. |
28
29
 
29
30
  For guidance on catching failures, retry behavior, and inspecting `WorkflowRunFailedError`, see [Errors and retries](/docs/foundations/errors-and-retries).
30
31
 
@@ -38,8 +38,8 @@ Workflow run is approaching the per-run event limit (<count> of <limit> events,
38
38
 
39
39
  ### Run on the QuickJS VM with snapshotting
40
40
 
41
- <Callout type="warn">
42
- The QuickJS engine is experimental, and its global surface differs from the default engine. Review the [differences](/docs/configuration/runtime-tuning#workflow_vm) before switching an existing deployment.
41
+ <Callout type="info">
42
+ This is the recommended fix for long-running workflows. Workflow code runs unchanged unless it uses one of the few globals QuickJS does not provide in workflow functions (any `Intl.*` constructor, `toLocaleString()`-style methods called with a locale, `crypto.subtle`, `WebAssembly`); those calls move into a step. See the [full list](/docs/configuration/runtime-tuning#workflow_vm).
43
43
  </Callout>
44
44
 
45
45
  Runs that execute on the QuickJS VM with snapshotting enabled are exempt from the default per-run event limit. A snapshotted run restores its VM memory and replays only the events recorded since the last snapshot, so its resume cost doesn't grow with the length of the log.
@@ -31,8 +31,8 @@ Workflow replay exceeded maximum duration (240s) after 4 attempts
31
31
 
32
32
  ### Run on the QuickJS VM with snapshotting
33
33
 
34
- <Callout type="warn">
35
- The QuickJS engine is experimental, and its global surface differs from the default engine. Review the [differences](/docs/configuration/runtime-tuning#workflow_vm) before switching an existing deployment.
34
+ <Callout type="info">
35
+ This is the recommended fix for long-running workflows. Workflow code runs unchanged unless it uses one of the few globals QuickJS does not provide in workflow functions (any `Intl.*` constructor, `toLocaleString()`-style methods called with a locale, `crypto.subtle`, `WebAssembly`); those calls move into a step. See the [full list](/docs/configuration/runtime-tuning#workflow_vm).
36
36
  </Callout>
37
37
 
38
38
  Under QuickJS with snapshotting, a run restores its VM memory from a snapshot and replays only the events recorded since, so replay time stays roughly constant as the log grows. These runs are also exempt from the default [per-run event limit](/docs/errors/max-events-exceeded).
@@ -10,7 +10,7 @@ related:
10
10
  - /docs/api-reference/workflow-errors/workflow-not-registered-error
11
11
  ---
12
12
 
13
- This error occurs when the Workflow runtime tries to execute a workflow function that is not registered in the current deployment. When this happens, the run fails with a `RUNTIME_ERROR` error code.
13
+ This error occurs when the Workflow runtime tries to execute a workflow function that is not registered in the current deployment. When this happens, the run fails with the `WORKFLOW_NOT_REGISTERED` error code. Runs that failed on SDK versions before this code was introduced recorded `RUNTIME_ERROR` instead.
14
14
 
15
15
  ## Error message
16
16
 
@@ -213,6 +213,7 @@ try {
213
213
  | `STREAM_ERROR` | Workflow stream infrastructure failed while reading or writing data. This is an SDK or backend failure rather than an error in workflow code; retry the run and report persistent failures with the `runId` |
214
214
  | `WORLD_CONTRACT_ERROR` | A World response violated the SDK contract; points at a World implementation bug |
215
215
  | `DEPLOYMENT_MISMATCH` | The run was delivered to a deployment other than the one it is pinned to, and automatic re-routing did not recover it. See [deployment-mismatch](/docs/errors/deployment-mismatch) |
216
+ | `WORKFLOW_NOT_REGISTERED` | The deployment executing the run does not have the run's workflow registered. See [workflow-not-registered](/docs/errors/workflow-not-registered) |
216
217
  | `RUNTIME_ERROR` | An internal runtime error. If you see this, please [file an issue](https://github.com/vercel/workflow/issues) |
217
218
 
218
219
  <Callout type="info">
@@ -276,7 +277,3 @@ export async function placeOrderSaga(orderId: string) {
276
277
  }
277
278
  }
278
279
  ```
279
-
280
- ## Spec 9 (experimental)
281
-
282
- The experimental spec 9 runtime retries steps differently: a failed step is retried after about a second by default on its one queue message, and a `maxRetries = 0` step whose invocation dies after it started fails instead of running again. See [Retries on spec 9 runs](/docs/changelog/spec-9#retries).
@@ -172,6 +172,7 @@ Events are categorized by the entity type they affect. Each event contains metad
172
172
  | `run_completed` | Transitions the run to `completed` state with the workflow's return value. |
173
173
  | `run_failed` | Transitions the run to `failed` state with error details and optional error code. |
174
174
  | `run_cancelled` | Transitions the run to `cancelled` state. Can be triggered from `pending` or `running` states. |
175
+ | `attr_set` | Records attribute changes on the run, one event per [`setAttributes()`](/docs/api-reference/workflow/set-attributes) call. Contains the changes and their writer. A write from the workflow body carries a correlation ID; a write from a step body does not. Does not change the run's state. |
175
176
 
176
177
  ### Step events
177
178
 
@@ -207,7 +208,7 @@ Events are categorized by the entity type they affect. Each event contains metad
207
208
 
208
209
  ### How fast a log grows
209
210
 
210
- Counting the events above is how you size a run. A step that succeeds on the first attempt contributes three events; a retry adds another `step_started`, preceded by a `step_retrying` when the World emits one; a sleep contributes two, and a hook at least two.
211
+ Every action your run takes adds to the event log. For example, a step that succeeds on the first attempt contributes three events (`step_created`, `step_started`, `step_completed`). A retry adds another `step_started`, preceded by a `step_retrying` when the World emits one; a sleep contributes two events, and a hook at least two, plus one for each resume.
211
212
 
212
213
  A run's log is capped — the [Vercel World](/worlds/vercel#per-run-limits) fails anything past its ceiling with `MAX_EVENTS_EXCEEDED`. Replay reads the whole log, so a run gets slower as it grows and is worth splitting well before it fails: split into [child workflows](/cookbook/advanced/child-workflows) once a run would grow past a few thousand events. Runs on the QuickJS VM with snapshotting resume from a snapshot instead of replaying the whole log, and are exempt from the ceiling; see [max-events-exceeded](/docs/errors/max-events-exceeded). How much the growth costs depends on how often the run replays; [Steps and long runs](/docs/performance#steps-and-long-runs) shows how step-to-step overhead changes through a 1,020-step run.
213
214
 
@@ -383,7 +384,3 @@ Step-to-step overhead (STSO) measures the time the runtime adds between two step
383
384
  <MetricVideo metric="stso" />
384
385
 
385
386
  See [Step-to-step overhead](/docs/performance#step-to-step-overhead-stso) on the Performance page for how it's measured and the latest results.
386
-
387
- ## Spec 9 (experimental)
388
-
389
- The experimental spec 9 runtime writes the same event types with a different model: one orchestrator per run writes every decision behind an in-band fence, step and wait events are plain appends, and an inline step is created by its first `step_started`. See [The event log on spec 9 runs](/docs/changelog/spec-9#the-event-log).
@@ -206,7 +206,7 @@ Your integration can expose physical files, virtual modules, or framework-native
206
206
 
207
207
  ## Vercel queue configuration
208
208
 
209
- On Vercel, configure the flow function as the sole queue consumer. `getWorkflowQueueTrigger()` handles the optional queue namespace and `WORKFLOW_SEQUENTIAL_REPLAYS=1` behavior.
209
+ On Vercel, configure the flow function as the sole queue consumer. `getWorkflowQueueTrigger()` handles the optional queue namespace.
210
210
 
211
211
  ```typescript
212
212
  import { getWorkflowQueueTrigger } from "@workflow/builders";
@@ -235,7 +235,7 @@ The generated trigger listens to one topic family:
235
235
 
236
236
  Both orchestration messages and step messages use this topic family. A step message is distinguished by its payload, not by a second topic or function.
237
237
 
238
- If you construct the trigger yourself, add `maxConcurrency: 1` when `WORKFLOW_SEQUENTIAL_REPLAYS=1`. The exported `isSequentialReplaysEnabled()` helper implements that build-time check.
238
+ If you construct the trigger yourself, set no `maxConcurrency` on it. `isSequentialReplaysEnabled()` is deprecated and always returns `false`; remove any `maxConcurrency: 1` that depended on it.
239
239
 
240
240
  ## Security
241
241
 
@@ -2,6 +2,7 @@
2
2
  title: Internal
3
3
  description: Preview-only page for internal tools, draft changelogs, and testing utilities.
4
4
  type: overview
5
+ internal: true
5
6
  ---
6
7
 
7
8
  <Callout type="warn">
@@ -2,6 +2,7 @@
2
2
  title: Native Nitro v3 bundling for workflows
3
3
  description: Workflow routes are now bundled by Nitro v3, so steps run in your app's runtime and can call any server-side Nitro API.
4
4
  type: overview
5
+ internal: true
5
6
  ---
6
7
 
7
8
  # Native Nitro v3 bundling for workflows
@@ -2,6 +2,7 @@
2
2
  title: Local web UI in Nitro dev
3
3
  description: Inspect, monitor, and debug your workflow runs from the /_workflow route during Nitro development.
4
4
  type: overview
5
+ internal: true
5
6
  ---
6
7
 
7
8
  # Local web UI in Nitro dev
@@ -2,6 +2,7 @@
2
2
  title: Serializable AbortController and AbortSignal
3
3
  description: AbortController and AbortSignal now work across workflow and step boundaries using the standard Web API.
4
4
  type: overview
5
+ internal: true
5
6
  ---
6
7
 
7
8
  # Serializable AbortController and AbortSignal
@@ -47,6 +47,8 @@ in: open `/_workflow` while `nitro dev` is running. No separate command is requi
47
47
 
48
48
  In the runs table, select one or more runs and choose **Cancel** to cancel the batch in a single request. Runs that fail with a retryable error stay selected so you can retry them.
49
49
 
50
+ In a run's **Streams** tab, a byte stream that carries a PNG, JPEG, GIF, or WebP image is shown as an image preview, with a **Download Image** button for the original bytes.
51
+
50
52
  To share a link to a specific run without opening a browser, use the `--url`
51
53
  flag. It prints the dashboard deep link to stdout and exits (no browser, no
52
54
  local server), which is useful for scripts, PR comments, or automation. Add `--json` to
@@ -46,9 +46,9 @@ The largest change in v5 has no API surface: the runtime does far less work per
46
46
 
47
47
  **Replay no longer downloads recorded step inputs.** Replay recomputes step arguments by re-running workflow code, so it reads the event log without the `input` of each step. For workflows that pass growing state into their steps, this removes the part of the replay transfer that grew quadratically with the run. Worlds opt in through [`resolveData: 'skip-step-inputs'`](/docs/api-reference/workflow-runtime/world/storage#eventslist), and Vercel Workflows supports it.
48
48
 
49
- **Resuming a hook takes one round trip instead of two.** `resumeHook()` writes the `hook_received` event and dispatches the queue message concurrently, with a `(runId, resumeId)` dedup constraint keeping the two writers converging on exactly one event. See [Resilient hook resumption](/docs/changelog/resilient-resume).
49
+ **Resuming a hook takes one round trip instead of two.** `resumeHook()` writes the `hook_received` event and dispatches the queue message concurrently, with a `(runId, resumeId)` dedup constraint keeping the two writers converging on exactly one event.
50
50
 
51
- **A suspension's writes go out as one batch.** The `step_created` and `wait_created` events a suspension produces are folded into a single durable write with a per-event outcome, instead of one request each, and a fan-out's inline step bodies start straight off that commit rather than each claiming its step first. This engages on Worlds that implement the batch API. See [Batched event writes](/docs/changelog/batched-event-writes).
51
+ **A suspension's writes go out as one batch.** The `step_created` and `wait_created` events a suspension produces are folded into a single durable write with a per-event outcome, instead of one request each, and a fan-out's inline step bodies start straight off that commit rather than each claiming its step first. This engages on Worlds that implement the batch API.
52
52
 
53
53
  **Concurrent writers no longer compete for a position in the log.** Each event's position used to be claimed by the write that filled it, so a wide fan-out serialized on that claim. Positions are now handed out ahead of the commit, which is what makes the fan-out above cheap. The cost is a position whose writer dies, which the backend closes with a `noop` event that replay steps over. Nothing about this is visible from workflow code; [`WORKFLOW_SPEC_VERSION=6`](/docs/configuration/runtime-tuning#workflow_spec_version) creates new runs on the previous scheme, and existing runs keep the scheme they were created on.
54
54
 
@@ -185,7 +185,7 @@ All three first-party Worlds now implement it: Vercel accepts up to 30 days, and
185
185
  - **Support for more frameworks.** [React Router](/docs/getting-started/react-router) (v7 and v8, via Nitro) and [NestJS](/docs/getting-started/nestjs) are now supported.
186
186
  - **A misrouted delivery no longer fails a run.** Runs are pinned to the deployment that created them. A delivery that arrives at a different deployment is now re-routed to the pinned one with backoff instead of failing, and only gives up with the new [`DEPLOYMENT_MISMATCH`](/docs/errors/deployment-mismatch) error once the recovery budget is spent. Nothing executes on the wrong deployment while this happens. In 4.x the same situation surfaced as an unexplained decryption failure.
187
187
  - **A run cannot be forked across environments.** `start()` stamps the environment it was called from onto the queue message, and a deployment refuses a delivery whose run was created in a different environment. Previously a preview client and a production deployment could each hold half of one run ID.
188
- - **An experimental QuickJS VM engine.** Set [`WORKFLOW_VM=quickjs`](/docs/configuration/runtime-tuning#workflow_vm) to run workflow functions in a QuickJS VM compiled to WebAssembly instead of `node:vm`, for platforms that do not provide `node:vm`. Replay semantics are identical, but the available globals are not: check the differences before switching an existing deployment. By default, an encrypted QuickJS run that passes 1,000 events resumes from a VM-memory snapshot instead of replaying its full event log (see [`WORKFLOW_SNAPSHOT_THRESHOLD`](/docs/configuration/runtime-tuning#workflow_snapshot_threshold)).
188
+ - **A QuickJS VM engine for long-running workflows.** Set [`WORKFLOW_VM=quickjs`](/docs/configuration/runtime-tuning#workflow_vm) to run workflow functions in a QuickJS VM compiled to WebAssembly instead of `node:vm`. Replay semantics are identical, and a few globals (such as `Intl` and `crypto.subtle`) move into steps. By default, an encrypted QuickJS run that passes 1,000 events resumes from a VM-memory snapshot instead of replaying its full event log, and is exempt from the default per-run event limit (see [`WORKFLOW_SNAPSHOT_THRESHOLD`](/docs/configuration/runtime-tuning#workflow_snapshot_threshold)). It also runs on platforms that do not provide `node:vm`.
189
189
  - **Experimental dynamic workflows.** Pass workflow source as a string to `start()` to run orchestration assembled after deployment over steps already deployed with your app. The code is stored with the run (encrypted on Vercel), so replays always execute the code the run started with. Off unless the deployment sets `WORKFLOW_EXPERIMENTAL_DYNAMIC_WORKFLOWS=1`. See [Dynamic Workflows](/docs/advanced/dynamic-workflows).
190
190
  - **A WebSocket transport for event and stream writes** on the Vercel World, which sends a run's event writes and stream writes over a socket instead of one HTTP request each. It is the default; set [`WORKFLOW_EVENTS_TRANSPORT=http`](/worlds/vercel#workflow_events_transport) or [`WORKFLOW_STREAMS_TRANSPORT=http`](/worlds/vercel#workflow_streams_transport) to opt out. Tracing is unaffected: each write still emits an `http POST` client span, synthesized around the frame, with the transport on `workflow.events.transport`.
191
191
  - **`await run.returnValue` waits instead of polling.** Reading a run's result long-polls the World until the run reaches a terminal status, rather than asking again on a fixed interval. A result is observed as soon as it exists, and an idle wait costs one open request instead of a request per tick. Worlds that do not implement the long poll keep the interval. Since 5.4.0, a parent awaiting a child run it started doesn't poll at all: it suspends on a system hook the child resumes when it finishes, so the wait uses no compute or worker slot. See [Child Workflows](/cookbook/advanced/child-workflows#how-the-parent-waits).
@@ -45,6 +45,7 @@ interface WorldCapabilities {
45
45
  active: boolean;
46
46
  };
47
47
  maxConcurrency?: boolean;
48
+ experimental_queueHold?: boolean;
48
49
  inBandFence?: boolean;
49
50
  hookForceClaim?: boolean;
50
51
  dynamicWorkflowCode?: boolean;
@@ -67,7 +68,7 @@ interface World extends Storage, Queue, Streamer {
67
68
 
68
69
  `specVersion` is required. See [Declaring the spec version](#declaring-the-spec-version).
69
70
 
70
- The optional `capabilities` object advertises additional behavior, and every capability **fails closed**. A missing member means "unsupported," and the runtime keeps its conservative behavior. Set `hookRetention.active` to `true` only when the World implements hook token retention. Set `maxConcurrency` only when the World's queue supports `maxConcurrency`-limited consumption, which `WORKFLOW_SEQUENTIAL_REPLAYS=1` uses. Set `hookForceClaim` only when the World implements [hook token takeover](/worlds/upgrading-to-v5#new-optional-surface). Without it, `createHook({ experimental_force: true })` fails the workflow when it registers the hook. Set `dynamicWorkflowCode` only when the World persists `dynamicWorkflowCode` from `run_created` (and from a `run_started` that creates the run), echoes it on the created run, and returns it from `runs.get` with `resolveData: 'all'`. Without it, `start()` refuses [dynamic workflows](/docs/advanced/dynamic-workflows). The code is sent inline unless the World also implements `uploadDynamicWorkflowCode` for large definitions. Set `inBandFence` only when the World implements the [in-band writer fence](#optional-the-in-band-writer-fence). Set `atomicStartHook.active` only when the World implements [atomic start Hook admission](#optional-atomic-start-hook-admission). Without it, `start({ experimental_hook })` throws before it enqueues anything.
71
+ The optional `capabilities` object advertises additional behavior, and every capability **fails closed**. A missing member means "unsupported," and the runtime keeps its conservative behavior. Set `hookRetention.active` to `true` only when the World implements hook token retention. Set `maxConcurrency` only when the World's queue delivers a spec 9 run's orchestrator messages one at a time. Set `hookForceClaim` only when the World implements [hook token takeover](/worlds/upgrading-to-v5#new-optional-surface). Without it, `createHook({ experimental_force: true })` fails the workflow when it registers the hook. Set `dynamicWorkflowCode` only when the World persists `dynamicWorkflowCode` from `run_created` (and from a `run_started` that creates the run), echoes it on the created run, and returns it from `runs.get` with `resolveData: 'all'`. Without it, `start()` refuses [dynamic workflows](/docs/advanced/dynamic-workflows). The code is sent inline unless the World also implements `uploadDynamicWorkflowCode` for large definitions. Set `inBandFence` only when the World implements the [in-band writer fence](#optional-the-in-band-writer-fence). Set `atomicStartHook.active` only when the World implements [atomic start Hook admission](#optional-atomic-start-hook-admission). Without it, `start({ experimental_hook })` throws before it enqueues anything. Set `experimental_queueHold` only when `queue()` implements [holding a message for its sender](#optional-holding-a-message-for-its-sender-experimental). Without it, callers keep their own fallback and never ask for a hold.
71
72
 
72
73
  [Slot-numbered event IDs](#event-id-allocation) are a contract requirement rather than a capability, so there is no flag or fallback path.
73
74
 
@@ -329,7 +330,7 @@ interface Queue {
329
330
  queueName: ValidQueueName,
330
331
  message: QueuePayload,
331
332
  opts?: QueueOptions
332
- ): Promise<{ messageId: MessageId | null }>;
333
+ ): Promise<QueueResult>; // { messageId: MessageId | null; experimental_hold?: QueueHoldResult }
333
334
 
334
335
  // Optional. Omit it and the runtime publishes one message at a time.
335
336
  queueBatch?(
@@ -362,7 +363,7 @@ interface Queue {
362
363
 
363
364
  The Workflow SDK's flow route is mounted in the app like any other route, so a request from outside the app can reach it. Before it reads the body or touches any run, the runtime checks every request to that route against the World's `queueAuthMode` mode. The check runs in the flow route handler `@workflow/core` generates, not in `createQueueHandler()`, so a queue consumer's own route (served with `createQueueHandler()` and registered with `registerRoute()`) is not checked and must authenticate deliveries itself. The modes:
364
365
 
365
- - `'loopback'`: for a queue that delivers back to the app's own flow route. The delivery must carry the app's queue key in the `QUEUE_AUTH_HEADER` (`x-workflow-auth`) header; a request without it gets a `401`, and no run is touched. "Loopback" means sent by the app's own processes, which share the key, not any request from `localhost`. The queue attaches the key to every delivery it sends, over HTTP or to an in-process handler, on every attempt. Set it when the delivery is sent, never store it with the message, and replace any copy a caller supplied in `opts.headers`. The runtime checks the key against the sources Worlds register with `setQueueAuthKeySource()` from `@workflow/utils`, one per data directory, accepting a key that matches any of them; when none is registered, it checks `getQueueAuthKey()`, a key held in memory by one process. `@workflow/world-local` registers the key in its data directory, which the app, the CLI and the web UI share (see [the Local World](/worlds/local#workflow_queue_auth)). A World whose queue reuses `@workflow/world-local`'s gets this for free. The mode is temporary: it exists while the Local World's queue delivers over the app's own HTTP route.
366
+ - `'loopback'`: for a queue that delivers back to the app's own flow route. The delivery must carry the app's queue key in the `QUEUE_AUTH_HEADER` (`x-workflow-auth`) header; a request without it gets a `401`, and no run is touched. "Loopback" means sent by the app's own processes, which share the key, not any request from `localhost`. The queue attaches the key to every delivery it sends, over HTTP or to an in-process handler, on every attempt. Set it when the delivery is sent, never store it with the message, and replace any copy a caller supplied in `opts.headers`. The runtime checks the key against the sources Worlds register with `setQueueAuthKeySource()` from `@workflow/utils`, one per data directory, accepting a key that matches any of them; when none is registered, it checks `getQueueAuthKey()`, a key held in memory by one process. `@workflow/world-local` registers the key in its data directory, which the app, the CLI and the web UI share (see [the Local World](/worlds/local#data-directory-layout)). A World whose queue reuses `@workflow/world-local`'s gets this for free. The mode is temporary: it exists while the Local World's queue delivers over the app's own HTTP route.
366
367
  - `'skip'`: the runtime does not check. For a World whose platform guarantees that only its queue reaches the route, as the [Vercel World](/worlds/vercel#security) does with two layers: the route can be triggered only by Vercel Queues, and the handler receives only a message ID, and retrieves and leases the message through Vercel Queues. Declare `'skip'` only when both hold. `@workflow/world-postgres` declares it for now, until its messages are delivered in-process ([#5258](https://github.com/vercel/workflow/issues/5258)); its flow route accepts any well-formed request, so protect it at the network edge (see [the Postgres World](/worlds/postgres#protect-the-queue-route)).
367
368
 
368
369
  A World that declares nothing is not checked, and the runtime logs a warning when its flow route starts (once, then at most once a minute when routes restart), saying the route is not authenticated and has to be protected at the network edge. The mode becomes required in SDK v6, so declare one now: `'loopback'` if the World's queue attaches the key, `'skip'` only when the route is protected as described above. Operators can turn the check off with [`WORKFLOW_QUEUE_AUTH=off`](/docs/configuration/runtime-tuning#workflow_queue_auth), except while dynamic workflows are enabled.
@@ -450,6 +451,47 @@ type QueueBatchResult =
450
451
 
451
452
  Every message targets one logical `queueName`, but you may split the batch internally — by a transport cap, or by any per-message routing dimension you derive from the payload — as long as the returned order still matches the input. The runtime passes a distinct `idempotencyKey` per message, because its recovery for both a request-level failure and a retryable entry is to republish the whole batch.
452
453
 
454
+ ### Optional: holding a message for its sender (experimental)
455
+
456
+ `QueueOptions.experimental_hold` asks `queue()` to claim the message's first delivery for the process that sent it, before `queue()` returns. That process runs the message in the same request, and your queue is the crash backstop. The Workflow SDK runtime doesn't use it today; callers that drive a World directly do. Declare `capabilities.experimental_queueHold: true` only when you implement it. A World without it can ignore the option entirely: return `{ messageId }` with no `experimental_hold`, and callers treat the message as delivered by the queue.
457
+
458
+ {/* @skip-typecheck - interface definition, not runnable code */}
459
+ ```typescript
460
+ // QueueOptions.experimental_hold?: true | QueueHoldOptions (`true` means `{}`)
461
+ interface QueueHoldOptions {
462
+ consumerGroup?: string; // the group that would otherwise receive it
463
+ visibilityTimeoutSeconds?: number; // the hold's lease
464
+ }
465
+
466
+ type QueueHoldResult = HeldQueueMessage | NotHeldQueueMessage;
467
+
468
+ interface HeldQueueMessage {
469
+ readonly status: "held";
470
+ readonly messageId: MessageId;
471
+ readonly leaseExpiresAt: Date;
472
+ consume(handler: QueueHandler): Promise<void>;
473
+ release(delaySeconds?: number): Promise<void>;
474
+ }
475
+
476
+ interface NotHeldQueueMessage {
477
+ readonly status: "not_held";
478
+ readonly reason:
479
+ | "unsupported" | "deferred" | "lost" | "coalesced"
480
+ | "concurrency_limited" | "duplicate" | "error";
481
+ }
482
+ ```
483
+
484
+ When you implement it:
485
+
486
+ - **Accept `true` as `{}`.** `experimental_hold: true` asks for a hold with your defaults.
487
+ - **Return exactly one outcome per hold request.** Return `held` only when this process now owns the message's first delivery. In every other case return `not_held` with a reason, and make sure the message still gets delivered (or is covered by a delivery that's running).
488
+ - **Run `consume(handler)` as a delivery.** Use the same code path `createQueueHandler()` uses: the same `meta` (`deliveryCount: 1`), the same result rules (`{ timeoutSeconds }` redelivers the same message, a rejection retries), lease renewal while the handler runs, and an acknowledgment when it resolves.
489
+ - **Deliver a lapsed hold as usual.** If nothing renews the lease, deliver the message to `consumerGroup` about `visibilityTimeoutSeconds` after the last renewal, with the same `messageId` and the next `deliveryCount`.
490
+ - **Make `release(delaySeconds)` hand the message back.** It becomes visible again after `delaySeconds`.
491
+ - **Refuse what can't be held.** Throw a `TypeError` for a hold with `delaySeconds`. Don't hold a message pinned to another deployment: send it as usual and return `not_held` / `unsupported`. `queueBatch()` never holds.
492
+
493
+ `@workflow/world-vercel` implements this with Vercel Queues' send-and-hold. Its `queue()` and `createQueueHandler()` share one delivery callback, which is the simplest way to keep a held run and a pushed delivery identical.
494
+
453
495
  ### Queue names
454
496
 
455
497
  Queue names follow a specific pattern:
@@ -719,4 +761,4 @@ Your World will then appear on the [Worlds ecosystem](/worlds) page with its com
719
761
 
720
762
  ## Supporting spec 9 runs (experimental)
721
763
 
722
- Everything above is the contract for spec 8 runs, which every World needs. A World may also let its users opt in to the experimental spec 9 runtime (`WORKFLOW_SPEC_VERSION=9`). To do so it implements the [in-band writer fence](#optional-the-in-band-writer-fence), serializes each spec 9 run's orchestrator deliveries, follows the spec 9 queue and deduplication rules, declares `capabilities.inBandFence: true`, and passes it on as `mintedSpecVersion(process.env, { inBandFence: true })`. `mintedSpecVersion()` called with no options never returns 9, so a World that does none of this keeps creating spec 8 runs. See [Implementing spec 9 in a World](/docs/changelog/spec-9#implementing-spec-9-in-a-world) and [World contract changes](/docs/changelog/spec-9#world-contract-changes).
764
+ Everything above is the contract for spec 8 runs, which every World needs. A World may also let its users opt in to the experimental spec 9 runtime (`WORKFLOW_SPEC_VERSION=9`). To do so it implements the [in-band writer fence](#optional-the-in-band-writer-fence), serializes each spec 9 run's orchestrator deliveries, follows the spec 9 queue and deduplication rules, declares `capabilities.inBandFence: true`, and passes it on as `mintedSpecVersion(process.env, { inBandFence: true })`. `mintedSpecVersion()` called with no options never returns 9, so a World that does none of this keeps creating spec 8 runs.