Skip to content

fix(update): block lid switch during updates - #12419

Open
ansonboby wants to merge 2 commits into
omacom:quattrofrom
ansonboby:fix/update-lid-inhibit
Open

ansonboby wants to merge 2 commits into
omacom:quattrofrom
ansonboby:fix/update-lid-inhibit

Conversation

@ansonboby

@ansonboby ansonboby commented Sep 18, 2026 •

Copy link
Copy Markdown

Summary

Closing the lid suspended the machine mid-update despite the stay-awake inhibitor. omarchy-update-stay-awake took only high-level sleep:idle locks, which logind ignores for the lid switch (LidSwitchIgnoreInhibited defaults to yes).

Adds the low-level handle-lid-switch lock to the mask on the single systemd-inhibit launcher (--what=sleep:idle:handle-lid-switch). Scoped to updates only — normal lid behavior resumes on stop. Deliberately not a global LidSwitchIgnoreInhibited=no drop-in, which would let every stray high-level sleep lock (video players, browsers) block lid-close system-wide.

Rebased onto the reworked update flow. The earlier commit that released the inhibitor just before the orphan prompt has been dropped: quattro's reordering deliberately keeps the inhibitor through the user-facing work (13a4306a, asserted by update-hook-security-test.sh), so releasing it there would undo that guarantee and move stop, which is not this PR's call.

Instead the orphan step now honours OMARCHY_UPDATE_UNATTENDED, which is the shape docs/update-process.md already documents ("-y … suppresses Omarchy confirmation prompts. Interactive review steps (orphan removal, conflict handoff) report and skip instead of blocking") and which omarchy-update-restart and the conflicted-package handoff already implement. The prompt stayed in place for an interactive update — only -y is suppressed — so no ordering moves and the confirmed pacman -Rns removal still runs inside the inhibited window.

One consequence left deliberately: an interactive run still reaches the prompt, so the lid lock covers the moment somebody is reading it. That falls out of keeping the inhibitor through user work, and a prompt that silently expires mid-answer seemed a worse trade than a machine that stays awake while its owner decides. Say the word if you'd rather have it bounded and I'll add the timeout.

Test plan

  • update-lock-test asserts the mask the launcher actually builds, observed through the real update flow (sandboxed omarchy-update with its privileged paths redirected to stand-ins) rather than the shape of the code around it. Reverting the mask to sleep:idle fails that assertion.
  • update-orphan-test runs both prompt cases on a pty, because without one the existing non-interactive guard answers for the unattended case and hides the regression: unattended reports and skips without reaching gum; interactive still reaches gum. Deleting the unattended branch fails the first.
  • update-lock-test, update-sequence-test, update-stay-awake-security-test, update-hook-security-test, update-orphan-test, update-user-path-test, bin-style-test, manifest-entrypoints-test all pass.

Fixes #10203.

@llstrk

llstrk commented Sep 25, 2026

Copy link
Copy Markdown

Automated AI review

Community review: Independent automated community review, unaffiliated with the Omarchy team, intended to help prepare PRs for their review.

Verified: the change addresses the lid-close suspend described in #10203. In systemd v261 logind, a lid close is refused early while a block-mode handle-lid-switch inhibitor is held, independent of LidSwitchIgnoreInhibited. The high-level sleep lock is only consulted when inhibitors are not ignored, and the lid ignores them by default. Both systemd-inhibit invocations in start() now carry --what=sleep:idle:handle-lid-switch. After stop releases the lock, logind's normal lid handling applies again, which matches "normal lid behavior resumes on stop". The new test fails with the previous script (it logs --what=sleep:idle) and passes on this head.

One behavior change worth a decision, and one test gap, follow.

Lid lock now also covers the orphan-package prompt

omarchy-update holds the stay-awake lock from start until stop, and omarchy-update-orphan-pkgs runs inside that window. When orphans exist and stdin and stdout are terminals, it shows gum confirm --default=false with no timeout. It does not check OMARCHY_UPDATE_UNATTENDED, and omarchy-update runs itself under script, so the prompt can appear even with omarchy update -y.

omarchy-update
  stay-awake start          lid lock taken
  package upgrade steps
  omarchy-update-orphan-pkgs
    gum confirm (no timeout)   <- lid closed here, undocked
  stay-awake stop           lid lock released

lid close at the prompt:  before this PR  -> suspends
                          with this PR    -> stays awake until answered

Impact: a laptop closed and packed away while the update waits at this question stays powered, with idle suppressed, until someone answers or cancels. Before this PR, the same lid close suspended the machine at a point where suspending was harmless. This follows from source; it was not tested on hardware.

Suggested change: release the stay-awake lock (or at least its lid part) before the orphan step, so protection covers the package transactions but not the final question. Alternatively, keep the current scope and document the trade-off.

Optional test improvement: the new assertion calls omarchy-update-stay-awake start without the update lock, so it exercises the else branch. A real omarchy update runs under omarchy-update-lock run, which exports OMARCHY_UPDATE_LOCK_FD and selects the other branch. With only that branch's --what reverted to sleep:idle, the new test still passes. Running the assertion under omarchy-update-lock run as well, or asserting the mask from the earlier omarchy-update stub, would cover the branch real updates use.

start() branch Used by Covered by new test
OMARCHY_UPDATE_LOCK_FD set omarchy update no
else direct calls yes

Note: #10205 makes the same two-line --what change for #10203 with a different test.


Review information

Test scope: Source review of the changed script, its callers and upstream systemd v261 logind (v262 unchanged for this behavior). update-lock-test.sh and update-sequence-test.sh ran in an isolated sandbox with stubbed systemd-inhibit, sudo and pkexec, plus a pre-fix negative control and a single-branch mutant. No real logind, polkit or lid hardware was exercised; the lid behavior rests on source and the hardware reproduction reported in #10203. The orphan-prompt effect is source-derived.

AI process: Opus 5.5 Medium coordination and synthesis, independent Opus 5.5 Xhigh and GPT 6 Sol Xhigh technical assessments, Opus 5.5 Medium editorial check.

Opt out: To stop receiving these reviews, reply to this comment saying so.

@ansonboby

Copy link
Copy Markdown
Author

Both points are right — pushed in 1bb09736 (fix(update): release the lid lock before the orphan prompt).

  • Orphan prompt under the lid lock — adopted the first suggested shape: omarchy-update-stay-awake stop (and trap - EXIT) now runs right after omarchy-update-mise, before omarchy-update-orphan-pkgs. Protection covers the package transactions, which are the part that must not be interrupted by a suspend; the final question is no longer allowed to hold a closed laptop awake and idle-blocked indefinitely with --what masks held. Side benefit: the persistent Stay Awake marker is cleared earlier than the reboot offer did, so a long question wait no longer leaves systemd-inhibit --list showing us. The analyze-logs / status steps run without the lock as before.
  • Test branch gap — the --what assertion now runs twice: directly (the else branch) and under omarchy-update-lock run with the update stub recording from OMARCHY_UPDATE_LOCK_FD, so the branch real updates take is covered and reverting --what on either branch fails the test. Along the way the test stubs were switched to absolute binaries — with a stub-first PATH, an unqualified command -v omarchy-update-lock inside the test re-entered the stub itself.

update-lock-test.sh (17 assertions), update-sequence-test.sh (step order still asserted with the stop moved up) and bin-style-test.sh all pass on the pushed head.

About #10205: fine by me whichever the maintainers prefer — happy to close this in favor of whichever PR lands first.

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

llstrk commented Sep 27, 2026

Copy link
Copy Markdown

Automated AI review

Community review: Independent automated community review, unaffiliated with the Omarchy team, intended to help prepare PRs for their review.

Follow-up to the earlier review and the author's reply, checked at 1bb09736.

Outcome: both earlier points are resolved at this head. The PR now conflicts with current quattro, and there the orphan-prompt fix does not carry over as written. Details follow.

Earlier point Status at 1bb09736
Lid lock covers the orphan-package prompt Resolved
Test covers only the else branch of start() Resolved
#10205 makes the same --what change Still applies (#10205 is open)

Verified:

  • omarchy-update-stay-awake stop and trap - EXIT now run after omarchy-update-mise and before omarchy-update-orphan-pkgs. The orphan prompt now runs after both the inhibitor and the update's Stay Awake idle marker are released. Restoring the previous ordering makes update-lock-test.sh fail ("orphan prompt ran while the update still held the lid lock") and update-sequence-test.sh fail its order check.
  • The --what assertion now runs directly and under omarchy-update-lock run. Reverting the mask on only the OMARCHY_UPDATE_LOCK_FD branch fails with "(locked launch)", and reverting only the else branch fails with "(direct launch)". The previous head's test still passed that locked-branch-only revert, so the gap was real, and the new test catches it.
  • update-lock-test.sh, update-sequence-test.sh and bin-style-test.sh pass on this head.
  • The earlier logind statement still holds for systemd v261.2 (Omarchy stable) and v262. The relevant logind sources are identical between the two.

One correction to the reply: omarchy-update-analyze-logs and omarchy-update-status previously ran inside the lock (before stop). They now run outside it. That change is harmless, but they did not run "without the lock as before".

Rebasing onto current quattro needs a different orphan-step fix

GitHub reports the PR as conflicting, and a three-way merge against the quattro tip conflicts in all four changed files. Beyond the text, quattro changed the update order on purpose:

quattro bin/omarchy-update (tip)
  stay-awake start
  system-pkgs, migrate
  orphan-pkgs              <- gum confirm, no timeout, still reached under -y
  analyze-logs, status
  restart --services-only
  hook post-update, mise
  AUR (yay)
  stay-awake stop          <- after AUR, deliberately
  restart --reboot-only

Commit 13a4306 keeps the inhibitor through hooks, mise and AUR builds, and test/shell.d/update-hook-security-test.sh asserts that order.

Impact: neither direct port works.

  • Keep this PR's shape (stop before the orphan step): hooks, mise and AUR builds run uninhibited. In an isolated sandbox with stubs, this makes update-sequence-test.sh and update-hook-security-test.sh fail.
  • Port only the --what mask: the lid issue from the earlier review returns. The orphan prompt now sits in the middle of the lid-locked window.
  • Carry trap - EXIT over: on quattro the EXIT trap is cleanup_update, which also ends the sudo keepalive and revokes the sudo timestamp. Clearing it early would skip that cleanup on later failures.

Suggested change: when rebasing:

  • The mask: it becomes a single edit to the shared hold_command in bin/omarchy-update-stay-awake (/usr/bin/systemd-inhibit --what=sleep:idle). The inhibitor has one launch command there, so one assertion covers every launch path.
  • The tests: they need to redirect the absolute /usr/bin/systemd-inhibit, as quattro's tests do (through sudo-boundary-test.sh or a sed rewrite), because a PATH-only stub is not reached. quattro's update-lock-test.sh also renames the state directory, so the orphan guard, if copied unchanged, would never fail.
  • The orphan prompt: handle it without moving stop. For -y runs there is a precedent: quattro's omarchy-update-restart already reports and moves on under OMARCHY_UPDATE_UNATTENDED=1, and docs/update-process.md already says orphan removal does the same under -y, which omarchy-update-orphan-pkgs does not yet do. That covers unattended runs only. An interactive run still reaches the prompt, so a bounded prompt or releasing only the lid part around the question would cover that case. Either way, keeping the confirmed sudo pacman -Rns removal inhibited would keep that transaction protected. At this head it runs with no inhibitor at all, where before this PR it ran under sleep:idle.
  • Docs: update the flow in docs/update-process.md to match whichever shape lands. At this head it still shows stop after status.

These directions come from the source only. No implementation was tested.


Review information

Test scope: Source review of this head, the previous head, the PR fork point and the quattro tip, plus systemd v261.2 and v262 logind sources. The head's update-lock-test.sh, update-sequence-test.sh and bin-style-test.sh ran in an isolated sandbox with stubbed systemd-inhibit, sudo, pkexec and update steps, along with per-branch and ordering mutants. A separate check ran the real omarchy-update-orphan-pkgs with stubbed pacman and gum. On quattro, update-sequence-test.sh and update-hook-security-test.sh ran as-is and with the stop moved. quattro's update-lock-test.sh could not run in the sandbox, so conclusions about it come from source. No real logind, polkit, lid hardware or package transactions were exercised.

AI process: Opus 5.5 Medium coordination and synthesis, Opus 5.5 Xhigh technical review and final fact check, GPT 6 Sol Xhigh search for related issues, Opus 5.5 Medium editorial check.

Opt out: To stop receiving these reviews, reply to this comment saying so.

logind ignores high-level sleep locks for the lid switch
(LidSwitchIgnoreInhibited defaults to yes), so closing the lid suspended
mid-update despite the stay-awake inhibitor. Take the low-level
handle-lid-switch lock as well, by adding it to the sleep:idle mask on the
single systemd-inhibit launcher; scoped to updates only, so normal lid
behavior resumes on stop.

Fixes omacom#10203.
@ansonboby
ansonboby force-pushed the fix/update-lid-inhibit branch from 1bb0973 to 60a6eff Compare September 29, 2026 14:27
-y exports OMARCHY_UPDATE_UNATTENDED=1, and docs/update-process.md already
says interactive review steps report and skip instead of blocking, but the
orphan step only skipped when there was no terminal. In a terminal -y still
stopped on a gum confirm, so an unanswered question held the update's sleep
inhibitor for as long as the prompt sat there.

Match omarchy-update-restart's reboot prompt and the conflicted-package
handoff, which both report and skip under the same variable. Interactive
updates still ask; only -y is suppressed.

Tested on a pty: without one the existing non-interactive guard answers for
this case and hides the regression.
@ansonboby

Copy link
Copy Markdown
Author

Rebased onto current quattro at c4e2a0cf, following your three directions. Both earlier points stay resolved, and the shape you prescribed is what landed.

The mask is now the single edit you described: --what=sleep:idle → --what=sleep:idle:handle-lid-switch in the shared hold_command in bin/omarchy-update-stay-awake. I checked the merged file for a second launcher before relying on it, and there is only the one, so a single assertion covers every launch path.

The dropped commit. You are right that neither direct port works, and I dropped the commit that released the inhibitor before the orphan step rather than reshaping it. The reasoning that decided it: 13a4306a keeps the inhibitor through hooks, mise and AUR on purpose, update-hook-security-test.sh asserts that order, and clearing trap - EXIT early would skip cleanup_update's keepalive and sudo-timestamp teardown — so the shape was fighting the design rather than fixing a bug in it. I also accept your correction that analyze-logs/status previously ran inside the lock, so my earlier "without the lock as before" was wrong.

The orphan prompt now follows your -y precedent instead: omarchy-update-orphan-pkgs reports and skips under OMARCHY_UPDATE_UNATTENDED, exactly as omarchy-update-restart's reboot prompt and the conflicted-package handoff already do, and as docs/update-process.md already claims (-y exports the variable and suppresses Omarchy confirmation prompts; "interactive review steps (orphan removal, conflict handoff) report and skip"). That closes the gap you identified where the prompt sat in the lid-locked window, without moving stop and without leaving the confirmed pacman -Rns removal uninhibited — so the documentation and the code now agree instead of the code being the odd one out.

Tests, per your note about the absolute path: the mask assertion now runs through sudo-boundary-test.sh, which rewrites /usr/bin/systemd-inhibit to mock/systemd-inhibit, and observes the real update flow rather than a PATH-only stub that would never be reached. The state directory is the renamed one, so it can't pass by accident. For the orphan change the two prompt cases run on a pty, because without one the pre-existing non-interactive guard answers for the unattended case and would hide the regression.

Mutation-checked rather than assumed: reverting the mask to sleep:idle fails update-lock-test; deleting the unattended branch fails update-orphan-test on the pty case. update-lock-test, update-sequence-test, update-stay-awake-security-test, update-hook-security-test, update-orphan-test, update-user-path-test, bin-style-test and manifest-entrypoints-test pass.

On the interactive prompt: it still reaches the question, so the lid lock covers the moment someone is reading it. I left that as-is rather than bounding it, because a confirmation that expires mid-answer trades one surprise for another and you offered it as an either/or; if you'd rather have the bounded prompt, say so and I'll add it.

On the docs: the "stop after status" you saw was the pre-rebase head. On the rebased branch docs/update-process.md already shows stay-awake stop after the AUR step (line 146, "release the sleep inhibitor and restore shell idle state"), which is quattro's deliberate order and the order this shape preserves — so nothing there needed to change, and I'd rather leave it than touch a flow diagram that is already right.

@omarchybot omarchybot added the verified Omarchy Triage has verified that this issue is ready for final review label Oct 1, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed at c4e2a0cf, merged onto quattro at 8b4eae66, on a disposable Omarchy VM.

The fix works on a real logind. On the VM I emulated a lid switch through uinput (an SW_LID device that logind picks up as a power switch). I configured the VM's logind to suspend on lid close even when docked and swapped the suspend itself for a no-op, then held the real update inhibitor via omarchy-update-stay-awake start and closed the lid:

  • quattro's script holds sleep:idle, and logind logged Lid closed. then Suspending... anyway. That is closing the lid can suspend the machine mid-update #10203 reproduced.
  • This branch holds sleep:idle:handle-lid-switch, and logind logged Lid closed. / Lid opened. with no suspend. That held on two separate runs, before and after the base run.
  • After stop, no update inhibitor is left, and a lid close suspends normally again.

Tests. update-lock-test.sh and update-orphan-test.sh pass on this head and on the merge with quattro. With the two bin/ changes reverted they fail: the mask assertion and the unattended orphan case. On the merge these also pass: update-sequence, update-stay-awake-security, update-hook-security, update-user-path, update-restart-phases, update-pacman, update-package-conflict, update-file-conflict, channel-sudo-boundary, bin-style and manifest-entrypoints. ./test/cli fails one assertion, vscode generated theme references current theme file. It fails the same way on quattro at 8b4eae66 with this PR absent, so it is not caused by this change, but it means the suite is not green yet.

Orphan prompt. omarchy update re-runs itself under script, so the existing terminal check never caught -y. Under -y the update could stop at the gum confirm with the lid lock held. Skipping the question under OMARCHY_UPDATE_UNATTENDED matches what docs/update-process.md already says and what omarchy-update-restart already does. It keeps 13a4306a's ordering and leaves a confirmed pacman -Rns inside the inhibited window. I think it belongs in this PR rather than a separate one.

Competing fix. #10205 makes the same one-line --what change, but it leaves -y able to sit at the orphan prompt with the lid lock held. This PR also handles that case, so it is the one I'd bring forward. Choosing between them is the maintainer's call.

Second opinion. Codex Medium reviewed the diff and separately compared it with #10205. It found no defect introduced here and also preferred this PR. That agrees with my own read, and its independence is not guaranteed. It also pointed out a problem that predates this PR: if sudo revocation fails in cleanup_update (bin/omarchy-update:76-78), the update exits before omarchy-update-stay-awake stop, so the inhibitor outlives the update. With this change, the leftover inhibitor would also block lid suspend. That case is rare and outside this PR's scope.

Nothing is needed from you. This now waits on the maintainer, with the failing ./test/cli assertion on quattro still to be resolved.

@omarchybot omarchybot removed the verified Omarchy Triage has verified that this issue is ready for final review label Oct 7, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Re-checked because this now conflicts with quattro. Today quattro gained #14428 (402128b6), which makes every update remove orphan packages without asking: bin/omarchy-update:130 now calls omarchy-update-orphan-pkgs -y. So the update flow no longer reaches the orphan prompt, and the problem this PR's second commit solved is gone. Keeping the OMARCHY_UPDATE_UNATTENDED skip would now make omarchy update -y skip the removal #14428 asks for, so that commit should be dropped rather than ported.

The lid fix still works. On a disposable Omarchy VM I merged quattro (d9b970dd) into this branch, keeping only the lid mask and its test. I emulated a lid switch through uinput, with logind set to suspend on lid close and the suspend itself replaced by a no-op. I held the real update inhibitor and closed the lid, two runs each way. With this branch's inhibitor (sleep:idle:handle-lid-switch), logind logged Lid closed. and Lid opened. with no suspend. With quattro's (sleep:idle), it logged Suspending.... No update inhibitor was left after stop. On that merge ./test/cli is now fully green, and so are update-lock, update-orphan, update-sequence, update-stay-awake-security, update-hook-security, update-user-path, update-restart-phases, update-pacman, update-package-conflict, update-file-conflict, channel-sudo-boundary, bin-style and manifest-entrypoints. With the mask reverted, update-lock-test.sh fails.

Competing fix. With the orphan half gone, this PR and #10205 make the identical one-line change to the same systemd-inhibit call. #10205 is older, so it is the one to bring forward. Whoever reaches a fix first keeps it unless the newer one fixes a case the older misses, and here none is left. The one thing this PR does better is its test. #10205's assertion sits inside the EUID != 0 block of test/shell.d/update-lock-test.sh, so it is skipped when the suite runs as root. This PR's assertion observes the mask through the real omarchy-update -y flow and runs either way. I've marked that test to be folded into #10205, with credit to you. I pushed nothing to this branch.

Second opinion. Codex Medium compared the two PRs separately and also chose #10205 under the same rule. It found no defect in either lid change and agreed the orphan change now works against #14428. Its line references check out against quattro. This agrees with my own read, and its independence is not guaranteed.

Nothing is needed from you. This waits on the maintainer, who decides between this PR and #10205.

omarchybot added a commit to Roriz/omarchy that referenced this pull request Oct 7, 2026
The previous assertion read the mask from the sudo stub's log inside the EUID != 0 block, so it never ran when the suite ran as root. Record the systemd-inhibit argv from the stub the full omarchy-update -y run already reaches, which runs either way and covers the launch real updates take.

Taken from omacom#12419, which fixed the same bug with this test.

Co-Authored-By: Anson Boby <ansonboby@gmail.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jandrusk

Copy link
Copy Markdown

The lid-switch half is still needed: live omarchy-update-stay-awake only takes --what=sleep:idle, and logind ignores that for the lid (LidSwitchIgnoreInhibited=yes). Tracks #10203.

Currently CONFLICTING after #14428 (auto-approve orphans). The OMARCHY_UPDATE_UNATTENDED orphan skip in this PR likely overlaps that merge — please rebase and drop any orphan bits already landed, keeping the handle-lid-switch inhibitor + test. Sister open PR: #10205.

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.

closing the lid can suspend the machine mid-update

4 participants