Skip to content

Two-phase drain

A drain separates two decisions: when to stop taking work, and when to stop work already running. The first phase refuses new intake while in-flight assignments and project runtimes continue. The second stops the runtimes. Between the two, the node reports and finishes its work and takes no new work.

This page covers what each phase refuses, what carries on, and how the node moves between them.

The two phases

flowchart TB
  subgraph CP["CONTROL PLANE"]
    direction LR
    DISP["Dispatch"]
    ING["Status and telemetry ingest"]
  end
  subgraph NODE["DATA PLANE NODE"]
    direction TB
    RDY{{"Readiness:<br/>ready for pull?"}}
    WRK["Workers holding<br/>claimed assignments"]
    ORCH["Runtime orchestrator"]
    MUX["Telemetry mux"]
  end
  subgraph RT["PROJECT RUNTIMES"]
    direction LR
    K["Project kernels"]
  end
  DISP -->|"intake: closed in phase one"| RDY
  RDY --> WRK
  WRK -->|"in-flight work continues"| ORCH
  ORCH -->|"stopped in phase two"| K
  WRK -->|"status reports continue"| MUX
  K -->|"evidence continues until stopped"| MUX
  MUX --> ING

Phase one cuts one edge: Readiness: ready for pull? closes intake from Dispatch. Every other path stays open, so Workers holding claimed assignments finish and report through Telemetry mux. Phase two cuts the edge from Runtime orchestrator to Project kernels, and it is entered only with a shutdown requested.

What phase one refuses

Refused Continues
New assignment intake, because readiness reports the node as unready for pull Assignments already claimed
Nothing else Status reports, telemetry delivery, evidence collection, lease renewal, heartbeats

The readiness probe is the mechanism: a draining node reports a status other than ready, the cycle's readiness check for pull fails, and the watch step is skipped. The node keeps heartbeating, so the control plane sees a live node that is not taking work.

What phase two does

With a shutdown requested and project runtimes still active, the node stops all of them with the recorded shutdown reason and reports the stop in the drain state:

{
  "contract_version": "xratud.runtime_drain.v1",
  "reason": "operator_requested",
  "stopped": 3,
  "active_count": 0,
  "desired_generation": 2,
  "observed_generation": 2,
  "finalization_evidence_refs": ["ev-7c41...", "ev-7c42..."],
  "cleanup_reason_code": "shutdown_drain_stop_all",
  "decommission_state": "draining",
  "decommission_reason_code": "DECOMMISSION_HARD_STOP"
}

stopped is how many runtimes the pass stopped and active_count is the number left, so a drain that needs another pass is visible in the document.

Returning from a drain

A drain entered from backpressure clears itself. The node leaves DRAINING for ACTIVE when the drain signal has gone, the queue is empty, no runtimes are active and bootstrap is complete, and it reports drain_complete as it does. While the signal has cleared and work is still finishing it reports drain_inflight, which distinguishes a node finishing a drain from a node still being held back.

An operator drain clears when the operator resumes the node. See Shutdown and drain.