Skip to content

fix: prevent Linux power inhibitor auth loops (fixes #763) - #784

Merged
1jehuang merged 1 commit into
masterfrom
fix/issue-763-power-inhibitor
Aug 4, 2026
Merged

fix: prevent Linux power inhibitor auth loops (fixes #763)#784
1jehuang merged 1 commit into
masterfrom
fix/issue-763-power-inhibitor

Conversation

@1jehuang

@1jehuang 1jehuang commented Aug 4, 2026

Copy link
Copy Markdown
Owner

Summary

  • make systemd-inhibit use noninteractive Polkit authorization
  • disable Linux inhibition for the process lifetime after the helper exits unsuccessfully
  • preserve normal bounded-TTL refreshes after successful helper exits
  • add regression coverage for the command arguments and failed-helper retry suppression

Root cause

spawn() returned before Polkit authorization completed, so Jcode recorded the helper as acquired. After authorization failed and the child exited, the five-second reconciliation loop launched a new interactive helper indefinitely.

Validation

  • cargo fmt --all -- --check
  • git diff --check
  • cargo test -p jcode-base --no-default-features power_inhibit -j 1 (6 passed)

--- — Jcode agent (automated triage), on behalf of @1jehuang

@greptile-apps

greptile-apps Bot commented Aug 4, 2026

Copy link
Copy Markdown

Greptile Summary

This PR fixes the Linux power inhibitor retry loop. The main changes are:

  • Adds --no-ask-password to the systemd-inhibit command.
  • Tracks child process exit status instead of only checking whether the helper is still running.
  • Disables Linux inhibition for the process lifetime after an unsuccessful helper exit.
  • Keeps normal bounded-TTL refresh behavior after successful helper exits.
  • Adds tests for command arguments and failed-helper retry suppression.

Confidence Score: 5/5

Safe to merge with minimal risk.

The change is narrowly scoped to the power inhibitor module and preserves the successful TTL refresh path. The updated Linux failure path has focused tests for command construction and retry suppression. No functional or security issues were identified.

Files Needing Attention: No files require special attention.

T-Rex T-Rex Logs

What T-Rex did

  • T-Rex captured the initial cargo test run in the power_inhibit_cargo_test.log, which showed the shell wrapper used PIPESTATUS[0] under /bin/sh and produced a bad substitution.
  • T-Rex re-ran the cargo test with bash -lc to obtain a clean, authoritative proof, reporting test result: ok. 6 passed; 0 failed; 0 ignored; 0 measured; 1223 filtered out.
  • T-Rex performed a git diff check and confirmed there were no diff check errors printed.
  • T-Rex ran a cargo fmt check; cargo-fmt was unavailable and the log indicates a rustup component suggestion and skip.

View all artifacts

T-Rex Ran code and verified through T-Rex

Important Files Changed

Filename Overview
crates/jcode-base/src/power_inhibit.rs Updates Linux systemd inhibitor handling to use noninteractive Polkit, disable retries after unsuccessful helper exits, and add focused tests.

Sequence Diagram

sequenceDiagram
participant Reconcile as set_active(true)
participant Inhibitor as PowerInhibitor.acquire
participant Child as systemd-inhibit child
participant State as PowerInhibitor state

Reconcile->>Inhibitor: request active inhibitor
Inhibitor->>Child: try_wait/status existing handle
alt Linux child exited unsuccessfully
    Inhibitor->>State: release handle
    Inhibitor->>State: "available = false"
    Inhibitor-->>Reconcile: stop retrying this process
else handle running and fresh
    Inhibitor-->>Reconcile: keep existing helper
else missing/stale/successfully exited helper
    Inhibitor->>Child: "spawn systemd-inhibit --no-ask-password sleep <TTL>"
    Inhibitor->>State: store handle and acquired_at
end
Loading

Reviews (1): Last reviewed commit: "fix: prevent Linux power inhibitor auth ..." | Re-trigger Greptile

@1jehuang 1jehuang changed the title Fix Linux power inhibitor authentication loop --- *— Jcode agent (automated triage), on behalf of @1jehuang* fix: prevent Linux power inhibitor auth loops (fixes #763) Aug 4, 2026
@1jehuang
1jehuang merged commit 39c07ce into master Aug 4, 2026
8 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant