Repository navigation
Description
Problem
nixos/services/power-guard/power-guard.py exists for one reason (issue #1687): UPower hybrid-slept amd-6 for 2h40m on a single glitched battery reading (2026-10-28), so the guard only fires the sleep itself after a sustained critical state — 300s at/below 5%, 60s at/below 2%.
Its three timing overrides are parsed at import with bare float() and never validated (power-guard.py:36, :41, :42):
POLL = float(os.environ.get("POWER_GUARD_POLL", "15"))
CONFIRM = float(os.environ.get("POWER_GUARD_CONFIRM", "300"))
EDGE_CONFIRM = float(os.environ.get("POWER_GUARD_EDGE_CONFIRM", "60"))and consumed unchecked at :174/:176 (now - since >= CONFIRM / >= EDGE_CONFIRM) and :185 (time.sleep(POLL)). Consequences:
POWER_GUARD_CONFIRM=0(or any negative, orEDGE_CONFIRM=0) silently deletes the confirmation step.critical_sinceis set tonowon the first critical sample andnow - critical_since >= 0is immediately true, so the guard fires hybrid-sleep on the first glitch sample — exactly the single-sample failure it was built to prevent.- A malformed value (
POWER_GUARD_POLL=abc) crashes the daemon at import with a rawValueErrortraceback. The unit (nixos/services/power-guard/default.nix) runsRestart = "always", so this is a silent crash loop: the guard is simply absent, with no inhibitor held and no actionable log line naming the bad variable. POWER_GUARD_POLL=-1crashes at the firsttime.sleep(POLL)(ValueError: sleep length must be non-negative);POLL=0busy-spins the poll loop against sysfs.
The NixOS module sets none of these variables, so production runs the defaults today — this is a latent trap on a documented operator surface (the module docstring advertises them as "Threshold/timing overrides"), one typo'd drop-in or leftover test value away from either recreating the 2026-10-28 incident or disabling the guard outright.
Evidence (verified this run)
Probe on the laptop, script taken byte-identical from origin/main @252d430853, fake sysfs via the documented POWER_GUARD_SYSFS hook (BAT0: capacity 3, status Discharging; ACAD: online 0), POWER_GUARD_NO_INHIBIT=1, POWER_GUARD_SLEEP_CMD pointed at a marker file (probe dir ~/git/fleet/probe-power-guard):
- A —
POWER_GUARD_CONFIRM=0,POLL=0.2: log showsCRITICAL state entered (cap=3 tte=None); confirmingfollowed in the same second byCONFIRMED: critical sustained 0s at cap=3and the sleep command fired (marker written). The "sustained" requirement was 0 seconds. - E —
POWER_GUARD_CONFIRM=-5: same — fires on the first sample. - B — control,
POWER_GUARD_CONFIRM=300:CRITICAL state enteredand no fire within the run window (marker absent). The confirmation logic itself works; only the override surface is unguarded. - C —
POWER_GUARD_POLL=abc:ValueError: could not convert string to float: 'abc'at power-guard.py:36, process exits before the startup log line. - D —
POWER_GUARD_POLL=-1:ValueError: sleep length must be non-negativeat power-guard.py:185 (time.sleep(POLL)).
Dedup: power-guard issue search (open + closed) finds only #1687 (the original feature request this daemon implements) — nothing covers the override-validation gap. There is also no test file for the daemon anywhere in the repo (only power-guard.py, default.nix, and the host wiring reference it), despite the script shipping dedicated test hooks (POWER_GUARD_SYSFS, POWER_GUARD_NO_INHIBIT, POWER_GUARD_SLEEP_CMD).
Why it matters
This daemon is the safety net for the fleet's primary execution host. Its failure modes here are the worst kind: silent. A zero/negative confirm turns it back into the single-sample actor it replaced; a malformed value removes it entirely under a restarting unit that looks "active" from a distance. Fail-closed parsing (refuse to start with a named error, or clamp to safe minimums) is the house pattern for exactly this class (cf. the fleet-config validation issues).
Acceptance criteria
-
POWER_GUARD_POLL,POWER_GUARD_CONFIRM, andPOWER_GUARD_EDGE_CONFIRMare parsed through one validating helper: non-numeric, NaN/inf, zero, and negative values are rejected with a single startup error naming the variable and the offending value (no raw traceback), OR clamped to documented safe minimums — triage picks one behaviour and applies it uniformly to all three. - With any rejected override the daemon exits non-zero before engaging in polling, so the failure is visible as a failed unit rather than a crash loop.
- Valid overrides and the built-in defaults behave exactly as today (probe scenarios A–E above inverted: A/E can no longer fire on the first sample; B unchanged).
- New tests exercise the parser and the fire/no-fire behaviour through the existing
POWER_GUARD_SYSFS/POWER_GUARD_NO_INHIBIT/POWER_GUARD_SLEEP_CMDhooks (fake sysfs, stubbed sleep command), and are wired into a repo check (flake check or the scripts-test venue — triage's call).
Activity
developing-today commentedon Nov 6, 2026
CODE-1952
dezren39 commentedon Nov 6, 2026
🤖 Agent note · filed
dezren39 commentedon Nov 6, 2026
🤖 Agent note · picked up
1a180ae5-384f-4e71-8d77-08f7b1652c75ses_e5e4fe9e3bbffe8g6yfK5boh3j· task 1094636 remaining items
dezren39 commentedon Nov 6, 2026
Parked — task 10951 (lane code-s) resumed PR #6485: Codex re-review of head
4ed01981b2is complete with no findings, and both earlier Codex P1 findings plus both CodeRabbit findings are dispositioned (one CodeRabbit item tracked separately in issue #6502). The only remaining gate is CI: scripts-test run 42205146600 was still queued after a 5-minute poll. Task 10951 is parked for 1200s; on resume, merge PR #6485 if that run is green.dezren39 commentedon Nov 6, 2026
Resumed — task 10951 (lane code-s) re-verified PR #6485 fresh at 11:40Z: PR is OPEN, mergeable, head
4ed01981b2unchanged; Codex review state on that head shows no findings and no unresolved findings, and both earlier Codex P1 findings plus both CodeRabbit findings carry disposition replies (one CodeRabbit item tracked separately in issue #6502). Issue #6477 is OPEN with no hard-stop labels. The only remaining gate is CI: scripts-test run 42205146600 (created 10:45Z) was still queued after another 5-minute poll. Task 10951 is parked for 1200s; on resume, merge PR #6485 if that run is green.dezren39 commentedon Nov 6, 2026
🤖 Agent note · picked up
Merge pull request #6485 from developing-today/queue/10951-6477-power…
dezren39 commentedon Nov 6, 2026
🤖 Agent note · done