omarchy icon indicating copy to clipboard operation
omarchy copied to clipboard

omarchy-sleep-lock.service fails intermittently on repeated suspend/resume cycles ("inhibition already running")

Open bryansiegel opened this issue 3 months ago • 8 comments

omarchy-sleep-lock.service fails intermittently on repeated suspend/resume cycles ("inhibition already running")

On repeated suspend/resume cycles in a short window (e.g. closing/opening a laptop lid several times), omarchy-sleep-lock.service reliably fails with:

systemd-inhibit: Failed to inhibit: The operation inhibition has been requested for is already running

Digging into it, the mechanism looks like this: omarchy-system-sleep-monitor acquires one delay-inhibitor, waits for a single PrepareForSleep(true) dbus signal, calls omarchy-system-sleep-lock, then exits. It relies on Restart=always/RestartSec=2 to respawn and re-acquire a fresh inhibitor before the next suspend. But real-clock RestartSec freezes during suspend and fires right on resume — a fast second suspend can beat the respawn, so that cycle proceeds uninhibited, and the eventually-restarted instance's systemd-inhibit call lands after logind has already moved past accepting a new inhibitor for that transition. Widening the restart delay (tried 0.5s and 2s) didn't fix it — it looks like a structural issue with the respawn-per-cycle design racing suspend duration itself, not a timing constant to tune.

Repro: close/reopen a laptop lid (or otherwise trigger systemd-sleep) several times in quick succession, then check journalctl --user -u omarchy-sleep-lock.service for status=1/FAILURE restarts.

bryansiegel avatar Aug 24 '26 22:08 bryansiegel

Hitting this on Omarchy 4.0.2-1. Confirming the analysis and adding a workaround, since there isn't one on the thread yet.

Reproduced without needing rapid lid cycling — a single normal suspend/resume is enough here. Two suspends over one uptime gave restart counter is at 4:

12:42:59 systemd-inhibit[172330]: Failed to inhibit: The operation inhibition has been requested for is already running
12:42:59 omarchy-sleep-lock.service: Main process exited, code=exited, status=1/FAILURE
12:42:59 omarchy-sleep-lock.service: Failed with result 'exit-code'.
12:43:01 omarchy-sleep-lock.service: Scheduled restart job, restart counter is at 4.

The 2s between the failure and the successful retry is exactly RestartSec=2, and no --what=sleep --mode=delay inhibitor is registered across it.

Workaround

Drop-in at ~/.config/systemd/user/omarchy-sleep-lock.service.d/restart-race.conf:

[Unit]
StartLimitBurst=30

[Service]
RestartSec=250ms

systemctl --user daemon-reload && systemctl --user restart omarchy-sleep-lock.service

This narrows the unprotected window from 2s to 250ms — the failing systemd-inhibit call is transient, so a fast retry rides out the transition instead of parking for two seconds.

StartLimitBurst=30 is load-bearing, not cosmetic: at 250ms the retries would otherwise burn the default burst of 5 inside StartLimitIntervalSec=10s and leave the unit dead in failed for the rest of the session, which is strictly worse than the bug. Raising the burst rather than setting StartLimitIntervalSec=0 keeps a ceiling, so a permanently broken monitor still stops instead of respawning every 250ms forever. The tradeoff is that ~7.5s of continuously refused inhibits would exhaust the burst and wedge the unit; that hasn't happened here, since the refusal only lasts as long as the sleep transition itself.

Not a fix

It shrinks the race, it doesn't remove it, and it still logs a failed start per suspend. The real fix belongs in omarchy-system-sleep-monitor, retrying the systemd-inhibit acquisition rather than letting the process exit 1 and delegating recovery to Restart=. Happy to send a PR if that's the direction you'd want.

Lajam421 avatar Sep 06 '26 21:09 Lajam421

Also observed on Omarchy 4.0.2-1 with systemd 261.2-1. The previous boot's user-unit journal contains 61 occurrences of:

Failed to inhibit: The operation inhibition has been requested for is already running

These are across the boot, not 61 failures in a single suspend. One recorded normal sleep interval on 2026-09-07 (UTC+8) shows retries both before entering S3 and after returning from it:

08:37:23 omarchy-shell: secure=true
08:37:25 omarchy-sleep-lock.service: Scheduled restart job, restart counter is at 58.
08:37:25 systemd-inhibit: Failed to inhibit: The operation inhibition has been requested for is already running
08:37:27/30/32 further failed retries
08:37:33 PM: suspend entry (deep)
12:40:14 PM: suspend exit
12:40:16/18/20/23/25/27 further failed retries
12:40:29 Finished System Suspend.
12:40:29 omarchy-sleep-lock.service: Scheduled restart job, restart counter is at 69.

The installed unit uses Restart=always and RestartSec=2. The monitor consumes one PrepareForSleep(true) event, invokes the lock helper, and exits, consistent with restarting while logind is still processing the same sleep operation. This captured interval was approximately four hours long; the symptom is not limited to rapidly closing/reopening the lid.

The shell reported secure=true before this suspend, so this evidence establishes repeated failed inhibitor acquisition/restarts, not an unlocked session in this incident. No restart-delay workaround has been applied or tested here.

chivopic avatar Sep 07 '26 13:09 chivopic

Reproduced on omarchy 4.0.4-1 / kernel linux 7.2.5-3-omarchy (HP OmniBook Ultra Flip 14-fh0xxx, Lunar Lake, s2idle, suspend-then-hibernate, stock unit + stock monitor, no local overrides).

Crash loop confirmed on every resume in my session:

Sep 18 17:33:21 systemd[1137]: omarchy-sleep-lock.service: Scheduled restart job, restart counter is at 1.
Sep 18 17:33:21 systemd[1137]: Started Lock Omarchy before suspend.
Sep 18 17:33:21 systemd-inhibit[481181]: Failed to inhibit: The operation inhibition has been requested for is already running
Sep 18 17:33:21 systemd[1137]: omarchy-sleep-lock.service: Main process exited, code=exited, status=1/FAILURE
Sep 18 17:33:21 systemd[1137]: omarchy-sleep-lock.service: Failed with result 'exit-code'.
Sep 18 17:33:23 systemd[1137]: omarchy-sleep-lock.service: Scheduled restart job, restart counter is at 2.
Sep 18 17:33:23 systemd[1137]: Started Lock Omarchy before suspend.

Counts over the last days on this machine (user journal, whole unit history):

  • Failed to inhibit: ... already running — 541
  • Scheduled restart job — 1142
  • dbus-monitor: ... Falling back to eavesdropping — 578 (see #10317, so the unit also runs degraded on every start)

Practical impact beyond the log noise: after a resume that lands in the loop, the next lid-close suspend proceeds without a delay inhibitor in time, so the pre-suspend lock never completes — the session suspends unlocked. I'm currently mitigating by keeping rfkill on soft-block for Bluetooth and a system-sleep hook that unbinds btintel_pcie (0000:00:14.7) around sleep, because the driver's suspend callback returns -EBUSY 2226 times and was aborting suspend cycles into a hard freeze (journal ends mid-suspend, ~8.5 h later a cold boot, no resume path logged).

Happy to test #12102 once it lands — this machine reproduces the failure deterministically on every resume.

exclude-barrier avatar Sep 18 '26 16:09 exclude-barrier

Adding a data point and a consolidation, since this bug has now generated four open reports and three fix PRs have been closed unmerged.

Still 100% reproducible as of today (2026-10-03).

  • Omarchy 4.0.4-1, kernel 7.2.5-3-omarchy
  • MSI Katana A15 AI B8VF (MS-158N), AMD Ryzen AI — Radeon iGPU + RTX 4060, amdxdna NPU
  • s2idle only; /sys/power/state exposes no S3

Across boot -1 (Sep 28 – Oct 3) there were 7 resume cycles and 7 failures — one per cycle, no exceptions, 14 restart attempts total. The unit recovers on the very next attempt, ~2s later:

Oct 03 10:34:05 systemd-inhibit[526742]: Failed to inhibit: The operation inhibition has been requested for is already running
Oct 03 10:34:05 systemd[1326]: omarchy-sleep-lock.service: Main process exited, code=exited, status=1/FAILURE
Oct 03 10:34:05 systemd[1326]: omarchy-sleep-lock.service: Failed with result 'exit-code'.
Oct 03 10:34:08 systemd[1326]: omarchy-sleep-lock.service: Scheduled restart job, restart counter is at 14.

Every failure lands within 2s of a resume (PM: suspend exit), never at suspend entry.

Consolidation. Four open reports of the same root cause: #8112, #12495, #13160, #13701. Plus #10317 for the dbus-monitor eavesdropping fallback that degrades the unit on every start. Fix attempts: #8150, #10279 and #12102 — all three closed without merging (#12102 on Sep 21). The three duplicate reports were filed after those PRs were closed, which reads like the absence of a merged fix plus a lack of consolidation rather than three independent discoveries.

I agree with #12495 and #13701 that the log line is cosmetic — the lock path itself works, and this is not urgent. But #8112's second commenter reports a functional consequence (a resume that lands in the loop leaves the next lid-close suspend without a delay inhibitor, so the session suspends unlocked). That is worth settling one way or the other, because if it is real it is a security property and not log noise.

Question for maintainers: is there a reason this is being deprioritized, or should the duplicates be merged here so there is a single place tracking it? Happy to test a re-opened #12102 — my machine fails deterministically on every resume.

Filed by big-pickle via opencode.

fernando-madepa avatar Oct 03 '26 22:10 fernando-madepa

Moving my analysis from #13701 to here, as suggested.

Root cause. omarchy-system-sleep-monitor is built to handle exactly one suspend per process — consume_sleep_events returns after the first PrepareForSleep(true) and exits 0. The unit leans on Restart=always / RestartSec=2 to bring it back for the next event. The queued restart lands while logind is still inside the same sleep transition, so the --what=sleep --mode=delay inhibitor cannot be registered, systemd-inhibit exits 1, and systemd records status=1/FAILURE. The next attempt 2s later succeeds, because by then the transition has finished.

Machine. MacBookPro12,1 (Intel Core i5-5257U, Broadwell-U), Omarchy 4.0.4-1, kernel 7.2.5-3-omarchy, Hyprland/Wayland. Same 100% rate as #8112's most recent report: 42 failures across 42 suspends, no exceptions. Restart counter has reached 24.

On the unlocked-suspend concern. fernando-madepa asked on #8112 whether a resume landing inside the restart loop leaves the next lid-close suspend without a delay inhibitor, and whether that means the session suspends unlocked. I looked for evidence of that and did not find it, for a structural reason rather than a probabilistic one.

omarchy-system-lid-close locks on the Hyprland switch:on:Lid Switch binding, well before logind ever sees the suspend. I confirmed that binding is registered on my machine (hyprctl binds shows switch:on:Lid Switch → dispatcher __lua arg 137). So a lid-close suspend locks at lid-event time, not at PrepareForSleep time. The sleep-lock service is the second lock, and the second lock's inhibitor is what's being refused. It is a defense-in-depth retry, not the only lock.

Two further points:

  • omarchy-system-sleep-lock already reports its own failure loudly rather than silently. If the session is not secured before logind's budget expires, it writes omarchy-system-sleep-lock: suspending without a secure lock (...) to stderr and raises a critical omarchy-notification-send notification. I have never seen that line in my journal, and my session is secure on every lid close.
  • The unlocked window is being closed independently, too. #13782 re-raises SIGTERM rather than exiting 143, so even a plain stop or restart no longer records the unit as failed.

So I'd characterize it as: cosmetic, as #12495, #13160, and I originally said. But not quite as low-priority as "log noise" implies — the service has a start limit of StartLimitBurst=5 inside StartLimitIntervalSec=10s, and every suspend costs two starts. If a resume lands inside the loop, that pair of starts can exhaust the burst limit and leave omarchy-sleep-lock.service dead in failed for the rest of the session. That is a real degradation, though on this machine the lid-close binding appears to cover it, and the lid-close path is not what fails here.

On consolidation. Happy to consolidate. My root-cause note is above and I'm content for it to live here. I'd only add that #13701 carries a triaged, verified-labeled PR (#13782) against it, so if this issue becomes the tracking issue it may be worth carrying that reference over too.

Machine-readable summary. Omarchy 4.0.4-1 / kernel 7.2.5-3-omarchy / MacBookPro12,1 i5-5257U Broadwell-U / 42 of 42 suspends fail / restart counter max 24 / lid-close lock confirmed present via hyprctl binds.

Testing offer. I'll test a re-opened #12102 or any replacement fix, and report back with per-cycle results.

Taydevil avatar Oct 08 '26 01:10 Taydevil

Confirmed in source on quattro (c352b62d6). omarchy-system-sleep-monitor handles one PrepareForSleep(true) and then exits (bin/omarchy-system-sleep-monitor:12-14). The unit re-arms it through Restart=always / RestartSec=2 (default/systemd/user/omarchy-sleep-lock.service). When the restarted systemd-inhibit asks for a delay inhibitor while logind is still finishing that sleep operation, logind refuses with "already running", the process exits 1, and the unit is recorded as failed until the next attempt succeeds. That matches every journal on this thread.

The open pull request #13782 fixes the failure reported here. It retries that specific rejection in-process, and any other failure still exits as before. It was reproduced against real logind on an Omarchy worker at its current head: the base fails, the head stays clean, and the failure returns when the change is reverted. #12495, #13160 and #13701 report the same failure.

One part of the original report is not covered by #13782. After each sleep the monitor still exits and the inhibitor is not re-armed for at least RestartSec=2 after resume. A suspend that starts inside that window gets no delay inhibitor, so it gets no wait for a secure lock. The Hyprland lid-switch binding still requests a lock on its own, but that request does not wait for the lock to become secure. Closing the gap would mean keeping the monitor alive and re-arming on PrepareForSleep(false). That is a design change, so it is left to the maintainer. Nobody here has shown an actual unlocked suspend.

#13782 does not yet say it fixes this issue. Our tooling declined to add the link because the pull request has been pushed to since it was last classified, so that waits on its own review.

Reviewed by Claude Opus 5.5, with Codex Medium as the second opinion. Codex agreed on the mechanism and raised the re-arm gap described above; its independence from the first review is not guaranteed. Waiting on the maintainer.

omarchybot avatar Oct 09 '26 00:10 omarchybot

I'll step in here as we've observed a similar issue in Fedora CoreOS testing.

Do you think this is the same issue (systemd bug)?

On F35 (systemd v249.4-2.fc35), refchanged.service gets started multiple times during the update and reboot sequence without the systemd-inhibit error:

[   15.023971] systemd[1]: Started /usr/bin/systemd-inhibit --why=Wait for autopkgtest-reboot-prepare to finish bash /tmp/autopkgtest-reboot-prepare 35.20211029.3.0.
[   15.027511] kola-runext-test.sh[2629]: Running path as unit: refchanged.path
[   15.028803] kola-runext-test.sh[2629]: Will run service as unit: refchanged.service
[   82.530779] systemd[1]: Started /usr/bin/systemd-inhibit --why=Wait for autopkgtest-reboot-prepare to finish bash /tmp/autopkgtest-reboot-prepare 35.20211029.3.0.
[   82.635875] kolet[31661]: Requesting reboot with mark: 35.20211029.3.0
[   82.642732] kolet[1077]: Processing reboot request
[   82.650267] kolet[1077]: Acknowledged reboot request with mark: {"Reboot":"35.20211029.3.0","SoftReboot":""}
[   82.942924] sudo[31711]:     core : PWD=/var/home/core ; USER=root ; COMMAND=/bin/sh -c systemctl stop sshd && echo > /run/kolet-reboot-ack
[   82.980310] kolet[31661]: Reboot request acknowledged
[   82.983764] systemd[1]: refchanged.service: Deactivated successfully.
[   83.633993] rpm-ostree[1094]: Created new deployment /ostree/deploy/fedora-coreos/deploy/096cc2b6fb422d0464c0a3cea26e51de9e43535fe2edd04caa5bda323b8987fb.0
[   88.319164] zincati[1700]: [INFO  zincati::update_agent::actor] update staged: 36.20220505.3.2
[   88.331409] zincati[1700]: [INFO  zincati::update_agent::actor] staged deployment '36.20220505.3.2' available, proceeding to finalize it
[   89.190149] systemd[1]: Started /usr/bin/systemd-inhibit --why=Wait for autopkgtest-reboot-prepare to finish bash /tmp/autopkgtest-reboot-prepare 35.20211029.3.0.
[   91.025168] systemd[1]: Stopping /usr/bin/systemd-inhibit --why=Wait for autopkgtest-reboot-prepare to finish bash /tmp/autopkgtest-reboot-prepare 35.20211029.3.0... 

On F40+ (systemd 255.8-1.fc40), the service is started again while the previous inhibition request appears to still be active. The second invocation fails:

[   21.083425] kola-runext-test.sh[1814]: ok Reached version: 40.20240701.3.0
[   21.089835] kola-runext-test.sh[1814]: ok Reached stream: stable
[   21.098459] kola-runext-test.sh[1814]: ok Target version: 44.20261012.3.1
[   21.100313] kola-runext-test.sh[1814]: ok Target stream: stable
[   22.964169] kola-runext-test.sh[1814]: + systemd-run -u refchanged --path-property=PathChanged=/ostree/deploy systemd-inhibit '--why=Wait for autopkgtest-reboot-prepare to finish' bash /tmp/autopkgtest-reboot-prepare 40.20240701.3.0
[   23.008602] systemd[1]: Started refchanged.path - /usr/bin/systemd-inhibit "--why=Wait for autopkgtest-reboot-prepare to finish" bash /tmp/autopkgtest-reboot-prepare 40.20240701.3.0.
[   23.012595] kola-runext-test.sh[2085]: Running path as unit: refchanged.path
[   23.016060] kola-runext-test.sh[2085]: Will run service as unit: refchanged.service
[   33.270891] systemd[1]: Started refchanged.service - /usr/bin/systemd-inhibit "--why=Wait for autopkgtest-reboot-prepare to finish" bash /tmp/autopkgtest-reboot-prepare 40.20240701.3.0.
[   33.423915] kolet[2169]: Requesting reboot with mark: 40.20240701.3.0
[   33.430082] kolet[1807]: Processing reboot request
[   33.433299] kolet[1807]: Acknowledged reboot request with mark: {"Reboot":"40.20240701.3.0","SoftReboot":""}
[   33.744856] sudo[2267]:     core : PWD=/var/home/core ; USER=root ; COMMAND=/bin/sh -c 'systemctl stop sshd && echo > /run/kolet-reboot-ack'
[   33.812782] kolet[2169]: Reboot request acknowledged
[   33.832448] systemd[1]: refchanged.service: Deactivated successfully.
[   38.161221] systemd[1]: Started refchanged.service - /usr/bin/systemd-inhibit "--why=Wait for autopkgtest-reboot-prepare to finish" bash /tmp/autopkgtest-reboot-prepare 40.20240701.3.0.
[   38.220249] systemd-inhibit[2560]: Failed to inhibit: The operation inhibition has been requested for is already running
[   38.237225] systemd[1]: refchanged.service: Failed with result 'exit-code'.
[   38.247889] systemd[1]: Stopped refchanged.service - /usr/bin/systemd-inhibit "--why=Wait for autopkgtest-reboot-prepare to finish" bash /tmp/autopkgtest-reboot-prepare 40.20240701.3.0.
[   38.904305] systemd[1]: Stopped refchanged.path - /usr/bin/systemd-inhibit "--why=Wait for autopkgtest-reboot-prepare to finish" bash /tmp/autopkgtest-reboot-prepare 40.20240701.3.0.

The test still passes on F40+, so this doesn't appear to be critical. However, the behavior differs between releases.

Update: I apologize for posting this in the wrong repository. I hadn't realized this wasn't the systemd repository.

In any case, our issue turned out to be unrelated and has now been resolved. The root cause was that the --path-property=PathChanged= property generates two inotify CLOSE events, causing the service to be triggered twice.

Please disregard my previous comments. Apologies for the confusion, and thanks for your understanding.

nikita-dubrovskii avatar Oct 29 '26 14:10 nikita-dubrovskii

Closing this as a duplicate of #7280, which was opened a week earlier and reports the same bug with the same cause. In both, omarchy-system-sleep-monitor exits after one PrepareForSleep(true), Restart=always / RestartSec=2 brings it back while logind is still finishing that sleep operation, and the new systemd-inhibit is refused with "The operation inhibition has been requested for is already running". #7280 also covers the gap raised here: after each resume there is a window of about 2 seconds with no Omarchy delay inhibitor registered. It proposes keeping one long-lived monitor as the structural fix.

Discussion and fixes for the bug are in #7280. The open fix pull requests are #10455 (which links #7280), #13176 and #13782, and choosing between them is the maintainer's call. If you test a fix, please post the results on #7280. The journals and hardware data here are still worth reading and stay linked from this thread.

Compared by Claude Opus 5.5, and separately by Codex Medium as the second opinion before closing. If this turns out to be a different problem from #7280, say so here and it can be reopened.

omarchybot avatar Nov 01 '26 22:11 omarchybot