Skip to content

Cluster power governor

The governor switches compute servers off when nothing needs them and on again before work is due. Protected servers are always on. Observation is the default; a server it cannot account for is kept on.

What decides that a server is needed

  • Scheduled routines and scheduled batch jobs (every schedule kept on this server, and the WorkerPool queue): a server is needed from the wake lead before its work is due until it is done. A queued job for any worker reserves a free batch slot; with no free slot, every available server is woken.
  • External services, by webhook: POST /api/fleet/power/demand with a lease and a TTL. The vLLM router renews vllm-router:<model> on each request for a model; the servers whose workers report serving that model are kept on while the lease lives.
  • Keep-on hours per server (days and times, in the governor's local time).
  • Running batch jobs and routines on the server, as its worker's heartbeat reports them. The worker leaves out its own process and its model servers (identified by their command line): a model server's demand comes from the router's leases and its load from the facts report.

Workers report; the governor never connects to them

Workers may sit behind NAT or a firewall: they only reach out. Every minute a Worker posts its facts to POST /api/workers/facts with its own token (it can report only its own name; shared tokens cannot establish machine identity):

  • network cards: MAC, IPv4 address and netmask, whether Wake-on-LAN is armed (ethtool on physical devices, probed once per interface state via unprivileged ethtool or sudo -n);
  • the BMC address, probed once when a local IPMI device is present;
  • its model servers (vLLM processes found by their command line): served models, healthy, requests running and waiting.

The governor uses only heartbeats and these facts. A worker is ready for dispatch when it reports in, including while its model is loading so startup and repair commands can run. A server is idle when no job or routine besides the Worker and its model servers runs and every discovered model server reports healthy with nothing running or waiting. A failed or incomplete discovery, or facts older than three minutes, keeps the server on. Last-known wake details for inventory hosts survive long off periods. Only a BMC can confirm that a server is off. Shutdown requires a coordinated API dispatch gate and fresh idle reports after draining; older APIs and heartbeats cannot authorize it.

Switching off and on

  • Off: the governor stops dispatching to the server, waits for a fresh idle heartbeat, rechecks demand, then sends the server's own worker one command. On the machine it refuses while a desktop or terminal is in use, or while a reported Wake-on-LAN card is no longer armed; otherwise it runs sudo -n systemctl poweroff. A refusal keeps the server on and is not retried for thirty minutes.
  • On: a Wake-on-LAN packet to each armed card the worker reported, on that card's own subnet, or the BMC when no armed card is known. If the server does not come up, the BMC is tried once. If that fails too, the server is marked on the WORKERS page and kept on (see "Failed-wake hold" below).
  • A server is switched off only if a way back is known: an armed card or a BMC with credentials.
  • One wake or power-off at a time, Seconds between power actions apart, earliest deadline first.

BMC credentials are never stored in code or in the inventory: set SHAREDDATA_BMC_USER and SHAREDDATA_BMC_PASSWORD in the governor's environment (one pair for the fleet).

WORKERS page: 2) Config

One card per worker, discovered from its account, its reports and the inventory.

  • Edited here: the mode (Always on, Autoscale, Manual: never switched), keep-on hours, and the worker's account: enable or disable it, rotate its token, its git credential, its API access (in Users), delete it.
  • Shown read-only: everything the worker reports (cards, addresses, MACs, Wake-on-LAN, BMC, model servers, system, last report) and how it wakes, as learned.
  • Fleet: Autoscale on or off, wake lead and cool-down (minutes), seconds between power actions.
  • Tokens and credentials: install codes, join tokens, shared worker tokens, command tokens and git credentials.

Saves are validated, written owner-only with a backup of the previous inventory, and picked up by the governor and the API within one cycle, without a restart. Internal inventory fields (including paths and credential references) stay on the server and are preserved when the page saves power policy. Model names that are private filesystem paths are omitted from reports.

Running it

python -m SharedData.Routines.ClusterPowerGovernor --mode observe   # decisions only
python -m SharedData.Routines.ClusterPowerGovernor --mode control   # acts

power.freeze in the state folder suppresses every action. --reset-error HOST (control mode) clears one failed action after its cause is repaired; it sends no power command.

WOL after a slow shutdown

A worker disappearing is not proof of power-off. For an own shutdown followed by OFF_UNCONFIRMED, the controller retains the shutdown timestamp and gives a WOL-only host one delayed second wake_host dispatch: at least 180 seconds after shutdown intent and 60 seconds after the first dispatch. The observed tail on a two-card host was 152 seconds. This margin is a second opportunity, not physical OFF evidence. The immutable wake_episode_started_at and wake_attempts survive restarts and are persisted before network I/O, including failures. There are at most two WOL dispatches (48 packets for a two-card/four-target configuration). The original 900-second inference / 300-second worker deadline is not extended. BMC-capable hosts keep their existing fallback priority and two-window budget, anchored to the episode start; the delayed WOL retry is not offered while the BMC is usable or already tried (if BMC only becomes usable later in the episode, the sequence is WOL, WOL retry, BMC, still within the same deadline). Legacy rows with valid since retain their deadline but do not gain a retry without recorded shutdown/attempt evidence. Unknown age fails closed.

Failed-wake hold

A tracked wake that times out (or whose dispatch fails) sets wake_failed: the server is kept on and the WORKERS page says why. The row records wake_failed_at, wake_failure_error (readiness timeout, readiness timeout after BMC, wake dispatch failed or unknown) and wake_failures, the number of failed wakes since the last tracked successful one. Each failure is counted once and audited as wake_hold_set before the state holding it is saved.

  • Tracked wake succeeds (WAKING -> READY): the hold is cleared and wake_failures returns to 0.
  • Automatic release, first failure only: when wake_failures is 1 and the failure was a Wake-on-LAN readiness timeout, the hold is released after 15 minutes of continuous recovery: the row READY at the start and end of every cycle, every heartbeat of its worker fresh and newer than the failure, machine facts fresh and received after the failure, controller inputs healthy, no freeze. Cycles more than 120 seconds apart, and any cycle without that evidence (missing or stale reports, ERROR, WAKING, STOPPING, unknown power, Manual, freeze, unreadable inputs), start the 15 minutes again. The release is audited as wake_hold_released before it is saved and keeps the failure history (wake_hold_released_at is added). It does not touch the idle timers: cool-down, minimum time on, drain, spacing, the off budget and the shutdown preflight still decide whether the server goes off.
  • Sticky: a second failure without a tracked success in between, a failure after the BMC was tried, a failed dispatch or an unknown history is never released automatically. Clear it with a tracked wake: under the owner's authorization, shut the server down gracefully through the worker-equivalent session/WOL checks (fleet_power.poweroff_command), wait at least 180 seconds after the poweroff command until its heartbeat is gone and SSH no longer connects (a lease posted earlier makes the controller wake it inside the shutdown tail), then POST a unique host-only lease (TTL at most 900 seconds) to /api/fleet/power/demand with the master SHAREDDATA_TOKEN from the controller environment, never logged. Release that lease in finally. If the tracked wake times out, make one separately logged manual-helper WOL attempt with the established targets, then report a physical-access blocker. No forced cuts, no loops.
  • A row held by an older release has no failure time: the first cycle of this release dates the failure then (never from since, which recoveries rewrite) and audits wake_hold_set with adopted: true. Its history is unknown, so it counts as one failure only when the row shows the signature of a single Wake-on-LAN readiness timeout (last_action WAKE, no BMC tried, error readiness timeout or cleared by the passive recovery); otherwise its kind is unknown (sticky). Future or invalid failure times are re-dated the same way.
  • A missing count is inferred only for that legacy signature. An explicitly malformed count or incomplete modern history is conservatively sticky (wake_failures at least 2), including Boolean and floating-point counts. Invalid retained history times become null; an active hold's invalid failure time is re-dated as above. Repairs are audited before saving as wake_history_invalid (or wake_hold_set for re-dating). Valid history and the normal timers are retained.
  • reset_error does not clear wake_failed. Do not hand-edit state or gates, invent WAKING, add fake jobs, or shorten timers to clear a hold.

Controller-only rollout and rollback

Install only the reviewed controller module plus a checked-hash bytecode cache, as an explicit overlay on the installed package (version and RECORD unchanged), after backing up the installed module/cache and their metadata. Restart only systemctl --user restart cluster-power-governor.service, keeping its existing arguments, and check that decisions advance with healthy inputs.

Rollback restores only the saved module/cache and restarts the same unit. It never restores shared state, and restoring an older module does not bring back a hold this release already released. So if a release itself is in question, first set that server to Manual on the WORKERS page (the same validated fleet_power.save_inventory(..., policy_only=True) save the page uses; Manual is protected: false, managed: false), confirm the next decision no longer manages it and proposes no action for it, then restore the module/cache and restart. Manual is the only lever that keeps it on: an unmanaged server's power-state row is dropped, failure history included, so the audit log and the rollout backups are its record. Return the server to Autoscale only after corrected code is deployed and verified, and record that close-out: Manual left set is a failed runbook, not a safe end state.