@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
@@ -1,5 +1,5 @@
1
1
  import type { Event } from '@workflow/world';
2
- import type { StepInvocationQueueItem } from '../global.js';
2
+ import type { StepInvocationQueueItem } from '../../global.js';
3
3
  /**
4
4
  * Inline step ownership helpers for the pending-step dispatch decision table
5
5
  * in runtime.ts (workflow#2780). Ownership state itself is derived per-replay
@@ -0,0 +1 @@
1
+ {"version":3,"file":"step-ownership.d.ts","sourceRoot":"","sources":["../../../src/runtime/spec8/step-ownership.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAG/D;;;;;;GAMG;AAEH;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,uBAAuB,GAAG,OAAO,CAM5E;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,yBAAyB,CACvC,IAAI,EAAE,uBAAuB,EAC7B,KAAK,EAAE,MAAM,GACZ,MAAM,CAKR;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,uBAAuB,GAAG,MAAM,CAE5E;AAED;;;;;;;;GAQG;AACH,wBAAgB,4BAA4B,CAC1C,MAAM,EAAE,KAAK,EAAE,EACf,qBAAqB,EAAE,GAAG,CAAC,MAAM,GAAG,SAAS,CAAC,EAC9C,SAAS,EAAE,MAAM,GAChB,OAAO,CAgCT"}
@@ -0,0 +1,114 @@
1
+ import { getInlineOwnershipLeaseSeconds } from './constants.js';
2
+ /**
3
+ * Inline step ownership helpers for the pending-step dispatch decision table
4
+ * in runtime.ts (workflow#2780). Ownership state itself is derived per-replay
5
+ * from the event log by the step consumer in step.ts and surfaced on
6
+ * StepInvocationQueueItem; these functions interpret that state at dispatch
7
+ * time.
8
+ */
9
+ /**
10
+ * Whether inline step ownership is active for a pending step: created,
11
+ * latest `step_started` carries an owner stamp, and no `step_retrying` has
12
+ * been observed (from `step_retrying` on, the step is queue-owned by its
13
+ * delayed retry handoff / replay requeue, so ownership is permanently
14
+ * lapsed for the correlation ID).
15
+ */
16
+ export function isStepOwnershipActive(step) {
17
+ return (step.hasCreatedEvent === true &&
18
+ step.ownerMessageId !== undefined &&
19
+ step.sawRetrying !== true);
20
+ }
21
+ /**
22
+ * Seconds left on an owned step's liveness lease, anchored at its latest
23
+ * `step_started`. 0 means the lease has expired (or the start timestamp is
24
+ * missing, the degraded mode for worlds whose events lack usable
25
+ * timestamps), in which case dispatch falls back to the immediate enqueue.
26
+ *
27
+ * The result is clamped to the configured lease: `lastStartedAt` is the
28
+ * server-stamped event `createdAt` while `nowMs` is the local clock, so a
29
+ * client running behind the server would otherwise compute a remainder
30
+ * LONGER than the lease itself, and with the lease tuned to the 900s cap,
31
+ * a `delaySeconds` above the queue's per-message maximum, which SQS-backed
32
+ * worlds reject outright (the wake replay's enqueue would throw and ride
33
+ * the redelivery loop). The clamp makes skew strictly harmless; remaining
34
+ * time can never legitimately exceed the full lease anyway.
35
+ */
36
+ export function stepLeaseRemainingSeconds(step, nowMs) {
37
+ if (step.lastStartedAt === undefined)
38
+ return 0;
39
+ const leaseSeconds = getInlineOwnershipLeaseSeconds();
40
+ const remainingMs = step.lastStartedAt + leaseSeconds * 1000 - nowMs;
41
+ return Math.min(leaseSeconds, Math.max(0, Math.ceil(remainingMs / 1000)));
42
+ }
43
+ /**
44
+ * Idempotency key for the delayed backstop wake of an inline-owned step.
45
+ *
46
+ * The key is scoped to the current OWNERSHIP EPOCH (the timestamp of the
47
+ * latest `step_started`), not just the correlation ID. Within one epoch,
48
+ * every wake replay derives the same key, so fan-out stays capped at one
49
+ * pending backstop per step. But when owner recovery re-stamps the step
50
+ * (queue redelivery of the owning message → new `step_started` → new
51
+ * `lastStartedAt`), the key CHANGES. This is load-bearing for liveness:
52
+ * queues dedupe an idempotency key for the lifetime of the original
53
+ * message (including while a delivery of it is in flight), so a backstop
54
+ * that fires during a refreshed lease and tries to re-arm under a fixed key
55
+ * would dedupe against ITSELF and be dropped, leaving no escape hatch if
56
+ * the recovered owner later dies without further redeliveries. The epoch
57
+ * suffix gives the re-arm a fresh key. Pending backstops are bounded by the
58
+ * number of ownership epochs, i.e. the queue's redelivery budget for the
59
+ * owning message.
60
+ *
61
+ * The epoch value comes from the persisted event's `createdAt`, so every
62
+ * replayer derives the same key. Callers only build backstops when the
63
+ * lease has time remaining, which requires `lastStartedAt` to be set.
64
+ *
65
+ * The key must also never be the step message's own `idempotencyKey`
66
+ * (the bare correlation ID): the owner's retry handoff enqueues the step
67
+ * under that key with a short backoff, and a pending backstop sharing it
68
+ * would absorb the retry, turning a 1s backoff into a full-lease stall.
69
+ */
70
+ export function backstopIdempotencyKey(step) {
71
+ return `${step.correlationId}:backstop:${step.lastStartedAt}`;
72
+ }
73
+ /**
74
+ * Whether any of the given pending correlation IDs is inline-owned by
75
+ * `messageId` per the raw event log: its LATEST `step_started` carries
76
+ * `ownerMessageId === messageId` and no `step_retrying` follows it. Used by
77
+ * the background-step fast path, which sees raw events (not the replay's
78
+ * queueItems), to decide whether to fall through to the main loop so this
79
+ * invocation can recover a step it owns instead of returning and leaving it
80
+ * to the delayed backstop.
81
+ */
82
+ export function hasPendingStepOwnedByMessage(events, pendingCorrelationIds, messageId) {
83
+ // Latest-wins scan: events are in log order, so later entries overwrite.
84
+ // A step_retrying lapses ownership permanently (matching the sawRetrying
85
+ // semantics of the replay consumer in step.ts): from that point the step
86
+ // is queue-owned, whatever starts follow.
87
+ const latestOwner = new Map();
88
+ const sawRetrying = new Set();
89
+ for (const e of events) {
90
+ if (e.correlationId === undefined)
91
+ continue;
92
+ if (e.eventType === 'step_started') {
93
+ const owner = 'eventData' in e &&
94
+ e.eventData &&
95
+ 'ownerMessageId' in e.eventData &&
96
+ typeof e.eventData.ownerMessageId === 'string'
97
+ ? e.eventData.ownerMessageId
98
+ : undefined;
99
+ latestOwner.set(e.correlationId, owner);
100
+ }
101
+ else if (e.eventType === 'step_retrying') {
102
+ sawRetrying.add(e.correlationId);
103
+ }
104
+ }
105
+ for (const id of pendingCorrelationIds) {
106
+ if (id !== undefined &&
107
+ !sawRetrying.has(id) &&
108
+ latestOwner.get(id) === messageId) {
109
+ return true;
110
+ }
111
+ }
112
+ return false;
113
+ }
114
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3RlcC1vd25lcnNoaXAuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvcnVudGltZS9zcGVjOC9zdGVwLW93bmVyc2hpcC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFFQSxPQUFPLEVBQUUsOEJBQThCLEVBQUUsTUFBTSxnQkFBZ0IsQ0FBQztBQUVoRTs7Ozs7O0dBTUc7QUFFSDs7Ozs7O0dBTUc7QUFDSCxNQUFNLFVBQVUscUJBQXFCLENBQUMsSUFBNkI7SUFDakUsT0FBTyxDQUNMLElBQUksQ0FBQyxlQUFlLEtBQUssSUFBSTtRQUM3QixJQUFJLENBQUMsY0FBYyxLQUFLLFNBQVM7UUFDakMsSUFBSSxDQUFDLFdBQVcsS0FBSyxJQUFJLENBQzFCLENBQUM7QUFDSixDQUFDO0FBRUQ7Ozs7Ozs7Ozs7Ozs7O0dBY0c7QUFDSCxNQUFNLFVBQVUseUJBQXlCLENBQ3ZDLElBQTZCLEVBQzdCLEtBQWE7SUFFYixJQUFJLElBQUksQ0FBQyxhQUFhLEtBQUssU0FBUztRQUFFLE9BQU8sQ0FBQyxDQUFDO0lBQy9DLE1BQU0sWUFBWSxHQUFHLDhCQUE4QixFQUFFLENBQUM7SUFDdEQsTUFBTSxXQUFXLEdBQUcsSUFBSSxDQUFDLGFBQWEsR0FBRyxZQUFZLEdBQUcsSUFBSSxHQUFHLE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xzdHJpbmcsIHN0cmluZyB8IHVuZGVmaW5lZD4oKTtcbiAgY29uc3Qgc2F3UmV0cnlpbmcgPSBuZXcgU2V0PHN0cmluZz4oKTtcbiAgZm9yIChjb25zdCBlIG9mIGV2ZW50cykge1xuICAgIGlmIChlLmNvcnJlbGF0aW9uSWQgPT09IHVuZGVmaW5lZCkgY29udGludWU7XG4gICAgaWYgKGUuZXZlbnRUeXBlID09PSAnc3RlcF9zdGFydGVkJykge1xuICAgICAgY29uc3Qgb3duZXIgPVxuICAgICAgICAnZXZlbnREYXRhJyBpbiBlICYmXG4gICAgICAgIGUuZXZlbnREYXRhICYmXG4gICAgICAgICdvd25lck1lc3NhZ2VJZCcgaW4gZS5ldmVudERhdGEgJiZcbiAgICAgICAgdHlwZW9mIGUuZXZlbnREYXRhLm93bmVyTWVzc2FnZUlkID09PSAnc3RyaW5nJ1xuICAgICAgICAgID8gZS5ldmVudERhdGEub3duZXJNZXNzYWdlSWRcbiAgICAgICAgICA6IHVuZGVmaW5lZDtcbiAgICAgIGxhdGVzdE93bmVyLnNldChlLmNvcnJlbGF0aW9uSWQsIG93bmVyKTtcbiAgICB9IGVsc2UgaWYgKGUuZXZlbnRUeXBlID09PSAnc3RlcF9yZXRyeWluZycpIHtcbiAgICAgIHNhd1JldHJ5aW5nLmFkZChlLmNvcnJlbGF0aW9uSWQpO1xuICAgIH1cbiAgfVxuICBmb3IgKGNvbnN0IGlkIG9mIHBlbmRpbmdDb3JyZWxhdGlvbklkcykge1xuICAgIGlmIChcbiAgICAgIGlkICE9PSB1bmRlZmluZWQgJiZcbiAgICAgICFzYXdSZXRyeWluZy5oYXMoaWQpICYmXG4gICAgICBsYXRlc3RPd25lci5nZXQoaWQpID09PSBtZXNzYWdlSWRcbiAgICApIHtcbiAgICAgIHJldHVybiB0cnVlO1xuICAgIH1cbiAgfVxuICByZXR1cm4gZmFsc2U7XG59XG4iXX0=
@@ -0,0 +1,34 @@
1
+ import type { StepExecutionResult } from './step-executor.js';
2
+ /**
3
+ * Single-flight for a step body. This is a required companion to inline step
4
+ * ownership (see `isInlineOwnershipEnabled` in `./constants.ts`): the
5
+ * ownership lease is a *death proof* only on platforms with a bounded
6
+ * invocation lifetime. On worlds without an invocation kill bound
7
+ * (world-local's single process, self-hosted deployments) a delayed backstop
8
+ * can fire while the owning execution is still mid-body, in the same process.
9
+ * This absorbs that race: the loser awaits the winner's settlement and then
10
+ * acks WITHOUT executing (a `skipped` result). On Vercel Fluid compute it also
11
+ * absorbs same-instance races between an owner redelivery and a backstop.
12
+ *
13
+ * A winner failure is not propagated to the loser: the winner's own queue
14
+ * message redelivers and drives the retry, so exactly one message keeps
15
+ * owning the outcome. If the loser's own invocation hits its deadline while
16
+ * waiting, its message redelivers and re-checks, degrading gracefully to
17
+ * polling.
18
+ *
19
+ * The exception is a winner that itself came back `skipped`. That outcome
20
+ * means it never ran the body: its claim lost to a concurrent writer, or the
21
+ * step had already settled. It owned nothing, so nothing on its side will
22
+ * drive the step, and the loser may be the very execution the claim lost to
23
+ * (say, the queued step message of the replay that created the step, while a
24
+ * racing replay of the same run tried to claim it inline). Skipping with it
25
+ * would leave the step created and never run. The loser runs its own attempt
26
+ * instead, which its claim gates like any other.
27
+ *
28
+ * Cross-instance duplicates are what the ownership lease bounds on platforms
29
+ * where it is a death proof, and the documented residual risk on
30
+ * multi-instance self-hosted worlds (mitigate by raising
31
+ * `WORKFLOW_INLINE_OWNERSHIP_LEASE_SECONDS`).
32
+ */
33
+ export declare function runStepSingleFlight(runId: string, correlationId: string, execute: () => Promise<StepExecutionResult>, logLevel?: 'debug' | 'warn'): Promise<StepExecutionResult>;
34
+ //# sourceMappingURL=step-single-flight.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"step-single-flight.d.ts","sourceRoot":"","sources":["../../../src/runtime/spec8/step-single-flight.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAE9D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,MAAM,EACb,aAAa,EAAE,MAAM,EACrB,OAAO,EAAE,MAAM,OAAO,CAAC,mBAAmB,CAAC,EAC3C,QAAQ,GAAE,OAAO,GAAG,MAAe,GAClC,OAAO,CAAC,mBAAmB,CAAC,CAS9B"}
@@ -0,0 +1,36 @@
1
+ import { runSingleFlight } from '../step-single-flight.js';
2
+ /**
3
+ * Single-flight for a step body. This is a required companion to inline step
4
+ * ownership (see `isInlineOwnershipEnabled` in `./constants.ts`): the
5
+ * ownership lease is a *death proof* only on platforms with a bounded
6
+ * invocation lifetime. On worlds without an invocation kill bound
7
+ * (world-local's single process, self-hosted deployments) a delayed backstop
8
+ * can fire while the owning execution is still mid-body, in the same process.
9
+ * This absorbs that race: the loser awaits the winner's settlement and then
10
+ * acks WITHOUT executing (a `skipped` result). On Vercel Fluid compute it also
11
+ * absorbs same-instance races between an owner redelivery and a backstop.
12
+ *
13
+ * A winner failure is not propagated to the loser: the winner's own queue
14
+ * message redelivers and drives the retry, so exactly one message keeps
15
+ * owning the outcome. If the loser's own invocation hits its deadline while
16
+ * waiting, its message redelivers and re-checks, degrading gracefully to
17
+ * polling.
18
+ *
19
+ * The exception is a winner that itself came back `skipped`. That outcome
20
+ * means it never ran the body: its claim lost to a concurrent writer, or the
21
+ * step had already settled. It owned nothing, so nothing on its side will
22
+ * drive the step, and the loser may be the very execution the claim lost to
23
+ * (say, the queued step message of the replay that created the step, while a
24
+ * racing replay of the same run tried to claim it inline). Skipping with it
25
+ * would leave the step created and never run. The loser runs its own attempt
26
+ * instead, which its claim gates like any other.
27
+ *
28
+ * Cross-instance duplicates are what the ownership lease bounds on platforms
29
+ * where it is a death proof, and the documented residual risk on
30
+ * multi-instance self-hosted worlds (mitigate by raising
31
+ * `WORKFLOW_INLINE_OWNERSHIP_LEASE_SECONDS`).
32
+ */
33
+ export function runStepSingleFlight(runId, correlationId, execute, logLevel = 'warn') {
34
+ return runSingleFlight(runId, correlationId, execute, () => ({ type: 'skipped' }), logLevel, (winner) => winner.type === 'skipped');
35
+ }
36
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3RlcC1zaW5nbGUtZmxpZ2h0LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL3J1bnRpbWUvc3BlYzgvc3RlcC1zaW5nbGUtZmxpZ2h0LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxlQUFlLEVBQUUsTUFBTSwwQkFBMEIsQ0FBQztBQUczRDs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7O0dBOEJHO0FBQ0gsTUFBTSxVQUFVLG1CQUFtQixDQUNqQyxLQUFhLEVBQ2IsYUFBcUIsRUFDckIsT0FBMkMsRUFDM0MsV0FBNkIsTUFBTTtJQUVuQyxPQUFPLGVBQWUsQ0FDcEIsS0FBSyxFQUNMLGFBQWEsRUFDYixPQUFPLEVBQ1AsR0FBRyxFQUFFLENBQUMsQ0FBQyxFQUFFLElBQUksRUFBRSxTQUFTLEVBQUUsQ0FBQyxFQUMzQixRQUFRLEVBQ1IsQ0FBQyxNQUFNLEVBQUUsRUFBRSxDQUFDLE1BQU0sQ0FBQyxJQUFJLEtBQUssU0FBUyxDQUN0QyxDQUFDO0FBQ0osQ0FBQyIsInNvdXJjZXNDb250ZW50IjpbImltcG9ydCB7IHJ1blNpbmdsZUZsaWdodCB9IGZyb20gJy4uL3N0ZXAtc2luZ2xlLWZsaWdodC5qcyc7XG5pbXBvcnQgdHlwZSB7IFN0ZXBFeGVjdXRpb25SZXN1bHQgfSBmcm9tICcuL3N0ZXAtZXhlY3V0b3IuanMnO1xuXG4vKipcbiAqIFNpbmdsZS1mbGlnaHQgZm9yIGEgc3RlcCBib2R5LiBUaGlzIGlzIGEgcmVxdWlyZWQgY29tcG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oaXAgbGVhc2UgYm91bmRzIG9uIHBsYXRmb3Jtc1xuICogd2hlcmUgaXQgaXMgYSBkZWF0aCBwcm9vZiwgYW5kIHRoZSBkb2N1bWVudGVkIHJlc2lkdWFsIHJpc2sgb25cbiAqIG11bHRpLWluc3RhbmNlIHNlbGYtaG9zdGVkIHdvcmxkcyAobWl0aWdhdGUgYnkgcmFpc2luZ1xuICogYFdPUktGTE9XX0lOTElORV9PV05FUlNISVBfTEVBU0VfU0VDT05EU2ApLlxuICovXG5leHBvcnQgZnVuY3Rpb24gcnVuU3RlcFNpbmdsZUZsaWdodChcbiAgcnVuSWQ6IHN0cmluZyxcbiAgY29ycmVsYXRpb25JZDogc3RyaW5nLFxuICBleGVjdXRlOiAoKSA9PiBQcm9taXNlPFN0ZXBFeGVjdXRpb25SZXN1bHQ+LFxuICBsb2dMZXZlbDogJ2RlYnVnJyB8ICd3YXJuJyA9ICd3YXJuJ1xuKTogUHJvbWlzZTxTdGVwRXhlY3V0aW9uUmVzdWx0PiB7XG4gIHJldHVybiBydW5TaW5nbGVGbGlnaHQoXG4gICAgcnVuSWQsXG4gICAgY29ycmVsYXRpb25JZCxcbiAgICBleGVjdXRlLFxuICAgICgpID0+ICh7IHR5cGU6ICdza2lwcGVkJyB9KSxcbiAgICBsb2dMZXZlbCxcbiAgICAod2lubmVyKSA9PiB3aW5uZXIudHlwZSA9PT0gJ3NraXBwZWQnXG4gICk7XG59XG4iXX0=
@@ -1,9 +1,10 @@
1
1
  import type { Span } from '@opentelemetry/api';
2
2
  import { type SerializedData, type TraceCarrier, type ValidQueueName, type WorkflowRun, type World } from '@workflow/world';
3
- import type { StepInvocationQueueItem, WorkflowSuspension } from '../global.js';
4
- import { type GuestCodeExecution } from '../serialization/hardened.js';
5
- import { type LoadedEventLog } from './helpers.js';
6
- import { ReplayRecoveryReporter } from './replay-recovery-reporter.js';
3
+ import type { StepInvocationQueueItem, WorkflowSuspension } from '../../global.js';
4
+ import type { PendingQueueDrain } from '../../workflow.js';
5
+ import type { SuspensionSerializationBlocker } from '../delivery.js';
6
+ import { type LoadedEventLog } from '../helpers.js';
7
+ import { ReplayRecoveryReporter } from '../replay-recovery-reporter.js';
7
8
  import type { PreclaimedInlineStart } from './step-executor.js';
8
9
  export interface SuspensionHandlerParams {
9
10
  suspension: WorkflowSuspension;
@@ -12,17 +13,20 @@ export interface SuspensionHandlerParams {
12
13
  span?: Span;
13
14
  requestId?: string;
14
15
  /**
15
- * The runtime's loaded event log. Event creations normally name the position
16
- * they were derived from, so a backend that has recorded
16
+ * The workflow is completing or failing. Its terminal event cleans up hooks,
17
+ * so only dispose hooks needed to release a token early or for a later
18
+ * registration.
19
+ */
20
+ terminalDrain?: boolean;
21
+ /**
22
+ * The runtime's loaded event log. Every event creation this suspension makes
23
+ * names the position it was derived from, so a backend that has recorded
17
24
  * events the replay did not see can report them back on the write, or, if
18
25
  * it would rather refuse than report, reject it with a 412. A rejection is
19
26
  * not retried here: the event's correlation id was minted by *this* replay's
20
27
  * seeded sequence, so re-committing it against a corrected log would persist
21
28
  * an event no correct replay produces. The caller restarts the replay
22
29
  * instead.
23
- * Independent concurrent hook registrations defer advisory catch-up until
24
- * all of their existing single-event requests settle; a gap in their returned
25
- * committed positions retains the caller's normal reload path.
26
30
  *
27
31
  * Extended in place by what those writes report back — the events on slots
28
32
  * they skipped over, and (on the hook create) the inline delta since its
@@ -93,6 +97,15 @@ export interface SuspensionHandlerParams {
93
97
  * suspension. Omitted, every suspension republishes on its own.
94
98
  */
95
99
  forceClaimVictimWakes?: Set<string>;
100
+ /**
101
+ * Steps this invocation is already executing inline from an earlier pass
102
+ * of the same delivery (see `isInlineEarlyAdvanceEnabled`). They are left
103
+ * out entirely: nothing is created, deferred, or reported in
104
+ * `pendingSteps` for them, since their own executions write their events.
105
+ * They still occupy inline slots, so fewer new steps are deferred for
106
+ * inline execution while they run.
107
+ */
108
+ inFlightStepCorrelationIds?: ReadonlySet<string>;
96
109
  }
97
110
  /**
98
111
  * Result of handling a suspension. Returns pending step items so the caller
@@ -131,6 +144,13 @@ export interface SuspensionHandlerResult {
131
144
  * was not provided or no step was eligible.
132
145
  */
133
146
  queuedStepCorrelationIds: Set<string>;
147
+ /**
148
+ * New steps this suspension did not defer for inline execution only
149
+ * because steps from `inFlightStepCorrelationIds` held inline slots. They
150
+ * are created and queued like any step past the inline limit. Zero
151
+ * without in-flight steps.
152
+ */
153
+ inlineSlotsHeldBack: number;
134
154
  /**
135
155
  * How many events this phase's writes reported back as occupying slots they
136
156
  * skipped over, already merged into the caller's `eventLog.events`. Nonzero
@@ -144,12 +164,16 @@ export interface SuspensionHandlerResult {
144
164
  * the step on the fly), saving one world round-trip per inline step. Up to
145
165
  * `getMaxInlineSteps()` steps are deferred; the caller runs them inline in
146
166
  * parallel and queues the rest. Empty when no step was deferred (nothing
147
- * pending, or a `hook.getConflict()` awaiter is present so nothing is
148
- * executed inline). The caller passes each `dehydratedInput` straight to
167
+ * pending). The caller passes each `dehydratedInput` straight to
149
168
  * `executeStep`, which sends it as the `step_started` payload. The atomic
150
169
  * create-claim inside each `step_started` is the exactly-one-owner gate that
151
170
  * the standalone `step_created` provided before: the loser of the race gets
152
171
  * `EntityConflictError` → `skipped` and does not run the body.
172
+ *
173
+ * When {@link hasAwaitedHookCreation} is also set, these steps are deferred
174
+ * but HELD: the caller advances the workflow over the `hook_created` that
175
+ * settles the awaiter first, and runs them on the pass after it. Nothing was
176
+ * written for them, so holding costs nothing and dangles nothing.
153
177
  */
154
178
  lazyInlineSteps: Array<{
155
179
  correlationId: string;
@@ -167,8 +191,9 @@ export interface SuspensionHandlerResult {
167
191
  * `owned: false` lost the pair's atomic create-claim to a concurrent
168
192
  * writer, and executeStep returns `skipped` without running the body,
169
193
  * the same outcome as losing the lazy claim. Empty whenever the fold did
170
- * not engage (batching off, no `ownerMessageId`, or the lone-inline case,
171
- * which keeps the optimistic lazy path and its claim/body overlap).
194
+ * not engage (batching off, no `ownerMessageId`, a `hook.getConflict()`
195
+ * awaiter whose continuation may hold the bodies back, or the lone-inline
196
+ * case, which keeps the optimistic lazy path and its claim/body overlap).
172
197
  *
173
198
  * Crash window: the pair commits before the caller runs the body, so a
174
199
  * crash between them leaves a started step stamped with this message's
@@ -217,7 +242,11 @@ export interface SuspensionHandlerResult {
217
242
  * started concurrently with the hook is not held back by its conflict.
218
243
  */
219
244
  hasHookConflict: boolean;
220
- /** Whether a `hook.getConflict()` awaiter needs the workflow to continue immediately */
245
+ /**
246
+ * Whether a `hook.getConflict()` awaiter needs the workflow to continue
247
+ * immediately. Any {@link lazyInlineSteps} this suspension deferred are
248
+ * HELD for that continuation rather than run before it; see their docs.
249
+ */
221
250
  hasAwaitedHookCreation: boolean;
222
251
  /**
223
252
  * Correlation ids of the hooks this suspension committed a `hook_created`
@@ -251,10 +280,12 @@ export interface SuspensionHandlerResult {
251
280
  * committed, so a caller that continues in this process can replay — or
252
281
  * resume a retained VM — straight off it with no read.
253
282
  *
254
- * True when a lone hook create returns a complete inline delta, or when
255
- * concurrent hook responses prove a complete consecutive suffix. In either
256
- * case every write in this suspension must be accounted for. Missing events,
257
- * intervening writers, or other suspension writes retain the reload path.
283
+ * True only when the hook create's inline delta came back complete and was
284
+ * folded in (see `hookDeltaCursor` below), and nothing else in this
285
+ * suspension wrote an event. False whenever a read is needed first: no
286
+ * delta was asked for or returned, it was truncated, or a step / wait /
287
+ * attribute / abort write (single or batched) also committed and may not be
288
+ * in it.
258
289
  *
259
290
  * Indifferent to which event the create committed: the delta is the slice
260
291
  * of the log after the caller's cursor either way, so it carries a
@@ -285,10 +316,6 @@ export interface SuspensionHandlerResult {
285
316
  /** Bounded sample used only for retention diagnostics. */
286
317
  serializationBlockers: SuspensionSerializationBlocker[];
287
318
  }
288
- export interface SuspensionSerializationBlocker extends GuestCodeExecution {
289
- source: 'step_input' | 'hook_metadata' | 'hook_abort';
290
- correlationId: string;
291
- }
292
319
  /**
293
320
  * Handles a workflow suspension by processing all pending operations (hooks, steps, waits).
294
321
  * Creates events for all operations but does NOT queue step messages; returns the pending
@@ -302,7 +329,24 @@ export interface SuspensionSerializationBlocker extends GuestCodeExecution {
302
329
  * started in the same suspension as a hook can therefore run before that hook
303
330
  * is registered; a workflow that needs the hook registered first (say, a step
304
331
  * that hands the token to something that resumes it at once) awaits
305
- * `hook.getConflict()` before calling the step.
332
+ * `hook.getConflict()` before calling the step. That awaiter also orders the
333
+ * steps this suspension DEFERRED (`lazyInlineSteps`) after the registration,
334
+ * because the caller continues the workflow over the `hook_created` before it
335
+ * runs them — the ordering costs a queue hop only for the steps that overflow
336
+ * the inline cap and were therefore created eagerly here.
337
+ */
338
+ export declare function handleSuspension({ suspension, world, run, span, requestId, eventLog, terminalDrain, runReadyBarrier, replayRecoveryReporter, stepDispatch, ownerMessageId, allowDeferredBatchWork, forceClaimVictimWakes, inFlightStepCorrelationIds, }: SuspensionHandlerParams): Promise<SuspensionHandlerResult>;
339
+ /**
340
+ * The end-of-run drain of the spec 8 orchestrator (see `PendingQueueDrain`):
341
+ * the queued items are written like any suspension's. In turbo the writes
342
+ * wait on `runReadyBarrier`, the backgrounded `run_started`, so they never
343
+ * reach the World before the run exists; a rejected barrier only orders them
344
+ * (the write itself surfaces a run that does not exist).
345
+ */
346
+ export declare function pendingQueueDrain(world: World, runReadyBarrier?: Promise<unknown>,
347
+ /**
348
+ * Steps the caller is still executing inline. Read live, and left out of
349
+ * the drain: their own executions write their events.
306
350
  */
307
- export declare function handleSuspension({ suspension, world, run, span, requestId, eventLog, runReadyBarrier, replayRecoveryReporter, stepDispatch, ownerMessageId, allowDeferredBatchWork, forceClaimVictimWakes, }: SuspensionHandlerParams): Promise<SuspensionHandlerResult>;
351
+ inFlightStepCorrelationIds?: ReadonlySet<string>): PendingQueueDrain;
308
352
  //# sourceMappingURL=suspension-handler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"suspension-handler.d.ts","sourceRoot":"","sources":["../../../src/runtime/spec8/suspension-handler.ts"],"names":[],"mappings":"AAAA,OAAO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