Skip to content

Runs

A run is a single execution of a workflow definition – it tracks the live state of every step from creation to terminal status.

WorkflowRun

When you start a workflow, the engine creates a WorkflowRun with all steps initialized to pending. The run holds mutable state that evolves as events arrive.

Key fields:

FieldTypePurpose
RunIDstringUnique execution identifier
WorkflowIDstringName of the workflow definition
StatusRunStatusCurrent lifecycle state
Stepsmap[string]StepStatePer-step mutable state
Inputjson.RawMessageOriginal user-supplied payload
CreatedAttime.TimeWhen the run was created (UTC)
ParentRunIDstringSet for child sub-workflow runs
Deadline*time.TimeWorkflow-level timeout deadline

Run Status State Machine

A run progresses through these states:

    stateDiagram-v2
    [*] --> Pending
    Pending --> Running: engine claims run
    Running --> Completed: all steps succeed
    Running --> Failed: step fails permanently
    Running --> Cancelled: external cancellation
    Running --> Compensated: saga rollback succeeds
    Running --> CompensateFailed: saga rollback fails
    Completed --> [*]
    Failed --> [*]
    Cancelled --> [*]
    Compensated --> [*]
    CompensateFailed --> [*]
  
StatusMeaning
pendingCreated but not yet claimed by the engine
runningEngine is actively scheduling steps
completedAll non-auxiliary steps finished successfully
failedA step failed permanently (retries exhausted, no compensation)
cancelledCancelled via API, CLI, or CancelOn event
compensatedFailed but saga compensation succeeded
compensate_failedCompensation itself failed

All statuses except pending and running are terminal – once reached, the run never changes state again.

Step Status States

Each step within a run has its own status:

StatusMeaning
pendingNot yet ready (dependencies unsatisfied)
queuedDispatched to NATS, waiting for a worker
runningWorker is executing the task
completedFinished successfully with output
failedFailed permanently
skippedBypassed via SkipIf condition
cancelledRun was cancelled while step was in progress
recoveredFailed but recovered via OnFailure handler

Input and Output

Run input is an arbitrary JSON payload supplied when starting the workflow. It is preserved on the WorkflowRun so retries can reuse it. Steps with no dependencies receive the run input as their task input.

Step output is stored as raw bytes on StepState.Output. Downstream steps receive the output of their dependencies as input. For steps with multiple dependencies, the engine assembles a merged input payload.

Starting a Run

Via CLI:

dagnats run start my-workflow '{"key": "value"}'

Via API:

runID, err := svc.StartRun(ctx, "my-workflow", inputJSON)

Inspecting a Run

dagnats run get <run-id>
dagnats run list --workflow=my-workflow --status=running

The get command shows the run status, each step’s status, and timing information. The list command filters runs by workflow name, status, and time range.

Cancelling a Run

dagnats run cancel <run-id>

Cancellation transitions the run to cancelled and terminates any in-flight steps. Steps that have already completed retain their output. Steps that are pending or queued are moved to cancelled without execution.

Workflows can also self-cancel via the CancelOn builder option, which watches for a matching external event.

Related pages