world.events

Query the append-only event log for workflow state changes, audit trails, and run cancellation.

The world.events interface provides access to the append-only event log that drives all workflow state. Runs, steps, and hooks are materialized views derived from events. Use this interface for audit trails, debugging, and programmatic run cancellation.

Import

import { getWorld } from "workflow/runtime";

const world = getWorld();
const events = world.events; 

Methods

create()

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

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

Parameters:

ParameterTypeDescription
runIdstringThe workflow run ID
dataobjectEvent data including eventType
paramsobjectOptional parameters

Returns: Event

get()

Retrieve a single event by run ID and event ID.

const event = await world.events.get(runId, eventId); 

Parameters:

ParameterTypeDescription
runIdstringThe workflow run ID
eventIdstringThe event ID
paramsobjectOptional parameters

Returns: Event

list()

List events with cursor pagination.

const result = await world.events.list({ 
  runId,
  pagination: { cursor },
}); 

Parameters:

ParameterTypeDescription
params.runIdstringFilter events by run ID
params.pagination.cursorstringCursor for the next page

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

listByCorrelationId()

List events that share a correlation ID, useful for tracing related events across runs.

const result = await world.events.listByCorrelationId({ 
  correlationId: "order-123",
}); 

Parameters:

ParameterTypeDescription
params.correlationIdstringThe correlation ID to filter by
params.pagination.cursorstringCursor for the next page

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

Event Types

Events are grouped by the entity they affect:

Run Events

Event TypeDescription
run_createdWorkflow run was created
run_startedWorkflow run execution began
run_completedWorkflow run completed successfully
run_failedWorkflow run failed with an error
run_cancelledWorkflow run was cancelled

Step Events

Event TypeDescription
step_createdStep was created
step_startedStep execution began
step_completedStep completed successfully
step_failedStep failed with an error
step_retryingStep scheduled for retry

Hook Events

Event TypeDescription
hook_createdHook was created (workflow paused)
hook_receivedHook received a payload
hook_disposedHook was disposed (workflow reached terminal state)
hook_conflictHook token conflict detected

Wait Events

Event TypeDescription
wait_createdWorkflow entered a wait state (e.g., sleep())
wait_completedWait state completed

Events are the append-only source of truth for all workflow state. WorkflowRun, Step, and Hook objects are materialized views derived from these events.

Examples

List Events for a Run as Audit Trail

import { getWorld } from "workflow/runtime";

export async function GET(req: Request) {
  const url = new URL(req.url);
  const runId = url.searchParams.get("runId");

  if (!runId) {
    return Response.json({ error: "runId required" }, { status: 400 });
  }

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

  return Response.json(events);
}

Cancel a Run via Event Creation

Cancelling a run is done by creating a run_cancelled event:

import { getWorld } from "workflow/runtime";

export async function POST(req: Request) {
  const { runId } = await req.json();

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

  return Response.json({ cancelled: true });
}

world.runs.cancel(runId) is a convenience wrapper around this event creation pattern. Use world.events.create() directly when you need to attach custom data to the cancellation event.

List Events by Correlation ID

Trace related events across workflow runs using a shared correlation ID:

import { getWorld } from "workflow/runtime";

const world = getWorld();
const events = await world.events.listByCorrelationId({ 
  correlationId: "order-123", 
}); 

for (const event of events.data) {
  console.log(event.eventType, event.runId, event.createdAt);
}
  • world.runs — Inspect runs (materialized from events)
  • world.steps — Inspect steps (materialized from events)
  • world.hooks — Inspect hooks (materialized from events)