Skip to content

Probe sudo non-interactively so unattended updates cannot hang - #9875

Closed
konsorsiumai wants to merge 1 commit into
omacom:quattrofrom
konsorsiumai:fix/update-stay-awake-sudo-probe
Closed

konsorsiumai wants to merge 1 commit into
omacom:quattrofrom
konsorsiumai:fix/update-stay-awake-sudo-probe

Conversation

@konsorsiumai

Copy link
Copy Markdown

Problem

omarchy update run non-interactively (scripts, cron, AI agents — a workflow the manual explicitly supports) hangs for exactly 5 minutes and then aborts with "Something went wrong during the update!". By that point the pre-update snapshot has already been created, so the user is left with a confusing failure and no update.

Root cause

Three pieces conspire:

  1. omarchy-update re-executes itself under script -qefc ... /tmp/omarchy-update.log for logging, so every step runs with a PTY on stdin.
  2. omarchy-update-stay-awake start() picks its privilege runner with [[ -t 0 ]] — which is therefore always true under the logging PTY — and runs sudo -v.
  3. sudo -v cannot complete without typed input: on current Arch sudo it prompts even when NOPASSWD: ALL is granted, waits passwd_timeout (default 300 s), then fails. set -e plus the ERR trap abort the whole update.

Journal evidence from a real machine: three failed update attempts at 00:27–00:28, and one that hung from 01:01:58 to exactly 01:07:01 (≈ passwd_timeout) before aborting right after the snapshot step.

Reproducer on an affected system (returns nothing until killed, 300 s unattended):

timeout 12 script -qefc 'omarchy-update-stay-awake start' /dev/null

Fix

Replace the tty guess with a capability probe:

if sudo -n true 2>/dev/null; then
  inhibit_runner=(sudo)
else
  inhibit_runner=(pkexec)
fi
  • Non-interactive by construction — it can never wait on input.
  • Interactive users with valid tickets or NOPASSWD keep the sudo path.
  • Everyone else gets the pkexec dialog: the branch that already existed for non-tty callers but could never trigger during an update, because the logging PTY always defeated the [[ -t 0 ]] check.

Tests

test/shell.d/update-lock-test.sh updated: the sudo stub handles the -n true probe, and the terminal-section assertion now verifies the non-interactive probe instead of sudo -v. All 7 assertions pass.

Related (not in this PR)

omarchy-sudo-keepalive (sourced by omarchy-pkg-install / omarchy-pkg-aur-install) opens with a bare sudo -v and can hang menu-driven package installs the same way while passwordless sudo is enabled. Happy to file or fix that separately.

@chessing234

Copy link
Copy Markdown
Contributor

hey — this looks like a duplicate of #12900 (same stay-awake sudo -v hang). mind closing in favor of that?

@omarchybot omarchybot added the bug Something isn't working label Sep 27, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Thanks for the clear write-up and reproducer. The hang you describe was real, and quattro no longer has it, so this pull request has nothing left to fix there.

What was checked. On a worker built from the Omarchy ISO, set up the way #9066 describes (a passworded %wheel ALL=(ALL:ALL) ALL rule beside a NOPASSWD: ALL rule, so sudo -n -v fails with "a password is required"), I ran bin/omarchy-update-stay-awake start under script with a fresh sudo timestamp at three revisions:

  • this branch's fork point (d3d23fdd): stopped at [sudo] password for omarchy: and failed, which reproduces the bug;
  • this pull request's head (41ef4c91): started the inhibitor without a prompt;
  • current quattro: also started the inhibitor without a prompt, through sudo -N -b -- systemd-inhibit ….

Why quattro is already fixed. 35b318ed0 (Complete command-scoped authentication across update phases) removed the [[ -t 0 ]] / sudo -v block this pull request edits, and #13323 (e1614f2bd) made omarchy-update authorize once by running sudo /usr/bin/true rather than sudo -v, for exactly the verifypw=all reason you identified. The terminal branch of start_locked in bin/omarchy-update-stay-awake now runs the inhibitor as a command, which a NOPASSWD rule covers. That is also why this pull request now conflicts: the code it changes is gone, and porting it would add nothing quattro does not already do.

The sudo -v you flagged in bin/omarchy-sudo-keepalive is still there, but it is outside the update path, so it is a separate question from this pull request.

Second opinion. Codex Medium reviewed the pull request against quattro and agreed that the bug is already fixed there and that the pull request has no defect for the case it targets. Independence is not guaranteed. It also pointed out that 35b318ed0 was the commit that removed the sudo -v, which I confirmed.

Next. This is waiting on the maintainer, with a recommendation to close it as already fixed on quattro. #9066 looks fixed by the same commits and could be closed with it.

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

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants