The run loop¶
The loop runs one cycle, decides what to do with the result, waits, and repeats. Three outcomes exist and they are handled differently, which is what decides whether a node keeps running, backs off, or fails.
The three outcomes¶
flowchart TB
A["Run one cycle"]
B["Cycle returned<br/>ready to exit?"]
C["Return: clean exit"]
D["Transient control-plane error"]
E["Mark degraded, sleep the backoff,<br/>skip the interval, run again"]
F["Any other exception"]
G["Raise: the process fails"]
H["Sleep the interval, run again"]
A --> B
B -->|yes| C
B -->|no| H
A --> D --> E
A --> F --> G
What the loop consults¶
flowchart LR
subgraph LOOP["RUN LOOP"]
direction TB
CY["Cycle"]
IV["Interval"]
BO["Backoff<br/>deterministic, jittered"]
end
CPC{{"Control-plane client<br/>classifies each error"}}
TS[("Transport state<br/>active or degraded_cp_unreachable")]
CY --> CPC
CPC -->|"transient"| TS
TS --> BO
CY -->|"ready to exit"| EXIT["Return"]
The loop does not judge an error itself. The control-plane client classifies it, and only a transient answer reaches the transport state that selects the backoff; anything else is raised out of the loop.
A clean exit is a cycle result¶
Shutdown is reported by a cycle rather than delivered as an interrupt. The loop returns when a cycle says it is ready to exit, so the node stops between cycles with its phases complete rather than partway through one.
That is why draining is a state the node passes through rather than a signal it races against. See Recovery, drain, and shutdown.
A transient control-plane error replaces the interval¶
When a cycle fails on a transient control-plane error, the loop computes the backoff for the loop operation, records the transport as degraded, sleeps the backoff, and starts the next cycle immediately after it.
The ordinary interval is skipped in that case. A node recovering from an outage therefore retries on its backoff schedule rather than adding the interval on top, so it catches up as fast as its backoff allows.
The backoff is exponential, capped, never shorter than any retry_after the
control plane asked for, and deterministically jittered from the node's identity
and the attempt. A fleet recovering together spreads rather than arriving as one
wave. See
Detection.
Anything else fails the process¶
A non-transient exception is raised rather than absorbed. The process exits and its supervisor restarts it, and the restart is a continuation because the node's identity, cursors and leases are durable.
That choice is deliberate: a loop that swallowed unknown errors would keep running in a state nobody had reasoned about, and its next cycle would act on it.
The interval is the idle cadence¶
A cycle that succeeds sleeps the configured interval before the next one. That interval is the node's baseline rhythm, and it is what heartbeat freshness and watch responsiveness are measured against.
Bounded runs exist for verification¶
The loop accepts a maximum cycle count and returns when it is reached. That is how a node's behaviour is exercised for a fixed number of cycles rather than requiring the loop to be interrupted.
What one cycle contains¶
Five phases, in order, each bounded. See The reconcile cycle and Cycle orchestration.