workflow 5.4.0 → 5.5.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/observability.d.ts +1 -1
- package/dist/observability.d.ts.map +1 -1
- package/dist/observability.js +2 -2
- 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-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/storage.mdx +1 -2
- package/docs/changelog/attributes-mvp.mdx +1 -1
- package/docs/changelog/batched-event-writes.mdx +0 -2
- package/docs/changelog/eager-processing.mdx +1 -1
- package/docs/changelog/lazy-event-creation.md +1 -1
- package/docs/changelog/spec-9.mdx +268 -120
- package/docs/changelog/step-message-ownership.mdx +2 -7
- package/docs/configuration/build-and-diagnostics.mdx +2 -0
- package/docs/configuration/cli-and-web-ui.mdx +9 -0
- package/docs/configuration/framework-options.mdx +7 -0
- package/docs/configuration/runtime-tuning.mdx +22 -77
- package/docs/configuration/worlds.mdx +54 -22
- package/docs/cookbook/advanced/child-workflows.mdx +3 -3
- package/docs/cookbook/agent-patterns/human-in-the-loop.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/runtime-decryption-failed.mdx +1 -1
- package/docs/foundations/errors-and-retries.mdx +3 -1
- package/docs/foundations/serialization.mdx +80 -0
- package/docs/getting-started/next.mdx +2 -0
- package/docs/how-it-works/event-sourcing.mdx +2 -2
- package/docs/observability/index.mdx +2 -0
- package/docs/whats-new.mdx +3 -3
- package/docs/worlds/building-a-world.mdx +18 -3
- package/docs/worlds/local.mdx +11 -7
- package/docs/worlds/postgres.mdx +10 -13
- package/docs/worlds/upgrading-to-v5.mdx +2 -2
- package/docs/worlds/vercel.mdx +10 -5
- package/package.json +14 -14
|
@@ -65,6 +65,8 @@ npx workflow inspect run <run_id> --backend vercel --url
|
|
|
65
65
|
The Workflow SDK CLI can inspect data from any [World](/docs/deploying). By default, it inspects data in your local development environment. For example, if you are using Next.js to develop workflows locally, the
|
|
66
66
|
CLI will find the data in your `.next/workflow-data/` directory.
|
|
67
67
|
|
|
68
|
+
On the Local World, the CLI and web UI also read the app's queue key from that directory and send it with every delivery to the app, for example when they start or recreate a run. Run them from the app's project directory (or set `WORKFLOW_LOCAL_DATA_DIR` to the app's data directory), and keep them on the same release as the app's `@workflow/world-local`. See [`WORKFLOW_QUEUE_AUTH`](/worlds/local#workflow_queue_auth).
|
|
69
|
+
|
|
68
70
|
If you're deploying workflows to a production environment, but want to inspect the data by using the CLI, you can specify the world you are using by setting the `--backend` flag to your world's name or package name, e.g. `vercel`.
|
|
69
71
|
|
|
70
72
|
<Callout>
|
package/docs/whats-new.mdx
CHANGED
|
@@ -48,9 +48,9 @@ The largest change in v5 has no API surface: the runtime does far less work per
|
|
|
48
48
|
|
|
49
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).
|
|
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
|
|
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).
|
|
52
52
|
|
|
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; [`
|
|
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
|
|
|
55
55
|
**Payloads are compressed** before they are encrypted and sent to the API. Repetitive payloads compress heavily; AI token streams average around 80% smaller. That is less stored data and less to move over the network.
|
|
56
56
|
|
|
@@ -188,7 +188,7 @@ All three first-party Worlds now implement it: Vercel accepts up to 30 days, and
|
|
|
188
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)).
|
|
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
|
-
- **`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.
|
|
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).
|
|
192
192
|
- **An event arriving mid-replay no longer fails the run.** A hook resume or step completion landing while a replay is in flight used to be able to fail it with [`CORRUPTED_EVENT_LOG`](/docs/errors/corrupted-event-log). Writes now come back with the events the replay had not seen, and the event is held for whichever part of the workflow awaits it. A run only fails when the log is genuinely missing a position.
|
|
193
193
|
|
|
194
194
|
## Breaking changes
|
|
@@ -99,9 +99,9 @@ export function createWorld(): World {
|
|
|
99
99
|
|
|
100
100
|
The runtime checks this before it creates or replays anything and throws if the version is outside the range it supports, naming both the range and what your World declared. A version below the range means your World allocates event IDs the runtime cannot read positions out of; above it means your World speaks a protocol this runtime has not learned.
|
|
101
101
|
|
|
102
|
-
`mintedSpecVersion()` returns the current spec version, or the
|
|
102
|
+
`mintedSpecVersion()` returns the current spec version, or the version [`WORKFLOW_SPEC_VERSION`](/docs/configuration/runtime-tuning#workflow_spec_version) selects. Call it inside `createWorld()` so a process can create Worlds with different settings. It reads `process.env` by default; in a host without `process`, such as a browser, pass the environment as its argument.
|
|
103
103
|
|
|
104
|
-
Calling it keeps the check passing across upgrades. It moves with the `@workflow/world` version your package resolves, so a spec bump raises your declaration and the runtime's requirement together. A hard-coded number, or `SPEC_VERSION_CURRENT`, which does not follow `
|
|
104
|
+
Calling it keeps the check passing across upgrades. It moves with the `@workflow/world` version your package resolves, so a spec bump raises your declaration and the runtime's requirement together. A hard-coded number, or `SPEC_VERSION_CURRENT`, which does not follow `WORKFLOW_SPEC_VERSION`, leaves your World out of step. Keep `@workflow/world` in the same release channel as the `workflow` version your users install. See [Spec versions](/worlds/upgrading-to-v5#spec-versions) for what each version requires of a World.
|
|
105
105
|
|
|
106
106
|
## The event log model
|
|
107
107
|
|
|
@@ -236,7 +236,7 @@ Spec version 7 supports one alternative to allocate-at-commit for Worlds whose s
|
|
|
236
236
|
|
|
237
237
|
The runtime skips `noop` events during replay. It never delivers them to a consumer or uses them to advance the deterministic clock, so a sealed log replays identically to one whose writers filled the holes. `noop` isn't user-creatable and is never sent to `events.create()`. Only your read path may write one. Worlds that allocate at the commit, through a synchronous counter or unique-constraint append, maintain perfect density and don't need sealing. `world-local` and `world-postgres` never seal, and a World that allocates at the commit is spec 7 compliant without additional work.
|
|
238
238
|
|
|
239
|
-
The version a World stamps comes from `mintedSpecVersion()`: 8 by default or the
|
|
239
|
+
The version a World stamps comes from `mintedSpecVersion()`: 8 by default, or the version [`WORKFLOW_SPEC_VERSION`](/docs/configuration/runtime-tuning#workflow_spec_version) selects, such as the slot-identity version (6). Declare `mintedSpecVersion()` instead of a literal so your World moves with the fleet. A runtime other than the one that created a spec 7 run may read it, so readers must understand `noop` before anything stamps 7 in that environment.
|
|
240
240
|
|
|
241
241
|
`events.create()` params carry `eventCount`: how many events the writer held in the log it replayed from, which is the position it expects to land on minus one. Attempt `eventCount + 1`. When that position is taken, **do not reject the write**. Advance to the next free position, commit there, and return the events occupying the positions you skipped over on the success response, in `events` with a matching `cursor` and `hasMore`. The writer merges them into its own log and replays once, rather than paying a second round trip to discover it was behind. A caller with a stale count is the normal case for a fan-out, and rejecting it would serialize writes the runtime issues in parallel.
|
|
242
242
|
|
|
@@ -321,6 +321,10 @@ The Queue interface handles asynchronous workflow execution, including queued st
|
|
|
321
321
|
interface Queue {
|
|
322
322
|
getDeploymentId(): Promise<string>;
|
|
323
323
|
|
|
324
|
+
// How the runtime authenticates deliveries to the flow route. Optional:
|
|
325
|
+
// omitted means not checked. Required in SDK v6.
|
|
326
|
+
queueAuthMode?: 'loopback' | 'skip';
|
|
327
|
+
|
|
324
328
|
queue(
|
|
325
329
|
queueName: ValidQueueName,
|
|
326
330
|
message: QueuePayload,
|
|
@@ -354,6 +358,17 @@ interface Queue {
|
|
|
354
358
|
|
|
355
359
|
`meta.messageId` should be stable across redeliveries of one message. The optional `meta.deliveryCount` is 1 on a message's first delivery and increments on every redelivery; leave it `undefined` when your queue cannot say. The optional `meta.createdAt` is when the message was first enqueued, unchanged across its redeliveries.
|
|
356
360
|
|
|
361
|
+
### Authenticating deliveries
|
|
362
|
+
|
|
363
|
+
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
|
+
- `'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
|
+
- `'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
|
+
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.
|
|
369
|
+
|
|
370
|
+
The runtime's `401` is marked: it carries the `x-workflow-auth-refused: 1` header (`QUEUE_AUTH_REFUSED_HEADER`) and `"code": "QUEUE_AUTH_REFUSED"` in its JSON body. A refused delivery carried a key other than the route's, for example one from before another process of the app wrote a new key. A queue that sees the marker (`isQueueAuthRefusal(response)` from `@workflow/utils`) should reload its key and retry at once if it changed, and otherwise retry a few times with a short backoff, then give the message up and log it once, rather than retry it for hours. A refused delivery reached no handler and touched no run, so retrying is safe, and it should not count as an attempt. `@workflow/world-local` gives up after 5 refusals its reload did not fix; a refusal followed by a new key is retried at once without counting, up to 16 times per message, after which it counts like any other. A `401` without the marker comes from something else in front of the app, such as a proxy, so keep retrying that one.
|
|
371
|
+
|
|
357
372
|
### Queue prefixes and delivery routes
|
|
358
373
|
|
|
359
374
|
A queue name is a prefix followed by an id. The Workflow SDK uses the prefix `__wkf_workflow_`, or `__{namespace}_wkf_workflow_` when a queue namespace is set. A library that keeps its own runs in a World and consumes its own messages, such as a durable agent harness, uses a namespace of its own (`__agent_wkf_workflow_session`) so that its messages never reach the Workflow SDK's handler, and the Workflow SDK's never reach it.
|
package/docs/worlds/local.mdx
CHANGED
|
@@ -54,6 +54,14 @@ Full base URL override for HTTPS or custom hostnames. Default: `http://localhost
|
|
|
54
54
|
|
|
55
55
|
Port resolution priority: `baseUrl` > `port` > `PORT` > auto-detected
|
|
56
56
|
|
|
57
|
+
### `WORKFLOW_QUEUE_AUTH`
|
|
58
|
+
|
|
59
|
+
Whether the flow route accepts only deliveries sent by the app's own processes. Default: `on`. Every delivery carries the app's queue key, and the route refuses a request without it with a `401` and touches no run.
|
|
60
|
+
|
|
61
|
+
The key is a random value in the file `queue-auth-key` in the [data directory](#data-directory-layout). The app writes a new one each time it starts, when it first uses its World and before it sends anything, so a restart needs no wait. A script that calls `start()` with the same data directory writes a new key the same way, and the app accepts it. The CLI and the web UI only read the key, so point them at the app's data directory (`WORKFLOW_LOCAL_DATA_DIR`). Several app processes on one data directory (PM2 with `-i N`, `node:cluster`, Nitro's `node-cluster` preset) end up on the newest key in the file.
|
|
62
|
+
|
|
63
|
+
A refused delivery is retried at once when the key in the file has changed, and otherwise a few times with a short backoff, then logged once and given up; its run is left as it was. Keep the CLI and the web UI on the same release as the app's `@workflow/world-local`: an older one sends no key. Set `off` on the app to accept deliveries from a process that cannot read its data directory, on a trusted machine only. `off` is refused while dynamic workflows are enabled. See [`WORKFLOW_QUEUE_AUTH`](/docs/configuration/runtime-tuning#workflow_queue_auth).
|
|
64
|
+
|
|
57
65
|
### `WORKFLOW_LOCAL_QUEUE_CONCURRENCY`
|
|
58
66
|
|
|
59
67
|
Maximum number of concurrent queue message handlers. Default: `1000`
|
|
@@ -62,12 +70,6 @@ Maximum number of concurrent queue message handlers. Default: `1000`
|
|
|
62
70
|
|
|
63
71
|
Maximum number of seconds a local queue message can stay hidden before the handler rechecks the run. Default: unlimited.
|
|
64
72
|
|
|
65
|
-
### `WORKFLOW_LOCAL_RUN_STATUS_POLL_INTERVAL_MS`
|
|
66
|
-
|
|
67
|
-
How often a wait for a terminal run status re-reads the run file, in milliseconds. Default: `100`.
|
|
68
|
-
|
|
69
|
-
`await run.returnValue` asks the World to wait for the run to finish. When the run and the caller share a process (the usual development server case), an in-process signal resolves the wait as soon as the run ends, and this interval never comes into play. The interval covers activity the signal cannot detect, primarily a second process awaiting a run over the same data directory, so it is set far below Workflow's own polling interval.
|
|
70
|
-
|
|
71
73
|
### `WORKFLOW_LOCAL_HEADERS_TIMEOUT_MS`
|
|
72
74
|
|
|
73
75
|
Maximum time in milliseconds to wait for a local queue handler to begin responding before redelivering the durable message. Default: `0` (no deadline).
|
|
@@ -151,6 +153,8 @@ Each run's event and step files are stored in their own directory (`events/<runI
|
|
|
151
153
|
|
|
152
154
|
A directory that mixes both layouts, or holds `.json` files in `events/` or `steps/` that the World did not write, is never deleted: starting fails with a `DataDirLayoutError` that lists the files.
|
|
153
155
|
|
|
156
|
+
The data directory also holds the app's queue key, `queue-auth-key` (see [`WORKFLOW_QUEUE_AUTH`](#workflow_queue_auth)). The file is readable and writable only by its owner (mode `0600`); Windows does not enforce that mode the same way, and the file gets the directory's permissions. The World writes a `.gitignore` containing `*` into the data directory when it has none, so neither the key nor the run data is committed, and never replaces one that is already there.
|
|
157
|
+
|
|
154
158
|
## Limitations
|
|
155
159
|
|
|
156
160
|
The Local World is designed for development, not production:
|
|
@@ -158,6 +162,6 @@ The Local World is designed for development, not production:
|
|
|
158
162
|
- **In-memory queue**: Workflow messages, including queued step invocations, do not persist across server restarts.
|
|
159
163
|
- **Filesystem storage**: Data is stored in local JSON files.
|
|
160
164
|
- **Single instance**: The Local World cannot handle distributed deployments.
|
|
161
|
-
- **
|
|
165
|
+
- **Minimal authentication**: The flow route accepts only deliveries carrying the app's queue key (see [`WORKFLOW_QUEUE_AUTH`](#workflow_queue_auth)), but nothing else is authenticated. Anyone who can read the data directory can read the key. The Local World is suitable only for local development.
|
|
162
166
|
|
|
163
167
|
For production deployments, use the [Vercel World](/worlds/vercel), which handles execution, persistence, multi-tenancy, scale, observability, and security for you on Vercel, or check out the [Postgres World](/worlds/postgres) - a tested reference implementation that implements the complete World spec and can be used to deploy workflows anywhere.
|
package/docs/worlds/postgres.mdx
CHANGED
|
@@ -232,6 +232,8 @@ Unlike the [Vercel World](/worlds/vercel), which authenticates and [encrypts](/d
|
|
|
232
232
|
|
|
233
233
|
`POST /.well-known/workflow/v1/flow` is where the worker delivers workflow orchestration and queued step invocations. It is mounted in your application like any other route, so it is publicly reachable by default, and it accepts any request whose headers and body are well-formed: there is no signature, shared secret, or caller check. Anyone who can reach it can forge or replay a workflow or step invocation, including steps your application would only reach after its own gating. Restrict it before you expose the app.
|
|
234
234
|
|
|
235
|
+
The runtime does not check deliveries to this route with a [queue key](/worlds/building-a-world#authenticating-deliveries): the Postgres World declares `queueAuthMode: 'skip'` until its messages are delivered in-process and the route is denied ([#5258](https://github.com/vercel/workflow/issues/5258)).
|
|
236
|
+
|
|
235
237
|
The other routes under `/.well-known/workflow/v1/` differ:
|
|
236
238
|
|
|
237
239
|
- `webhook/:token`, created by [`createWebhook()`](/docs/api-reference/workflow/create-webhook), is authorized by the token in the URL and nothing else. Use [`createHook()`](/docs/api-reference/workflow/create-hook) behind your own authenticated route and [`resumeHook()`](/docs/api-reference/workflow-api/resume-hook) when you need more than that.
|
|
@@ -285,10 +287,9 @@ The defaults work for a single process on a local database, so most apps set onl
|
|
|
285
287
|
| [`WORKFLOW_POSTGRES_POLL_INTERVAL_MS`](#workflow_postgres_poll_interval_ms) | `500` ms | Idle job polling |
|
|
286
288
|
| [`WORKFLOW_POSTGRES_MAX_POOL_SIZE`](#workflow_postgres_max_pool_size) | `10` | Connection pool size |
|
|
287
289
|
| [`WORKFLOW_POSTGRES_APPLICATION_MANAGED_SHUTDOWN`](#workflow_postgres_application_managed_shutdown) | off | Who coordinates shutdown |
|
|
288
|
-
| [`WORKFLOW_POSTGRES_RUN_STATUS_POLL_INTERVAL_MS`](#workflow_postgres_run_status_poll_interval_ms) | `1000` ms | Backstop for `await run.returnValue` |
|
|
289
290
|
| [`WORKFLOW_POSTGRES_HEADERS_TIMEOUT_MS`](#workflow_postgres_headers_timeout_ms) | `0` ms (no deadline) | Hung delivery detection |
|
|
290
291
|
| [`WORKFLOW_POSTGRES_BODY_TIMEOUT_MS`](#workflow_postgres_body_timeout_ms) | `0` ms (no deadline) | Stalled response detection |
|
|
291
|
-
| [`WORKFLOW_POSTGRES_JOB_LOCK_STALE_SECONDS`](#workflow_postgres_job_lock_stale_seconds) |
|
|
292
|
+
| [`WORKFLOW_POSTGRES_JOB_LOCK_STALE_SECONDS`](#workflow_postgres_job_lock_stale_seconds) | unset: 300 s for spec 9 named queues only | Redelivery after a process dies |
|
|
292
293
|
| [`WORKFLOW_POSTGRES_HOOK_RETENTION_LIMIT_DAYS`](#workflow_postgres_hook_retention_limit_days) | `30` days | Maximum hook retention |
|
|
293
294
|
| [`WORKFLOW_QUEUE_NAMESPACE`](#workflow_queue_namespace) | unset | Queue topic namespace |
|
|
294
295
|
| [`WORKFLOW_STREAM_FLUSH_INTERVAL_MS`](#workflow_stream_flush_interval_ms) | `0` ms | Stream write batching |
|
|
@@ -331,12 +332,6 @@ For higher worker concurrency, Graphile Worker recommends setting `maxPoolSize`
|
|
|
331
332
|
|
|
332
333
|
Set to `1` when the application or framework coordinates shutdown and awaits `world.close()` before closing its workflow HTTP server and any caller-owned pool. Default: unset (`false`).
|
|
333
334
|
|
|
334
|
-
### `WORKFLOW_POSTGRES_RUN_STATUS_POLL_INTERVAL_MS`
|
|
335
|
-
|
|
336
|
-
How often a wait for a terminal run status re-reads the run, in milliseconds. Default: `1000`.
|
|
337
|
-
|
|
338
|
-
`await run.returnValue` asks the World to wait for the run to finish, and the Postgres World parks that wait on a `NOTIFY` issued by the run-terminal write. This interval is only the backstop: it bounds how long a lost notification can go unnoticed, so lowering it costs a query per waiting run per interval and buys nothing while notifications are arriving.
|
|
339
|
-
|
|
340
335
|
### `WORKFLOW_POSTGRES_HEADERS_TIMEOUT_MS`
|
|
341
336
|
|
|
342
337
|
Maximum time in milliseconds a queue delivery waits for the workflow handler to begin responding before the delivery is failed and Graphile Worker redelivers the message. Default: `0` (no deadline).
|
|
@@ -349,15 +344,17 @@ Maximum gap in milliseconds between response body chunks from the workflow handl
|
|
|
349
344
|
|
|
350
345
|
### `WORKFLOW_POSTGRES_JOB_LOCK_STALE_SECONDS`
|
|
351
346
|
|
|
352
|
-
Seconds a running delivery's job lock may go unrenewed before another process releases the job for redelivery. Default:
|
|
347
|
+
Seconds a running delivery's job lock may go unrenewed before another process releases the job for redelivery. Default: unset (see below). `30` is a good value when more than one process shares the database. Programmatic option: `jobLockStaleSeconds`.
|
|
348
|
+
|
|
349
|
+
A running delivery renews its lock every quarter of the window, and at least every 10 seconds. When a process dies mid-delivery, another process redelivers its jobs within about one and a half windows (about 45 seconds at `30`), instead of after Graphile Worker's fixed 4 hour stale-lock reset or the next restart.
|
|
353
350
|
|
|
354
|
-
|
|
351
|
+
Unset, every delivery still renews its lock, and its worker registers as renewing in `workflow.workflow_job_lock_holders` (migration 0030, which `bootstrap` applies). Then only the jobs of a spec 9 run's named queue (its orchestrator deliveries, and invoke mode's executor lane) are released, after 300 seconds unrenewed, and only those whose holder registered. A spec 9 run whose worker was killed therefore continues within about 8 minutes (one and a half windows) instead of 4 hours. A job held by a process on an earlier version, which does not register, is never released this way, so the default is safe during a rolling upgrade. `0` turns renewal and release off.
|
|
355
352
|
|
|
356
353
|
Use the same value on every process that shares the database, and keep it well above the longest a process can go without running its timers (synchronous work that blocks the event loop) or getting a pool connection. A delivery whose renewals stall past the window is redelivered while it still runs.
|
|
357
354
|
|
|
358
|
-
|
|
355
|
+
Setting it releases every job of this World, whoever holds it, so set it only after a rolling upgrade has finished. A process on an earlier version doesn't renew its locks, so a process that has this set would redeliver any of that process's deliveries that run longer than the window. When the earlier-version process then finishes such a delivery, its acknowledgement, which isn't fenced on the lock holder, can delete the redelivered job's row, and the redelivery loses its retry.
|
|
359
356
|
|
|
360
|
-
To
|
|
357
|
+
To set it, use `WORKFLOW_POSTGRES_JOB_LOCK_STALE_SECONDS=30` (or `jobLockStaleSeconds: 30`) on every process that shares the database, once all of them run a version that includes this option.
|
|
361
358
|
|
|
362
359
|
### `WORKFLOW_POSTGRES_HOOK_RETENTION_LIMIT_DAYS`
|
|
363
360
|
|
|
@@ -490,7 +487,7 @@ The Postgres World uses PostgreSQL as a durable backend:
|
|
|
490
487
|
|
|
491
488
|
- **Storage**: Workflow runs, events, steps, and hooks are stored in PostgreSQL tables.
|
|
492
489
|
- **Job queue**: [graphile-worker](https://github.com/graphile/worker) handles reliable job processing with retries.
|
|
493
|
-
- **Crash recovery**: The next `start()` re-enqueues active runs.
|
|
490
|
+
- **Crash recovery**: The next `start()` re-enqueues active runs. A running delivery also renews its job lock. If its process dies, any other process redelivers a spec 9 run's orchestrator job once its lock has gone unrenewed for 300 seconds, and with [`WORKFLOW_POSTGRES_JOB_LOCK_STALE_SECONDS`](#workflow_postgres_job_lock_stale_seconds) set, any job of this World once its lock has gone unrenewed for that many seconds.
|
|
494
491
|
- **Streaming**: PostgreSQL NOTIFY/LISTEN enables real-time event distribution. If the database drops the `LISTEN` connection, the World reconnects every second and re-reads persisted chunks for open stream readers, so readers don't miss chunks written during the outage.
|
|
495
492
|
|
|
496
493
|
This architecture ensures workflows survive application restarts with all state reliably persisted. For implementation details, see the [source code](https://github.com/vercel/workflow/tree/main/packages/world-postgres).
|
|
@@ -52,7 +52,7 @@ export function createWorld(): World {
|
|
|
52
52
|
|
|
53
53
|
In v4 the runtime required that number to equal its own current version exactly. In v5 it checks the declaration against a range before it creates or replays anything, and refuses a World outside it with an error naming both the range and what your World declared. The floor is the version that introduced [slot-numbered event IDs](#event-id-allocation), because a World below it allocates IDs the runtime cannot read positions out of, and admitting one would only move the failure from startup into the middle of a run. The ceiling is the highest version this runtime can read.
|
|
54
54
|
|
|
55
|
-
`mintedSpecVersion()` is a function rather than a constant because the version a World stamps is a deployment-level choice. It answers with the sealed-log version by default, and with the
|
|
55
|
+
`mintedSpecVersion()` is a function rather than a constant because the version a World stamps is a deployment-level choice. It answers with the sealed-log version by default, and with the version [`WORKFLOW_SPEC_VERSION`](/docs/configuration/runtime-tuning#workflow_spec_version) selects, such as the slot-identity version (6), when that is set. Every version it accepts sits inside the accepted range, so any answer is a valid declaration. Reading it per `createWorld()` call rather than once at module load is what lets a single process create Worlds with different settings.
|
|
56
56
|
|
|
57
57
|
Calling it is also what keeps the check passing across upgrades, since it moves with the `@workflow/world` version your package resolves. A hard-coded number leaves your World a version behind the next bump and gets it rejected by the runtime it ships alongside. That includes the constants: `SPEC_VERSION_CURRENT` and `SPEC_VERSION_SUPPORTS_SLOT_IDENTITY` are literals by another name for this purpose, since neither follows the sealed-log setting. Keep `@workflow/world` in the same release channel as the `workflow` version your users install.
|
|
58
58
|
|
|
@@ -63,7 +63,7 @@ The sealed-log version exists for a World whose store makes allocating a positio
|
|
|
63
63
|
Two consequences for an implementation:
|
|
64
64
|
|
|
65
65
|
- **If you allocate at the commit, you are already compliant** and have nothing to build. No write can leave a position empty, so you have no holes to seal and will never emit a `noop`. `@workflow/world-local` and `@workflow/world-postgres` are in this position.
|
|
66
|
-
- **What the version actually gates is the reader.** A run stamped at the sealed-log version can only be replayed by a reader that knows to skip `noop`. That is every runtime on this release train, but a runtime pinning its own accepted range separately, such as the Python runtime, has to catch up first. `
|
|
66
|
+
- **What the version actually gates is the reader.** A run stamped at the sealed-log version can only be replayed by a reader that knows to skip `noop`. That is every runtime on this release train, but a runtime pinning its own accepted range separately, such as the Python runtime, has to catch up first. `WORKFLOW_SPEC_VERSION=6` is the setting for an environment where it has not.
|
|
67
67
|
|
|
68
68
|
Runs carry a spec version too, and a run keeps the version it was created under for its whole life. Read the stamped version off the run rather than assuming every run matches what your World declares today. Changing what you stamp does not reach runs already in your store: their version is persisted, every version test in the runtime is a lower bound, and a run's event ID scheme is resolved from what is stored.
|
|
69
69
|
|
package/docs/worlds/vercel.mdx
CHANGED
|
@@ -378,7 +378,7 @@ The Vercel World doesn't follow HTTP redirects on workflow API requests, so poin
|
|
|
378
378
|
|
|
379
379
|
### `VERCEL_WORKFLOW_SERVER_URL`
|
|
380
380
|
|
|
381
|
-
Custom
|
|
381
|
+
Custom backend URL for direct runtime requests, or for the proxy to forward to via `WORKFLOW_VERCEL_BACKEND_URL`. Default: unset; normal deployments should not need this.
|
|
382
382
|
|
|
383
383
|
### `WORKFLOW_SEQUENTIAL_REPLAYS`
|
|
384
384
|
|
|
@@ -400,13 +400,11 @@ Vercel Queues can delay messages for up to 7 days, capped by the message TTL. Be
|
|
|
400
400
|
|
|
401
401
|
### `WORKFLOW_REQUEST_TIMEOUT_MS`
|
|
402
402
|
|
|
403
|
-
Per-request timeout, in milliseconds, for Vercel World HTTP calls to
|
|
403
|
+
Per-request timeout, in milliseconds, for Vercel World HTTP calls to its backend. Default: `60000`. Clamped to `10000`-`120000`; a value outside that range is pulled into it and warns once.
|
|
404
404
|
|
|
405
405
|
Below the floor the deadline starts canceling requests that would have succeeded, since a cold route or a large event page can take seconds, and a canceled request is redriven through the queue rather than making progress. The ceiling matches the longest a backend route holds a response. Requests that legitimately outlast it (stream reads and writes, event batches) opt out of the deadline entirely rather than relying on this value.
|
|
406
406
|
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
Maximum stream chunks written in one Vercel World request. Larger batches are split across multiple requests. Default: `1000`. Minimum: `1`.
|
|
407
|
+
The same deadline bounds the [events WebSocket](#workflow_events_transport): opening the socket, including resolving the token it is opened with, and each event write over it.
|
|
410
408
|
|
|
411
409
|
### `WORKFLOW_STREAMS_TRANSPORT`
|
|
412
410
|
|
|
@@ -456,11 +454,16 @@ try {
|
|
|
456
454
|
|
|
457
455
|
`openEventsChannel()` returns `undefined`, and writes stay on HTTP, when the transport is disabled or the World cannot hold a socket, such as a `projectConfig` World.
|
|
458
456
|
|
|
457
|
+
A write issued while the channel's socket is still connecting waits for the handshake, except `run_started`, which goes over HTTP instead. It is a delivery's first write, and every later write of the delivery waits for it.
|
|
458
|
+
|
|
459
|
+
If the first connect fails, or opening the socket or a write over it gets no answer within [`WORKFLOW_REQUEST_TIMEOUT_MS`](#workflow_request_timeout_ms), the channel closes. The write that failed is retried over HTTP where the event type allows a retry, and every later event write for that run goes over HTTP until a new channel is opened, which the next delivery does. The channel is shared by every concurrent invocation of the run in the same process, so one timed out write moves all of them to HTTP, and releasing it afterwards has nothing left to close.
|
|
460
|
+
|
|
459
461
|
Tracing is unaffected by the choice. Each event write emits an `http POST` client span against the same `url.full`, regardless of which transport carries it. On the WebSocket path, the span is synthesized around the frame because no HTTP request is made. Attributes distinguish the transports:
|
|
460
462
|
|
|
461
463
|
| Attribute | HTTP | WebSocket |
|
|
462
464
|
| --- | --- | --- |
|
|
463
465
|
| `workflow.events.transport` | `http` | `ws` |
|
|
466
|
+
| `workflow.events.transport_fallback` | why a write that tried the socket went over HTTP: `no_channel` (no socket for the run) or `connecting` (a `run_started` during the handshake). Absent when the write never tried the socket, and through a `projectConfig` World. | — |
|
|
464
467
|
| `workflow.event.type` | the event type, e.g. `step_started` | same |
|
|
465
468
|
| `network.protocol.name` | — | `websocket` |
|
|
466
469
|
| `workflow.events.ws.url` | — | the socket the frame went over |
|
|
@@ -554,6 +557,8 @@ Practically, this means:
|
|
|
554
557
|
- Only messages delivered through Vercel Queues can trigger execution
|
|
555
558
|
- Handlers receive only a message ID that must be retrieved from Vercel's backend, making it impossible to craft custom payloads
|
|
556
559
|
|
|
560
|
+
These two layers, a route only Vercel Queues can trigger and a handler that takes a message ID and retrieves and leases the message through Vercel Queues, are why the Vercel World declares `queueAuthMode: 'skip'`: the runtime does not also check a [queue key](/worlds/building-a-world#authenticating-deliveries) on its deliveries. A custom World should declare `'skip'` only when its platform provides both layers.
|
|
561
|
+
|
|
557
562
|
<Callout>
|
|
558
563
|
The Workflow SDK build step manages this configuration. If you are writing a custom integration, see [Framework integrations: Security](/docs/how-it-works/framework-integrations#security) for more details.
|
|
559
564
|
</Callout>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "workflow",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.5.0",
|
|
4
4
|
"description": "Workflow SDK - Build durable, resilient, and observable workflows",
|
|
5
5
|
"main": "dist/typescript-plugin.cjs",
|
|
6
6
|
"type": "module",
|
|
@@ -58,23 +58,23 @@
|
|
|
58
58
|
}
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@workflow/astro": "5.0.
|
|
62
|
-
"@workflow/cli": "5.0
|
|
63
|
-
"@workflow/core": "5.
|
|
64
|
-
"@workflow/errors": "5.1.
|
|
61
|
+
"@workflow/astro": "5.0.9",
|
|
62
|
+
"@workflow/cli": "5.1.0",
|
|
63
|
+
"@workflow/core": "5.5.0",
|
|
64
|
+
"@workflow/errors": "5.1.1",
|
|
65
65
|
"@workflow/typescript-plugin": "5.0.0",
|
|
66
|
-
"@workflow/utils": "5.0
|
|
66
|
+
"@workflow/utils": "5.1.0",
|
|
67
67
|
"ms": "2.1.3",
|
|
68
|
-
"@workflow/next": "5.0
|
|
69
|
-
"@workflow/nest": "5.1.
|
|
70
|
-
"@workflow/nitro": "5.0.
|
|
71
|
-
"@workflow/nuxt": "5.0.
|
|
72
|
-
"@workflow/sveltekit": "5.0.
|
|
73
|
-
"@workflow/rollup": "5.0.
|
|
68
|
+
"@workflow/next": "5.1.0",
|
|
69
|
+
"@workflow/nest": "5.1.7",
|
|
70
|
+
"@workflow/nitro": "5.0.9",
|
|
71
|
+
"@workflow/nuxt": "5.0.9",
|
|
72
|
+
"@workflow/sveltekit": "5.0.9",
|
|
73
|
+
"@workflow/rollup": "5.0.9"
|
|
74
74
|
},
|
|
75
75
|
"devDependencies": {
|
|
76
76
|
"@types/ms": "2.1.0",
|
|
77
|
-
"@types/node": "22.19.
|
|
77
|
+
"@types/node": "22.19.21",
|
|
78
78
|
"@workflow/tsconfig": "5.0.0",
|
|
79
79
|
"typescript": "^6.0.3"
|
|
80
80
|
},
|
|
@@ -90,7 +90,7 @@
|
|
|
90
90
|
"build": "tsc && chmod +x bin/run.js",
|
|
91
91
|
"clean": "tsc --build --clean && rm -rf dist docs ||:",
|
|
92
92
|
"dev": "tsc --watch",
|
|
93
|
-
"test": "vitest run src",
|
|
93
|
+
"test": "vitest run --config=../../vitest.config.ts src",
|
|
94
94
|
"typecheck": "tsc --noEmit"
|
|
95
95
|
}
|
|
96
96
|
}
|