workflow 5.2.3 → 5.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api.d.ts +1 -1
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +1 -1
- package/dist/internal/errors.d.ts +1 -1
- package/dist/internal/errors.d.ts.map +1 -1
- package/dist/internal/errors.js +2 -2
- package/docs/api-reference/workflow/create-hook.mdx +8 -0
- package/docs/api-reference/workflow/fetch.mdx +6 -0
- package/docs/api-reference/workflow-api/get-hook-by-token.mdx +5 -1
- package/docs/api-reference/workflow-api/get-run.mdx +4 -0
- package/docs/api-reference/workflow-api/resume-hook.mdx +58 -2
- package/docs/api-reference/workflow-api/start.mdx +64 -1
- package/docs/api-reference/workflow-errors/hook-conflict-error.mdx +6 -3
- package/docs/api-reference/workflow-errors/in-band-superseded-error.mdx +68 -0
- package/docs/api-reference/workflow-errors/index.mdx +6 -0
- package/docs/api-reference/workflow-errors/meta.json +2 -0
- package/docs/api-reference/workflow-errors/precondition-failed-error.mdx +2 -0
- package/docs/api-reference/workflow-errors/workflow-start-error.mdx +58 -0
- package/docs/api-reference/workflow-errors/workflow-world-error.mdx +12 -1
- package/docs/api-reference/workflow-runtime/world/storage.mdx +1 -1
- package/docs/changelog/eager-processing.mdx +2 -0
- package/docs/changelog/index.mdx +1 -0
- package/docs/changelog/lazy-event-creation.md +1 -1
- package/docs/changelog/meta.json +1 -0
- package/docs/changelog/spec-9.mdx +4019 -0
- package/docs/changelog/turbo-mode.md +4 -0
- package/docs/configuration/runtime-tuning.mdx +61 -2
- package/docs/configuration/worlds.mdx +12 -0
- package/docs/cookbook/advanced/child-workflows.mdx +2 -2
- package/docs/cookbook/common-patterns/batching.mdx +3 -1
- package/docs/cookbook/common-patterns/idempotency.mdx +11 -12
- package/docs/errors/fetch-in-workflow.mdx +7 -1
- package/docs/foundations/errors-and-retries.mdx +6 -0
- package/docs/foundations/hooks.mdx +3 -1
- package/docs/foundations/idempotency.mdx +190 -60
- package/docs/how-it-works/event-sourcing.mdx +6 -0
- package/docs/whats-new.mdx +3 -1
- package/docs/worlds/building-a-world.mdx +28 -3
- package/docs/worlds/local.mdx +6 -0
- package/docs/worlds/postgres.mdx +211 -145
- package/docs/worlds/upgrading-to-v5.mdx +7 -1
- package/docs/worlds/vercel.mdx +11 -5
- package/package.json +11 -11
|
@@ -136,7 +136,7 @@ None of this is required. Each entry is a hook the runtime uses if your World pr
|
|
|
136
136
|
|
|
137
137
|
| Member | What it buys |
|
|
138
138
|
| --- | --- |
|
|
139
|
-
| `capabilities` | Advertises `hookRetention.active`, `hookResumeDedup`, `hookForceClaim`, `deploymentAffinity`, `maxConcurrency`, and `dynamicWorkflowCode`. See the contract note above about failing closed. Event ID allocation is *not* in here: it is a requirement, not a capability. |
|
|
139
|
+
| `capabilities` | Advertises `hookRetention.active`, `hookResumeDedup`, `hookForceClaim`, `atomicStartHook.active`, `deploymentAffinity`, `maxConcurrency`, `inBandFence`, and `dynamicWorkflowCode`. See the contract note above about failing closed. Event ID allocation is *not* in here: it is a requirement, not a capability. |
|
|
140
140
|
| `events.createBatch` | Appends an ordered list of events in one durable write, with a per-event outcome for each. Implementing the method *is* the declaration: the runtime folds a suspension's `step_created` / `wait_created` writes into batches only when it exists, and otherwise takes the single-event path unchanged. Implement it with real atomicity per attempt, so a lost race leaves nothing behind, or leave it out. See [Batched event writes](/docs/changelog/batched-event-writes). |
|
|
141
141
|
| `runs.waitForTerminalStatus` | Long-polls until a run reaches a terminal status. `await run.returnValue` uses it when present, instead of polling on an interval. |
|
|
142
142
|
| `analytics` | A metadata-only read namespace for observability surfaces. Payload-bearing reads stay on `runs`, `steps`, `events`, and `hooks`. |
|
|
@@ -152,7 +152,9 @@ None of this is required. Each entry is a hook the runtime uses if your World pr
|
|
|
152
152
|
| `close()` | Releases connection pools and listeners so CLI commands and short-lived processes can exit without `process.exit()`. |
|
|
153
153
|
| `streams.streamFlushIntervalMs` | Sets the stream flush window. The v5 default is `0`, so the first chunk flushes immediately; set a value to coalesce writes again. |
|
|
154
154
|
| Hook token retention | `Hook.tokenRetentionUntil` marks the earliest time a token may become available after its run ends. Keep the owning run readable at least that long, and honor `hook_disposed` as an immediate release. Declare `capabilities.hookRetention.active` only once this is implemented, since the runtime otherwise rejects retained hooks before registration. |
|
|
155
|
+
| Atomic start Hooks | Backs [`start({ hook })`](/docs/api-reference/workflow-api/start#prevent-duplicate-starts): admit a run and create its start Hook in one atomic step, so a duplicate start is refused naming the owner and the start Hook can be resumed from admission. Declare `capabilities.atomicStartHook.active` only once you implement [the contract](/worlds/building-a-world#optional-atomic-start-hook-admission). |
|
|
155
156
|
| Hook resume dedup | `resumeHook()` writes `hook_received` and dispatches the queue message in parallel when the backend collapses concurrent writes carrying the same `(runId, resumeId)` onto one committed event. Declare `capabilities.hookResumeDedup` only if you enforce that constraint **and** `events.list()` returns the committed event's top-level `resumeId`. A World that omits either guarantee must leave the flag unset, which keeps the sequential path. See [Durable hook resume](/docs/changelog/lazy-hook-resume). |
|
|
157
|
+
| Resolved hook resume | Lets `resumeHook()` deliver to a stored [`Hook`](/docs/api-reference/workflow-api/resume-hook#reuse-a-resolved-hook) without looking up its token again. Declare `capabilities.resolvedHookResume` only if a write carrying `requireHookResumeDedup` either commits with atomic resume deduplication or is refused (400/404) before anything is written. The runtime then looks the token up and delivers as usual. Without the flag, a stored Hook is delivered through the existing path. |
|
|
156
158
|
| Hook token takeover | Backs [`createHook({ experimental_force: true })`](/docs/api-reference/workflow/create-hook#take-over-a-token-another-run-holds). When a forced `hook_created` names a token another live run holds, append `hook_disposed` with `forceClaimedBy: { runId, hookId }` to the holder's log and refuse later `hook_received` writes to it, then re-point the token to the claimer and record `Hook.claimedFrom`. Refuse the takeover with an ordinary `hook_conflict` carrying `forceRefusedReason: 'victim-spec-version'` when the holder was stamped below spec version 8, and answer a `hook_received` refused by a takeover with `HookForceClaimedError` so `resumeHook()` can follow the token. Declare `capabilities.hookForceClaim` only once you give these guarantees. Without it, the runtime fails a forced `createHook()` at registration. |
|
|
157
159
|
|
|
158
160
|
## If you also maintain a build integration
|
|
@@ -182,3 +184,7 @@ The cases worth covering explicitly:
|
|
|
182
184
|
`@workflow/world-testing` is the shared suite the first-party Worlds run, and it now covers event ID allocation directly: `numbers events by position` fails a World whose IDs do not decode to slots, whose run is not dense from 1, or whose IDs are not in canonical form. A World padding to a different width sorts its own log incorrectly past ten events. Run it against your World before the end-to-end cases above; it turns the failure that would otherwise appear on a first replay into one line of test output.
|
|
183
185
|
|
|
184
186
|
The first-party implementations in `packages/world-local` and `packages/world-postgres` are the reference for everything else, and their test suites are the closest thing to full conformance while the compatibility tests are being rebuilt.
|
|
187
|
+
|
|
188
|
+
## Spec 9 (experimental)
|
|
189
|
+
|
|
190
|
+
A World does not need to implement anything for the experimental spec 9 runtime to migrate to v5: `mintedSpecVersion()` with no options keeps creating spec 8 runs. A World that opts in must tell its users to upgrade every deployment and process that shares it before they set `WORKFLOW_SPEC_VERSION=9`, and not to roll back below that release once spec 9 runs exist. See [Implementing spec 9 in a World](/docs/changelog/spec-9#implementing-spec-9-in-a-world) and [The rollback floor](/docs/changelog/spec-9#the-rollback-floor).
|
package/docs/worlds/vercel.mdx
CHANGED
|
@@ -77,13 +77,13 @@ For self-hosted deployments, use the [Postgres World](/worlds/postgres). For loc
|
|
|
77
77
|
|
|
78
78
|
## Per-run limits
|
|
79
79
|
|
|
80
|
-
The Vercel World
|
|
80
|
+
The Vercel World supplies a per-run [event limit](/docs/how-it-works/event-sourcing). Each step adds events to that log, so the event budget also constrains how many steps a run can execute. See [Workflow run limits](https://vercel.com/docs/workflows/pricing#workflow-run-limits) for the published default limits and sizing guidance. A run that exhausts its event budget fails with `MAX_EVENTS_EXCEEDED` and cannot be continued.
|
|
81
81
|
|
|
82
|
-
|
|
82
|
+
On the default runtime, replay cost can grow with the event log. For workflows with many steps or frequent resumes, consider the experimental [QuickJS runtime](/docs/configuration/runtime-tuning#workflow_vm). Set `WORKFLOW_VM=quickjs` in your project's environment variables and redeploy. Only runs started after the change use the new runtime.
|
|
83
83
|
|
|
84
|
-
|
|
84
|
+
QuickJS runs are exempt from the default event cap, allowing larger event logs and more steps. They restore workflow state and replay only events recorded since the last snapshot, reducing replay overhead as the log grows. This does not speed up the work inside individual steps or remove payload, storage, and request rate limits. See [max-events-exceeded](/docs/errors/max-events-exceeded) for eligibility and compatibility details.
|
|
85
85
|
|
|
86
|
-
|
|
86
|
+
Use [child workflows](/cookbook/advanced/child-workflows) when independent units of work benefit from separate run histories and failure boundaries. To write fewer events, [process multiple items within each step](/cookbook/common-patterns/batching#tips), accounting for retries of the whole group.
|
|
87
87
|
|
|
88
88
|
## Multi-region
|
|
89
89
|
|
|
@@ -158,7 +158,7 @@ The route serves `world.createQueueHandler("__agent_wkf_workflow_", handler)`. T
|
|
|
158
158
|
## Limitations
|
|
159
159
|
|
|
160
160
|
- **No run migration**: A run's region is fixed at creation. Existing runs cannot be moved to a different region.
|
|
161
|
-
- **Hook minimum retention**:
|
|
161
|
+
- **Hook minimum retention**: `experimental_minRetention` cannot exceed 30 days, on both [`createHook()`](/docs/api-reference/workflow/create-hook#keep-a-token-unavailable-after-the-run-ends) and [`start({ hook })`](/docs/api-reference/workflow-api/start#prevent-duplicate-starts).
|
|
162
162
|
|
|
163
163
|
## Observability
|
|
164
164
|
|
|
@@ -374,10 +374,16 @@ Vercel team ID.
|
|
|
374
374
|
|
|
375
375
|
Custom base URL for the Vercel workflow API proxy. Default: `https://api.vercel.com/v1/workflow`.
|
|
376
376
|
|
|
377
|
+
The Vercel World doesn't follow HTTP redirects on workflow API requests, so point custom URLs at an endpoint that answers directly. A `3xx` response fails the request.
|
|
378
|
+
|
|
377
379
|
### `VERCEL_WORKFLOW_SERVER_URL`
|
|
378
380
|
|
|
379
381
|
Custom workflow-server URL for direct runtime requests, or for the proxy to forward to via `WORKFLOW_VERCEL_BACKEND_URL`. Default: unset; normal deployments should not need this.
|
|
380
382
|
|
|
383
|
+
### `WORKFLOW_VERCEL_EXPERIMENTAL_START_HOOK`
|
|
384
|
+
|
|
385
|
+
Set to `1` (or `true`) to enable [`start({ hook })`](/docs/api-reference/workflow-api/start#prevent-duplicate-starts) on the Vercel World. Off by default; without it, `start({ hook })` throws before it enqueues anything. It needs a backend that supports start Hooks. Set it on the deployment that starts runs and on any deployment those runs target.
|
|
386
|
+
|
|
381
387
|
### `WORKFLOW_SEQUENTIAL_REPLAYS`
|
|
382
388
|
|
|
383
389
|
Set `WORKFLOW_SEQUENTIAL_REPLAYS=1` to guarantee that **at most one orchestrator (flow) invocation runs at a time per workflow run**. This behavior is off by default; without it, the runtime relies on idempotency and the event log to tolerate concurrent flow invocations of the same run.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "workflow",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.3.0",
|
|
4
4
|
"description": "Workflow SDK - Build durable, resilient, and observable workflows",
|
|
5
5
|
"main": "dist/typescript-plugin.cjs",
|
|
6
6
|
"type": "module",
|
|
@@ -58,19 +58,19 @@
|
|
|
58
58
|
}
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@workflow/astro": "5.0.
|
|
62
|
-
"@workflow/cli": "5.0.
|
|
63
|
-
"@workflow/core": "5.
|
|
64
|
-
"@workflow/errors": "5.0
|
|
61
|
+
"@workflow/astro": "5.0.7",
|
|
62
|
+
"@workflow/cli": "5.0.7",
|
|
63
|
+
"@workflow/core": "5.3.0",
|
|
64
|
+
"@workflow/errors": "5.1.0",
|
|
65
65
|
"@workflow/typescript-plugin": "5.0.0",
|
|
66
66
|
"@workflow/utils": "5.0.2",
|
|
67
67
|
"ms": "2.1.3",
|
|
68
|
-
"@workflow/next": "5.0.
|
|
69
|
-
"@workflow/nest": "5.1.
|
|
70
|
-
"@workflow/nitro": "5.0.
|
|
71
|
-
"@workflow/nuxt": "5.0.
|
|
72
|
-
"@workflow/sveltekit": "5.0.
|
|
73
|
-
"@workflow/rollup": "5.0.
|
|
68
|
+
"@workflow/next": "5.0.7",
|
|
69
|
+
"@workflow/nest": "5.1.5",
|
|
70
|
+
"@workflow/nitro": "5.0.7",
|
|
71
|
+
"@workflow/nuxt": "5.0.7",
|
|
72
|
+
"@workflow/sveltekit": "5.0.7",
|
|
73
|
+
"@workflow/rollup": "5.0.7"
|
|
74
74
|
},
|
|
75
75
|
"devDependencies": {
|
|
76
76
|
"@types/ms": "2.1.0",
|