workflow 5.3.0 → 5.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. package/docs/api-reference/workflow/create-hook.mdx +1 -1
  2. package/docs/api-reference/workflow/create-webhook.mdx +1 -1
  3. package/docs/api-reference/workflow/fetch.mdx +1 -5
  4. package/docs/api-reference/workflow-api/get-hook-by-token.mdx +2 -2
  5. package/docs/api-reference/workflow-api/resume-hook.mdx +2 -2
  6. package/docs/api-reference/workflow-api/start.mdx +12 -8
  7. package/docs/api-reference/workflow-errors/hook-conflict-error.mdx +2 -2
  8. package/docs/api-reference/workflow-errors/index.mdx +1 -1
  9. package/docs/api-reference/workflow-errors/workflow-start-error.mdx +5 -5
  10. package/docs/api-reference/workflow-runtime/world/storage.mdx +1 -1
  11. package/docs/changelog/eager-processing.mdx +2 -0
  12. package/docs/configuration/cli-and-web-ui.mdx +4 -2
  13. package/docs/configuration/runtime-tuning.mdx +7 -0
  14. package/docs/configuration/worlds.mdx +1 -1
  15. package/docs/cookbook/advanced/child-workflows.mdx +126 -186
  16. package/docs/cookbook/common-patterns/idempotency.mdx +2 -2
  17. package/docs/cookbook/common-patterns/sequential-and-parallel.mdx +1 -1
  18. package/docs/cookbook/common-patterns/workflow-composition.mdx +5 -5
  19. package/docs/errors/fetch-in-workflow.mdx +15 -35
  20. package/docs/foundations/hooks.mdx +1 -1
  21. package/docs/foundations/idempotency.mdx +11 -11
  22. package/docs/foundations/starting-workflows.mdx +3 -7
  23. package/docs/whats-new.mdx +1 -1
  24. package/docs/worlds/building-a-world.mdx +4 -4
  25. package/docs/worlds/postgres.mdx +7 -11
  26. package/docs/worlds/upgrading-to-v5.mdx +1 -1
  27. package/docs/worlds/vercel.mdx +3 -7
  28. package/package.json +10 -10
@@ -188,7 +188,7 @@ Custom hook tokens are the recommended way to coordinate active workflow runs. U
188
188
 
189
189
  ### Open the run's start Hook
190
190
 
191
- A run started with [`start(workflow, args, { hook: { token } })`](/docs/api-reference/workflow-api/start#prevent-duplicate-starts) already owns its token through its start Hook. Calling `createHook({ token })` with that token in the run returns a handle bound to the start Hook instead of registering a new one: it adds no step, `await hook.getConflict()` resolves `null`, and payloads resumed before the call are delivered in order. Set `metadata` and `experimental_minRetention` on `start({ hook })`; a start Hook can't be a webhook or force-claim its token. Passing any of `metadata`, `experimental_minRetention`, `isWebhook` or `experimental_force` to this `createHook()` throws. Open it with `const`: disposing the handle frees the token, as for any Hook, and a later `start()` with it is then admitted as a new run (see [Take care with the start Hook's lifecycle](/docs/api-reference/workflow-api/start#take-care-with-the-start-hooks-lifecycle)). See [Receive the payloads in the workflow](/docs/foundations/idempotency#receive-the-payloads-in-the-workflow).
191
+ A run started with [`start(workflow, args, { experimental_hook: { token } })`](/docs/api-reference/workflow-api/start#prevent-duplicate-starts) already owns its token through its start Hook. Calling `createHook({ token })` with that token in the run returns a handle bound to the start Hook instead of registering a new one: it adds no step, `await hook.getConflict()` resolves `null`, and payloads resumed before the call are delivered in order. Set `metadata` and `experimental_minRetention` on `start({ experimental_hook })`; a start Hook can't be a webhook or force-claim its token. Passing any of `metadata`, `experimental_minRetention`, `isWebhook` or `experimental_force` to this `createHook()` throws. Open it with `const`: disposing the handle frees the token, as for any Hook, and a later `start()` with it is then admitted as a new run (see [Take care with the start Hook's lifecycle](/docs/api-reference/workflow-api/start#take-care-with-the-start-hooks-lifecycle)). See [Receive the payloads in the workflow](/docs/foundations/idempotency#receive-the-payloads-in-the-workflow).
192
192
 
193
193
  ### Keep a token unavailable after the run ends
194
194
 
@@ -53,7 +53,7 @@ showSections={['returns']}
53
53
 
54
54
  The returned `Webhook` object has:
55
55
 
56
- - `url`: The HTTP endpoint URL that external systems can call
56
+ - `url`: The HTTP endpoint URL that external systems can call. On Vercel, it uses the deployment URL. Elsewhere, it's `http://localhost` on the `PORT` environment variable, or on the detected server port when `PORT` is unset
57
57
  - `token`: The unique token identifying this webhook
58
58
  - `getConflict()`: A promise that resolves with the conflicting run if another active hook already owns this token, or `null` once the webhook endpoint has been registered. The endpoint is registered alongside the steps the workflow starts at the same time, not ahead of them, so await `getConflict()` before a step that hands `url` to a caller who may request it right away. See [Registering a hook before a step uses it](/docs/api-reference/workflow/create-hook#registering-a-hook-before-a-step-uses-it).
59
59
  - Implements `AsyncIterable<T>` for handling multiple requests, where `T` is `Request` (default) or `RequestWithResponse` (manual mode)
@@ -91,11 +91,7 @@ We call `fetch()` with a URL and optional request options, like the standard fet
91
91
 
92
92
  This API lets you use `fetch` in a workflow. You can also implement a custom fetch for different error handling and retry logic.
93
93
 
94
- ### Reading the response body
95
-
96
- Inside a workflow function, `response.json()`, `response.text()`, and `response.arrayBuffer()` each read the body through a step, so the result is recorded in the event log and replays deterministically.
97
-
98
- `response.body` can also be read with `getReader()` or `for await`, which is how libraries such as the AI SDK read responses. The whole body is loaded through a single step and delivered as one chunk. The body is not marked as used after a read: each new reader or body method runs its own step, so read the body once and reuse the result. Incremental streaming APIs such as `pipeThrough()` and `tee()` are not available in workflow functions. To process a response as a stream, read it inside a step function.
94
+ Libraries that call `fetch` internally, like AI SDK calls, should be called from a step function. For agents, use AI SDK's [`WorkflowAgent`](https://ai-sdk.dev/v7/docs/agents/workflow-agent#workflowagent). See [`fetch-in-workflow`](/docs/errors/fetch-in-workflow).
99
95
 
100
96
  ### Customizing fetch behavior
101
97
 
@@ -13,7 +13,7 @@ Retrieves a hook by its unique token, returning the associated workflow run info
13
13
 
14
14
  When `experimental_minRetention` is set, this function continues to return the Hook after its workflow ends until retention ends. That Hook cannot be resumed. Use `getRun(hook.runId)` to inspect the finished run.
15
15
 
16
- A run started with [`start({ hook })`](/docs/api-reference/workflow-api/start#prevent-duplicate-starts) has its start Hook from the moment it is admitted, so this function returns it right away, with the `hook.metadata` passed to `start()`, even before the run starts executing.
16
+ A run started with [`start({ experimental_hook })`](/docs/api-reference/workflow-api/start#prevent-duplicate-starts) has its start Hook from the moment it is admitted, so this function returns it right away, with the `hook.metadata` passed to `start()`, even before the run starts executing.
17
17
 
18
18
  When the Hook was created with [`experimental_force`](/docs/api-reference/workflow/create-hook#take-over-a-token-another-run-holds) and took its token from another run, `hook.claimedFrom` names that run and its Hook. A lookup always follows the token to its current owner, so the same token returns the new Hook as soon as the takeover happens.
19
19
 
@@ -28,7 +28,7 @@ To deliver several payloads to the same Hook, store the returned Hook and pass i
28
28
  </Callout>
29
29
 
30
30
  <Callout type="info">
31
- Looking up a deterministic hook token is useful in hook-based idempotency flows, but it is only an advisory check. If no hook exists yet, another request can still start the same workflow before your `start()` call registers its hook. Use the lookup to avoid obvious duplicate starts, and handle the race inside the workflow by checking `await hook.getConflict()` before duplicate-sensitive work. On a conflict it resolves with the run that owns the token, so the duplicate can route the caller to the active owner. To reject duplicates before a workflow body runs, use [`start({ hook })`](/docs/api-reference/workflow-api/start#prevent-duplicate-starts) instead. See [Run idempotency](/docs/foundations/idempotency#run-idempotency).
31
+ Looking up a deterministic hook token is useful in hook-based idempotency flows, but it is only an advisory check. If no hook exists yet, another request can still start the same workflow before your `start()` call registers its hook. Use the lookup to avoid obvious duplicate starts, and handle the race inside the workflow by checking `await hook.getConflict()` before duplicate-sensitive work. On a conflict it resolves with the run that owns the token, so the duplicate can route the caller to the active owner. To reject duplicates before a workflow body runs, use [`start({ experimental_hook })`](/docs/api-reference/workflow-api/start#prevent-duplicate-starts) instead. See [Run idempotency](/docs/foundations/idempotency#run-idempotency).
32
32
  </Callout>
33
33
 
34
34
  ```typescript lineNumbers
@@ -16,7 +16,7 @@ It durably writes the `hook_received` event and only then publishes a workflow w
16
16
 
17
17
  `resumeHook()` throws `HookNotFoundError` when no hook holds the token or when its `hook_received` write is refused because the hook was disposed or the run ended. See [durable hook resume](/docs/changelog/lazy-hook-resume).
18
18
 
19
- A run started with [`start({ hook })`](/docs/api-reference/workflow-api/start#prevent-duplicate-starts) has its start Hook from the moment it is admitted, so `resumeHook()` with that token works right away, even before the run starts executing. Payloads sent before the workflow calls `createHook({ token })` are kept and delivered in order once it does. See [Start or route to the owner](/docs/foundations/idempotency#start-or-route-to-the-owner).
19
+ A run started with [`start({ experimental_hook })`](/docs/api-reference/workflow-api/start#prevent-duplicate-starts) has its start Hook from the moment it is admitted, so `resumeHook()` with that token works right away, even before the run starts executing. Payloads sent before the workflow calls `createHook({ token })` are kept and delivered in order once it does. See [Start or route to the owner](/docs/foundations/idempotency#start-or-route-to-the-owner).
20
20
 
21
21
  Other errors can occur before or after persistence. A lost write response leaves
22
22
  the write's outcome unknown; a failed workflow wake can leave an already durable
@@ -222,7 +222,7 @@ export async function POST(request: Request) {
222
222
 
223
223
  A common endpoint shape is "resume or start": one route that resumes the active workflow run for a business key if one exists, or starts a new run otherwise. This comes up when the workflow uses a deterministic hook token as its idempotency key, for example, one active run per order or conversation.
224
224
 
225
- On a World that supports [`start({ hook })`](/docs/api-reference/workflow-api/start#prevent-duplicate-starts), flip the order: start with the token first, and on `HookConflictError` resume the owner's start Hook, which accepts payloads right away. See [Start or route to the owner](/docs/foundations/idempotency#start-or-route-to-the-owner). Without it, use the pattern below.
225
+ On a World that supports [`start({ experimental_hook })`](/docs/api-reference/workflow-api/start#prevent-duplicate-starts), flip the order: start with the token first, and on `HookConflictError` resume the owner's start Hook, which accepts payloads right away. See [Start or route to the owner](/docs/foundations/idempotency#start-or-route-to-the-owner). Without it, use the pattern below.
226
226
 
227
227
  `resumeHook()` is the resume half of that flow. Try it first; if it throws `HookNotFoundError`, no active run owns the token yet, so start the workflow. One subtlety: `start()` returns before the new run executes and registers its hook, so you cannot resume immediately after starting. Retry the resume until the hook is registered: if you drop the payload and only start the workflow, the data from this request is lost.
228
228
 
@@ -57,7 +57,7 @@ Learn more about [`WorkflowReadableStreamOptions`](/docs/api-reference/workflow-
57
57
  * In v5, you can also call `start()` directly from a workflow function to spawn a child run or continue work in a new run. See [Workflow Composition](/cookbook/common-patterns/workflow-composition) and [Versioning](/docs/foundations/versioning).
58
58
  * This is different from calling workflow functions directly, which is the typical pattern in Next.js applications.
59
59
  * The function returns immediately after enqueuing the workflow. It doesn't wait for the workflow to complete.
60
- * Each call to `start()` creates a new workflow run, unless you pass `hook`. With a deterministic `hook.token`, at most one run can own the token, and a duplicate start throws [`HookConflictError`](/docs/api-reference/workflow-errors/hook-conflict-error) naming the owner instead of creating a run. See [Prevent duplicate starts](#prevent-duplicate-starts) and [Idempotency](/docs/foundations/idempotency#run-idempotency).
60
+ * Each call to `start()` creates a new workflow run, unless you pass `experimental_hook`. With a deterministic `experimental_hook.token`, at most one run can own the token, and a duplicate start throws [`HookConflictError`](/docs/api-reference/workflow-errors/hook-conflict-error) naming the owner instead of creating a run. See [Prevent duplicate starts](#prevent-duplicate-starts) and [Idempotency](/docs/foundations/idempotency#run-idempotency).
61
61
  * All arguments must be [serializable](/docs/foundations/serialization).
62
62
  * When you provide `deploymentId`, the argument types and return type become `unknown` because the workflow function's types may differ across deployments.
63
63
  * When `deploymentId` names a deployment other than the caller's, the run is stamped with the spec version the *target* deployment reports on its capability probe (capped at the caller's own), since the target is what executes it. `start()` waits up to 10 seconds for the first probe to a deployment and returns as soon as the target answers; later starts to the same deployment reuse the answer. If the target does not answer in time, the run is stamped with spec version 6, the lowest version a v5 runtime executes; a target on an older major version (such as `stable`) cannot execute such a run, so it logs a warning. In either case, the `attributes` and `experimental_retention` checks below apply to the stamped version, and fail naming the target deployment.
@@ -74,7 +74,7 @@ If `start()` throws `'start' received an invalid workflow function. Ensure the W
74
74
 
75
75
  ### Prevent duplicate starts
76
76
 
77
- Pass a `hook` with a token from your domain to make the start idempotent. The World admits the run and creates its start Hook in one atomic step, before any workflow code runs:
77
+ Pass an `experimental_hook` with a token from your domain to make the start idempotent. The World admits the run and creates its start Hook in one atomic step, before any workflow code runs:
78
78
 
79
79
  ```typescript lineNumbers
80
80
  import { start } from "workflow/api";
@@ -86,7 +86,7 @@ export async function POST(request: Request) {
86
86
 
87
87
  try {
88
88
  const run = await start(processOrder, [orderId], {
89
- hook: { // [!code highlight]
89
+ experimental_hook: { // [!code highlight]
90
90
  token: `order:${orderId}`, // [!code highlight]
91
91
  experimental_minRetention: "30 days", // [!code highlight]
92
92
  metadata: { orderId }, // [!code highlight]
@@ -106,7 +106,7 @@ export async function POST(request: Request) {
106
106
  }
107
107
  ```
108
108
 
109
- `hook` takes:
109
+ `experimental_hook` takes:
110
110
 
111
111
  | Option | Description |
112
112
  | --- | --- |
@@ -116,13 +116,13 @@ export async function POST(request: Request) {
116
116
 
117
117
  * Exactly one run owns the token. A duplicate throws [`HookConflictError`](/docs/api-reference/workflow-errors/hook-conflict-error) with the owner's `conflictingRunId`. The duplicate never becomes a run, and none of its code runs.
118
118
  * The start Hook exists from the moment the run is admitted, so [`resumeHook(token, payload)`](/docs/api-reference/workflow-api/resume-hook) works right away, even before the run starts executing. Payloads resumed before the workflow opens the Hook are kept and delivered in order once it does.
119
- * In the workflow, `createHook({ token })` with the same token returns a handle bound to the start Hook. It doesn't register a new Hook, so it adds no step, and `getConflict()` resolves `null`. Set `metadata` and `experimental_minRetention` on `start({ hook })`; a start Hook can't be a webhook or force-claim its token. Passing any of `metadata`, `experimental_minRetention`, `isWebhook` or `experimental_force` to that `createHook()` throws. If the workflow never opens the Hook, the token is only an idempotency key: the run completes normally and unread payloads are left unread.
119
+ * In the workflow, `createHook({ token })` with the same token returns a handle bound to the start Hook. It doesn't register a new Hook, so it adds no step, and `getConflict()` resolves `null`. Set `metadata` and `experimental_minRetention` on `start({ experimental_hook })`; a start Hook can't be a webhook or force-claim its token. Passing any of `metadata`, `experimental_minRetention`, `isWebhook` or `experimental_force` to that `createHook()` throws. If the workflow never opens the Hook, the token is only an idempotency key: the run completes normally and unread payloads are left unread.
120
120
  * The start Hook follows the ordinary Hook lifecycle. The token is released when the run ends, or once `experimental_minRetention` has passed if that is later. Disposing the start Hook releases it at once; see [Take care with the start Hook's lifecycle](#take-care-with-the-start-hooks-lifecycle). On a World without Hook retention, `experimental_minRetention` makes `start()` throw.
121
121
  * If `start()` cannot confirm whether the run was queued or admitted, it asks the World again a few times with the same candidate, then throws [`WorkflowStartError`](/docs/api-reference/workflow-errors/workflow-start-error) with the candidate's `runId` and the `stage` that failed. Retrying with the same token is safe: the retry either becomes the owner or throws `HookConflictError` naming it. Inside a workflow, the `start()` step retries it automatically, while a `HookConflictError` (or a permanent rejection) reaches the workflow on the first attempt.
122
122
  * If the run named by a `HookConflictError` is still `pending` more than a minute after it was created (its first queue message was most likely lost, so nothing will start it), the refused `start()` re-publishes that run's orchestrator message in the background, at most once a minute per run (per process, for a single-orchestrator run), and throws without waiting for it. The run then starts; the refusal itself is unchanged.
123
123
  * Rarely, a `HookConflictError` names a candidate that was admitted but never became a run, because the writer that admitted it died. `getRun()` doesn't find it. While the World can still create the run, resuming the token waits and may throw a retryable error with `retryAfter`; once it can't, the World releases the token and resuming throws `HookNotFoundError`. Start again with the same token then.
124
124
  * Stream arguments (for example a webhook's `request.body`) are read only once the run is admitted, so a refused duplicate leaves them untouched. Because `start()` confirms an uncertain admission before giving up, an admitted run usually still gets its input. If it throws `WorkflowStartError` anyway, the run may have been admitted and be waiting on input that will never arrive. Cancel it with [`getRun(error.runId).cancel()`](/docs/api-reference/workflow-api/get-run), which also works when the run doesn't exist yet (see [`WorkflowStartError`](/docs/api-reference/workflow-errors/workflow-start-error)).
125
- * The World must support atomic start Hooks (and Hook retention, when you set one). The Local World does; on the Postgres World it is behind [`WORKFLOW_POSTGRES_EXPERIMENTAL_START_HOOK`](/worlds/postgres#workflow_postgres_experimental_start_hook) and on the Vercel World behind [`WORKFLOW_VERCEL_EXPERIMENTAL_START_HOOK`](/worlds/vercel#workflow_vercel_experimental_start_hook). Otherwise `start()` throws before it enqueues anything. For a cross-deployment start, the target deployment must support it too. `hook` is not supported for [dynamic workflows](/docs/advanced/dynamic-workflows).
125
+ * The World must support atomic start Hooks (and Hook retention, when you set one). The Local, Postgres and Vercel Worlds do (the Postgres World after [migration `0028`](/worlds/postgres#start-hooks)). Otherwise `start()` throws before it enqueues anything. For a cross-deployment start, the target deployment must support it too. `hook` is not supported for [dynamic workflows](/docs/advanced/dynamic-workflows).
126
126
 
127
127
  To route a duplicate's payload to the run that owns the token, resume the owner's start Hook on a conflict. See [Start or route to the owner](/docs/foundations/idempotency#start-or-route-to-the-owner).
128
128
 
@@ -214,13 +214,17 @@ export async function parentWorkflow(value: number) {
214
214
  ```
215
215
 
216
216
  <Callout type="info">
217
- The returned `Run` object is fully functional inside a workflow. Each property access or method call (`.status`, `.returnValue`, `.cancel()`) executes as a separate step. See [Workflow Composition](/cookbook/common-patterns/workflow-composition) for choosing between spawning a child run and awaiting a workflow function directly.
217
+ The returned `Run` object is fully functional inside a workflow. Each property access or method call (`.status`, `.cancel()`) executes as a separate step. See [Workflow Composition](/cookbook/common-patterns/workflow-composition) for choosing between spawning a child run and awaiting a workflow function directly.
218
218
  </Callout>
219
219
 
220
+ Awaiting `returnValue` of a run the workflow started does not poll. The parent suspends on its system completion hook, a single hook shared by all of its children, and each child resumes it when it completes, fails, or is canceled through the SDK, so the wait costs no compute or worker slot and the parent resumes as soon as the child finishes. The same holds when the `Run` was returned from a step of the parent that called `start()`. See [Child Workflows](/cookbook/advanced/child-workflows#how-the-parent-waits).
221
+
220
222
  <Callout type="warn">
221
- `returnValue` polls the child run every second and holds the polling step's worker slot open for as long as the child takes to finish. For long-running children, spawn without awaiting `returnValue` and have the child resume a [hook](/docs/foundations/hooks) when it completes. See the [`startAndWait()` pattern](/cookbook/advanced/child-workflows).
223
+ A child canceled without the SDK (by a tool that writes the cancellation to the World directly) does not notify its parent. The parent finds out at its next safety-net check, 5 minutes after it starts waiting and then at doubling intervals up to 6 hours. See [Cancellations that bypass the SDK](/cookbook/advanced/child-workflows#cancellations-that-bypass-the-sdk).
222
224
  </Callout>
223
225
 
226
+ `returnValue` still polls when the waiting code is not the parent: a step, an API route, or another workflow handed the `Run`. It also polls for a child on another deployment (`deploymentId`) that predates the system hook, and for every child while `WORKFLOW_CHILD_RUN_COMPLETION_HOOK=0` is set. A polling step holds its worker slot until the child finishes.
227
+
224
228
  ### Dynamic Workflow Source
225
229
 
226
230
  <Callout type="warning">
@@ -2,7 +2,7 @@
2
2
  title: HookConflictError
3
3
  description: Thrown when creating a hook, or starting a run with a hook, whose token another workflow run owns.
4
4
  type: reference
5
- summary: Catch HookConflictError when a hook token is already owned by another workflow run, including a duplicate start({ hook }).
5
+ summary: Catch HookConflictError when a hook token is already owned by another workflow run, including a duplicate start({ experimental_hook }).
6
6
  related:
7
7
  - /docs/api-reference/workflow/create-hook
8
8
  - /docs/foundations/hooks
@@ -10,7 +10,7 @@ related:
10
10
  - /docs/foundations/idempotency
11
11
  ---
12
12
 
13
- `HookConflictError` is thrown when creating a hook, or calling [`start({ hook })`](/docs/api-reference/workflow-api/start#prevent-duplicate-starts), with a token that another workflow run owns. From `start()` it always carries `conflictingRunId`, and no run was created for the duplicate. The owner may still be running, or may have finished while an `experimental_minRetention` holds the token. To deliver the duplicate's data instead, resume the owner's start Hook: see [Start or route to the owner](/docs/foundations/idempotency#start-or-route-to-the-owner).
13
+ `HookConflictError` is thrown when creating a hook, or calling [`start({ experimental_hook })`](/docs/api-reference/workflow-api/start#prevent-duplicate-starts), with a token that another workflow run owns. From `start()` it always carries `conflictingRunId`, and no run was created for the duplicate. The owner may still be running, or may have finished while an `experimental_minRetention` holds the token. To deliver the duplicate's data instead, resume the owner's start Hook: see [Start or route to the owner](/docs/foundations/idempotency#start-or-route-to-the-owner).
14
14
 
15
15
  When creating a hook, it means the token is already in use by another active workflow run. Hook tokens must be unique across all running workflows. See the [hook-conflict](/docs/errors/hook-conflict) error guide for resolution strategies. To take the token over instead, create the hook with [`experimental_force: true`](/docs/api-reference/workflow/create-hook#take-over-a-token-another-run-holds).
16
16
 
@@ -52,7 +52,7 @@ All errors extend [`WorkflowError`](/docs/api-reference/workflow-errors/workflow
52
52
  Thrown when the workflow runtime encounters an execution error, such as serialization failures or timeouts.
53
53
  </Card>
54
54
  <Card href="/docs/api-reference/workflow-errors/workflow-start-error" title="WorkflowStartError">
55
- Thrown when `start({ hook })` cannot confirm whether its run was queued or admitted.
55
+ Thrown when `start({ experimental_hook })` cannot confirm whether its run was queued or admitted.
56
56
  </Card>
57
57
  <Card href="/docs/api-reference/workflow-errors/run-expired-error" title="RunExpiredError">
58
58
  Thrown when a workflow run has expired and can no longer be operated on.
@@ -2,13 +2,13 @@
2
2
  title: WorkflowStartError
3
3
  description: Thrown when start with a hook cannot confirm whether its run was queued or admitted.
4
4
  type: reference
5
- summary: Catch WorkflowStartError to identify a start({ hook }) candidate whose outcome is unknown, then retry with the same token.
5
+ summary: Catch WorkflowStartError to identify a start({ experimental_hook }) candidate whose outcome is unknown, then retry with the same token.
6
6
  related:
7
7
  - /docs/api-reference/workflow-api/start
8
8
  - /docs/foundations/idempotency
9
9
  ---
10
10
 
11
- `WorkflowStartError` is thrown when [`start({ hook })`](/docs/api-reference/workflow-api/start#prevent-duplicate-starts) cannot confirm whether its candidate run was queued or admitted, for example because the World timed out. The outcome is unknown, not failed: the candidate may still become the run that owns the token.
11
+ `WorkflowStartError` is thrown when [`start({ experimental_hook })`](/docs/api-reference/workflow-api/start#prevent-duplicate-starts) cannot confirm whether its candidate run was queued or admitted, for example because the World timed out. The outcome is unknown, not failed: the candidate may still become the run that owns the token.
12
12
 
13
13
  ```typescript lineNumbers
14
14
  import { start } from "workflow/api";
@@ -19,13 +19,13 @@ declare const orderId: string; // @setup
19
19
  async function startOrder() {
20
20
  try {
21
21
  return await start(processOrder, [orderId], {
22
- hook: { token: `order:${orderId}`, experimental_minRetention: "1h" },
22
+ experimental_hook: { token: `order:${orderId}`, experimental_minRetention: "1h" },
23
23
  });
24
24
  } catch (error) {
25
25
  if (WorkflowStartError.is(error)) { // [!code highlight]
26
26
  console.warn(`Unconfirmed start ${error.runId} (${error.stage}); retrying`);
27
27
  return await start(processOrder, [orderId], {
28
- hook: { token: `order:${orderId}`, experimental_minRetention: "1h" },
28
+ experimental_hook: { token: `order:${orderId}`, experimental_minRetention: "1h" },
29
29
  });
30
30
  }
31
31
  throw error;
@@ -33,7 +33,7 @@ async function startOrder() {
33
33
  }
34
34
  ```
35
35
 
36
- `WorkflowStartError` is only thrown by a start that passes `hook`, and retrying it with the same token is safe while the token is held. If the first candidate was admitted and still holds the token, the retry throws [`HookConflictError`](/docs/api-reference/workflow-errors/hook-conflict-error) with `conflictingRunId` set to it; if it was not admitted, the retry's run becomes the owner. The owner holds the token until it ends, then for any `experimental_minRetention`, unless it [disposes its start Hook](/docs/api-reference/workflow-api/start#take-care-with-the-start-hooks-lifecycle) first, which releases the token at once. A retry after the token is released is admitted as a new run, which is why the example sets a retention that covers its retry window. Either way, a payload you meant for the run can go to [`resumeHook()`](/docs/api-reference/workflow-api/resume-hook) after a conflict, as in [Start or route to the owner](/docs/foundations/idempotency#start-or-route-to-the-owner). Inside a workflow, the `start()` step retries it on its own. It extends `WorkflowError`, not `WorkflowWorldError`: it is not a World response, so World error checks never classify it as permanent.
36
+ `WorkflowStartError` is only thrown by a start that passes `experimental_hook`, and retrying it with the same token is safe while the token is held. If the first candidate was admitted and still holds the token, the retry throws [`HookConflictError`](/docs/api-reference/workflow-errors/hook-conflict-error) with `conflictingRunId` set to it; if it was not admitted, the retry's run becomes the owner. The owner holds the token until it ends, then for any `experimental_minRetention`, unless it [disposes its start Hook](/docs/api-reference/workflow-api/start#take-care-with-the-start-hooks-lifecycle) first, which releases the token at once. A retry after the token is released is admitted as a new run, which is why the example sets a retention that covers its retry window. Either way, a payload you meant for the run can go to [`resumeHook()`](/docs/api-reference/workflow-api/resume-hook) after a conflict, as in [Start or route to the owner](/docs/foundations/idempotency#start-or-route-to-the-owner). Inside a workflow, the `start()` step retries it on its own. It extends `WorkflowError`, not `WorkflowWorldError`: it is not a World response, so World error checks never classify it as permanent.
37
37
 
38
38
  ## API Signature
39
39
 
@@ -352,7 +352,7 @@ Look up a hook by its token. Useful in webhook resume flows where you receive a
352
352
  <Callout type="info">
353
353
  For runtime application code, prefer [`getHookByToken()`](/docs/api-reference/workflow-api/get-hook-by-token). Use `world.hooks.getByToken()` when you are working directly with the World storage interface for custom tooling, admin views, or low-level integrations.
354
354
 
355
- Hook-token lookup is the low-level form of the recommended idempotency flow: if a hook is already registered for your business key, reuse the hook's `runId` or resume that hook instead of starting another run. If no hook exists yet, start the workflow with [`start({ hook: { token } })`](/docs/api-reference/workflow-api/start#prevent-duplicate-starts), which creates the Hook atomically with the run and refuses a duplicate with `HookConflictError` naming the owner. On a World without atomic start Hooks, have the workflow create the deterministic hook near the beginning and check `await hook.getConflict()` to detect whether another run claimed the token first. See [Run idempotency](/docs/foundations/idempotency#run-idempotency).
355
+ Hook-token lookup is the low-level form of the recommended idempotency flow: if a hook is already registered for your business key, reuse the hook's `runId` or resume that hook instead of starting another run. If no hook exists yet, start the workflow with [`start({ experimental_hook: { token } })`](/docs/api-reference/workflow-api/start#prevent-duplicate-starts), which creates the Hook atomically with the run and refuses a duplicate with `HookConflictError` naming the owner. On a World without atomic start Hooks, have the workflow create the deterministic hook near the beginning and check `await hook.getConflict()` to detect whether another run claimed the token first. See [Run idempotency](/docs/foundations/idempotency#run-idempotency).
356
356
  </Callout>
357
357
 
358
358
  ```typescript lineNumbers
@@ -157,6 +157,8 @@ To prevent deadlock when polling is executed inline by the step executor, `Run#p
157
157
 
158
158
  **Follow-up**: Replace the worker-pool sizing requirement with a polling design that does not occupy a worker slot. Options under consideration: moving child-completion polling out of the step body into the suspension layer, or emitting a `run_completed` notification on the parent's stream/queue so the parent only resumes when the child actually finishes.
159
159
 
160
+ **Update**: A parent awaiting `returnValue` of a child it started now suspends on a system hook the child resumes when it finishes, so it holds no worker slot while it waits. Only `returnValue` awaits that fall back to polling (inside a step, or with `WORKFLOW_CHILD_RUN_COMPLETION_HOOK=0`) still count toward this sizing. See [Child Workflows](/cookbook/advanced/child-workflows#how-the-parent-waits).
161
+
160
162
  ### Mixed suspensions
161
163
 
162
164
  A suspension may contain steps, hooks, and waits simultaneously. The handler creates events for all, then dispatches everything we are not running inline as a single parallel batch of queue messages:
@@ -10,7 +10,7 @@ related:
10
10
 
11
11
  The Workflow CLI uses flags first, then environment variables, then defaults or local inference.
12
12
 
13
- Vercel project and auth settings can often be inferred from `.vercel/project.json` and your Vercel CLI login.
13
+ Vercel project and auth settings can often be inferred from `.vercel/project.json` and your Vercel CLI login. In a monorepo, the CLI uses the nearest `.vercel/project.json` before the repository's `.vercel/repo.json`.
14
14
 
15
15
  Whichever way they are resolved, the CLI ends up building a Vercel World from an auth token plus a project ID, team ID, and environment — the same four values any external client needs. Set them explicitly when there is no interactive `vercel login` to infer from, or when writing your own script instead of using the CLI; see [Connecting from outside a deployment](/worlds/vercel#connecting-from-outside-a-deployment).
16
16
 
@@ -32,13 +32,15 @@ Whichever way they are resolved, the CLI ends up building a Vercel World from an
32
32
 
33
33
  - Environment variable: `WORKFLOW_VERCEL_PROJECT`
34
34
  - Default: inferred when possible
35
- - Vercel project ID for `--backend vercel`.
35
+ - Vercel project ID or slug for `--backend vercel`.
36
+ - Takes precedence over the project in the `.vercel` link. When `--project` names a different project, pass `--team` too, or the CLI uses the linked team and logs a warning.
36
37
 
37
38
  ### `--team`
38
39
 
39
40
  - Environment variable: `WORKFLOW_VERCEL_TEAM`
40
41
  - Default: inferred when possible
41
42
  - Vercel team ID for `--backend vercel`.
43
+ - Takes precedence over the team in the `.vercel` link.
42
44
 
43
45
  ### `WORKFLOW_VERCEL_PROJECT_NAME`
44
46
 
@@ -45,6 +45,13 @@ The runtime reads these variables where workflows execute. Set them on the deplo
45
45
  - The kill switch for the wait. Worlds that do not implement waiting are already on the interval path, so this changes nothing for them.
46
46
  - Read by the process awaiting `Run.returnValue`, like the interval above.
47
47
 
48
+ ### `WORKFLOW_CHILD_RUN_COMPLETION_HOOK`
49
+
50
+ - Default: enabled
51
+ - Inside a workflow, awaiting `returnValue` of a run that workflow started suspends the parent on a system hook the child resumes when it finishes, instead of polling. See [Child Workflows](/cookbook/advanced/child-workflows#how-the-parent-waits).
52
+ - Set to `0` or `false` to stop `start()` from marking new child runs for the hook, so their parents poll `returnValue` inside a step on the variables above.
53
+ - Read by the deployment calling `start()` from a workflow. A child already marked keeps resuming its parent, so a parent waiting on it is never stranded.
54
+
48
55
  ## Replay and queue delivery
49
56
 
50
57
  ### `WORKFLOW_REPLAY_TIMEOUT_MS`
@@ -161,7 +161,7 @@ The Postgres World is a self-hosted durable backend for long-running server proc
161
161
  - Environment variable: `WORKFLOW_POSTGRES_WORKER_CONCURRENCY`
162
162
  - Default: `50`
163
163
  - Number of concurrent workers polling for jobs.
164
- - Also bounds concurrent parent-to-child workflow return-value polls.
164
+ - Also bounds concurrent `returnValue` polls that run inside steps. A parent workflow awaiting a child it started suspends on a system hook instead and holds no worker (see [Child Workflows](/cookbook/advanced/child-workflows#how-the-parent-waits)).
165
165
 
166
166
  ### `pollInterval`
167
167