@workflow/core 5.0.0-beta.4 → 5.0.0-beta.5

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 (161) hide show
  1. package/dist/capture-stack.d.ts +16 -0
  2. package/dist/capture-stack.d.ts.map +1 -0
  3. package/dist/capture-stack.js +21 -0
  4. package/dist/classify-error.d.ts +7 -0
  5. package/dist/classify-error.d.ts.map +1 -1
  6. package/dist/classify-error.js +25 -4
  7. package/dist/context-errors.d.ts +27 -0
  8. package/dist/context-errors.d.ts.map +1 -0
  9. package/dist/context-errors.js +101 -0
  10. package/dist/context-violation-error.d.ts +97 -0
  11. package/dist/context-violation-error.d.ts.map +1 -0
  12. package/dist/context-violation-error.js +147 -0
  13. package/dist/create-hook.d.ts.map +1 -1
  14. package/dist/create-hook.js +4 -3
  15. package/dist/define-hook.d.ts.map +1 -1
  16. package/dist/define-hook.js +20 -5
  17. package/dist/describe-error.d.ts +70 -0
  18. package/dist/describe-error.d.ts.map +1 -0
  19. package/dist/describe-error.js +119 -0
  20. package/dist/encryption.d.ts.map +1 -1
  21. package/dist/encryption.js +4 -20
  22. package/dist/events-consumer.d.ts +7 -0
  23. package/dist/events-consumer.d.ts.map +1 -1
  24. package/dist/events-consumer.js +9 -2
  25. package/dist/flushable-stream.d.ts +10 -10
  26. package/dist/flushable-stream.d.ts.map +1 -1
  27. package/dist/flushable-stream.js +13 -12
  28. package/dist/global.d.ts +4 -0
  29. package/dist/global.d.ts.map +1 -1
  30. package/dist/global.js +8 -2
  31. package/dist/log-format.d.ts +25 -0
  32. package/dist/log-format.d.ts.map +1 -0
  33. package/dist/log-format.js +250 -0
  34. package/dist/logger.d.ts +28 -30
  35. package/dist/logger.d.ts.map +1 -1
  36. package/dist/logger.js +77 -31
  37. package/dist/private.js +3 -3
  38. package/dist/runtime/get-port-lazy.d.ts +10 -0
  39. package/dist/runtime/get-port-lazy.d.ts.map +1 -0
  40. package/dist/runtime/get-port-lazy.js +30 -0
  41. package/dist/runtime/get-world-lazy.d.ts +32 -0
  42. package/dist/runtime/get-world-lazy.d.ts.map +1 -0
  43. package/dist/runtime/get-world-lazy.js +56 -0
  44. package/dist/runtime/helpers.d.ts +38 -5
  45. package/dist/runtime/helpers.d.ts.map +1 -1
  46. package/dist/runtime/helpers.js +67 -18
  47. package/dist/runtime/resume-hook.js +4 -4
  48. package/dist/runtime/run.d.ts.map +1 -1
  49. package/dist/runtime/run.js +31 -6
  50. package/dist/runtime/start.js +3 -3
  51. package/dist/runtime/step-executor.d.ts +40 -0
  52. package/dist/runtime/step-executor.d.ts.map +1 -0
  53. package/dist/runtime/step-executor.js +480 -0
  54. package/dist/runtime/step-handler.d.ts.map +1 -1
  55. package/dist/runtime/step-handler.js +209 -111
  56. package/dist/runtime/suspension-handler.d.ts +22 -4
  57. package/dist/runtime/suspension-handler.d.ts.map +1 -1
  58. package/dist/runtime/suspension-handler.js +86 -73
  59. package/dist/runtime/world-init.d.ts +75 -0
  60. package/dist/runtime/world-init.d.ts.map +1 -0
  61. package/dist/runtime/world-init.js +75 -0
  62. package/dist/runtime/world.d.ts.map +1 -1
  63. package/dist/runtime/world.js +47 -18
  64. package/dist/runtime.d.ts +8 -7
  65. package/dist/runtime.d.ts.map +1 -1
  66. package/dist/runtime.js +649 -292
  67. package/dist/schemas.d.ts +1 -1
  68. package/dist/schemas.d.ts.map +1 -1
  69. package/dist/schemas.js +1 -1
  70. package/dist/serialization/client.d.ts +17 -0
  71. package/dist/serialization/client.d.ts.map +1 -0
  72. package/dist/serialization/client.js +44 -0
  73. package/dist/serialization/codec-devalue.d.ts +14 -0
  74. package/dist/serialization/codec-devalue.d.ts.map +1 -0
  75. package/dist/serialization/codec-devalue.js +98 -0
  76. package/dist/serialization/codec.d.ts +90 -0
  77. package/dist/serialization/codec.d.ts.map +1 -0
  78. package/dist/serialization/codec.js +17 -0
  79. package/dist/serialization/encryption.d.ts +32 -0
  80. package/dist/serialization/encryption.d.ts.map +1 -0
  81. package/dist/serialization/encryption.js +51 -0
  82. package/dist/serialization/errors.d.ts +21 -0
  83. package/dist/serialization/errors.d.ts.map +1 -0
  84. package/dist/serialization/errors.js +41 -0
  85. package/dist/serialization/format.d.ts +60 -0
  86. package/dist/serialization/format.d.ts.map +1 -0
  87. package/dist/serialization/format.js +97 -0
  88. package/dist/serialization/index.d.ts +18 -0
  89. package/dist/serialization/index.d.ts.map +1 -0
  90. package/dist/serialization/index.js +20 -0
  91. package/dist/serialization/reducers/class.d.ts +11 -0
  92. package/dist/serialization/reducers/class.d.ts.map +1 -0
  93. package/dist/serialization/reducers/class.js +68 -0
  94. package/dist/serialization/reducers/common.d.ts +16 -0
  95. package/dist/serialization/reducers/common.d.ts.map +1 -0
  96. package/dist/serialization/reducers/common.js +362 -0
  97. package/dist/serialization/reducers/step-function.d.ts +35 -0
  98. package/dist/serialization/reducers/step-function.d.ts.map +1 -0
  99. package/dist/serialization/reducers/step-function.js +88 -0
  100. package/dist/serialization/step.d.ts +17 -0
  101. package/dist/serialization/step.d.ts.map +1 -0
  102. package/dist/serialization/step.js +44 -0
  103. package/dist/serialization/types.d.ts +201 -0
  104. package/dist/serialization/types.d.ts.map +1 -0
  105. package/dist/serialization/types.js +21 -0
  106. package/dist/serialization/workflow.d.ts +29 -0
  107. package/dist/serialization/workflow.d.ts.map +1 -0
  108. package/dist/serialization/workflow.js +54 -0
  109. package/dist/serialization-format.d.ts.map +1 -1
  110. package/dist/serialization-format.js +77 -3
  111. package/dist/serialization.d.ts +202 -226
  112. package/dist/serialization.d.ts.map +1 -1
  113. package/dist/serialization.js +773 -633
  114. package/dist/sleep.d.ts.map +1 -1
  115. package/dist/sleep.js +3 -2
  116. package/dist/step/get-closure-vars.d.ts.map +1 -1
  117. package/dist/step/get-closure-vars.js +3 -2
  118. package/dist/step/get-step-metadata.d.ts.map +1 -1
  119. package/dist/step/get-step-metadata.js +3 -2
  120. package/dist/step/get-workflow-metadata.d.ts.map +1 -1
  121. package/dist/step/get-workflow-metadata.js +3 -2
  122. package/dist/step/writable-stream.d.ts.map +1 -1
  123. package/dist/step/writable-stream.js +3 -2
  124. package/dist/step.d.ts.map +1 -1
  125. package/dist/step.js +83 -16
  126. package/dist/symbols.d.ts +4 -0
  127. package/dist/symbols.d.ts.map +1 -1
  128. package/dist/symbols.js +5 -1
  129. package/dist/telemetry/semantic-conventions.d.ts +2 -2
  130. package/dist/telemetry/semantic-conventions.js +1 -1
  131. package/dist/util.d.ts +18 -3
  132. package/dist/util.d.ts.map +1 -1
  133. package/dist/util.js +28 -5
  134. package/dist/version.d.ts +1 -1
  135. package/dist/version.js +2 -2
  136. package/dist/vm/index.d.ts.map +1 -1
  137. package/dist/vm/index.js +3 -2
  138. package/dist/workflow/abort-controller.d.ts +65 -0
  139. package/dist/workflow/abort-controller.d.ts.map +1 -0
  140. package/dist/workflow/abort-controller.js +245 -0
  141. package/dist/workflow/create-hook.d.ts.map +1 -1
  142. package/dist/workflow/create-hook.js +3 -2
  143. package/dist/workflow/define-hook.d.ts +1 -1
  144. package/dist/workflow/define-hook.d.ts.map +1 -1
  145. package/dist/workflow/define-hook.js +8 -4
  146. package/dist/workflow/get-workflow-metadata.d.ts.map +1 -1
  147. package/dist/workflow/get-workflow-metadata.js +14 -3
  148. package/dist/workflow/index.d.ts.map +1 -1
  149. package/dist/workflow/index.js +4 -3
  150. package/dist/workflow/world-init-stub.d.ts +15 -0
  151. package/dist/workflow/world-init-stub.d.ts.map +1 -0
  152. package/dist/workflow/world-init-stub.js +15 -0
  153. package/dist/workflow.d.ts.map +1 -1
  154. package/dist/workflow.js +71 -28
  155. package/docs/foundations/cancellation.mdx +460 -0
  156. package/docs/foundations/errors-and-retries.mdx +7 -3
  157. package/docs/foundations/meta.json +1 -0
  158. package/docs/foundations/serialization.mdx +77 -41
  159. package/docs/how-it-works/cancellation.mdx +287 -0
  160. package/docs/how-it-works/meta.json +2 -1
  161. package/package.json +15 -6
@@ -0,0 +1,287 @@
1
+ ---
2
+ title: How Cancellation Works
3
+ description: Learn how AbortController is made durable using hooks and streams under the hood.
4
+ type: conceptual
5
+ summary: Understand the hook and stream backing that makes AbortSignal work across workflow boundaries.
6
+ prerequisites:
7
+ - /docs/foundations/cancellation
8
+ - /docs/how-it-works/event-sourcing
9
+ related:
10
+ - /docs/foundations/hooks
11
+ - /docs/foundations/streaming
12
+ - /docs/foundations/serialization
13
+ ---
14
+
15
+ <Callout>
16
+ This guide explains how cancellation works internally. Understanding these details is helpful for debugging and advanced use cases, but is not required to use `AbortController` in workflows. For usage patterns, see the [Cancellation](/docs/foundations/cancellation) guide.
17
+ </Callout>
18
+
19
+ When you write `new AbortController()` in a workflow function, Workflow DevKit creates a durable controller backed by two existing primitives: a [hook](/docs/foundations/hooks) and a [stream](/docs/foundations/streaming). This page explains why both are needed and how they work together.
20
+
21
+ ## The Problem
22
+
23
+ `AbortController` and `AbortSignal` are inherently stateful — an abort happens once and is permanent. In a durable workflow, this state must:
24
+
25
+ 1. **Survive replay** — If `abort()` was called, `signal.aborted` must return `true` on every subsequent replay of the workflow.
26
+ 2. **Propagate in real-time** — A running step on a different compute instance must receive the abort immediately, not on the next replay.
27
+
28
+ No single primitive solves both. Hooks provide durable event log state but can't reach into a running step. Streams provide real-time cross-process communication but aren't part of the event log. The solution is to use both.
29
+
30
+ ## Dual Backing: Hook + Stream
31
+
32
+ Every `AbortController` in the workflow context is backed by:
33
+
34
+ ### Hook (Durable State)
35
+
36
+ When `new AbortController()` is called in a workflow, an internal hook is created — similar to calling `createHook()`. This hook is registered in the workflow's invocations queue and produces events in the [event log](/docs/how-it-works/event-sourcing):
37
+
38
+ - **On creation**: A `hook_created` event records that the controller exists
39
+ - **On abort**: The hook is resumed (producing a `hook_received` event), recording the abort permanently
40
+ - **On replay**: The event consumer processes the `hook_received` event and updates `signal.aborted` to `true` at the same point in the replay as the original abort
41
+
42
+ This gives the workflow deterministic access to the abort state — `controller.signal.aborted` always returns the correct value, even after cold starts.
43
+
44
+ ### Stream (Real-Time Propagation)
45
+
46
+ When `controller.signal` is serialized as a step argument, a stream name is included in the serialized form. Inside the step, the deserialized `AbortSignal` listens on this stream:
47
+
48
+ - **On abort**: A cancellation packet is written to the stream
49
+ - **In the step**: A background reader receives the packet and calls `abort()` on the local `AbortController`, firing the signal immediately
50
+
51
+ This gives steps real-time cancellation without waiting for the workflow to replay.
52
+
53
+ ### Why Both?
54
+
55
+ | Mechanism | Solves | Doesn't Solve |
56
+ |---|---|---|
57
+ | Hook only | Deterministic replay, event log consistency | Can't reach into a running step on another instance |
58
+ | Stream only | Real-time propagation to running steps | Not part of the event log, lost on replay |
59
+ | Hook + Stream | Both | — |
60
+
61
+ ## Lifecycle
62
+
63
+ ### 1. Controller Created in Workflow
64
+
65
+ ```
66
+ new AbortController()
67
+
68
+ ├─→ Internal hook created (registered in invocations queue)
69
+ └─→ Stream name generated (deterministic ULID)
70
+ ```
71
+
72
+ ### 2. Signal Passed to Step
73
+
74
+ ```
75
+ stepFunction(controller.signal)
76
+
77
+ ├─→ Signal serialized as { streamName, hookToken, aborted }
78
+ └─→ In the step: deserialized as real AbortSignal
79
+
80
+ └─→ Background reader listens on stream for abort packet
81
+ ```
82
+
83
+ ### 3. abort() Called in Workflow
84
+
85
+ ```
86
+ controller.abort()
87
+
88
+ ├─→ signal.aborted set to true (synchronous, local state)
89
+ ├─→ Hook marked for resumption in invocations queue
90
+ └─→ Workflow suspends (reaches next step/sleep/hook await)
91
+
92
+ ├─→ Suspension handler creates hook_received event
93
+ ├─→ Suspension handler writes cancellation packet to stream
94
+ │ │
95
+ │ └─→ Step receives packet → local signal fires → fetch cancelled
96
+ └─→ Workflow re-enqueued for replay
97
+ ```
98
+
99
+ ### 4. Workflow Replays After Abort
100
+
101
+ ```
102
+ Replay starts → events loaded
103
+
104
+ ├─→ new AbortController() → hook created → event consumer subscribes
105
+ ├─→ hook_created event consumed
106
+ ├─→ hook_received event consumed → signal.aborted re-asserted as true
107
+ └─→ Workflow code sees signal.aborted === true at the correct point in replay
108
+ ```
109
+
110
+ On replay, the events consumer re-applies the abort by calling `_setAborted` when it encounters the `hook_received` event in the log — at the same point in execution where the original `abort()` happened. This is what makes the abort deterministic across replays.
111
+
112
+ ## Where the Hook Is Created
113
+
114
+ The backing hook is set up whenever an `AbortController` or `AbortSignal` enters the workflow context:
115
+
116
+ **`new AbortController()` in a workflow function** — The workflow VM provides a durable `AbortController` implementation (similar to how it provides deterministic `Date` and serializable `Request`/`Response`). The hook is created in the constructor using the orchestrator context injected via VM globals.
117
+
118
+ **Returned from a step** — A step can create a plain `new AbortController()` and return it. The step-side serializer generates a stream name and hook token (using a random ULID) and includes them in the serialized payload. When the return value is deserialized into the workflow via `hydrateStepReturnValue`, the workflow reviver reads the token from the payload and sets up the hook with that token. Since the serialized payload is stored in the event log (as part of the `step_completed` event), the same token is used on every replay — no deterministic generation needed in the workflow.
119
+
120
+ **Passed as workflow input** — Conceptually the same as "returned from a step". The **external reducer** handles it at serialization time:
121
+
122
+ 1. Generates a stream name and hook token (random ULID)
123
+ 2. Attaches an `abort` event listener on the source signal: when the external code calls `controller.abort()`, the listener writes the cancellation packet to the stream
124
+ 3. Pushes the listener's async work into `ops` (awaited via `waitUntil`)
125
+ 4. Serializes the reference as `{ streamName, hookToken, aborted }`
126
+
127
+ The serialized payload (including the generated token) is stored in the event log as part of the workflow's input. When the workflow deserializes the input, the reviver reads the token from the payload and creates the hook — identical to the "returned from a step" case. On replay, the same token is read from the event log, so the hook matches the same events.
128
+
129
+ If the external code calls `abort()` while the process is still alive (within the `waitUntil` window), the stream packet arrives in the workflow, and the workflow can resume the hook to record it in the event log.
130
+
131
+ <Callout type="info">
132
+ Since the external `AbortController` is a plain JavaScript object (not the workflow VM's durable version), the stream write depends on the originating process still being alive. This is the same constraint that applies to passing a `ReadableStream` as a workflow argument — the stream pipe runs via `waitUntil` and requires the process to remain active until the data is written.
133
+ </Callout>
134
+
135
+ ## Serialization & Deserialization
136
+
137
+ ### Serialized Form
138
+
139
+ An `AbortController` or `AbortSignal` is serialized as:
140
+
141
+ {/* @skip-typecheck: type definition, not runnable code */}
142
+ ```typescript
143
+ {
144
+ streamName: string; // e.g., "abrt_01HWKZ..."
145
+ hookToken: string; // Generated at serialization time, used by workflow reviver to create the hook
146
+ aborted: boolean; // Current state at serialization time
147
+ reason?: unknown; // The abort reason, if any
148
+ }
149
+ ```
150
+
151
+ The `streamName` and `hookToken` are generated once at serialization time (in the step or external context) and stored in the event log as part of the serialized payload. On replay, the workflow reviver reads them from the payload — it never generates them itself. This is the same pattern used by `ReadableStream` and `WritableStream` serialization.
152
+
153
+ ### Reducers (Serialization)
154
+
155
+ **In step context** (`getStepReducers`): When a step returns an `AbortController`, the reducer captures the stream name. If `abort()` was called in the step, `aborted: true` is recorded.
156
+
157
+ **In workflow context** (`getWorkflowReducers`): The reducer captures the stream name and hook token. These are handles — no I/O happens during serialization in the workflow.
158
+
159
+ **In external context** (`getExternalReducers`): When an `AbortController` is passed as a workflow argument from outside, the reducer creates the backing stream and serializes the reference.
160
+
161
+ ### Revivers (Deserialization)
162
+
163
+ **Into step context** (`getStepRevivers`): Creates a real `AbortController`. If `aborted: true`, calls `abort()` immediately. Otherwise, pushes a stream reader into the step's `ops` array that listens for the cancellation packet and calls `abort()` when received.
164
+
165
+ **Into workflow context** (`getWorkflowRevivers`): Creates the durable AbortController with hook backing. Subscribes to the events consumer for the hook's correlation ID. If the event log contains a `hook_received` event, `signal.aborted` is `true`.
166
+
167
+ ### abort() in a Step
168
+
169
+ When `abort()` is called on a deserialized `AbortController` inside a step:
170
+
171
+ 1. The local signal is aborted synchronously (standard behavior)
172
+ 2. The stream write (cancellation packet) is pushed into `ctx.ops`
173
+ 3. The hook resume (`resumeHook`) is pushed into `ctx.ops`
174
+
175
+ The step's `ops` array is awaited via `waitUntil(Promise.all(ops))` after the step function returns — the same mechanism used by [`getWritable()`](/docs/api-reference/workflow/get-writable). This keeps `abort()` synchronous from the caller's perspective while ensuring the async work completes.
176
+
177
+ ### Abort Errors Are Wrapped in FatalError
178
+
179
+ When a step throws due to an abort — whether from `fetch` throwing `AbortError`, `signal.throwIfAborted()`, or any other abort-induced error — the step handler wraps the error in `FatalError` before recording it in the event log. This ensures:
180
+
181
+ - **No retries**: An abort is intentional cancellation, not a transient failure. Retrying would just abort again.
182
+ - **Immediate propagation**: The error bubbles up to the workflow as a `FatalError`, which the workflow can catch with `FatalError.is(err)`.
183
+
184
+ The wrapping happens at the step handler level (`runtime/step-handler.ts`), during error hydration. When the step's thrown error is an `AbortError` (checked via `err.name === 'AbortError'`), it is treated as fatal regardless of the step's `maxRetries` configuration.
185
+
186
+ ### abort() in the Workflow
187
+
188
+ When `abort()` is called in the workflow context:
189
+
190
+ 1. `signal.aborted` is updated to `true` immediately (so subsequent reads and serialization capture the correct state)
191
+ 2. The internal hook is marked for resumption in the invocations queue (same pattern as `hook.dispose()`)
192
+ 3. The workflow continues until it reaches the next suspension point (step call, hook await, or sleep) or completes
193
+ 4. The pending queue items are processed:
194
+ - Creates a `hook_received` event in the event log
195
+ - Writes the cancellation packet to the stream (for real-time step propagation)
196
+ - Re-enqueues the workflow for replay
197
+ 4. On replay, the event consumer processes the `hook_received` event, updating `signal.aborted` to `true` at the deterministically correct point
198
+
199
+ `signal.aborted` is updated synchronously so that the workflow can immediately check the state and serialization captures `aborted: true` when passing the signal to steps. On replay, the event consumer also processes the `hook_received` event, ensuring the state is consistent.
200
+
201
+ For abort specifically, this ensures that:
202
+
203
+ - The abort's `hook_received` event is created in the event log
204
+ - The cancellation stream packet is written to propagate to running steps
205
+
206
+ ## Race Conditions
207
+
208
+ ### Abort Before Hook Exists
209
+
210
+ When an `AbortSignal` is passed as a workflow argument via `start()`, the external reducer attaches a listener at serialization time. If the external code calls `abort()` before the workflow has started and created the internal hook, the stream packet is written but the hook doesn't exist yet.
211
+
212
+ This is resolved through eventual consistency:
213
+
214
+ 1. The stream packet is durable — it persists in storage
215
+ 2. When the workflow runs and passes the signal to a step, the step's reviver reads from the stream starting at index 0
216
+ 3. The step sees the existing packet, aborts locally, and resumes the hook (via `ops`)
217
+ 4. On the next workflow replay, the hook event is in the log and `signal.aborted` is `true`
218
+
219
+ **Important:** There is a window where the workflow's `signal.aborted` returns `false` even though the external code has already called `abort()`. This lasts until a step processes the stream packet and resumes the hook. This is analogous to hooks — `resumeHook()` doesn't take effect until the workflow replays.
220
+
221
+ ### Abort at Serialization Time
222
+
223
+ To prevent a micro-window where `abort()` is called between checking `signal.aborted` and attaching the listener, the external reducer uses this order:
224
+
225
+ 1. Attach the `abort` event listener first
226
+ 2. Then check `signal.aborted` — if already `true`, the listener won't fire, so handle immediately
227
+
228
+ This ensures no abort events are missed regardless of timing.
229
+
230
+ ## Stream/Hook Consistency
231
+
232
+ Since abort involves two operations (stream write + hook resume), partial failure is possible:
233
+
234
+ ### Stream Succeeds, Hook Fails
235
+
236
+ - Steps see the abort and throw `AbortError` (stream worked)
237
+ - Workflow doesn't see `signal.aborted === true` on the next replay (hook not resumed)
238
+ - The workflow sees the step failure as an error, which it can handle with try/catch
239
+ - **Recovery:** The step-side `resumeHook` call is best-effort — if it throws, the failure is swallowed. Convergence comes from the next replay: when the step's reviver re-reads the stream, it sees the abort packet and calls `resumeHook` again. There's no in-process retry loop; the dual-mechanism design relies on either the stream or the hook eventually landing.
240
+
241
+ ### Hook Succeeds, Stream Fails
242
+
243
+ - Workflow sees `signal.aborted === true` on replay (hook worked)
244
+ - Steps don't receive real-time cancellation (stream failed) — they run to completion
245
+ - On the next suspension, the workflow knows the abort happened and can stop calling more steps
246
+ - **Recovery:** Natural convergence — no active harm, just missed real-time cancellation for in-flight steps.
247
+
248
+ ### Both Fail
249
+
250
+ - Abort is lost — no propagation
251
+ - No crash or corruption — the system continues as if abort was never called
252
+ - **Recovery:** The caller can retry the abort. If using a hook for external cancellation, the hook's retry semantics apply.
253
+
254
+ The dual mechanism provides natural resilience — if either one succeeds, the system converges on the correct state.
255
+
256
+ ## `AbortSignal.timeout()` in Workflow VM
257
+
258
+ `AbortSignal.timeout()` is blocked in the workflow VM because it depends on real-time timers, which break deterministic replay. Calling it throws an error with a suggestion to use `sleep()` + `AbortController` instead. See [AbortSignal.timeout() in Workflow](/docs/errors/abort-signal-timeout-in-workflow) for details.
259
+
260
+ `AbortSignal.timeout()` works normally in step functions, which have full Node.js runtime access.
261
+
262
+ ## Request.signal
263
+
264
+ A `Request`'s `.signal` is forwarded by the `Request` reducer in two cases:
265
+
266
+ 1. **The signal is already aborted.** The serialized payload preserves `aborted: true` and the abort `reason`, so the deserialized step sees the cancellation that happened before the boundary.
267
+ 2. **The signal is workflow-managed** (i.e., it has the `ABORT_STREAM_NAME` symbol — produced by a workflow-context `AbortController`). Its hook + stream backing carries through, and the deserialized step listens on the stream as usual.
268
+
269
+ Plain non-aborted native signals are intentionally dropped, including the auto-generated signal that `new Request(url)` synthesizes when no `signal` is passed. Forwarding every Request signal would mint stream infrastructure for the throwaway auto-signals on every Request, even ones the caller never intended to use for cancellation.
270
+
271
+ If you want cross-boundary cancellation through a `Request`, build it with a signal from a workflow-context `AbortController`:
272
+
273
+ {/* @skip-typecheck: conceptual snippet */}
274
+ ```typescript
275
+ const controller = new AbortController(); // in workflow function
276
+ const req = new Request(url, { signal: controller.signal });
277
+ await fetchStep(req); // signal carries through
278
+ controller.abort(); // step-side fetch sees the abort
279
+ ```
280
+
281
+ ## Related Documentation
282
+
283
+ - [Cancellation](/docs/foundations/cancellation) — Usage patterns and API
284
+ - [Event Sourcing](/docs/how-it-works/event-sourcing) — How the event log works
285
+ - [Hooks](/docs/foundations/hooks) — The hook primitive
286
+ - [Streaming](/docs/foundations/streaming) — The stream primitive
287
+ - [Serialization](/docs/foundations/serialization) — Serializable types
@@ -5,7 +5,8 @@
5
5
  "code-transform",
6
6
  "framework-integrations",
7
7
  "event-sourcing",
8
- "encryption"
8
+ "encryption",
9
+ "cancellation"
9
10
  ],
10
11
  "defaultOpen": false
11
12
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@workflow/core",
3
- "version": "5.0.0-beta.4",
3
+ "version": "5.0.0-beta.5",
4
4
  "description": "Core runtime and engine for Workflow SDK",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -48,6 +48,11 @@
48
48
  "types": "./dist/runtime/resume-hook.d.ts",
49
49
  "default": "./dist/runtime/resume-hook.js"
50
50
  },
51
+ "./runtime/world-init": {
52
+ "types": "./dist/runtime/world-init.d.ts",
53
+ "workflow": "./dist/workflow/world-init-stub.js",
54
+ "default": "./dist/runtime/world-init.js"
55
+ },
51
56
  "./class-serialization": {
52
57
  "types": "./dist/class-serialization.d.ts",
53
58
  "default": "./dist/class-serialization.js"
@@ -64,6 +69,10 @@
64
69
  "types": "./dist/encryption.d.ts",
65
70
  "default": "./dist/encryption.js"
66
71
  },
72
+ "./describe-error": {
73
+ "types": "./dist/describe-error.d.ts",
74
+ "default": "./dist/describe-error.js"
75
+ },
67
76
  "./_workflow": "./dist/workflow/index.js"
68
77
  },
69
78
  "dependencies": {
@@ -80,12 +89,12 @@
80
89
  "semver": "7.7.4",
81
90
  "ulid": "~3.0.1",
82
91
  "zod": "4.3.6",
83
- "@workflow/errors": "5.0.0-beta.1",
92
+ "@workflow/errors": "5.0.0-beta.2",
84
93
  "@workflow/serde": "5.0.0-beta.1",
85
- "@workflow/utils": "5.0.0-beta.1",
86
- "@workflow/world": "5.0.0-beta.1",
87
- "@workflow/world-local": "5.0.0-beta.3",
88
- "@workflow/world-vercel": "5.0.0-beta.3"
94
+ "@workflow/utils": "5.0.0-beta.2",
95
+ "@workflow/world": "5.0.0-beta.2",
96
+ "@workflow/world-local": "5.0.0-beta.4",
97
+ "@workflow/world-vercel": "5.0.0-beta.4"
89
98
  },
90
99
  "devDependencies": {
91
100
  "@opentelemetry/api": "1.9.0",