workflow 5.2.3 → 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 (48) hide show
  1. package/dist/api.d.ts +1 -1
  2. package/dist/api.d.ts.map +1 -1
  3. package/dist/api.js +1 -1
  4. package/dist/internal/errors.d.ts +1 -1
  5. package/dist/internal/errors.d.ts.map +1 -1
  6. package/dist/internal/errors.js +2 -2
  7. package/docs/api-reference/workflow/create-hook.mdx +8 -0
  8. package/docs/api-reference/workflow/create-webhook.mdx +1 -1
  9. package/docs/api-reference/workflow/fetch.mdx +2 -0
  10. package/docs/api-reference/workflow-api/get-hook-by-token.mdx +5 -1
  11. package/docs/api-reference/workflow-api/get-run.mdx +4 -0
  12. package/docs/api-reference/workflow-api/resume-hook.mdx +58 -2
  13. package/docs/api-reference/workflow-api/start.mdx +70 -3
  14. package/docs/api-reference/workflow-errors/hook-conflict-error.mdx +6 -3
  15. package/docs/api-reference/workflow-errors/in-band-superseded-error.mdx +68 -0
  16. package/docs/api-reference/workflow-errors/index.mdx +6 -0
  17. package/docs/api-reference/workflow-errors/meta.json +2 -0
  18. package/docs/api-reference/workflow-errors/precondition-failed-error.mdx +2 -0
  19. package/docs/api-reference/workflow-errors/workflow-start-error.mdx +58 -0
  20. package/docs/api-reference/workflow-errors/workflow-world-error.mdx +12 -1
  21. package/docs/api-reference/workflow-runtime/world/storage.mdx +1 -1
  22. package/docs/changelog/eager-processing.mdx +4 -0
  23. package/docs/changelog/index.mdx +1 -0
  24. package/docs/changelog/lazy-event-creation.md +1 -1
  25. package/docs/changelog/meta.json +1 -0
  26. package/docs/changelog/spec-9.mdx +4019 -0
  27. package/docs/changelog/turbo-mode.md +4 -0
  28. package/docs/configuration/cli-and-web-ui.mdx +4 -2
  29. package/docs/configuration/runtime-tuning.mdx +68 -2
  30. package/docs/configuration/worlds.mdx +13 -1
  31. package/docs/cookbook/advanced/child-workflows.mdx +127 -187
  32. package/docs/cookbook/common-patterns/batching.mdx +3 -1
  33. package/docs/cookbook/common-patterns/idempotency.mdx +11 -12
  34. package/docs/cookbook/common-patterns/sequential-and-parallel.mdx +1 -1
  35. package/docs/cookbook/common-patterns/workflow-composition.mdx +5 -5
  36. package/docs/errors/fetch-in-workflow.mdx +15 -29
  37. package/docs/foundations/errors-and-retries.mdx +6 -0
  38. package/docs/foundations/hooks.mdx +3 -1
  39. package/docs/foundations/idempotency.mdx +190 -60
  40. package/docs/foundations/starting-workflows.mdx +3 -7
  41. package/docs/how-it-works/event-sourcing.mdx +6 -0
  42. package/docs/whats-new.mdx +3 -1
  43. package/docs/worlds/building-a-world.mdx +28 -3
  44. package/docs/worlds/local.mdx +6 -0
  45. package/docs/worlds/postgres.mdx +208 -146
  46. package/docs/worlds/upgrading-to-v5.mdx +7 -1
  47. package/docs/worlds/vercel.mdx +9 -7
  48. package/package.json +11 -11
package/dist/api.d.ts CHANGED
@@ -3,5 +3,5 @@ export type { CancelRunOptions, Event, StopSleepOptions, StopSleepResult, Workfl
3
3
  export { type RunCompletedHookParams, type RunFailedHookParams, registerLifecycleHooks, type WorkflowLifecycleHooks, } from '@workflow/core/runtime/lifecycle-hooks';
4
4
  export { getHookByToken, type Hook, type ResumedHook, resumeHook, resumeWebhook, } from '@workflow/core/runtime/resume-hook';
5
5
  export { getRun, Run, type WorkflowReadableStream, type WorkflowReadableStreamOptions, type WorkflowRunWritableStreamOptions, } from '@workflow/core/runtime/run';
6
- export { type DynamicStartOptions, type DynamicWorkflowOptions, type DynamicWorkflowStepReference, type StartOptions, start, } from '@workflow/core/runtime/start';
6
+ export { type DynamicStartOptions, type DynamicWorkflowOptions, type DynamicWorkflowStepReference, type StartHookOptions, type StartOptions, start, } from '@workflow/core/runtime/start';
7
7
  //# sourceMappingURL=api.d.ts.map
package/dist/api.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAOA,OAAO,mCAAmC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jB,KAAK,GACN,MAAM,8BAA8B,CAAC"}
package/dist/api.js CHANGED
@@ -10,4 +10,4 @@ export { registerLifecycleHooks, } from '@workflow/core/runtime/lifecycle-hooks'
10
10
  export { getHookByToken, resumeHook, resumeWebhook, } from '@workflow/core/runtime/resume-hook';
11
11
  export { getRun, Run, } from '@workflow/core/runtime/run';
12
12
  export { start, } from '@workflow/core/runtime/start';
13
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXBpLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL2FwaS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxxRUFBcUU7QUFDckUseUVBQXlFO0FBQ3pFLDJFQUEyRTtBQUMzRSw0RUFBNEU7QUFDNUUsNkVBQTZFO0FBQzdFLG1CQUFtQjtBQUNuQix5RUFBeUU7QUFDekUsT0FBTyxtQ0FBbUMsQ0FBQztBQVMzQyxPQUFPLEVBR0wsc0JBQXNCLEdBRXZCLE1BQU0sd0NBQXdDLENBQUM7QUFDaEQsT0FBTyxFQUNMLGNBQWMsRUFHZCxVQUFVLEVBQ1YsYUFBYSxHQUNkLE1BQU0sb0NBQW9DLENBQUM7QUFDNUMsT0FBTyxFQUNMLE1BQU0sRUFDTixHQUFHLEdBSUosTUFBTSw0QkFBNEIsQ0FBQztBQUNwQyxPQUFPLEVBS0wsS0FBSyxHQUNOLE1BQU0sOEJBQThCLENBQUMiLCJzb3VyY2VzQ29udGVudCI6WyIvLyBTaWRlLWVmZmVjdCBpbXBvcnQ6IGVuc3VyZSBgd29ybGQudHNgIGlzIGxvYWRlZCBzbyBpdHMgbW9kdWxlLWxvYWRcbi8vIGBnbG9iYWxUaGlzW0dldFdvcmxkRm5LZXldID8/PSBnZXRXb3JsZGAgcmVnaXN0cmF0aW9uIGZpcmVzIGJlZm9yZSBhbnlcbi8vIGhvc3Qgcm91dGUgcmVhY2hlcyBgZ2V0V29ybG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xpZmVjeWNsZUhvb2tzLFxufSBmcm9tICdAd29ya2Zsb3cvY29yZS9ydW50aW1lL2xpZmVjeWNsZS1ob29rcyc7XG5leHBvcnQge1xuICBnZXRIb29rQnlUb2tlbixcbiAgdHlwZSBIb29rLFxuICB0eXBlIFJlc3VtZWRIb29rLFxuICByZXN1bWVIb29rLFxuICByZXN1bWVXZWJob29rLFxufSBmcm9tICdAd29ya2Zsb3cvY29yZS9ydW50aW1lL3Jlc3VtZS1ob29rJztcbmV4cG9ydCB7XG4gIGdldFJ1bixcbiAgUnVuLFxuICB0eXBlIFdvcmtmbG93UmVhZGFibGVTdHJlYW0sXG4gIHR5cGUgV29ya2Zsb3dSZWFkYWJsZVN0cmVhbU9wdGlvbnMsXG4gIHR5cGUgV29ya2Zsb3dSdW5Xcml0YWJsZVN0cmVhbU9wdGlvbnMsXG59IGZyb20gJ0B3b3JrZmxvdy9jb3JlL3J1bnRpbWUvcnVuJztcbmV4cG9ydCB7XG4gIHR5cGUgRHluYW1pY1N0YXJ0T3B0aW9ucyxcbiAgdHlwZSBEeW5hbWljV29ya2Zsb3dPcHRpb25zLFxuICB0eXBlIER5bmFtaWNXb3JrZmxvd1N0ZXBSZWZlcmVuY2UsXG4gIHR5cGUgU3RhcnRIb29rT3B0aW9ucyxcbiAgdHlwZSBTdGFydE9wdGlvbnMsXG4gIHN0YXJ0LFxufSBmcm9tICdAd29ya2Zsb3cvY29yZS9ydW50aW1lL3N0YXJ0JztcbiJdfQ==
@@ -1,2 +1,2 @@
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';
1
+ export { EntityConflictError, HookConflictError, HookForceClaimedError, HookNotFoundError, InBandSupersededError, PreconditionFailedError, RunExpiredError, RunNotSupportedError, StepNotRegisteredError, StreamError, ThrottleError, TooEarlyError, WorkflowError, WorkflowNotRegisteredError, WorkflowRunCancelledError, WorkflowRunFailedError, WorkflowRunNotCompletedError, WorkflowRunNotFoundError, WorkflowRuntimeError, WorkflowStartError, 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,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"}
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,EAClB,kBAAkB,GACnB,MAAM,kBAAkB,CAAC"}
@@ -1,2 +1,2 @@
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==
1
+ export { EntityConflictError, HookConflictError, HookForceClaimedError, HookNotFoundError, InBandSupersededError, PreconditionFailedError, RunExpiredError, RunNotSupportedError, StepNotRegisteredError, StreamError, ThrottleError, TooEarlyError, WorkflowError, WorkflowNotRegisteredError, WorkflowRunCancelledError, WorkflowRunFailedError, WorkflowRunNotCompletedError, WorkflowRunNotFoundError, WorkflowRuntimeError, WorkflowStartError, WorkflowWorldError, } from '@workflow/errors';
2
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZXJyb3JzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL2ludGVybmFsL2Vycm9ycy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQ0wsbUJBQW1CLEVBQ25CLGlCQUFpQixFQUNqQixxQkFBcUIsRUFDckIsaUJBQWlCLEVBQ2pCLHFCQUFxQixFQUNyQix1QkFBdUIsRUFDdkIsZUFBZSxFQUNmLG9CQUFvQixFQUNwQixzQkFBc0IsRUFDdEIsV0FBVyxFQUNYLGFBQWEsRUFDYixhQUFhLEVBQ2IsYUFBYSxFQUNiLDBCQUEwQixFQUMxQix5QkFBeUIsRUFDekIsc0JBQXNCLEVBQ3RCLDRCQUE0QixFQUM1Qix3QkFBd0IsRUFDeEIsb0JBQW9CLEVBQ3BCLGtCQUFrQixFQUNsQixrQkFBa0IsR0FDbkIsTUFBTSxrQkFBa0IsQ0FBQyIsInNvdXJjZXNDb250ZW50IjpbImV4cG9ydCB7XG4gIEVudGl0eUNvbmZsaWN0RXJyb3IsXG4gIEhvb2tDb25mbGljdEVycm9yLFxuICBIb29rRm9yY2VDbGFpbWVkRXJyb3IsXG4gIEhvb2tOb3RGb3VuZEVycm9yLFxuICBJbkJhbmRTdXBlcnNlZGVkRXJyb3IsXG4gIFByZWNvbmRpdGlvbkZhaWxlZEVycm9yLFxuICBSdW5FeHBpcmVkRXJyb3IsXG4gIFJ1bk5vdFN1cHBvcnRlZEVycm9yLFxuICBTdGVwTm90UmVnaXN0ZXJlZEVycm9yLFxuICBTdHJlYW1FcnJvcixcbiAgVGhyb3R0bGVFcnJvcixcbiAgVG9vRWFybHlFcnJvcixcbiAgV29ya2Zsb3dFcnJvcixcbiAgV29ya2Zsb3dOb3RSZWdpc3RlcmVkRXJyb3IsXG4gIFdvcmtmbG93UnVuQ2FuY2VsbGVkRXJyb3IsXG4gIFdvcmtmbG93UnVuRmFpbGVkRXJyb3IsXG4gIFdvcmtmbG93UnVuTm90Q29tcGxldGVkRXJyb3IsXG4gIFdvcmtmbG93UnVuTm90Rm91bmRFcnJvcixcbiAgV29ya2Zsb3dSdW50aW1lRXJyb3IsXG4gIFdvcmtmbG93U3RhcnRFcnJvcixcbiAgV29ya2Zsb3dXb3JsZEVycm9yLFxufSBmcm9tICdAd29ya2Zsb3cvZXJyb3JzJztcbiJdfQ==
@@ -178,10 +178,18 @@ async function approvalWorkflow() {
178
178
 
179
179
  On a conflict, the resolved value is a `Run` handle for the run that owns the token, with durable step-backed accessors. The duplicate run can decide in code how to handle it: return or log `conflict.runId`, inspect `await conflict.status`, wait on `await conflict.returnValue`, or cancel the owner with `await conflict.cancel()` and continue in the current run. See [Run idempotency](/docs/foundations/idempotency#run-idempotency) for these strategies in context.
180
180
 
181
+ Work started *beside* the awaiter, rather than after it, is not slowed down by it. In `await Promise.all([hook.getConflict(), prepare()])` the registration and the step are scheduled together: the runtime commits the registration, resolves the awaiter in the same invocation, and then runs `prepare()` there too, so the step does not pay an extra round trip through the queue for having been started next to a `getConflict()`.
182
+
183
+ This is a scheduling improvement, not an ordering guarantee. Only the steps the invocation runs inline start after the registration is recorded: the first [`WORKFLOW_MAX_INLINE_STEPS`](/docs/configuration/runtime-tuning#workflow_max_inline_steps) of them, less any inline steps the invocation is still running from an earlier part of the workflow (see [`WORKFLOW_INLINE_EARLY_ADVANCE`](/docs/configuration/runtime-tuning#workflow_inline_early_advance)). A wider fan-out beside the awaiter has its remaining steps created and queued alongside the hook, exactly as described above, so they can start before the registration commits and can start even if it conflicts. When the ordering is what you need, await `hook.getConflict()` *before* calling the step.
184
+
181
185
  <Callout type="info">
182
186
  Custom hook tokens are the recommended way to coordinate active workflow runs. Use a deterministic token from your domain, such as an order ID or conversation ID, create the hook near the beginning of the workflow, and check `await hook.getConflict()` before work that depends on owning the token. See [Run idempotency](/docs/foundations/idempotency#run-idempotency).
183
187
  </Callout>
184
188
 
189
+ ### Open the run's start Hook
190
+
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
+
185
193
  ### Keep a token unavailable after the run ends
186
194
 
187
195
  By default, another Hook can use the token after its workflow ends. Set `experimental_minRetention` to keep the token unavailable for at least a specific time after `createHook()` runs:
@@ -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,6 +91,8 @@ 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
+ 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).
95
+
94
96
  ### Customizing fetch behavior
95
97
 
96
98
  The following custom fetch wrapper provides more advanced error handling with custom retry logic. Call `globalThis.fetch` inside your own `"use step"` function because calling the workflow `fetch` imported from `workflow` would nest a step inside a step:
@@ -13,8 +13,12 @@ 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({ 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
+
16
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.
17
19
 
20
+ To deliver several payloads to the same Hook, store the returned Hook and pass it to `resumeHook()` instead of the token, which skips the lookup on each later delivery. See [Reuse a resolved hook](/docs/api-reference/workflow-api/resume-hook#reuse-a-resolved-hook).
21
+
18
22
  <Callout type="warn">
19
23
  `getHookByToken` is a runtime function that must be called from outside a workflow function.
20
24
  </Callout>
@@ -24,7 +28,7 @@ When the Hook was created with [`experimental_force`](/docs/api-reference/workfl
24
28
  </Callout>
25
29
 
26
30
  <Callout type="info">
27
- 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. If duplicates must be rejected before a workflow body runs, keep a durable request record until native atomic start-and-hook registration exists. 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).
28
32
  </Callout>
29
33
 
30
34
  ```typescript lineNumbers
@@ -199,6 +199,10 @@ export async function POST(req: Request) {
199
199
 
200
200
  The options object is optional: `await run.cancel()` cancels the run without recording a reason.
201
201
 
202
+ ## Spec 9 (experimental)
203
+
204
+ On runs of the experimental spec 9 runtime, `wakeUp()` asks the run's orchestrator to complete the sleeps instead of completing them itself, `stoppedCount` counts the sleeps it asked to complete, and the request is best-effort while the run is active. See [`run.wakeUp()` on spec 9 runs](/docs/changelog/spec-9#runwakeup-and-waitforsleep).
205
+
202
206
  ## Related functions
203
207
 
204
208
  - [`start()`](/docs/api-reference/workflow-api/start): Start a new workflow and get its run ID.
@@ -10,13 +10,19 @@ related:
10
10
  - /docs/foundations/idempotency
11
11
  ---
12
12
 
13
- Resumes a workflow run by sending a payload to a hook identified by its token.
13
+ Resumes a workflow run by sending a payload to a hook identified by its token. You can also pass a `Hook` from an earlier `getHookByToken()` or `resumeHook()` call to skip the token lookup. See [Reuse a resolved hook](#reuse-a-resolved-hook).
14
14
 
15
15
  It durably writes the `hook_received` event and only then publishes a workflow wake. The call resolves only after both operations succeed, in that order.
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
- If `resumeHook()` throws any other error, the outcome is ambiguous only in dispatch, never in durability: the event may already be durable even though the workflow wake failed, and any later wake of the run delivers it. Calling `resumeHook()` again creates a new `resumeId` and can append a second `hook_received`. Callers that need at-most-once behavior across separate invocations must retain and deduplicate their own request key.
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
+
21
+ Other errors can occur before or after persistence. A lost write response leaves
22
+ the write's outcome unknown; a failed workflow wake can leave an already durable
23
+ event waiting for a later wake. Calling `resumeHook()` again creates a new
24
+ `resumeId` and can append a second `hook_received`. Callers that need at-most-once
25
+ behavior across separate invocations must retain and deduplicate their own request key.
20
26
 
21
27
  <Callout type="warn">
22
28
  `resumeHook` is a runtime function that must be called from outside a workflow function.
@@ -67,6 +73,54 @@ showSections={["returns"]}
67
73
 
68
74
  ## Examples
69
75
 
76
+ ### Reuse a resolved hook
77
+
78
+ Pass the `Hook` returned by `getHookByToken()` to `resumeHook()` to skip the
79
+ token lookup on later deliveries. Store the Hook alongside your application's
80
+ session state; JSON and other ordinary serializers are supported.
81
+
82
+ ```typescript
83
+ import { getHookByToken, resumeHook } from 'workflow/api';
84
+
85
+ // Resolve once; save the returned JSON alongside your server-side session.
86
+ export async function prepareSession(token: string): Promise<string> {
87
+ const hook = await getHookByToken(token);
88
+ return JSON.stringify(hook);
89
+ }
90
+
91
+ // Load that JSON for later deliveries, then save the updated snapshot.
92
+ export async function deliverMessage(storedHook: string, message: unknown): Promise<string> {
93
+ const hook = await resumeHook(JSON.parse(storedHook), message);
94
+ return JSON.stringify(hook);
95
+ }
96
+ ```
97
+
98
+ A Hook object targets that specific hook and its force-claim successor. It does
99
+ not send to an unrelated hook that later happens to use the same token. Hooks
100
+ without `resumeContext` keep the existing run-lookup behavior. The
101
+ [Vercel World](/worlds/vercel) supports guarded delivery. Other Worlds accept a
102
+ Hook object and deliver it through their existing path.
103
+
104
+ A stored Hook contains its **token** and is at least as sensitive as that token.
105
+ Keep it server-side, or sign the **whole object** before returning it to a client;
106
+ also encrypt it if the token must remain secret. The deployment ID controls both
107
+ the payload encryption key and the deployment that is woken, so authenticating
108
+ only the IDs is insufficient. Trace carriers may contain private baggage; omit
109
+ them before exposing a snapshot to a client. Schema validation is not authentication.
110
+
111
+ The SDK handles a definite refusal of the first send by looking up the token
112
+ and falling back to ordinary delivery. It retries admission throttles and
113
+ 503 `run-spec-version-changed` or `start-hook-run-pending`, retaining the delivery identity. Other 503s
114
+ are uncertain even with `Retry-After` and are never resent. A refusal after a
115
+ retried send is also surfaced without fallback, because an earlier send may
116
+ have committed. Do not implement fallback yourself.
117
+
118
+ | Outcome | Meaning |
119
+ | --- | --- |
120
+ | `HookNotFoundError` | The hook cannot receive this message; the SDK has already checked for a live token or an eligible successor. |
121
+ | `HookForceClaimedError` | The SDK follows supported ownership redirects automatically. |
122
+ | Any other error | The write may already have committed. Do not call `resumeHook()` again as a new delivery. |
123
+
70
124
  ### Basic API route
71
125
 
72
126
  Using `resumeHook` in a basic API route to resume a hook:
@@ -168,6 +222,8 @@ export async function POST(request: Request) {
168
222
 
169
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.
170
224
 
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
+
171
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.
172
228
 
173
229
  ```typescript lineNumbers
@@ -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. If retried requests must route to one active workflow, have the workflow create a deterministic hook token and use [`getHookByToken()`](/docs/api-reference/workflow-api/get-hook-by-token) to reuse an already-registered active hook. The lookup is not atomic with `start()`, so concurrent callers can still create extra runs before the hook is registered. Handle that 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 return the active owner to the caller. If duplicates must be rejected before a workflow body runs, keep a durable request record until native atomic start-and-hook registration exists. See [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.
@@ -72,6 +72,69 @@ If `start()` throws `'start' received an invalid workflow function. Ensure the W
72
72
 
73
73
  ## Examples
74
74
 
75
+ ### Prevent duplicate starts
76
+
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
+
79
+ ```typescript lineNumbers
80
+ import { start } from "workflow/api";
81
+ import { HookConflictError, WorkflowStartError } from "workflow/errors";
82
+ import { processOrder } from "./workflows/process-order";
83
+
84
+ export async function POST(request: Request) {
85
+ const { orderId } = await request.json();
86
+
87
+ try {
88
+ const run = await start(processOrder, [orderId], {
89
+ experimental_hook: { // [!code highlight]
90
+ token: `order:${orderId}`, // [!code highlight]
91
+ experimental_minRetention: "30 days", // [!code highlight]
92
+ metadata: { orderId }, // [!code highlight]
93
+ }, // [!code highlight]
94
+ });
95
+ return Response.json({ runId: run.runId, duplicate: false });
96
+ } catch (error) {
97
+ if (HookConflictError.is(error)) {
98
+ return Response.json({ runId: error.conflictingRunId, duplicate: true });
99
+ }
100
+ if (WorkflowStartError.is(error)) {
101
+ // Unknown outcome: retrying with the same token is safe.
102
+ console.error(`Could not confirm start of ${error.runId} (${error.stage})`);
103
+ }
104
+ throw error;
105
+ }
106
+ }
107
+ ```
108
+
109
+ `experimental_hook` takes:
110
+
111
+ | Option | Description |
112
+ | --- | --- |
113
+ | `token` | Required. A non-empty Hook token. Exactly one run owns it. |
114
+ | `metadata` | Optional. Stored on the start Hook, with the same serialization as [`createHook({ metadata })`](/docs/api-reference/workflow/create-hook). [`getHookByToken()`](/docs/api-reference/workflow-api/get-hook-by-token) returns it. |
115
+ | `experimental_minRetention` | Optional. Keeps the token unavailable until at least this time, even after the run ends. Accepts the same duration string, milliseconds, or `Date` as [`createHook({ experimental_minRetention })`](/docs/api-reference/workflow/create-hook#keep-a-token-unavailable-after-the-run-ends); a duration counts from `start()`. No default: without it, the token is released when the run ends. |
116
+
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
+ * 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({ 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
+ * 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
+ * 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
+ * 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
+ * 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
+ * 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, 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
+
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
+
129
+ #### Take care with the start Hook's lifecycle
130
+
131
+ The token is the run's idempotency key only while its start Hook holds it. In the workflow, open the start Hook with `const hook = createHook({ token })` and leave it to the run's end. Disposing it, with `hook.dispose()` or when a `using` declaration in an inner scope ends, releases the token immediately:
132
+
133
+ - a later `start()` with the token is admitted as a new run, even while this run is still running;
134
+ - `experimental_minRetention` no longer applies, because it only holds the token after a run that ends without disposing the Hook.
135
+
136
+ A `using` declaration at the top level of the workflow function disposes the start Hook only as the function returns, so it keeps the token for the whole run. With a retention, it still releases the token at the run's end instead of holding it for the retention: use `const` there.
137
+
75
138
  ### With arguments
76
139
 
77
140
  ```typescript
@@ -151,13 +214,17 @@ export async function parentWorkflow(value: number) {
151
214
  ```
152
215
 
153
216
  <Callout type="info">
154
- 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.
155
218
  </Callout>
156
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
+
157
222
  <Callout type="warn">
158
- `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).
159
224
  </Callout>
160
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
+
161
228
  ### Dynamic Workflow Source
162
229
 
163
230
  <Callout type="warning">
@@ -1,15 +1,18 @@
1
1
  ---
2
2
  title: HookConflictError
3
- description: Thrown when creating a hook with a token that is already in use by another workflow run.
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 claimed by another active workflow run.
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
9
9
  - /docs/errors/hook-conflict
10
+ - /docs/foundations/idempotency
10
11
  ---
11
12
 
12
- `HookConflictError` is thrown when creating a hook with a token that 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).
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
+
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).
13
16
 
14
17
  ```typescript lineNumbers
15
18
  import { HookConflictError } from "workflow/errors"
@@ -0,0 +1,68 @@
1
+ ---
2
+ title: InBandSupersededError
3
+ description: A World throws this error when it refuses an in-band write from an orchestrator invocation that another invocation of the same run has superseded.
4
+ type: reference
5
+ summary: InBandSupersededError is the in-band fence's refusal. The runtime handles it by stopping the superseded orchestrator invocation, which sends the queue messages its own writes owe and then asks for a redelivery of its message.
6
+ related:
7
+ - /docs/api-reference/workflow-errors/workflow-world-error
8
+ - /docs/changelog/spec-9
9
+ ---
10
+
11
+ A World throws `InBandSupersededError` (HTTP 412, code `in-band-superseded`) when it refuses a write made by a run's orchestrator because another invocation of the same run's orchestrator has written in-band since this one loaded the event log. It applies only to runs of the experimental spec 9 runtime (`WORKFLOW_SPEC_VERSION=9`).
12
+
13
+ <Callout>
14
+ The Workflow runtime handles this error. The refused invocation stops writing, sends the queue messages its own committed writes still owe, and asks for a redelivery of its queue message instead of acknowledging it. You will only encounter it when interacting with World storage APIs directly.
15
+ </Callout>
16
+
17
+ See [The in-band fence](/docs/changelog/spec-9#the-in-band-fence) on the spec 9 page.
18
+
19
+ ```typescript lineNumbers
20
+ import { InBandSupersededError } from "workflow/errors"
21
+ declare const world: { events: { create(...args: any[]): Promise<any> } }; // @setup
22
+ declare const runId: string; // @setup
23
+ declare const event: any; // @setup
24
+
25
+ try {
26
+ await world.events.create(runId, event, { inBand: true, expectedSeqInBand: 3 });
27
+ } catch (error) {
28
+ if (InBandSupersededError.is(error)) { // [!code highlight]
29
+ console.log("Another orchestrator invocation holds this run");
30
+ }
31
+ }
32
+ ```
33
+
34
+ ## API signature
35
+
36
+ ### Properties
37
+
38
+ <TSDoc
39
+ definition={`
40
+ interface InBandSupersededError {
41
+ /** The run's highest allocated position at the refusal, when the World reports it. Diagnostic only. */
42
+ seq?: number;
43
+ /** The run's in-band position count at the refusal, when the World reports it. Diagnostic only: never adopt it. */
44
+ seqInBand?: number;
45
+ /** HTTP status: 412. */
46
+ status?: number;
47
+ /** Error code: 'in-band-superseded'. */
48
+ code?: string;
49
+ /** The error message. */
50
+ message: string;
51
+ }
52
+ export default InBandSupersededError;`}
53
+ />
54
+
55
+ ### Static methods
56
+
57
+ #### `InBandSupersededError.is(value)`
58
+
59
+ Type-safe check for `InBandSupersededError` instances. Preferred over `instanceof` because it works across module boundaries and VM contexts.
60
+
61
+ ```typescript
62
+ import { InBandSupersededError } from "workflow/errors"
63
+ declare const error: unknown; // @setup
64
+
65
+ if (InBandSupersededError.is(error)) {
66
+ // error is typed as InBandSupersededError
67
+ }
68
+ ```
@@ -51,6 +51,9 @@ All errors extend [`WorkflowError`](/docs/api-reference/workflow-errors/workflow
51
51
  <Card href="/docs/api-reference/workflow-errors/workflow-runtime-error" title="WorkflowRuntimeError">
52
52
  Thrown when the workflow runtime encounters an execution error, such as serialization failures or timeouts.
53
53
  </Card>
54
+ <Card href="/docs/api-reference/workflow-errors/workflow-start-error" title="WorkflowStartError">
55
+ Thrown when `start({ experimental_hook })` cannot confirm whether its run was queued or admitted.
56
+ </Card>
54
57
  <Card href="/docs/api-reference/workflow-errors/run-expired-error" title="RunExpiredError">
55
58
  Thrown when a workflow run has expired and can no longer be operated on.
56
59
  </Card>
@@ -85,6 +88,9 @@ All errors extend [`WorkflowError`](/docs/api-reference/workflow-errors/workflow
85
88
  <Card href="/docs/api-reference/workflow-errors/precondition-failed-error" title="PreconditionFailedError">
86
89
  Thrown when an event creation is rejected because the client's event-log snapshot is stale.
87
90
  </Card>
91
+ <Card href="/docs/api-reference/workflow-errors/in-band-superseded-error" title="InBandSupersededError">
92
+ Thrown on the experimental spec 9 runtime when a World refuses an in-band write from a superseded orchestrator invocation.
93
+ </Card>
88
94
  <Card href="/docs/api-reference/workflow-errors/too-early-error" title="TooEarlyError">
89
95
  Thrown when a request is made before the system is ready to process it.
90
96
  </Card>
@@ -12,10 +12,12 @@
12
12
  "workflow-run-cancelled-error",
13
13
  "workflow-run-not-completed-error",
14
14
  "workflow-runtime-error",
15
+ "workflow-start-error",
15
16
  "workflow-world-error",
16
17
  "throttle-error",
17
18
  "entity-conflict-error",
18
19
  "precondition-failed-error",
20
+ "in-band-superseded-error",
19
21
  "run-expired-error",
20
22
  "run-not-supported-error",
21
23
  "too-early-error"
@@ -66,3 +66,5 @@ if (PreconditionFailedError.is(error)) {
66
66
  // error is typed as PreconditionFailedError
67
67
  }
68
68
  ```
69
+
70
+ The experimental spec 9 runtime does not act on this error. See [`InBandSupersededError`](/docs/api-reference/workflow-errors/in-band-superseded-error).
@@ -0,0 +1,58 @@
1
+ ---
2
+ title: WorkflowStartError
3
+ description: Thrown when start with a hook cannot confirm whether its run was queued or admitted.
4
+ type: reference
5
+ summary: Catch WorkflowStartError to identify a start({ experimental_hook }) candidate whose outcome is unknown, then retry with the same token.
6
+ related:
7
+ - /docs/api-reference/workflow-api/start
8
+ - /docs/foundations/idempotency
9
+ ---
10
+
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
+
13
+ ```typescript lineNumbers
14
+ import { start } from "workflow/api";
15
+ import { WorkflowStartError } from "workflow/errors";
16
+ import { processOrder } from "./workflows/process-order";
17
+ declare const orderId: string; // @setup
18
+
19
+ async function startOrder() {
20
+ try {
21
+ return await start(processOrder, [orderId], {
22
+ experimental_hook: { token: `order:${orderId}`, experimental_minRetention: "1h" },
23
+ });
24
+ } catch (error) {
25
+ if (WorkflowStartError.is(error)) { // [!code highlight]
26
+ console.warn(`Unconfirmed start ${error.runId} (${error.stage}); retrying`);
27
+ return await start(processOrder, [orderId], {
28
+ experimental_hook: { token: `order:${orderId}`, experimental_minRetention: "1h" },
29
+ });
30
+ }
31
+ throw error;
32
+ }
33
+ }
34
+ ```
35
+
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
+
38
+ ## API Signature
39
+
40
+ ### Properties
41
+
42
+ <TSDoc
43
+ definition={`
44
+ import { WorkflowStartError } from "workflow/errors";
45
+ export default WorkflowStartError;`}
46
+ />
47
+
48
+ `start()` re-confirms an uncertain admission a few times with the same candidate before it throws, so a candidate that was in fact admitted is usually found. It also throws this error when the World answered that admission is switched off without recording a decision, since another copy of the candidate may still be admitted once it is back on.
49
+
50
+ A start with stream arguments pipes its streams only to a confirmed run. If it throws this error, the candidate may be admitted and waiting on input that nothing will send: cancel it with `getRun(error.runId).cancel()`. That ends the candidate as it would any run, so its token is released (once any `experimental_minRetention` has passed). `cancel()` works even if the run doesn't exist yet: a candidate that was admitted but never created can no longer be created once cancelled. If `cancel()` throws `WorkflowRunNotFoundError`, the World had not decided the candidate at all, and its queued copy can still create the run later. To learn who owns the token in that case, start again with the same token: you either become the owner or get a `HookConflictError` naming it.
51
+
52
+ `stage` is `"queue"` when the SDK could not confirm that the run was queued, and `"admission"` when it was queued but the SDK could not confirm the World's admission decision. `runId` is the candidate's run ID, for inspection.
53
+
54
+ ### Static Methods
55
+
56
+ #### `WorkflowStartError.is(value)`
57
+
58
+ Type-safe check for `WorkflowStartError` instances across module boundaries and VM contexts.
@@ -46,14 +46,25 @@ interface WorkflowWorldError {
46
46
  code?: string;
47
47
  /** The URL that was requested, if available. */
48
48
  url?: string;
49
- /** Retry-After value in seconds, present on 429 and 425 responses. */
49
+ /**
50
+ * Retry-After value in seconds, present on 429 and 425 responses, and on a
51
+ * Vercel World 503 for a start Hook whose run is still being created.
52
+ */
50
53
  retryAfter?: number;
54
+ /**
55
+ * Why the World gave \`code\`, when it says. For a start Hook request
56
+ * refused with START_HOOK_ADMISSION_REJECTED: invalid, expired,
57
+ * token_mismatch, ordinary_run or disabled.
58
+ */
59
+ reason?: string;
51
60
  /** The error message. */
52
61
  message: string;
53
62
  }
54
63
  export default WorkflowWorldError;`}
55
64
  />
56
65
 
66
+ `status`, `code` and `reason` are set where the error is thrown, in a step or outside a workflow. A `WorkflowWorldError` that reaches workflow code from a step arrives without them (`undefined`), with its name and message intact.
67
+
57
68
  ### Static methods
58
69
 
59
70
  #### `WorkflowWorldError.is(value)`
@@ -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 a workflow that creates the deterministic hook near the beginning and checks `await hook.getConflict()` to detect whether another run claimed the token first. On a conflict it resolves with the run that owns the token. 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
@@ -78,6 +78,8 @@ Each background step message is handled by a separate function invocation of the
78
78
  - **Steps still pending**: The handler returns without queuing a continuation. The last handler to complete its step will see all steps done and replay inline.
79
79
  - **Pending ops (stream writes)**: The handler queues a continuation and returns, so `waitUntil` can flush the pending stream data.
80
80
 
81
+ The inline steps of one invocation do not wait for each other. When one of them completes while its siblings are still running, the handler replays the workflow right away, so the branch it belongs to can start its next step inline. The siblings stay owned by this handler. If the workflow returns or throws first, the run ends right away; the handler still lets the siblings' bodies finish before it returns, so their step events can follow `run_completed` or `run_failed` in the log, and a sibling whose attempt fails retryably is not retried. See [`WORKFLOW_INLINE_EARLY_ADVANCE`](/docs/configuration/runtime-tuning#workflow_inline_early_advance).
82
+
81
83
  ### Convergence after parallel steps
82
84
 
83
85
  When multiple background steps complete near-simultaneously, multiple handlers may observe "all steps done" and attempt to advance the workflow concurrently. The event-sourced architecture plus the invariants below ensure safe convergence:
@@ -155,6 +157,8 @@ To prevent deadlock when polling is executed inline by the step executor, `Run#p
155
157
 
156
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.
157
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
+
158
162
  ### Mixed suspensions
159
163
 
160
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:
@@ -12,6 +12,7 @@ Stay up to date with the latest changes to Workflow SDK.
12
12
 
13
13
  ## 2026
14
14
 
15
+ - [Spec 9: single orchestrator](/docs/changelog/spec-9), opt-in (October 2026)
15
16
  - [Durable hook resume](/docs/changelog/lazy-hook-resume) (August 2026)
16
17
  - [Resilient hook resume](/docs/changelog/resilient-resume) (July 2026)
17
18
  - [Eager processing of steps and incremental event replay](/docs/changelog/eager-processing) (March 2026)