Skip to main content
Routine runs require an Enterprise Edition license (queues entitlement). A routine run (RoutineRun) is the persisted execution record created each time a routine (workflow template) is triggered. It wraps the underlying job_result row and enriches it with resolved routine metadata (workflowName, agent). Run records are scoped to routines the authenticated user can read — callers without a role see an empty result, never an error.

Types

Field notes

Queries

routineRuns

Returns a paginated list of run records filtered to routines the caller can read.
Arguments Role-less behavior: When the authenticated user has no assigned role, readableRoutines catches the access-control error and returns an empty routine set. Both routineRuns and routineRunsNeedingAttentionCount return their zero-result equivalents ({ items: [], total: 0 } and 0) rather than propagating an error.

routineRunsNeedingAttentionCount

Returns a scalar count of runs currently in waiting_approval state across all routines the caller can read. Intended for nav-badge polling — it executes a single aggregation query against the composite (workflow, state, trigger, createdAt) index.
Returns 0 for role-less users (same graceful path as routineRuns).

Mutations

cancelRoutineRun

Cancels an active or waiting run.
Cancellable states: waiting, active, waiting_approval. Runs in any terminal state (completed, failed, filtered, cancelled) return an error — the resolver uses a compare-and-swap (CAS) update so a concurrent completion cannot be overwritten. On a successful cancel the resolver also attempts a best-effort removal of the pending BullMQ job and clears the session’s stream-active flag.

retryRoutineRun

Re-enqueues a failed or cancelled run, resuming from the step where it stopped.
Retryable states: failed, cancelled. The resolver reads current_step_index from the run’s stored bookkeeping metadata and enqueues a new BullMQ job on the same queue with resumeFromIndex set to that step. Prior step outputs are preserved in the existing job_result row. The run’s error field is cleared and the state transitions to waiting before the job is enqueued. Returns an error for runs that were created before the bookkeeping metadata was introduced (pre-migration rows with no queue_name recorded). Retry semantics summary:
  • The same job_result row is reused (same id, same session).
  • Re-execution begins at the failed step — steps that already completed are not re-run.
  • tries is incremented by the worker on pickup.

Example query

Example mutation

Run state lifecycle

See Job results for the complete state machine, including the waiting_approval non-terminal state (run paused on a tool-approval request) and the filtered and cancelled terminal states.