workflow 5.4.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.
- package/dist/api-workflow.js +1 -1
- package/dist/api.js +1 -1
- package/dist/astro.js +1 -1
- package/dist/index.js +1 -1
- package/dist/internal/builtins.js +1 -1
- package/dist/internal/class-serialization.js +1 -1
- package/dist/internal/errors.js +1 -1
- package/dist/nest-builder.js +1 -1
- package/dist/nest-vercel-builder.js +1 -1
- package/dist/nest.js +1 -1
- package/dist/next.cjs +1 -1
- package/dist/nitro.js +1 -1
- package/dist/nuxt.js +1 -1
- package/dist/observability.d.ts +1 -1
- package/dist/observability.js +2 -2
- package/dist/runtime.js +1 -1
- package/dist/stdlib.js +1 -1
- package/dist/sveltekit.js +1 -1
- package/dist/typescript-plugin.cjs +1 -1
- package/dist/vite.js +1 -1
- package/dist/workflow.js +1 -1
- package/docs/ai/chat-session-modeling.mdx +1 -1
- package/docs/ai/resumable-streams.mdx +1 -1
- package/docs/api-reference/workflow/create-hook.mdx +2 -2
- package/docs/api-reference/workflow/get-step-metadata.mdx +19 -0
- package/docs/api-reference/workflow-ai/durable-agent.mdx +2 -1
- package/docs/api-reference/workflow-ai/workflow-chat-transport.mdx +4 -4
- package/docs/api-reference/workflow-api/get-run.mdx +0 -4
- package/docs/api-reference/workflow-api/resume-hook.mdx +1 -1
- package/docs/api-reference/workflow-api/start.mdx +1 -1
- package/docs/api-reference/workflow-errors/in-band-superseded-error.mdx +0 -3
- package/docs/api-reference/workflow-errors/index.mdx +1 -1
- package/docs/api-reference/workflow-errors/precondition-failed-error.mdx +0 -2
- package/docs/api-reference/workflow-errors/workflow-not-registered-error.mdx +1 -1
- package/docs/api-reference/workflow-errors/workflow-run-cancelled-error.mdx +1 -1
- package/docs/api-reference/workflow-errors/workflow-run-failed-error.mdx +1 -1
- package/docs/api-reference/workflow-next/with-workflow.mdx +57 -0
- package/docs/api-reference/workflow-observability/create-state-resolver.mdx +56 -0
- package/docs/api-reference/workflow-observability/index.mdx +5 -0
- package/docs/api-reference/workflow-observability/meta.json +1 -0
- package/docs/api-reference/workflow-runtime/world/queue.mdx +70 -3
- package/docs/api-reference/workflow-runtime/world/storage.mdx +1 -2
- package/docs/comparisons/index.mdx +4 -1
- package/docs/comparisons/workflow-sdk-vs-aws-step-functions.mdx +3 -1
- package/docs/comparisons/workflow-sdk-vs-cloudflare-workflows.mdx +4 -1
- package/docs/comparisons/workflow-sdk-vs-inngest.mdx +271 -28
- package/docs/comparisons/workflow-sdk-vs-temporal.mdx +6 -2
- package/docs/comparisons/workflow-sdk-vs-trigger-dev.mdx +2 -0
- package/docs/configuration/build-and-diagnostics.mdx +2 -0
- package/docs/configuration/cli-and-web-ui.mdx +40 -1
- package/docs/configuration/framework-options.mdx +7 -0
- package/docs/configuration/runtime-tuning.mdx +31 -85
- package/docs/configuration/worlds.mdx +69 -40
- package/docs/cookbook/advanced/child-workflows.mdx +3 -3
- package/docs/cookbook/agent-patterns/human-in-the-loop.mdx +1 -1
- package/docs/cookbook/common-patterns/batching.mdx +1 -1
- package/docs/cookbook/integrations/ai-sdk.mdx +2 -2
- package/docs/errors/corrupted-event-log.mdx +1 -1
- package/docs/errors/hook-force-claimed.mdx +1 -1
- package/docs/errors/index.mdx +1 -0
- package/docs/errors/max-events-exceeded.mdx +2 -2
- package/docs/errors/replay-timeout.mdx +2 -2
- package/docs/errors/runtime-decryption-failed.mdx +1 -1
- package/docs/errors/workflow-not-registered.mdx +1 -1
- package/docs/foundations/errors-and-retries.mdx +4 -5
- package/docs/foundations/serialization.mdx +80 -0
- package/docs/getting-started/next.mdx +2 -0
- package/docs/how-it-works/event-sourcing.mdx +4 -7
- package/docs/how-it-works/framework-integrations.mdx +2 -2
- package/docs/internal/index.mdx +1 -0
- package/docs/internal/nitro-native-build.mdx +1 -0
- package/docs/internal/nitro-web-ui.mdx +1 -0
- package/docs/internal/serializable-abort-controller.mdx +1 -0
- package/docs/observability/index.mdx +4 -0
- package/docs/whats-new.mdx +5 -5
- package/docs/worlds/building-a-world.mdx +63 -6
- package/docs/worlds/local.mdx +115 -26
- package/docs/worlds/postgres.mdx +110 -33
- package/docs/worlds/upgrading-to-v5.mdx +6 -6
- package/docs/worlds/vercel.mdx +194 -81
- package/package.json +17 -15
- package/dist/api-workflow.d.ts.map +0 -1
- package/dist/api.d.ts.map +0 -1
- package/dist/astro.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/internal/builtins.d.ts.map +0 -1
- package/dist/internal/class-serialization.d.ts.map +0 -1
- package/dist/internal/errors.d.ts.map +0 -1
- package/dist/nest-builder.d.ts.map +0 -1
- package/dist/nest-vercel-builder.d.ts.map +0 -1
- package/dist/nest.d.ts.map +0 -1
- package/dist/nitro.d.ts.map +0 -1
- package/dist/nuxt.d.ts.map +0 -1
- package/dist/observability.d.ts.map +0 -1
- package/dist/runtime.d.ts.map +0 -1
- package/dist/stdlib.d.ts.map +0 -1
- package/dist/sveltekit.d.ts.map +0 -1
- package/dist/vite.d.ts.map +0 -1
- package/dist/workflow.d.ts.map +0 -1
- package/docs/changelog/attributes-mvp.mdx +0 -380
- package/docs/changelog/batched-event-writes.mdx +0 -79
- package/docs/changelog/eager-processing.mdx +0 -273
- package/docs/changelog/index.mdx +0 -19
- package/docs/changelog/lazy-event-creation.md +0 -127
- package/docs/changelog/lazy-hook-resume.mdx +0 -78
- package/docs/changelog/meta.json +0 -16
- package/docs/changelog/resilient-resume.mdx +0 -32
- package/docs/changelog/resilient-start.mdx +0 -77
- package/docs/changelog/spec-9.mdx +0 -4019
- package/docs/changelog/step-message-ownership.mdx +0 -360
- package/docs/changelog/turbo-mode.md +0 -91
|
@@ -49,6 +49,8 @@ Accepted values:
|
|
|
49
49
|
- Framework option: `discoverWorkflowsInNodeModules` where supported
|
|
50
50
|
- Default: enabled
|
|
51
51
|
- Controls whether workflow discovery descends into `node_modules`. By default, dependencies that declare a `workflow`/`@workflow/*` dependency can ship `"use workflow"`/`"use step"` files that are discovered and compiled into your app's bundles.
|
|
52
|
+
- Dependencies without that declaration are not walked, but the file each import of them resolves to is still checked for serialization classes, and registered in the step bundle if it defines one. This is how AI SDK provider models (`@ai-sdk/openai`, `@ai-sdk/google`, and others) created inside a `"use workflow"` function deserialize in the steps they are passed to.
|
|
53
|
+
- Only that one file is checked: the class must be defined in the file your import resolves to. A class the file re-exports from another package or from a code-split chunk (`export { Model } from './chunk-….js'`) is not found this way. To register such a class, import the package that defines it directly, or reference it from a `"use step"` function so the step bundle loads it.
|
|
52
54
|
- Set `0` or `false` to opt out: imports from your application code that resolve into `node_modules` are not followed, so the build never reads, scans, or descends into dependency file graphs. This skips the cost of scanning `node_modules` and stops third-party workflow/step/serde code from being discovered. Useful when a dependency ships workflow code you don't want compiled into your app, or trips discovery with directive strings you don't intend to run.
|
|
53
55
|
- The SDK's own runtime serde classes (for example, `Run`) stay registered because they are reached through a seeded entry point, and imports *within* `node_modules` are still followed.
|
|
54
56
|
- Explicit framework config wins over this environment variable.
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
title: CLI and Web UI
|
|
3
3
|
description: CLI flags and environment variables for inspecting local, Postgres, and Vercel Workflow runs.
|
|
4
4
|
type: reference
|
|
5
|
-
summary: Configure workflow inspect, workflow cancel, workflow web, workflow health, and observability tooling.
|
|
5
|
+
summary: Configure workflow inspect, workflow cancel, workflow web, workflow health, workflow migrate, and observability tooling.
|
|
6
6
|
related:
|
|
7
7
|
- /docs/observability
|
|
8
8
|
- /docs/configuration/worlds
|
|
@@ -214,6 +214,36 @@ per flag.
|
|
|
214
214
|
- Default: disabled
|
|
215
215
|
- Skips the interactive confirmation prompt.
|
|
216
216
|
|
|
217
|
+
## Migrate from Inngest
|
|
218
|
+
|
|
219
|
+
`workflow migrate inngest [paths...]` rewrites Inngest functions as Workflow SDK code in place: each `createFunction()` becomes a `"use workflow"` function, and each `step.run()` closure becomes a `"use step"` function whose parameters are the variables the closure captured. It prints every step it lifted with its captured variables, and marks what needs a decision with `TODO(workflow-migrate)` comments. See [Migrating from Inngest](/docs/comparisons/workflow-sdk-vs-inngest#run-the-codemod) for what it changes.
|
|
220
|
+
|
|
221
|
+
Without paths, it migrates the files of the project's `tsconfig.json` (its `include` and `exclude`), plus JavaScript files outside `node_modules` and the build output directories. It parses them with the project's own `typescript` package, so install it as a dev dependency first, or run `npx -p typescript -p workflow workflow migrate inngest`. It refuses to overwrite files with uncommitted changes, and leaves a file unchanged if its migrated code does not parse.
|
|
222
|
+
|
|
223
|
+
### `--dry-run`
|
|
224
|
+
|
|
225
|
+
- Command: `workflow migrate`
|
|
226
|
+
- Default: disabled
|
|
227
|
+
- Prints what would change without writing any files.
|
|
228
|
+
|
|
229
|
+
### `--report`
|
|
230
|
+
|
|
231
|
+
- Command: `workflow migrate`
|
|
232
|
+
- Default: unset
|
|
233
|
+
- Writes a Markdown report to this file: each lifted step with its captured variables, each TODO, and every `inngest.send()` and `serve()` call in the project with the `start()` or `resumeHook()` call that replaces it.
|
|
234
|
+
|
|
235
|
+
### `--tsconfig`
|
|
236
|
+
|
|
237
|
+
- Command: `workflow migrate`
|
|
238
|
+
- Default: the nearest `tsconfig.json`
|
|
239
|
+
- The tsconfig to read the files and compiler options from.
|
|
240
|
+
|
|
241
|
+
### `--force`
|
|
242
|
+
|
|
243
|
+
- Command: `workflow migrate`
|
|
244
|
+
- Default: disabled
|
|
245
|
+
- Writes files even if they have uncommitted changes.
|
|
246
|
+
|
|
217
247
|
## Health checks
|
|
218
248
|
|
|
219
249
|
### `--port` / `-p`
|
|
@@ -224,6 +254,14 @@ per flag.
|
|
|
224
254
|
- Local server port for health checks.
|
|
225
255
|
- The flag writes `WORKFLOW_LOCAL_BASE_URL`.
|
|
226
256
|
|
|
257
|
+
### `--base-path`
|
|
258
|
+
|
|
259
|
+
- Command: `workflow health`
|
|
260
|
+
- Environment variable: none
|
|
261
|
+
- Default: unset, so the check targets `/.well-known/workflow/v1/flow` at the server root
|
|
262
|
+
- Path the workflow routes are served under on the local server: Next.js' `basePath` followed by [`workflows.experimentalRoutePrefix`](/docs/api-reference/workflow-next/with-workflow#workflow-route-prefix). For example, `--base-path /v2/dashboard` checks `/v2/dashboard/.well-known/workflow/v1/flow`.
|
|
263
|
+
- Appended to the URL from `--port`, `WORKFLOW_LOCAL_BASE_URL` or `PORT`.
|
|
264
|
+
|
|
227
265
|
## Verbose logging and updates
|
|
228
266
|
|
|
229
267
|
### `--verbose` / `-v`
|
|
@@ -251,3 +289,4 @@ per flag.
|
|
|
251
289
|
- CLI flag: none
|
|
252
290
|
- Default: inferred
|
|
253
291
|
- Explicit path to the workflow manifest for the web UI.
|
|
292
|
+
- Inferred from `app/`, `src/app/` and `.well-known/` at the project root first, then from a manifest generated below a [route prefix](/docs/api-reference/workflow-next/with-workflow#workflow-route-prefix), such as `app/dashboard/.well-known/workflow/v1/manifest.json`. Set it when more than one prefixed manifest exists.
|
|
@@ -28,6 +28,13 @@ Framework options are read at build or dev-server startup. Use them for settings
|
|
|
28
28
|
- Controls source maps for generated workflow bundles.
|
|
29
29
|
- Explicit config wins over `WORKFLOW_SOURCEMAP`.
|
|
30
30
|
|
|
31
|
+
### `workflows.experimentalRoutePrefix`
|
|
32
|
+
|
|
33
|
+
- Environment override: none
|
|
34
|
+
- Default: none, so the routes are generated at the app root
|
|
35
|
+
- Experimental. Emits the generated workflow routes below a route segment the app owns, such as `/dashboard/.well-known/workflow/v1/flow`, for apps that cannot own the origin's root paths.
|
|
36
|
+
- See [`withWorkflow`](/docs/api-reference/workflow-next/with-workflow#workflow-route-prefix) for the generated paths and the Turborepo caching caveat.
|
|
37
|
+
|
|
31
38
|
```typescript title="next.config.ts" lineNumbers
|
|
32
39
|
import { withWorkflow } from "workflow/next";
|
|
33
40
|
|
|
@@ -38,13 +38,6 @@ The runtime reads these variables where workflows execute. Set them on the deplo
|
|
|
38
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
39
|
- Read by the process awaiting `Run.returnValue`, like the interval above.
|
|
40
40
|
|
|
41
|
-
### `WORKFLOW_RETURN_VALUE_LONG_POLL`
|
|
42
|
-
|
|
43
|
-
- Default: enabled
|
|
44
|
-
- Set to `0` or `false` to stop `Run.returnValue` from waiting and restore fixed-interval polling on `WORKFLOW_RETURN_VALUE_POLL_INTERVAL_MS` exactly.
|
|
45
|
-
- The kill switch for the wait. Worlds that do not implement waiting are already on the interval path, so this changes nothing for them.
|
|
46
|
-
- Read by the process awaiting `Run.returnValue`, like the interval above.
|
|
47
|
-
|
|
48
41
|
### `WORKFLOW_CHILD_RUN_COMPLETION_HOOK`
|
|
49
42
|
|
|
50
43
|
- Default: enabled
|
|
@@ -75,6 +68,19 @@ For example, a workflow can run a 10-minute inline step even with `WORKFLOW_REPL
|
|
|
75
68
|
- Delivery attempts before a run or step is failed gracefully.
|
|
76
69
|
- Can only be lowered. Workflow calibrates the default to record failure before the queue expires the message.
|
|
77
70
|
|
|
71
|
+
### `WORKFLOW_QUEUE_AUTH`
|
|
72
|
+
|
|
73
|
+
- 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.
|
|
83
|
+
|
|
78
84
|
### `WORKFLOW_MAX_EVENTS`
|
|
79
85
|
|
|
80
86
|
- Default: `25000`
|
|
@@ -114,25 +120,6 @@ For example, a workflow can run a 10-minute inline step even with `WORKFLOW_REPL
|
|
|
114
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.
|
|
115
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.
|
|
116
122
|
|
|
117
|
-
### `WORKFLOW_SLOT_GAP_CHECK`
|
|
118
|
-
|
|
119
|
-
- Default: enabled
|
|
120
|
-
- A replay checks that the [event log](/docs/how-it-works/event-sourcing#event-ids) it loaded is dense before it runs, and fails the run with [`CORRUPTED_EVENT_LOG`](/docs/errors/corrupted-event-log) when a position below the log's highest holds no event. A log missing only its first position, meaning a run whose `run_created` is still being written, is left alone.
|
|
121
|
-
- A position can be briefly empty while the write that occupies it is still committing, so the check re-reads the log a few times before it decides, and the replay continues from whichever log it settled on.
|
|
122
|
-
- The check trades one failure for another. Most holes stand for an event that never happened, and replaying past those is correct. A hole standing for an event that did happen looks identical, and replaying past that one produces a run whose result is silently wrong. Failing is the recoverable side of that trade.
|
|
123
|
-
- Set `0` to replay across holes instead.
|
|
124
|
-
|
|
125
|
-
### `WORKFLOW_SEALED_LOG`
|
|
126
|
-
|
|
127
|
-
- Default: enabled
|
|
128
|
-
- New runs are created at the sealed-log spec version, in which the World's backend assigns each event its position *before* the write commits rather than letting concurrent writers race for one. Concurrent writes then never contend for a position, which is what makes a wide fan-out cheap.
|
|
129
|
-
- The price of assigning positions in advance is that a writer which claims one and then dies leaves a position no writer will ever fill. The backend closes such a position by writing a `noop` event into it once it can prove the position was abandoned, so a reader still sees the dense log it needs. Replay steps over a `noop` without delivering it to the workflow or advancing the deterministic clock. Its timestamp belongs to whichever reader sealed it, not to the run.
|
|
130
|
-
- Set `0` to put a deployment back on the previous scheme, where each position is allocated by the write that occupies it. Use this as the kill switch if position assignment turns out to be at fault for event-log problems.
|
|
131
|
-
- Setting `0` also stamps new runs below spec version 8, so another run can't take their hook tokens 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. Runs created with `0` can still take tokens over from others.
|
|
132
|
-
- Existing runs are unaffected either way. A run's spec version is stamped once, at creation, and read from the run for the rest of its life, so flipping this changes only what *new* runs get, and a run in flight keeps the scheme it started on. Every build reads sealed logs regardless of the setting.
|
|
133
|
-
- A run created at the sealed-log version can only be replayed by a reader that knows to skip `noop` events. That includes every runtime on this release train, but a runtime that pins its own accepted spec range separately, such as the Python runtime, has to catch up before it can read these runs. Switch this off in an environment where it has not.
|
|
134
|
-
- Only the Vercel World seals. The Local and Postgres Worlds allocate each position at the commit that occupies it, so they cannot leave a hole and never write a `noop`; the setting still moves the version they stamp, so the fleet stays on one spec.
|
|
135
|
-
|
|
136
123
|
### `WORKFLOW_PRECONDITION_MAX_INPROCESS_RESTARTS`
|
|
137
124
|
|
|
138
125
|
- Default: `3`
|
|
@@ -151,16 +138,6 @@ For example, a workflow can run a 10-minute inline step even with `WORKFLOW_REPL
|
|
|
151
138
|
- Delay before a re-invocation caused by a rejected event creation.
|
|
152
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.
|
|
153
140
|
|
|
154
|
-
### `WORKFLOW_LOG_ORDER_DRAWS`
|
|
155
|
-
|
|
156
|
-
- Default: enabled
|
|
157
|
-
- Experimental. Pins correlation-ID draw order to event-log order. A branch-deciding delivery (a step result, hook payload, or wait completion) resolves to the workflow only after every earlier-in-log delivery's continuation has fully quiesced, and never ahead of a lower-slot delivery that is committed to happening.
|
|
158
|
-
- Without it, a delivery that resolves while an earlier delivery's continuation is still a few microtask hops from its next step/hook/wait call can overtake it on the run's shared correlation-ID sequence. Draw order, and therefore correlation IDs, then depends on how much of the event log a replay had loaded. Two concurrent replays holding different-length prefixes can bind one ID to two different entities, failing the run with `CORRUPTED_EVENT_LOG`.
|
|
159
|
-
- Costs one event-loop turn (roughly 15 to 20 microseconds via `setImmediate`) per branch-deciding delivery during replay, and more when continuations genuinely overlap. Measurements on a 100-step sequential replay show about 2 ms added end to end.
|
|
160
|
-
- Only applies to the default Node.js VM engine. `WORKFLOW_VM=quickjs` has its own event feed and correlation-ID sequence and is unaffected by this setting.
|
|
161
|
-
- Correlation IDs of runs created before the setting changed are not affected on platforms where a run keeps replaying on the deployment it started on. Elsewhere, only change it while no runs are in flight.
|
|
162
|
-
- Set `0` to opt back into arrival-order delivery resolution. Only the literal value `0` opts out; `false` or `off` leave it enabled.
|
|
163
|
-
|
|
164
141
|
## Inline execution
|
|
165
142
|
|
|
166
143
|
### `WORKFLOW_V2_TIMEOUT_MS`
|
|
@@ -177,18 +154,6 @@ For example, a workflow can run a 10-minute inline step even with `WORKFLOW_REPL
|
|
|
177
154
|
- Number of newly-created steps one invocation runs inline in parallel before queueing the rest.
|
|
178
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.
|
|
179
156
|
|
|
180
|
-
### `WORKFLOW_INLINE_EARLY_ADVANCE`
|
|
181
|
-
|
|
182
|
-
- Default: enabled
|
|
183
|
-
- Spec 8 runs on the Node.js VM engine only (not QuickJS, and not spec 9 runs). When one inline step of a parallel batch completes or fails while its siblings are still running, the invocation replays the workflow right away instead of waiting for the slowest sibling. A branch of a `Promise.all` can then start its next step without waiting for the other branches.
|
|
184
|
-
- Steps still running stay owned by the invocation that started them. They count against `WORKFLOW_MAX_INLINE_STEPS`, so fewer new steps run inline while they run. A branch that fans out while its siblings still run queues the steps past the remaining slots as background steps.
|
|
185
|
-
- When the workflow returns or throws while one of its inline steps is still running (for example a `Promise.race` loser), the run completes or fails right away. That step gets only its current attempt: the invocation lets its body finish, and the bundled Worlds record its `step_completed`, `step_failed` or `step_retrying` after the run's terminal event, but a retry is never run, so a step whose attempt fails retryably stays pending. This matches what happens when a `sleep()` or hook wins a race. `run_completed` or `run_failed` is therefore not always the last event of a run. With this setting off, the run waits for the loser and its retries. The `workflow.inline.running_at_terminal` and `workflow.inline.discarded_outcomes` span attributes, and an info log, report these steps.
|
|
186
|
-
- A step that retries, is throttled, or leaves stream writes unflushed waits for its whole batch, as with this setting off.
|
|
187
|
-
- Branches whose steps were queued because the batch exceeded `WORKFLOW_MAX_INLINE_STEPS` still advance only when the last pending step of the batch completes.
|
|
188
|
-
- When the invocation hands the run off (its replay budget or inline window is spent), it waits for every inline step still running first, so branches advance in lockstep at that point, as with this setting off. An info log marks the hand-off.
|
|
189
|
-
- `workflow.inline.early_advances` counts early replays and `workflow.inline.slots_held_back` counts steps queued because running steps held the inline slots.
|
|
190
|
-
- Set `0` or `false` to wait for every inline step of a batch before replaying.
|
|
191
|
-
|
|
192
157
|
### `WORKFLOW_TURBO`
|
|
193
158
|
|
|
194
159
|
- Default: enabled
|
|
@@ -211,12 +176,6 @@ For example, a workflow can run a 10-minute inline step even with `WORKFLOW_REPL
|
|
|
211
176
|
- 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.
|
|
212
177
|
- Set `0` or `false` to replay the Node.js workflow from scratch in a fresh VM on every iteration.
|
|
213
178
|
|
|
214
|
-
### `WORKFLOW_INLINE_OWNERSHIP`
|
|
215
|
-
|
|
216
|
-
- Default: enabled
|
|
217
|
-
- Records which queue message owns each inline step execution, so a wake (hook resume, elapsed wait) that replays the run mid-step schedules a delayed backstop instead of immediately redispatching and reexecuting the step. See [Inline step message ownership](/docs/changelog/step-message-ownership).
|
|
218
|
-
- Set `0` or `false` to revert to the previous unconditional immediate re-dispatch.
|
|
219
|
-
|
|
220
179
|
### `WORKFLOW_INLINE_OWNERSHIP_LEASE_SECONDS`
|
|
221
180
|
|
|
222
181
|
- Default: `860`
|
|
@@ -231,9 +190,10 @@ For example, a workflow can run a 10-minute inline step even with `WORKFLOW_REPL
|
|
|
231
190
|
- Default: `node`
|
|
232
191
|
- Values: `node` or `quickjs`
|
|
233
192
|
- Selects the sandboxed VM engine that executes workflow functions (`"use workflow"`). Step functions are unaffected and always run with full Node.js access.
|
|
234
|
-
- `node` (default) runs workflow code in a [`node:vm`](https://nodejs.org/api/vm.html) context.
|
|
235
|
-
- `quickjs`
|
|
236
|
-
-
|
|
193
|
+
- `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).
|
|
194
|
+
- `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 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`.
|
|
195
|
+
- 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.
|
|
196
|
+
- 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:
|
|
237
197
|
- `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`.
|
|
238
198
|
- `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.
|
|
239
199
|
- `WebAssembly` and `Atomics` are not available.
|
|
@@ -253,7 +213,7 @@ For example, a workflow can run a 10-minute inline step even with `WORKFLOW_REPL
|
|
|
253
213
|
|
|
254
214
|
- Default: `1000` when the QuickJS engine is selected
|
|
255
215
|
- Values: non-negative integer. `0` disables snapshotting.
|
|
256
|
-
-
|
|
216
|
+
- 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).
|
|
257
217
|
- 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.
|
|
258
218
|
- 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.
|
|
259
219
|
- 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.
|
|
@@ -315,12 +275,7 @@ What a snapshot contains, and how it is protected:
|
|
|
315
275
|
|
|
316
276
|
## Transport
|
|
317
277
|
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
- Default: enabled
|
|
321
|
-
- On the Vercel World, lets concurrent event-log requests share one HTTP/2 connection instead of one connection per in-flight request.
|
|
322
|
-
- 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.
|
|
323
|
-
- Has no effect when `WORKFLOW_NODE_HTTP` is enabled, which takes the whole HTTP/2 path away.
|
|
278
|
+
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).
|
|
324
279
|
|
|
325
280
|
### `WORKFLOW_NODE_HTTP`
|
|
326
281
|
|
|
@@ -335,24 +290,9 @@ Node's own modules do less than the client they replace, so enabling this drops
|
|
|
335
290
|
- Requests lose their transport-level retry. Failures still surface to the layers above, which retry event writes and redeliver queue messages, so nothing is silently dropped, but a failure that a same-connection retry would have hidden now costs a full redelivery.
|
|
336
291
|
- Stream close loses its retry of retriable server errors. A transient failure at close can leave a stream marked closing until the run expires, where it would previously have resolved on the retry.
|
|
337
292
|
|
|
338
|
-
Connection pooling, keep-alive, and the request, header, and body deadlines are preserved. Node's agents configure pooling and keep-alive, and each request receives the deadlines from the Local World's two queue timeouts or the same defaults that the Vercel World's HTTP client currently applies. Queue sends are the partial exception: that client takes no transport override, so it cannot move to Node's modules. It does honor this variable, by dispatching through the runtime's own copy of the library rather than the copy the World bundles, which is the distinction that matters when the bundled copy is the thing that does not work.
|
|
293
|
+
Connection pooling, keep-alive, and the request, header, and body deadlines are preserved. Node's agents configure pooling and keep-alive, and each request receives the deadlines from the Local World's two queue timeouts or the same defaults that the Vercel World's HTTP client currently applies. Queue sends are the partial exception: that client takes no transport override, so it cannot move to Node's modules. It does honor this variable, by dispatching through the runtime's own copy of the library rather than the copy the World bundles, which is the distinction that matters when the bundled copy is the thing that does not work. That copy's global agent has no connection cap and only undici's default 300-second timeouts, so queue sends lose the queue client's own cap and deadline (30 seconds by default): [`WORKFLOW_VERCEL_QUEUE_CONNECTIONS`](/docs/configuration/worlds#workflow_vercel_queue_connections) and [`WORKFLOW_VERCEL_QUEUE_TIMEOUT_MS`](/docs/configuration/worlds#workflow_vercel_queue_timeout_ms) do not apply.
|
|
339
294
|
|
|
340
|
-
A `dispatcher` passed to `
|
|
341
|
-
|
|
342
|
-
### `WORKFLOW_VERCEL_QUEUE_TIMEOUT_MS`
|
|
343
|
-
|
|
344
|
-
- Default: `30000`
|
|
345
|
-
- Total deadline for one request the Vercel World's queue client makes, measured from the moment it is handed to the transport, so it also covers time the request spends waiting for a free connection.
|
|
346
|
-
- Clamped to `[5000, 120000]`.
|
|
347
|
-
- 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.
|
|
348
|
-
- 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.
|
|
349
|
-
|
|
350
|
-
### `WORKFLOW_VERCEL_QUEUE_CONNECTIONS`
|
|
351
|
-
|
|
352
|
-
- Default: `64`
|
|
353
|
-
- Connections the Vercel World's queue client may open to the queue service.
|
|
354
|
-
- Clamped to `[1, 1024]`.
|
|
355
|
-
- 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.
|
|
295
|
+
A `dispatcher` passed to `createWorld()` still wins over this variable. The variable chooses which transport the World builds when you have not supplied one.
|
|
356
296
|
|
|
357
297
|
## Queue namespace
|
|
358
298
|
|
|
@@ -442,13 +382,14 @@ These variables are primarily for tests, debugging, or unusual deployments.
|
|
|
442
382
|
|
|
443
383
|
## Spec 9 (experimental)
|
|
444
384
|
|
|
445
|
-
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.
|
|
385
|
+
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.
|
|
446
386
|
|
|
447
387
|
### `WORKFLOW_SPEC_VERSION`
|
|
448
388
|
|
|
449
|
-
- Default: unset. New runs use spec version 8
|
|
389
|
+
- Default: unset. New runs use spec version 8.
|
|
450
390
|
- `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.
|
|
451
|
-
-
|
|
391
|
+
- `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.
|
|
392
|
+
- 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.
|
|
452
393
|
|
|
453
394
|
### `WORKFLOW_ORCHESTRATOR_POLL_INTERVAL_MS`
|
|
454
395
|
|
|
@@ -463,7 +404,12 @@ Everything above describes spec 8 runs, the default. The experimental spec 9 run
|
|
|
463
404
|
### `WORKFLOW_ORCHESTRATOR_LINGER_MS`
|
|
464
405
|
|
|
465
406
|
- Default: `30000`
|
|
466
|
-
- How long an orchestrator with nothing left to run stays live on the event feed while the run waits on
|
|
407
|
+
- How long 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 too.
|
|
408
|
+
|
|
409
|
+
### `WORKFLOW_ORCHESTRATOR_HOOK_LINGER_MS`
|
|
410
|
+
|
|
411
|
+
- Default: `5000`, and never more than [`WORKFLOW_ORCHESTRATOR_LINGER_MS`](#workflow_orchestrator_linger_ms)
|
|
412
|
+
- How long an orchestrator with nothing left to run stays live on the event feed while the run waits only on open hooks. Any hook that is created and not disposed counts, however rarely it is resumed. `0` turns it off.
|
|
467
413
|
|
|
468
414
|
### `WORKFLOW_ORCHESTRATOR_READ_TIMEOUT_MS`
|
|
469
415
|
|
|
@@ -62,6 +62,7 @@ The Local World is the default outside Vercel and is intended for development.
|
|
|
62
62
|
- Environment variable: `WORKFLOW_LOCAL_DATA_DIR`
|
|
63
63
|
- Default: `.workflow-data`
|
|
64
64
|
- Directory where runs, steps, events, hooks, streams, and the local manifest are written.
|
|
65
|
+
- Also holds the app's queue key (`queue-auth-key`), which the CLI and web UI read to send deliveries, so point them at the same directory. See [`WORKFLOW_QUEUE_AUTH`](/worlds/local#workflow_queue_auth).
|
|
65
66
|
|
|
66
67
|
### `baseUrl`
|
|
67
68
|
|
|
@@ -106,6 +107,13 @@ The Local World is the default outside Vercel and is intended for development.
|
|
|
106
107
|
- Default: `true`
|
|
107
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.
|
|
108
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
|
+
|
|
109
117
|
### `WORKFLOW_LOCAL_HOOK_RETENTION_LIMIT_DAYS`
|
|
110
118
|
|
|
111
119
|
- Factory option: none
|
|
@@ -180,12 +188,11 @@ The Postgres World is a self-hosted durable backend for long-running server proc
|
|
|
180
188
|
### `jobLockStaleSeconds`
|
|
181
189
|
|
|
182
190
|
- Environment variable: `WORKFLOW_POSTGRES_JOB_LOCK_STALE_SECONDS`
|
|
183
|
-
- Default:
|
|
184
|
-
- Seconds a running delivery's job lock may go unrenewed before another process releases
|
|
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.
|
|
185
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.
|
|
186
|
-
- `0` leaves recovery to Graphile Worker's fixed 4 hour reset and to restarts.
|
|
187
|
-
-
|
|
188
|
-
- To turn it on, set the same value on every process that shares the database once all of them run a version that includes this option. See [Postgres World: `WORKFLOW_POSTGRES_JOB_LOCK_STALE_SECONDS`](/worlds/postgres#workflow_postgres_job_lock_stale_seconds).
|
|
194
|
+
- `0` turns renewal and release off, and leaves recovery to Graphile Worker's fixed 4 hour reset and to restarts.
|
|
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).
|
|
189
196
|
|
|
190
197
|
### `maxPoolSize`
|
|
191
198
|
|
|
@@ -193,6 +200,25 @@ The Postgres World is a self-hosted durable backend for long-running server proc
|
|
|
193
200
|
- Default: `pg` default
|
|
194
201
|
- Maximum size of the internal `pg.Pool` when the World creates the pool.
|
|
195
202
|
|
|
203
|
+
### `enableInvoke`
|
|
204
|
+
|
|
205
|
+
- Environment variable: `WORKFLOW_POSTGRES_INVOKE` (`1` enables)
|
|
206
|
+
- Default: `false`
|
|
207
|
+
- Experimental. Delivers hook resumes to the run's executor instead of writing the hook event and enqueueing a wake-up. Apply the migrations and upgrade producers and workers together before enabling it. See [experimental invocation delivery](/worlds/postgres#experimental-invocation-delivery).
|
|
208
|
+
|
|
209
|
+
### `WORKFLOW_POSTGRES_HEADERS_TIMEOUT_MS`
|
|
210
|
+
|
|
211
|
+
- Factory option: none
|
|
212
|
+
- Default: `0` (no deadline)
|
|
213
|
+
- Maximum time a queue delivery waits for the workflow handler to begin responding before it is failed and redelivered.
|
|
214
|
+
- A delivery runs the workflow inline, so a deadline shorter than your longest inline step redelivers a healthy delivery and runs its steps twice. See [`WORKFLOW_POSTGRES_HEADERS_TIMEOUT_MS`](/worlds/postgres#workflow_postgres_headers_timeout_ms).
|
|
215
|
+
|
|
216
|
+
### `WORKFLOW_POSTGRES_BODY_TIMEOUT_MS`
|
|
217
|
+
|
|
218
|
+
- Factory option: none
|
|
219
|
+
- Default: `0` (no deadline)
|
|
220
|
+
- Maximum gap between response body chunks from the workflow handler before the delivery is failed and redelivered. The same caution as `WORKFLOW_POSTGRES_HEADERS_TIMEOUT_MS` applies.
|
|
221
|
+
|
|
196
222
|
### `WORKFLOW_POSTGRES_HOOK_RETENTION_LIMIT_DAYS`
|
|
197
223
|
|
|
198
224
|
- Factory option: none
|
|
@@ -224,8 +250,8 @@ Platform-provided values such as `VERCEL_DEPLOYMENT_ID`, `VERCEL_PROJECT_ID`, an
|
|
|
224
250
|
|
|
225
251
|
### `token`
|
|
226
252
|
|
|
227
|
-
- Environment variable: `WORKFLOW_VERCEL_AUTH_TOKEN
|
|
228
|
-
- 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`
|
|
229
255
|
- Default: inferred when possible
|
|
230
256
|
- Vercel API token for external tooling. Keep it secret.
|
|
231
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`.
|
|
@@ -236,6 +262,7 @@ Platform-provided values such as `VERCEL_DEPLOYMENT_ID`, `VERCEL_PROJECT_ID`, an
|
|
|
236
262
|
- CLI flag: `--env` or `-e`
|
|
237
263
|
- Default: `production`
|
|
238
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.
|
|
239
266
|
|
|
240
267
|
### `projectConfig.projectId`
|
|
241
268
|
|
|
@@ -253,7 +280,7 @@ Platform-provided values such as `VERCEL_DEPLOYMENT_ID`, `VERCEL_PROJECT_ID`, an
|
|
|
253
280
|
|
|
254
281
|
### `WORKFLOW_VERCEL_PROJECT_NAME`
|
|
255
282
|
|
|
256
|
-
- Factory option:
|
|
283
|
+
- Factory option: `projectConfig.projectName`
|
|
257
284
|
- CLI flag: none
|
|
258
285
|
- Default: inferred when possible
|
|
259
286
|
- Project slug used for dashboard links.
|
|
@@ -266,19 +293,12 @@ Platform-provided values such as `VERCEL_DEPLOYMENT_ID`, `VERCEL_PROJECT_ID`, an
|
|
|
266
293
|
- Workflow API proxy URL for external tooling.
|
|
267
294
|
- The Vercel World doesn't follow HTTP redirects, so the URL must answer directly. A `3xx` response fails the request.
|
|
268
295
|
|
|
269
|
-
### `WORKFLOW_SEQUENTIAL_REPLAYS`
|
|
270
|
-
|
|
271
|
-
- Default: disabled
|
|
272
|
-
- 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.
|
|
273
|
-
- 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.
|
|
274
|
-
- 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.
|
|
275
|
-
|
|
276
296
|
### `VERCEL_WORKFLOW_SERVER_URL`
|
|
277
297
|
|
|
278
298
|
- Factory option: none
|
|
279
299
|
- CLI flag: none
|
|
280
300
|
- Default: unset
|
|
281
|
-
- Direct
|
|
301
|
+
- Direct Vercel World backend URL override for testing or custom infrastructure. Normal deployments do not need it.
|
|
282
302
|
|
|
283
303
|
### `VERCEL_QUEUE_MAX_DELAY_SECONDS`
|
|
284
304
|
|
|
@@ -296,16 +316,9 @@ Platform-provided values such as `VERCEL_DEPLOYMENT_ID`, `VERCEL_PROJECT_ID`, an
|
|
|
296
316
|
- CLI flag: none
|
|
297
317
|
- Default: `60000`
|
|
298
318
|
- Clamp: `10000` to `120000` (values outside are clamped, with a warning)
|
|
299
|
-
- Per-request timeout for Vercel World HTTP calls to
|
|
319
|
+
- Per-request timeout for Vercel World HTTP calls to its backend.
|
|
300
320
|
- At the `10000` floor the run-status long poll disables itself, because its budget is this value minus 10s of headroom.
|
|
301
321
|
|
|
302
|
-
### `WORKFLOW_MAX_CHUNKS_PER_REQUEST`
|
|
303
|
-
|
|
304
|
-
- Factory option: none
|
|
305
|
-
- CLI flag: none
|
|
306
|
-
- Default: `1000`
|
|
307
|
-
- Maximum stream chunks written in one Vercel World request. Larger batches are split.
|
|
308
|
-
|
|
309
322
|
### `WORKFLOW_STREAMS_TRANSPORT`
|
|
310
323
|
|
|
311
324
|
- Factory option: none
|
|
@@ -318,27 +331,12 @@ Platform-provided values such as `VERCEL_DEPLOYMENT_ID`, `VERCEL_PROJECT_ID`, an
|
|
|
318
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.
|
|
319
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.
|
|
320
333
|
|
|
321
|
-
### `WORKFLOW_DISABLE_ANALYTICS_READS`
|
|
322
|
-
|
|
323
|
-
- Factory option: none
|
|
324
|
-
- CLI flag: none
|
|
325
|
-
- Default: disabled
|
|
326
|
-
- 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.
|
|
327
|
-
|
|
328
|
-
### `WORKFLOW_BATCH_TRANSITIONS`
|
|
329
|
-
|
|
330
|
-
- Surface: environment variable
|
|
331
|
-
- Default: on
|
|
332
|
-
- Set to `0` (or `false`) to **disable** batched event writes, the escape hatch that restores the exact prior one-write-per-event path.
|
|
333
|
-
|
|
334
|
-
When enabled (the default), a suspension's eager `step_created` and `wait_created` writes fold into batched `events.createBatch` calls (one durable write with per-event outcomes) on Worlds that implement the optional batch API. The fold only engages when the World implements `events.createBatch` (the Vercel World does; Local and Postgres do not), the run's spec version supports slot identity (≥ 6), and the suspension carries no attribute writes. Hook writes in the same suspension go through the single-event path concurrently with the batch. Everything else keeps the single-event path unchanged, so disabling is only needed as an operational escape hatch. Batches are capped at 16 events; larger fan-outs commit in several batches at once. See the [batched event writes changelog](/docs/changelog/batched-event-writes) for the World API contract.
|
|
335
|
-
|
|
336
334
|
### `WORKFLOW_EVENTS_TRANSPORT`
|
|
337
335
|
|
|
338
336
|
- Factory option: none
|
|
339
337
|
- CLI flag: none
|
|
340
338
|
- Default: `ws`
|
|
341
|
-
- Ships workflow run events to the Vercel World over a WebSocket instead of one HTTP request each. Set to
|
|
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.
|
|
342
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.
|
|
343
341
|
|
|
344
342
|
### `WORKFLOW_EVENTS_TRANSPORT_WS_OVERRIDE_WORKFLOWS`
|
|
@@ -359,3 +357,34 @@ When enabled (the default), a suspension's eager `step_created` and `wait_create
|
|
|
359
357
|
- Largest WebSocket message the Vercel World sends, header included, for both the events and stream-write transports. The ceiling is the 16 MiB WebSocket message limit.
|
|
360
358
|
- Events: a larger frame is sent as several messages and rebuilt on the other side.
|
|
361
359
|
- Stream writes: a larger write group is split into several ordered write requests; a single chunk too large for one message is written over HTTP, as are the rest of that writer's writes.
|
|
360
|
+
|
|
361
|
+
### `WORKFLOW_H2_MULTIPLEX`
|
|
362
|
+
|
|
363
|
+
- Factory option: none
|
|
364
|
+
- CLI flag: none
|
|
365
|
+
- Default: enabled
|
|
366
|
+
- On the Vercel World, lets concurrent event-log requests share one HTTP/2 connection instead of one connection per in-flight request.
|
|
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.
|
|
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).
|
|
370
|
+
|
|
371
|
+
### `WORKFLOW_VERCEL_QUEUE_TIMEOUT_MS`
|
|
372
|
+
|
|
373
|
+
- Factory option: none
|
|
374
|
+
- CLI flag: none
|
|
375
|
+
- Default: `30000`
|
|
376
|
+
- Total deadline for one request the Vercel World's queue client makes, measured from the moment it is handed to the transport, so it also covers time the request spends waiting for a free connection.
|
|
377
|
+
- Clamped to `[5000, 120000]`.
|
|
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.
|
|
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).
|
|
381
|
+
|
|
382
|
+
### `WORKFLOW_VERCEL_QUEUE_CONNECTIONS`
|
|
383
|
+
|
|
384
|
+
- Factory option: none
|
|
385
|
+
- CLI flag: none
|
|
386
|
+
- Default: `64`
|
|
387
|
+
- Connections the Vercel World's queue client may open to the queue service.
|
|
388
|
+
- Clamped to `[1, 1024]`.
|
|
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).
|
|
@@ -67,9 +67,9 @@ export async function processDocumentBatch(documentIds: string[]) {
|
|
|
67
67
|
Awaiting `returnValue` of a run the workflow started does not poll. The SDK waits on a **system hook**, the same handshake you would otherwise write by hand, but with one hook for the whole parent rather than one per child:
|
|
68
68
|
|
|
69
69
|
1. `start()` records the parent's run ID on the child, and remembers the parent on the returned `Run`.
|
|
70
|
-
2. When the parent awaits a child, it registers its completion hook (a system hook whose token is derived from the parent's run ID)
|
|
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.
|
|
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
|
|
|
@@ -244,7 +244,7 @@ export async function reviewDocument(documentId: string) {
|
|
|
244
244
|
|
|
245
245
|
## Tips
|
|
246
246
|
|
|
247
|
-
- **Await only the children you need**:
|
|
247
|
+
- **Await only the children you need**: Until the parent first awaits a child's `returnValue`, it has no completion hook open, so a child that finishes costs one extra hook lookup and nothing in the parent. Once the parent has awaited a child, the hook stays open for the rest of the run, so every child that finishes afterwards adds a notification to the parent's log and wakes it, including children it never awaits and children that finish between waits. If a parent starts many children it never waits for, start them from an intermediate run that does not await any child, so their completions do not wake the parent.
|
|
248
248
|
- **Use chunked spawning for large batches**: Starting 500 children at once can create a large burst of work. Break the work into chunks of 10–50.
|
|
249
249
|
- **Watch the parent's log too**: The parent records events for spawning and collecting every child (the spawn step, the child's notification on the parent's completion hook, and the step that reads its result). On the default runtime, count those events against the parent's [event limit](/worlds/vercel#per-run-limits) and consider another layer of intermediate runs if needed. QuickJS with snapshotting reduces replay overhead and exempts eligible parent runs from the default event cap, but does not reduce their event count or remove payload and storage limits.
|
|
250
250
|
- **Account for each child's retry semantics**: Steps inside child workflows retry independently. The parent only sees the child's final result or error.
|
|
@@ -159,7 +159,7 @@ Approval requests arrive as typed tool parts with `state: "approval-requested"`.
|
|
|
159
159
|
"use client";
|
|
160
160
|
|
|
161
161
|
import { useChat } from "@ai-sdk/react";
|
|
162
|
-
import { WorkflowChatTransport } from "@ai-sdk/workflow";
|
|
162
|
+
import { WorkflowChatTransport } from "@ai-sdk/workflow/client";
|
|
163
163
|
import { lastAssistantMessageIsCompleteWithApprovalResponses } from "ai";
|
|
164
164
|
import { useMemo } from "react";
|
|
165
165
|
import type { BookingAgentUIMessage } from "@/workflows/booking-agent";
|
|
@@ -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
|
-
- **
|
|
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.
|
|
@@ -17,7 +17,7 @@ related:
|
|
|
17
17
|
|
|
18
18
|
[AI SDK](https://ai-sdk.dev/) is Vercel's framework-agnostic TypeScript toolkit for building AI-powered apps and agents. It provides unified provider access, streaming, tool calling, structured output, and UI hooks. Workflow SDK makes the multi-turn loop durable, so the conversation state, hooks, and per-turn responses survive restarts and timeouts. In this pattern, the durability boundary is the entire turn, and individual tool calls inside a turn are **not** durable on their own (see [Pitfalls](#tools-are-not-individually-durable)).
|
|
19
19
|
|
|
20
|
-
For the full AI SDK reference, including providers, `streamText`, `
|
|
20
|
+
For the full AI SDK reference, including providers, `streamText`, structured output with `Output.object`, `useChat`, and tool calling, see the [AI SDK docs](https://ai-sdk.dev/docs). This page covers the Workflow-specific integration points.
|
|
21
21
|
|
|
22
22
|
<Callout type="info">
|
|
23
23
|
For most agent use cases, prefer AI SDK's [`WorkflowAgent`](https://ai-sdk.dev/v7/docs/agents/workflow-agent#workflowagent), which implements the same agent loop as [`streamText`](https://ai-sdk.dev/docs/reference/ai-sdk-core/stream-text), manages tool calling automatically, and runs tools at workflow scope: each tool can be marked `"use step"` for per-call durability and retries, or stay at workflow level to use primitives like `sleep()` and hooks. Use this page's raw `streamText()` pattern when you want the exact AI SDK API (for example `toUIMessageStream()`, `onChunk`, or `generateText`), or when the durability boundary should be an entire user turn in one step, accepting that tool calls inside that turn are not individually durable.
|
|
@@ -256,7 +256,7 @@ Store the `runId` in a ref and pass it in the body of every follow-up. `Workflow
|
|
|
256
256
|
"use client";
|
|
257
257
|
|
|
258
258
|
import { useChat } from "@ai-sdk/react";
|
|
259
|
-
import { WorkflowChatTransport } from "@ai-sdk/workflow";
|
|
259
|
+
import { WorkflowChatTransport } from "@ai-sdk/workflow/client";
|
|
260
260
|
import { useMemo, useRef, useState } from "react";
|
|
261
261
|
|
|
262
262
|
export function SupportChat() {
|
|
@@ -49,7 +49,7 @@ Common scenarios that produce this error:
|
|
|
49
49
|
|
|
50
50
|
- **An unclaimed event that repeats nothing**: A duplicate of a kind the log already records for that entity is read past rather than failing the run, so a second `step_completed` or `wait_completed` is not this error (see [Duplicate Events](/docs/how-it-works/event-sourcing#duplicate-events)). What fails is an unclaimed event with no earlier counterpart to defer to: a `step_started` behind a `step_completed` on a log that never recorded a `step_started`, for instance. No consumer remains for the step, and there is no earlier event of that kind the replay could be reading instead.
|
|
51
51
|
- **Orphaned events**: A `step_completed` or `wait_completed` event whose `correlationId` doesn't match any step or sleep in the workflow code, so the replay reaches its end still holding it.
|
|
52
|
-
- **A hole in the log**: Events are numbered by their position in the run's log, and those positions are dense, so a position below the log's highest that holds no event means the log the replay loaded is incomplete. The runtime cannot tell a position no write ever occupied from one whose event it failed to read, so it refuses to replay rather than produce a result that may be silently wrong.
|
|
52
|
+
- **A hole in the log**: Events are numbered by their position in the run's log, and those positions are dense, so a position below the log's highest that holds no event means the log the replay loaded is incomplete. The runtime cannot tell a position no write ever occupied from one whose event it failed to read, so it refuses to replay rather than produce a result that may be silently wrong.
|
|
53
53
|
- **An unreadable stored payload**: An event row still references a payload object, but the World reports that the object no longer exists in its storage. The same log would fail on every replay, so the run fails immediately instead of retrying forever.
|
|
54
54
|
|
|
55
55
|
## What to do
|
|
@@ -74,7 +74,7 @@ Any number of runs can force the same token at once without leaving the token or
|
|
|
74
74
|
|
|
75
75
|
## Runs that cannot be taken from
|
|
76
76
|
|
|
77
|
-
A run that was started at a Workflow spec version below 8 (an older SDK release, a Python SDK run, or a deployment with `
|
|
77
|
+
A run that was started at a Workflow spec version below 8 (an older SDK release, a Python SDK run, or a deployment with `WORKFLOW_SPEC_VERSION` set below 8) would never learn that its hook was disposed. The World declines to take its token: the forced hook rejects with the ordinary [`HookConflictError`](/docs/errors/hook-conflict), whose `conflictingRunId` names that run, and the run keeps receiving its payloads. Handle it like any other conflict, for example by [delegating to the active run](/docs/errors/hook-conflict#delegate-to-the-active-run). A finished run holding a retained token is taken over at any version.
|
|
78
78
|
|
|
79
79
|
## Deciding who takes over
|
|
80
80
|
|