Open MercatoDocsSearch docsAPI reference

Framework

Run Outcomes

A workflow can reach its end after an optional write failed. Read status to understand control flow and outcome to decide whether the business operation actually succeeded. Older runs can have no recorded outcome.

A workflow run carries two independent answers about how it went.

FieldQuestion it answersWho reads it
statusDid it reach the end?control flow – the executor, retry/cancel guards, the failure queue, third-party subscribers
outcomeDid everything it attempted actually happen?operators, KPIs, triage

Before outcome existed, one enum was asked both questions, so it answered neither honestly: a run that swallowed three failed writes and a clean run both reported COMPLETED.

status is untouched by this feature. outcome is additive and nullable – null while the run is still going, and null for ever on a row written before outcomes existed. Nothing was backfilled: a fabricated verdict would be the same dishonesty in the other direction.

The vocabulary

outcomeMeaning
successReached END. Nothing failed, nothing was suppressed.
success_with_warningsReached END and did everything it was asked to, but something is worth reading – a step skipped by design, for instance.
partial_failureReached END, but at least one activity or step failed and was tolerated.
failureDid not reach END.
cancelledA human stopped it.
compensatedRolled back.

The invariant

A run that suppressed at least one failure MUST NOT be success.

It holds by construction. resolveRunOutcome in packages/core/src/modules/workflows/lib/run-outcome.ts is a pure function and the only decision point – no exit point in the engine assembles a verdict of its own – and it consults the failure evidence before it can return success. It is covered by its own test (lib/__tests__/run-outcome.test.ts), which sweeps every terminal status against every evidence shape.

What counts as evidence

lib/run-outcome-evidence.ts counts, under the run's own tenant and organization:

EvidenceWeightWhy
StepInstance rows in status FAILEDfailureA step row becomes FAILED whether or not the run went on to tolerate the failure. Tolerating a failure is a routing decision, not a reason to forget it happened.
ACTIVITY_FAILED eventsfailureA transition's activities run leaving their source step, whose row has already exited COMPLETED. A transition-level continueOnActivityFailure therefore leaves no failed step row anywhere – this event is the only trace.
StepInstance rows in status SKIPPED, STEP_SKIPPED eventswarningSkipped by design.

STEP_FAILED events are deliberately not counted: they are one-to-one with a FAILED row, and counting both would double-count one failure.

Evidence is read only when the run terminates COMPLETED. cancelled, compensated and failure are decided by the lifecycle alone, so a failing run pays no extra queries on its way out.

Known imprecision

A run that failed, was retried, and then completed still carries its pre-retry ACTIVITY_FAILED rows, so it reports partial_failure. The engine records no attempt boundary to subtract them by. Over-reporting a degraded run is the safe direction for a change whose entire purpose is to stop under-reporting one.

The enabling fix

A verdict needs evidence, so a tolerated failure must still be recorded as a failure. handleAutomatedStep reports a failed sync activity as { status: 'FAILED' } rather than throwing, so executeStep's catch never ran: the StepInstance row stayed ACTIVE for ever and no STEP_FAILED was logged. markStepInstanceFailed (lib/step-handler.ts) is now the one place a step row becomes FAILED, on both the reported and the thrown path, and is idempotent.

This also repaired a second bug: because the row stayed ACTIVE, POST /api/workflows/instances/[id]/rerun-step refused it with 409 WORKFLOW_STEP_STILL_PARKED – rerun-from-step could not rerun exactly the step it exists for.

Recovery: partial_failure is not retryable as a whole run

Retrying replays the graph, which would re-run every part that already succeeded – duplicating their effects in order to re-attempt the parts that did not. So:

isRetryableRunOutcome in lib/run-outcome.ts states this in one place.

Consumers

Compensation timestamps

COMPENSATED used to have no terminal timestamp at all – compensation-handler flipped the status and completeWorkflow returned before its own completedAt assignment – so a compensated run belonged to no KPI time window and its duration was unmeasurable. The outcome write now stamps completedAt on that path, and on the partial-compensation path (status back to FAILED), which had the same gap. An instant that was already recorded is never moved, and CANCELLED is excluded because cancelledAt is its terminal instant.

COMPENSATED therefore joins WORKFLOW_TERMINAL_STATUSES, and the rollup reports runsCompensated as its own number – neither a success nor an ordinary failure. Runs compensated before this fix still carry a null timestamp and, exactly as before, fall into no window: nothing is backfilled.

Previous: Workflows Framework · Next: Run State Presentation