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
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  title: Idempotency
3
- description: Make step retries safe, and start a workflow run at most once per key with start({ hook }).
3
+ description: Make step retries safe, and start a workflow run at most once per key with start({ experimental_hook }).
4
4
  type: conceptual
5
5
  summary: Use step IDs for retry-safe external calls, and pass a deterministic hook token to start() so a duplicate request is refused or routed to the run that owns it.
6
6
  prerequisites:
@@ -71,7 +71,7 @@ export async function POST(request: Request) {
71
71
 
72
72
  try {
73
73
  const run = await start(processOrder, [orderId], {
74
- hook: { token: `order:${orderId}` }, // [!code highlight]
74
+ experimental_hook: { token: `order:${orderId}` }, // [!code highlight]
75
75
  });
76
76
  return Response.json({ runId: run.runId, duplicate: false });
77
77
  } catch (error) {
@@ -81,7 +81,7 @@ export async function POST(request: Request) {
81
81
  }
82
82
  ```
83
83
 
84
- `start({ hook })` admits the run and creates its **start Hook** in one atomic step. Exactly one run owns the token. A duplicate `start()` with the same token 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.
84
+ `start({ experimental_hook })` admits the run and creates its **start Hook** in one atomic step. Exactly one run owns the token. A duplicate `start()` with the same token 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.
85
85
 
86
86
  ### Start or route to the owner
87
87
 
@@ -99,7 +99,7 @@ export async function POST(request: Request) {
99
99
  let owner: string | undefined;
100
100
  for (let attempt = 0; attempt < 3; attempt++) {
101
101
  try {
102
- const run = await start(processOrder, [orderId, note], { hook: { token } });
102
+ const run = await start(processOrder, [orderId, note], { experimental_hook: { token } });
103
103
  return Response.json({ runId: run.runId, started: true });
104
104
  } catch (error) {
105
105
  if (!HookConflictError.is(error)) throw error;
@@ -152,7 +152,7 @@ export async function processOrder(orderId: string, note: string) {
152
152
  - `createHook({ token })` with the run's start token returns a handle bound to the start Hook. It doesn't register a new Hook, so it adds no step, and `await hook.getConflict()` resolves `null`.
153
153
  - Payloads resumed before the workflow opens the Hook are kept, and are delivered in order once it does.
154
154
  - If the workflow never opens it, the token was only an idempotency key. The run completes normally, and unread payloads are simply left unread.
155
- - `metadata` and `experimental_minRetention` belong 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.
155
+ - `metadata` and `experimental_minRetention` belong 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.
156
156
 
157
157
  ### Keep the token after the run ends
158
158
 
@@ -166,7 +166,7 @@ import { processOrder } from "./workflows/process-order";
166
166
  declare const orderId: string; // @setup
167
167
 
168
168
  const run = await start(processOrder, [orderId, ""], {
169
- hook: {
169
+ experimental_hook: {
170
170
  token: `order:${orderId}`,
171
171
  experimental_minRetention: "30 days", // [!code highlight]
172
172
  metadata: { orderId },
@@ -222,17 +222,17 @@ Disposing the start Hook ends the run's idempotency: from the end of that block,
222
222
 
223
223
  ### When `start()` can't confirm the outcome
224
224
 
225
- If `start({ hook })` can't confirm whether its candidate run was queued or admitted, for example because the World timed out, it throws [`WorkflowStartError`](/docs/api-reference/workflow-errors/workflow-start-error) with the candidate's `runId`. The outcome is unknown, not failed. Retrying with the same token is safe: the retry either becomes the owner, or is refused with a `HookConflictError` naming the owner. Inside a workflow, the `start()` step retries it on its own.
225
+ If `start({ experimental_hook })` can't confirm whether its candidate run was queued or admitted, for example because the World timed out, it throws [`WorkflowStartError`](/docs/api-reference/workflow-errors/workflow-start-error) with the candidate's `runId`. The outcome is unknown, not failed. Retrying with the same token is safe: the retry either becomes the owner, or is refused with a `HookConflictError` naming the owner. Inside a workflow, the `start()` step retries it on its own.
226
226
 
227
227
  ### World support
228
228
 
229
- `start({ hook })` requires a World that supports atomic start Hooks (`capabilities.atomicStartHook`), and Hook retention when you set `experimental_minRetention`. Otherwise `start()` throws before it enqueues anything.
229
+ `start({ experimental_hook })` requires a World that supports atomic start Hooks (`capabilities.atomicStartHook`), and Hook retention when you set `experimental_minRetention`. Otherwise `start()` throws before it enqueues anything.
230
230
 
231
231
  | World | Support |
232
232
  | --- | --- |
233
233
  | [Local World](/worlds/local) | Supported. |
234
- | [Postgres World](/worlds/postgres) | Opt in with [`WORKFLOW_POSTGRES_EXPERIMENTAL_START_HOOK=1`](/worlds/postgres#workflow_postgres_experimental_start_hook), after applying migration `0028_add_start_hook_admissions` (required for every Postgres World on this version, with or without the flag). Stop workers running a previous version first. |
235
- | [Vercel World](/worlds/vercel) | Opt in with [`WORKFLOW_VERCEL_EXPERIMENTAL_START_HOOK=1`](/worlds/vercel#workflow_vercel_experimental_start_hook), which needs a backend that supports start Hooks. |
234
+ | [Postgres World](/worlds/postgres) | Supported, after applying migration `0028_add_start_hook_admissions`. Stop workers running a previous version first; see [Start Hooks](/worlds/postgres#start-hooks). |
235
+ | [Vercel World](/worlds/vercel) | Supported. |
236
236
 
237
237
  See [`start()`](/docs/api-reference/workflow-api/start#prevent-duplicate-starts) for the full option reference.
238
238
 
@@ -278,7 +278,7 @@ export async function processOrder(orderId: string): Promise<OrderResult> {
278
278
  Outside the workflow, try `resumeHook()` first, and on `HookNotFoundError` call `start()` and retry the resume until the new run registers its hook.
279
279
 
280
280
  <Callout type="warn">
281
- Unlike `start({ hook })`, this doesn't stop a duplicate from becoming a run. Two concurrent requests can both see "no hook yet" and each call `start()`. The losing run is still created, queued, and started, and returns once `getConflict()` resolves with the owner. The route can detect it by comparing the resumed hook's `runId` with the run it started.
281
+ Unlike `start({ experimental_hook })`, this doesn't stop a duplicate from becoming a run. Two concurrent requests can both see "no hook yet" and each call `start()`. The losing run is still created, queued, and started, and returns once `getConflict()` resolves with the owner. The route can detect it by comparing the resumed hook's `runId` with the run it started.
282
282
  </Callout>
283
283
 
284
284
  The token becomes available when its workflow ends, unless you set `experimental_minRetention` on `createHook()`. See [`createHook()` minimum retention](/docs/api-reference/workflow/create-hook#keep-a-token-unavailable-after-the-run-ends).
@@ -100,16 +100,12 @@ export async function parentWorkflow(inputValue: number) {
100
100
  }
101
101
  ```
102
102
 
103
- When you call `start()` inside a workflow function, it automatically executes through an internal step to maintain deterministic replay. The returned `Run` object works as it does outside workflows. Properties such as `.runId`, `.status`, and `.returnValue`, and methods such as `.cancel()`, are all available. Each property access or method call executes as a separate step.
103
+ When you call `start()` inside a workflow function, it automatically executes through an internal step to maintain deterministic replay. The returned `Run` object works as it does outside workflows. Properties such as `.runId`, `.status`, and `.returnValue`, and methods such as `.cancel()`, are all available.
104
104
 
105
- If the child run fails or is canceled, `await childRun.returnValue` throws [`WorkflowRunFailedError`](/docs/api-reference/workflow-errors/workflow-run-failed-error) or [`WorkflowRunCancelledError`](/docs/api-reference/workflow-errors/workflow-run-cancelled-error) on the first attempt.
105
+ Awaiting `childRun.returnValue` suspends the parent on a system hook that the child resumes when it finishes, so the parent waits without polling, uses no compute while it waits, and resumes as soon as the child is done. A child canceled without going through the SDK is noticed later, at the parent's next safety-net check; see [Cancellations that bypass the SDK](/cookbook/advanced/child-workflows#cancellations-that-bypass-the-sdk). If the child run fails or is canceled, `await childRun.returnValue` throws [`WorkflowRunFailedError`](/docs/api-reference/workflow-errors/workflow-run-failed-error) or [`WorkflowRunCancelledError`](/docs/api-reference/workflow-errors/workflow-run-cancelled-error) on the first attempt.
106
106
 
107
107
  <Callout type="info">
108
- Inside workflow functions, each `Run` property access (e.g., `run.status`, `run.returnValue`) triggers a workflow step. This means each access is recorded in the event log and replayed deterministically.
109
- </Callout>
110
-
111
- <Callout type="warn">
112
- Awaiting `returnValue` polls the child run every second, and the polling step holds its worker slot open until the child finishes. Size worker-based Worlds to cover the peak number of these polls in flight. If the child workflow is long-running, spawn it without awaiting `returnValue` and have it resume a [hook](/docs/foundations/hooks) when it completes. See the [`startAndWait()` pattern](/cookbook/advanced/child-workflows).
108
+ Inside workflow functions, each `Run` property access (e.g., `run.status`, `run.returnValue`) is recorded in the event log and replayed deterministically. Most accessors run as one step; `returnValue` records the system hook and the steps that read the child's result.
113
109
  </Callout>
114
110
 
115
111
  ### Fire and forget
@@ -179,7 +179,7 @@ All three first-party Worlds now implement it: Vercel accepts up to 30 days, and
179
179
 
180
180
  - **`start()` from inside a workflow.** Spawn a child run or hand off to a new run directly in a workflow function, without wrapping it in a step. See [Starting workflows](/docs/foundations/starting-workflows).
181
181
  - **Hook token takeover.** Pass `experimental_force: true` to [`createHook()`](/docs/api-reference/workflow/create-hook#take-over-a-token-another-run-holds) when the newest run should own a token another run still holds. The previous owner is woken and its `await hook` rejects with [`HookForceClaimedError`](/docs/api-reference/workflow-errors/hook-force-claimed-error), while `resumeHook()` callers, including one already in flight, are routed to the new owner without noticing. Supported by all three first-party Worlds.
182
- - **Idempotent starts.** Pass `hook: { token }` to [`start()`](/docs/api-reference/workflow-api/start#prevent-duplicate-starts) to admit at most one run per token. A duplicate throws `HookConflictError` naming the owner and never becomes a run, and the owner's start Hook can be resumed right away. See [Run idempotency](/docs/foundations/idempotency#start-a-run-once-per-key).
182
+ - **Idempotent starts.** Pass `experimental_hook: { token }` to [`start()`](/docs/api-reference/workflow-api/start#prevent-duplicate-starts) to admit at most one run per token. A duplicate throws `HookConflictError` naming the owner and never becomes a run, and the owner's start Hook can be resumed right away. See [Run idempotency](/docs/foundations/idempotency#start-a-run-once-per-key).
183
183
  - **Resume a stored Hook without another lookup.** Pass the `Hook` returned by `getHookByToken()` or `resumeHook()` back to [`resumeHook()`](/docs/api-reference/workflow-api/resume-hook#reuse-a-resolved-hook) instead of its token, and later deliveries skip the token lookup. The Hook survives JSON serialization, so you can keep it with your server-side session state. Supported on the Vercel World.
184
184
  - **Stronger hook coordination.** `hook.getConflict()` resolves with the conflicting [`Run`](/docs/api-reference/workflow-api/get-run) rather than a bare `{ runId }`, so a duplicate can `await conflict.status`, `await conflict.returnValue`, or `await conflict.cancel()` directly. See [Run idempotency](/docs/foundations/idempotency#run-idempotency).
185
185
  - **Support for more frameworks.** [React Router](/docs/getting-started/react-router) (v7 and v8, via Nitro) and [NestJS](/docs/getting-started/nestjs) are now supported.
@@ -67,7 +67,7 @@ interface World extends Storage, Queue, Streamer {
67
67
 
68
68
  `specVersion` is required. See [Declaring the spec version](#declaring-the-spec-version).
69
69
 
70
- The optional `capabilities` object advertises additional behavior, and every capability **fails closed**. A missing member means "unsupported," and the runtime keeps its conservative behavior. Set `hookRetention.active` to `true` only when the World implements hook token retention. Set `maxConcurrency` only when the World's queue supports `maxConcurrency`-limited consumption, which `WORKFLOW_SEQUENTIAL_REPLAYS=1` uses. Set `hookForceClaim` only when the World implements [hook token takeover](/worlds/upgrading-to-v5#new-optional-surface). Without it, `createHook({ experimental_force: true })` fails the workflow when it registers the hook. Set `dynamicWorkflowCode` only when the World persists `dynamicWorkflowCode` from `run_created` (and from a `run_started` that creates the run), echoes it on the created run, and returns it from `runs.get` with `resolveData: 'all'`. Without it, `start()` refuses [dynamic workflows](/docs/advanced/dynamic-workflows). The code is sent inline unless the World also implements `uploadDynamicWorkflowCode` for large definitions. Set `inBandFence` only when the World implements the [in-band writer fence](#optional-the-in-band-writer-fence). Set `atomicStartHook.active` only when the World implements [atomic start Hook admission](#optional-atomic-start-hook-admission). Without it, `start({ hook })` throws before it enqueues anything.
70
+ The optional `capabilities` object advertises additional behavior, and every capability **fails closed**. A missing member means "unsupported," and the runtime keeps its conservative behavior. Set `hookRetention.active` to `true` only when the World implements hook token retention. Set `maxConcurrency` only when the World's queue supports `maxConcurrency`-limited consumption, which `WORKFLOW_SEQUENTIAL_REPLAYS=1` uses. Set `hookForceClaim` only when the World implements [hook token takeover](/worlds/upgrading-to-v5#new-optional-surface). Without it, `createHook({ experimental_force: true })` fails the workflow when it registers the hook. Set `dynamicWorkflowCode` only when the World persists `dynamicWorkflowCode` from `run_created` (and from a `run_started` that creates the run), echoes it on the created run, and returns it from `runs.get` with `resolveData: 'all'`. Without it, `start()` refuses [dynamic workflows](/docs/advanced/dynamic-workflows). The code is sent inline unless the World also implements `uploadDynamicWorkflowCode` for large definitions. Set `inBandFence` only when the World implements the [in-band writer fence](#optional-the-in-band-writer-fence). Set `atomicStartHook.active` only when the World implements [atomic start Hook admission](#optional-atomic-start-hook-admission). Without it, `start({ experimental_hook })` throws before it enqueues anything.
71
71
 
72
72
  [Slot-numbered event IDs](#event-id-allocation) are a contract requirement rather than a capability, so there is no flag or fallback path.
73
73
 
@@ -296,21 +296,21 @@ The conformance suite in [`packages/world/src/test-support/in-band-fence-conform
296
296
 
297
297
  ### Optional: atomic start Hook admission
298
298
 
299
- [`start({ hook })`](/docs/api-reference/workflow-api/start#prevent-duplicate-starts) makes a start idempotent on a Hook token, and gives the run a **start Hook** that can be resumed from the moment the run is admitted. `start()` enqueues the candidate run first and then writes `run_created`; the queue consumer's `run_started` carries the same request in `eventData.startHook`, and either write may reach the World first. Declare `capabilities.atomicStartHook: { active: true }` when `events.create()` implements all of the following for a `run_created`, or a `run_started` that creates the run, carrying `eventData.startHook = { token, tokenRetentionUntil?, metadata? }`:
299
+ [`start({ experimental_hook })`](/docs/api-reference/workflow-api/start#prevent-duplicate-starts) makes a start idempotent on a Hook token, and gives the run a **start Hook** that can be resumed from the moment the run is admitted. `start()` enqueues the candidate run first and then writes `run_created`; the queue consumer's `run_started` carries the same request in `eventData.startHook`, and either write may reach the World first. Declare `capabilities.atomicStartHook: { active: true }` when `events.create()` implements all of the following for a `run_created`, or a `run_started` that creates the run, carrying `eventData.startHook = { token, tokenRetentionUntil?, metadata? }`:
300
300
 
301
301
  - **Atomic admission.** Claim the token, record the decision, and create the start Hook as one atomic step. A run must never exist for a candidate that was refused, and a crash partway through must be recoverable by retrying the candidate.
302
302
  - **One immutable decision per candidate `runId`.** Every later attempt for the same `runId`, through either write, returns the first decision even if the token has since changed hands: an accepted candidate returns its run (never `EntityConflictError`), and a refused one throws `HookConflictError` with the same `conflictingRunId`.
303
303
  - **The start Hook exists from admission.** Its id is `startHookId(runId)` from `@workflow/world`, and it is an ordinary Hook record with the start's `token`, `metadata` and `tokenRetentionUntil`, and `isWebhook: false`. `hooks.getByToken()` and `hooks.get()` return it as soon as admission is durable. `run_created` stands for its `hook_created`: never write a `hook_created` for it, and refuse a `hook_created` whose `correlationId` is `startHookId(runId)` with a 400-class validation error.
304
304
  - **Echo.** The run returned from `run_created`, `run_started` and `runs.get` carries `startHook`, including its `hookId`. Keep `token`, `hookId` and `tokenRetentionUntil` in the `run_created` event's `eventData.startHook` (you may drop `metadata` there): the runtime binds the workflow's `createHook({ token })` to the start Hook from it on every replay.
305
305
  - **Deliveries to a pending run.** Accept `hook_received` for `startHookId(runId)` while the run is `pending` or `running` (ordinary Hooks stay running-only), and wake the run as for any resume. Never commit a delivery before the run's `run_created` event. If your World admits the run in more than one write and the run doesn't exist yet when a delivery arrives, wait briefly, then answer a retryable error with a `retryAfter` rather than not found.
306
- - **Ordinary lifecycle.** From then on the start Hook behaves like a Hook the run created. Another run's `start({ hook })` or `createHook()` with the token conflicts, naming the owner. `hook_disposed` for the start Hook frees the token at once, even when `tokenRetentionUntil` is set, and a later `createHook({ token })` in the run is an ordinary `hook_created`. At run end, release the Hook as for any other, or, with `tokenRetentionUntil`, keep it findable by `hooks.getByToken()` but refuse deliveries until that time.
306
+ - **Ordinary lifecycle.** From then on the start Hook behaves like a Hook the run created. Another run's `start({ experimental_hook })` or `createHook()` with the token conflicts, naming the owner. `hook_disposed` for the start Hook frees the token at once, even when `tokenRetentionUntil` is set, and a later `createHook({ token })` in the run is an ordinary `hook_created`. At run end, release the Hook as for any other, or, with `tokenRetentionUntil`, keep it findable by `hooks.getByToken()` but refuse deliveries until that time.
307
307
  - **Force claims.** A forced `createHook()` takes the start Hook like any other, including before the owning workflow opens it, and writes `hook_disposed` with `forceClaimedBy` for `startHookId(runId)` to the owner's log. If the owner's run does not exist yet and can still be created, answer a retryable refusal instead.
308
308
  - **Orphans.** A candidate that was admitted but whose run was never created must not hold the token forever. A candidate older than `START_HOOK_CANDIDATE_MAX_AGE_MS` (the same bound `run_created` applies to client-minted run IDs) can never be created. While it can still be created, never release its token, and treat deliveries as for a pending run that doesn't exist yet. Once it can't, or once it is fenced, release the token and answer not found.
309
309
  - **Permanent refusals.** A request you will never admit (an invalid retention, a candidate past the orphan bound) throws `WorkflowWorldError` with `code: START_HOOK_ADMISSION_REJECTED`, so the queued copy stops retrying. Every copy of the candidate must get the same answer. Set its `reason` to one of `invalid`, `expired`, `token_mismatch`, `ordinary_run` or `disabled` (`StartHookRejectionReason`), which `start()` and the queued copy record on their spans as `workflow.start_hook.rejection_reason`.
310
310
  - **Cancelling an uncreated candidate.** A `run_cancelled` for a run ID with no run but an accepted decision fences the candidate (no copy can create it any more), releases its token as for an ended run, and throws `WorkflowWorldError` with `code: START_HOOK_CANDIDATE_CANCELLED`. With no decision, throw `WorkflowRunNotFoundError` as for any missing run.
311
311
  - **Switching admission off.** If you can switch admission off, either record the refusal as the candidate's decision and answer `START_HOOK_ADMISSION_REJECTED`, or throw `WorkflowWorldError` with `code: START_HOOK_ADMISSION_DISABLED` and record nothing. The second is not final: `start()` reports it as `WorkflowStartError`, and the queued copy is redelivered, because another copy may be admitted once admission is back on.
312
312
 
313
- `world-local` declares it; `world-postgres` declares it only with `WORKFLOW_POSTGRES_EXPERIMENTAL_START_HOOK=1`, and `world-vercel` only with `WORKFLOW_VERCEL_EXPERIMENTAL_START_HOOK=1`. The conformance suite in [`packages/world/src/test-support/atomic-start-hook-conformance.ts`](https://github.com/vercel/workflow/blob/main/packages/world/src/test-support/atomic-start-hook-conformance.ts) checks these rules against a World's storage.
313
+ `world-local`, `world-postgres` and `world-vercel` declare it. The conformance suite in [`packages/world/src/test-support/atomic-start-hook-conformance.ts`](https://github.com/vercel/workflow/blob/main/packages/world/src/test-support/atomic-start-hook-conformance.ts) checks these rules against a World's storage.
314
314
 
315
315
  ## Queue interface
316
316
 
@@ -315,7 +315,7 @@ Set the prefix through `WORKFLOW_POSTGRES_JOB_PREFIX` rather than only in code.
315
315
 
316
316
  Number of concurrent workers polling for jobs. Default: `50`.
317
317
 
318
- This value also bounds how many parent→child workflow polls can be in flight simultaneously. Every `await childRun.returnValue` inside a workflow holds a worker slot until the child run terminates. If you expect recursive or highly-fanned-out parent/child workflows, raise this ceiling above the peak number of concurrent polls. With the default of 50, the included `fibonacciWorkflow` end-to-end test (`fib(6)`, about 24 concurrent polls at peak) passes; deeper recursion or larger fanouts need a correspondingly larger setting.
318
+ A parent workflow awaiting `childRun.returnValue` of a child it started does not hold a worker slot: it suspends on a system hook the child resumes when it finishes (see [Child Workflows](/cookbook/advanced/child-workflows#how-the-parent-waits)). A `returnValue` that falls back to polling still does, for example one awaited inside a step, or any await while `WORKFLOW_CHILD_RUN_COMPLETION_HOOK=0` is set. Each of those holds a worker slot until its child run terminates, so raise this ceiling above the peak number of such polls in flight.
319
319
 
320
320
  ### `WORKFLOW_POSTGRES_POLL_INTERVAL_MS`
321
321
 
@@ -363,16 +363,6 @@ To turn it on, set `WORKFLOW_POSTGRES_JOB_LOCK_STALE_SECONDS=30` (or `jobLockSta
363
363
 
364
364
  Maximum [`experimental_minRetention`](/docs/api-reference/workflow/create-hook#keep-a-token-unavailable-after-the-run-ends) accepted by the Postgres World, in days. Default: `30`. Set this to the same limit as your production World so oversized values fail during development.
365
365
 
366
- ### `WORKFLOW_POSTGRES_EXPERIMENTAL_START_HOOK`
367
-
368
- Set to `1` (or `true`) to enable [`start({ hook })`](/docs/api-reference/workflow-api/start#prevent-duplicate-starts) on the Postgres World. Off by default; without it, `start({ hook })` throws before it enqueues anything.
369
-
370
- Stop workers running a previous version before you turn it on. The queue does not route by deployment, so an older worker that picks up a candidate's queued message would create its run without the start Hook, and the start would no longer be idempotent (`start()` reports that the World did not confirm the start Hook). An older runtime replaying a start Hook run can't bind the workflow's `createHook({ token })` to the start Hook either.
371
-
372
- For the same reason, don't roll back past migration `0028_add_start_hook_admissions` while start Hooks are live.
373
-
374
- Migration `0028_add_start_hook_admissions` is required even with this variable unset, because every Hook insert writes its `claims_token` column. It takes table locks on `workflow_hooks` and then `workflow_runs` (building the new unique index scans `workflow_hooks` first), and gives up after 10 seconds (unless the session sets its own `lock_timeout`), leaving the migration to retry, rather than stall traffic. Apply it with the rest of the migrations before deploying this version.
375
-
376
366
  ### `WORKFLOW_QUEUE_NAMESPACE`
377
367
 
378
368
  Queue topic namespace shared by build output and the Postgres World. Default: unset.
@@ -405,6 +395,12 @@ at most 10 seconds for its locks; if a long transaction holds them,
405
395
  `bootstrap` fails and can be run again.
406
396
  </Callout>
407
397
 
398
+ ### Start Hooks
399
+
400
+ Migration `0028_add_start_hook_admissions` adds [`start({ experimental_hook })`](/docs/api-reference/workflow-api/start#prevent-duplicate-starts) support. It is required for every Postgres World on this version, because every Hook insert writes its `claims_token` column. It takes table locks on `workflow_hooks` and then `workflow_runs` (building the new unique index scans `workflow_hooks` first), and gives up after 10 seconds (unless the session sets its own `lock_timeout`), leaving the migration to retry, rather than stall traffic. Apply it with the rest of the migrations before deploying this version.
401
+
402
+ Stop workers running a previous version before your app passes `experimental_hook` to `start()`. The queue does not route by deployment, so an older worker that picks up a candidate's queued message would create its run without the start Hook, and the start would no longer be idempotent (`start()` reports that the World did not confirm the start Hook). An older runtime replaying a start Hook run can't bind the workflow's `createHook({ token })` to the start Hook either. For the same reason, don't roll back past migration `0028_add_start_hook_admissions` while start Hooks are in use.
403
+
408
404
  ## Advanced
409
405
 
410
406
  Most apps don't need anything in this section. It covers building your own World module, sharing the queue with other consumers, coordinating shutdown yourself, and an experimental delivery mode.
@@ -152,7 +152,7 @@ None of this is required. Each entry is a hook the runtime uses if your World pr
152
152
  | `close()` | Releases connection pools and listeners so CLI commands and short-lived processes can exit without `process.exit()`. |
153
153
  | `streams.streamFlushIntervalMs` | Sets the stream flush window. The v5 default is `0`, so the first chunk flushes immediately; set a value to coalesce writes again. |
154
154
  | Hook token retention | `Hook.tokenRetentionUntil` marks the earliest time a token may become available after its run ends. Keep the owning run readable at least that long, and honor `hook_disposed` as an immediate release. Declare `capabilities.hookRetention.active` only once this is implemented, since the runtime otherwise rejects retained hooks before registration. |
155
- | Atomic start Hooks | Backs [`start({ hook })`](/docs/api-reference/workflow-api/start#prevent-duplicate-starts): admit a run and create its start Hook in one atomic step, so a duplicate start is refused naming the owner and the start Hook can be resumed from admission. Declare `capabilities.atomicStartHook.active` only once you implement [the contract](/worlds/building-a-world#optional-atomic-start-hook-admission). |
155
+ | Atomic start Hooks | Backs [`start({ experimental_hook })`](/docs/api-reference/workflow-api/start#prevent-duplicate-starts): admit a run and create its start Hook in one atomic step, so a duplicate start is refused naming the owner and the start Hook can be resumed from admission. Declare `capabilities.atomicStartHook.active` only once you implement [the contract](/worlds/building-a-world#optional-atomic-start-hook-admission). |
156
156
  | Hook resume dedup | `resumeHook()` writes `hook_received` and dispatches the queue message in parallel when the backend collapses concurrent writes carrying the same `(runId, resumeId)` onto one committed event. Declare `capabilities.hookResumeDedup` only if you enforce that constraint **and** `events.list()` returns the committed event's top-level `resumeId`. A World that omits either guarantee must leave the flag unset, which keeps the sequential path. See [Durable hook resume](/docs/changelog/lazy-hook-resume). |
157
157
  | Resolved hook resume | Lets `resumeHook()` deliver to a stored [`Hook`](/docs/api-reference/workflow-api/resume-hook#reuse-a-resolved-hook) without looking up its token again. Declare `capabilities.resolvedHookResume` only if a write carrying `requireHookResumeDedup` either commits with atomic resume deduplication or is refused (400/404) before anything is written. The runtime then looks the token up and delivers as usual. Without the flag, a stored Hook is delivered through the existing path. |
158
158
  | Hook token takeover | Backs [`createHook({ experimental_force: true })`](/docs/api-reference/workflow/create-hook#take-over-a-token-another-run-holds). When a forced `hook_created` names a token another live run holds, append `hook_disposed` with `forceClaimedBy: { runId, hookId }` to the holder's log and refuse later `hook_received` writes to it, then re-point the token to the claimer and record `Hook.claimedFrom`. Refuse the takeover with an ordinary `hook_conflict` carrying `forceRefusedReason: 'victim-spec-version'` when the holder was stamped below spec version 8, and answer a `hook_received` refused by a takeover with `HookForceClaimedError` so `resumeHook()` can follow the token. Declare `capabilities.hookForceClaim` only once you give these guarantees. Without it, the runtime fails a forced `createHook()` at registration. |
@@ -158,7 +158,7 @@ The route serves `world.createQueueHandler("__agent_wkf_workflow_", handler)`. T
158
158
  ## Limitations
159
159
 
160
160
  - **No run migration**: A run's region is fixed at creation. Existing runs cannot be moved to a different region.
161
- - **Hook minimum retention**: `experimental_minRetention` cannot exceed 30 days, on both [`createHook()`](/docs/api-reference/workflow/create-hook#keep-a-token-unavailable-after-the-run-ends) and [`start({ hook })`](/docs/api-reference/workflow-api/start#prevent-duplicate-starts).
161
+ - **Hook minimum retention**: `experimental_minRetention` cannot exceed 30 days, on both [`createHook()`](/docs/api-reference/workflow/create-hook#keep-a-token-unavailable-after-the-run-ends) and [`start({ experimental_hook })`](/docs/api-reference/workflow-api/start#prevent-duplicate-starts).
162
162
 
163
163
  ## Observability
164
164
 
@@ -176,7 +176,7 @@ npx workflow inspect runs --backend vercel
176
176
  npx workflow web --backend vercel
177
177
  ```
178
178
 
179
- The CLI automatically retrieves authentication from the Vercel CLI (`vercel login`) and infers project/team IDs from your local Vercel project linking.
179
+ The CLI automatically retrieves authentication from the Vercel CLI (`vercel login`) and infers project/team IDs from your local Vercel project linking. In a monorepo, it uses the nearest `.vercel/project.json`.
180
180
 
181
181
  To use the local observability UI instead of the Vercel dashboard:
182
182
 
@@ -184,7 +184,7 @@ To use the local observability UI instead of the Vercel dashboard:
184
184
  npx workflow web --backend vercel --localUi
185
185
  ```
186
186
 
187
- To override the automatic configuration:
187
+ To override the automatic configuration, pass the values explicitly. `--project` and `--team` take precedence over the linked project:
188
188
 
189
189
  ```bash
190
190
  npx workflow inspect runs \
@@ -380,10 +380,6 @@ The Vercel World doesn't follow HTTP redirects on workflow API requests, so poin
380
380
 
381
381
  Custom workflow-server URL for direct runtime requests, or for the proxy to forward to via `WORKFLOW_VERCEL_BACKEND_URL`. Default: unset; normal deployments should not need this.
382
382
 
383
- ### `WORKFLOW_VERCEL_EXPERIMENTAL_START_HOOK`
384
-
385
- Set to `1` (or `true`) to enable [`start({ hook })`](/docs/api-reference/workflow-api/start#prevent-duplicate-starts) on the Vercel World. Off by default; without it, `start({ hook })` throws before it enqueues anything. It needs a backend that supports start Hooks. Set it on the deployment that starts runs and on any deployment those runs target.
386
-
387
383
  ### `WORKFLOW_SEQUENTIAL_REPLAYS`
388
384
 
389
385
  Set `WORKFLOW_SEQUENTIAL_REPLAYS=1` to guarantee that **at most one orchestrator (flow) invocation runs at a time per workflow run**. This behavior is off by default; without it, the runtime relies on idempotency and the event log to tolerate concurrent flow invocations of the same run.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "workflow",
3
- "version": "5.3.0",
3
+ "version": "5.4.0",
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.7",
62
- "@workflow/cli": "5.0.7",
63
- "@workflow/core": "5.3.0",
61
+ "@workflow/astro": "5.0.8",
62
+ "@workflow/cli": "5.0.8",
63
+ "@workflow/core": "5.4.0",
64
64
  "@workflow/errors": "5.1.0",
65
65
  "@workflow/typescript-plugin": "5.0.0",
66
66
  "@workflow/utils": "5.0.2",
67
67
  "ms": "2.1.3",
68
- "@workflow/next": "5.0.7",
69
- "@workflow/nest": "5.1.5",
70
- "@workflow/nitro": "5.0.7",
71
- "@workflow/nuxt": "5.0.7",
72
- "@workflow/sveltekit": "5.0.7",
73
- "@workflow/rollup": "5.0.7"
68
+ "@workflow/next": "5.0.8",
69
+ "@workflow/nest": "5.1.6",
70
+ "@workflow/nitro": "5.0.8",
71
+ "@workflow/nuxt": "5.0.8",
72
+ "@workflow/sveltekit": "5.0.8",
73
+ "@workflow/rollup": "5.0.8"
74
74
  },
75
75
  "devDependencies": {
76
76
  "@types/ms": "2.1.0",