workflow 5.2.0 → 5.2.2
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/README.md +1 -1
- package/dist/internal/errors.d.ts +1 -1
- package/dist/internal/errors.d.ts.map +1 -1
- package/dist/internal/errors.js +2 -2
- package/docs/api-reference/workflow-api/start.mdx +1 -0
- package/docs/api-reference/workflow-runtime/world/storage.mdx +2 -0
- package/docs/changelog/batched-event-writes.mdx +1 -1
- package/docs/configuration/cli-and-web-ui.mdx +12 -4
- package/docs/configuration/runtime-tuning.mdx +1 -9
- package/docs/configuration/worlds.mdx +1 -1
- package/docs/cookbook/common-patterns/sequential-and-parallel.mdx +8 -0
- package/docs/foundations/hooks.mdx +8 -0
- package/docs/foundations/starting-workflows.mdx +8 -0
- package/docs/foundations/streaming.mdx +8 -0
- package/docs/foundations/versioning.mdx +3 -2
- package/docs/how-it-works/event-sourcing.mdx +9 -1
- package/docs/meta.json +1 -0
- package/docs/performance.mdx +187 -0
- package/docs/whats-new.mdx +32 -1
- package/docs/worlds/building-a-world.mdx +65 -2
- package/docs/worlds/local.mdx +25 -1
- package/docs/worlds/postgres.mdx +9 -3
- package/docs/worlds/vercel.mdx +20 -0
- package/package.json +12 -12
package/README.md
CHANGED
|
@@ -68,7 +68,7 @@ Choose your framework in the
|
|
|
68
68
|
For application-level completion and failure reporting, `registerLifecycleHooks`
|
|
69
69
|
from `workflow/api` registers handlers in the workflow executor's host startup.
|
|
70
70
|
Calling it inside a workflow or step throws. Check the
|
|
71
|
-
[lifecycle hooks guide](https://workflow-sdk.dev/
|
|
71
|
+
[lifecycle hooks guide](https://workflow-sdk.dev/docs/observability/lifecycle-hooks)
|
|
72
72
|
for supported framework/deployment combinations and stream cleanup requirements.
|
|
73
73
|
|
|
74
74
|
Local development uses the bundled backend with no configuration. Deploy to
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { EntityConflictError, HookConflictError, HookForceClaimedError, HookNotFoundError, PreconditionFailedError, RunExpiredError, RunNotSupportedError, StepNotRegisteredError, StreamError, ThrottleError, TooEarlyError, WorkflowError, WorkflowNotRegisteredError, WorkflowRunCancelledError, WorkflowRunFailedError, WorkflowRunNotCompletedError, WorkflowRunNotFoundError, WorkflowRuntimeError, WorkflowWorldError, } from '@workflow/errors';
|
|
1
|
+
export { EntityConflictError, HookConflictError, HookForceClaimedError, HookNotFoundError, InBandSupersededError, PreconditionFailedError, RunExpiredError, RunNotSupportedError, StepNotRegisteredError, StreamError, ThrottleError, TooEarlyError, WorkflowError, WorkflowNotRegisteredError, WorkflowRunCancelledError, WorkflowRunFailedError, WorkflowRunNotCompletedError, WorkflowRunNotFoundError, WorkflowRuntimeError, WorkflowWorldError, } from '@workflow/errors';
|
|
2
2
|
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/internal/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,qBAAqB,EACrB,iBAAiB,EACjB,uBAAuB,EACvB,eAAe,EACf,oBAAoB,EACpB,sBAAsB,EACtB,WAAW,EACX,aAAa,EACb,aAAa,EACb,aAAa,EACb,0BAA0B,EAC1B,yBAAyB,EACzB,sBAAsB,EACtB,4BAA4B,EAC5B,wBAAwB,EACxB,oBAAoB,EACpB,kBAAkB,GACnB,MAAM,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/internal/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,qBAAqB,EACrB,iBAAiB,EACjB,qBAAqB,EACrB,uBAAuB,EACvB,eAAe,EACf,oBAAoB,EACpB,sBAAsB,EACtB,WAAW,EACX,aAAa,EACb,aAAa,EACb,aAAa,EACb,0BAA0B,EAC1B,yBAAyB,EACzB,sBAAsB,EACtB,4BAA4B,EAC5B,wBAAwB,EACxB,oBAAoB,EACpB,kBAAkB,GACnB,MAAM,kBAAkB,CAAC"}
|
package/dist/internal/errors.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { EntityConflictError, HookConflictError, HookForceClaimedError, HookNotFoundError, PreconditionFailedError, RunExpiredError, RunNotSupportedError, StepNotRegisteredError, StreamError, ThrottleError, TooEarlyError, WorkflowError, WorkflowNotRegisteredError, WorkflowRunCancelledError, WorkflowRunFailedError, WorkflowRunNotCompletedError, WorkflowRunNotFoundError, WorkflowRuntimeError, WorkflowWorldError, } from '@workflow/errors';
|
|
2
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
1
|
+
export { EntityConflictError, HookConflictError, HookForceClaimedError, HookNotFoundError, InBandSupersededError, PreconditionFailedError, RunExpiredError, RunNotSupportedError, StepNotRegisteredError, StreamError, ThrottleError, TooEarlyError, WorkflowError, WorkflowNotRegisteredError, WorkflowRunCancelledError, WorkflowRunFailedError, WorkflowRunNotCompletedError, WorkflowRunNotFoundError, WorkflowRuntimeError, WorkflowWorldError, } from '@workflow/errors';
|
|
2
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZXJyb3JzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL2ludGVybmFsL2Vycm9ycy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQ0wsbUJBQW1CLEVBQ25CLGlCQUFpQixFQUNqQixxQkFBcUIsRUFDckIsaUJBQWlCLEVBQ2pCLHFCQUFxQixFQUNyQix1QkFBdUIsRUFDdkIsZUFBZSxFQUNmLG9CQUFvQixFQUNwQixzQkFBc0IsRUFDdEIsV0FBVyxFQUNYLGFBQWEsRUFDYixhQUFhLEVBQ2IsYUFBYSxFQUNiLDBCQUEwQixFQUMxQix5QkFBeUIsRUFDekIsc0JBQXNCLEVBQ3RCLDRCQUE0QixFQUM1Qix3QkFBd0IsRUFDeEIsb0JBQW9CLEVBQ3BCLGtCQUFrQixHQUNuQixNQUFNLGtCQUFrQixDQUFDIiwic291cmNlc0NvbnRlbnQiOlsiZXhwb3J0IHtcbiAgRW50aXR5Q29uZmxpY3RFcnJvcixcbiAgSG9va0NvbmZsaWN0RXJyb3IsXG4gIEhvb2tGb3JjZUNsYWltZWRFcnJvcixcbiAgSG9va05vdEZvdW5kRXJyb3IsXG4gIEluQmFuZFN1cGVyc2VkZWRFcnJvcixcbiAgUHJlY29uZGl0aW9uRmFpbGVkRXJyb3IsXG4gIFJ1bkV4cGlyZWRFcnJvcixcbiAgUnVuTm90U3VwcG9ydGVkRXJyb3IsXG4gIFN0ZXBOb3RSZWdpc3RlcmVkRXJyb3IsXG4gIFN0cmVhbUVycm9yLFxuICBUaHJvdHRsZUVycm9yLFxuICBUb29FYXJseUVycm9yLFxuICBXb3JrZmxvd0Vycm9yLFxuICBXb3JrZmxvd05vdFJlZ2lzdGVyZWRFcnJvcixcbiAgV29ya2Zsb3dSdW5DYW5jZWxsZWRFcnJvcixcbiAgV29ya2Zsb3dSdW5GYWlsZWRFcnJvcixcbiAgV29ya2Zsb3dSdW5Ob3RDb21wbGV0ZWRFcnJvcixcbiAgV29ya2Zsb3dSdW5Ob3RGb3VuZEVycm9yLFxuICBXb3JrZmxvd1J1bnRpbWVFcnJvcixcbiAgV29ya2Zsb3dXb3JsZEVycm9yLFxufSBmcm9tICdAd29ya2Zsb3cvZXJyb3JzJztcbiJdfQ==
|
|
@@ -64,6 +64,7 @@ Learn more about [`WorkflowReadableStreamOptions`](/docs/api-reference/workflow-
|
|
|
64
64
|
* `attributes` seeds plaintext run metadata as part of creation and requires a World implementing spec version 4 or later. Keys that start with `$` are reserved for framework and library code; framework-level callers can pass `allowReservedAttributes: true` to seed reserved keys, with the same semantics as the [`setAttributes`](/docs/api-reference/workflow/set-attributes) option of the same name.
|
|
65
65
|
* `region` pins the new run to a specific region on Worlds with a regional dimension. The [Vercel World](/worlds/vercel#explicit-region-selection) then serves the run's storage, queue dispatch, and streams from that region. When you omit `region`, the run is pinned to the region where it was created. Worlds without regions ignore the option.
|
|
66
66
|
* `experimental_retention` asks the World to delete the run's user data as soon as the run completes or fails, instead of keeping it for the World's default window. `0` requests immediate deletion; `'default'` is identical to omitting the option. These are the only two values accepted — the value is a duration and zero is the only one implemented, and its unit is not yet decided. Recorded as the reserved `$retention` attribute, so it needs a World implementing spec version 4 or later. Retention is enforced by the World, not the SDK: the first-party Worlds implement it and a World that does not keeps the data. Note that `await run.returnValue` on a run started with `experimental_retention: 0` usually throws [`RunExpiredError`](/docs/errors/run-expired) rather than resolving, because the deletion races the read. See [Data retention](/docs/observability/retention).
|
|
67
|
+
* `compressArguments: false` stores the run's arguments uncompressed. By default they are compressed when the target run can decode them. Arguments of 256 KiB or more are compressed off the caller's event loop, so starting a run with a large input doesn't stall other requests the process is serving. The attempt still costs CPU proportional to the input size and is wasted on data that will not shrink (media, encrypted or random bytes), so skip it when you know the inputs are incompressible. `true` is the default and does not force compression. The option only affects the arguments; a [dynamic workflow's](/docs/advanced/dynamic-workflows) code is compressed regardless. To disable compression for every write in a process, see [`WORKFLOW_DISABLE_COMPRESSION`](/docs/configuration/runtime-tuning#workflow_disable_compression).
|
|
67
68
|
|
|
68
69
|
<Callout type="info">
|
|
69
70
|
If `start()` throws `'start' received an invalid workflow function. Ensure the Workflow SDK is configured correctly and the function includes a 'use workflow' directive.`, the compiler did not transform the passed function as a workflow. The two most common causes are a missing `"use workflow"` directive or missing framework integration. See [start-invalid-workflow-function](/docs/errors/start-invalid-workflow-function).
|
|
@@ -200,6 +200,7 @@ const result = await world.runs.list({ // [!code highlight]
|
|
|
200
200
|
| `params.workflowName` | `string` | Only return runs of this workflow |
|
|
201
201
|
| `params.status` | `WorkflowRunStatus \| WorkflowRunStatus[]` | Only return runs in this status. Pass an array to match any of the listed statuses; an empty array matches no runs. `@workflow/world-vercel` accepts a single status only and throws `WorkflowWorldError` (`INVALID_ARGUMENT`) for an array |
|
|
202
202
|
| `params.pagination.cursor` | `string` | Cursor for the next page |
|
|
203
|
+
| `params.pagination.sortOrder` | `"asc" \| "desc"` | Run creation order. Default: `"desc"` (newest first) |
|
|
203
204
|
| `params.resolveData` | `'all' \| 'none'` | Whether to include input/output data |
|
|
204
205
|
|
|
205
206
|
**Returns:** `{ data: WorkflowRun[], cursor?: string }`
|
|
@@ -297,6 +298,7 @@ const result = await world.steps.list({ // [!code highlight]
|
|
|
297
298
|
|-----------|------|-------------|
|
|
298
299
|
| `params.runId` | `string` | Filter steps by run ID |
|
|
299
300
|
| `params.pagination.cursor` | `string` | Cursor for the next page |
|
|
301
|
+
| `params.pagination.sortOrder` | `"asc" \| "desc"` | Step creation order. Default: `"desc"` (newest first) |
|
|
300
302
|
| `params.resolveData` | `'all' \| 'none'` | Whether to include input/output data |
|
|
301
303
|
|
|
302
304
|
**Returns:** `{ data: Step[], cursor?: string }`
|
|
@@ -62,7 +62,7 @@ The contract:
|
|
|
62
62
|
|
|
63
63
|
## The runtime integration (suspension fan-out fold)
|
|
64
64
|
|
|
65
|
-
**On by default.** The suspension handler folds a **clean fan-out** (the suspension's eager `step_created` and `wait_created` writes) into `createBatch` calls of at most 16 events. The server's transaction budgets allow more; 16 is a latency choice (see **Per-chunk continuation**). Chunks of a larger fan-out commit **concurrently**: slot assignment is the World's, so parallel chunks race for slot ranges exactly like the pre-fold path's parallel single writes did, and per-entity conditions, not commit order, carry correctness. The fold only engages when the World implements `createBatch`, the run is on slot identity, and the suspension carries no attribute writes
|
|
65
|
+
**On by default.** The suspension handler folds a **clean fan-out** (the suspension's eager `step_created` and `wait_created` writes) into `createBatch` calls of at most 16 events. The server's transaction budgets allow more; 16 is a latency choice (see **Per-chunk continuation**). Chunks of a larger fan-out commit **concurrently**: slot assignment is the World's, so parallel chunks race for slot ranges exactly like the pre-fold path's parallel single writes did, and per-entity conditions, not commit order, carry correctness. The fold only engages when the World implements `createBatch`, the run is on slot identity, and the suspension carries no attribute writes; everything else keeps the single-event path byte-for-byte. A suspension that also creates or disposes hooks still folds: hook writes are not batchable, so they go through the single-event path **concurrently** with the fold rather than ahead of it.
|
|
66
66
|
|
|
67
67
|
**Per-chunk continuation.** Each chunk's follow-on work starts the moment **that chunk** commits, not when the whole fold does: a chunk's step-execution queue messages publish right off its own commit (publish-after-create holds per step), and only the chunk carrying the inline pairs gates the replay's continuation: trailing chunks' commits and publishes are joined before the invocation can acknowledge its message, so the durability contract ("every create durable before ack") is unchanged. A queued step's message therefore waits on two hops in series, its chunk's commit and then its chunk's batched publish, and both grow with the chunk's size, so smaller chunks start a wide fan-out's queued branches sooner. More chunks also means more concurrent batch writes per run, and from about 16 of them the pair chunk, and with it the first inline branch, slows down. The 16-event cap is where production measurements balanced the two: on 64- and 128-branch fan-outs the last branch started about 90 to 200 ms sooner than at 32 events, with no first-branch cost at those widths.
|
|
68
68
|
|
|
@@ -107,7 +107,7 @@ Vercel project and auth settings can often be inferred from `.vercel/project.jso
|
|
|
107
107
|
|
|
108
108
|
- Environment variable: none
|
|
109
109
|
- Default: unset
|
|
110
|
-
- Pagination cursor for list commands.
|
|
110
|
+
- Pagination cursor for list commands. A `workflow inspect` listing that stops with more rows prints the next page's cursor: in its `--json` page object for `runs`, `hooks`, and `attributes`, and on stderr for `steps`, `events`, and `sleeps`, whose `--json` output is an array.
|
|
111
111
|
|
|
112
112
|
### `--interactive` / `-i`
|
|
113
113
|
|
|
@@ -125,12 +125,20 @@ per flag.
|
|
|
125
125
|
- Command: `workflow inspect`
|
|
126
126
|
- Default: unset
|
|
127
127
|
- Scopes the listing to one run. Required for `steps`, `events`, and `sleeps`; optional for `hooks`. Must be a run ID: `wrun_` followed by a 26-character ULID.
|
|
128
|
+
- Also required to read one step, event, or stream, as in `workflow inspect step <step-id> --runId=<run-id>`: their IDs and names are scoped to their run.
|
|
128
129
|
|
|
129
130
|
### `--limit` (inspect)
|
|
130
131
|
|
|
131
132
|
- Command: `workflow inspect`
|
|
132
133
|
- Default: `20`
|
|
133
|
-
- Must be an integer between 1 and 100, the smallest page any inspect listing accepts. Larger pages are reachable by paging: pass `--cursor`, or `--interactive` to walk them.
|
|
134
|
+
- Must be an integer between 1 and 100, the smallest page any inspect listing accepts. Larger pages are reachable by paging: pass `--cursor`, `--all` to read every page, or `--interactive` to walk them.
|
|
135
|
+
|
|
136
|
+
### `--all`
|
|
137
|
+
|
|
138
|
+
- Command: `workflow inspect steps`, `workflow inspect events`, `workflow inspect sleeps`
|
|
139
|
+
- Default: disabled
|
|
140
|
+
- Follows cursors to the last page and prints every row: one table, or with `--json` one array. `--limit` sets the size of each page it fetches and `--cursor` where it starts.
|
|
141
|
+
- Cannot be combined with `--interactive`, an ID, or `--url`/`--web`. The `runs`, `hooks`, and `attributes` listings take `--cursor` instead: their `--json` output carries it.
|
|
134
142
|
|
|
135
143
|
### `--stepId` / `-s`
|
|
136
144
|
|
|
@@ -187,8 +195,8 @@ per flag.
|
|
|
187
195
|
|
|
188
196
|
- Command: `workflow cancel`
|
|
189
197
|
- Default: unset
|
|
190
|
-
- Restricts the batch to one workflow. Expects the generated workflow ID from `workflow inspect runs`, not the short function name.
|
|
191
|
-
- Also filters `workflow inspect runs` and `workflow inspect attributes`.
|
|
198
|
+
- Restricts the batch to one workflow. Expects the generated workflow ID from `workflow inspect runs --json`, not the short function name.
|
|
199
|
+
- Also filters `workflow inspect runs` and `workflow inspect attributes`. These also accept the short name the runs table shows, such as `processOrder`: it is looked up among the workflows of the 500 most recent runs (in the `--since` window when given) and replaced by the full name. A short name that more than one of those workflows share is rejected with the candidates, and one that none of them has is used as given.
|
|
192
200
|
|
|
193
201
|
### `--limit` (cancel)
|
|
194
202
|
|
|
@@ -89,15 +89,6 @@ For example, a workflow can run a 10-minute inline step even with `WORKFLOW_REPL
|
|
|
89
89
|
- Only applies to Worlds with atomic, immutable deployments (the Vercel World). A run whose pinned deployment cannot be reached at all fails immediately regardless of this value.
|
|
90
90
|
- Transient or unknown queue publishing failures use normal queue redelivery and do not consume this budget.
|
|
91
91
|
|
|
92
|
-
### `WORKFLOW_RESILIENT_STEP_DISPATCH`
|
|
93
|
-
|
|
94
|
-
- Default: disabled
|
|
95
|
-
- When a suspension hands newly created steps to the queue, the runtime publishes each step's execution message in parallel with its `step_created` event write instead of sequencing them, cutting a round trip per dispatched step. The message also carries the serialized step input (`stepInput`), so a transient `step_created` write failure (429 / 5xx / transport) still executes the step. The queue consumer idempotently re-ensures the event before running it, converging with the producer's write on the step's correlation ID. This mirrors resilient start (`runInput`) and the legacy lazy hook resume's `hookInput` (which current producers no longer send; see [durable hook resume](/docs/changelog/lazy-hook-resume)).
|
|
96
|
-
- It is off by default because the publish races the create's verdict, and a create can come back refused: as a duplicate this replay should stop pursuing, or as a [stale write](#stale-reads-and-why-nothing-has-to-be-rejected) on a World that refuses rather than reports. Either way the message carrying the payload is already out, so the consumer can materialize a step whose create was refused, and nothing orders the verdict before the consumer's redelivery re-ensure. The sequential path is the only one that gives the message a happens-after edge over it.
|
|
97
|
-
- Even when enabled, the runtime falls back to the sequential create-then-publish dispatch when the step input is too large to inline on the queue message, or when the run's queue transport cannot carry binary payloads (pre-CBOR spec versions).
|
|
98
|
-
- Producer-side recoveries are reported on the suspension span as `workflow.step.resilient_dispatch_recovered`; a consumer that materialized the event reports `workflow.step.resilient_dispatch_materialized`.
|
|
99
|
-
- Set `1` to enable it.
|
|
100
|
-
|
|
101
92
|
### `WORKFLOW_OPEN_WAIT_CLOCK_SKEW_MS`
|
|
102
93
|
|
|
103
94
|
- Default: `30000` (30 seconds)
|
|
@@ -279,6 +270,7 @@ What a snapshot contains, and how it is protected:
|
|
|
279
270
|
- Default: compression enabled
|
|
280
271
|
- Set `1` to disable compression when writing payloads.
|
|
281
272
|
- Reads still decompress existing payloads.
|
|
273
|
+
- To skip compression only for one run's arguments, pass `compressArguments: false` to [`start()`](/docs/api-reference/workflow-api/start) instead.
|
|
282
274
|
|
|
283
275
|
### `WORKFLOW_COMPRESSION_CODEC`
|
|
284
276
|
|
|
@@ -314,7 +314,7 @@ Platform-provided values such as `VERCEL_DEPLOYMENT_ID`, `VERCEL_PROJECT_ID`, an
|
|
|
314
314
|
- Default: on
|
|
315
315
|
- Set to `0` (or `false`) to **disable** batched event writes, the escape hatch that restores the exact prior one-write-per-event path.
|
|
316
316
|
|
|
317
|
-
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
|
|
317
|
+
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.
|
|
318
318
|
|
|
319
319
|
### `WORKFLOW_EVENTS_TRANSPORT`
|
|
320
320
|
|
|
@@ -148,6 +148,14 @@ export async function birthdayWorkflow(
|
|
|
148
148
|
- **Add a deadline to any race**: Pair the operation with `sleep("30s").then(() => "timeout" as const)` and check the discriminated result. See [Timeouts](/cookbook/common-patterns/timeouts).
|
|
149
149
|
- **Mix steps and hooks in a race**: Wait for an external signal, a deadline, or a step result in the same `Promise.race`. The first promise to resolve wins.
|
|
150
150
|
|
|
151
|
+
## Performance
|
|
152
|
+
|
|
153
|
+
The fan-out benchmark measures how quickly a `Promise.all` over 64 steps gets going and finishes: from `start()` until the first branch and the slowest branch start, and from the slowest branch finishing until the code after `Promise.all` runs. The animation shows the branches starting close together and in no fixed order.
|
|
154
|
+
|
|
155
|
+
<MetricVideo metric="fanout" />
|
|
156
|
+
|
|
157
|
+
See [Fan-out](/docs/performance#fan-out-ttfs-ttls-join) on the Performance page for how it's measured and the latest results.
|
|
158
|
+
|
|
151
159
|
## Key APIs
|
|
152
160
|
|
|
153
161
|
- [`"use workflow"`](/docs/foundations/workflows-and-steps): Marks the orchestrator function.
|
|
@@ -670,6 +670,14 @@ for await (const event of hook) {
|
|
|
670
670
|
|
|
671
671
|
This pattern allows a single workflow instance to handle multiple events over time, maintaining state between events.
|
|
672
672
|
|
|
673
|
+
## Performance
|
|
674
|
+
|
|
675
|
+
Time to resume (TTR) measures how quickly a workflow that is waiting on a hook continues once your app calls `resumeHook()`: the clock starts at that call and stops when the first line of the workflow's next step runs. The animation shows where it starts and stops in a run.
|
|
676
|
+
|
|
677
|
+
<MetricVideo metric="resume" />
|
|
678
|
+
|
|
679
|
+
See [Time to resume](/docs/performance#time-to-resume-ttr) on the Performance page for how it's measured and the latest results.
|
|
680
|
+
|
|
673
681
|
## Related documentation
|
|
674
682
|
|
|
675
683
|
- [Serialization](/docs/foundations/serialization) - Understanding what data can be passed through hooks
|
|
@@ -289,6 +289,14 @@ export async function syncDashboard() {
|
|
|
289
289
|
|
|
290
290
|
By default a chained run starts on the same deployment as its parent. For workflows that chain over long periods, pass [`deploymentId: "latest"`](/docs/api-reference/workflow-api/start#using-deploymentid-latest) so the next run picks up new code. [Versioning](/docs/foundations/versioning#self-upgrading-workflows) covers this pattern in full, including how the serialized state acts as the migration boundary between versions.
|
|
291
291
|
|
|
292
|
+
## Performance
|
|
293
|
+
|
|
294
|
+
Time to first step (TTFS) measures how long a new run takes to get going: from your app calling `start()` until the first line of the workflow's first step runs. The animation shows the run being created, the workflow running up to its first step, and that step starting.
|
|
295
|
+
|
|
296
|
+
<MetricVideo metric="ttfs" />
|
|
297
|
+
|
|
298
|
+
See [Time to first step](/docs/performance#time-to-first-step-ttfs) on the Performance page for how it's measured and the latest results.
|
|
299
|
+
|
|
292
300
|
## Next steps
|
|
293
301
|
|
|
294
302
|
- Browse the [Cookbook](/cookbook) for copy-paste recipes covering composition, scheduling, timeouts, and more
|
|
@@ -635,6 +635,14 @@ export async function streamErrorWorkflow() {
|
|
|
635
635
|
Stream errors don't trigger automatic retries for the producer step. Design your stream consumers to handle errors. Because the stream is already in an errored state, retrying the consumer won't help. Use `FatalError` to fail the workflow immediately.
|
|
636
636
|
</Callout>
|
|
637
637
|
|
|
638
|
+
## Performance
|
|
639
|
+
|
|
640
|
+
Chunk trip time (CTT) measures how quickly a chunk written to a stream reaches its reader: the clock starts when one step writes the chunk and stops when another step receives it. The animation shows a writer step replaying a recorded agent stream and a reader step receiving each chunk.
|
|
641
|
+
|
|
642
|
+
<MetricVideo metric="stream" />
|
|
643
|
+
|
|
644
|
+
See [Chunk trip time](/docs/performance#chunk-trip-time-ctt) on the Performance page for how it's measured and the latest results.
|
|
645
|
+
|
|
638
646
|
## Related documentation
|
|
639
647
|
|
|
640
648
|
- [`getWritable()` API reference](/docs/api-reference/workflow/get-writable): Get the workflow's writable stream
|
|
@@ -81,7 +81,8 @@ This keeps the version boundary visible. The old run ends as canceled or failed,
|
|
|
81
81
|
# Inspect affected runs and copy the exact workflowName value.
|
|
82
82
|
npx workflow inspect runs \
|
|
83
83
|
--backend vercel \
|
|
84
|
-
--status running
|
|
84
|
+
--status running \
|
|
85
|
+
--json
|
|
85
86
|
|
|
86
87
|
# Cancel one run.
|
|
87
88
|
npx workflow cancel <run-id> \
|
|
@@ -94,7 +95,7 @@ npx workflow cancel \
|
|
|
94
95
|
--backend vercel
|
|
95
96
|
```
|
|
96
97
|
|
|
97
|
-
The
|
|
98
|
+
The `workflow cancel --workflowName` filter expects the generated workflow ID, not only the exported function's short name. Copy the `workflowName` value from `workflow inspect runs --json`, since the runs table shows the short name, and use [`parseWorkflowName()`](/docs/api-reference/workflow-observability/parse-workflow-name) when you need display-friendly names.
|
|
98
99
|
|
|
99
100
|
In the [observability UI](/docs/observability), use **Rerun on latest** to enqueue the workflow again with the same inputs against the latest deployment.
|
|
100
101
|
|
|
@@ -207,7 +207,7 @@ Events are categorized by the entity type they affect. Each event contains metad
|
|
|
207
207
|
|
|
208
208
|
Counting the events above is how you size a run. A step that succeeds on the first attempt contributes three events; a retry adds another `step_started`, preceded by a `step_retrying` when the World emits one; a sleep contributes two, and a hook at least two.
|
|
209
209
|
|
|
210
|
-
A run's log is capped — the [Vercel World](/worlds/vercel#per-run-limits) fails anything past its ceiling with `MAX_EVENTS_EXCEEDED`. Replay reads the whole log, so a run gets slower as it grows and is worth splitting well before it fails: split into [child workflows](/cookbook/advanced/child-workflows) once a run would grow past a few thousand events.
|
|
210
|
+
A run's log is capped — the [Vercel World](/worlds/vercel#per-run-limits) fails anything past its ceiling with `MAX_EVENTS_EXCEEDED`. Replay reads the whole log, so a run gets slower as it grows and is worth splitting well before it fails: split into [child workflows](/cookbook/advanced/child-workflows) once a run would grow past a few thousand events. How much the growth costs depends on how often the run replays; [Steps and long runs](/docs/performance#steps-and-long-runs) shows how step-to-step overhead changes through a 1,020-step run.
|
|
211
211
|
|
|
212
212
|
## Terminal states
|
|
213
213
|
|
|
@@ -373,3 +373,11 @@ An event ID is a **slot number**: the event's 1-based position in the run's even
|
|
|
373
373
|
Density is what lets a reader tell a complete log from an incomplete one by its length alone. A replay that loads a log with a position missing below the highest one it can see cannot tell an event that was never written from one it failed to read, so it fails the run with [`CORRUPTED_EVENT_LOG`](/docs/errors/corrupted-event-log) rather than replay across the hole. See [`WORKFLOW_SLOT_GAP_CHECK`](/docs/configuration/runtime-tuning#workflow_slot_gap_check).
|
|
374
374
|
|
|
375
375
|
A slot ID carries no timestamp. Zero-padded decimal digits are a subset of the ULID alphabet, so a slot ID passes ULID validation and sorts correctly, but decoding its first 48 bits yields the Unix epoch instead of a creation time. Read `createdAt` on the event when you need to know when it was written, and don't decode the time from an `evnt_` ID you get back from an API, a log line, or a cursor.
|
|
376
|
+
|
|
377
|
+
## Performance
|
|
378
|
+
|
|
379
|
+
Step-to-step overhead (STSO) measures the time the runtime adds between two steps: from one step finishing until the next one starts, which covers recording the step's result, resuming the workflow, and starting the next step. The work inside each step isn't counted. The animation shows where that gap starts and stops.
|
|
380
|
+
|
|
381
|
+
<MetricVideo metric="stso" />
|
|
382
|
+
|
|
383
|
+
See [Step-to-step overhead](/docs/performance#step-to-step-overhead-stso) on the Performance page for how it's measured and the latest results.
|
package/docs/meta.json
CHANGED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Performance
|
|
3
|
+
description: How we measure the Workflow SDK runtime's performance, the metrics we track, and the latest results.
|
|
4
|
+
type: reference
|
|
5
|
+
summary: The benchmarks we run on the Workflow SDK runtime, how each one is measured, and the latest results.
|
|
6
|
+
related:
|
|
7
|
+
- /docs/whats-new
|
|
8
|
+
- /docs/how-it-works/event-sourcing
|
|
9
|
+
- /docs/foundations/hooks
|
|
10
|
+
- /docs/foundations/streaming
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
We benchmark the Workflow SDK runtime on Vercel at each point where a workflow waits on it: starting a run, moving from one step to the next, fanning out, resuming from a hook, and delivering a stream. This page explains what each benchmark measures and how, and then shows the [latest results](#latest-results), which compare a new release with an earlier one.
|
|
14
|
+
|
|
15
|
+
## What we measure
|
|
16
|
+
|
|
17
|
+
Each benchmark starts a clock at one line of code and stops it at another. The work inside a step is not counted, so the numbers measure the runtime itself. Choose a metric below, then play or scrub through a run to see when its clock runs.
|
|
18
|
+
|
|
19
|
+
<PerformanceExplainer />
|
|
20
|
+
|
|
21
|
+
### Time to first step (TTFS)
|
|
22
|
+
|
|
23
|
+
How long it takes from your app calling [`start()`](/docs/api-reference/workflow-api/start) until the first line of the workflow's first step runs. This covers creating and queuing the run, running the workflow code up to its first step, and starting that step. It is measured on a five-step workflow. See [Steps and long runs](#steps-and-long-runs) for the latest results.
|
|
24
|
+
|
|
25
|
+
### Step-to-step overhead (STSO)
|
|
26
|
+
|
|
27
|
+
How long it takes from one step finishing until the next step starts: recording the step's result, resuming the workflow, and starting the next step. It is measured on the same five-step workflow, and at steps 1 to 20, 101 to 120, and 1,001 to 1,020 of a 1,020-step workflow, which shows whether the overhead grows as the run's [event log](/docs/how-it-works/event-sourcing) grows. See [Steps and long runs](#steps-and-long-runs) for the latest results.
|
|
28
|
+
|
|
29
|
+
### Fan-out (TTFS, TTLS, join)
|
|
30
|
+
|
|
31
|
+
A workflow starts 64 one-step branches at once with `Promise.all`. The runtime queues the branches in batches, so they start close together and in no fixed order. The first branch (TTFS) and the slowest branch to start, or time to last step (TTLS), are timed from `start()` until that branch's first line runs. The join is timed from the slowest branch finishing until the code after `Promise.all` runs. See [Fan-out](#fan-out) for the latest results.
|
|
32
|
+
|
|
33
|
+
### Time to resume (TTR)
|
|
34
|
+
|
|
35
|
+
A workflow creates a [hook](/docs/foundations/hooks) and waits on it for 1 s, the way an agent waits for a person's approval, and then your app calls `resumeHook()`. Time to resume runs from that call until the first line of the workflow's next step runs. Each run resumes five times. See [Resuming a workflow](#resuming-a-workflow) for the latest results.
|
|
36
|
+
|
|
37
|
+
### Chunk trip time (CTT)
|
|
38
|
+
|
|
39
|
+
One step replays a recorded AI agent's token stream, 2,593 chunks over 52.4 s, in real time to a [namespaced stream](/docs/foundations/streaming#namespaced-streams) with [`getWritable()`](/docs/api-reference/workflow/get-writable), and a second step in the same run reads it with `getRun(runId).getReadable()`. Chunk trip time runs from the writer writing a chunk until the reader receives it. The same benchmark records how long the whole response takes to reach the reader and how many runs had a chunk delayed by over 1 s. See [Streams](#streams) for the latest results.
|
|
40
|
+
|
|
41
|
+
## Methodology
|
|
42
|
+
|
|
43
|
+
- **Platform**: Each version runs the same benchmark app on Vercel production in `iad1`, against the managed [Vercel World](/worlds/vercel), on its own deployment. The versions are measured at the same time. Before measuring, each deployment runs two short workflows and one fan-out that are not counted.
|
|
44
|
+
- **Workload**: Every step takes 1 KB of JSON in and out and does 100 ms of simulated work, which the overhead measurements exclude.
|
|
45
|
+
- **Runs**: Each version runs every benchmark several times, and each result pools the samples from all of its runs. The run counts are listed with the latest results.
|
|
46
|
+
- **Percentiles**: Each percentile pools every sample across a version's runs and uses the nearest-rank method. Half of the samples are at or below the p50 (the median), three quarters at or below the p75, and all but the slowest 1% at or below the p99. With 100 or fewer samples, a p99 is the slowest sample.
|
|
47
|
+
|
|
48
|
+
### Limits
|
|
49
|
+
|
|
50
|
+
- The benchmarks run in one region, against one World. Other regions, Worlds, and workloads will see different numbers.
|
|
51
|
+
- The versions share the platform while they are measured. Any exception is noted with the results.
|
|
52
|
+
- The explainer and the animations are schematic: they show where each clock starts and stops, not real timings.
|
|
53
|
+
|
|
54
|
+
## Latest results
|
|
55
|
+
|
|
56
|
+
<Callout type="info">
|
|
57
|
+
{/* generated:performance latest */}
|
|
58
|
+
|
|
59
|
+
**Latest results:** Workflow SDK v5.2.0 compared with v4.8.12, measured October 8, 2026. We run these benchmarks regularly and publish updated results here.
|
|
60
|
+
|
|
61
|
+
{/* end generated:performance latest */}
|
|
62
|
+
</Callout>
|
|
63
|
+
|
|
64
|
+
{/* generated:performance headline */}
|
|
65
|
+
|
|
66
|
+
At p75, v5.2.0 is as fast as or faster than v4.8.12 on every benchmark. The largest change is in long runs: 1,000 steps into a run, v5.2.0 adds 70 ms between steps where v4.8.12 adds 1,748 ms.
|
|
67
|
+
|
|
68
|
+
{/* end generated:performance headline */}
|
|
69
|
+
|
|
70
|
+
{/* generated:performance caveats */}
|
|
71
|
+
|
|
72
|
+
Both versions ran at the same time and shared the platform. The exception is the 1,020-step benchmark on v4: one of its five runs ran alongside v5.2.0's, and the other four ran on their own afterwards, the same day with the same configuration. Each version ran the sequential workflow 10 times, the agent stream 10 times, the fan-out 25 times, the resume benchmark 25 times, and the 1,020-step run 5 times.
|
|
73
|
+
|
|
74
|
+
{/* end generated:performance caveats */}
|
|
75
|
+
|
|
76
|
+
<Image
|
|
77
|
+
srcLight="/performance/v5.2.0/01-overview-light.png"
|
|
78
|
+
srcDark="/performance/v5.2.0/01-overview-dark.png"
|
|
79
|
+
alt="Dot plot of how many times faster the newer version is than the older one at p75 on each benchmark, on a log scale. The full values are in the results table below."
|
|
80
|
+
width={2016}
|
|
81
|
+
height={1444}
|
|
82
|
+
/>
|
|
83
|
+
|
|
84
|
+
### Steps and long runs
|
|
85
|
+
|
|
86
|
+
{/* generated:performance sequential */}
|
|
87
|
+
|
|
88
|
+
At p75, a five-step workflow reaches its first step in 172 ms on v5.2.0 and 418 ms on v4.8.12, and v5.2.0 adds 109 ms between steps where v4.8.12 adds 618 ms.
|
|
89
|
+
|
|
90
|
+
{/* end generated:performance sequential */}
|
|
91
|
+
|
|
92
|
+
{/* generated:performance long-run */}
|
|
93
|
+
|
|
94
|
+
Through a 1,020-step run, step-to-step overhead on v4.8.12 grows from 622 ms in steps 1 to 20 to 1,748 ms in steps 1,001 to 1,020, at p75. On v5.2.0 it is 110 ms and 70 ms. The median run takes 21.0 min on v4.8.12 and 3.0 min on v5.2.0.
|
|
95
|
+
|
|
96
|
+
{/* end generated:performance long-run */}
|
|
97
|
+
|
|
98
|
+
<Image
|
|
99
|
+
srcLight="/performance/v5.2.0/02-sequential-light.png"
|
|
100
|
+
srcDark="/performance/v5.2.0/02-sequential-dark.png"
|
|
101
|
+
alt="Three charts comparing the two versions: time to first step and step-to-step overhead for a five-step workflow, step-to-step overhead through a 1,020-step run at p75, and the time to finish all 1,020 steps. The full values are in the results table below."
|
|
102
|
+
width={2016}
|
|
103
|
+
height={2328}
|
|
104
|
+
/>
|
|
105
|
+
|
|
106
|
+
### Fan-out
|
|
107
|
+
|
|
108
|
+
{/* generated:performance fanout */}
|
|
109
|
+
|
|
110
|
+
At p75, v5.2.0 starts the first of 64 branches in 360 ms against 478 ms on v4.8.12, then starts the slowest branch at about the same time (996 ms against 972 ms) and joins in 448 ms against 464 ms.
|
|
111
|
+
|
|
112
|
+
{/* end generated:performance fanout */}
|
|
113
|
+
|
|
114
|
+
<Image
|
|
115
|
+
srcLight="/performance/v5.2.0/03-fanout-light.png"
|
|
116
|
+
srcDark="/performance/v5.2.0/03-fanout-dark.png"
|
|
117
|
+
alt="Dumbbell chart of a 64-branch fan-out at p75, comparing the two versions for the first branch to start, the slowest branch to start, and the join. The full values are in the results table below."
|
|
118
|
+
width={2016}
|
|
119
|
+
height={804}
|
|
120
|
+
/>
|
|
121
|
+
|
|
122
|
+
### Resuming a workflow
|
|
123
|
+
|
|
124
|
+
{/* generated:performance resume */}
|
|
125
|
+
|
|
126
|
+
At p75, a workflow waiting on a hook resumes in 425 ms on v5.2.0 against 699 ms on v4.8.12.
|
|
127
|
+
|
|
128
|
+
{/* end generated:performance resume */}
|
|
129
|
+
|
|
130
|
+
<Image
|
|
131
|
+
srcLight="/performance/v5.2.0/04-resume-light.png"
|
|
132
|
+
srcDark="/performance/v5.2.0/04-resume-dark.png"
|
|
133
|
+
alt="Dumbbell chart of time to resume after 1 s idle at p50 and p75, comparing the two versions. The full values are in the results table below."
|
|
134
|
+
width={2016}
|
|
135
|
+
height={700}
|
|
136
|
+
/>
|
|
137
|
+
|
|
138
|
+
### Streams
|
|
139
|
+
|
|
140
|
+
{/* generated:performance streams */}
|
|
141
|
+
|
|
142
|
+
The agent produced its 2,593-chunk response over 52.4 s. On v4.8.12 the writer step manages about 12 chunks per second, so the response takes 226.1 s to reach the reader. v5.2.0 writes streams over a WebSocket by default, keeps up at about 49 chunks per second, and delivers the response in 53.5 s.
|
|
143
|
+
|
|
144
|
+
At p75, a chunk reaches the reader in 102 ms on v5.2.0 against 172 ms on v4.8.12. v5.2.0 had a chunk delayed by over 1 s in 0 of 10 runs, against 6 of 10 on v4.8.12.
|
|
145
|
+
|
|
146
|
+
{/* end generated:performance streams */}
|
|
147
|
+
|
|
148
|
+
On the Vercel World, [`WORKFLOW_STREAMS_TRANSPORT`](/docs/configuration/worlds#workflow_streams_transport) sets the transport for stream writes.
|
|
149
|
+
|
|
150
|
+
<Image
|
|
151
|
+
srcLight="/performance/v5.2.0/05-streams-light.png"
|
|
152
|
+
srcDark="/performance/v5.2.0/05-streams-dark.png"
|
|
153
|
+
alt="Three charts of a replayed agent stream comparing the two versions: the time to deliver the whole response against the recording's length, chunk trip time at p50 and p75, and the number of runs with a chunk delayed by over 1 s. The full values are in the results table below."
|
|
154
|
+
width={2016}
|
|
155
|
+
height={1628}
|
|
156
|
+
/>
|
|
157
|
+
|
|
158
|
+
### All results
|
|
159
|
+
|
|
160
|
+
Every measured value from the latest results. Percentiles follow the [methodology](#methodology) above.
|
|
161
|
+
|
|
162
|
+
{/* generated:performance table */}
|
|
163
|
+
|
|
164
|
+
| Metric | v4.8.12 | v5.2.0 | Change | Samples per version |
|
|
165
|
+
| --- | --: | --: | --: | --: |
|
|
166
|
+
| **Sequential workflow, 5 steps, 10 runs** | | | | |
|
|
167
|
+
| Time to first step, p75 | 418 ms | 172 ms | 2.4× faster | 10 runs |
|
|
168
|
+
| Time to first step, slowest run | 451 ms | 253 ms | 1.8× faster | 10 runs |
|
|
169
|
+
| Step-to-step overhead, p75 | 618 ms | 109 ms | 5.7× faster | 40 gaps |
|
|
170
|
+
| Step-to-step overhead, p99 | 777 ms | 327 ms | 2.4× faster | 40 gaps |
|
|
171
|
+
| **Long run, 1,020 steps, 5 runs** | | | | |
|
|
172
|
+
| Step overhead, steps 1 to 20, p75 | 622 ms | 110 ms | 5.7× faster | 95 gaps |
|
|
173
|
+
| Step overhead, steps 101 to 120, p75 | 719 ms | 74 ms | 9.7× faster | 95 gaps |
|
|
174
|
+
| Step overhead, steps 1,001 to 1,020, p75 | 1,748 ms | 70 ms | 25.0× faster | 95 gaps |
|
|
175
|
+
| Whole run, median wall time | 21.0 min | 3.0 min | 7.0× faster | 5 runs |
|
|
176
|
+
| **Fan-out, 64 parallel branches, 25 runs** | | | | |
|
|
177
|
+
| First branch starts, p75 | 478 ms | 360 ms | 1.3× faster | 25 runs |
|
|
178
|
+
| Slowest branch to start, p75 | 972 ms | 996 ms | No change | 25 runs |
|
|
179
|
+
| Join, p75 | 464 ms | 448 ms | No change | 25 runs |
|
|
180
|
+
| **Resume after 1 s idle, 25 runs of 5 resumes** | | | | |
|
|
181
|
+
| Time to resume, p50 | 619 ms | 383 ms | 1.6× faster | 125 resumes |
|
|
182
|
+
| Time to resume, p75 | 699 ms | 425 ms | 1.6× faster | 125 resumes |
|
|
183
|
+
| **Agent stream, 52.4 s recording, 10 runs** | | | | |
|
|
184
|
+
| Delivery, median wall time | 226.1 s | 53.5 s | 4.2× faster | 10 runs |
|
|
185
|
+
| Chunk trip time, p75 | 172 ms | 102 ms | 1.7× faster | 25,930 chunks |
|
|
186
|
+
|
|
187
|
+
{/* end generated:performance table */}
|
package/docs/whats-new.mdx
CHANGED
|
@@ -27,6 +27,15 @@ npx skills add https://github.com/vercel/workflow --skill migrating-workflow-v4-
|
|
|
27
27
|
|
|
28
28
|
### Faster and cheaper runs
|
|
29
29
|
|
|
30
|
+
<Image
|
|
31
|
+
srcLight="/performance/v5.2.0/01-overview-light.png"
|
|
32
|
+
srcDark="/performance/v5.2.0/01-overview-dark.png"
|
|
33
|
+
alt="Dot plot of how many times faster v5.2.0 is than v4.8.12 at p75 on each benchmark, on a log scale. Every benchmark is faster or unchanged."
|
|
34
|
+
caption="At p75, v5.2.0 is as fast as or faster than v4.8.12 on every benchmark."
|
|
35
|
+
width={2016}
|
|
36
|
+
height={1444}
|
|
37
|
+
/>
|
|
38
|
+
|
|
30
39
|
The largest change in v5 has no API surface: the runtime does far less work per unit of progress. The time between calling `start()` and your first step body executing is now less than half of what it was in v4. This is made possible by many smaller optimizations:
|
|
31
40
|
|
|
32
41
|
**A workflow invocation now does as much as it can in a single pass.** In 4.x, progress was largely deferred to the queue: an invocation would execute a step, hand back to the queue, and let a fresh invocation pick up the next one. v5 creates and executes several steps inline per suspension, in parallel, and only uses the queue for a wait, a hook, or when the function approaches its timeout.
|
|
@@ -49,6 +58,28 @@ On [Vercel Workflows](/worlds/vercel) these benefits compound to reduce compute
|
|
|
49
58
|
|
|
50
59
|
How much work fits in one invocation now scales with the function's own limit: the inline budget is derived from the runtime deadline the World reports, so raising `maxDuration` widens it without configuration. See [`WORKFLOW_V2_TIMEOUT_MS`](/docs/configuration/runtime-tuning#workflow_v2_timeout_ms).
|
|
51
60
|
|
|
61
|
+
Benchmarks on Vercel compare v5.2.0 with v4.8.12:
|
|
62
|
+
|
|
63
|
+
<Image
|
|
64
|
+
srcLight="/performance/v5.2.0/02-sequential-light.png"
|
|
65
|
+
srcDark="/performance/v5.2.0/02-sequential-dark.png"
|
|
66
|
+
alt="Three charts: v5.2.0 reaches the first step and moves between steps sooner than v4.8.12; through a 1,020-step run, step-to-step overhead on v4.8.12 grows toward the end while v5.2.0 stays flat; and v5.2.0 finishes all 1,020 steps several times sooner."
|
|
67
|
+
caption="Step-to-step overhead stays flat through a 1,020-step run on v5.2.0, while on v4.8.12 it grows with the event log."
|
|
68
|
+
width={2016}
|
|
69
|
+
height={2328}
|
|
70
|
+
/>
|
|
71
|
+
|
|
72
|
+
<Image
|
|
73
|
+
srcLight="/performance/v5.2.0/05-streams-light.png"
|
|
74
|
+
srcDark="/performance/v5.2.0/05-streams-dark.png"
|
|
75
|
+
alt="Three charts of a replayed agent stream: v5.2.0 delivers the response in about the recording's length while v4.8.12 takes about four times as long, v5.2.0 has a shorter chunk trip time, and no v5.2.0 run had a chunk delayed by over 1 s."
|
|
76
|
+
caption="v5.2.0 writes streams over a WebSocket by default and keeps pace with a recorded agent stream that v4.8.12 falls behind."
|
|
77
|
+
width={2016}
|
|
78
|
+
height={1628}
|
|
79
|
+
/>
|
|
80
|
+
|
|
81
|
+
See [Performance](/docs/performance) for how these benchmarks are measured, the full results, and their limits.
|
|
82
|
+
|
|
52
83
|
### Multi-region support
|
|
53
84
|
|
|
54
85
|
Workflow run IDs are now tagged with the compute region they were created in, or the region specified when calling `start()`. Worlds can use this to pin execution to that region.
|
|
@@ -154,7 +185,7 @@ All three first-party Worlds now implement it: Vercel accepts up to 30 days, and
|
|
|
154
185
|
- **A run cannot be forked across environments.** `start()` stamps the environment it was called from onto the queue message, and a deployment refuses a delivery whose run was created in a different environment. Previously a preview client and a production deployment could each hold half of one run ID.
|
|
155
186
|
- **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)).
|
|
156
187
|
- **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).
|
|
157
|
-
- **A WebSocket transport for event writes** on the Vercel World, which
|
|
188
|
+
- **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`.
|
|
158
189
|
- **`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.
|
|
159
190
|
- **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.
|
|
160
191
|
|
|
@@ -42,6 +42,7 @@ interface WorldCapabilities {
|
|
|
42
42
|
active: boolean;
|
|
43
43
|
};
|
|
44
44
|
maxConcurrency?: boolean;
|
|
45
|
+
inBandFence?: boolean;
|
|
45
46
|
hookForceClaim?: boolean;
|
|
46
47
|
dynamicWorkflowCode?: boolean;
|
|
47
48
|
}
|
|
@@ -62,7 +63,7 @@ interface World extends Storage, Queue, Streamer {
|
|
|
62
63
|
|
|
63
64
|
`specVersion` is required. See [Declaring the spec version](#declaring-the-spec-version).
|
|
64
65
|
|
|
65
|
-
The optional `capabilities` object advertises additional behavior, and every capability **fails closed**. A missing member means "unsupported," and the runtime keeps its conservative behavior. Set `hookRetention.active` to `true` only when the World implements hook token retention. Set `maxConcurrency` only when the World's queue supports `maxConcurrency`-limited consumption, which `WORKFLOW_SEQUENTIAL_REPLAYS=1` uses. Set `hookForceClaim` only when the World implements [hook token takeover](/worlds/upgrading-to-v5#new-optional-surface). Without it, `createHook({ experimental_force: true })` fails the workflow when it registers the hook. Set `dynamicWorkflowCode` only when the World persists `dynamicWorkflowCode` from `run_created` (and from a `run_started` that creates the run), echoes it on the created run, and returns it from `runs.get` with `resolveData: 'all'`. Without it, `start()` refuses [dynamic workflows](/docs/advanced/dynamic-workflows). The code is sent inline unless the World also implements `uploadDynamicWorkflowCode` for large definitions.
|
|
66
|
+
The optional `capabilities` object advertises additional behavior, and every capability **fails closed**. A missing member means "unsupported," and the runtime keeps its conservative behavior. Set `hookRetention.active` to `true` only when the World implements hook token retention. Set `maxConcurrency` only when the World's queue supports `maxConcurrency`-limited consumption, which `WORKFLOW_SEQUENTIAL_REPLAYS=1` uses. Set `hookForceClaim` only when the World implements [hook token takeover](/worlds/upgrading-to-v5#new-optional-surface). Without it, `createHook({ experimental_force: true })` fails the workflow when it registers the hook. Set `dynamicWorkflowCode` only when the World persists `dynamicWorkflowCode` from `run_created` (and from a `run_started` that creates the run), echoes it on the created run, and returns it from `runs.get` with `resolveData: 'all'`. Without it, `start()` refuses [dynamic workflows](/docs/advanced/dynamic-workflows). The code is sent inline unless the World also implements `uploadDynamicWorkflowCode` for large definitions. Set `inBandFence` only when the World implements the [in-band writer fence](#optional-the-in-band-writer-fence).
|
|
66
67
|
|
|
67
68
|
[Slot-numbered event IDs](#event-id-allocation) are a contract requirement rather than a capability, so there is no flag or fallback path.
|
|
68
69
|
|
|
@@ -251,6 +252,31 @@ A rejection may include the events the caller was missing as `{ events, cursor }
|
|
|
251
252
|
|
|
252
253
|
The runtime handles a rejection wherever it arrives. It restarts the replay in-process from a corrected log and invokes a fresh replay after spending that budget. It never retries the rejected write as-is because a replay working from a corrected log derives different events. This behavior requires no declaration or capability.
|
|
253
254
|
|
|
255
|
+
### Optional: the in-band writer fence
|
|
256
|
+
|
|
257
|
+
The in-band writer fence keeps a run to one orchestrator writer when two orchestrator invocations of the same run overlap, for example a delivery that outlives its queue lease while a redelivery of the run is already running. A write made by the run's orchestrator is **in-band** (`params.inBand: true`). Everything else is **out-of-band**: a background step's own events, `hook_received` from `resumeHook()` and webhooks, `run_cancelled` from `cancel()`, and `attr_set` from `setAttributes()` outside the workflow.
|
|
258
|
+
|
|
259
|
+
The fence is optional, and the runtime does not send `inBand` yet, so a World without it stays fully supported. Declare `capabilities.inBandFence: true` when you implement all of the following:
|
|
260
|
+
|
|
261
|
+
- **Two counters per run.** Next to whatever allocates event positions, keep `seq`, the highest position allocated to any write, and `seqInBand`, the number of positions allocated to in-band writes. `run_created` counts as in-band and is never fenced itself, so a new run holds `seq = 1, seqInBand = 1` (`IN_BAND_SEQ_AT_RUN_CREATION` from `@workflow/world`).
|
|
262
|
+
- **List snapshot, or counters on a refusal.** On every `events.list()` page of a slot-numbered run, return `snapshot: { seq, seqInBand }`, read before the listing. A full load, followed to `hasMore: false`, covers every position up to the first page's `seq`. A fenced writer takes its count from that first page, never from counting events, because a count cannot tell which positions were in-band. If your store cannot read the counters on a list, you may list no snapshot, as long as every refusal carries both counters, read together (see below).
|
|
263
|
+
- **Fenced in-band creates.** An in-band write carries `expectedSeqInBand`. Accept it only when that equals `seqInBand`, and advance both counters by the positions it allocates in the same atomic operation as the allocation. On a mismatch, throw `InBandSupersededError` from `@workflow/errors` (HTTP 412, `in-band-superseded`) and write and allocate nothing, so a refusal never leaves a hole. A batch is one fenced allocation for the whole block.
|
|
264
|
+
- **Fence first.** Decide the fence before anything else the write does. A stale writer must touch no entity row. If the write updates entity state as well as appending, make the check, the update and the append one atomic operation (in Postgres, one transaction that locks the run's counter row first).
|
|
265
|
+
- **Missing count.** Answer an in-band write without `expectedSeqInBand` with a 400 (`WorkflowWorldError` with `status: 400`).
|
|
266
|
+
- **Out-of-band creates** (`inBand: false` or absent) allocate unconditionally, move `seq`, and never move `seqInBand`. The fence never refuses them.
|
|
267
|
+
|
|
268
|
+
`world-local`, `world-postgres` and `world-vercel` declare the fence. `world-vercel`'s backend fences in-band writes on every run with an event sequencer (spec version 7 and later). On an older run it answers an in-band write with a 400 (`WorkflowWorldError`, `code: 'in-band-fence-unsupported'`) rather than writing it unfenced, so a writer decides whether to fence from the run's spec version. Its list responses carry the snapshot only where the backend reports one, so a writer there can find none.
|
|
269
|
+
|
|
270
|
+
A writer that finds no snapshot takes its count from a refusal:
|
|
271
|
+
|
|
272
|
+
1. **Get the counters.** On a run it has just created, before any other in-band write, the count is `IN_BAND_SEQ_AT_RUN_CREATION`. Otherwise, send an in-band write with a count no run holds, such as `Number.MAX_SAFE_INTEGER`. The World refuses it and writes and allocates nothing, and the `InBandSupersededError` carries `seq` and `seqInBand`, read together after the fence refused the write.
|
|
273
|
+
2. **Load up to `seq`.** List the log until it holds position `seq` itself. A position can be allocated before its event is committed, so a listing that ends below `seq` is retried, not trusted.
|
|
274
|
+
3. **Write at `seqInBand`.** That log holds every in-band write `seqInBand` counts, so the writer sends its next in-band write with `expectedSeqInBand: seqInBand`, and advances by the positions each accepted write allocated.
|
|
275
|
+
|
|
276
|
+
A writer that was refused while writing stops writing from the log it held; only a writer that loads the log again, as above, takes up the refusal's counters.
|
|
277
|
+
|
|
278
|
+
The conformance suite in [`packages/world/src/test-support/in-band-fence-conformance.ts`](https://github.com/vercel/workflow/blob/main/packages/world/src/test-support/in-band-fence-conformance.ts) checks each rule against a World's `events` storage, and `createTestSuite()` from `@workflow/world-testing` checks the counters (from the snapshot, or from a refusal where the World lists none) and a stale in-band write end to end when the World declares the capability.
|
|
279
|
+
|
|
254
280
|
## Queue interface
|
|
255
281
|
|
|
256
282
|
The Queue interface handles asynchronous workflow execution, including queued step work:
|
|
@@ -277,11 +303,48 @@ interface Queue {
|
|
|
277
303
|
|
|
278
304
|
createQueueHandler(
|
|
279
305
|
queueNamePrefix: QueuePrefix,
|
|
280
|
-
handler: (
|
|
306
|
+
handler: (
|
|
307
|
+
message: unknown,
|
|
308
|
+
meta: {
|
|
309
|
+
attempt: number;
|
|
310
|
+
deliveryCount?: number;
|
|
311
|
+
createdAt?: Date;
|
|
312
|
+
queueName: ValidQueueName;
|
|
313
|
+
messageId: MessageId;
|
|
314
|
+
}
|
|
315
|
+
) => Promise<unknown>
|
|
281
316
|
): (req: Request) => Promise<Response>;
|
|
282
317
|
}
|
|
283
318
|
```
|
|
284
319
|
|
|
320
|
+
`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.
|
|
321
|
+
|
|
322
|
+
### Queue prefixes and delivery routes
|
|
323
|
+
|
|
324
|
+
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.
|
|
325
|
+
|
|
326
|
+
Only the Workflow SDK's handler is mounted at `/.well-known/workflow/v1/flow` (`WORKFLOW_FLOW_ROUTE` from `@workflow/world`). A World decides where every other prefix's messages go:
|
|
327
|
+
|
|
328
|
+
- **By subscription.** A World whose transport pushes each message to whatever subscribed to its topic, like the Vercel World, needs nothing more: the app subscribes the consumer's route to that prefix's topics.
|
|
329
|
+
- **By path.** A World that POSTs deliveries to the app itself should implement the optional `registerRoute(prefix, path)`: messages of `prefix` go to `path` on the app's base URL, and a prefix without a route goes to the flow route. Read the route at each delivery attempt, so a route registered after a message was enqueued takes its next attempt.
|
|
330
|
+
- **In process.** A World whose queue runs inside the app's process can also implement the optional `registerHandler(prefix, handler)`, which delivers a prefix's messages to `handler(request)` without HTTP. The request is the one a route serving `createQueueHandler(prefix, ...)` would receive, and it takes precedence over a route for the same prefix.
|
|
331
|
+
|
|
332
|
+
{/* @skip-typecheck - interface definition, not runnable code */}
|
|
333
|
+
```typescript
|
|
334
|
+
interface Queue {
|
|
335
|
+
// ...
|
|
336
|
+
registerHandler?(
|
|
337
|
+
prefix: QueuePrefix,
|
|
338
|
+
handler: (req: Request) => Promise<Response>
|
|
339
|
+
): void;
|
|
340
|
+
registerRoute?(prefix: QueuePrefix, path: string): void;
|
|
341
|
+
}
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
Keep a message's full queue name from `queue()` to its delivery, including its prefix. A World that delivers by path should also have `createQueueHandler(prefix, ...)` refuse a message outside `prefix` (the Local World answers 400), so a misrouted message is retried rather than run by the wrong consumer.
|
|
345
|
+
|
|
346
|
+
If your World re-enqueues active runs when it starts, send each run back to the queue namespace it recorded at creation, `executionContext.queueNamespace` (read it with `getRunQueueNamespace()` from `@workflow/world`), rather than to the starting process's own namespace. `reenqueueActiveRuns()` from `@workflow/world` does this. The Workflow SDK's `start()` records the namespace when one is set, and a library that creates its own runs records its own.
|
|
347
|
+
|
|
285
348
|
### Invocation delivery
|
|
286
349
|
|
|
287
350
|
Implement the optional `invoke` method to send an input to a workflow runner and
|
package/docs/worlds/local.mdx
CHANGED
|
@@ -117,9 +117,33 @@ WORKFLOW_TARGET_WORLD="./my-world.ts"
|
|
|
117
117
|
|
|
118
118
|
`createWorld()` also accepts `tag`, which scopes local storage files to a suffix. It is mainly used by test harnesses that share one `.workflow-data` directory.
|
|
119
119
|
|
|
120
|
+
### Queue consumers other than the Workflow SDK
|
|
121
|
+
|
|
122
|
+
The Local World delivers queue messages over HTTP to the app, and by default every message goes to the Workflow SDK's flow route, `/.well-known/workflow/v1/flow`. A library that consumes messages of its own on the same World, such as a durable agent harness, uses its own queue prefix (`__{namespace}_wkf_workflow_`) and tells the World where those go:
|
|
123
|
+
|
|
124
|
+
```typescript title="lib/agent-queue.ts" lineNumbers
|
|
125
|
+
import { getWorld } from "workflow/runtime";
|
|
126
|
+
|
|
127
|
+
const PREFIX = "__agent_wkf_workflow_";
|
|
128
|
+
|
|
129
|
+
export async function registerAgentQueue(
|
|
130
|
+
handler: (req: Request) => Promise<Response>
|
|
131
|
+
) {
|
|
132
|
+
const world = await getWorld();
|
|
133
|
+
// Over HTTP: deliveries for this prefix go to the app's own route.
|
|
134
|
+
world.registerRoute?.(PREFIX, "/api/agent/queue");
|
|
135
|
+
// In this process: deliveries skip HTTP entirely.
|
|
136
|
+
world.registerHandler?.(PREFIX, handler);
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
`registerHandler()` takes precedence over `registerRoute()` for the same prefix. A prefix with neither still goes to the flow route, which answers `400` for a prefix it does not handle, and the Local World retries the message every five seconds, so a route registered later takes the next attempt. When the World restarts, `start()` re-enqueues each active run to the queue namespace it recorded at creation (`executionContext.queueNamespace`), so register the route or handler before calling `start()`.
|
|
141
|
+
|
|
120
142
|
## Data directory layout
|
|
121
143
|
|
|
122
|
-
Each run's event and step files are stored in their own directory (`events/<runId>/`, `steps/<runId>/`).
|
|
144
|
+
Each run's event and step files are stored in their own directory (`events/<runId>/`, `steps/<runId>/`). Data written by `@workflow/world-local` releases before 5.1.0 uses a flat layout and is not migrated: when the World starts on a data directory that holds only flat-layout files, it logs a warning, deletes the directory, and starts with an empty one. The CLI and web UI only read the data directory and never delete it. Older releases see no events or steps in the new layout, so clear `.workflow-data` by hand before downgrading.
|
|
145
|
+
|
|
146
|
+
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.
|
|
123
147
|
|
|
124
148
|
## Limitations
|
|
125
149
|
|
package/docs/worlds/postgres.mdx
CHANGED
|
@@ -65,7 +65,7 @@ bunx --package @workflow/world-postgres bootstrap
|
|
|
65
65
|
```
|
|
66
66
|
|
|
67
67
|
<Callout type="info">
|
|
68
|
-
The migration is idempotent and can safely be run as a post-deployment lifecycle script.
|
|
68
|
+
The migration is idempotent and can safely be run as a post-deployment lifecycle script. Run it again when you upgrade `@workflow/world-postgres`: a release can add migrations that the upgraded World needs before it handles workflows.
|
|
69
69
|
</Callout>
|
|
70
70
|
|
|
71
71
|
## Starting the World
|
|
@@ -320,14 +320,18 @@ export default createWorld({
|
|
|
320
320
|
});
|
|
321
321
|
```
|
|
322
322
|
|
|
323
|
-
|
|
323
|
+
You can also pass an existing `pg.Pool` as `pool` instead of a connection string. On a pool it creates, the World logs and drops an idle connection that the database closes, for example on a restart. A pool you pass needs its own `pool.on("error", ...)` listener. Without one, Node.js throws the error as an uncaught exception and the process exits.
|
|
324
324
|
|
|
325
|
-
|
|
325
|
+
Options passed to `createWorld()` take precedence over the environment variables above. Export the World from a module and point `WORKFLOW_TARGET_WORLD` at that module:
|
|
326
326
|
|
|
327
327
|
```bash title=".env"
|
|
328
328
|
WORKFLOW_TARGET_WORLD="./my-world.ts"
|
|
329
329
|
```
|
|
330
330
|
|
|
331
|
+
### Queue consumers other than the Workflow SDK
|
|
332
|
+
|
|
333
|
+
The worker delivers every job over HTTP, and by default to the Workflow SDK's flow route, `/.well-known/workflow/v1/flow`. A library that consumes messages of its own on the same World, such as a durable agent harness, uses its own queue prefix (`__{namespace}_wkf_workflow_`) and registers where those go: `world.registerRoute(prefix, "/api/agent/queue")` to deliver them to its own route, or `world.registerHandler(prefix, handler)` to deliver them inside the process that took the job, without HTTP. A job keeps the prefix it was enqueued under and the route its producer had registered, so a worker in another process delivers it to the same place. Register before calling `start()`, which re-enqueues each active run to the queue namespace it recorded at creation (`executionContext.queueNamespace`).
|
|
334
|
+
|
|
331
335
|
### Application-managed shutdown
|
|
332
336
|
|
|
333
337
|
Graphile Worker responds automatically when the application is asked to shut down. If your application or framework already coordinates a broader shutdown sequence, set `WORKFLOW_POSTGRES_APPLICATION_MANAGED_SHUTDOWN=1` when selecting the package directly with `WORKFLOW_TARGET_WORLD`, or set `applicationManagedShutdown: true` in a programmatic World. Use the application's normal shutdown hook. This prevents Graphile Worker's default handler from terminating the process as soon as its queue stops. The hook must handle cleanup errors and await resources in this order:
|
|
@@ -361,6 +365,8 @@ The other routes under `/.well-known/workflow/v1/` differ:
|
|
|
361
365
|
- `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.
|
|
362
366
|
- `manifest.json` responds with `404` unless the app was built with `WORKFLOW_PUBLIC_MANIFEST=1`. That variable is read at build time, so unsetting it in the runtime environment of an already-built deployment does not withdraw the manifest. Leave it unset outside of testing, because the manifest lists your workflow and step names.
|
|
363
367
|
|
|
368
|
+
A queue consumer that registered its own route with `registerRoute()` receives deliveries the same way, so protect that route like the flow route.
|
|
369
|
+
|
|
364
370
|
### Bringing your own auth
|
|
365
371
|
|
|
366
372
|
Workflow does not prescribe an auth mechanism for self-hosted Worlds, so restrict the flow route at the network edge rather than inside the application:
|
package/docs/worlds/vercel.mdx
CHANGED
|
@@ -128,6 +128,24 @@ const run = await start(myWorkflow, [input], { region: "sfo1" });
|
|
|
128
128
|
- Runs created by 4.x SDKs, including runs that existed before you upgraded, live in `iad1` and are unaffected by an upgrade. There is no migration.
|
|
129
129
|
- **Hook tokens are currently stored in `iad1`** for every run, regardless of the run's region. The token-to-run mapping that powers [`getHookByToken()`](/docs/api-reference/workflow-api/get-hook-by-token) and [`resumeHook()`](/docs/api-reference/workflow-api/resume-hook) lives there so tokens without region information can always be resolved. Hook *payloads* are not affected. A received payload is recorded on the run's event log, which lives in the run's region like all other run data. This token placement may become a project-level setting in the future.
|
|
130
130
|
|
|
131
|
+
## Queue consumers other than the Workflow SDK
|
|
132
|
+
|
|
133
|
+
The Vercel World delivers each queue message to the functions subscribed to its topic, not to a fixed path. The Workflow SDK's build integration subscribes the generated flow route to `__wkf_workflow_*` (or `__{namespace}_wkf_workflow_*`). A library that consumes messages of its own on the same World, such as a durable agent harness, uses its own queue prefix and subscribes its own route to that prefix's topics:
|
|
134
|
+
|
|
135
|
+
```json title="vercel.json"
|
|
136
|
+
{
|
|
137
|
+
"functions": {
|
|
138
|
+
"app/api/agent/queue/route.ts": {
|
|
139
|
+
"experimentalTriggers": [
|
|
140
|
+
{ "type": "queue/v2beta", "topic": "__agent_wkf_workflow_*" }
|
|
141
|
+
]
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
The route serves `world.createQueueHandler("__agent_wkf_workflow_", handler)`. Topic names replace characters other than letters, digits, `-` and `_` with `-`. The Vercel World has no `registerRoute()` or `registerHandler()`: a message reaches a function only through a subscription declared at deploy time. Every subscribed function receives its own copy of a message and runs it, whatever prefix its handler was created with, so subscribe each route only to its own prefix's topics.
|
|
148
|
+
|
|
131
149
|
## Limitations
|
|
132
150
|
|
|
133
151
|
- **No run migration**: A run's region is fixed at creation. Existing runs cannot be moved to a different region.
|
|
@@ -347,6 +365,8 @@ export default createWorld({
|
|
|
347
365
|
WORKFLOW_TARGET_WORLD="./my-world.ts"
|
|
348
366
|
```
|
|
349
367
|
|
|
368
|
+
Pass `dispatcher` (for example an undici `Agent`) to replace the World's HTTP dispatchers, including the queue's and the one for stream writes. The default stream writer retries a write that was rejected with a 429 (after its `Retry-After`) or that failed to connect, sending a fresh request each time. A custom dispatcher turns that retry off. Don't configure a custom dispatcher to retry stream write `PUT` requests itself, because a retry after a 5xx or a dropped connection can append a chunk the server already stored.
|
|
369
|
+
|
|
350
370
|
## Versioning
|
|
351
371
|
|
|
352
372
|
On Vercel, workflow runs are pegged to the deployment that started them. This means:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "workflow",
|
|
3
|
-
"version": "5.2.
|
|
3
|
+
"version": "5.2.2",
|
|
4
4
|
"description": "Workflow SDK - Build durable, resilient, and observable workflows",
|
|
5
5
|
"main": "dist/typescript-plugin.cjs",
|
|
6
6
|
"type": "module",
|
|
@@ -58,19 +58,19 @@
|
|
|
58
58
|
}
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@workflow/astro": "5.0.
|
|
62
|
-
"@workflow/cli": "5.0.
|
|
63
|
-
"@workflow/core": "5.2.
|
|
64
|
-
"@workflow/errors": "5.0.
|
|
61
|
+
"@workflow/astro": "5.0.5",
|
|
62
|
+
"@workflow/cli": "5.0.5",
|
|
63
|
+
"@workflow/core": "5.2.2",
|
|
64
|
+
"@workflow/errors": "5.0.4",
|
|
65
65
|
"@workflow/typescript-plugin": "5.0.0",
|
|
66
|
-
"@workflow/utils": "5.0.
|
|
66
|
+
"@workflow/utils": "5.0.2",
|
|
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.0.5",
|
|
69
|
+
"@workflow/nest": "5.1.3",
|
|
70
|
+
"@workflow/nitro": "5.0.5",
|
|
71
|
+
"@workflow/nuxt": "5.0.5",
|
|
72
|
+
"@workflow/sveltekit": "5.0.5",
|
|
73
|
+
"@workflow/rollup": "5.0.5"
|
|
74
74
|
},
|
|
75
75
|
"devDependencies": {
|
|
76
76
|
"@types/ms": "2.1.0",
|