Skip to content

power-guard: release() blocks the sampling loop up to ~10s reaping a stalled child, delaying the confirmed sleep command (PR #8025 review finding) #8183

Closed

Description

@dezren39

Finding (unaddressed PR review comment)

On PR #8025 (fix(power-guard): detect dead systemd-inhibit child, re-engage loudly, for issue #6534), CodeRabbit raised a stability finding that was never fixed or replied to:

Keep sampling while a stalled child is reaped. If systemd-inhibit does not exit promptly, release() can block the loop for about 10 seconds. This delays the next sample or the confirmed sleep command. Handle stalled reaping without blocking sampling, and confirm inhibitor release before issuing sleep.

No-response evidence

Still-live evidence (PR head 2a6abfda81, read 2026-11-10)

nixos/services/power-guard/power-guard.py:

  • _reap() (lines 153–175) waits synchronously: proc.wait(timeout=5), and on timeout escalates to kill() and waits another 5 seconds — up to ~10 seconds of blocking in the caller.
  • release() calls _reap() synchronously (line 253), and main() calls release() inline in the sampling loop — both on the recovery path (line 292) and, critically, on the confirmed-sleep path (lines 310–312), where the sleep command is only issued after release() returns. A stalled child therefore delays an already-confirmed emergency sleep by up to ~10 seconds on a critical battery, and delays every other sample while reaping.

Note the interaction with the companion finding from the same review (release forgetting a still-running child): the fix must keep sampling/reaping from blocking the loop without dropping the requirement that inhibitor release is confirmed before the sleep command is issued.

Acceptance criteria

  • Reaping a stalled systemd-inhibit child no longer blocks the sampling loop for the full double-wait; sampling continues while reaping is pending, and the confirmed-sleep path still does not issue the sleep command until inhibitor release is confirmed; or the current behavior is resolved by a documented decision recorded on this issue.
  • The existing timeout and kill-escalation safeguards are preserved.
  • Regression coverage: a fake child that ignores terminate/kill exercises the non-blocking reap path in test_power_guard.py.

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
    on Nov 10, 2026
  2. developing-today commented on Nov 10, 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 10, 2026
  4. dezren39 commented on Nov 10, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · filed

  5. dezren39 commented on Nov 10, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · parked awaiting triage — Agent: queue worker (repo-worker-code), lane code-u — Session/ID: task 14652, repo-queue-worker-shift-u 2026-11-10 run. Task 14652 (triage) for issue #8183. Fresh check: issue #8183 OPEN, labels: kind/bug, task/triage, status/needs-triage, priority/normal, queue/queued, area/nixos, source/pr-comment-review, app/power-guard. triage belongs to the triage step (#8097 rule 3).

  6. added
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    status/parkedDeliberately paused with a recorded resume condition
    and removed
    task/triageQueue packet kind: verify, reproduce, and route this item
    on Nov 10, 2026
  7. 24 remaining items

  8. dezren39 commented on Nov 11, 2026

    @dezren39
    MemberAuthor

    Parked — Queue task 14655 is parked for 30 minutes. PR #8188 targets the Drew-owned branch of #8025, so this lane will not merge it there. Checks are pending. Before integration, establish an authorized path and verify that the proposed handling preserves confirmed inhibitor release, including the concern in #8182.

  9. dezren39 commented on Nov 11, 2026

    @dezren39
    MemberAuthor

    state: in-progress
    task: 14655
    lane: code-u
    pr: 8188
    outcome: resumed_fix_pr_exists

    Task 14655 (issue #8183) resumed by lane code-u. The fix already exists as PR #8188 (lane code-w) targeting PR #8025's branch fix/6534-power-guard-dead-child — the only place _reap() exists. Fresh verification this shift: full diff read against the #8183 acceptance (0.5s inline grace, background kill-escalation reap, held stays true while a reap is in flight so no second inhibitor stacks — the #8182 requirement — and the confirmed-sleep path issues sleep only after reap_settled()); python3 -m unittest test_power_guard at head 91de65d: 14 tests OK, including the FakeStalledProc regression. Codex review on PR #8188 failed on Codex usage limits and posted no findings; CodeRabbit skipped (non-default base). PR #8025 carries no held/user/owned/do-not-merge labels, so integration proceeds: merging PR #8188 into #8025's branch now.

  10. added
    queue/claimedQueue worker lifecycle state
    and removed
    status/parkedDeliberately paused with a recorded resume condition
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    on Nov 11, 2026
  11. added a commit that references this issue on Nov 11, 2026
  12. dezren39 commented on Nov 11, 2026

    @dezren39
    MemberAuthor

    state: done
    task: 14655
    lane: code-u
    pr: 8188
    outcome: fixed_merged

    Task 14655 complete: PR #8188 merged into PR #8025's branch fix/6534-power-guard-dead-child as 88d1022 (PR #8025 head verified at that commit). The #8183 acceptance is met on that branch: release() no longer blocks the sampling loop on a stalled child (0.5s inline grace, background kill-escalation reap), the confirmed-sleep path still waits for reap_settled() before issuing sleep, the timeout/kill safeguards are preserved with a loud UNCONFIRMED log, and the FakeStalledProc regression test covers it — full suite 14 tests OK in a fresh run this shift. The original CodeRabbit finding thread on PR #8025 was dispositioned with the fix summary.

    This issue stays open until PR #8025 itself merges to main (that PR is #6534's, outside this task's scope); the fix rides with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    app/power-guardnixos/services/power-guard battery confirmation daemonarea/nixosNixOS modules and machine configurationeffort/sSmall: expected under 2 hours of workkind/bugSomething isn't working (prefixed form of the classic bug label)priority/normalOrdinary priority (the default)source/pr-comment-reviewFiled by the pr-comment-review jobstatus:donetask/small-fixQueue packet kind: bounded fix with reproduction and targeted tests

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions