@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
@@ -0,0 +1,270 @@
1
+ /**
2
+ * One orchestrator delivery, as both orchestrators see it: what the shared
3
+ * entrypoint (`../runtime.ts`) hands to the orchestrator for the run's spec
4
+ * version, and the helpers both use.
5
+ *
6
+ * - Spec 8 and below (`./spec8/`): several orchestrator invocations of a run
7
+ * may write at once; steps keep entities and the World's precondition guard
8
+ * keeps their writes consistent.
9
+ * - Spec 9 (`./spec9/`): one writer per run, enforced by the World's in-band
10
+ * fence; steps are folded from the log.
11
+ *
12
+ * A run keeps the orchestrator of the spec version it was created with.
13
+ */
14
+ import type { Span } from '@opentelemetry/api';
15
+ import { type RunErrorCode } from '@workflow/errors';
16
+ import type { Queue } from '@workflow/world';
17
+ import { type CreateEventRequest, type Event, type resolveQueueNamespace, type WorkflowInvokePayload, type WorkflowRun, type World } from '@workflow/world';
18
+ import type { WorkflowSuspension } from '../global.js';
19
+ import { type Logger } from '../logger.js';
20
+ import type { GuestCodeExecution } from '../serialization/hardened.js';
21
+ import { type PayloadKey } from '../serialization.js';
22
+ import { type DynamicWorkflowMetadata } from './dynamic-workflow.js';
23
+ import type { RunInputActivity } from './invocations.js';
24
+ import type { ReplayBudget } from './replay-budget.js';
25
+ import type { ResumeTtrTracking } from './resume-latency.js';
26
+ type QueueHandler = Parameters<Queue['createQueueHandler']>[1];
27
+ /** The queue metadata of one delivery. */
28
+ export type DeliveryMetadata = Parameters<QueueHandler>[1];
29
+ /**
30
+ * What a delivery hands back to the queue: a redelivery delay (on a spec 9
31
+ * run, `0` is a handoff to the next delivery; see `Queue.createQueueHandler`),
32
+ * or nothing to ack.
33
+ */
34
+ export type DeliveryResult = {
35
+ timeoutSeconds: number;
36
+ } | undefined;
37
+ /** One orchestrator delivery, set up by the shared entrypoint. */
38
+ export interface WorkflowDelivery {
39
+ /** The parsed queue message. */
40
+ readonly message: WorkflowInvokePayload;
41
+ readonly metadata: DeliveryMetadata;
42
+ /**
43
+ * The run's input activity for this handler, on Worlds that deliver
44
+ * invocations (`capabilities.invoke`); see `withRunInputs`.
45
+ */
46
+ readonly activity: RunInputActivity | undefined;
47
+ readonly workflowCode: string;
48
+ readonly namespace: ReturnType<typeof resolveQueueNamespace>;
49
+ readonly world: World;
50
+ /** The delivery's `workflow.execute` span. */
51
+ readonly span: Span | undefined;
52
+ readonly runLogger: Logger;
53
+ readonly workflowName: string;
54
+ readonly requestId: string | undefined;
55
+ /** Hook-resume TTR tracking, consumed by the first durable step after it. */
56
+ readonly resumeTracking: ResumeTtrTracking | undefined;
57
+ /** Trace carrier to attach to the messages this delivery enqueues. */
58
+ readonly nextTraceCarrier: () => Promise<Record<string, string>>;
59
+ readonly replayBudget: ReplayBudget;
60
+ /**
61
+ * The run (`resolveData: 'none'`), when routing the delivery had to read
62
+ * it; a read that wants the same view uses it instead of reading again.
63
+ */
64
+ readonly prefetchedRun: WorkflowRun | undefined;
65
+ /**
66
+ * The spec version of the run, as routing resolved it (the message's
67
+ * stamp or hint, or the run itself; see `resolveRunSpec`). Every
68
+ * orchestrator message the delivery sends carries it, so a World that
69
+ * reads the run's spec off the payload never sees an unstamped one.
70
+ */
71
+ readonly runSpecVersion: number;
72
+ }
73
+ /**
74
+ * Whether this delivery reached the orchestrator of another spec than its
75
+ * run's, by the run row the orchestrator loaded, and if so hands it on.
76
+ *
77
+ * Routing trusts a message's `runSpecVersion` hint (see `resolveRunSpec`),
78
+ * so a wrong hint can deliver a run's message to the other orchestrator. The
79
+ * row is authoritative: this sends the message again with the run's version
80
+ * as its hint, which the next delivery routes to the right orchestrator. The
81
+ * caller acknowledges its message without writing anything else.
82
+ *
83
+ * A first delivery (`runInput`) is never handed on: its version is the one
84
+ * `start()` stamped the run with. Nor is a delivery whose run row records no
85
+ * version.
86
+ */
87
+ export declare function handOffToRunOrchestrator(params: {
88
+ world: World;
89
+ message: WorkflowInvokePayload;
90
+ metadata: DeliveryMetadata;
91
+ run: WorkflowRun;
92
+ /** Whether the delivering orchestrator is the single orchestrator. */
93
+ singleOrchestrator: boolean;
94
+ }): Promise<boolean>;
95
+ /** What the shared entrypoint needs from the orchestrator of a run's spec. */
96
+ export interface Orchestrator {
97
+ /** Whether a delivery of `message` counts toward the run's max queue deliveries. */
98
+ countsTowardMaxDeliveries(message: WorkflowInvokePayload): boolean;
99
+ /**
100
+ * Writes the `run_failed` that ends a run past its max queue deliveries.
101
+ * Resolves `'superseded'` when the in-band fence refused the write, which
102
+ * does not prove another orchestrator is running; the caller has the queue
103
+ * redeliver the message to retry it. Otherwise resolves the run the write
104
+ * returned (when the World returned one), or throws what the World threw.
105
+ */
106
+ writeMaxDeliveriesFailure(world: World, runId: string, eventData: RunFailedEventRequest['eventData'], requestId: string | undefined): Promise<{
107
+ run: WorkflowRun | undefined;
108
+ } | 'superseded'>;
109
+ /** Runs one delivery of the run's queue message. */
110
+ runDelivery(delivery: WorkflowDelivery): Promise<DeliveryResult>;
111
+ }
112
+ /**
113
+ * A workflow-code execution observed while a suspension serialized its
114
+ * writes, which keeps the retained VM from being reused (see
115
+ * `getRetentionDecision`).
116
+ */
117
+ export interface SuspensionSerializationBlocker extends GuestCodeExecution {
118
+ source: 'step_input' | 'hook_metadata' | 'hook_abort';
119
+ correlationId: string;
120
+ }
121
+ /** The max-deliveries `run_failed` request. */
122
+ export type RunFailedEventRequest = Extract<CreateEventRequest, {
123
+ eventType: 'run_failed';
124
+ }>;
125
+ /** The workflow code a delivery replays, and the marker when it is dynamic. */
126
+ export interface ResolvedWorkflowCode {
127
+ code: string;
128
+ dynamicWorkflow?: DynamicWorkflowMetadata;
129
+ }
130
+ export type RetentionDecision = {
131
+ retain: true;
132
+ } | {
133
+ retain: false;
134
+ reason: 'disabled' | 'serialization_executed_workflow_code' | 'no_replay_driver';
135
+ };
136
+ /**
137
+ * The complete retained-VM policy for a suspension boundary.
138
+ *
139
+ * Every suspension producer uses the suspension-generation guard when
140
+ * signaling. Otherwise a signal scheduled at boundary N could suspend the VM
141
+ * after it has already resumed into boundary N+1. The strictly ordered event
142
+ * log determines which branch resolution wins. A step or attribute write is
143
+ * required to drive the next inline iteration; hook- or wait-only suspensions
144
+ * park normally.
145
+ *
146
+ * Retaining across an open hook or wait also permits an out-of-band cold replay
147
+ * to race this invocation. That is safe only because each loaded log is a
148
+ * monotone, hole-free prefix; replaying a longer prefix preserves all earlier
149
+ * correlation-ID draws; and `step_started` atomically chooses one owner. The
150
+ * generation guard keeps losing same-boundary suspension signals stale, while
151
+ * a stale-snapshot/412 restart discards the retained session and replays from
152
+ * the authoritative log. A World that exposes a non-prefix view would violate
153
+ * this policy's precondition and could bind one ordinal to two logical branches
154
+ * before the step-ownership claim has a chance to arbitrate them.
155
+ *
156
+ * A hook-write continuation is the one boundary retained without a step or
157
+ * attribute driver. The suspension committed the event a hook's own awaiter is
158
+ * parked on — the `hook_created` a `hook.getConflict()` waits for, or the
159
+ * `hook_conflict` a create whose token was already claimed committed instead —
160
+ * and the caller advances the workflow over that event by resuming the session
161
+ * in this process rather than re-invoking (see `continueOverHookWrite` in the
162
+ * replay loop), so the runtime itself drives the next iteration. One arm for
163
+ * both outcomes because it is one boundary: same write, same event slot, same
164
+ * continuation. Steps in the same suspension ride along deferred rather than
165
+ * queued: an awaiter holds `lazyInlineSteps` back for the pass the
166
+ * continuation drives, and the conflict branch returns before any inline
167
+ * execution, so a step body is never ordered ahead of a continuation this
168
+ * invocation is still going to take. (A continuation it has already taken and
169
+ * been refused for — the repeat guard — does let the batch run first; there is
170
+ * nothing left for the ordering to protect by then.) The hook this suspension
171
+ * just created is an open hook by
172
+ * definition, and is no more a hazard than any other open hook here: a
173
+ * `hook_received` landing out of band is absent from the log the resume reads
174
+ * exactly as it is absent from a fetch that returned a moment before it — a
175
+ * prefix, never a hole, corrected on the next write.
176
+ *
177
+ * Quiescence assumes workflow code stays inside the sandbox's determinism
178
+ * contract. Escaping to the host realm (for example, recovering a host
179
+ * `Function` constructor to schedule real timers) already makes ordinary cold
180
+ * replay nondeterministic and is not defended here.
181
+ *
182
+ */
183
+ export declare function getRetentionDecision({ suspension, serializationBlockerCount, hookContinuation, invocationContinuation, }: {
184
+ suspension: WorkflowSuspension;
185
+ serializationBlockerCount: number;
186
+ /**
187
+ * Whether this suspension committed the event a hook's own awaiter is
188
+ * waiting on and the caller will continue over it in-process, making the
189
+ * runtime the replay driver for a boundary that has no step or attribute
190
+ * write of its own. See the policy above.
191
+ */
192
+ hookContinuation?: boolean;
193
+ invocationContinuation?: boolean;
194
+ }): RetentionDecision;
195
+ export declare const SERIALIZATION_BLOCKER_LOG_DETAIL_LIMIT = 160;
196
+ /** Keep retention diagnostics useful without emitting unbounded guest data. */
197
+ export declare function serializationBlockerLogMetadata(blockers: SuspensionSerializationBlocker[], count: number): {
198
+ serializationBlockerCount: number;
199
+ serializationBlockers: {
200
+ source: "step_input" | "hook_metadata" | "hook_abort";
201
+ correlationId: string;
202
+ kind: "getter" | "proxy" | "method";
203
+ detail: string | undefined;
204
+ }[];
205
+ serializationBlockersTruncated: boolean;
206
+ };
207
+ export declare function clampMaxEvents(serverValue: number | undefined): number | undefined;
208
+ export declare function findRecordedTerminalRunEvent(events: Event[], runId: string): Event | undefined;
209
+ export declare function hasRecordedTerminalRunEvent(events: Event[], runId: string): boolean;
210
+ /**
211
+ * Maximum inline-execution duration for a single handler invocation.
212
+ *
213
+ * Order of precedence:
214
+ * 1. `WORKFLOW_V2_TIMEOUT_MS` env var
215
+ * 2. Tiered budget derived from `world.getRuntimeDeadline()`
216
+ * 3. Default of 2 minutes
217
+ */
218
+ export declare function getMaxInlineDurationMs(world: World, invocationStartTime: number): Promise<number>;
219
+ export declare function getWorkflowSetupErrorCode(err: unknown): RunErrorCode | null;
220
+ export declare function recordFatalRunError({ world, workflowRun, runId, workflowName, requestId, err, errorCode, logMessage, }: {
221
+ world: World;
222
+ workflowRun: WorkflowRun | undefined;
223
+ runId: string;
224
+ workflowName: string;
225
+ requestId: string | undefined;
226
+ err: unknown;
227
+ errorCode: RunErrorCode;
228
+ logMessage: string;
229
+ }): Promise<void>;
230
+ /**
231
+ * Pick the workflow code this run replays.
232
+ *
233
+ * For a static run this is the deployment's bundle, returned unchanged after
234
+ * one plaintext property read. The dynamic branch exists for runs started from
235
+ * source: their workflow function was never in the bundle, so the code came
236
+ * with the run, and replaying it means evaluating that exact code rather than
237
+ * whatever the deployment now contains.
238
+ *
239
+ * Stored code is only executed when all of these hold, and each failure is a
240
+ * `WorkflowRuntimeError` so the caller fails the run instead of redelivering a
241
+ * message whose verdict cannot change:
242
+ *
243
+ * - this deployment has opted in to dynamic workflows;
244
+ * - the run's `workflowName` is the id its `dynamicWorkflow` marker derives
245
+ * (a marker on a static workflow's run does not redirect it to stored code);
246
+ * - the code exists and hydrates, which requires the `encr` envelope whenever
247
+ * the run has key material or was started with encryption.
248
+ *
249
+ * Two sources for the code, in order of what the invocation already holds:
250
+ *
251
+ * 1. On the run snapshot. The normal case: `run_created` and the queue
252
+ * message both carry the bytes, so a read is already unnecessary by the
253
+ * time replay begins.
254
+ * 2. Read back from the run. Needed when the definition was too large to
255
+ * send inline and lives behind a ref, or the snapshot was read with
256
+ * `resolveData: 'none'`, which omits the code. The run has to exist first,
257
+ * hence the barrier.
258
+ *
259
+ * World and key-lookup errors propagate unchanged, so transient failures are
260
+ * still redelivered.
261
+ *
262
+ * @param getEncryptionKey - Resolved only on the dynamic branch. The key is
263
+ * lazy for a reason: some deliveries never need it, and forcing it here
264
+ * would put a key fetch on every static run's critical path.
265
+ * @param awaitRunReady - Orders the fallback read after the write that
266
+ * creates the run; a no-op once the run is durable.
267
+ */
268
+ export declare function resolveWorkflowCodeForRun(staticWorkflowCode: string, workflowRun: WorkflowRun, getEncryptionKey: () => Promise<PayloadKey | undefined>, world: World, awaitRunReady: () => Promise<void>): Promise<ResolvedWorkflowCode>;
269
+ export {};
270
+ //# sourceMappingURL=delivery.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"del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