workflow 5.0.0-beta.43 → 5.0.0-beta.44

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 (182) hide show
  1. package/README.md +6 -4
  2. package/dist/internal/builtins.d.ts +4 -4
  3. package/dist/internal/builtins.js +6 -6
  4. package/docs/ai/chat-session-modeling.mdx +23 -24
  5. package/docs/ai/defining-tools.mdx +5 -6
  6. package/docs/ai/human-in-the-loop.mdx +11 -11
  7. package/docs/ai/index.mdx +20 -20
  8. package/docs/ai/message-queueing.mdx +6 -6
  9. package/docs/ai/meta.json +1 -0
  10. package/docs/ai/resumable-streams.mdx +28 -28
  11. package/docs/ai/sleep-and-delays.mdx +9 -9
  12. package/docs/ai/streaming-updates-from-tools.mdx +4 -4
  13. package/docs/api-reference/vitest/index.mdx +8 -8
  14. package/docs/api-reference/workflow/create-hook.mdx +15 -15
  15. package/docs/api-reference/workflow/create-webhook.mdx +15 -15
  16. package/docs/api-reference/workflow/define-hook.mdx +10 -10
  17. package/docs/api-reference/workflow/fatal-error.mdx +2 -2
  18. package/docs/api-reference/workflow/fetch.mdx +7 -7
  19. package/docs/api-reference/workflow/get-step-metadata.mdx +2 -2
  20. package/docs/api-reference/workflow/get-workflow-metadata.mdx +3 -3
  21. package/docs/api-reference/workflow/get-writable.mdx +7 -7
  22. package/docs/api-reference/workflow/index.mdx +1 -1
  23. package/docs/api-reference/workflow/retryable-error.mdx +1 -1
  24. package/docs/api-reference/workflow/set-attributes.mdx +2 -2
  25. package/docs/api-reference/workflow/sleep.mdx +3 -3
  26. package/docs/api-reference/workflow-ai/durable-agent.mdx +42 -42
  27. package/docs/api-reference/workflow-ai/index.mdx +3 -3
  28. package/docs/api-reference/workflow-ai/workflow-chat-transport.mdx +28 -28
  29. package/docs/api-reference/workflow-api/get-hook-by-token.mdx +11 -11
  30. package/docs/api-reference/workflow-api/get-run.mdx +10 -10
  31. package/docs/api-reference/workflow-api/index.mdx +2 -4
  32. package/docs/api-reference/workflow-api/resume-hook.mdx +14 -14
  33. package/docs/api-reference/workflow-api/resume-webhook.mdx +3 -3
  34. package/docs/api-reference/workflow-api/start.mdx +16 -15
  35. package/docs/api-reference/workflow-astro/workflow.mdx +3 -3
  36. package/docs/api-reference/workflow-errors/entity-conflict-error.mdx +4 -4
  37. package/docs/api-reference/workflow-errors/hook-conflict-error.mdx +4 -4
  38. package/docs/api-reference/workflow-errors/hook-not-found-error.mdx +8 -8
  39. package/docs/api-reference/workflow-errors/index.mdx +6 -6
  40. package/docs/api-reference/workflow-errors/precondition-failed-error.mdx +9 -9
  41. package/docs/api-reference/workflow-errors/run-expired-error.mdx +2 -2
  42. package/docs/api-reference/workflow-errors/run-not-supported-error.mdx +4 -4
  43. package/docs/api-reference/workflow-errors/step-not-registered-error.mdx +5 -5
  44. package/docs/api-reference/workflow-errors/throttle-error.mdx +2 -2
  45. package/docs/api-reference/workflow-errors/too-early-error.mdx +2 -2
  46. package/docs/api-reference/workflow-errors/workflow-error.mdx +4 -4
  47. package/docs/api-reference/workflow-errors/workflow-not-registered-error.mdx +5 -6
  48. package/docs/api-reference/workflow-errors/workflow-run-cancelled-error.mdx +6 -6
  49. package/docs/api-reference/workflow-errors/workflow-run-failed-error.mdx +5 -5
  50. package/docs/api-reference/workflow-errors/workflow-run-not-completed-error.mdx +4 -4
  51. package/docs/api-reference/workflow-errors/workflow-run-not-found-error.mdx +4 -4
  52. package/docs/api-reference/workflow-errors/workflow-runtime-error.mdx +2 -2
  53. package/docs/api-reference/workflow-errors/workflow-world-error.mdx +8 -8
  54. package/docs/api-reference/workflow-globals.mdx +12 -11
  55. package/docs/api-reference/workflow-nest/configure-workflow-controller.mdx +2 -2
  56. package/docs/api-reference/workflow-nest/nest-local-builder.mdx +4 -4
  57. package/docs/api-reference/workflow-nest/workflow-controller.mdx +1 -1
  58. package/docs/api-reference/workflow-nest/workflow-module.mdx +4 -4
  59. package/docs/api-reference/workflow-next/with-workflow.mdx +16 -16
  60. package/docs/api-reference/workflow-nitro/index.mdx +6 -6
  61. package/docs/api-reference/workflow-nuxt/index.mdx +4 -4
  62. package/docs/api-reference/workflow-observability/hydrate-data.mdx +5 -5
  63. package/docs/api-reference/workflow-observability/hydrate-resource-io.mdx +4 -4
  64. package/docs/api-reference/workflow-observability/index.mdx +6 -8
  65. package/docs/api-reference/workflow-observability/observability-revivers.mdx +2 -2
  66. package/docs/api-reference/workflow-observability/parse-class-name.mdx +3 -3
  67. package/docs/api-reference/workflow-observability/parse-step-name.mdx +4 -4
  68. package/docs/api-reference/workflow-observability/parse-workflow-name.mdx +4 -4
  69. package/docs/api-reference/workflow-runtime/create-world.mdx +8 -8
  70. package/docs/api-reference/workflow-runtime/get-world-handlers.mdx +6 -6
  71. package/docs/api-reference/workflow-runtime/get-world.mdx +4 -4
  72. package/docs/api-reference/workflow-runtime/health-check.mdx +1 -1
  73. package/docs/api-reference/workflow-runtime/index.mdx +2 -4
  74. package/docs/api-reference/workflow-runtime/set-world.mdx +15 -13
  75. package/docs/api-reference/workflow-runtime/workflow-entrypoint.mdx +6 -5
  76. package/docs/api-reference/workflow-runtime/world/analytics.mdx +9 -9
  77. package/docs/api-reference/workflow-runtime/world/index.mdx +5 -3
  78. package/docs/api-reference/workflow-runtime/world/queue.mdx +11 -11
  79. package/docs/api-reference/workflow-runtime/world/storage.mdx +62 -28
  80. package/docs/api-reference/workflow-runtime/world/streams.mdx +7 -7
  81. package/docs/api-reference/workflow-serde/index.mdx +1 -1
  82. package/docs/api-reference/workflow-serde/workflow-deserialize.mdx +2 -2
  83. package/docs/api-reference/workflow-serde/workflow-serialize.mdx +7 -7
  84. package/docs/api-reference/workflow-sveltekit/workflow-plugin.mdx +3 -3
  85. package/docs/api-reference/workflow-vite/workflow.mdx +5 -5
  86. package/docs/changelog/attributes-mvp.mdx +39 -39
  87. package/docs/changelog/batched-event-writes.mdx +12 -12
  88. package/docs/changelog/eager-processing.mdx +63 -63
  89. package/docs/changelog/index.mdx +3 -3
  90. package/docs/changelog/lazy-event-creation.md +27 -27
  91. package/docs/changelog/resilient-resume.mdx +5 -5
  92. package/docs/changelog/resilient-start.mdx +14 -14
  93. package/docs/changelog/step-message-ownership.mdx +47 -47
  94. package/docs/changelog/turbo-mode.md +20 -20
  95. package/docs/comparisons/index.mdx +13 -13
  96. package/docs/comparisons/workflow-sdk-vs-aws-agentcore.mdx +15 -15
  97. package/docs/comparisons/workflow-sdk-vs-aws-step-functions.mdx +12 -12
  98. package/docs/comparisons/workflow-sdk-vs-cloudflare-workflows.mdx +11 -11
  99. package/docs/comparisons/workflow-sdk-vs-inngest.mdx +19 -19
  100. package/docs/comparisons/workflow-sdk-vs-temporal.mdx +23 -23
  101. package/docs/comparisons/workflow-sdk-vs-trigger-dev.mdx +18 -17
  102. package/docs/configuration/build-and-diagnostics.mdx +5 -5
  103. package/docs/configuration/cli-and-web-ui.mdx +4 -4
  104. package/docs/configuration/runtime-tuning.mdx +86 -23
  105. package/docs/configuration/worlds.mdx +28 -14
  106. package/docs/cookbook/advanced/child-workflows.mdx +25 -25
  107. package/docs/cookbook/advanced/publishing-libraries.mdx +40 -40
  108. package/docs/cookbook/advanced/serializable-steps.mdx +21 -21
  109. package/docs/cookbook/advanced/upgrading-workflows.mdx +31 -31
  110. package/docs/cookbook/agent-patterns/agent-cancellation.mdx +20 -20
  111. package/docs/cookbook/agent-patterns/human-in-the-loop.mdx +22 -22
  112. package/docs/cookbook/common-patterns/batching.mdx +14 -14
  113. package/docs/cookbook/common-patterns/idempotency.mdx +9 -9
  114. package/docs/cookbook/common-patterns/rate-limiting.mdx +3 -3
  115. package/docs/cookbook/common-patterns/saga.mdx +19 -19
  116. package/docs/cookbook/common-patterns/scheduling.mdx +23 -23
  117. package/docs/cookbook/common-patterns/sequential-and-parallel.mdx +26 -26
  118. package/docs/cookbook/common-patterns/timeouts.mdx +23 -23
  119. package/docs/cookbook/common-patterns/webhooks.mdx +6 -6
  120. package/docs/cookbook/common-patterns/workflow-composition.mdx +19 -19
  121. package/docs/cookbook/index.mdx +22 -22
  122. package/docs/cookbook/integrations/ai-sdk.mdx +43 -41
  123. package/docs/cookbook/integrations/chat-sdk.mdx +34 -34
  124. package/docs/cookbook/integrations/sandbox.mdx +46 -46
  125. package/docs/deploying.mdx +15 -15
  126. package/docs/errors/abort-signal-timeout-in-workflow.mdx +12 -12
  127. package/docs/errors/corrupted-event-log.mdx +11 -11
  128. package/docs/errors/deployment-mismatch.mdx +14 -14
  129. package/docs/errors/fetch-in-workflow.mdx +8 -8
  130. package/docs/errors/hook-conflict.mdx +11 -11
  131. package/docs/errors/index.mdx +1 -1
  132. package/docs/errors/node-js-module-in-workflow.mdx +5 -5
  133. package/docs/errors/replay-divergence.mdx +2 -2
  134. package/docs/errors/runtime-decryption-failed.mdx +12 -12
  135. package/docs/errors/serialization-failed.mdx +40 -12
  136. package/docs/errors/start-invalid-workflow-function.mdx +5 -5
  137. package/docs/errors/step-executed-multiple-times.mdx +2 -2
  138. package/docs/errors/step-not-registered.mdx +5 -5
  139. package/docs/errors/timeout-in-workflow.mdx +8 -8
  140. package/docs/errors/webhook-invalid-respond-with-value.mdx +18 -18
  141. package/docs/errors/webhook-response-not-sent.mdx +16 -16
  142. package/docs/errors/workflow-not-registered.mdx +5 -5
  143. package/docs/foundations/cancellation.mdx +31 -31
  144. package/docs/foundations/errors-and-retries.mdx +42 -11
  145. package/docs/foundations/hooks.mdx +35 -35
  146. package/docs/foundations/idempotency.mdx +9 -9
  147. package/docs/foundations/serialization.mdx +21 -22
  148. package/docs/foundations/starting-workflows.mdx +36 -37
  149. package/docs/foundations/streaming.mdx +46 -41
  150. package/docs/foundations/versioning.mdx +3 -3
  151. package/docs/foundations/workflows-and-steps.mdx +9 -9
  152. package/docs/getting-started/astro.mdx +16 -16
  153. package/docs/getting-started/express.mdx +8 -8
  154. package/docs/getting-started/fastify.mdx +8 -8
  155. package/docs/getting-started/hono.mdx +8 -8
  156. package/docs/getting-started/nestjs.mdx +18 -17
  157. package/docs/getting-started/next.mdx +11 -11
  158. package/docs/getting-started/nitro.mdx +16 -16
  159. package/docs/getting-started/nuxt.mdx +8 -8
  160. package/docs/getting-started/python.mdx +4 -4
  161. package/docs/getting-started/react-router/v7.mdx +1 -1
  162. package/docs/getting-started/react-router/v8.mdx +1 -1
  163. package/docs/getting-started/sveltekit.mdx +14 -14
  164. package/docs/getting-started/tanstack-start.mdx +12 -12
  165. package/docs/getting-started/vite.mdx +8 -8
  166. package/docs/how-it-works/cancellation.mdx +62 -62
  167. package/docs/how-it-works/code-transform.mdx +66 -54
  168. package/docs/how-it-works/encryption.mdx +25 -21
  169. package/docs/how-it-works/event-sourcing.mdx +53 -35
  170. package/docs/how-it-works/framework-integrations.mdx +12 -12
  171. package/docs/how-it-works/understanding-directives.mdx +21 -21
  172. package/docs/internal/index.mdx +6 -6
  173. package/docs/internal/nitro-native-build.mdx +2 -2
  174. package/docs/internal/nitro-web-ui.mdx +4 -4
  175. package/docs/internal/serializable-abort-controller.mdx +7 -7
  176. package/docs/observability/attributes.mdx +3 -3
  177. package/docs/observability/index.mdx +14 -10
  178. package/docs/observability/tracing.mdx +10 -10
  179. package/docs/testing/index.mdx +33 -33
  180. package/docs/testing/server-based.mdx +10 -10
  181. package/docs/whats-new.mdx +185 -0
  182. package/package.json +12 -12
@@ -18,30 +18,30 @@ This guide explains how cancellation works internally. Understanding these detai
18
18
 
19
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
20
 
21
- ## The Problem
21
+ ## The problem
22
22
 
23
- `AbortController` and `AbortSignal` are inherently stateful an abort happens once and is permanent. In a durable workflow, this state must:
23
+ `AbortController` and `AbortSignal` are inherently stateful: an abort happens once and is permanent. In a durable workflow, this state must:
24
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.
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
27
 
28
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
29
 
30
- ## Dual Backing: Hook + Stream
30
+ ## Dual backing: hook + stream
31
31
 
32
32
  Every `AbortController` in the workflow context is backed by:
33
33
 
34
- ### Hook (Durable State)
34
+ ### Hook (durable state)
35
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):
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
37
 
38
38
  - **On creation**: A `hook_created` event records that the controller exists
39
39
  - **On abort**: The hook is resumed (producing a `hook_received` event), recording the abort permanently
40
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
41
 
42
- This gives the workflow deterministic access to the abort state `controller.signal.aborted` always returns the correct value, even after cold starts.
42
+ This gives the workflow deterministic access to the abort state: `controller.signal.aborted` always returns the correct value, even after cold starts.
43
43
 
44
- ### Stream (Real-Time Propagation)
44
+ ### Stream (real-time propagation)
45
45
 
46
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
47
 
@@ -50,7 +50,7 @@ When `controller.signal` is serialized as a step argument, a stream name is incl
50
50
 
51
51
  This gives steps real-time cancellation without waiting for the workflow to replay.
52
52
 
53
- ### Why Both?
53
+ ### Why both?
54
54
 
55
55
  | Mechanism | Solves | Doesn't Solve |
56
56
  |---|---|---|
@@ -60,18 +60,18 @@ This gives steps real-time cancellation without waiting for the workflow to repl
60
60
 
61
61
  ## Lifecycle
62
62
 
63
- ### 1. Controller Created in Workflow
63
+ ### 1. Controller created in workflow
64
64
 
65
- ```
65
+ ```text
66
66
  new AbortController()
67
67
 
68
68
  ├─→ Internal hook created (registered in invocations queue)
69
69
  └─→ Stream name generated (deterministic ULID)
70
70
  ```
71
71
 
72
- ### 2. Signal Passed to Step
72
+ ### 2. Signal passed to step
73
73
 
74
- ```
74
+ ```text
75
75
  stepFunction(controller.signal)
76
76
 
77
77
  ├─→ Signal serialized as { streamName, hookToken, aborted }
@@ -80,9 +80,9 @@ stepFunction(controller.signal)
80
80
  └─→ Background reader listens on stream for abort packet
81
81
  ```
82
82
 
83
- ### 3. abort() Called in Workflow
83
+ ### 3. abort() called in workflow
84
84
 
85
- ```
85
+ ```text
86
86
  controller.abort()
87
87
 
88
88
  ├─→ signal.aborted set to true (synchronous, local state)
@@ -92,13 +92,13 @@ controller.abort()
92
92
  ├─→ Suspension handler creates hook_received event
93
93
  ├─→ Suspension handler writes cancellation packet to stream
94
94
  │ │
95
- │ └─→ Step receives packet → local signal fires → fetch cancelled
95
+ │ └─→ Step receives packet → local signal fires → fetch canceled
96
96
  └─→ Workflow re-enqueued for replay
97
97
  ```
98
98
 
99
- ### 4. Workflow Replays After Abort
99
+ ### 4. Workflow replays after abort
100
100
 
101
- ```
101
+ ```text
102
102
  Replay starts → events loaded
103
103
 
104
104
  ├─→ new AbortController() → hook created → event consumer subscribes
@@ -107,34 +107,34 @@ Replay starts → events loaded
107
107
  └─→ Workflow code sees signal.aborted === true at the correct point in replay
108
108
  ```
109
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.
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
111
 
112
- ## Where the Hook Is Created
112
+ ## Where the hook is created
113
113
 
114
114
  The backing hook is set up whenever an `AbortController` or `AbortSignal` enters the workflow context:
115
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.
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
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.
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, so no deterministic generation is needed in the workflow.
119
119
 
120
- **Passed as workflow input** Conceptually the same as "returned from a step". The **external reducer** handles it at serialization time:
120
+ **Passed as workflow input**: Conceptually the same as "returned from a step". The **external reducer** handles it at serialization time:
121
121
 
122
122
  1. Generates a stream name and hook token (random ULID)
123
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
124
  3. Pushes the listener's async work into `ops` (awaited via `waitUntil`)
125
125
  4. Serializes the reference as `{ streamName, hookToken, aborted }`
126
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.
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
128
 
129
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
130
 
131
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.
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
133
  </Callout>
134
134
 
135
- ## Serialization & Deserialization
135
+ ## Serialization & deserialization
136
136
 
137
- ### Serialized Form
137
+ ### Serialized form
138
138
 
139
139
  An `AbortController` or `AbortSignal` is serialized as:
140
140
 
@@ -148,23 +148,23 @@ An `AbortController` or `AbortSignal` is serialized as:
148
148
  }
149
149
  ```
150
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.
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
152
 
153
- ### Reducers (Serialization)
153
+ ### Reducers (serialization)
154
154
 
155
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
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.
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
158
 
159
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
160
 
161
- ### Revivers (Deserialization)
161
+ ### Revivers (deserialization)
162
162
 
163
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
164
 
165
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
166
 
167
- ### abort() in a Step
167
+ ### abort() in a step
168
168
 
169
169
  When `abort()` is called on a deserialized `AbortController` inside a step:
170
170
 
@@ -172,18 +172,18 @@ When `abort()` is called on a deserialized `AbortController` inside a step:
172
172
  2. The stream write (cancellation packet) is pushed into `ctx.ops`
173
173
  3. The hook resume (`resumeHook`) is pushed into `ctx.ops`
174
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.
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
176
 
177
- ### Abort Errors Are Wrapped in FatalError
177
+ ### Abort errors are wrapped in FatalError
178
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 executor wraps the error in `FatalError` before recording it in the event log. This ensures:
179
+ When a step throws due to an abort (whether from `fetch` throwing `AbortError`, `signal.throwIfAborted()`, or any other abort-induced error), the step executor wraps the error in `FatalError` before recording it in the event log. This ensures:
180
180
 
181
- - **No retries**: An abort is intentional cancellation, not a transient failure. Retrying would just abort again.
181
+ - **No retries**: An abort is intentional cancellation, not a transient failure. Retrying would abort again.
182
182
  - **Immediate propagation**: The error bubbles up to the workflow as a `FatalError`, which the workflow can catch with `FatalError.is(err)`.
183
183
 
184
184
  The wrapping happens in `runtime/step-executor.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
185
 
186
- ### abort() in the Workflow
186
+ ### abort() in the workflow
187
187
 
188
188
  When `abort()` is called in the workflow context:
189
189
 
@@ -194,7 +194,7 @@ When `abort()` is called in the workflow context:
194
194
  - Creates a `hook_received` event in the event log
195
195
  - Writes the cancellation packet to the stream (for real-time step propagation)
196
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
197
+ 5. On replay, the event consumer processes the `hook_received` event, updating `signal.aborted` to `true` at the deterministically correct point
198
198
 
199
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
200
 
@@ -203,55 +203,55 @@ For abort specifically, this ensures that:
203
203
  - The abort's `hook_received` event is created in the event log
204
204
  - The cancellation stream packet is written to propagate to running steps
205
205
 
206
- ## Race Conditions
206
+ ## Race conditions
207
207
 
208
- ### Abort Before Hook Exists
208
+ ### Abort before hook exists
209
209
 
210
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
211
 
212
212
  This is resolved through eventual consistency:
213
213
 
214
- 1. The stream packet is durable it persists in storage
214
+ 1. The stream packet is durable; it persists in storage
215
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
216
  3. The step sees the existing packet, aborts locally, and resumes the hook (via `ops`)
217
217
  4. On the next workflow replay, the hook event is in the log and `signal.aborted` is `true`
218
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.
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
220
 
221
- ### Abort at Serialization Time
221
+ ### Abort at serialization time
222
222
 
223
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
224
 
225
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
226
+ 2. Then check `signal.aborted`; if already `true`, the listener won't fire, so handle immediately
227
227
 
228
228
  This ensures no abort events are missed regardless of timing.
229
229
 
230
- ## Stream/Hook Consistency
230
+ ## Stream/hook consistency
231
231
 
232
232
  Since abort involves two operations (stream write + hook resume), partial failure is possible:
233
233
 
234
- ### Stream Succeeds, Hook Fails
234
+ ### Stream succeeds, hook fails
235
235
 
236
236
  - Steps see the abort and throw `AbortError` (stream worked)
237
237
  - Workflow doesn't see `signal.aborted === true` on the next replay (hook not resumed)
238
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.
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
240
 
241
- ### Hook Succeeds, Stream Fails
241
+ ### Hook succeeds, stream fails
242
242
 
243
243
  - Workflow sees `signal.aborted === true` on replay (hook worked)
244
- - Steps don't receive real-time cancellation (stream failed) they run to completion
244
+ - Steps don't receive real-time cancellation (stream failed), so they run to completion
245
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.
246
+ - **Recovery:** Natural convergence. No active harm, only missed real-time cancellation for in-flight steps.
247
247
 
248
- ### Both Fail
248
+ ### Both fail
249
249
 
250
- - Abort is lost no propagation
251
- - No crash or corruption the system continues as if abort was never called
250
+ - Abort is lost; no propagation
251
+ - No crash or corruption; the system continues as if abort was never called
252
252
  - **Recovery:** The caller can retry the abort. If using a hook for external cancellation, the hook's retry semantics apply.
253
253
 
254
- The dual mechanism provides natural resilience if either one succeeds, the system converges on the correct state.
254
+ The dual mechanism provides natural resilience: if either one succeeds, the system converges on the correct state.
255
255
 
256
256
  ## `AbortSignal.timeout()` in Workflow VM
257
257
 
@@ -264,7 +264,7 @@ The dual mechanism provides natural resilience — if either one succeeds, the s
264
264
  A `Request`'s `.signal` is forwarded by the `Request` reducer in two cases:
265
265
 
266
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.
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
268
 
269
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
270
 
@@ -278,10 +278,10 @@ await fetchStep(req); // signal carries through
278
278
  controller.abort(); // step-side fetch sees the abort
279
279
  ```
280
280
 
281
- ## Related Documentation
281
+ ## Related documentation
282
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
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
@@ -1,5 +1,5 @@
1
1
  ---
2
- title: How the Directives Work
2
+ title: How the directives work
3
3
  description: Deep dive into the internals of how Workflow SDK directives transform your code.
4
4
  type: conceptual
5
5
  summary: Learn how the compiler transforms directive-annotated code into three execution modes.
@@ -10,16 +10,15 @@ related:
10
10
  ---
11
11
 
12
12
  <Callout>
13
- This is an advanced guide that dives into internals of the Workflow SDK directive and is not required reading to use workflows. To simply use the Workflow SDK, check out the [getting started](/docs/getting-started) guides for your framework.
13
+ This advanced guide covers the internals of Workflow SDK directives. To start using Workflow SDK, see the [getting started](/docs/getting-started) guide for your framework.
14
14
  </Callout>
15
15
 
16
- Workflows use special directives to mark code for transformation by the Workflow SDK compiler. This page explains how `"use workflow"` and `"use step"` directives work, what transformations are applied, and why they're necessary for durable execution.
16
+ Workflows use special directives to mark code for transformation by the Workflow SDK compiler. The `"use workflow"` and `"use step"` directives apply the transformations required for durable execution.
17
17
 
18
- ## Directives Overview
18
+ ## Directives overview
19
19
 
20
20
  Workflows use two directives to mark functions for special handling:
21
21
 
22
- {/* @skip-typecheck: incomplete code sample */}
23
22
  ```typescript
24
23
  export async function handleUserSignup(email: string) {
25
24
  "use workflow"; // [!code highlight]
@@ -44,7 +43,7 @@ async function createUser(email: string) {
44
43
 
45
44
  These directives trigger the `@workflow/swc-plugin` compiler to transform your code in different ways depending on the execution context.
46
45
 
47
- ## The Three Transformation Modes
46
+ ## The three transformation modes
48
47
 
49
48
  The compiler operates in three distinct modes, transforming the same source code differently for each execution context:
50
49
 
@@ -52,39 +51,47 @@ The compiler operates in three distinct modes, transforming the same source code
52
51
  flowchart LR
53
52
  A["Source Code<br/>with directives"] --> B["Step Mode"]
54
53
  A --> C["Workflow Mode"]
55
- A --> D["Client Mode"]
54
+ A --> D["Detect Mode"]
56
55
  B --> E["Step registration bundle"]
56
+ B --> G["Your App Code<br/>(Enables `start`)"]
57
57
  C --> F["Workflow bundle"]
58
58
  E --> H["Combined flow handler"]
59
59
  F --> H
60
- D --> G["Your App Code<br/>(Enables `start`)"]
60
+ D --> I["Build manifest<br/>(discovery)"]
61
61
  ```
62
62
 
63
- ### Comparison Table
63
+ ### Comparison table
64
64
 
65
65
  | Mode | Used In | Purpose | Runtime role | Required? |
66
66
  |----------|------------|--------------------------------|--------------|-----------|
67
- | Step | Build time | Registers executable step functions | Imported by the combined flow handler | Yes |
67
+ | Step | Build time + your app code | Registers executable step functions; gives app code workflow IDs for `start()` | Imported by the combined flow handler, and applied to application code by the framework loader | Yes |
68
68
  | Workflow | Build time | Bundles workflow orchestrators | Executed by `.well-known/workflow/v1/flow` | Yes |
69
- | Client | Build/Runtime | Provides workflow IDs and types to `start` | Your application code | Optional* |
69
+ | Detect | Build time | Discovers workflows, steps, and serialization classes without transforming code | Feeds the build's discovery phase and manifest | Yes (build-internal) |
70
70
 
71
- \* Client mode is **recommended** for better developer experience—it provides automatic ID generation and type safety. Without it, you must manually construct workflow IDs or use the build manifest.
71
+ <Callout type="info">
72
+ Earlier releases had a separate **client mode** for application code. In 5.0 it merged into step mode, which produces the same app-code behavior (workflow functions throw on direct calls and carry `workflowId` for `start()`) while also registering step functions. Build integrations that passed `mode: "client"` now pass `mode: "step"`.
73
+ </Callout>
72
74
 
73
- ## Detailed Transformation Examples
75
+ ## Detailed transformation examples
74
76
 
75
- <Tabs items={["Step Mode", "Workflow Mode", "Client Mode"]}>
77
+ <Tabs items={["Step Mode", "Workflow Mode", "Detect Mode"]}>
76
78
  <Tab value="Step Mode">
77
79
 
78
- **Step Mode** creates a registration bundle that the combined flow handler imports. It is not an HTTP route.
80
+ **Step Mode** creates the registration bundle that the combined flow handler imports (it is not an HTTP route), and is also the transform framework loaders apply to your application code.
79
81
 
80
82
  **Input:**
81
83
 
82
- {/* @skip-typecheck: incomplete code sample */}
83
84
  ```typescript
84
85
  export async function createUser(email: string) {
85
86
  "use step";
86
87
  return { id: crypto.randomUUID(), email };
87
88
  }
89
+
90
+ export async function handleUserSignup(email: string) {
91
+ "use workflow";
92
+ const user = await createUser(email);
93
+ return { userId: user.id };
94
+ }
88
95
  ```
89
96
 
90
97
  **Output:**
@@ -99,18 +106,25 @@ export async function createUser(email: string) {
99
106
  __wf_reg.set(__wf_id, __wf_fn); // [!code highlight]
100
107
  __wf_fn.stepId = __wf_id; // [!code highlight]
101
108
  })(createUser, "step//workflows/user.js//createUser"); // [!code highlight]
109
+
110
+ export async function handleUserSignup(email: string) {
111
+ throw new Error("You attempted to execute ..."); // [!code highlight]
112
+ }
113
+ handleUserSignup.workflowId = "workflow//workflows/user.js//handleUserSignup"; // [!code highlight]
102
114
  ```
103
115
 
104
116
  **What happens:**
105
117
 
106
118
  - The `"use step"` directive is removed
107
- - The function body is kept completely intact (no transformation)
108
- - The function is registered with the runtime via an inline IIFE (no imports needed)
119
+ - Step function bodies are kept completely intact (no transformation)
120
+ - Each step function is registered with the runtime via an inline IIFE (no imports needed)
109
121
  - Step functions run with full Node.js/Deno/Bun access
122
+ - Workflow function bodies are **replaced** with an error throw, and a `workflowId` property is attached. Launch workflow functions with [`start()`](/docs/api-reference/workflow-api/start) instead of calling them directly. The ID identifies the workflow to `start()`
123
+ - A dead-code-elimination pass removes code reachable only from the replaced workflow bodies
110
124
 
111
- **Why no transformation?** Step functions execute in your main runtime with full access to Node.js APIs, file system, databases, etc. They don't need any special handling—they just run normally.
125
+ **Why no step transformation?** Step functions execute in your main runtime with full access to Node.js APIs, the file system, databases, and other resources. They run normally without special handling.
112
126
 
113
- **ID Format:** Step IDs follow the pattern `step//{filepath}//{functionName}`, where the filepath is relative to your project root.
127
+ **ID format:** Step IDs follow the pattern `step//{filepath}//{functionName}`, where the file path is relative to your project root.
114
128
 
115
129
  </Tab>
116
130
  <Tab value="Workflow Mode">
@@ -119,7 +133,6 @@ export async function createUser(email: string) {
119
133
 
120
134
  **Input:**
121
135
 
122
- {/* @skip-typecheck: incomplete code sample */}
123
136
  ```typescript
124
137
  export async function createUser(email: string) {
125
138
  "use step";
@@ -151,7 +164,7 @@ handleUserSignup.workflowId = "workflow//workflows/user.js//handleUserSignup"; /
151
164
  **What happens:**
152
165
 
153
166
  - Step function bodies are **replaced** with calls to `globalThis[Symbol.for("WORKFLOW_USE_STEP")]`
154
- - Workflow function bodies remain **intact**—they execute deterministically during replay
167
+ - Workflow function bodies remain **intact**, so they execute deterministically during replay
155
168
  - The workflow function gets a `workflowId` property for runtime identification
156
169
  - The `"use workflow"` directive is removed
157
170
 
@@ -159,14 +172,14 @@ handleUserSignup.workflowId = "workflow//workflows/user.js//handleUserSignup"; /
159
172
 
160
173
  1. Checks if the step has already been executed (in the event log)
161
174
  2. If yes: Returns the cached result
162
- 3. If no: Triggers a suspension and enqueues the step for background execution
175
+ 3. If no: Suspends the replay and executes the step, usually inline in the same invocation. The runtime returns the run to the queue only when the invocation's inline budget is exhausted or its timeout approaches
163
176
 
164
- **ID Format:** Workflow IDs follow the pattern `workflow//{filepath}//{functionName}`. The `workflowId` property is attached to the function to allow [`start()`](/docs/api-reference/workflow-api/start) to work at runtime.
177
+ **ID format:** Workflow IDs follow the pattern `workflow//{filepath}//{functionName}`. The `workflowId` property is attached to the function so [`start()`](/docs/api-reference/workflow-api/start) works at runtime.
165
178
 
166
179
  </Tab>
167
- <Tab value="Client Mode">
180
+ <Tab value="Detect Mode">
168
181
 
169
- **Client Mode** transforms workflow functions in your application code to prevent direct execution.
182
+ **Detect Mode** is a lightweight, non-transforming mode used during the build's discovery phase.
170
183
 
171
184
  **Input:**
172
185
 
@@ -183,35 +196,30 @@ export async function handleUserSignup(email: string) {
183
196
 
184
197
  {/* @skip-typecheck: incomplete code sample */}
185
198
  ```typescript
199
+ /**__internal_workflows{"workflows":{"user.js":{"handleUserSignup":{"workflowId":"workflow//workflows/user.js//handleUserSignup"}}}}*/; // [!code highlight]
186
200
  export async function handleUserSignup(email: string) {
187
- throw new Error("You attempted to execute ..."); // [!code highlight]
201
+ "use workflow";
202
+ const user = await createUser(email);
203
+ return { userId: user.id };
188
204
  }
189
- handleUserSignup.workflowId = "workflow//workflows/user.js//handleUserSignup"; // [!code highlight]
190
205
  ```
191
206
 
192
207
  **What happens:**
193
208
 
194
- - Workflow function bodies are **replaced** with an error throw
195
- - The `workflowId` property is added (same as workflow mode)
196
- - Step functions are not transformed in client mode
197
-
198
- **Why this transformation?** Workflow functions cannot be called directly from application code—they must be started using [`start()`](/docs/api-reference/workflow-api/start). The error prevents accidental direct execution while the `workflowId` property allows the `start()` function to identify which workflow to launch.
209
+ - The code is **not modified**. Detect mode only walks the AST
210
+ - Discovered workflows, steps, and custom-serialization classes are emitted as a JSON manifest comment
211
+ - The build uses this to decide which files feed the step and workflow bundles
199
212
 
200
- The IDs are generated exactly like in workflow mode to ensure they can be directly referenced at runtime.
213
+ **Why a separate mode?** The build system first runs a fast regular expression pre-scan to find candidate files containing directive-like strings. It then runs detect mode on those candidates to validate them at the abstract syntax tree (AST) level. The plugin eliminates false positives, such as a directive-like string inside a template literal, because it only recognizes genuine directive statements.
201
214
 
202
215
  <Callout type="info">
203
- **Client mode is optional:** While recommended for better developer experience (automatic IDs and type safety), you can skip client mode and instead:
204
- - Manually construct workflow IDs using the pattern `workflow//{filepath}//{functionName}`
205
- - Use the workflow manifest file generated during build to lookup IDs
206
- - Pass IDs directly to `start()` as strings
207
-
208
- All framework integrations include client mode as a loader by default.
216
+ **Working without the app-code loader:** Frameworks apply the step-mode transform to application code by default, which is what gives `start(handleUserSignup)` its automatic IDs and type safety. If your setup can't run the loader, you can instead construct workflow IDs manually using the pattern `workflow//{filepath}//{functionName}`, look them up in the build manifest, and pass them to `start()` as strings.
209
217
  </Callout>
210
218
 
211
219
  </Tab>
212
220
  </Tabs>
213
221
 
214
- ## Generated Files
222
+ ## Generated files
215
223
 
216
224
  When you build your application, the Workflow SDK generates a combined flow handler, an internal step registration bundle, and a webhook handler. Exact filenames vary by framework.
217
225
 
@@ -224,7 +232,7 @@ Contains all workflow functions transformed in **workflow mode**. This file is i
224
232
  All workflow code is bundled together and embedded as a string inside `flow.js`. When a workflow needs to execute, this bundled code is run inside a **Node.js VM** (virtual machine) to ensure:
225
233
 
226
234
  - **Determinism**: The same inputs always produce the same outputs
227
- - **Side-effect prevention**: Direct access to Node.js APIs, file system, network, etc. is blocked
235
+ - **Side-effect prevention**: Direct access to Node.js APIs, the file system, the network, and other resources is blocked
228
236
  - **Sandboxed execution**: Workflow orchestration logic is isolated from the main runtime
229
237
 
230
238
  **Build-time validation:**
@@ -259,6 +267,10 @@ Contains all step functions transformed in **step mode**. The combined flow hand
259
267
 
260
268
  This module must not be exposed as an HTTP endpoint.
261
269
 
270
+ <Callout type="info">
271
+ **Changed in 5.0:** In 4.x, the step bundle was served as its own HTTP route at `POST /.well-known/workflow/v1/step`, with step messages delivered on a separate `__wkf_step_*` queue topic. v5 merged both into the combined flow handler. The step bundle became a registration module imported by `flow.js`, and step messages arrive on the shared workflow queue. Use the version picker to see the old layout on the v4 version of this page.
272
+ </Callout>
273
+
262
274
  ### `webhook.js`
263
275
 
264
276
  Contains webhook handling logic for delivering external data to running workflows via [`createWebhook()`](/docs/api-reference/workflow/create-webhook).
@@ -269,24 +281,24 @@ Contains webhook handling logic for delivering external data to running workflow
269
281
  - Validates tokens and routes data to the correct workflow run
270
282
  - Resumes workflow execution after webhook delivery
271
283
 
272
- **Note:** The webhook file structure varies by framework. Next.js generates `webhook/[token]/route.js` to leverage App Router's dynamic routing, while other frameworks generate a single `webhook.js` or `webhook.mjs` handler.
284
+ The webhook file structure varies by framework. Next.js generates `webhook/[token]/route.js` to use App Router's dynamic routing, while other frameworks generate a single `webhook.js` or `webhook.mjs` handler.
273
285
 
274
- ## Why Three Modes?
286
+ ## Why three modes?
275
287
 
276
288
  The multi-mode transformation enables the Workflow SDK's durable execution model:
277
289
 
278
- 1. **Step Mode** (required) - Bundles executable step functions that can access the full runtime
279
- 2. **Workflow Mode** (required) - Creates orchestration logic that can replay from event logs
280
- 3. **Client Mode** (optional) - Prevents direct execution and enables type-safe workflow references
290
+ 1. **Step mode** (required): Bundles executable step functions that can access the full runtime and serves as the application-code transform that prevents direct workflow execution and enables type-safe `start()` references
291
+ 2. **Workflow mode** (required): Creates orchestration logic that can replay from event logs
292
+ 3. **Detect mode** (build-internal): Discovers directive-marked functions for the build without changing the code
281
293
 
282
294
  This separation allows:
283
295
 
284
296
  - **Deterministic replay**: Workflows can be safely replayed from event logs without re-executing side effects
285
297
  - **Sandboxed orchestration**: Workflow logic runs in a controlled VM without direct runtime access
286
298
  - **Stateless execution**: Your compute can scale to zero and resume from any point in the workflow
287
- - **Type safety**: TypeScript works seamlessly with workflow references (when using client mode)
299
+ - **Type safety**: TypeScript supports workflow references passed to `start()`
288
300
 
289
- ## Determinism and Replay
301
+ ## Determinism and replay
290
302
 
291
303
  A key aspect of the transformation is maintaining **deterministic replay** for workflow functions.
292
304
 
@@ -296,7 +308,7 @@ A key aspect of the transformation is maintaining **deterministic replay** for w
296
308
  - No direct side effects (no API calls, no database writes, no file I/O)
297
309
  - Can use seeded random/time APIs provided by the VM (`Math.random()`, `Date.now()`, etc.)
298
310
 
299
- Because workflow functions are deterministic and have no side effects, they can be safely re-run multiple times to calculate what the next step should be. This is why workflow function bodies remain intact in workflow modethey're pure orchestration logic.
311
+ Because workflow functions are deterministic and have no side effects, they can be safely rerun multiple times to calculate the next step. Workflow function bodies remain intact in workflow mode because they're pure orchestration logic.
300
312
 
301
313
  **Step functions can be non-deterministic:**
302
314
 
@@ -306,7 +318,7 @@ Because workflow functions are deterministic and have no side effects, they can
306
318
 
307
319
  Learn more about [Workflows and Steps](/docs/foundations/workflows-and-steps).
308
320
 
309
- ## ID Generation
321
+ ## ID generation
310
322
 
311
323
  The compiler generates stable IDs for workflows and steps based on file paths and function names:
312
324
 
@@ -328,15 +340,15 @@ The compiler generates stable IDs for workflows and steps based on file paths an
328
340
  Although IDs can change when files are moved or functions are renamed, Workflow SDK functions assume [atomic versioning](/docs/foundations/versioning) in the World. This means changing IDs won't break old workflows from running, but will prevent runs from being upgraded and will cause your workflow/step names to change in observability across deployments.
329
341
  </Callout>
330
342
 
331
- ## Framework Integration
343
+ ## Framework integration
332
344
 
333
- These transformations are framework-agnostic—they output standard JavaScript that works anywhere.
345
+ These transformations are framework-agnostic. They output standard JavaScript that works anywhere.
334
346
 
335
347
  **For users**: Your framework handles all transformations automatically. See the [Getting Started](/docs/getting-started) guide for your framework.
336
348
 
337
349
  **For framework authors**: Learn how to integrate these transformations into your framework in [Building Framework Integrations](/docs/how-it-works/framework-integrations).
338
350
 
339
- ## Debugging Transformed Code
351
+ ## Debugging transformed code
340
352
 
341
353
  If you need to debug transformation issues, you can inspect the generated files:
342
354