Repository navigation
Description
Problem
power-guard never notices when its systemd-inhibit child dies. The daemon's only protection against UPower's single-sample CriticalPowerAction is the block inhibitor it holds while it confirms a critical reading (#1687); if that child exits, the guard keeps believing it holds the block for the rest of the process lifetime, logs nothing, and never tries to re-engage — so the machine is exactly as unguarded as if power-guard were not running, while the daemon reports a healthy state.
Evidence
nixos/services/power-guard/power-guard.py @ 2bcd46e0dc:
Inhibitor.engage()(:153-173): returns immediately whenself.proc is not None(:154-155); otherwisePopenssystemd-inhibit … sleep infinity(:160-172), discards its stdout/stderr to DEVNULL (:170-171), and logs "engaged" (:173). Nothing ever callspoll()/wait()on the child.Inhibitor.held(:183-185):return self.proc is not None— handle non-None is treated as lock held, regardless of whether the process is alive.Inhibitor.release()(:175-181) is the only placeself.procreturns toNone(plusterminate()withoutwait()).- Main loop (:208-215): the low-battery path calls
inh.engage()every poll; with a dead child every one of those calls is a no-op.
Verified this run on the laptop (probe ~/git/fleet/probe-pg-inhibit, real power-guard.py, stub systemd-inhibit on PATH):
- Stub exits 1 immediately: after
engage(),inh.proc.poll() == 1(child dead) yetinh.held == True; a secondengage()did not invokesystemd-inhibitagain (stub invocation log: exactly 1 call). The daemon would sit in this state forever. - Control (stub
exec sleep 30):poll() is None,held == True,release()clearsheld— the live path works as intended.
A child can die for ordinary reasons: systemd-inhibit failing to acquire the lock, the inhibitor being killed, a logind restart/reload, or the sleep infinity being signalled. Because stderr goes to DEVNULL, even the child's own complaint is invisible.
Why it matters
The guard exists because of the 2026-10-28 incident (#1687): UPower hybrid-slept the laptop for 2h40m on a glitched reading. A silently dead inhibitor recreates that exact exposure with a false sense of coverage — the unit is active, the log says "INHIBIT(block sleep) engaged", and the first glitched critical sample sleeps the machine. Silent loss of a safety control is worse than the control failing loudly.
Acceptance criteria
- The daemon detects a dead inhibitor child (e.g.
heldreflectspoll() is Nonefor a real process, checked on engage and/or each poll cycle). - On detection it acts, per a stated policy: re-engage the inhibitor (logging the death and the child's exit status loudly) and/or exit non-zero so the unit surfaces as failed — it must not continue indefinitely believing it holds a lock it does not hold.
- The child's stderr is no longer unconditionally discarded, or its exit status is logged on death, so the failure is diagnosable from the journal.
-
release()reaps the child (wait()or equivalent) instead of leaving a zombie. - Tests in
test_power_guard.py(the suite added for power-guard: timing env overrides are never validated — CONFIRM=0/negative fires hybrid-sleep on the first critical sample, malformed/negative POLL crash-loops the daemon #6477) cover: a child that exits immediately is detected and handled; a live child is not disturbed; the NO_INHIBIT stub path is unchanged. - Existing power-guard tests still pass.
Activity
developing-today commentedon Nov 6, 2026
CODE-1986
dezren39 commentedon Nov 6, 2026
🤖 Agent note · state: filed
152 remaining items
dezren39 commentedon Nov 9, 2026
🤖 Agent note · handed off
opencode(lane row 5320)dezren39 commentedon Nov 9, 2026
agent-note:v1 task 14266 lane code-t: picked up and handed off to opencode claimant (lane row 5320). Verified fresh: issue #6534 OPEN labels=['kind/bug', 'task/triage', 'status/parked', 'source/creator', 'priority/normal', 'queue/parked', 'area/nixos', 'work/assigned', 'app/power-guard']; ; no hard-stop labels. Next: claimant launches the bound opencode session.
dezren39 commentedon Nov 9, 2026
Handed off — task 14266 (lane code-v)
Execution lane assigned: opencode (lane row 5320). Checkpointed handed_off and parked 1200s; the laptop opencode claimant launches the bound session. Revalidated fresh via gh this shift: open, no hard-stop labels (held / user/owned / do-not-merge / do-not-auto-edit).
dezren39 commentedon Nov 9, 2026
🤖 Agent note · handed off
fix(power-guard): detect dead systemd-inhibit child, re-engage loudly…
dezren39 commentedon Nov 9, 2026
fix(power-guard): detect dead systemd-inhibit child, re-engage loudly…