workflow 5.6.1 → 5.7.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-workflow.d.ts +2 -1
- package/dist/api-workflow.js +2 -1
- package/dist/api.d.ts +2 -1
- package/dist/api.js +2 -1
- package/docs/advanced/meta.json +1 -1
- package/docs/advanced/quickjs-runtime.mdx +77 -0
- package/docs/api-reference/workflow-api/delete-runs.mdx +57 -0
- package/docs/api-reference/workflow-api/get-run.mdx +33 -0
- package/docs/api-reference/workflow-api/index.mdx +3 -0
- package/docs/api-reference/workflow-runtime/world/storage.mdx +2 -0
- package/docs/configuration/cli-and-web-ui.mdx +29 -2
- package/docs/configuration/runtime-tuning.mdx +14 -12
- package/docs/errors/max-events-exceeded.mdx +0 -1
- package/docs/observability/retention.mdx +44 -0
- package/docs/worlds/postgres.mdx +15 -1
- package/package.json +11 -11
package/dist/api-workflow.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
export type { CancelRunOptions, Event, StartOptions, StopSleepOptions, StopSleepResult, WorkflowReadableStreamOptions, WorkflowRun, WorkflowRunWritableStreamOptions, } from '@workflow/core/runtime';
|
|
1
|
+
export type { CancelRunOptions, DeleteRunDataResult, DeleteRunsDataResult, Event, StartOptions, StopSleepOptions, StopSleepResult, WorkflowReadableStreamOptions, WorkflowRun, WorkflowRunWritableStreamOptions, } from '@workflow/core/runtime';
|
|
2
2
|
export { Run } from '@workflow/core/runtime/run';
|
|
3
3
|
export { start } from '@workflow/core/runtime/start';
|
|
4
4
|
export declare const getRun: () => never;
|
|
5
|
+
export declare const deleteRuns: () => never;
|
|
5
6
|
export declare const getHookByToken: () => never;
|
|
6
7
|
export declare const resumeHook: () => never;
|
|
7
8
|
export declare const resumeWebhook: () => never;
|
package/dist/api-workflow.js
CHANGED
|
@@ -4,6 +4,7 @@ const workflowStub = (item) => {
|
|
|
4
4
|
throw new Error(`The workflow environment doesn't allow this runtime usage of ${item}. Move this call to a step function ("use step") or call it outside the workflow context.`);
|
|
5
5
|
};
|
|
6
6
|
export const getRun = () => workflowStub('getRun');
|
|
7
|
+
export const deleteRuns = () => workflowStub('deleteRuns');
|
|
7
8
|
export const getHookByToken = () => workflowStub('getHookByToken');
|
|
8
9
|
export const resumeHook = () => workflowStub('resumeHook');
|
|
9
10
|
export const resumeWebhook = () => workflowStub('resumeWebhook');
|
|
@@ -11,4 +12,4 @@ export const runStep = () => workflowStub('runStep');
|
|
|
11
12
|
export const registerLifecycleHooks = () => {
|
|
12
13
|
throw new Error('registerLifecycleHooks must be called at host startup, not inside a workflow or step function. Register before handling workflow requests (for example, in instrumentation.ts on Next.js).');
|
|
13
14
|
};
|
|
14
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
15
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXBpLXdvcmtmbG93LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL2FwaS13b3JrZmxvdy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFhQSxPQUFPLEVBQUUsR0FBRyxFQUFFLE1BQU0sNEJBQTRCLENBQUM7QUFDakQsT0FBTyxFQUFFLEtBQUssRUFBRSxNQUFNLDhCQUE4QixDQUFDO0FBRXJELE1BQU0sWUFBWSxHQUFHLENBQUMsSUFBWSxFQUFFLEVBQUU7SUFDcEMsTUFBTSxJQUFJLEtBQUssQ0FDYixnRUFBZ0UsSUFBSSwyRkFBMkYsQ0FDaEssQ0FBQztBQUNKLENBQUMsQ0FBQztBQUVGLE1BQU0sQ0FBQyxNQUFNLE1BQU0sR0FBRyxHQUFHLEVBQUUsQ0FBQyxZQUFZLENBQUMsUUFBUSxDQUFDLENBQUM7QUFDbkQsTUFBTSxDQUFDLE1BQU0sVUFBVSxHQUFHLEdBQUcsRUFBRSxDQUFDLFlBQVksQ0FBQyxZQUFZLENBQUMsQ0FBQztBQUMzRCxNQUFNLENBQUMsTUFBTSxjQUFjLEdBQUcsR0FBRyxFQUFFLENBQUMsWUFBWSxDQUFDLGdCQUFnQixDQUFDLENBQUM7QUFDbkUsTUFBTSxDQUFDLE1BQU0sVUFBVSxHQUFHLEdBQUcsRUFBRSxDQUFDLFlBQVksQ0FBQyxZQUFZLENBQUMsQ0FBQztBQUMzRCxNQUFNLENBQUMsTUFBTSxhQUFhLEdBQUcsR0FBRyxFQUFFLENBQUMsWUFBWSxDQUFDLGVBQWUsQ0FBQyxDQUFDO0FBQ2pFLE1BQU0sQ0FBQyxNQUFNLE9BQU8sR0FBRyxHQUFHLEVBQUUsQ0FBQyxZQUFZLENBQUMsU0FBUyxDQUFDLENBQUM7QUFDckQsTUFBTSxDQUFDLE1BQU0sc0JBQXNCLEdBQUcsR0FBRyxFQUFFO0lBQ3pDLE1BQU0sSUFBSSxLQUFLLENBQ2IsNExBQTRMLENBQzdMLENBQUM7QUFDSixDQUFDLENBQUMifQ==
|
package/dist/api.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import '@workflow/core/runtime/world-init';
|
|
2
|
-
export type { CancelRunOptions, Event, StopSleepOptions, StopSleepResult, WorkflowRun, } from '@workflow/core/runtime';
|
|
2
|
+
export type { CancelRunOptions, DeleteRunDataResult, DeleteRunsDataResult, Event, StopSleepOptions, StopSleepResult, WorkflowRun, } from '@workflow/core/runtime';
|
|
3
|
+
export { deleteRuns } from '@workflow/core/runtime/delete-runs';
|
|
3
4
|
export { type RunCompletedHookParams, type RunFailedHookParams, registerLifecycleHooks, type WorkflowLifecycleHooks, } from '@workflow/core/runtime/lifecycle-hooks';
|
|
4
5
|
export { getHookByToken, type Hook, type ResumedHook, resumeHook, resumeWebhook, } from '@workflow/core/runtime/resume-hook';
|
|
5
6
|
export { getRun, Run, type WorkflowReadableStream, type WorkflowReadableStreamOptions, type WorkflowRunWritableStreamOptions, } from '@workflow/core/runtime/run';
|
package/dist/api.js
CHANGED
|
@@ -6,8 +6,9 @@
|
|
|
6
6
|
// stays host-only.
|
|
7
7
|
// See `@workflow/core/src/runtime/world-init.ts` for the full rationale.
|
|
8
8
|
import '@workflow/core/runtime/world-init';
|
|
9
|
+
export { deleteRuns } from '@workflow/core/runtime/delete-runs';
|
|
9
10
|
export { registerLifecycleHooks, } from '@workflow/core/runtime/lifecycle-hooks';
|
|
10
11
|
export { getHookByToken, resumeHook, resumeWebhook, } from '@workflow/core/runtime/resume-hook';
|
|
11
12
|
export { getRun, Run, } from '@workflow/core/runtime/run';
|
|
12
13
|
export { start, } from '@workflow/core/runtime/start';
|
|
13
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
14
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXBpLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL2FwaS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxxRUFBcUU7QUFDckUseUVBQXlFO0FBQ3pFLDJFQUEyRTtBQUMzRSw0RUFBNEU7QUFDNUUsNkVBQTZFO0FBQzdFLG1CQUFtQjtBQUNuQix5RUFBeUU7QUFDekUsT0FBTyxtQ0FBbUMsQ0FBQztBQVczQyxPQUFPLEVBQUUsVUFBVSxFQUFFLE1BQU0sb0NBQW9DLENBQUM7QUFDaEUsT0FBTyxFQUdMLHNCQUFzQixHQUV2QixNQUFNLHdDQUF3QyxDQUFDO0FBQ2hELE9BQU8sRUFDTCxjQUFjLEVBR2QsVUFBVSxFQUNWLGFBQWEsR0FDZCxNQUFNLG9DQUFvQyxDQUFDO0FBQzVDLE9BQU8sRUFDTCxNQUFNLEVBQ04sR0FBRyxHQUlKLE1BQU0sNEJBQTRCLENBQUM7QUFDcEMsT0FBTyxFQU1MLEtBQUssR0FDTixNQUFNLDhCQUE4QixDQUFDIn0=
|
package/docs/advanced/meta.json
CHANGED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: QuickJS Runtime
|
|
3
|
+
description: Keep long-running workflows fast by resuming from a saved snapshot instead of replaying every event.
|
|
4
|
+
type: guide
|
|
5
|
+
summary: Run workflow functions on the QuickJS runtime with snapshotting so resume cost stays flat and runs are exempt from the per-run event limit.
|
|
6
|
+
prerequisites:
|
|
7
|
+
- /docs/how-it-works/event-sourcing
|
|
8
|
+
related:
|
|
9
|
+
- /docs/configuration/runtime-tuning#workflow_vm
|
|
10
|
+
- /docs/errors/max-events-exceeded
|
|
11
|
+
- /docs/errors/replay-timeout
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
Every time a workflow resumes, it re-executes from the top and replays its [event log](/docs/how-it-works/event-sourcing) to get back to where it left off. That takes milliseconds for most runs. For agents, chat sessions, and loops that run for days, the log keeps growing, so each resume gets slower and the run eventually fails with [`MAX_EVENTS_EXCEEDED`](/docs/errors/max-events-exceeded) or [`REPLAY_TIMEOUT`](/docs/errors/replay-timeout).
|
|
15
|
+
|
|
16
|
+
The QuickJS runtime fixes this. It runs your workflow functions in a [QuickJS](https://github.com/quickjs-ng/quickjs) VM instead of the default `node:vm` context and, once a run has processed 1,000 events, saves the VM's memory when the run suspends. The next resume restores that snapshot and replays only the events recorded since, so resume cost stays roughly flat however long the run gets. Runs on the QuickJS runtime with snapshotting are also exempt from the default per-run event limit.
|
|
17
|
+
|
|
18
|
+
Step functions are not affected. They always run with full Node.js access.
|
|
19
|
+
|
|
20
|
+
## Enable it
|
|
21
|
+
|
|
22
|
+
Set `WORKFLOW_VM=quickjs` in the environment that starts runs, which is the process that calls [`start()`](/docs/api-reference/workflow-api/start):
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
WORKFLOW_VM=quickjs
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Snapshotting is on by default under QuickJS, so that is the only variable you need. See [Tuning](#tuning) to change how often a run snapshots.
|
|
29
|
+
|
|
30
|
+
<Callout type="info">
|
|
31
|
+
The exemption from the per-run event limit needs `workflow` 5.2.3 or later. Earlier versions snapshot the same way, but only record the snapshot policy on the run when you also set `WORKFLOW_SNAPSHOT_THRESHOLD`.
|
|
32
|
+
</Callout>
|
|
33
|
+
|
|
34
|
+
Only runs started after the change use the QuickJS runtime. A run keeps the VM and snapshot policy it started with, so runs already in progress are not changed, and a run that already failed is not revived. Start it again.
|
|
35
|
+
|
|
36
|
+
The setting applies to every workflow the process starts.
|
|
37
|
+
|
|
38
|
+
### World support
|
|
39
|
+
|
|
40
|
+
Snapshots are stored by your World, next to the run's event log:
|
|
41
|
+
|
|
42
|
+
| World | Snapshots | Notes |
|
|
43
|
+
| --- | --- | --- |
|
|
44
|
+
| Vercel World | Encrypted | Each run has an encryption key, and its snapshots are encrypted and authenticated with it. |
|
|
45
|
+
| Local World, Postgres World | Plaintext | Runs have no encryption key, so snapshots are stored the same way as the event log and payloads. Protect snapshot storage like the rest of the World's storage. |
|
|
46
|
+
| Other Worlds | Depends on the World | A World that implements snapshot storage snapshots by default, encrypted when it provides a run encryption key. Without snapshot storage, runs still execute on QuickJS and replay the full log on every resume. |
|
|
47
|
+
|
|
48
|
+
The exemption from the per-run event limit applies on the Local World and the Vercel World.
|
|
49
|
+
|
|
50
|
+
## Check your workflow code first
|
|
51
|
+
|
|
52
|
+
QuickJS does not provide a few globals inside workflow functions. If your workflow functions use any of these, move the call into a step:
|
|
53
|
+
|
|
54
|
+
| Not available in workflow functions | What to do |
|
|
55
|
+
| --- | --- |
|
|
56
|
+
| `Intl.*`, and `toLocaleString()`-style methods called with an explicit locale | Format in a step |
|
|
57
|
+
| `crypto.subtle.*`, including `digest` | Hash or sign in a step |
|
|
58
|
+
| `WebAssembly`, `Atomics` | Use them in a step |
|
|
59
|
+
|
|
60
|
+
`crypto.randomUUID()` and `crypto.getRandomValues()` still work and stay deterministic. See [`WORKFLOW_VM`](/docs/configuration/runtime-tuning#workflow_vm) for the full list.
|
|
61
|
+
|
|
62
|
+
## Tuning
|
|
63
|
+
|
|
64
|
+
Snapshotting needs no configuration. To change how often a run snapshots, set `WORKFLOW_SNAPSHOT_THRESHOLD`. This is the same entry as on the [Runtime tuning](/docs/configuration/runtime-tuning#workflow_snapshot_threshold) page:
|
|
65
|
+
|
|
66
|
+
<include>../configuration/runtime-tuning.mdx#workflow_snapshot_threshold</include>
|
|
67
|
+
|
|
68
|
+
## On Vercel
|
|
69
|
+
|
|
70
|
+
Add `WORKFLOW_VM=quickjs` to your project's environment variables, then redeploy. You can add it in two ways:
|
|
71
|
+
|
|
72
|
+
- **From a run.** When a run fails at the event limit, times out while replaying, or passes 20,000 events, its page in the Workflows observability tab shows an **Optimize Long Runs** button. It adds the variable to Production and prompts you to redeploy.
|
|
73
|
+
- **From project settings.** Open **Settings**, then **Environment Variables**, add the variable, and redeploy.
|
|
74
|
+
|
|
75
|
+
Runs on Vercel keep executing on the deployment they started on, so the redeploy does not affect runs in progress.
|
|
76
|
+
|
|
77
|
+
For every setting and what a snapshot contains, see [Runtime tuning](/docs/configuration/runtime-tuning#workflow-vm-engine).
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: deleteRuns
|
|
3
|
+
description: Delete the stored data of finished workflow runs in one call.
|
|
4
|
+
type: reference
|
|
5
|
+
summary: Use deleteRuns to delete the inputs, outputs, streams, and hook payloads of up to 100 finished runs.
|
|
6
|
+
related:
|
|
7
|
+
- /docs/observability/retention
|
|
8
|
+
- /docs/api-reference/workflow-api/get-run
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
Deletes the stored data of up to 100 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 stay listed, and so do their steps, events and hooks, with their IDs, names, statuses, timestamps and attributes. Only the payloads go, reading back as expired. This cannot be undone. See [Data retention](/docs/observability/retention#deleting-a-finished-runs-data).
|
|
12
|
+
|
|
13
|
+
For a single run, call [`run.delete()`](/docs/api-reference/workflow-api/get-run#delete-a-finished-runs-data) instead.
|
|
14
|
+
|
|
15
|
+
{/* @skip-typecheck: abbreviated usage; the run IDs are the reader's own */}
|
|
16
|
+
```typescript lineNumbers
|
|
17
|
+
import { deleteRuns } from "workflow/api";
|
|
18
|
+
|
|
19
|
+
const { summary, results } = await deleteRuns([runIdA, runIdB]); // [!code highlight]
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
`deleteRuns()` never cancels a run: a run that hasn't finished is answered `skipped` and keeps running. Cancel it first to delete its data now.
|
|
23
|
+
|
|
24
|
+
## API signature
|
|
25
|
+
|
|
26
|
+
### Parameters
|
|
27
|
+
|
|
28
|
+
<TSDoc
|
|
29
|
+
definition={`
|
|
30
|
+
import { deleteRuns } from "workflow/api";
|
|
31
|
+
export default deleteRuns;`}
|
|
32
|
+
showSections={["parameters"]}
|
|
33
|
+
/>
|
|
34
|
+
|
|
35
|
+
### Returns
|
|
36
|
+
|
|
37
|
+
A summary that counts each outcome, and one result per run in the order of `runIds`. Each result has one of these outcomes:
|
|
38
|
+
|
|
39
|
+
| Outcome | Meaning |
|
|
40
|
+
| --- | --- |
|
|
41
|
+
| `deleted` | The run's data was deleted. |
|
|
42
|
+
| `already_deleted` | The run's data was already gone, from an earlier deletion or `experimental_retention: 0`. |
|
|
43
|
+
| `skipped` | The run hasn't finished, so nothing was deleted. `status` is the run's status. |
|
|
44
|
+
| `not_created` | The run was cancelled before it was created. What it held is deleted. |
|
|
45
|
+
| `not_found` | No run has this ID. |
|
|
46
|
+
| `failed` | The deletion didn't complete. `code` says why, and `retryable` says whether retrying can succeed. |
|
|
47
|
+
|
|
48
|
+
## Retries
|
|
49
|
+
|
|
50
|
+
Deletion is idempotent, so retrying is always safe: a run that was already handled answers `already_deleted`.
|
|
51
|
+
|
|
52
|
+
- Inside a step, runs answered `failed` with `retryable: true` are sent again once, on their own, a second later. If any still fail, or the World rate-limits a request, it throws a [`RetryableError`](/docs/api-reference/workflow/retryable-error) so the step retries the whole batch, after the World's requested delay, or 10 seconds when it gives none.
|
|
53
|
+
- Outside a step, `failed` results are returned as they are, so retry the runs answered `failed` with `retryable: true` yourself. A rate limit throws the World's `ThrottleError`, whose `retryAfter` is the number of seconds to wait.
|
|
54
|
+
|
|
55
|
+
## Errors
|
|
56
|
+
|
|
57
|
+
`deleteRuns()` throws when `runIds` is empty, contains duplicates, or has more than 100 IDs, and when the configured World doesn't support deleting run data. Send more runs in batches of 100. The World enforces the same limit.
|
|
@@ -199,6 +199,39 @@ export async function POST(req: Request) {
|
|
|
199
199
|
|
|
200
200
|
The options object is optional: `await run.cancel()` cancels the run without recording a reason.
|
|
201
201
|
|
|
202
|
+
### Delete a finished run's data
|
|
203
|
+
|
|
204
|
+
Delete the stored data of a run that has finished: its input, output and error, its steps' and events' payloads, its hook payloads, and its stream contents. Metadata is not deleted: the run stays listed, and so do its steps, events and hooks, with their IDs, names, statuses, timestamps and attributes. Only the payloads go, reading back as expired. This cannot be undone. See [Data retention](/docs/observability/retention#deleting-a-finished-runs-data).
|
|
205
|
+
|
|
206
|
+
```typescript lineNumbers
|
|
207
|
+
import { getRun } from "workflow/api";
|
|
208
|
+
|
|
209
|
+
export async function POST(req: Request) {
|
|
210
|
+
const { runId } = await req.json();
|
|
211
|
+
|
|
212
|
+
const result = await getRun(runId).delete(); // [!code highlight]
|
|
213
|
+
switch (result.outcome) {
|
|
214
|
+
case "deleted":
|
|
215
|
+
case "already_deleted":
|
|
216
|
+
case "not_created":
|
|
217
|
+
return Response.json({ deleted: true });
|
|
218
|
+
case "skipped":
|
|
219
|
+
// The run hasn't finished. Cancel it first to delete its data now.
|
|
220
|
+
return Response.json({ deleted: false, status: result.status }, { status: 409 });
|
|
221
|
+
case "not_found":
|
|
222
|
+
return Response.json({ deleted: false }, { status: 404 });
|
|
223
|
+
case "failed":
|
|
224
|
+
// Deletion is idempotent: a retryable failure can be requested again.
|
|
225
|
+
return Response.json(
|
|
226
|
+
{ deleted: false, retryable: result.retryable },
|
|
227
|
+
{ status: 503 }
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
`delete()` never cancels a run: a run that hasn't finished answers `skipped` and keeps running. It runs as a step, so inside a workflow a retryable failure throws a `RetryableError` and the step retries. It throws if the configured World doesn't support deleting run data. To delete the data of many runs in one call, use [`deleteRuns()`](/docs/api-reference/workflow-api/delete-runs).
|
|
234
|
+
|
|
202
235
|
## Related functions
|
|
203
236
|
|
|
204
237
|
- [`start()`](/docs/api-reference/workflow-api/start): Start a new workflow and get its run ID.
|
|
@@ -25,6 +25,9 @@ The `workflow/api` package provides runtime functions to inspect runs, start new
|
|
|
25
25
|
<Card href="/docs/api-reference/workflow-api/get-run" title="getRun()">
|
|
26
26
|
Get workflow run status and metadata without waiting for completion.
|
|
27
27
|
</Card>
|
|
28
|
+
<Card href="/docs/api-reference/workflow-api/delete-runs" title="deleteRuns()">
|
|
29
|
+
Delete the stored data of finished runs.
|
|
30
|
+
</Card>
|
|
28
31
|
<Card href="/docs/api-reference/workflow-api/register-lifecycle-hooks" title="registerLifecycleHooks()">
|
|
29
32
|
Observe run completions and failures with global handlers.
|
|
30
33
|
</Card>
|
|
@@ -247,6 +247,8 @@ To cancel a run, create a `run_cancelled` event through `world.events.create()`
|
|
|
247
247
|
|
|
248
248
|
To cancel a batch in one call, a world may implement the optional `runs.cancelMany({ runIds })`. It returns a summary plus a per-run outcome (`cancelled`, `already_cancelled`, `not_cancellable`, `not_found`, or `failed`). Backends that omit it fall back to per-run cancellation automatically.
|
|
249
249
|
|
|
250
|
+
To delete the stored data of finished runs, a world may implement the optional `runs.deleteDataMany({ runIds })`. It deletes run payloads but not metadata: it keeps the run, step, event and hook records listed, with their IDs, names, statuses, timestamps and the run's attributes. It must delete only the data of finished runs and answer every other run `skipped` without cancelling it. It returns a summary plus a per-run outcome, in the order of `runIds`: `deleted`, `already_deleted` (the data was already gone; anything left behind is deleted too), `skipped` (with a `reason` and the run's `status`), `not_created`, `not_found`, or `failed` (with a `code`, and `retryable` when retrying can succeed). Deletion must be idempotent. Backends that omit it have no fallback: `deleteRuns()` throws.
|
|
251
|
+
|
|
250
252
|
### WorkflowRun type
|
|
251
253
|
|
|
252
254
|
| Field | Type | Description |
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
title: CLI and Web UI
|
|
3
3
|
description: CLI flags and environment variables for inspecting local, Postgres, and Vercel Workflow runs.
|
|
4
4
|
type: reference
|
|
5
|
-
summary: Configure workflow inspect, workflow cancel, workflow web, workflow health, workflow migrate, and observability tooling.
|
|
5
|
+
summary: Configure workflow inspect, workflow cancel, workflow delete, workflow web, workflow health, workflow migrate, and observability tooling.
|
|
6
6
|
related:
|
|
7
7
|
- /docs/observability
|
|
8
8
|
- /docs/configuration/worlds
|
|
@@ -210,10 +210,37 @@ per flag.
|
|
|
210
210
|
|
|
211
211
|
### `--confirm` / `-y`
|
|
212
212
|
|
|
213
|
-
- Command: `workflow cancel`
|
|
213
|
+
- Command: `workflow cancel`, `workflow delete`
|
|
214
214
|
- Default: disabled
|
|
215
215
|
- Skips the interactive confirmation prompt.
|
|
216
216
|
|
|
217
|
+
## Delete
|
|
218
|
+
|
|
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.
|
|
220
|
+
|
|
221
|
+
```bash
|
|
222
|
+
pnpx workflow delete <runId>
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
Pass several run IDs to delete the data of several runs, and [`--backend`](#--backend---b) to pick the World, such as `--backend vercel`. To delete many runs, pass `-` to read the run IDs from stdin, one per line or separated by whitespace. Reading from stdin requires `-y`.
|
|
226
|
+
|
|
227
|
+
```bash
|
|
228
|
+
cat run-ids.txt | pnpx workflow delete - -y --strict
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
- Only finished runs have their data deleted. A run that hasn't finished is reported as skipped and keeps running; cancel it first to delete its data now.
|
|
232
|
+
- Run IDs are sent in batches of 100, the most the World accepts in one request.
|
|
233
|
+
- A run that fails with a retryable error is retried, as is a rate-limited request, up to four attempts in all, after the delay the World asks for when it gives one.
|
|
234
|
+
- The command prints a line for each run that was skipped, not found, or failed, then a summary. The summary counts runs that were cancelled before they were created (`not_created`) as deleted. With `--json`, it prints the per-run results instead, which keep them separate.
|
|
235
|
+
- It exits with `1` when a run still failed after its retries, and `0` otherwise, including when runs were skipped or not found. Running it again is safe: runs already handled are reported as already deleted.
|
|
236
|
+
- The configured World must support deleting run data; see [Data retention](/docs/observability/retention#deleting-a-finished-runs-data).
|
|
237
|
+
|
|
238
|
+
### `--strict`
|
|
239
|
+
|
|
240
|
+
- Command: `workflow delete`
|
|
241
|
+
- Default: disabled
|
|
242
|
+
- Exits with `1` unless the data of every run is gone: also when a run isn't found (a mistyped ID, or a run from another project) or hasn't finished. Use it in scripts that must delete every run they name.
|
|
243
|
+
|
|
217
244
|
## Migrate from Inngest
|
|
218
245
|
|
|
219
246
|
`workflow migrate inngest [paths...]` rewrites Inngest functions as Workflow SDK code in place: each `createFunction()` becomes a `"use workflow"` function, and each `step.run()` closure becomes a `"use step"` function whose parameters are the variables the closure captured. It prints every step it lifted with its captured variables, and marks what needs a decision with `TODO(workflow-migrate)` comments. See [Migrating from Inngest](/docs/comparisons/workflow-sdk-vs-inngest#run-the-codemod) for what it changes.
|
|
@@ -158,8 +158,10 @@ For example, a workflow can run a 10-minute inline step even with `WORKFLOW_REPL
|
|
|
158
158
|
|
|
159
159
|
- Default: enabled
|
|
160
160
|
- Fast path for a run's first delivery.
|
|
161
|
+
- Applies only while that delivery's queue message is at most 15 seconds old. An older one, such as a platform re-running a crashed invocation, loads the event log first.
|
|
161
162
|
- Stops forcing optimistic inline step start once the run creates a hook or wait.
|
|
162
|
-
-
|
|
163
|
+
- A run started with `start({ experimental_hook })` never runs steps before `run_started` returns, but its first delivery still writes `run_started` without loading the event log first.
|
|
164
|
+
- Set `0` or `false` to disable, including for such runs.
|
|
163
165
|
|
|
164
166
|
### `WORKFLOW_OPTIMISTIC_INLINE_START`
|
|
165
167
|
|
|
@@ -191,7 +193,7 @@ For example, a workflow can run a 10-minute inline step even with `WORKFLOW_REPL
|
|
|
191
193
|
- Values: `node` or `quickjs`
|
|
192
194
|
- Selects the sandboxed VM engine that executes workflow functions (`"use workflow"`). Step functions are unaffected and always run with full Node.js access.
|
|
193
195
|
- `node` (default) runs workflow code in a [`node:vm`](https://nodejs.org/api/vm.html) context. Every resume replays the run's full event log, so resume cost grows with the log, and runs are subject to the World's default [per-run event limit](/docs/errors/max-events-exceeded).
|
|
194
|
-
- `quickjs` runs workflow code in a [QuickJS](https://github.com/quickjs-ng/quickjs) VM compiled to WebAssembly (via [`quickjs-wasi`](https://github.com/vercel-labs/quickjs-wasi)). **Use it for long-running workflows**: agents, chat sessions, and loops that wait on hooks or sleeps, or any run with many steps. With snapshotting (on by default
|
|
196
|
+
- `quickjs` runs workflow code in a [QuickJS](https://github.com/quickjs-ng/quickjs) VM compiled to WebAssembly (via [`quickjs-wasi`](https://github.com/vercel-labs/quickjs-wasi)). **Use it for long-running workflows**: agents, chat sessions, and loops that wait on hooks or sleeps, or any run with many steps. With snapshotting (on by default, see [`WORKFLOW_SNAPSHOT_THRESHOLD`](#workflow_snapshot_threshold)), a run resumes from a VM-memory snapshot and replays only the events recorded since, so resume cost stays roughly flat as the log grows, and the run is exempt from the default per-run event limit on the Local and Vercel Worlds. It also runs on platforms that do not implement `node:vm`.
|
|
195
197
|
- Both engines implement the same event-replay execution model (seeded PRNG, deterministic clock, and correlation-ID sequences are identical), so workflow code that sticks to plain JavaScript and the Workflow APIs runs unchanged. To switch, set `WORKFLOW_VM=quickjs` in the environment that starts runs, and runs started after that use QuickJS. The few globals QuickJS does not provide in workflow functions are listed below.
|
|
196
198
|
- Global-surface differences under `quickjs` apply to workflow functions only. Step functions always have full Node.js, so the fix for each is to move that call into a step:
|
|
197
199
|
- `crypto.getRandomValues()` and `crypto.randomUUID()` are provided and deterministic (seeded like the node engine's). All `crypto.subtle.*` methods, including `digest`, throw with guidance to move to a step function. The node engine supports `digest`.
|
|
@@ -226,16 +228,11 @@ For example, a workflow can run a 10-minute inline step even with `WORKFLOW_REPL
|
|
|
226
228
|
What a snapshot contains, and how it is protected:
|
|
227
229
|
|
|
228
230
|
- A snapshot is the workflow VM's memory: the workflow's code and in-memory state, including step results and hook payloads it holds, and the copy of `process.env` the VM exposes. It is executable state, so write access to snapshot storage is equivalent to running code in the workflow VM.
|
|
229
|
-
-
|
|
230
|
-
-
|
|
231
|
+
- When the run has an encryption key, its snapshots are compressed and then encrypted with that key. The encryption also authenticates the snapshot: on restore, the runtime rejects any snapshot that isn't encrypted with the run's key, or whose stored metadata doesn't match the metadata sealed inside it.
|
|
232
|
+
- Runs without an encryption key (world-local, world-postgres, and any World that doesn't implement `getEncryptionKeyForRun()`) are snapshotted in plaintext, the same as their event log and payloads (in `.workflow-data/snapshots/` or the `workflow_snapshots` table). Those snapshots are not authenticated, so snapshot storage needs the same protection as the rest of the World's storage.
|
|
231
233
|
- A restored run sees `process.env` as of the current invocation, the same as a full replay.
|
|
232
234
|
- Snapshots are deleted after the run reaches a terminal state. world-local and world-postgres have no separate retention for them, so a snapshot of a run that ends without any invocation observing it (for example, one cancelled externally) stays until you remove it.
|
|
233
235
|
|
|
234
|
-
### `WORKFLOW_SNAPSHOT_ALLOW_UNENCRYPTED`
|
|
235
|
-
|
|
236
|
-
- Default: disabled
|
|
237
|
-
- Set `1` or `true` on the workflow handler to let the QuickJS engine persist VM snapshots for runs without an encryption key. See [`WORKFLOW_SNAPSHOT_THRESHOLD`](#workflow_snapshot_threshold) for what that stores.
|
|
238
|
-
|
|
239
236
|
## Dynamic workflows
|
|
240
237
|
|
|
241
238
|
### `WORKFLOW_EXPERIMENTAL_DYNAMIC_WORKFLOWS`
|
|
@@ -403,13 +400,18 @@ Everything above describes spec 8 runs, the default. The experimental spec 9 run
|
|
|
403
400
|
|
|
404
401
|
### `WORKFLOW_ORCHESTRATOR_LINGER_MS`
|
|
405
402
|
|
|
406
|
-
- Default: `
|
|
407
|
-
- How long an orchestrator with nothing left to run stays live on the event feed while the run waits on a background step. `0` turns it off, for hooks too.
|
|
403
|
+
- Default: `5000`
|
|
404
|
+
- How long an orchestrator with nothing left to run stays live on the event feed while the run waits on a background step. A step that takes longer ends the invocation, and its outcome starts a new one. `0` turns it off, for hooks and sleeps too.
|
|
408
405
|
|
|
409
406
|
### `WORKFLOW_ORCHESTRATOR_HOOK_LINGER_MS`
|
|
410
407
|
|
|
411
408
|
- Default: `5000`, and never more than [`WORKFLOW_ORCHESTRATOR_LINGER_MS`](#workflow_orchestrator_linger_ms)
|
|
412
|
-
- How long an orchestrator with nothing left to run stays live on the event feed while the run waits only on open hooks. Any hook that is created and not disposed counts, however rarely it is resumed. `0` turns it off.
|
|
409
|
+
- How long an orchestrator with nothing left to run stays live on the event feed while the run waits only on open hooks. Set it below `WORKFLOW_ORCHESTRATOR_LINGER_MS` to keep background steps on a longer window than hooks. Any hook that is created and not disposed counts, however rarely it is resumed. `0` turns it off.
|
|
410
|
+
|
|
411
|
+
### `WORKFLOW_ORCHESTRATOR_WAIT_LINGER_MS`
|
|
412
|
+
|
|
413
|
+
- Default: [`WORKFLOW_ORCHESTRATOR_LINGER_MS`](#workflow_orchestrator_linger_ms) (`5000`), and never more than it
|
|
414
|
+
- How far ahead a `sleep()` may end for an orchestrator with nothing left to run to stay live on the event feed until it does, instead of ending the invocation and starting a new one when the sleep's timer fires. A sleep up to 1 second longer than this still counts, so a sleep as long as the window lingers despite small clock differences. Only for a sleep that ends before the invocation's inline window less [`WORKFLOW_INLINE_STEP_DEADLINE_MARGIN_MS`](#workflow_inline_step_deadline_margin_ms), and only on a World with a live event feed (such as world-vercel and world-postgres; world-local has none, so it never lingers). On those Worlds, a `run.wakeUp()` sent during such a sleep is not applied, so the sleep runs its full length. `0` turns it off.
|
|
413
415
|
|
|
414
416
|
### `WORKFLOW_ORCHESTRATOR_READ_TIMEOUT_MS`
|
|
415
417
|
|
|
@@ -56,7 +56,6 @@ A run qualifies when its `executionContext` records `workflowVm: "quickjs"` and
|
|
|
56
56
|
|
|
57
57
|
- Only runs started after the change are exempt. Runs keep the VM and snapshot policy they started with.
|
|
58
58
|
- Runs that have already failed with `MAX_EVENTS_EXCEEDED` are not revived. Start them again.
|
|
59
|
-
- On the Local World and Postgres World, snapshots are only stored when [`WORKFLOW_SNAPSHOT_ALLOW_UNENCRYPTED=1`](/docs/configuration/runtime-tuning#workflow_snapshot_allow_unencrypted) is set. Without it, exempt runs still replay the full log on every invocation.
|
|
60
59
|
|
|
61
60
|
### Split the work into child workflows
|
|
62
61
|
|
|
@@ -91,6 +91,50 @@ caller can tell a successful run whose result is gone from a failed one whose
|
|
|
91
91
|
error is gone. If the run's metadata is gone too, the World reports the run as
|
|
92
92
|
missing and you get `WorkflowRunNotFoundError` instead.
|
|
93
93
|
|
|
94
|
+
## Deleting a finished run's data
|
|
95
|
+
|
|
96
|
+
To delete the data of a run that has already finished, call
|
|
97
|
+
[`run.delete()`](/docs/api-reference/workflow-api/get-run#delete-a-finished-runs-data),
|
|
98
|
+
call [`deleteRuns()`](/docs/api-reference/workflow-api/delete-runs)
|
|
99
|
+
for up to 100 runs at once, or run `workflow delete` from the
|
|
100
|
+
[CLI](/docs/configuration/cli-and-web-ui#delete). The World deletes the
|
|
101
|
+
same data a run started with `experimental_retention: 0` has deleted when it
|
|
102
|
+
ends. Metadata is not deleted: the runs stay listed, and so do their steps,
|
|
103
|
+
events and hooks, with their IDs, names, statuses, timestamps and attributes.
|
|
104
|
+
|
|
105
|
+
{/* @skip-typecheck: abbreviated usage; the run IDs are the reader's own */}
|
|
106
|
+
```typescript lineNumbers
|
|
107
|
+
import { deleteRuns, getRun } from 'workflow/api'
|
|
108
|
+
|
|
109
|
+
await getRun(runId).delete() // [!code highlight]
|
|
110
|
+
await deleteRuns([runIdA, runIdB]) // [!code highlight]
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
pnpx workflow delete <runId>
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Only finished runs have their data deleted. A run that is still running,
|
|
118
|
+
sleeping, or waiting on a hook is answered `skipped` and left untouched:
|
|
119
|
+
deleting data never cancels a run. To delete an active run's data now, cancel
|
|
120
|
+
it first, then delete its data. Each run gets its own outcome: `deleted`,
|
|
121
|
+
`already_deleted` (its data was already gone), `skipped`, `not_created`,
|
|
122
|
+
`not_found`, or `failed`. A `failed` outcome with `retryable: true` can be
|
|
123
|
+
retried, since deletion is idempotent. Inside a step, a retryable failure
|
|
124
|
+
throws a `RetryableError`, so the step retries on its own.
|
|
125
|
+
|
|
126
|
+
Deleting run data is optional for a World to implement, and there is no
|
|
127
|
+
fallback: on a World that doesn't support it, `run.delete()` and
|
|
128
|
+
`deleteRuns()` throw, and `workflow delete` exits with an error. The
|
|
129
|
+
[Local World](/worlds/local), the [Postgres World](/worlds/postgres) and the
|
|
130
|
+
[Vercel World](/worlds/vercel) support it. Deleting run data doesn't change
|
|
131
|
+
how a run is billed; see the
|
|
132
|
+
[Vercel Workflows docs](https://vercel.com/docs/workflows/retention).
|
|
133
|
+
|
|
134
|
+
Nothing records that a run's data was deleted: the run reads back as expired,
|
|
135
|
+
the same as a run whose retention ended. If you need a record of the deletion,
|
|
136
|
+
keep it yourself.
|
|
137
|
+
|
|
94
138
|
## Retention is implemented by the World
|
|
95
139
|
|
|
96
140
|
The SDK records your preference; it does not enforce it. `start()` writes the
|
package/docs/worlds/postgres.mdx
CHANGED
|
@@ -220,6 +220,20 @@ Before you go live, make sure that:
|
|
|
220
220
|
- `/.well-known/workflow/v1/flow` is restricted so untrusted clients cannot reach it (see [Security](#security))
|
|
221
221
|
- If more than one process shares the database, you have set [`WORKFLOW_POSTGRES_JOB_LOCK_STALE_SECONDS`](#workflow_postgres_job_lock_stale_seconds) to the same value on every process, so another process picks up the jobs of one that dies
|
|
222
222
|
|
|
223
|
+
### Kubernetes
|
|
224
|
+
|
|
225
|
+
The package includes a Helm chart for Kubernetes in its `chart` directory, and the helpers it relies on in `@workflow/world-postgres/kubernetes`. Each release pins its runs to its image tag with [`WORKFLOW_POSTGRES_DEPLOYMENT_ID`](#workflow_postgres_deployment_id), and older releases keep worker pods that finish their own runs:
|
|
226
|
+
|
|
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
|
+
- **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.
|
|
230
|
+
- **Graceful shutdown.** `createLifecycle` stops a pod from receiving traffic, then lets its running deliveries finish before it exits.
|
|
231
|
+
- **Migrations.** An optional init container runs `bootstrap` before each pod starts.
|
|
232
|
+
|
|
233
|
+
The chart needs KEDA in the cluster, and an image whose entrypoint reads `WORKFLOW_ROLE` (`service`, `worker` or `prune`). The chart's README, in the same directory, covers the entrypoint, the image, and how long old versions keep running. To deploy workers with your own tooling instead, run `npx workflow-postgres-prune` after each deploy.
|
|
234
|
+
The package includes a Helm chart for Kubernetes in its `chart` directory, as an optional way for production deployments into Kubernetes clusters. It works by pinning each run to its image tag, and by keeping around older releases' worker pods until their runs finish. It's scale-to-zero and supports pruning.
|
|
235
|
+
|
|
236
|
+
See [`chart/README.md`](./chart/README.md) for more information.
|
|
223
237
|
<Callout type="info">
|
|
224
238
|
The Postgres World is not compatible with Vercel deployments. On Vercel, workflows automatically use the [Vercel World](/worlds/vercel) with zero configuration.
|
|
225
239
|
</Callout>
|
|
@@ -567,7 +581,7 @@ The Postgres World uses PostgreSQL as a durable backend:
|
|
|
567
581
|
|
|
568
582
|
- **Storage**: Workflow runs, events, steps, and hooks are stored in PostgreSQL tables.
|
|
569
583
|
- **Job queue**: [graphile-worker](https://github.com/graphile/worker) handles reliable job processing with retries.
|
|
570
|
-
- **Crash recovery**: The next `start()` re-enqueues active runs. A running delivery also renews its job lock. If its process dies, any other process redelivers a spec 9 run's orchestrator job once its lock has gone unrenewed for 300 seconds, and with [`WORKFLOW_POSTGRES_JOB_LOCK_STALE_SECONDS`](#workflow_postgres_job_lock_stale_seconds) set, any job of this World once its lock has gone unrenewed for that many seconds.
|
|
584
|
+
- **Crash recovery**: The next `start()` re-enqueues active runs, except a run parked on a hook or a wait that is not yet due with no wake left to deliver and no delivery in progress. A run's recovery job is keyed by the run, so repeated boots do not stack duplicates. A running delivery also renews its job lock. If its process dies, any other process redelivers a spec 9 run's orchestrator job once its lock has gone unrenewed for 300 seconds, and with [`WORKFLOW_POSTGRES_JOB_LOCK_STALE_SECONDS`](#workflow_postgres_job_lock_stale_seconds) set, any job of this World once its lock has gone unrenewed for that many seconds.
|
|
571
585
|
- **Streaming**: PostgreSQL NOTIFY/LISTEN enables real-time event distribution. If the database drops the `LISTEN` connection, the World reconnects every second and re-reads persisted chunks for open stream readers, so readers don't miss chunks written during the outage.
|
|
572
586
|
|
|
573
587
|
This architecture ensures workflows survive application restarts with all state reliably persisted. For implementation details, see the [source code](https://github.com/vercel/workflow/tree/main/packages/world-postgres).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "workflow",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.7.0",
|
|
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.
|
|
64
|
-
"@workflow/cli": "5.
|
|
65
|
-
"@workflow/core": "5.
|
|
66
|
-
"@workflow/errors": "5.1.
|
|
63
|
+
"@workflow/astro": "5.0.12",
|
|
64
|
+
"@workflow/cli": "5.3.0",
|
|
65
|
+
"@workflow/core": "5.7.0",
|
|
66
|
+
"@workflow/errors": "5.1.4",
|
|
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.
|
|
71
|
-
"@workflow/nest": "5.1.
|
|
72
|
-
"@workflow/nitro": "5.0.
|
|
73
|
-
"@workflow/nuxt": "5.0.
|
|
74
|
-
"@workflow/sveltekit": "5.0.
|
|
75
|
-
"@workflow/rollup": "5.0.
|
|
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"
|
|
76
76
|
},
|
|
77
77
|
"devDependencies": {
|
|
78
78
|
"@types/ms": "2.1.0",
|