@workflow/core 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 (283) hide show
  1. package/README.md +27 -0
  2. package/dist/capabilities.d.ts +2 -0
  3. package/dist/capabilities.d.ts.map +1 -1
  4. package/dist/capabilities.js +7 -1
  5. package/dist/classify-error.d.ts.map +1 -1
  6. package/dist/classify-error.js +3 -2
  7. package/dist/create-hook.d.ts +15 -0
  8. package/dist/create-hook.d.ts.map +1 -1
  9. package/dist/create-hook.js +1 -1
  10. package/dist/events-consumer.d.ts +98 -6
  11. package/dist/events-consumer.d.ts.map +1 -1
  12. package/dist/events-consumer.js +198 -13
  13. package/dist/flushable-stream.js +11 -2
  14. package/dist/global.d.ts +6 -0
  15. package/dist/global.d.ts.map +1 -1
  16. package/dist/global.js +1 -1
  17. package/dist/logger.d.ts.map +1 -1
  18. package/dist/logger.js +65 -35
  19. package/dist/private.d.ts +41 -2
  20. package/dist/private.d.ts.map +1 -1
  21. package/dist/private.js +39 -4
  22. package/dist/replay-payload-cache.d.ts +13 -2
  23. package/dist/replay-payload-cache.d.ts.map +1 -1
  24. package/dist/replay-payload-cache.js +20 -10
  25. package/dist/runtime/after-terminal-write.d.ts +33 -0
  26. package/dist/runtime/after-terminal-write.d.ts.map +1 -0
  27. package/dist/runtime/after-terminal-write.js +23 -0
  28. package/dist/runtime/child-run-completion-notify.d.ts +36 -0
  29. package/dist/runtime/child-run-completion-notify.d.ts.map +1 -0
  30. package/dist/runtime/child-run-completion-notify.js +97 -0
  31. package/dist/runtime/child-run-completion.d.ts +45 -0
  32. package/dist/runtime/child-run-completion.d.ts.map +1 -0
  33. package/dist/runtime/child-run-completion.js +192 -0
  34. package/dist/runtime/constants.d.ts +161 -176
  35. package/dist/runtime/constants.d.ts.map +1 -1
  36. package/dist/runtime/constants.js +194 -273
  37. package/dist/runtime/delivery.d.ts +270 -0
  38. package/dist/runtime/delivery.d.ts.map +1 -0
  39. package/dist/runtime/delivery.js +325 -0
  40. package/dist/runtime/deployment-guard.d.ts +8 -1
  41. package/dist/runtime/deployment-guard.d.ts.map +1 -1
  42. package/dist/runtime/deployment-guard.js +12 -6
  43. package/dist/runtime/get-port-lazy.d.ts.map +1 -1
  44. package/dist/runtime/get-port-lazy.js +77 -14
  45. package/dist/runtime/helpers.d.ts +50 -4
  46. package/dist/runtime/helpers.d.ts.map +1 -1
  47. package/dist/runtime/helpers.js +88 -10
  48. package/dist/runtime/hook-creation.d.ts +45 -0
  49. package/dist/runtime/hook-creation.d.ts.map +1 -0
  50. package/dist/runtime/hook-creation.js +98 -0
  51. package/dist/runtime/hook-wake.d.ts +16 -14
  52. package/dist/runtime/hook-wake.d.ts.map +1 -1
  53. package/dist/runtime/hook-wake.js +31 -18
  54. package/dist/runtime/invocations.d.ts.map +1 -1
  55. package/dist/runtime/invocations.js +9 -3
  56. package/dist/runtime/out-of-band-observation.d.ts +28 -17
  57. package/dist/runtime/out-of-band-observation.d.ts.map +1 -1
  58. package/dist/runtime/out-of-band-observation.js +12 -3
  59. package/dist/runtime/quickjs-delivery-shared.d.ts +126 -0
  60. package/dist/runtime/quickjs-delivery-shared.d.ts.map +1 -0
  61. package/dist/runtime/quickjs-delivery-shared.js +176 -0
  62. package/dist/runtime/quickjs-log-view.d.ts +17 -0
  63. package/dist/runtime/quickjs-log-view.d.ts.map +1 -1
  64. package/dist/runtime/quickjs-log-view.js +31 -1
  65. package/dist/runtime/quickjs-pending-ops.d.ts +181 -0
  66. package/dist/runtime/quickjs-pending-ops.d.ts.map +1 -0
  67. package/dist/runtime/quickjs-pending-ops.js +633 -0
  68. package/dist/runtime/quickjs-runtime.d.ts +30 -5
  69. package/dist/runtime/quickjs-runtime.d.ts.map +1 -1
  70. package/dist/runtime/quickjs-runtime.js +546 -169
  71. package/dist/runtime/quickjs-serde.d.ts.map +1 -1
  72. package/dist/runtime/quickjs-serde.js +96 -5
  73. package/dist/runtime/replay-budget.d.ts +8 -1
  74. package/dist/runtime/replay-budget.d.ts.map +1 -1
  75. package/dist/runtime/replay-budget.js +12 -8
  76. package/dist/runtime/resume-hook.d.ts +15 -10
  77. package/dist/runtime/resume-hook.d.ts.map +1 -1
  78. package/dist/runtime/resume-hook.js +211 -65
  79. package/dist/runtime/run-spec-routing.d.ts +52 -0
  80. package/dist/runtime/run-spec-routing.d.ts.map +1 -0
  81. package/dist/runtime/run-spec-routing.js +78 -0
  82. package/dist/runtime/run-spec-version.d.ts +8 -4
  83. package/dist/runtime/run-spec-version.d.ts.map +1 -1
  84. package/dist/runtime/run-spec-version.js +11 -7
  85. package/dist/runtime/run.d.ts +29 -3
  86. package/dist/runtime/run.d.ts.map +1 -1
  87. package/dist/runtime/run.js +116 -11
  88. package/dist/runtime/runs.d.ts +58 -2
  89. package/dist/runtime/runs.d.ts.map +1 -1
  90. package/dist/runtime/runs.js +228 -30
  91. package/dist/runtime/spec8/constants.d.ts +177 -0
  92. package/dist/runtime/spec8/constants.d.ts.map +1 -0
  93. package/dist/runtime/spec8/constants.js +232 -0
  94. package/dist/runtime/spec8/count-step-started-events.d.ts.map +1 -0
  95. package/dist/runtime/spec8/count-step-started-events.js +72 -0
  96. package/dist/runtime/spec8/delivery.d.ts +6 -0
  97. package/dist/runtime/spec8/delivery.d.ts.map +1 -0
  98. package/dist/runtime/spec8/delivery.js +4250 -0
  99. package/dist/runtime/spec8/inline-steps-in-flight.d.ts +58 -0
  100. package/dist/runtime/spec8/inline-steps-in-flight.d.ts.map +1 -0
  101. package/dist/runtime/spec8/inline-steps-in-flight.js +104 -0
  102. package/dist/runtime/spec8/open-hook-wait-state.d.ts.map +1 -0
  103. package/dist/runtime/spec8/open-hook-wait-state.js +93 -0
  104. package/dist/runtime/{quickjs-entrypoint.d.ts → spec8/quickjs-entrypoint.d.ts} +0 -20
  105. package/dist/runtime/spec8/quickjs-entrypoint.d.ts.map +1 -0
  106. package/dist/runtime/spec8/quickjs-entrypoint.js +1779 -0
  107. package/dist/runtime/{step-executor.d.ts → spec8/step-executor.d.ts} +11 -7
  108. package/dist/runtime/spec8/step-executor.d.ts.map +1 -0
  109. package/dist/runtime/spec8/step-executor.js +1134 -0
  110. package/dist/runtime/{step-ownership.d.ts → spec8/step-ownership.d.ts} +1 -1
  111. package/dist/runtime/spec8/step-ownership.d.ts.map +1 -0
  112. package/dist/runtime/spec8/step-ownership.js +114 -0
  113. package/dist/runtime/spec8/step-single-flight.d.ts +34 -0
  114. package/dist/runtime/spec8/step-single-flight.d.ts.map +1 -0
  115. package/dist/runtime/spec8/step-single-flight.js +36 -0
  116. package/dist/runtime/{suspension-handler.d.ts → spec8/suspension-handler.d.ts} +68 -24
  117. package/dist/runtime/spec8/suspension-handler.d.ts.map +1 -0
  118. package/dist/runtime/spec8/suspension-handler.js +1291 -0
  119. package/dist/runtime/spec9/consume-after-commit.d.ts +33 -0
  120. package/dist/runtime/spec9/consume-after-commit.d.ts.map +1 -0
  121. package/dist/runtime/spec9/consume-after-commit.js +13 -0
  122. package/dist/runtime/spec9/consumed-position.d.ts +38 -0
  123. package/dist/runtime/spec9/consumed-position.d.ts.map +1 -0
  124. package/dist/runtime/spec9/consumed-position.js +48 -0
  125. package/dist/runtime/spec9/creator-rules.d.ts +220 -0
  126. package/dist/runtime/spec9/creator-rules.d.ts.map +1 -0
  127. package/dist/runtime/spec9/creator-rules.js +357 -0
  128. package/dist/runtime/spec9/deadline.d.ts +18 -0
  129. package/dist/runtime/spec9/deadline.d.ts.map +1 -0
  130. package/dist/runtime/spec9/deadline.js +27 -0
  131. package/dist/runtime/spec9/delivery.d.ts +17 -0
  132. package/dist/runtime/spec9/delivery.d.ts.map +1 -0
  133. package/dist/runtime/spec9/delivery.js +3837 -0
  134. package/dist/runtime/spec9/fence-refusals.d.ts +20 -0
  135. package/dist/runtime/spec9/fence-refusals.d.ts.map +1 -0
  136. package/dist/runtime/spec9/fence-refusals.js +55 -0
  137. package/dist/runtime/spec9/in-band-writer.d.ts +275 -0
  138. package/dist/runtime/spec9/in-band-writer.d.ts.map +1 -0
  139. package/dist/runtime/spec9/in-band-writer.js +831 -0
  140. package/dist/runtime/spec9/live-feed.d.ts +151 -0
  141. package/dist/runtime/spec9/live-feed.d.ts.map +1 -0
  142. package/dist/runtime/spec9/live-feed.js +311 -0
  143. package/dist/runtime/spec9/log-state.d.ts +137 -0
  144. package/dist/runtime/spec9/log-state.d.ts.map +1 -0
  145. package/dist/runtime/spec9/log-state.js +176 -0
  146. package/dist/runtime/spec9/quickjs-entrypoint.d.ts +185 -0
  147. package/dist/runtime/spec9/quickjs-entrypoint.d.ts.map +1 -0
  148. package/dist/runtime/spec9/quickjs-entrypoint.js +2332 -0
  149. package/dist/runtime/spec9/read-deadline.d.ts +46 -0
  150. package/dist/runtime/spec9/read-deadline.d.ts.map +1 -0
  151. package/dist/runtime/spec9/read-deadline.js +88 -0
  152. package/dist/runtime/spec9/run-ahead.d.ts +65 -0
  153. package/dist/runtime/spec9/run-ahead.d.ts.map +1 -0
  154. package/dist/runtime/spec9/run-ahead.js +102 -0
  155. package/dist/runtime/spec9/step-delivery.d.ts +111 -0
  156. package/dist/runtime/spec9/step-delivery.d.ts.map +1 -0
  157. package/dist/runtime/spec9/step-delivery.js +149 -0
  158. package/dist/runtime/spec9/step-executor.d.ts +217 -0
  159. package/dist/runtime/spec9/step-executor.d.ts.map +1 -0
  160. package/dist/runtime/spec9/step-executor.js +782 -0
  161. package/dist/runtime/spec9/step-handler.d.ts +92 -0
  162. package/dist/runtime/spec9/step-handler.d.ts.map +1 -0
  163. package/dist/runtime/spec9/step-handler.js +375 -0
  164. package/dist/runtime/spec9/step-message.d.ts +42 -0
  165. package/dist/runtime/spec9/step-message.d.ts.map +1 -0
  166. package/dist/runtime/spec9/step-message.js +81 -0
  167. package/dist/runtime/spec9/step-retention.d.ts +44 -0
  168. package/dist/runtime/spec9/step-retention.d.ts.map +1 -0
  169. package/dist/runtime/spec9/step-retention.js +51 -0
  170. package/dist/runtime/spec9/step-single-flight.d.ts +19 -0
  171. package/dist/runtime/spec9/step-single-flight.d.ts.map +1 -0
  172. package/dist/runtime/spec9/step-single-flight.js +24 -0
  173. package/dist/runtime/spec9/step-wait-creation.d.ts +162 -0
  174. package/dist/runtime/spec9/step-wait-creation.d.ts.map +1 -0
  175. package/dist/runtime/spec9/step-wait-creation.js +450 -0
  176. package/dist/runtime/spec9/suspension-handler.d.ts +125 -0
  177. package/dist/runtime/spec9/suspension-handler.d.ts.map +1 -0
  178. package/dist/runtime/spec9/suspension-handler.js +327 -0
  179. package/dist/runtime/spec9/wait-timer.d.ts +143 -0
  180. package/dist/runtime/spec9/wait-timer.d.ts.map +1 -0
  181. package/dist/runtime/spec9/wait-timer.js +173 -0
  182. package/dist/runtime/start-hook-binding.d.ts +50 -0
  183. package/dist/runtime/start-hook-binding.d.ts.map +1 -0
  184. package/dist/runtime/start-hook-binding.js +85 -0
  185. package/dist/runtime/start-hook-delivery.d.ts +47 -0
  186. package/dist/runtime/start-hook-delivery.d.ts.map +1 -0
  187. package/dist/runtime/start-hook-delivery.js +94 -0
  188. package/dist/runtime/start-hook-holder.d.ts +50 -0
  189. package/dist/runtime/start-hook-holder.d.ts.map +1 -0
  190. package/dist/runtime/start-hook-holder.js +149 -0
  191. package/dist/runtime/start.d.ts +76 -4
  192. package/dist/runtime/start.d.ts.map +1 -1
  193. package/dist/runtime/start.js +451 -62
  194. package/dist/runtime/step-latency.d.ts +3 -3
  195. package/dist/runtime/step-latency.js +1 -1
  196. package/dist/runtime/step-single-flight.d.ts +4 -8
  197. package/dist/runtime/step-single-flight.d.ts.map +1 -1
  198. package/dist/runtime/step-single-flight.js +23 -36
  199. package/dist/runtime/step-streams.d.ts +6 -0
  200. package/dist/runtime/step-streams.d.ts.map +1 -0
  201. package/dist/runtime/step-streams.js +40 -0
  202. package/dist/runtime/suspension-hooks.d.ts +84 -0
  203. package/dist/runtime/suspension-hooks.d.ts.map +1 -0
  204. package/dist/runtime/suspension-hooks.js +310 -0
  205. package/dist/runtime/wait-continuation.d.ts +27 -0
  206. package/dist/runtime/wait-continuation.d.ts.map +1 -1
  207. package/dist/runtime/wait-continuation.js +27 -2
  208. package/dist/runtime/world-compatibility.d.ts +22 -3
  209. package/dist/runtime/world-compatibility.d.ts.map +1 -1
  210. package/dist/runtime/world-compatibility.js +37 -2
  211. package/dist/runtime/world.d.ts.map +1 -1
  212. package/dist/runtime/world.js +2 -1
  213. package/dist/runtime.d.ts +2 -2
  214. package/dist/runtime.d.ts.map +1 -1
  215. package/dist/runtime.js +118 -4154
  216. package/dist/serialization/abort-stream.d.ts +11 -0
  217. package/dist/serialization/abort-stream.d.ts.map +1 -0
  218. package/dist/serialization/abort-stream.js +86 -0
  219. package/dist/serialization/reducers/common-vm.d.ts.map +1 -1
  220. package/dist/serialization/reducers/common-vm.js +39 -2
  221. package/dist/serialization/reducers/common.d.ts.map +1 -1
  222. package/dist/serialization/reducers/common.js +26 -3
  223. package/dist/serialization/types.d.ts +10 -1
  224. package/dist/serialization/types.d.ts.map +1 -1
  225. package/dist/serialization/types.js +1 -1
  226. package/dist/serialization.d.ts +21 -5
  227. package/dist/serialization.d.ts.map +1 -1
  228. package/dist/serialization.js +136 -79
  229. package/dist/set-attributes.d.ts.map +1 -1
  230. package/dist/set-attributes.js +9 -14
  231. package/dist/step/context-storage.d.ts +2 -0
  232. package/dist/step/context-storage.d.ts.map +1 -1
  233. package/dist/step/context-storage.js +1 -1
  234. package/dist/step.d.ts.map +1 -1
  235. package/dist/step.js +23 -16
  236. package/dist/telemetry/semantic-conventions.d.ts +218 -3
  237. package/dist/telemetry/semantic-conventions.d.ts.map +1 -1
  238. package/dist/telemetry/semantic-conventions.js +161 -2
  239. package/dist/test-support/append-only-world.d.ts +437 -0
  240. package/dist/test-support/append-only-world.d.ts.map +1 -0
  241. package/dist/test-support/append-only-world.js +816 -0
  242. package/dist/test-support/fence-snapshot.d.ts +11 -0
  243. package/dist/test-support/fence-snapshot.d.ts.map +1 -0
  244. package/dist/test-support/fence-snapshot.js +12 -0
  245. package/dist/test-support/load-events.d.ts +8 -0
  246. package/dist/test-support/load-events.d.ts.map +1 -0
  247. package/dist/test-support/load-events.js +27 -0
  248. package/dist/test-support/orchestrator-harness.d.ts +502 -0
  249. package/dist/test-support/orchestrator-harness.d.ts.map +1 -0
  250. package/dist/test-support/orchestrator-harness.js +116 -0
  251. package/dist/version.d.ts +1 -1
  252. package/dist/version.js +2 -2
  253. package/dist/workflow/abort-controller.d.ts.map +1 -1
  254. package/dist/workflow/abort-controller.js +7 -5
  255. package/dist/workflow/hook.d.ts +5 -0
  256. package/dist/workflow/hook.d.ts.map +1 -1
  257. package/dist/workflow/hook.js +83 -19
  258. package/dist/workflow.d.ts +45 -16
  259. package/dist/workflow.d.ts.map +1 -1
  260. package/dist/workflow.js +111 -50
  261. package/docs/api-reference/create-hook.mdx +8 -0
  262. package/docs/api-reference/create-webhook.mdx +1 -1
  263. package/docs/api-reference/fetch.mdx +2 -0
  264. package/docs/foundations/errors-and-retries.mdx +6 -0
  265. package/docs/foundations/hooks.mdx +3 -1
  266. package/docs/foundations/idempotency.mdx +190 -60
  267. package/docs/foundations/starting-workflows.mdx +3 -7
  268. package/docs/how-it-works/event-sourcing.mdx +6 -0
  269. package/package.json +5 -5
  270. package/dist/runtime/count-step-started-events.d.ts.map +0 -1
  271. package/dist/runtime/count-step-started-events.js +0 -72
  272. package/dist/runtime/open-hook-wait-state.d.ts.map +0 -1
  273. package/dist/runtime/open-hook-wait-state.js +0 -93
  274. package/dist/runtime/quickjs-entrypoint.d.ts.map +0 -1
  275. package/dist/runtime/quickjs-entrypoint.js +0 -2314
  276. package/dist/runtime/step-executor.d.ts.map +0 -1
  277. package/dist/runtime/step-executor.js +0 -1156
  278. package/dist/runtime/step-ownership.d.ts.map +0 -1
  279. package/dist/runtime/step-ownership.js +0 -114
  280. package/dist/runtime/suspension-handler.d.ts.map +0 -1
  281. package/dist/runtime/suspension-handler.js +0 -1562
  282. /package/dist/runtime/{count-step-started-events.d.ts → spec8/count-step-started-events.d.ts} +0 -0
  283. /package/dist/runtime/{open-hook-wait-state.d.ts → spec8/open-hook-wait-state.d.ts} +0 -0
@@ -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:
@@ -170,6 +170,8 @@ On Vercel, backend connection failures and interrupted event streams use the exi
170
170
 
171
171
  The SDK also replaces its shared events connection pool after repeated HTTP/2 session failures, and retries event-log reads whose HTTP/2 stream the backend resets. An events request that receives no response data for 60 seconds fails and is retried instead of stalling the invocation. Invalid backend URLs, including unsupported protocols and embedded credentials, fail immediately. Fetch requests to blocked ports or with unsupported headers (such as `Expect`) also fail without retrying. Interrupted event writes retain their existing retries; caller cancellations do not trigger another write.
172
172
 
173
+ Writing to a stream forwarded from another run looks up that run's encryption key first. A transient lookup failure (a connection error, a timeout, an HTTP `429`, or a `5xx`) uses the step's retry policy. Any other lookup failure, such as an HTTP `404` when the owner run no longer exists, fails the step without retrying, with a `EncryptionKeyLookupError` whose `cause` is the original failure.
174
+
173
175
  A connection failure does not prove that the backend rejected a write: it may have accepted it before the response was lost. Continue to make step side effects [idempotent](/docs/foundations/idempotency).
174
176
 
175
177
  Failed-run logs include the underlying error causes and their codes, exposing socket, DNS, or TLS errors behind messages such as `TypeError: fetch failed`. If a cause cannot be read, the log includes `[unavailable cause]` and the run can still be recorded as failed.
@@ -272,3 +274,7 @@ export async function placeOrderSaga(orderId: string) {
272
274
  }
273
275
  }
274
276
  ```
277
+
278
+ ## Spec 9 (experimental)
279
+
280
+ The experimental spec 9 runtime retries steps differently: a failed step is retried after about a second by default on its one queue message, and a `maxRetries = 0` step whose invocation dies after it started fails instead of running again. See [Retries on spec 9 runs](/docs/changelog/spec-9#retries).
@@ -112,7 +112,9 @@ export async function orderWorkflow(orderId: string) {
112
112
  }
113
113
  ```
114
114
 
115
- Calling `createHook()` on its own does not register the hook; registration is only committed when the workflow suspends. Awaiting `hook.getConflict()` suspends the workflow to commit the hook registration, then resolves with `null` once the hook is registered and ready to receive payloads, or with a `Run` handle for the run that owns the token (see [`HookConflictError`](/docs/errors/hook-conflict)). For `hook_conflict` events persisted by older worlds that did not record the owning run's ID, `getConflict()` rejects with `HookConflictError` instead of resolving with an incomplete handle. The conflicting run's accessors are durable steps, so the workflow can inspect `await conflict.status`, wait on `await conflict.returnValue`, or cancel the owner with `await conflict.cancel()`. See [Run idempotency](/docs/foundations/idempotency#run-idempotency) for these strategies.
115
+ Calling `createHook()` on its own does not register the hook; registration is only committed when the workflow suspends. Awaiting `hook.getConflict()` suspends the workflow to commit the hook registration, then resolves with `null` once the hook is registered and ready to receive payloads, or with a `Run` handle for the run that owns the token (see [`HookConflictError`](/docs/errors/hook-conflict)). For `hook_conflict` events persisted by older worlds that did not record the owning run's ID, `getConflict()` rejects with `HookConflictError` instead of resolving with an incomplete handle. The conflicting run's accessors are durable steps, so the workflow can inspect `await conflict.status`, wait on `await conflict.returnValue`, or cancel the owner with `await conflict.cancel()`. See [Run idempotency](/docs/foundations/idempotency#run-idempotency) for these strategies. A run started with [`start({ experimental_hook })`](/docs/api-reference/workflow-api/start#prevent-duplicate-starts) already owns its token: `createHook({ token })` with that token binds to the run's start Hook, and `getConflict()` resolves `null` without suspending.
116
+
117
+ Awaiting the registration costs one write, not a round trip through the queue: the invocation that commits the registration is the one that carries on past the awaiter, and it runs the steps the workflow started beside the awaiter — as in `await Promise.all([hook.getConflict(), prepare()])` — in that same invocation, once the registration is recorded. That covers the steps the invocation runs inline; a fan-out wider than the free inline slots ([`WORKFLOW_MAX_INLINE_STEPS`](/docs/configuration/runtime-tuning#workflow_max_inline_steps), less any inline steps the invocation is still running) queues the rest alongside the hook, so await `hook.getConflict()` before the step when the ordering itself matters. See [`createHook()`](/docs/api-reference/workflow/create-hook#registering-a-hook-before-a-step-uses-it).
116
118
 
117
119
  ### Custom tokens for deterministic hooks
118
120
 
@@ -1,8 +1,8 @@
1
1
  ---
2
2
  title: Idempotency
3
- description: Make step retries safe and coordinate duplicate workflow starts with hook tokens.
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
- summary: Use step IDs for retry-safe external calls, and route duplicate workflow-start requests through deterministic hook tokens.
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:
7
7
  - /docs/foundations/workflows-and-steps
8
8
  related:
@@ -13,7 +13,7 @@ related:
13
13
 
14
14
  Idempotency is a property of an operation that ensures repeated attempts have the same effect as a single attempt.
15
15
 
16
- In Workflow, idempotency shows up in two related places: step idempotency makes external calls safe when a step retries, and run idempotency coordinates duplicate requests that try to start the same workflow.
16
+ In Workflow, idempotency shows up in two related places: step idempotency makes external calls safe when a step retries, and run idempotency makes duplicate requests start the same workflow run only once.
17
17
 
18
18
  ## Step idempotency
19
19
 
@@ -57,11 +57,190 @@ Why this works:
57
57
 
58
58
  Step idempotency protects side effects **inside** a workflow run. Run idempotency answers a different question: if the same API request is sent twice, should it create one workflow run or two?
59
59
 
60
- Because [hooks](/docs/foundations/hooks) already ensure globally unique active tokens, Workflow can use the same mechanism to coordinate duplicate requests while a run is active.
60
+ Workflow uses a [Hook](/docs/foundations/hooks) token as the idempotency key. Pick a token from your domain, such as an order ID, invoice ID, import ID, or request ID, and pass it to `start()`.
61
61
 
62
- Use a hook token as the idempotency key for an active workflow run. Hook tokens are globally unique while they are active: if another run tries to create a hook with the same token, the runtime records a conflict, `hook.getConflict()` resolves with a `Run` handle for the run that owns the token, and the hook rejects with [`HookConflictError`](/docs/errors/hook-conflict) when the workflow awaits or iterates its payload.
62
+ ### Start a run once per key
63
63
 
64
- The token should come from your domain, such as an order ID, invoice ID, import ID, or request ID. Create the hook near the beginning of the workflow and check `await hook.getConflict()` before doing duplicate-sensitive work that depends on owning the active token. Calling `createHook()` alone does not register the hook; awaiting `getConflict()` suspends the workflow to commit the registration. Check it before calling any step: steps the workflow calls before it suspends are started alongside the hook's registration, so a duplicate run that only learns of the conflict later (for example, by awaiting the hook and letting `HookConflictError` end the run) may already have started them. See [Registering a hook before a step uses it](/docs/api-reference/workflow/create-hook#registering-a-hook-before-a-step-uses-it).
64
+ ```typescript title="app/api/orders/route.ts" lineNumbers
65
+ import { start } from "workflow/api";
66
+ import { HookConflictError } from "workflow/errors";
67
+ import { processOrder } from "./workflows/process-order";
68
+
69
+ export async function POST(request: Request) {
70
+ const { orderId } = await request.json();
71
+
72
+ try {
73
+ const run = await start(processOrder, [orderId], {
74
+ experimental_hook: { token: `order:${orderId}` }, // [!code highlight]
75
+ });
76
+ return Response.json({ runId: run.runId, duplicate: false });
77
+ } catch (error) {
78
+ if (!HookConflictError.is(error)) throw error;
79
+ return Response.json({ runId: error.conflictingRunId, duplicate: true }); // [!code highlight]
80
+ }
81
+ }
82
+ ```
83
+
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
+
86
+ ### Start or route to the owner
87
+
88
+ A duplicate request often carries data the owner should receive, such as a follow-up message in a chat. Since the start Hook exists from the moment the run is admitted, you can resume it right away on a conflict, even before the owner starts executing:
89
+
90
+ ```typescript title="app/api/orders/route.ts" lineNumbers
91
+ import { resumeHook, start } from "workflow/api";
92
+ import { HookConflictError, HookNotFoundError } from "workflow/errors";
93
+ import { processOrder } from "./workflows/process-order";
94
+
95
+ export async function POST(request: Request) {
96
+ const { orderId, note } = await request.json();
97
+ const token = `order:${orderId}`;
98
+
99
+ let owner: string | undefined;
100
+ for (let attempt = 0; attempt < 3; attempt++) {
101
+ try {
102
+ const run = await start(processOrder, [orderId, note], { experimental_hook: { token } });
103
+ return Response.json({ runId: run.runId, started: true });
104
+ } catch (error) {
105
+ if (!HookConflictError.is(error)) throw error;
106
+ owner = error.conflictingRunId;
107
+ }
108
+
109
+ try {
110
+ const hook = await resumeHook(token, { note }); // [!code highlight]
111
+ return Response.json({ runId: hook.runId, started: false });
112
+ } catch (error) {
113
+ // The owner's Hook is no longer resumable (it ended, or disposed its
114
+ // start Hook): try to start again, which may take the token.
115
+ if (!HookNotFoundError.is(error)) throw error; // [!code highlight]
116
+ }
117
+ }
118
+
119
+ // Still refused: a finished owner holds the token for its retention, or
120
+ // the owner is a candidate that was admitted but never became a run.
121
+ throw new Error(`Run ${owner} holds ${token}; it can't be started or resumed`);
122
+ }
123
+ ```
124
+
125
+ Every caller either starts the run, delivers its payload to the owner, or learns which run holds the token. While the owner's start Hook is open, the loop needs at most two calls. A `HookNotFoundError` after a conflict means the owner's Hook is no longer resumable: the owner ended, or [disposed its start Hook](#take-care-with-the-start-hooks-lifecycle). The next `start()` may then take the token, or be refused again: by a finished owner that still holds it for its retention, or by another caller that started first.
126
+
127
+ If the token has a [retention](#keep-the-token-after-the-run-ends), a finished owner keeps refusing new starts until the retention passes, and its Hook can no longer be resumed, so the loop above gives up after its attempts and names that run. Use `getRun(owner)` to tell the caller what the finished run returned.
128
+
129
+ ### Receive the payloads in the workflow
130
+
131
+ To read the payloads, call `createHook()` in the workflow with the same token:
132
+
133
+ ```typescript title="workflows/process-order.ts" lineNumbers
134
+ import { createHook } from "workflow";
135
+
136
+ type OrderUpdate = { note: string; done?: boolean };
137
+ declare function recordNote(orderId: string, note: string): Promise<void>; // @setup
138
+
139
+ export async function processOrder(orderId: string, note: string) {
140
+ "use workflow";
141
+
142
+ await recordNote(orderId, note);
143
+
144
+ const updates = createHook<OrderUpdate>({ token: `order:${orderId}` }); // [!code highlight]
145
+ for await (const update of updates) {
146
+ await recordNote(orderId, update.note);
147
+ if (update.done) break;
148
+ }
149
+ }
150
+ ```
151
+
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
+ - Payloads resumed before the workflow opens the Hook are kept, and are delivered in order once it does.
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({ 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
+
157
+ ### Keep the token after the run ends
158
+
159
+ The start Hook follows the ordinary Hook lifecycle, like a `createHook()` in the run. Without a retention, the token is released when the run ends, and a later `start()` with the token is admitted as a new run.
160
+
161
+ To refuse late duplicates too, set `experimental_minRetention`. It 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), and a duration counts from `start()`:
162
+
163
+ ```typescript lineNumbers
164
+ import { start } from "workflow/api";
165
+ import { processOrder } from "./workflows/process-order";
166
+ declare const orderId: string; // @setup
167
+
168
+ const run = await start(processOrder, [orderId, ""], {
169
+ experimental_hook: {
170
+ token: `order:${orderId}`,
171
+ experimental_minRetention: "30 days", // [!code highlight]
172
+ metadata: { orderId },
173
+ },
174
+ });
175
+ ```
176
+
177
+ The run owns the token until it ends, even if the retention passes first. After the run ends, and until the retention passes:
178
+
179
+ - a duplicate `start()` throws `HookConflictError` naming the finished owner;
180
+ - [`getHookByToken()`](/docs/api-reference/workflow-api/get-hook-by-token) still returns the Hook, with the `start()` metadata;
181
+ - `resumeHook()` throws `HookNotFoundError`, because a finished run can't receive payloads.
182
+
183
+ There is no default retention.
184
+
185
+ Cancelling the owner ends the run, so it releases the token too, once any retention has passed.
186
+
187
+ ### Take care with the start Hook's lifecycle
188
+
189
+ <Callout type="warn">
190
+ The run holds its token only while its start Hook does. Disposing the start Hook, with `hook.dispose()` or when a `using` declaration in an inner scope ends, releases the token at once, as it does for any Hook. A later `start()` with the token is then admitted as a new run, even while this one is still running, and `experimental_minRetention` no longer applies: it only holds the token after a run that ends without disposing the Hook.
191
+ </Callout>
192
+
193
+ Open the start Hook with `const`, as in the examples above, and let the run's end release it. After disposing it, the run can call `createHook({ token })` again for a new Hook, but only if no other run has taken the token in the meantime; otherwise `getConflict()` names that run.
194
+
195
+ ### Dispose the start Hook with `using`
196
+
197
+ `using` disposes a Hook when its scope ends, which reads well when the workflow only needs the payloads for part of its work:
198
+
199
+ ```typescript title="workflows/process-order.ts" lineNumbers
200
+ import { createHook } from "workflow";
201
+
202
+ type OrderUpdate = { note: string; done?: boolean };
203
+ declare function recordNote(orderId: string, note: string): Promise<void>; // @setup
204
+ declare function shipOrder(orderId: string): Promise<void>; // @setup
205
+
206
+ export async function processOrder(orderId: string, note: string) {
207
+ "use workflow";
208
+
209
+ {
210
+ using updates = createHook<OrderUpdate>({ token: `order:${orderId}` }); // [!code highlight]
211
+ for await (const update of updates) {
212
+ await recordNote(orderId, update.note);
213
+ if (update.done) break;
214
+ }
215
+ } // The start Hook is disposed here, and the token is released.
216
+
217
+ await shipOrder(orderId);
218
+ }
219
+ ```
220
+
221
+ Disposing the start Hook ends the run's idempotency: from the end of that block, another `start()` with the token is admitted while this run ships the order. Use it when that is what you want. To keep duplicates out for the whole run, use `const`. A `using` at the top level of the workflow function disposes the Hook only as the run returns, but with a retention it releases the token then instead of holding it.
222
+
223
+ ### When `start()` can't confirm the outcome
224
+
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
+
227
+ ### World support
228
+
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
+
231
+ | World | Support |
232
+ | --- | --- |
233
+ | [Local World](/worlds/local) | Supported. |
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
+
237
+ See [`start()`](/docs/api-reference/workflow-api/start#prevent-duplicate-starts) for the full option reference.
238
+
239
+ ### Coordinate inside the workflow
240
+
241
+ On a World without atomic start Hooks, or when a run should decide for itself how to treat a duplicate, coordinate with `createHook()` and `getConflict()` in the workflow instead. Hook tokens are unique while active: if another run already owns the token, `await hook.getConflict()` resolves with a `Run` handle for the owner, and awaiting the hook rejects with [`HookConflictError`](/docs/errors/hook-conflict).
242
+
243
+ Create the hook near the beginning of the workflow, and check `await hook.getConflict()` before calling any step. Awaiting it suspends the workflow to commit the registration; steps called before that suspension start alongside it, so a duplicate run that learns of the conflict later may already have started them. See [Registering a hook before a step uses it](/docs/api-reference/workflow/create-hook#registering-a-hook-before-a-step-uses-it).
65
244
 
66
245
  ```typescript lineNumbers
67
246
  import { createHook } from "workflow";
@@ -96,62 +275,15 @@ export async function processOrder(orderId: string): Promise<OrderResult> {
96
275
  }
97
276
  ```
98
277
 
99
- The runtime creates the hook atomically. At most one hook can own `order:${orderId}`, so duplicate workflow runs converge on one owner. A duplicate run observes `getConflict()` resolving with the owner's `Run` and returns before it reaches `chargeOrder()`. The conflicting run's accessors (`status`, `returnValue`, `cancel()`, …) are durable steps, so the duplicate run can do more than report the owner. See [conflict-handling strategies](#conflict-handling-strategies) below.
100
-
101
- Outside the workflow, try to resume the hook first. If the hook is not registered yet, start the workflow and retry the resume until the new run creates the hook:
102
-
103
- ```typescript lineNumbers
104
- import { resumeHook, start } from "workflow/api";
105
- import { HookNotFoundError } from "workflow/errors";
106
- import { processOrder } from "./workflows/process-order";
107
-
108
- type OrderRequest = { confirmed: boolean };
109
-
110
- async function resumeOrder(token: string, payload: OrderRequest) {
111
- for (let attempt = 0; attempt < 5; attempt++) {
112
- try {
113
- return await resumeHook(token, payload); // [!code highlight]
114
- } catch (error) {
115
- if (!HookNotFoundError.is(error)) throw error;
116
- await new Promise((resolve) => setTimeout(resolve, 100));
117
- }
118
- }
119
-
120
- throw new Error("Order workflow did not register its hook in time");
121
- }
122
-
123
- export async function POST(request: Request) {
124
- const { orderId, confirmed } = await request.json();
125
- const token = `order:${orderId}`;
126
- const payload = { confirmed };
127
-
128
- try {
129
- const hook = await resumeHook(token, payload); // [!code highlight]
130
- return Response.json({ runId: hook.runId, reused: true });
131
- } catch (error) {
132
- if (!HookNotFoundError.is(error)) throw error;
133
- }
134
-
135
- const run = await start(processOrder, [orderId]); // [!code highlight]
136
- const resumed = await resumeOrder(token, payload);
137
-
138
- // A concurrent request's run may have won the race between `start()` // [!code highlight]
139
- // and hook registration. The resume always reaches the actual active // [!code highlight]
140
- // owner, so compare run IDs instead of waiting for this run to finish. // [!code highlight]
141
- return Response.json({ // [!code highlight]
142
- runId: resumed.runId, // [!code highlight]
143
- reused: resumed.runId !== run.runId, // [!code highlight]
144
- }); // [!code highlight]
145
- }
146
- ```
278
+ Outside the workflow, try `resumeHook()` first, and on `HookNotFoundError` call `start()` and retry the resume until the new run registers its hook.
147
279
 
148
280
  <Callout type="warn">
149
- This avoids creating a new run only after the first run has registered its hook. Because `start()` returns before the run body executes and calls `createHook()`, two concurrent requests can both observe "no hook yet" and each call `start()`. The race is resolved inside the workflow body, where the losing run observes `getConflict()` resolving with the active owner and returns without doing duplicate-sensitive work, and the route detects it by comparing the resumed hook's `runId` against the run it just started, without waiting for either run to finish. A native API for atomically starting a run and registering a hook is in the works. Until then, model recovery inside the workflow by checking `hook.getConflict()`.
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.
150
282
  </Callout>
151
283
 
152
- This coordinates active runs by default: the token becomes available when its workflow ends. Set `experimental_minRetention` to keep it unavailable to late duplicates. After the workflow ends, the Hook can still be found with `getHookByToken()` until retention ends, but it cannot be resumed. See [`createHook()` minimum retention](/docs/api-reference/workflow/create-hook#keep-a-token-unavailable-after-the-run-ends) for examples and supported values.
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).
153
285
 
154
- ### Conflict-handling strategies
286
+ #### Conflict-handling strategies
155
287
 
156
288
  Some workflow systems resolve duplicate IDs with a fixed, pre-declared policy, typically a static choice between rejecting the new execution, deferring to the existing one, or terminating it. Workflow has no policy enum. `hook.getConflict()` hands the duplicate run the conflicting `Run` itself, and the policy is ordinary code, including policies that inspect state before deciding, which static configuration can't express.
157
289
 
@@ -302,9 +434,7 @@ export async function processOrderNewestWins(orderId: string) {
302
434
 
303
435
  A run started at a Workflow spec version below 8, including runs started by older SDK releases, can't be taken from. In that case the forced Hook rejects with `HookConflictError`, as it would without `experimental_force`.
304
436
 
305
- If duplicate requests should only reuse the active run without sending data, use [`getHookByToken()`](/docs/api-reference/workflow-api/get-hook-by-token) as an advisory pre-check before calling `start()`. The workflow should still check `hook.getConflict()`, because the lookup and `start()` are not atomic.
306
-
307
- Because this pattern uses hooks for idempotency, duplicate requests can also inject additional data and steer the existing run. The route example above uses `resumeHook()` for that: if the hook already exists, the duplicate request resumes the active workflow; if the hook is not registered yet, the route starts the workflow and retries `resumeHook()` so the payload is not dropped.
437
+ [`getHookByToken()`](/docs/api-reference/workflow-api/get-hook-by-token) before `start()` is only an advisory pre-check in this pattern: the lookup and `start()` are not atomic, so the workflow should still check `hook.getConflict()`.
308
438
 
309
439
  ## Related docs
310
440
 
@@ -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
@@ -129,6 +129,8 @@ While a hook is active, its token is reserved and cannot be used by other workfl
129
129
 
130
130
  When a workflow ends, its hooks can no longer be resumed. They are normally removed, and their tokens become available again. With `experimental_minRetention`, a hook remains readable, and its token remains unavailable until retention ends. A `hook_disposed` event removes the hook and makes its token available immediately.
131
131
 
132
+ A hook disposed as the workflow returns or throws, such as one declared with `using` in the workflow function's top-level scope, is released by the run's `run_completed` or `run_failed` event, so the log records no separate `hook_disposed`. Disposing a hook that uses `experimental_minRetention` still records one, because it releases the token before retention ends.
133
+
132
134
  See [Hooks and webhooks](/docs/foundations/hooks) for more on how hooks and webhooks work.
133
135
 
134
136
  ### Wait lifecycle
@@ -381,3 +383,7 @@ Step-to-step overhead (STSO) measures the time the runtime adds between two step
381
383
  <MetricVideo metric="stso" />
382
384
 
383
385
  See [Step-to-step overhead](/docs/performance#step-to-step-overhead-stso) on the Performance page for how it's measured and the latest results.
386
+
387
+ ## Spec 9 (experimental)
388
+
389
+ The experimental spec 9 runtime writes the same event types with a different model: one orchestrator per run writes every decision behind an in-band fence, step and wait events are plain appends, and an inline step is created by its first `step_started`. See [The event log on spec 9 runs](/docs/changelog/spec-9#the-event-log).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@workflow/core",
3
- "version": "5.2.3",
3
+ "version": "5.4.0",
4
4
  "description": "Core runtime and engine for Workflow SDK",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -89,12 +89,12 @@
89
89
  "@standard-schema/spec": "1.0.0",
90
90
  "@types/ms": "2.1.0",
91
91
  "@vercel/functions": "^3.8.0",
92
- "@workflow/errors": "5.0.5",
92
+ "@workflow/errors": "5.1.0",
93
93
  "@workflow/serde": "5.0.0",
94
94
  "@workflow/utils": "5.0.2",
95
- "@workflow/world": "5.0.5",
96
- "@workflow/world-local": "5.1.2",
97
- "@workflow/world-vercel": "5.2.3",
95
+ "@workflow/world": "5.1.0",
96
+ "@workflow/world-local": "5.2.1",
97
+ "@workflow/world-vercel": "5.4.0",
98
98
  "acorn": "8.15.0",
99
99
  "debug": "4.4.3",
100
100
  "devalue": "6.0.3",
@@ -1 +0,0 @@
1
- {"version":3,"file":"count-step-started-events.d.ts","sourceRoot":"","sources":["../../src/runtime/count-step-started-events.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAE7C;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,cAAc,GACtB;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GACtC;IAAE,IAAI,EAAE,eAAe,CAAA;CAAE,CAAC;AAU9B;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,GAAG,SAAS,EAClC,MAAM,EAAE,MAAM,EACd,KAAK,CAAC,EAAE,cAAc,GACrB,MAAM,CAmCR"}
@@ -1,72 +0,0 @@
1
- const ownerOf = (e) => 'eventData' in e &&
2
- e.eventData &&
3
- 'ownerMessageId' in e.eventData &&
4
- typeof e.eventData.ownerMessageId === 'string'
5
- ? e.eventData.ownerMessageId
6
- : undefined;
7
- /**
8
- * Number of `step_started` events already recorded for a step, used as the
9
- * authoritative attempt count for the maxRetries ceiling (the only bound for
10
- * steps that time out without writing a `step_failed`).
11
- *
12
- * IMPORTANT: the raw (unscoped) count is NOT a reliable attempt number.
13
- * Concurrent invocations racing on the same pending batch (stale replays,
14
- * wake replays, a step message dispatched by a replay that lost the
15
- * create-claim race, ...) can each write a `step_started` for the same
16
- * logical attempt. Worlds without an atomic start guard (world-local) let
17
- * all of them through. Counting those duplicates as "attempts" made the
18
- * maxRetries ceiling fire on healthy runs and fail them with a false
19
- * "exceeded max retries" (see workflow#3069).
20
- *
21
- * Callers therefore scope the count to the starts their ceiling is actually
22
- * about via `scope`:
23
- * - the inline owned-recovery ceiling counts only THIS message's starts
24
- * (`ownedBy`): each real (re)delivery of the owning message stamps its
25
- * `ownerMessageId` on the start it writes, while racing invocations stamp
26
- * their own IDs (or none), so they no longer inflate the count;
27
- * - the background-step ceiling counts the lifecycle attempt total
28
- * (`totalAttempts`: bare starts plus the largest single owner's starts),
29
- * so a step that exhausted part of its budget under inline ownership
30
- * before transitioning to queued/bare retries still trips the combined
31
- * ceiling, while racers' one-off stamped duplicates don't accumulate, and
32
- * throttle/too-early redeliveries (which write no start at all) stay
33
- * excluded as before.
34
- */
35
- export function countStepStartedEvents(events, stepId, scope) {
36
- if (!events) {
37
- return 0;
38
- }
39
- let bare = 0;
40
- const byOwner = new Map();
41
- for (const e of events) {
42
- if (e.eventType !== 'step_started' || e.correlationId !== stepId) {
43
- continue;
44
- }
45
- const owner = ownerOf(e);
46
- if (owner === undefined) {
47
- bare++;
48
- }
49
- else {
50
- byOwner.set(owner, (byOwner.get(owner) ?? 0) + 1);
51
- }
52
- }
53
- if (scope === undefined) {
54
- let total = bare;
55
- for (const count of byOwner.values()) {
56
- total += count;
57
- }
58
- return total;
59
- }
60
- if (scope.type === 'ownedBy') {
61
- return byOwner.get(scope.messageId) ?? 0;
62
- }
63
- // totalAttempts
64
- let maxOwner = 0;
65
- for (const count of byOwner.values()) {
66
- if (count > maxOwner) {
67
- maxOwner = count;
68
- }
69
- }
70
- return bare + maxOwner;
71
- }
72
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY291bnQtc3RlcC1zdGFydGVkLWV2ZW50cy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydW50aW1lL2NvdW50LXN0ZXAtc3RhcnRlZC1ldmVudHMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBcUJBLE1BQU0sT0FBTyxHQUFHLENBQUMsQ0FBUSxFQUFzQixFQUFFLENBQy9DLFdBQVcsSUFBSSxDQUFDO0lBQ2hCLENBQUMsQ0FBQyxTQUFTO0lBQ1gsZ0JBQWdCLElBQUksQ0FBQyxDQUFDLFNBQVM7SUFDL0IsT0FBTyxDQUFDLENBQUMsU0FBUyxDQUFDLGNBQWMsS0FBSyxRQUFRO0lBQzVDLENBQUMsQ0FBQyxDQUFDLENBQUMsU0FBUyxDQUFDLGNBQWM7SUFDNUIsQ0FBQyxDQUFDLFNBQVMsQ0FBQztBQUVoQjs7Ozs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VybiB0b3RhbDtcbiAgfVxuICBpZiAoc2NvcGUudHlwZSA9PT0gJ293bmVkQnknKSB7XG4gICAgcmV0dXJuIGJ5T3duZXIuZ2V0KHNjb3BlLm1lc3NhZ2VJZCkgPz8gMDtcbiAgfVxuICAvLyB0b3RhbEF0dGVtcHRzXG4gIGxldCBtYXhPd25lciA9IDA7XG4gIGZvciAoY29uc3QgY291bnQgb2YgYnlPd25lci52YWx1ZXMoKSkge1xuICAgIGlmIChjb3VudCA+IG1heE93bmVyKSB7XG4gICAgICBtYXhPd25lciA9IGNvdW50O1xuICAgIH1cbiAgfVxuICByZXR1cm4gYmFyZSArIG1heE93bmVyO1xufVxuIl19
@@ -1 +0,0 @@
1
- {"version":3,"file":"open-hook-wait-state.d.ts","sourceRoot":"","sources":["../../src/runtime/open-hook-wait-state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAE7C;;;GAGG;AACH,MAAM,WAAW,oBAAoB;IACnC,+FAA+F;IAC/F,QAAQ,EAAE,OAAO,CAAC;IAClB,6FAA6F;IAC7F,QAAQ,EAAE,OAAO,CAAC;IAClB;;;;;;OAMG;IACH,0BAA0B,EAAE,MAAM,GAAG,SAAS,CAAC;CAChD;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,oBAAoB,CAiC1E;AAuBD;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,IAAI,CAAC,oBAAoB,EAAE,4BAA4B,CAAC,EAC/D,UAAU,EAAE,MAAM,GACjB,OAAO,CAKT"}