workflow 5.7.0 → 5.7.2

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.
@@ -1,2 +1,2 @@
1
- export { EntityConflictError, HookConflictError, HookForceClaimedError, HookNotFoundError, InBandSupersededError, PreconditionFailedError, RunExpiredError, RunNotSupportedError, StepNotRegisteredError, StreamError, ThrottleError, TooEarlyError, WorkflowError, WorkflowNotRegisteredError, WorkflowRunCancelledError, WorkflowRunFailedError, WorkflowRunNotCompletedError, WorkflowRunNotFoundError, WorkflowRuntimeError, WorkflowStartError, WorkflowWorldError, } from '@workflow/errors';
1
+ export { DynamicWorkflowsNotEnabledError, EntityConflictError, HookConflictError, HookForceClaimedError, HookNotFoundError, InBandSupersededError, PreconditionFailedError, RunExpiredError, RunNotSupportedError, StepNotRegisteredError, StreamError, ThrottleError, TooEarlyError, WorkflowError, WorkflowNotRegisteredError, WorkflowRunCancelledError, WorkflowRunFailedError, WorkflowRunNotCompletedError, WorkflowRunNotFoundError, WorkflowRuntimeError, WorkflowStartError, WorkflowWorldError, } from '@workflow/errors';
2
2
  //# sourceMappingURL=errors.d.ts.map
@@ -1,2 +1,2 @@
1
- export { EntityConflictError, HookConflictError, HookForceClaimedError, HookNotFoundError, InBandSupersededError, PreconditionFailedError, RunExpiredError, RunNotSupportedError, StepNotRegisteredError, StreamError, ThrottleError, TooEarlyError, WorkflowError, WorkflowNotRegisteredError, WorkflowRunCancelledError, WorkflowRunFailedError, WorkflowRunNotCompletedError, WorkflowRunNotFoundError, WorkflowRuntimeError, WorkflowStartError, WorkflowWorldError, } from '@workflow/errors';
2
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZXJyb3JzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL2ludGVybmFsL2Vycm9ycy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQ0wsbUJBQW1CLEVBQ25CLGlCQUFpQixFQUNqQixxQkFBcUIsRUFDckIsaUJBQWlCLEVBQ2pCLHFCQUFxQixFQUNyQix1QkFBdUIsRUFDdkIsZUFBZSxFQUNmLG9CQUFvQixFQUNwQixzQkFBc0IsRUFDdEIsV0FBVyxFQUNYLGFBQWEsRUFDYixhQUFhLEVBQ2IsYUFBYSxFQUNiLDBCQUEwQixFQUMxQix5QkFBeUIsRUFDekIsc0JBQXNCLEVBQ3RCLDRCQUE0QixFQUM1Qix3QkFBd0IsRUFDeEIsb0JBQW9CLEVBQ3BCLGtCQUFrQixFQUNsQixrQkFBa0IsR0FDbkIsTUFBTSxrQkFBa0IsQ0FBQyJ9
1
+ export { DynamicWorkflowsNotEnabledError, EntityConflictError, HookConflictError, HookForceClaimedError, HookNotFoundError, InBandSupersededError, PreconditionFailedError, RunExpiredError, RunNotSupportedError, StepNotRegisteredError, StreamError, ThrottleError, TooEarlyError, WorkflowError, WorkflowNotRegisteredError, WorkflowRunCancelledError, WorkflowRunFailedError, WorkflowRunNotCompletedError, WorkflowRunNotFoundError, WorkflowRuntimeError, WorkflowStartError, WorkflowWorldError, } from '@workflow/errors';
2
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZXJyb3JzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL2ludGVybmFsL2Vycm9ycy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQ0wsK0JBQStCLEVBQy9CLG1CQUFtQixFQUNuQixpQkFBaUIsRUFDakIscUJBQXFCLEVBQ3JCLGlCQUFpQixFQUNqQixxQkFBcUIsRUFDckIsdUJBQXVCLEVBQ3ZCLGVBQWUsRUFDZixvQkFBb0IsRUFDcEIsc0JBQXNCLEVBQ3RCLFdBQVcsRUFDWCxhQUFhLEVBQ2IsYUFBYSxFQUNiLGFBQWEsRUFDYiwwQkFBMEIsRUFDMUIseUJBQXlCLEVBQ3pCLHNCQUFzQixFQUN0Qiw0QkFBNEIsRUFDNUIsd0JBQXdCLEVBQ3hCLG9CQUFvQixFQUNwQixrQkFBa0IsRUFDbEIsa0JBQWtCLEdBQ25CLE1BQU0sa0JBQWtCLENBQUMifQ==
@@ -73,8 +73,8 @@ WORKFLOW_EXPERIMENTAL_DYNAMIC_WORKFLOWS=1
73
73
 
74
74
  Only `1` or `true` (case-insensitive) enables them; any other value, or no value, leaves them off. The runtime reads the variable where workflows execute, when it needs it, so set it on the deployment or dev server rather than at build time. It controls three things:
75
75
 
76
- - **Starting.** `start()` with source throws before it contacts the World, creates a run, or enqueues anything unless this process has opted in.
77
- - **Delivery.** When a dynamic run reaches a deployment that has not opted in, the runtime does not execute its stored code. It fails the run with a `RUNTIME_ERROR` rather than retrying it.
76
+ - **Starting.** `start()` with source throws [`DynamicWorkflowsNotEnabledError`](/docs/api-reference/workflow-errors/dynamic-workflows-not-enabled-error) before it contacts the World, creates a run, or enqueues anything unless this process has opted in. The error is fatal, so a step that calls `start()` fails without retrying, and a run that fails on it is recorded as `USER_ERROR`.
77
+ - **Delivery.** When a dynamic run reaches a deployment that has not opted in, the runtime does not execute its stored code. It fails the run with `DynamicWorkflowsNotEnabledError` and a `USER_ERROR` code rather than retrying it.
78
78
  - **Health check.** A deployment advertises dynamic support in its [health check](/docs/api-reference/workflow-runtime/health-check) only when it has opted in.
79
79
 
80
80
  ### Same deployment only
@@ -268,6 +268,6 @@ async function workflow(input) {
268
268
 
269
269
  The return type is `Run<unknown>`: the source's shape is only known to whatever generated it, so there is nothing to infer. The workflow ID is derived from the source and its step bindings — it cannot be supplied.
270
270
 
271
- A dynamic start throws a `WorkflowRuntimeError`, before anything is written, when the deployment has not opted in, when `deploymentId` targets another deployment (including `'latest'` resolving to one), or when the World's backend does not support dynamic-source storage.
271
+ A dynamic start throws before anything is written when the deployment has not opted in ([`DynamicWorkflowsNotEnabledError`](/docs/api-reference/workflow-errors/dynamic-workflows-not-enabled-error)), and a `WorkflowRuntimeError` when `deploymentId` targets another deployment (including `'latest'` resolving to one) or when the World's backend does not support dynamic-source storage. Earlier releases threw `WorkflowRuntimeError` for the opt-in refusal too, so code that checked for it with `WorkflowRuntimeError.is()` should use `DynamicWorkflowsNotEnabledError.is()`.
272
272
 
273
273
  See [Dynamic Workflows](/docs/advanced/dynamic-workflows) for the opt-in, the source rules and limits, the predefined runtime bindings (`steps`, `sleep`, `createHook`), how the code is stored, and the security model.
@@ -0,0 +1,57 @@
1
+ ---
2
+ title: DynamicWorkflowsNotEnabledError
3
+ description: Thrown when a dynamic workflow is started or delivered on a deployment that has not enabled dynamic workflows.
4
+ type: reference
5
+ summary: Catch DynamicWorkflowsNotEnabledError when start() is given workflow source on a deployment without WORKFLOW_EXPERIMENTAL_DYNAMIC_WORKFLOWS=1.
6
+ related:
7
+ - /docs/advanced/dynamic-workflows
8
+ - /docs/api-reference/workflow-api/start
9
+ ---
10
+
11
+ `DynamicWorkflowsNotEnabledError` is thrown when your project has not enabled [dynamic workflows](/docs/advanced/dynamic-workflows):
12
+
13
+ - `start()` is given workflow source on a deployment that has not opted in. No run is created.
14
+ - A dynamic run is delivered to a deployment that has not opted in. Its stored code is not executed, and the run fails.
15
+
16
+ This is a configuration problem in your project, not an SDK error, so a run that fails on it is recorded with the `USER_ERROR` code. The error is fatal: a step that calls `start()` fails on the first attempt instead of retrying.
17
+
18
+ To fix it, set the `WORKFLOW_EXPERIMENTAL_DYNAMIC_WORKFLOWS=1` environment variable on your project, then redeploy (or restart your dev server) so the new value takes effect. See [Enabling dynamic workflows](/docs/advanced/dynamic-workflows#enabling-dynamic-workflows).
19
+
20
+ ```typescript lineNumbers
21
+ import { DynamicWorkflowsNotEnabledError } from "workflow/errors"
22
+ declare const error: unknown; // @setup
23
+
24
+ if (DynamicWorkflowsNotEnabledError.is(error)) { // [!code highlight]
25
+ console.error("Dynamic workflows are not enabled:", error.message);
26
+ }
27
+ ```
28
+
29
+ ## API signature
30
+
31
+ ### Properties
32
+
33
+ <TSDoc
34
+ definition={`
35
+ interface DynamicWorkflowsNotEnabledError {
36
+ /** Always true: retrying cannot succeed until the project opts in. */
37
+ fatal: true;
38
+ /** The error message, including how to enable dynamic workflows. */
39
+ message: string;
40
+ }
41
+ export default DynamicWorkflowsNotEnabledError;`}
42
+ />
43
+
44
+ ### Static methods
45
+
46
+ #### `DynamicWorkflowsNotEnabledError.is(value)`
47
+
48
+ Type-safe check for `DynamicWorkflowsNotEnabledError` instances. Preferred over `instanceof` because it works across module boundaries and virtual machine contexts.
49
+
50
+ ```typescript
51
+ import { DynamicWorkflowsNotEnabledError } from "workflow/errors"
52
+ declare const error: unknown; // @setup
53
+
54
+ if (DynamicWorkflowsNotEnabledError.is(error)) {
55
+ // error is typed as DynamicWorkflowsNotEnabledError
56
+ }
57
+ ```
@@ -54,6 +54,9 @@ All errors extend [`WorkflowError`](/docs/api-reference/workflow-errors/workflow
54
54
  <Card href="/docs/api-reference/workflow-errors/workflow-start-error" title="WorkflowStartError">
55
55
  Thrown when `start({ experimental_hook })` cannot confirm whether its run was queued or admitted.
56
56
  </Card>
57
+ <Card href="/docs/api-reference/workflow-errors/dynamic-workflows-not-enabled-error" title="DynamicWorkflowsNotEnabledError">
58
+ Thrown when a dynamic workflow is started or delivered on a deployment that has not enabled dynamic workflows.
59
+ </Card>
57
60
  <Card href="/docs/api-reference/workflow-errors/run-expired-error" title="RunExpiredError">
58
61
  Thrown when a workflow run has expired and can no longer be operated on.
59
62
  </Card>
@@ -13,6 +13,7 @@
13
13
  "workflow-run-not-completed-error",
14
14
  "workflow-runtime-error",
15
15
  "workflow-start-error",
16
+ "dynamic-workflows-not-enabled-error",
16
17
  "workflow-world-error",
17
18
  "throttle-error",
18
19
  "entity-conflict-error",
@@ -54,6 +54,7 @@ export default defineConfig({
54
54
  | `typescriptPlugin` | `boolean` | `false` | Adds the `workflow` TypeScript plugin to the generated `tsconfig.json` for integrated development environment (IDE) IntelliSense. |
55
55
  | `runtime` | `string` | — | Node.js runtime version for Vercel Functions (for example, `'nodejs22.x'` or `'nodejs24.x'`). Only applies when deploying to Vercel. |
56
56
  | `sourcemap` | `boolean \| 'inline' \| 'linked' \| 'external' \| 'both'` | `'inline'` (dev) / `false` (prod) | Controls source maps on generated workflow bundles. Accepts the same values as esbuild's `sourcemap` option. Defaults to `'inline'` in development and `false` in production (smaller function bundles, which helps stay under the Vercel 250 MB function size limit). Set it explicitly, or use the `WORKFLOW_SOURCEMAP` environment variable, to override in either environment. |
57
+ | `dashboard` | `boolean \| { enabled?: boolean; path?: string; allowedHosts?: string[] \| true }` | `true` (dev) / `false` (prod) | Embeds the observability web UI at `/_workflow` (or `path`). Never mounted on Vercel. `allowedHosts` lists host names the dashboard accepts besides `localhost`, `*.localhost`, and IP addresses; defaults to `WORKFLOW_WEB_ALLOWED_HOSTS`. |
57
58
 
58
59
  ## Vite-based Nitro
59
60
 
@@ -69,6 +69,12 @@ Whichever way they are resolved, the CLI ends up building a Vercel World from an
69
69
  - Default: `3456`
70
70
  - Port for the local web UI server.
71
71
 
72
+ ### `--webAllowedHosts`
73
+
74
+ - Environment variable: `WORKFLOW_WEB_ALLOWED_HOSTS`
75
+ - Default: none
76
+ - Comma-separated host names the local web UI accepts in the `Host` header, in addition to `localhost`, `*.localhost`, and IP addresses, which are always accepted. An entry starting with a dot (`.example.com`) matches the domain and all of its subdomains; `*` accepts any host name. Requests under any other host name are rejected with `403`, which protects the UI from DNS rebinding by web pages you visit. Set this when you reach the UI under a domain name, for example behind a reverse proxy or through a hostname on your network.
77
+
72
78
  ### `--noBrowser`
73
79
 
74
80
  - Environment variable: `WORKFLOW_DISABLE_BROWSER_OPEN`
@@ -184,6 +190,15 @@ per flag.
184
190
  - Default: disabled
185
191
  - Decrypts encrypted values. Triggers an audit-logged key retrieval.
186
192
 
193
+ ### `--usage`
194
+
195
+ - Command: `workflow inspect run <run-id>`
196
+ - Default: disabled
197
+ - Prints the run's [usage](/docs/observability/usage) instead of the run: its events by type, and its storage. With `--json`, prints the same numbers as JSON.
198
+ - Only the Local World counts usage; on other backends the command fails rather than printing the run.
199
+ - Cannot be combined with `--url`/`--web`, `--withData`, or `--decrypt`.
200
+ - Prints in color only to a terminal; output is plain text when piped, with `NO_COLOR` set, or with `TERM=dumb`.
201
+
187
202
  ## Bulk cancel
188
203
 
189
204
  `workflow cancel <run-id>` cancels one run. Given a filter instead, it bulk-cancels a batch; bulk mode requires `--status` or `--workflowName`.
@@ -216,7 +231,7 @@ per flag.
216
231
 
217
232
  ## Delete
218
233
 
219
- `workflow delete <runId>...` deletes the stored data of finished runs: their inputs, outputs and errors, their steps' and events' payloads, their hook payloads, and their stream contents. Metadata is not deleted: the runs, steps, events and hooks stay listed with their IDs, names, statuses, timestamps and attributes, and only the payloads read back as expired. This cannot be undone, so the command asks for confirmation unless you pass [`--confirm` / `-y`](#--confirm---y), and aborts without a terminal to ask on. Deleting run data is CLI-only: the [Web UI](#web-ui) doesn't offer it.
234
+ `workflow delete <runId>...` deletes the stored data of finished runs: their inputs, outputs and errors, their steps' and events' payloads, their hook payloads, and their stream contents. Metadata is not deleted: the runs, steps, events and hooks stay listed with their IDs, names, statuses, timestamps and attributes, and only the payloads read back as expired. This cannot be undone, so the command asks for confirmation unless you pass [`--confirm` / `-y`](#--confirm---y), and aborts without a terminal to ask on. The local [Web UI](#web-ui) doesn't offer it. For runs on Vercel, you can also delete run data from the [Vercel dashboard](https://vercel.com/docs/workflows/retention#delete-the-data-of-finished-runs).
220
235
 
221
236
  ```bash
222
237
  pnpx workflow delete <runId>
@@ -81,6 +81,12 @@ Configure Workflow through the Nitro `workflow` module options.
81
81
  - Default: `inline` in development, `false` in production
82
82
  - Controls source maps for generated workflow bundles.
83
83
 
84
+ ### `workflow.dashboard`
85
+
86
+ - Environment override: `WORKFLOW_WEB_ALLOWED_HOSTS` (for `allowedHosts`)
87
+ - Default: enabled in development, disabled in production builds, never mounted on Vercel
88
+ - Embeds the observability web UI in the Nitro server at `/_workflow`. Pass `true` or `false` to force it on or off, or an object `{ enabled, path, allowedHosts }`. `allowedHosts` lists host names the dashboard accepts in the `Host` header besides `localhost`, `*.localhost`, and IP addresses (`.example.com` matches the domain and its subdomains, `true` accepts any host); requests under any other name get a `403`. See [`--webAllowedHosts`](/docs/configuration/cli-and-web-ui#--weballowedhosts).
89
+
84
90
  ## NestJS
85
91
 
86
92
  Configure Workflow through `WorkflowModule.forRoot()`.
@@ -185,6 +185,15 @@ The Postgres World is a self-hosted durable backend for long-running server proc
185
185
  - Set to `true` only when the application awaits `world.close()` before closing its workflow HTTP server and caller-owned pool.
186
186
  - Prevents Graphile Worker's default handler from terminating the process before the application's remaining cleanup finishes.
187
187
 
188
+ ### `skipWorkers`
189
+
190
+ - Environment variable: `WORKFLOW_POSTGRES_SKIP_WORKERS` (`1` enables)
191
+ - Default: `false`
192
+ - Runs no workers in this process. It can still start runs, resume hooks, cancel runs and read them, but it claims none of the jobs those create and doesn't recover interrupted runs at startup.
193
+ - At least one process with workers must share the database, `jobPrefix` and, when one is set, `deploymentId`: it executes those runs. A run on a deployment ID no worker claims stays pending.
194
+ - A run this process created but didn't get to enqueue (it stopped in between) is recovered the next time a process with workers starts.
195
+ - Use it for processes that should send work but not execute it, such as those in a region far from the database. See [Postgres World: `WORKFLOW_POSTGRES_SKIP_WORKERS`](/worlds/postgres#workflow_postgres_skip_workers).
196
+
188
197
  ### `jobLockStaleSeconds`
189
198
 
190
199
  - Environment variable: `WORKFLOW_POSTGRES_JOB_LOCK_STALE_SECONDS`
@@ -15,7 +15,7 @@ When a workflow run fails, its `errorCode` identifies the failure category. You
15
15
 
16
16
  | Code | Description |
17
17
  | --- | --- |
18
- | `USER_ERROR` | An error thrown by workflow or step code, including an unhandled step failure or `FatalError`. |
18
+ | `USER_ERROR` | An error thrown by workflow or step code, including an unhandled step failure or `FatalError`, or a project configuration problem such as [`DynamicWorkflowsNotEnabledError`](/docs/api-reference/workflow-errors/dynamic-workflows-not-enabled-error). |
19
19
  | `RUNTIME_ERROR` | The Workflow runtime encountered an internal error, such as missing runtime data or an invariant failure. Persistent occurrences should be [reported](https://github.com/vercel/workflow/issues). |
20
20
  | [`CORRUPTED_EVENT_LOG`](/docs/errors/corrupted-event-log) | The run's event log cannot be replayed because it contains orphaned or mismatched events, a gap, or an unreadable stored payload. |
21
21
  | [`REPLAY_DIVERGENCE`](/docs/errors/replay-divergence) | One replay could not consume the event log deterministically. The runtime automatically retries before treating repeated divergence as a corrupted event log. |
@@ -63,7 +63,7 @@ If a run doesn't need to be a single long-lived run, start [child workflows](/co
63
63
 
64
64
  ### Fix unbounded loops
65
65
 
66
- If the run wasn't expected to grow this large, check the workflow function for loops that create steps, hooks, or sleeps without terminating.
66
+ If the run wasn't expected to grow this large, check the workflow function for loops that create steps, hooks, or sleeps without terminating. A run's [usage](/docs/observability/usage) shows which steps and hooks write its events.
67
67
 
68
68
  ## This error cannot be caught
69
69
 
@@ -10,7 +10,7 @@ related:
10
10
  ---
11
11
 
12
12
  <CopyPrompt
13
- text="In this NestJS app, run `npm i workflow @workflow/nest` and `npm i -D @swc/cli @swc/core`. Configure `nest-cli.json` with `compilerOptions.builder: &quot;swc&quot;` and `deleteOutDir: true`. Run `npx @workflow/nest init`, add `.swcrc` to `.gitignore`, and set package scripts `prebuild: &quot;npx @workflow/nest init --force&quot;` and `start:dev: &quot;npx @workflow/nest init --force && nest start --watch&quot;`. Import `WorkflowModule.forRoot()` from `@workflow/nest` in `src/app.module.ts` (use `{ moduleType: &quot;commonjs&quot;, distDir: &quot;dist&quot; }` if compiling CommonJS). Create `src/workflows/user-signup.ts` with `&quot;use workflow&quot;`, `sleep`, and `&quot;use step&quot;` helpers. Add a `POST /signup` controller method that reads `email`, calls `start(handleUserSignup, [email])` from `workflow/api`, and returns JSON. Run `npm run start:dev`, call `curl -X POST --json '{&quot;email&quot;:&quot;hello@example.com&quot;}' http://localhost:3000/signup`, and inspect with `npx workflow web` or `npx workflow inspect runs`."
13
+ text="In this NestJS app, run `npm i workflow @workflow/nest` and `npm i -D @swc/cli @swc/core@~1.15.18`. Configure `nest-cli.json` with `compilerOptions.builder: &quot;swc&quot;` and `deleteOutDir: true`. Run `npx @workflow/nest init`, add `.swcrc` to `.gitignore`, and set package scripts `prebuild: &quot;npx @workflow/nest init --force&quot;` and `start:dev: &quot;npx @workflow/nest init --force && nest start --watch&quot;`. Import `WorkflowModule.forRoot()` from `@workflow/nest` in `src/app.module.ts` (use `{ moduleType: &quot;commonjs&quot;, distDir: &quot;dist&quot; }` if compiling CommonJS). Create `src/workflows/user-signup.ts` with `&quot;use workflow&quot;`, `sleep`, and `&quot;use step&quot;` helpers. Add a `POST /signup` controller method that reads `email`, calls `start(handleUserSignup, [email])` from `workflow/api`, and returns JSON. Run `npm run start:dev`, call `curl -X POST --json '{&quot;email&quot;:&quot;hello@example.com&quot;}' http://localhost:3000/signup`, and inspect with `npx workflow web` or `npx workflow inspect runs`."
14
14
  />
15
15
 
16
16
  Set up your first durable workflow in a NestJS app and learn the core Workflow SDK concepts.
@@ -92,12 +92,14 @@ export class AppModule {}
92
92
 
93
93
  NestJS supports SWC as an alternative compiler for faster builds. The Workflow SDK uses an SWC plugin to transform workflow files.
94
94
 
95
- Install the required SWC packages:
95
+ Install the required SWC packages. `@swc/core` is pinned to 1.15.x because the Workflow SWC plugin does not run on `@swc/core` 1.16 yet:
96
96
 
97
97
  ```package-install
98
- npm i -D @swc/cli @swc/core
98
+ npm i -D @swc/cli @swc/core@~1.15.18
99
99
  ```
100
100
 
101
+ Don't upgrade `@swc/core` past 1.15 (for example with `pnpm update --latest`, Dependabot or Renovate) until the Workflow SWC plugin supports 1.16; `npx @workflow/nest init` warns if the installed version isn't 1.15.x.
102
+
101
103
  Ensure your `nest-cli.json` has SWC as the builder:
102
104
 
103
105
  ```json title="nest-cli.json" lineNumbers
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "title": "Observability",
3
- "pages": ["tracing", "attributes", "retention", "lifecycle-hooks"]
3
+ "pages": ["tracing", "attributes", "retention", "usage", "lifecycle-hooks"]
4
4
  }
@@ -59,7 +59,8 @@ error; the payloads on the event log; and stream contents.
59
59
  status, step names, and any [attributes](/docs/observability/attributes) you
60
60
  set. They are kept for the World's default period so the run stays visible in
61
61
  the CLI and web UI. A purged run is still listed and still traceable; its
62
- payloads simply read back as expired.
62
+ payloads simply read back as expired. Its [usage](/docs/observability/usage)
63
+ still reports what it wrote.
63
64
 
64
65
  Inspecting a purged run shows it as expired rather than failing. The Workflow
65
66
  CLI renders the run's own input, output and error as `<data expired>`:
@@ -0,0 +1,83 @@
1
+ ---
2
+ title: Usage
3
+ description: See where a run's events come from and how much it stores.
4
+ type: reference
5
+ summary: See a run's events, by step and hook, and its storage, counted the way Vercel bills them.
6
+ prerequisites:
7
+ - /docs/foundations/workflows-and-steps
8
+ related:
9
+ - /docs/observability
10
+ - /docs/observability/retention
11
+ ---
12
+
13
+ A run's usage shows where its events come from (which steps and hooks drive them) and how much it stores, counted the way Vercel bills them, so you can estimate a workflow's cost before you deploy it. Usage is available on the Local World.
14
+
15
+ ## See a run's usage
16
+
17
+ ```bash
18
+ npx workflow inspect run <run_id> --usage
19
+ ```
20
+
21
+ ```
22
+ processOrder wrun_01M7V5GYES4PYRWR5STNZ6G5ME ● completed
23
+
24
+ Events 19
25
+ Storage (local) 3.52 KB
26
+
27
+ TYPE NAME EVENTS SHARE
28
+ Steps 3 calls ↻ 1 retry 11 58% ██████░░░░
29
+ ├─ sendEmail 2 calls 6 32% ███░░░░░░░
30
+ └─ chargeCard 1 call ↻ 1 retry 5 26% ███░░░░░░░
31
+ Hooks 1 hook 3 16% ██░░░░░░░░
32
+ └─ approval:order-1042 3 16% ██░░░░░░░░
33
+ Sleeps 1 sleep 2 11% █░░░░░░░░░
34
+ Run 3 16% ██░░░░░░░░
35
+ TOTAL 19 100%
36
+
37
+ How usage is counted: https://workflow-sdk.dev/docs/observability/usage
38
+
39
+ STORAGE (LOCAL) SIZE
40
+ Run 500 B
41
+ Steps 2.82 KB
42
+ Hooks 200 B
43
+ TOTAL 3.52 KB
44
+
45
+ Local runs aren't billed. Counted from this run's log in your local data directory.
46
+ Machine-readable: --json
47
+ ```
48
+
49
+ In the web UI, a run's header shows its **Events** and **Storage (local)**. Select either one, or the run's **Usage** tab, to open its Usage page (`/run/<run_id>/usage`), which shows the same table.
50
+
51
+ `--json` prints the same numbers as JSON. Its shape is experimental and may change.
52
+
53
+ The output includes hook tokens, and a token resumes its hook. Share it, `--json` included, only where you would share the run's data.
54
+
55
+ ## What's counted
56
+
57
+ ### Events
58
+
59
+ Every event in the run's log counts once. [Event sourcing](/docs/how-it-works/event-sourcing) describes which events a run, its steps, hooks and sleeps write.
60
+
61
+ ### Storage
62
+
63
+ **Storage (local)** counts the bytes of the run's payloads as the SDK sent them (compressed when that saves space, and encrypted when encryption is on): run inputs and outputs, step inputs and results, errors, and hook metadata and payloads. It adds the bytes the run wrote to its streams. Event metadata, such as ids and timestamps, isn't counted. A run started with `experimental_retention: 0` reports what it wrote before its data was deleted.
64
+
65
+ When a run's data is deleted, its sizes stay in the local data directory, so usage can still report them.
66
+
67
+ Two kinds of data aren't counted locally:
68
+
69
+ - **QuickJS VM snapshots.**
70
+ - **A dynamic workflow's code.**
71
+
72
+ The numbers describe this run. The same workflow can record a different number of events on another run, for example with more or fewer retries.
73
+
74
+ ## On Vercel
75
+
76
+ A run's events are its Workflow Events, and **Storage (local)** is counted the way Data Written is, except that Data Written also includes QuickJS VM snapshots and a dynamic workflow's code. Usage doesn't show Data Retained, function compute, or queues; see [Workflow pricing](https://vercel.com/docs/workflows/pricing), and open a run on the Workflows page in the [Vercel dashboard](https://vercel.com/dashboard) for what it was billed.
77
+
78
+ ## Reduce a run's usage
79
+
80
+ - [Batching](/cookbook/common-patterns/batching)
81
+ - [Child workflows](/cookbook/advanced/child-workflows)
82
+ - [QuickJS runtime](/docs/advanced/quickjs-runtime)
83
+ - [Data retention](/docs/observability/retention)
@@ -30,6 +30,8 @@ npx workflow inspect runs
30
30
  npx workflow web
31
31
  ```
32
32
 
33
+ `npx workflow inspect run <run_id> --usage` shows where a run's events come from and how much it stores; see [Usage](/docs/observability/usage).
34
+
33
35
  Learn more in the [Observability](/docs/observability) documentation.
34
36
 
35
37
  ## Testing & compatibility
@@ -226,7 +226,7 @@ The package includes a Helm chart for Kubernetes in its `chart` directory, and t
226
226
 
227
227
  - **Workers per version.** Each release gets a worker Deployment that runs only the runs it started. A rollout leaves the previous release's workers in place.
228
228
  - **Scale to zero.** KEDA scales each version's workers on its due deliveries, which the application reports through `createBacklogEndpoints`. Workers drop to zero while that version's runs sleep or wait on a hook.
229
- - **Pruning.** A CronJob deletes a version's workers once all its runs have finished, and recreates them for a version that still has unfinished runs.
229
+ - **Pruning.** A CronJob deletes a version's workers once all its runs have finished, and recreates them for a version that still has unfinished runs. A run with `experimental_retention: 0` counts as unfinished until its data deletion is confirmed, about a minute after it ends.
230
230
  - **Graceful shutdown.** `createLifecycle` stops a pod from receiving traffic, then lets its running deliveries finish before it exits.
231
231
  - **Migrations.** An optional init container runs `bootstrap` before each pod starts.
232
232
 
@@ -309,6 +309,7 @@ The defaults work for a single process on a local database, so most apps set onl
309
309
  | [`WORKFLOW_POSTGRES_POLL_INTERVAL_MS`](#workflow_postgres_poll_interval_ms) | `500` ms | Idle job polling |
310
310
  | [`WORKFLOW_POSTGRES_MAX_POOL_SIZE`](#workflow_postgres_max_pool_size) | `10` | Connection pool size |
311
311
  | [`WORKFLOW_POSTGRES_APPLICATION_MANAGED_SHUTDOWN`](#workflow_postgres_application_managed_shutdown) | off | Who coordinates shutdown |
312
+ | [`WORKFLOW_POSTGRES_SKIP_WORKERS`](#workflow_postgres_skip_workers) | off | Send work without executing it |
312
313
  | [`WORKFLOW_POSTGRES_HEADERS_TIMEOUT_MS`](#workflow_postgres_headers_timeout_ms) | `0` ms (no deadline) | Hung delivery detection |
313
314
  | [`WORKFLOW_POSTGRES_BODY_TIMEOUT_MS`](#workflow_postgres_body_timeout_ms) | `0` ms (no deadline) | Stalled response detection |
314
315
  | [`WORKFLOW_POSTGRES_JOB_LOCK_STALE_SECONDS`](#workflow_postgres_job_lock_stale_seconds) | unset: 300 s for spec 9 run-lease jobs only | Redelivery after a process dies |
@@ -403,6 +404,17 @@ Whether the application, instead of Graphile Worker, coordinates shutdown. Set t
403
404
 
404
405
  Change it when: the application or framework coordinates shutdown and awaits `world.close()` before closing its workflow HTTP server and any caller-owned pool. See [Application-managed shutdown](#application-managed-shutdown).
405
406
 
407
+ ### `WORKFLOW_POSTGRES_SKIP_WORKERS`
408
+
409
+ - Default: unset (`false`)
410
+ - Factory option: `skipWorkers`
411
+
412
+ Runs no workers in this process. Set to `1` to enable. The process can still start runs, resume hooks, cancel runs and read them, but it claims none of the jobs those create, and it doesn't recover interrupted runs at startup.
413
+
414
+ Its runs execute on processes with workers on the same database, `WORKFLOW_POSTGRES_JOB_PREFIX` and, when one is set, `WORKFLOW_POSTGRES_DEPLOYMENT_ID`, so at least one must be running. A run on a deployment ID that no worker claims stays pending. A run this process created but didn't get to enqueue (it stopped in between) is recovered the next time a process with workers starts. At startup the process logs the job prefix and deployment ID its runs need.
415
+
416
+ Change it when: some processes should send work without executing it, for example application instances in a region far from the database, whose step executions would wait on many cross-region round trips. Run the workers near the database.
417
+
406
418
  ### `WORKFLOW_POSTGRES_HEADERS_TIMEOUT_MS`
407
419
 
408
420
  - Default: `0` (no deadline)
@@ -137,6 +137,8 @@ Retention for the Vercel World is documented in the [Vercel Workflows docs](http
137
137
 
138
138
  To delete a run's payloads as soon as it finishes, start it with [`experimental_retention: 0`](/docs/observability/retention).
139
139
 
140
+ To delete the payloads of runs that have already finished, call [`run.delete()`](/docs/api-reference/workflow-api/get-run#delete-a-finished-runs-data) or [`deleteRuns()`](/docs/api-reference/workflow-api/delete-runs), run [`workflow delete`](/docs/configuration/cli-and-web-ui#delete), or select **Delete Data** in the Vercel dashboard.
141
+
140
142
  ## Queue consumers other than the Workflow SDK
141
143
 
142
144
  The Vercel World delivers each queue message to the functions subscribed to its topic, not to a fixed path. The Workflow SDK's build integration subscribes the generated flow route to `__wkf_workflow_*` (or `__{namespace}_wkf_workflow_*`). A library that consumes messages of its own on the same World, such as a durable agent harness, uses its own queue prefix and subscribes its own route to that prefix's topics:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "workflow",
3
- "version": "5.7.0",
3
+ "version": "5.7.2",
4
4
  "description": "Workflow SDK - Build durable, resilient, and observable workflows",
5
5
  "main": "dist/typescript-plugin.cjs",
6
6
  "type": "module",
@@ -60,19 +60,19 @@
60
60
  }
61
61
  },
62
62
  "dependencies": {
63
- "@workflow/astro": "5.0.12",
64
- "@workflow/cli": "5.3.0",
65
- "@workflow/core": "5.7.0",
66
- "@workflow/errors": "5.1.4",
63
+ "@workflow/astro": "5.0.14",
64
+ "@workflow/cli": "5.3.2",
65
+ "@workflow/core": "5.7.2",
66
+ "@workflow/errors": "5.1.6",
67
67
  "@workflow/typescript-plugin": "5.0.1",
68
68
  "@workflow/utils": "5.1.1",
69
69
  "ms": "2.1.3",
70
- "@workflow/next": "5.1.3",
71
- "@workflow/nest": "5.1.10",
72
- "@workflow/nitro": "5.0.12",
73
- "@workflow/nuxt": "5.0.12",
74
- "@workflow/sveltekit": "5.0.12",
75
- "@workflow/rollup": "5.0.12"
70
+ "@workflow/next": "5.1.5",
71
+ "@workflow/nest": "5.1.12",
72
+ "@workflow/nitro": "5.0.14",
73
+ "@workflow/nuxt": "5.0.14",
74
+ "@workflow/sveltekit": "5.0.14",
75
+ "@workflow/rollup": "5.0.14"
76
76
  },
77
77
  "devDependencies": {
78
78
  "@types/ms": "2.1.0",