workflow 5.5.0 → 5.6.1

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 (88) hide show
  1. package/dist/api-workflow.js +1 -1
  2. package/dist/api.js +1 -1
  3. package/dist/astro.js +1 -1
  4. package/dist/index.js +1 -1
  5. package/dist/internal/builtins.js +1 -1
  6. package/dist/internal/class-serialization.js +1 -1
  7. package/dist/internal/errors.js +1 -1
  8. package/dist/nest-builder.js +1 -1
  9. package/dist/nest-vercel-builder.js +1 -1
  10. package/dist/nest.js +1 -1
  11. package/dist/next.cjs +1 -1
  12. package/dist/nitro.js +1 -1
  13. package/dist/nuxt.js +1 -1
  14. package/dist/observability.js +1 -1
  15. package/dist/runtime.js +1 -1
  16. package/dist/stdlib.js +1 -1
  17. package/dist/sveltekit.js +1 -1
  18. package/dist/typescript-plugin.cjs +1 -1
  19. package/dist/vite.js +1 -1
  20. package/dist/workflow.js +1 -1
  21. package/docs/api-reference/workflow-api/get-run.mdx +0 -4
  22. package/docs/api-reference/workflow-api/resume-hook.mdx +1 -1
  23. package/docs/api-reference/workflow-api/start.mdx +1 -1
  24. package/docs/api-reference/workflow-errors/in-band-superseded-error.mdx +0 -3
  25. package/docs/api-reference/workflow-errors/index.mdx +1 -1
  26. package/docs/api-reference/workflow-errors/precondition-failed-error.mdx +0 -2
  27. package/docs/api-reference/workflow-errors/workflow-not-registered-error.mdx +1 -1
  28. package/docs/api-reference/workflow-runtime/world/queue.mdx +70 -3
  29. package/docs/comparisons/index.mdx +4 -1
  30. package/docs/comparisons/workflow-sdk-vs-aws-step-functions.mdx +3 -1
  31. package/docs/comparisons/workflow-sdk-vs-cloudflare-workflows.mdx +4 -1
  32. package/docs/comparisons/workflow-sdk-vs-inngest.mdx +271 -28
  33. package/docs/comparisons/workflow-sdk-vs-temporal.mdx +6 -2
  34. package/docs/comparisons/workflow-sdk-vs-trigger-dev.mdx +2 -0
  35. package/docs/configuration/cli-and-web-ui.mdx +31 -1
  36. package/docs/configuration/runtime-tuning.mdx +9 -8
  37. package/docs/configuration/worlds.mdx +18 -21
  38. package/docs/cookbook/advanced/child-workflows.mdx +1 -1
  39. package/docs/cookbook/common-patterns/batching.mdx +1 -1
  40. package/docs/errors/index.mdx +1 -0
  41. package/docs/errors/max-events-exceeded.mdx +2 -2
  42. package/docs/errors/replay-timeout.mdx +2 -2
  43. package/docs/errors/workflow-not-registered.mdx +1 -1
  44. package/docs/foundations/errors-and-retries.mdx +1 -4
  45. package/docs/how-it-works/event-sourcing.mdx +2 -5
  46. package/docs/how-it-works/framework-integrations.mdx +2 -2
  47. package/docs/internal/index.mdx +1 -0
  48. package/docs/internal/nitro-native-build.mdx +1 -0
  49. package/docs/internal/nitro-web-ui.mdx +1 -0
  50. package/docs/internal/serializable-abort-controller.mdx +1 -0
  51. package/docs/observability/index.mdx +2 -0
  52. package/docs/whats-new.mdx +3 -3
  53. package/docs/worlds/building-a-world.mdx +46 -4
  54. package/docs/worlds/local.mdx +110 -25
  55. package/docs/worlds/postgres.mdx +107 -27
  56. package/docs/worlds/upgrading-to-v5.mdx +4 -4
  57. package/docs/worlds/vercel.mdx +190 -82
  58. package/package.json +16 -14
  59. package/dist/api-workflow.d.ts.map +0 -1
  60. package/dist/api.d.ts.map +0 -1
  61. package/dist/astro.d.ts.map +0 -1
  62. package/dist/index.d.ts.map +0 -1
  63. package/dist/internal/builtins.d.ts.map +0 -1
  64. package/dist/internal/class-serialization.d.ts.map +0 -1
  65. package/dist/internal/errors.d.ts.map +0 -1
  66. package/dist/nest-builder.d.ts.map +0 -1
  67. package/dist/nest-vercel-builder.d.ts.map +0 -1
  68. package/dist/nest.d.ts.map +0 -1
  69. package/dist/nitro.d.ts.map +0 -1
  70. package/dist/nuxt.d.ts.map +0 -1
  71. package/dist/observability.d.ts.map +0 -1
  72. package/dist/runtime.d.ts.map +0 -1
  73. package/dist/stdlib.d.ts.map +0 -1
  74. package/dist/sveltekit.d.ts.map +0 -1
  75. package/dist/vite.d.ts.map +0 -1
  76. package/dist/workflow.d.ts.map +0 -1
  77. package/docs/changelog/attributes-mvp.mdx +0 -380
  78. package/docs/changelog/batched-event-writes.mdx +0 -77
  79. package/docs/changelog/eager-processing.mdx +0 -273
  80. package/docs/changelog/index.mdx +0 -19
  81. package/docs/changelog/lazy-event-creation.md +0 -127
  82. package/docs/changelog/lazy-hook-resume.mdx +0 -78
  83. package/docs/changelog/meta.json +0 -16
  84. package/docs/changelog/resilient-resume.mdx +0 -32
  85. package/docs/changelog/resilient-start.mdx +0 -77
  86. package/docs/changelog/spec-9.mdx +0 -4167
  87. package/docs/changelog/step-message-ownership.mdx +0 -355
  88. package/docs/changelog/turbo-mode.md +0 -91
@@ -1,77 +0,0 @@
1
- ---
2
- title: Resilient run start
3
- description: Run start logic tolerates World storage unavailability when the queue is healthy and reduces run start latency.
4
- ---
5
-
6
- # Resilient `start()`
7
-
8
- ## Motivation
9
-
10
- When `world` storage is unavailable but the queue is up, `start()` previously failed entirely because `world.events.create(run_created)` is called before `world.queue()`. This change decouples run creation from queue dispatch so that runs can still be accepted when storage is degraded.
11
-
12
- The runtime also previously called `world.runs.get(runId)` before `run_started`, adding an extra round trip. Calling `run_started` directly removes that round trip and can return preloaded events in the response to skip the initial `events.list` call, reducing time to first byte (TTFB).
13
-
14
- ## Design
15
-
16
- ### `start()` changes
17
-
18
- - `world.events.create` (run_created) and `world.queue` are now called **in parallel** via `Promise.allSettled`.
19
- - If `events.create` returns a **429 or 5xx** error, the runtime logs a warning that run creation failed but the run was accepted. The runtime retries creation asynchronously when it processes the queue message. The returned `Run` instance is marked with `resilientStart = true`.
20
- - If `events.create` errors with **409** (EntityConflictError), the run already exists (e.g., the queue handler's resilient start path created it first due to a cold-start race). This is treated as success.
21
- - If `world.queue` fails, we still throw: the run truly failed and was not enqueued.
22
- - The queue invocation now receives all the run inputs (`input`, `deploymentId`, `workflowName`, `specVersion`, `executionContext`) via `runInput` so the runtime can create the run later if needed.
23
- - When the runtime re-enqueues itself, it does **not** pass these inputs: only the first queue cycle carries them.
24
-
25
- ### `workflowEntrypoint` changes
26
-
27
- - When calling `world.events.create` with `run_started`, we now also always pass the run input that was sent through the queue, if available. The world is responsible for creating the run if it doesn't already exist.
28
-
29
- ### `Run.returnValue` polling
30
-
31
- - When `resilientStart` is true on the Run instance (run_created failed), the `pollReturnValue` loop retries on `WorkflowRunNotFoundError` up to 3 times (1s + 3s + 6s = 10s total) to give the queue time to deliver and the runtime to create the run via `run_started`.
32
- - When `resilientStart` is false (normal path), 404 fails immediately: no delay for the common case of a wrong run ID.
33
-
34
- ### World contract changes
35
-
36
- - Posting `run_started` to a **non-existent** run is now allowed when the run input is sent along with the payload. The world creates a `run_created` event first (so the event log is consistent), then creates the `run_started` event normally.
37
- - When `run_started` encounters an **already-running** run, all worlds return `{ run }` with `event: undefined` instead of throwing. No duplicate event is created.
38
-
39
- ### Queue transport changes
40
-
41
- `Uint8Array` values (the serialized workflow input in `runInput`) don't survive plain JSON serialization. Each world uses a transport that preserves binary data:
42
-
43
- - **world-vercel**: Uses Concise Binary Object Representation (CBOR) transport, which CBOR-encodes the entire queue payload into a `Buffer` and uses `BufferTransport` from `@vercel/queue`. `Uint8Array` survives natively.
44
- - **world-local**: Uses `TypedJsonTransport`, which encodes `Uint8Array` as `{ __type: 'Uint8Array', data: '<base64>' }`.
45
- - **world-postgres**: Uses inline typed JSON transport, the same tagged-envelope approach as world-local.
46
-
47
- ## Decisions
48
-
49
- 1. **Parallel, not sequential**: We chose `Promise.allSettled` over sequential calls to minimize latency in the successful path.
50
-
51
- 2. **Already-running returns run without event**: When `run_started` encounters an already-running run, all worlds return `{ run }` with `event: undefined` (no `events` array) instead of throwing. The runtime detects this by checking for `result.event === undefined`. This avoids an extra `world.runs.get` round trip.
52
-
53
- 3. **Events in 200 response**: We only return events on the 200 path (first caller). On the already-running path, we fall back to the normal `events.list` call. This is correct because only on 200 can we be certain we know the full event history.
54
-
55
- 4. **Conditional 404 retry on Run.returnValue**: Only when `resilientStart = true` (run_created failed). Normal runs fail fast on 404.
56
-
57
- ## Known concerns
58
-
59
- ### Cold-start race on Vercel
60
-
61
- On Vercel, the parallel dispatch can cause the queue message to be processed before `run_created` completes, if `run_created` hits a cold-start lambda. When this happens:
62
-
63
- 1. The runtime's resilient start path creates the run from `run_started`.
64
- 2. The original `run_created` arrives and gets 409 (EntityConflictError).
65
- 3. `start()` treats the 409 as success (the run exists).
66
-
67
- The `resilientStart` flag is not set on the `Run` instance in this case (409 is not a retryable error), so `returnValue` fails immediately on 404.
68
-
69
- ### Atomicity of run entity creation
70
-
71
- The normal `run_created` path and the resilient start path can race on creating the run entity. In `world-local`, both paths use `writeExclusive` (O_CREAT|O_EXCL), atomic at the OS level, so exactly one writer wins and the other gets EEXIST. The normal path throws `EntityConflictError` on conflict (handled by `start()` as 409); the resilient start path re-reads the run from disk on conflict.
72
-
73
- Local World now restores a lost `run_created` from the run record before the run's first lifecycle event.
74
-
75
- In `world-postgres`, the resilient start path uses `onConflictDoNothing` plus a re-read on conflict for the same effect, with the same outcome on either side of the race.
76
-
77
- The narrow crash window in `world-postgres` between the run insert and the event insert is acceptable: if the run insert succeeds but the event insert crashes, the run exists and `run_started` will still proceed normally (the event log will be missing a `run_created` entry, but the run itself is functional).