Skip to content

Cover the lid switch in the update sleep inhibitor - #10205

Open
Roriz wants to merge 10 commits into
omacom:quattrofrom
Roriz:fix-update-inhibitor-lid-switch
Open

Roriz wants to merge 10 commits into
omacom:quattrofrom
Roriz:fix-update-inhibitor-lid-switch

Conversation

@Roriz

@Roriz Roriz commented Sep 4, 2026 •

Copy link
Copy Markdown

Closing a laptop lid during an Omarchy update can suspend it in the middle of a package transaction. The existing sleep:idle inhibitor does not cover the lid switch with logind's default LidSwitchIgnoreInhibited=yes.

Add handle-lid-switch to the update inhibitor's mask. This low-level lock covers lid-triggered suspend for the duration of the update without changing system-wide lid policy.

Cleanup also stops the caller-owned inhibitor if sudo timestamp revocation fails, then exits unsuccessfully and retries revocation through the existing exit helper. Previously the immediate exit could leave the inhibitor blocking sleep after the update had failed.

The existing update-lock suite checks the actual inhibitor arguments, including when run as root, and checks cleanup on errors, HUP, INT, TERM and failed sudo revocation. The lid assertion was contributed by @ansonboby from #12419.

Updated to current quattro (79dcccf) in fae7f44, without conflicts or changes to the fix.

Validation:

  • 18 update-lock groups and 125 CLI assertions pass.
  • All 21 focused files pass: the update suites, channel sudo boundary, bin style and manifest entrypoints. The restart-kernel test needs the checkout's bin directory on PATH for the new translation helper.
  • In an isolated checkout, reverting the lid mask fails the lid assertion; restoring the old cleanup exit fails the revoked-sudo inhibitor-release assertion.
  • Earlier reviewer verification on a disposable Omarchy VM reproduced suspend with the base mask and prevented it with this fix, using an emulated lid switch and real logind. That live logind check was not repeated during this update.
  • The full shell suite was not repeated. The previous review documented unrelated failures that also reproduced on its base checkout.

Closes #10203. #12419 contains the same lid-mask fix; the reviewer previously selected this older PR to move forward.

sleep and idle are high-level inhibitor locks, and logind ignores those
for the lid switch unless LidSwitchIgnoreInhibited=no. Omarchy ships no
such drop-in, so closing the lid during an update suspended the machine
despite the block inhibitor that exists to prevent exactly that.

handle-lid-switch is a low-level lock, which logind.conf(5) says is
always honored irrespective of that setting.

Closes omacom#10203

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
quattro rewrote the inhibitor launch into a single hold_command run
through sudo -b, pkexec, or directly as root. Re-apply the
handle-lid-switch lock to that command and keep the lid-switch
assertion alongside the new cancellation tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AXE1uhq3MnwcgFFkGFspbX
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed at 5a9daafc. I read it against quattro but did not run it, because a competing pull request makes the same fix.

The diagnosis holds. With LidSwitchIgnoreInhibited at its default, logind ignores the high-level sleep:idle lock when the lid closes, and Omarchy's logind drop-ins don't change that. handle-lid-switch is the low-level lock logind always honours. The new assertion in test/shell.d/update-lock-test.sh does check the real argv, but it sits inside the EUID != 0 block, so it doesn't run when the suite runs as root.

Competing fix. #12419 makes the identical --what=sleep:idle:handle-lid-switch change to the same systemd-inhibit call, also for #10203. It also makes omarchy-update-orphan-pkgs report and skip under -y. That matters with the lid lock in place: omarchy update re-runs itself under script, so the orphan prompt's terminal check never fires under -y. The prompt runs at bin/omarchy-update:130, before the inhibitor is released at :156. With this change alone, an unattended update that stops at that prompt would keep the lid from suspending for as long as it waits. #12419 was reproduced on a disposable Omarchy VM with an emulated lid switch, so it is the one being brought forward. Only one of the two should land, and which one is the maintainer's choice. This one is older and smaller.

Second opinion. Codex Medium compared the two separately. This time it preferred this pull request, because it judged the orphan-prompt change unrelated to #10203. An earlier comparison by the same reviewer preferred #12419 for the reason above. It found no defect in the lid fix in either pull request. Its independence is not guaranteed.

Nothing is needed from you. This waits on the maintainer's choice between the two.

omarchybot and others added 2 commits October 7, 2026 17:44
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>
@omarchybot omarchybot added 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 at 5b76f69b on a disposable Omarchy VM. #12419 makes the same one-line fix, and this one is older, so it is the one being brought forward. I pushed two commits to your branch:

  • A merge of quattro (d9b970dd), which was 116 commits ahead. It merged without conflicts.
  • The lid-lock assertion from fix(update): block lid switch during updates #12419, credited to @ansonboby. The assertion this PR added was inside the EUID != 0 block of test/shell.d/update-lock-test.sh, so it was skipped when the suite ran as root. The new one records the systemd-inhibit arguments during the full omarchy-update -y run earlier in that file, so it runs either way. It replaces yours, since both check the same mask. bin/omarchy-update-stay-awake is unchanged from your fix.

The fix works on a real logind. I emulated a lid switch through uinput, with logind set to suspend on lid close and the suspend itself replaced by a no-op. Then I held the update inhibitor with omarchy-update-stay-awake start and closed the lid:

  • With quattro's script (sleep:idle), logind logged Lid closed. and then Suspending.... That is closing the lid can suspend the machine mid-update #10203.
  • With this branch (sleep:idle:handle-lid-switch), logind logged Lid closed. and Lid opened. with no suspend, on two runs.
  • With this branch's mask reverted, it suspended again.
  • After stop, no update inhibitor was left.

Tests. update-lock-test.sh passes on this head and fails with the mask reverted. ./test/cli is green, and so is every update-* test, plus channel-sudo-boundary, bin-style and manifest-entrypoints. The full ./test/shell run has 5 failing files: ascii, branding-about-animation, default-agent, launch-browser and passwordless-grant-lifecycle. They fail the same way on quattro at d9b970dd without this PR, so this change didn't cause them. But the suite isn't green yet. On this head, bar-widget-contract and screenshot-sanity also failed once and then passed on two reruns.

Second opinion. Codex Medium reviewed this head and found no defect. It found the change proportionate and checked that the root, sudo and pkexec launch paths all use the same hold_command. It also confirmed that the test's stub is the one the real launcher reaches. It repeated a problem that predates this PR: if the updater is killed outright, or sudo revocation fails in cleanup_update (bin/omarchy-update:76), the inhibitor can outlive the update, and it would now block lid suspend as well. Its independence is not guaranteed.

Nothing is needed from you. This waits on the maintainer, and on the failing quattro tests being fixed.

@greptile-apps

greptile-apps Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable new issues were found.

Summary

Adds handle-lid-switch to the update's existing sleep and idle inhibitor.

  • Omarchy updates block lid-triggered suspension while update work runs.

Reviews (5) · Last reviewed commit: "Drop the update cleanup test loop" · Reviewed by Greptile

@omarchybot omarchybot removed the verified Omarchy Triage has verified that this issue is ready for final review label Oct 14, 2026
quattro shortened the keyring stub's sleep in update-lock-test.sh while this branch added the inhibitor argv log to the stubs beside it; keep both.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@omarchybot omarchybot added the verified Omarchy Triage has verified that this issue is ready for final review label Oct 14, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

This stopped merging cleanly after quattro moved on, so I merged quattro (58a289e2) into your branch as f13fca57. One conflict, in the stubs of test/shell.d/update-lock-test.sh: quattro shortened the keyring stub's sleep, and this branch logs the systemd-inhibit arguments in the stub beside it. The merge keeps both. Your fix in bin/omarchy-update-stay-awake is unchanged.

Re-checked at f13fca57 on a disposable Omarchy VM, with the same emulated lid switch as before (logind set to suspend on lid close, suspend itself a no-op):

  • quattro's sleep:idle inhibitor: logind suspended on lid close.
  • This branch's sleep:idle:handle-lid-switch: lid closed and opened with no suspend, on five runs.
  • This branch with the mask reverted: it suspended.
  • After stop, no update inhibitor was left.

One run of this branch did suspend, and it was the test, not the fix: it started while the previous run's suspend was still finishing, so omarchy-update-stay-awake start was refused and no inhibitor was held. Run on its own, it passed every time.

Tests. ./test/cli is green, and so is every update-* test, plus channel-sudo-boundary, bin-style and manifest-entrypoints. The full ./test/shell run has 5 failing files: ascii, background-instant-reload, background-intro-clone, branding-about-animation and launch-browser. They fail the same way on quattro at 58a289e2 without this PR, so the suite isn't green, but not because of this change.

Second opinion. Codex Medium reviewed the merged head and found no defect. It checked the conflict resolution and that the assertion still rejects quattro's mask, and it judged the change proportionate. It added a caveat: quattro's new boot verification (bin/omarchy-update:161) runs while the inhibitor is held, and on Apple Silicon it can prompt for a password even under -y, so lid suspend now stays blocked while that prompt waits, as it already does for AUR builds' sudo prompts. Its independence is not guaranteed.

#12419 makes the same lid fix. Its extra change to omarchy-update-orphan-pkgs was the case for it, and quattro has since made orphan removal under -y non-interactive (#14428), so that no longer applies. This one is older, so it stays the one brought forward.

Nothing is needed from you. This waits on the maintainer, and on those quattro tests being fixed.

@omarchybot omarchybot added verified Omarchy Triage has verified that this issue is ready for final review and removed verified Omarchy Triage has verified that this issue is ready for final review labels Oct 18, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Re-checked at 4bf2ea80 on a disposable Omarchy VM, after your merge of quattro and the new commit that releases the inhibitor when sudo revocation fails.

The lid fix still works. I ran the same emulated lid switch as before: logind set to suspend on lid close, with the suspend itself a no-op, and the update inhibitor held while the lid closed.

  • quattro at dd07b626 (sleep:idle): logind suspended.
  • This head (sleep:idle:handle-lid-switch): the lid closed and opened with no suspend, on two runs.
  • This head with the mask reverted: it suspended.
  • After stop, no update inhibitor was left.

The cleanup change. cleanup_update in bin/omarchy-update now stops the inhibitor before exiting when sudo -k fails, where it used to exit straight away. With the lid lock in place, a leaked inhibitor would block lid suspend until the next update cleaned it up, so this belongs in this PR. The new loop in test/shell.d/update-lock-test.sh covers what it says: with the old immediate exit restored, the revoke case fails, and the error and signal cases keep their exit statuses. One thing for the maintainer to accept knowingly: the immediate exit came in deliberately with f2c3925 ("Revoke before session cleanup"). In the shipped code the stop path only reads its own state, removes the Stay Awake marker and signals the inhibitor it started. It runs nothing through sudo, and a timestamp that sudo -k could not clear stays valid after exit either way. So I found no defect, but the change does trade a strict rule for releasing the inhibitor.

Tests. update-lock-test.sh passes 18 of 18 on this head. It fails with the mask reverted, and fails again with the old cleanup restored. ./test/cli is green. The full ./test/shell run has 11 failing files: ascii, background-instant-reload, background-intro-clone, branding-about-animation, brave-widevine, hyprland-startup-cursor-cold, i18n, lock-appear-budget, passwordless-grant-lifecycle, runtime-smoke and screenshot-sanity. All of them fail the same way on quattro at dd07b626 without this PR. So the suite isn't green, but this change isn't the cause.

Second opinion. Codex Medium reviewed this head and found no defect in the fix. It judged the whole change proportionate and the cleanup commit in scope. It reached the same view of the revocation trade-off: a call for the maintainer, not a demonstrated security problem. It also preferred this PR over #12419, which makes the same lid fix and is newer. Its independence is not guaranteed.

Nothing is needed from you. This waits on the maintainer, and on those quattro tests being fixed.

@Roriz

Roriz commented Oct 28, 2026

Copy link
Copy Markdown
Author

@omarchybot, please review current head fae7f44 and restore/retain verified and add ready if it passes.

Merged current quattro (79dcccf) without conflicts. The production fix is unchanged: the inhibitor includes handle-lid-switch, and cleanup releases it even when sudo revocation fails. No unresolved review threads or new code defects were found.

Validation on this merge:

  • 18 update-lock groups and 125 CLI assertions pass.
  • All 21 focused test files pass: update suites, channel sudo boundary, bin style and manifest entrypoints. The restart-kernel test passes with the checkout's bin/ on PATH so it can find the new translation helper.
  • Reverting the lid mask in an isolated checkout fails the lid assertion. Restoring the old immediate cleanup exit fails the revoked-sudo inhibitor-release assertion.
  • The full shell suite and the emulated-lid real-logind check were not repeated. Your previous review already verified real logind behavior and reported the broader failures as also present on the base branch.

Please identify any remaining condition for ready, especially whether the previously reported base-suite failures still block it. The last review found no defect and left this waiting on the maintainer. The new merge commit is signed with my registered SSH signing key.

@omarchybot omarchybot removed the verified Omarchy Triage has verified that this issue is ready for final review label Oct 29, 2026
quattro's omacom#17000 dropped sudo revocation, so cleanup_update can no longer fail to revoke: take quattro's cleanup and drop the revoke case from the cleanup test, keeping the error and signal cases that check a failed update releases the lid lock.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@omarchybot omarchybot added the verified Omarchy Triage has verified that this issue is ready for final review label Nov 1, 2026
It was added to check that cleanup released the inhibitor when sudo revocation failed. With quattro no longer revoking, the error and signal cases test behaviour quattro already has and pass without this change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Codex Medium <noreply@openai.com>
@omarchybot

Copy link
Copy Markdown
Collaborator

Re-checked at 6c13ea48 on a disposable Omarchy VM. Since your merge, quattro moved on and this PR stopped merging. I pushed two commits to your branch:

  • A merge of quattro (879534b6). Use ordinary sudo: one password for ten minutes, plain update scripts #17000 dropped sudo revocation from omarchy update: end_update_authorization now only stops the keepalive and can't fail. So the conflict in cleanup_update resolves to quattro's version, and your commit that released the inhibitor when sudo -k failed has nothing left to do. The merge also drops the revoke case and its mock/sudo wrapper from test/shell.d/update-lock-test.sh, since that failure can no longer happen.
  • The rest of the cleanup loop removed (6c13ea48). Without revocation, the error, HUP, INT and TERM cases test what quattro already does, and they pass without this PR, so under the base AGENTS.md test rules they don't belong in it. The omarchy-toggle-idle stub added with them went too.

What's left is your fix in bin/omarchy-update-stay-awake (--what=sleep:idle:handle-lid-switch) plus the lid assertion in the existing update flow test.

The fix still works on a real logind. I emulated a lid switch through uinput, with logind set to suspend on lid close and the suspend itself a no-op. Then I held the update inhibitor and closed the lid:

  • quattro at d367a568 (sleep:idle): suspended.
  • This branch: the lid closed and opened with no suspend, on two runs, and no update inhibitor was left after stop.
  • This branch with the mask reverted: suspended.

Tests. update-lock-test.sh passes on this head and fails only "update inhibitor blocks the lid switch" with the mask reverted. ./test/cli is green. The full ./test/shell run at 879534b6 (same production code) has 5 of 413 files failing: agent-account-exec, ascii, branding-about-animation, first-run and runtime-smoke. All five fail the same way on quattro at d367a568 without this PR.

Second opinion. Codex Medium and muse-wonder (via pi, thinking high) reviewed both rounds and found no defect. Both checked the conflict resolution against #17000 and found that it keeps everything this PR still needs. Codex raised that the cleanup loop no longer failed without this change, which is why it was removed. Both also preferred this PR over #12419. That one makes the same lid fix but is newer, and its orphan-prompt change adds nothing now: omarchy-update already calls omarchy-update-orphan-pkgs -y, which doesn't prompt. Their independence is not guaranteed.

To answer your question: yes, ready needs the full shell suite green on a worker, so those five quattro failures still hold it back even though this PR doesn't cause them.

One thing for you: the PR description still describes the sudo-revocation cleanup change and its test. Neither is in the diff now. Please update it so it describes only the lid lock. After that, this waits on the maintainer's choice between this and #12419, and on those quattro tests being fixed.

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

Labels

bug Something isn't working verified Omarchy Triage has verified that this issue is ready for final review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

closing the lid can suspend the machine mid-update

3 participants