title: List and Inspect Workflows impact: CRITICAL impactDescription: Enables monitoring and debugging of workflow executions tags: workflow, list, inspect, status, monitoring
List and Inspect Workflows
Use DBOS.listWorkflows to query workflow executions by status, name, time range, and other criteria.
Incorrect (no monitoring of workflow state):
// Start workflow with no way to check on it later
await DBOS.startWorkflow(processTask)("data");
// If something goes wrong, no way to find or debug it
Correct (listing and inspecting workflows):
const erroredWorkflows = await DBOS.listWorkflows({
status: "ERROR",
});
for (const wf of erroredWorkflows) {
console.log(`Workflow ${wf.workflowID}: ${wf.workflowName} - ${wf.error}`);
}
Common queries:
// Find failed workflows
const failed = await DBOS.listWorkflows({ status: "ERROR", limit: 100 });
// Find workflows by name, filtering on multiple statuses
const processing = await DBOS.listWorkflows({
workflowName: "processOrder",
status: ["PENDING", "ENQUEUED", "DELAYED"],
});
// Find workflows on a specific queue
const queued = await DBOS.listWorkflows({ queueName: "high_priority" });
// Only queued workflows (shortcut)
const stillQueued = await DBOS.listQueuedWorkflows({ queueName: "task_queue" });
// Find old-version workflows for blue-green deploys
const old = await DBOS.listWorkflows({
applicationVersion: "1.0.0",
status: ["PENDING", "ENQUEUED", "DELAYED"],
});
// Find children of a parent workflow
const children = await DBOS.listWorkflows({ parentWorkflowID: parentId });
// Find every workflow forked from one ID
const forks = await DBOS.listWorkflows({ forkedFrom: originalId });
// Find workflows by custom attributes (set via workflowAttributes on startWorkflow)
const acme = await DBOS.listWorkflows({ attributes: { customer: "acme" } });
// Find all runs of a schedule
const runs = await DBOS.listWorkflows({ scheduleName: "nightly-report" });
// Sort newest-first, paginate
const page = await DBOS.listWorkflows({ limit: 50, offset: 100, sortDesc: true });Tagging Workflows With Attributes
Attach a JSON-serializable key-value record to a workflow at creation to find it later (e.g., customer, tenant, region). Attributes must be an object (not a scalar or array), are stored as GIN-indexed JSONB, and are not inherited by child workflows:
const handle = await DBOS.startWorkflow(processOrder, {
workflowAttributes: { customer: "acme", region: "us-east-1" },
})(order);
// From a DBOSClient, the option is named `attributes`
await client.enqueue({ workflowName: "processOrder", queueName: "orders", attributes: { customer: "acme" } }, order);
// Matches workflows whose attributes contain ALL the given pairs
const acmeWorkflows = await DBOS.listWorkflows({ attributes: { customer: "acme" } });
Workflows started by a schedule are tagged with the schedule name; find them with listWorkflows({ scheduleName }).
Filter Fields (GetWorkflowsInput)
- workflowIDs: Specific IDs to fetch
- workflowName: Workflow function name (or array)
- status: Single status or array (see status values below)
- startTime / endTime: RFC 3339 timestamps
- completedAfter / completedBefore: RFC 3339 timestamps; completed at-or-after / at-or-before that timestamp
- dequeuedAfter / dequeuedBefore: RFC 3339 timestamps; dequeued at-or-after / at-or-before that timestamp
- applicationVersion: Version(s) the workflow ran on
- executorId: Executor process ID(s)
- workflow_id_prefix: Match workflows whose IDs start with this
- authenticatedUser: User(s) who ran the workflow
- queueName: Queue name(s)
- queuesOnly: If
true, only currently-enqueued workflows (ENQUEUED,DELAYED, orPENDINGon a queue;listQueuedWorkflowsis equivalent to this plusloadOutput: false) - forkedFrom: Source workflow ID(s) for forks
- wasForkedFrom:
truefor workflows that have been forked from,falsefor those that haven’t - isFork:
truefor workflows that are themselves forks of another workflow,falsefor those that aren’t - parentWorkflowID: Parent workflow ID(s)
- hasParent:
truefor child workflows only,falsefor top-level only - attributes: Workflows whose custom attributes contain all these key-value pairs
- scheduleName: Workflows enqueued by this schedule (or any of these schedules)
- applicationName: Workflows owned by these applications (unowned workflows always included). Defaults to this application unless
workflowIDsis set - limit / offset: Pagination
- sortDesc: Sort by creation time descending (default ascending)
- loadInput / loadOutput: Set to
falseto skip deserializing for performance
Status Values
ENQUEUED, DELAYED, PENDING, SUCCESS, ERROR, CANCELLED, MAX_RECOVERY_ATTEMPTS_EXCEEDED
ENQUEUED: durably recorded on a queue, awaiting dequeueDELAYED: enqueued withdelaySeconds; transitions toENQUEUEDwhen the delay expiresPENDING: actively executing (or about to)SUCCESS/ERROR: terminalCANCELLED: cancelled viacancelWorkflow(or timed out)MAX_RECOVERY_ATTEMPTS_EXCEEDED: exceeded retry attempts on recovery
cancelWorkflow(workflowID, options?: { cancelChildren?: boolean }) and cancelWorkflows(workflowIDs, options?: { cancelChildren?: boolean }) cancel workflows. Child workflows are not cancelled by default; pass { cancelChildren: true } to also recursively cancel all child workflows.
WorkflowStatus Fields
interface WorkflowStatus {
workflowID: string;
status: string;
workflowName: string;
workflowClassName: string;
workflowConfigName?: string;
queueName?: string;
authenticatedUser?: string;
authenticatedRoles?: string[];
input?: unknown[];
output?: unknown;
error?: unknown;
executorId?: string;
applicationVersion?: string;
createdAt: number; // Unix epoch ms
updatedAt?: number;
completedAt?: number; // The time the workflow completed (SUCCESS, ERROR, or CANCELLED), as a Unix epoch timestamp in milliseconds. Undefined if not completed.
timeoutMS?: number;
deadlineEpochMS?: number; // Computed deadline from start time + timeoutMS
deduplicationID?: string; // Cleared on completion
priority: number; // 0 = highest (unset)
queuePartitionKey?: string;
dequeuedAt?: number;
delayUntilEpochMS?: number; // When a DELAYED workflow becomes ENQUEUED
forkedFrom?: string;
wasForkedFrom?: boolean;
parentWorkflowID?: string;
attributes?: Record<string, unknown>; // Custom attributes set at creation
scheduleName?: string; // Schedule that enqueued this workflow, if any
applicationName?: string; // Owning application
}Listing Steps
const steps = await DBOS.listWorkflowSteps(workflowID, { limit: 100, offset: 0 });
if (steps) {
for (const step of steps) {
console.log(`Step ${step.functionID}: ${step.name}`);
if (step.error) console.log(` Error: ${step.error}`);
if (step.childWorkflowID) console.log(` Child: ${step.childWorkflowID}`);
if (step.startedAtEpochMs && step.completedAtEpochMs) {
console.log(` Duration: ${step.completedAtEpochMs - step.startedAtEpochMs}ms`);
}
}
}
Each StepInfo exposes: functionID, name, output, error, childWorkflowID, startedAtEpochMs, completedAtEpochMs. Returns undefined if the workflow is not found.
listWorkflows, listQueuedWorkflows, and listWorkflowSteps are subject to the observabilityQueryTimeoutMs statement timeout (30 seconds by default; list queries with workflowIDs set are exempt) and throw DBOSQueryTimeoutError if a query exceeds it.
To optimize performance, set loadInput: false and loadOutput: false on listWorkflows when you don’t need workflow inputs or outputs.
Reference: Workflow Management