Skip to content

power-guard: a dead systemd-inhibit child is never noticed — held stays true forever, engage() is a no-op, and the machine is silently unguarded #6534

Closed

Description

@dezren39

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 when self.proc is not None (:154-155); otherwise Popens systemd-inhibit … sleep infinity (:160-172), discards its stdout/stderr to DEVNULL (:170-171), and logs "engaged" (:173). Nothing ever calls poll() / 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 place self.proc returns to None (plus terminate() without wait()).
  • 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) yet inh.held == True; a second engage() did not invoke systemd-inhibit again (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() clears held — 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. held reflects poll() is None for 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

  1. added
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    task/triageQueue packet kind: verify, reproduce, and route this item
    source/creatorFiled by the new-issue-creator job
    on Nov 6, 2026
  2. developing-today commented on Nov 6, 2026

    @developing-today
    Contributor
  3. added
    priority/normalOrdinary priority (the default)
    area/nixosNixOS modules and machine configuration
    app/power-guardnixos/services/power-guard battery confirmation daemon
    on Nov 6, 2026
  4. dezren39 commented on Nov 6, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · state: filed

  5. added
    work/assignedQueue worker lifecycle state
    queue/claimedQueue worker lifecycle state
    and removed on Nov 6, 2026
  6. 152 remaining items

  7. added
    status/parkedDeliberately paused with a recorded resume condition
    work/assignedQueue worker lifecycle state
    and removed
    queue/claimedQueue worker lifecycle state
    on Nov 9, 2026
  8. dezren39 commented on Nov 9, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · handed off

  9. dezren39 commented on Nov 9, 2026

    @dezren39
    MemberAuthor

    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.

  10. dezren39 commented on Nov 9, 2026

    @dezren39
    MemberAuthor

    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).

  11. dezren39 commented on Nov 9, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · handed off

  12. dezren39 commented on Nov 9, 2026

    @dezren39
    MemberAuthor
    \n## Triage verdict — REAL AND CURRENT (fix task 14266)\n\nRe-verified against current main before fix: nixos/services/power-guard/power-guard.py still had the filed failure (engage() early-return on non-None proc, held = proc is not None, no poll()/wait(), release() terminate without wait). No open fix PR existed.\n\nFix: PR #8025 (branch fix/6534-power-guard-dead-child) — held reflects poll() is None, engage() detects dead child, logs exit loudly, reaps and re-engages; release() reaps via wait() with kill fallback; tests cover dead/live/stub/release paths. Existing 8 tests still pass (13 total OK).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

app/power-guardnixos/services/power-guard battery confirmation daemonarea/nixosNixOS modules and machine configurationkind/bugSomething isn't working (prefixed form of the classic bug label)priority/normalOrdinary priority (the default)queue/parkedQueue task is parked (waiting on CI, time, or an event)source/creatorFiled by the new-issue-creator jobstatus/parkedDeliberately paused with a recorded resume conditionstatus:donetask/triageQueue packet kind: verify, reproduce, and route this itemwork/assignedQueue worker lifecycle state

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions