Storage

The World storage interface exposes four sub-interfaces for querying workflow data:

  • world.events: The append-only event log. This is the source of truth for all workflow state. See Event Sourcing for background.
  • world.runs, world.steps, world.hooks: Materialized views derived from the event log, provided as convenience accessors for the most common query patterns.
import { getWorld } from "workflow/runtime";

const world = await getWorld();

world.events

The event log drives all workflow state. Use it for audit trails, debugging, and programmatic run cancellation.

events.create()

Create a new event for a workflow run. Most commonly used to cancel a run.

await world.events.create(runId, {
  eventType: "run_cancelled",
});
ParameterTypeDescription
runIdstring | nullThe workflow run ID (null only for run_created events, where the server generates an ID)
dataCreateEventRequestEvent data including eventType
paramsobjectOptional parameters

Returns: EventResult, the created event and the affected entity (run/step/hook)

events.get()

Retrieve a single event by run ID and event ID.

const event = await world.events.get(runId, eventId);
ParameterTypeDescription
runIdstringThe workflow run ID
eventIdstringThe event ID

Returns: Event

events.list()

List events for a run. Omit pagination.limit to return every remaining event, or set it to return one bounded page.

const result = await world.events.list({ runId, pagination: { cursor } });
ParameterTypeDescription
params.runIdstringFilter events by run ID
params.pagination.cursorstringCursor for the next page
params.pagination.limitnumberMaximum events to return. When omitted, returns every remaining event up to the World's event ceiling.
params.pagination.sortOrder"asc" | "desc"Event order
params.resolveData"all" | "none" | "skip-step-inputs"Include or omit event payload data. "skip-step-inputs" is "all" without the input of step_created and step_started events, which replay does not read.

Returns: { data: Event[], cursor: string | null, hasMore: boolean }

events.listByCorrelationId()

List one run's events that share a correlation ID, useful for tracing a single step, hook or wait through its lifecycle.

A correlation ID is unique within its run, not across runs: two runs can each hold a step_…, hook_… or wait_… ID that reads the same. runId is therefore required, and it is also what makes the pagination cursor unambiguous.

const result = await world.events.listByCorrelationId({
  runId,
  correlationId: "order-123",
});
ParameterTypeDescription
params.runIdstringThe run the correlation ID belongs to
params.correlationIdstringThe correlation ID to filter by
params.pagination.cursorstringCursor for the next page

Returns: { data: Event[], cursor?: string }

Event types

CategoryTypes
Runrun_created, run_started, run_completed, run_failed, run_cancelled
Attributeattr_set
Stepstep_created, step_started, step_completed, step_failed, step_retrying
Hookhook_created, hook_received, hook_disposed, hook_conflict
Waitwait_created, wait_completed

world.runs

Materialized from run events. Use it for canonical operational reads, including reads that require workflow input or output data. For observability dashboards, inspection tools, and historical listings, use world.analytics.runs.list().

runs.get()

const run = await world.runs.get(runId);
ParameterTypeDescription
runIdstringThe workflow run ID
params.resolveData'all' | 'none'Whether to include input/output data. Default: 'all'

Returns: WorkflowRun (or WorkflowRunWithoutData when resolveData: 'none')

runs.waitForTerminalStatus()

Optional. Long poll for a run to reach a terminal status (completed, failed, or cancelled) instead of re-reading it on an interval. This is what await run.returnValue uses, so a run's result reaches the awaiting side as soon as it finishes rather than at the next poll tick.

const run = await world.runs.waitForTerminalStatus?.(runId, {
  timeoutMs: 25_000,
});
ParameterTypeDescription
runIdstringThe workflow run ID
params.timeoutMsnumberUpper bound on the wait. The call returns earlier, the moment the run is terminal
params.signalAbortSignalAbandons the wait
params.resolveData'all' | 'none'Whether to include input/output data. Default: 'all'

Returns: the same WorkflowRun as runs.get(): terminal if the run finished within the budget, otherwise the latest snapshot. An expired budget is a normal return, not an error, and a missing run throws WorkflowRunNotFoundError exactly as runs.get() does.

Not every backend can hold a read open, so this method is optional and may also return a non-terminal snapshot before timeoutMs is up. Callers pace their own retries (await run.returnValue keeps consecutive non-terminal observations at least one WORKFLOW_RETURN_VALUE_POLL_INTERVAL_MS apart), and worlds that omit the method are polled on that interval instead.

runs.list()

const result = await world.runs.list({
  status: "running",
  pagination: { cursor },
});
ParameterTypeDescription
params.workflowNamestringOnly return runs of this workflow
params.statusWorkflowRunStatus | WorkflowRunStatus[]Only return runs in this status. Pass an array to match any of the listed statuses; an empty array matches no runs. @workflow/world-vercel accepts a single status only and throws WorkflowWorldError (INVALID_ARGUMENT) for an array
params.pagination.cursorstringCursor for the next page
params.pagination.sortOrder"asc" | "desc"Run creation order. Default: "desc" (newest first)
params.resolveData'all' | 'none'Whether to include input/output data

Returns: { data: WorkflowRun[], cursor?: string }

The array form of status lets you express set filters without restating the status vocabulary. @workflow/world exports TERMINAL_WORKFLOW_RUN_STATUSES (['completed', 'failed', 'cancelled']) for that purpose:

import { TERMINAL_WORKFLOW_RUN_STATUSES } from "@workflow/world";

// Every run that has not reached a terminal status
const inFlight = await world.runs.list({
  status: ["pending", "running"],
});

// The complement, without hardcoding the list
const finished = await world.runs.list({
  status: [...TERMINAL_WORKFLOW_RUN_STATUSES],
});

status: [] matches no runs, mirroring SQL IN (). To leave the filter unset, omit the field entirely.

Support for the array form is per World. The Local and Postgres Worlds accept it; the Vercel World's /v2/runs endpoint takes a single status today and throws a WorkflowWorldError (INVALID_ARGUMENT) when given an array, rather than silently filtering on something else.

Observability and inspection usage of world.runs.list() is deprecated. Use world.analytics.runs.list() for metadata-only, plan-aware queries backed by the observability pipeline. world.runs.list() remains supported for operational and payload-bearing reads.

Cancelling runs

To cancel a run, create a run_cancelled event through world.events.create() (see world.events above), or use the Workflow CLI or web interface helpers.

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.

WorkflowRun type

FieldTypeDescription
runIdstringUnique run identifier
statusstring'pending', 'running', 'completed', 'failed', 'cancelled'
workflowNamestringMachine-readable workflow identifier
inputanyWorkflow input data (when resolveData: 'all')
outputanyWorkflow output data (when resolveData: 'all')
erroranyError data if the run failed
startedAtstringISO timestamp when the run started
completedAtstring | nullISO timestamp when the run completed

workflowName is a machine-readable identifier like workflow//./src/workflows/order//processOrder. Use parseWorkflowName() from workflow/observability to extract a display-friendly name.


world.steps

Materialized from step events. Use it to list steps, inspect their input/output, and build progress dashboards.

steps.get()

const step = await world.steps.get(runId, stepId);
ParameterTypeDescription
runIdstringThe workflow run ID that owns the step
stepIdstringThe step ID
params.resolveData'all' | 'none'Whether to include input/output data. Default: 'all'

Returns: Step (or StepWithoutData when resolveData: 'none')

steps.list()

const result = await world.steps.list({
  runId,
  pagination: { cursor },
});
ParameterTypeDescription
params.runIdstringFilter steps by run ID
params.pagination.cursorstringCursor for the next page
params.pagination.sortOrder"asc" | "desc"Step creation order. Default: "desc" (newest first)
params.resolveData'all' | 'none'Whether to include input/output data

Returns: { data: Step[], cursor?: string }

Step type

FieldTypeDescription
runIdstringParent workflow run ID
stepIdstringUnique step identifier
stepNamestringMachine-readable step identifier
statusstring'running', 'completed', 'failed'
inputanyStep input data (when resolveData: 'all')
outputanyStep output data (when resolveData: 'all')
erroranyError data if the step failed
attemptnumberCurrent retry attempt number
startedAtstringISO timestamp when the step started
completedAtstring | nullISO timestamp when the step completed
retryAfterstring | nullISO timestamp for next retry attempt

Step input/output (I/O) is serialized using the devalue format. Use hydrateResourceIO() from workflow/observability to deserialize it for display. See hydrateResourceIO().

stepName is a machine-readable identifier like step//./src/workflows/order//processPayment. Use parseStepName() from workflow/observability to extract the shortName for display in a user interface.


world.hooks

Materialized from hook events. Hooks are pause points in workflows that wait for external input. Use this interface to look up hooks by ID or token, inspect metadata, and build UIs for pending approvals.

hooks.get()

const hook = await world.hooks.get(hookId);
ParameterTypeDescription
hookIdstringThe hook ID

Returns: Hook

hooks.getByToken()

Look up a hook by its token. Useful in webhook resume flows where you receive a token in the callback URL.

For runtime application code, prefer getHookByToken(). Use world.hooks.getByToken() when you are working directly with the World storage interface for custom tooling, admin views, or low-level integrations.

Hook-token lookup is the low-level form of the recommended idempotency flow: if a hook is already registered for your business key, reuse the hook's runId or resume that hook instead of starting another run. If no hook exists yet, start the workflow with start({ experimental_hook: { token } }), which creates the Hook atomically with the run and refuses a duplicate with HookConflictError naming the owner. On a World without atomic start Hooks, have the workflow create the deterministic hook near the beginning and check await hook.getConflict() to detect whether another run claimed the token first. See Run idempotency.

const hook = await world.hooks.getByToken(token);
ParameterTypeDescription
tokenstringThe hook token

Returns: Hook

hooks.list()

const result = await world.hooks.list({
  pagination: { cursor },
});
ParameterTypeDescription
params.pagination.cursorstringCursor for the next page

Returns: { data: Hook[], cursor?: string }

Hook type

FieldTypeDescription
runIdstringParent workflow run ID
hookIdstringUnique hook identifier
tokenstringHook token for resuming
ownerIdstringOwner (team/user) ID
projectIdstringProject ID
environmentstringDeployment environment
metadataobjectCustom metadata attached to the hook
isWebhookbooleanWhether this is a webhook-style hook
claimedFrom{ runId: string; hookId: string } | undefinedSet when this hook took its token from another run with experimental_force. Names that run and its hook

Examples

List runs with pagination

import { getWorld } from "workflow/runtime";

const world = await getWorld();
let cursor: string | undefined;

const runs = await world.runs.list({
  pagination: { cursor },
});

cursor = runs.cursor; // pass to next call for pagination

Get a run: full data vs. metadata only

import { getWorld } from "workflow/runtime";

const world = await getWorld();

// Full data (default): includes serialized input/output
const run = await world.runs.get(runId);

// Metadata only: lighter, no I/O loaded
const lightweight = await world.runs.get(runId, {
  resolveData: "none",
});

List steps for a progress dashboard

import { getWorld } from "workflow/runtime";
import { parseStepName } from "workflow/observability";

const world = await getWorld();
const steps = await world.steps.list({
  runId,
  resolveData: "none",
});

const progress = steps.data.map((step) => {
  const parsed = parseStepName(step.stepName);
  return {
    stepId: step.stepId,
    displayName: parsed?.shortName ?? step.stepName,
    status: step.status,
  };
});

Hydrate step I/O

import { getWorld } from "workflow/runtime";
import { hydrateResourceIO, observabilityRevivers } from "workflow/observability";

const world = await getWorld();
const step = await world.steps.get(runId, stepId);
const hydrated = hydrateResourceIO(step, observabilityRevivers);
console.log(hydrated.input, hydrated.output);

Cancel a run

import { getWorld } from "workflow/runtime";

const world = await getWorld();
await world.events.create(runId, {
  eventType: "run_cancelled",
});

Look up hook by token

import { getWorld } from "workflow/runtime";

const world = await getWorld();
const hook = await world.hooks.getByToken(token);
console.log(hook.runId);

The World-level Hook carries metadata as the raw serialized (and, on encrypting Worlds, encrypted) value, not the object the workflow passed to createHook(). To read the decoded value, use getHookByToken(), whose hook.metadata is a Promise that hydrates it on first access.

List events for audit trail

import { getWorld } from "workflow/runtime";

const world = await getWorld();
const events = await world.events.list({ runId });

for (const event of events.data) {
  console.log(event.eventType, event.createdAt);
}