Skip to main content

Threshold Enforcement Model

Every workflow can carry a maximum cost per run and a maximum execution time. Enforcing them raises a subtle problem — the platform doesn't run the workflow, the engine does — and the solution is a layered model whose governing concern is keeping platform and engine in sync.

The consumption signal

The mechanism starts with a signal the platform already has. On every /logs response, the core returns the run's running tally: max_time, time_consumed, max_cost, cost_consumed, and an abort flag. Enforcement uses >=, not strict >: reaching a limit exactly is a breach. Because Agent and Log nodes log on every step, the workflow is continuously told whether it's over budget.

Three layers

Enforcement is layered so that no single failure lets a run exceed its limits unchecked:

  1. Workflow self-termination (primary). The Circus n8n nodes read abort; when it's true, they call /terminate and stop. Prompt, but dependent on the workflow cooperating.
  2. Operator termination. An operator can manually terminate a running or queued execution from the UI.
  3. Reconciler backstop. A background service independently inspects running executions and remotely stops any that have breached their limits but failed to self-terminate.

The core reports consumption so the engine can self-terminate promptly — but enforcement does not depend on it doing so. If layer 1 misfires (the node didn't check the flag, or the terminate call didn't land), layer 3 still catches it.

Why layered rather than authoritative

A single authoritative enforcer would have to choose between two bad options: block the engine synchronously (a race that can kill a workflow before it finishes gracefully) or trust the engine entirely (which fails silently when the engine misbehaves). The layered model avoids both — prompt cooperative self-termination for the common case, an independent backstop for the rest — all under the Truthfulness Invariant: the platform never declares a run terminal while the engine might still be executing. The reconciler article covers that backstop in depth.