Skip to content

Wait for an active output before sleep-lock finishes - #13480

Open
AnPod wants to merge 1 commit into
omacom:quattrofrom
AnPod:fix/sleep-lock-active-output
Open

AnPod wants to merge 1 commit into
omacom:quattrofrom
AnPod:fix/sleep-lock-active-output

Conversation

@AnPod

@AnPod AnPod commented Sep 27, 2026

Copy link
Copy Markdown
Contributor

Summary

Undocking with the lid closed can suspend the laptop while only FALLBACK/empty outputs exist, causing the lock client to have no real output for a surface and leaving resume waking to a black screen (#13300).

This change:

  1. Reconciles clamshell state via omarchy-hyprland-monitor-clamshell until a real monitor is enabled.
  2. Ensures at least one non-placeholder, non-FALLBACK active display is available before sleep-lock completes.
  3. Fails closed with a warning notification if no display can be enabled within the logind inhibitor budget.
  4. Adds test coverage in test/shell.d/sleep-lock-test.sh verifying active output recovery and headless fallback handling.

Fixes #13300

@llstrk

llstrk commented Sep 28, 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 two new sleep-lock scenarios are real regression tests. Each fails against the base omarchy-system-sleep-lock and passes on this head. Normal suspend paths (lid open, docked clamshell with an enabled external, desktops with a connected monitor) behave as before, apart from one extra hyprctl monitors -j call before the loop and one per poll (two in total when the shell is already secure), as long as Hyprland answers promptly. Hyprland 0.56.2 does list FALLBACK in hyprctl monitors while in fallback state, so filtering it by name is justified.

The review found one issue in the new check: the Hyprland query it adds is not bounded by the inhibitor budget. There is also an open question about whether this resolves #13300, a misleading warning on the FALLBACK-only path, and an unrelated Windows VM commit bundled into the branch.

The new hyprctl query is not bounded by the budget, and now gates success

has_active_output (bin/omarchy-system-sleep-lock:97-101) runs hyprctl monitors -j without timeout. The script's other IPC calls are bounded. The header says "Every call below is bounded by what is left of the budget", lock_ipc clamps the shell calls to the remaining time, and sync_clamshell is capped at 0.4 s because "Lid transitions can temporarily stall Hyprland IPC". hyprctl's only limit is its own 5 s socket receive timeout. exit 0 is now reachable only after this query succeeds.

Mocked runs, with the shell always reporting {"secure":true}:

hyprctl behaviour Budget Base Head
answers correctly after 2.5 s 1500 ms not run (base reaches hyprctl only through the 0.4 s-capped clamshell sync) exit 1 at 2510 ms, "the shell did not secure the session within 1500ms"
blocks for its 5 s receive timeout 4000 ms (5 s logind window) exit 0 at 16 ms exit 1 at 5011 ms, past the logind window
exits 1 immediately 4000 ms (5 s logind window) exit 0 at 12 ms exit 1 at 4092 ms

Each head exit 1 also sends the critical "Screen did not lock before suspend. The session was left unlocked (...)" notification.

Impact: when Hyprland IPC is slow or stalled at PrepareForSleep, a session that the shell already secured is held for up to the whole budget (12 s at the shipped 15 s window), can outlive logind's window, and ends with a false "left unlocked" warning. The script itself notes that lid transitions can stall Hyprland IPC, and undocking with the lid closed reconfigures displays.

Suggested change: run the query under timeout, clamped to the remaining budget as lock_ipc does. Distinguish "Hyprland answered and no real output is enabled" from "Hyprland could not be asked", and in the second case fall back to the previous behaviour of trusting the shell's secure.

FALLBACK-only path can report "left unlocked" for a locked session

The new undock_headless_forever test mocks a shell that reports {"secure":true} while only FALLBACK is listed, and expects failure. From source, the shell can report secure in that state: Hyprland advertises FALLBACK to clients as a named 1920x1080 output, which shell/plugins/lock/Service.qml counts as a lockable screen. In a mocked run, head waited the whole budget (4005 ms at a 4000 ms budget) and then showed "The session was left unlocked (no active display was available before suspend)". Base exited 0 in 12 ms.

Impact: the wait path never asks the shell, so when the shell has secured the session (as the new test models), the warning still says "left unlocked" although only a physical display was missing. On machines where no display can be recovered, for example a desktop whose only monitor dropped off when switched off, sync_clamshell has no internal panel to re-enable. Every such suspend then waits the full budget (12 s at the shipped window) before this warning.

Suggested change: use a message that names the actual condition, and wait only when there is something to recover, such as an internal panel or a set clamshell flag.

Related: has_active_output counts an enabled 0x0 (modeless) output as active, while Service.qml's realScreenCount() requires a non-zero size, so in that state the new wait never engages. Base behaves the same, so this is a gap rather than a regression. Requiring a non-zero size, as realScreenCount() does, would make the two agree on modeless outputs. On its own that only changes the exit message, because clamshell's external-monitor check still counts the 0x0 output and keeps eDP-1 off.

Does this resolve #13300?

The new check looks at Hyprland's monitor list, not at whether the lock client has a surface on the panel. Quickshell's secure stays true from the moment Hyprland confirms the lock until unlock. Hyprland confirms once every enabled, powered-on monitor has rendered a lock frame, immediately if there is none, and after a 5 s timer regardless. The issue's journal suggests the lock had already been requested or taken, and a real monitor had already been added, before PM: suspend entry:

22:42:33 omarchy-shell: DEBUG: Not creating lock surface for screen QScreen(..., name="") as it is not backed by a valid wayland output.
         -> logged only while the shell is taking or holding the session lock (Quickshell session_lock.cpp)
22:42:33 omarchy-shell: WARN quickshell.hyprland.ipc: Got removal for monitor "FALLBACK" which was not previously tracked.
         -> Hyprland leaves fallback when a real monitor is added (FallbackState.cpp)
22:42:34 kernel: PM: suspend entry (s2idle)

In that state the new check passes, so it would not hold the suspend back if the shell had already reported secure. Opening the lid also runs omarchy-hyprland-monitor-clamshell through the locked switch:off:Lid Switch binding, and Quickshell adds lock surfaces for new screens. So "suspend overtook the re-enable" does not by itself explain a screen that stays black. This is source analysis of the journal, not a reproduction. The reporter has seen the failure once.

Impact: in the state the journal suggests, the new check would pass, so the PR's claim to fix #13300 is not established. The change may still narrow a related race.

Suggested change: unless the fix has been reproduced and verified on hardware, use "Refs #13300" instead of "Fixes #13300", or check for a lock surface on the panel rather than for an enabled monitor.

Unrelated Windows VM commit

Commit 2b4b0eba ("Clear setgid when hardening Windows VM mount folders (#1)") changes both chmod 0700 hardening sites in bin/omarchy-windows-vm to chmod 00700 and adds tests. The PR description does not mention it, and it is unrelated to #13300, so the PR bundles two unrelated fixes.

Verified: the change itself is correct. GNU chmod keeps an existing directory setgid bit for a 4-digit numeric mode (chmod 0700 on a 2777 directory gives 2700; chmod 00700 gives 700), and dockur/windows sets an empty share to 2777.

Impact: the same fix is already open in other PRs on the same lines, for example #13154 and #13213 (same chmod 00700) and #12323 (equivalent u=rwx,go=,a-s, with different test expectations).

Suggested change: drop this commit from the PR and leave the Windows VM fix to one of the dedicated PRs.

Optional test improvement: three diagnostic mutants of the head script each pass the whole head sleep-lock-test.sh: polling lock status before sync_clamshell, removing the main-loop has_active_output gate, and removing the second request_lock. The first survives because the existing check "sleep lock checks security after clamshell reconciliation" now only asserts that both calls appear somewhere in the log. Comparing the index of the first clamshell with the first shell lock status keeps the check's intent. A scenario that loses its output after the initial wait would cover the main-loop gate, and a slow or failing hyprctl case would cover the unbounded query above. The second request_lock is better removed than tested (see the optional note below).

Optional cleanup: the second request_lock is redundant. Once lockRequested is set, the shell's lock() IPC returns "ok" without acting (Service.qml), and a request that never landed is re-sent by the main loop anyway. The comment above it implies that asking again helps produce a surface, but the shell already retries on its own until a real screen exists.


Review information

Test scope: Source review of the head, merge-base and current quattro, plus Hyprland 0.56.2, Quickshell 0.3.1, gnulib/coreutils chmod and dockur/windows sources. Sleep-lock behaviour was tested only with mocked hyprctl, shell and clamshell commands in an isolated sandbox, so the timings above are from mocks. No real compositor, logind, lock screen or undock was exercised, and the #13300 analysis is not a reproduction. The Windows VM compose and mount-boundary runtime tests could not run in the sandbox. The chmod conclusion rests on a direct GNU chmod run, windows-vm-test.sh and source reading.

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.

Undocking with the lid closed can suspend while only FALLBACK/empty outputs
exist, so no lock surface is created and resume wakes black. Reconcile
clamshell until a real monitor is enabled before treating the session as
ready to sleep.

Fixes omacom#13300

Co-authored-by: AnPod <AnPod@users.noreply.github.com>
@cursor
cursor Bot force-pushed the fix/sleep-lock-active-output branch from ebf5341 to 06fea19 Compare September 29, 2026 21:09
@omarchybot omarchybot added the bug Something isn't working label Oct 1, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed at 06fea19 by Claude Opus 5.5, with a second opinion from Codex at medium effort. The idea holds up: re-running clamshell reconciliation until a real output is back addresses the race in #13300. But two defects need fixing before this can go further, and the fix still needs confirming on hardware.

What ran, on a disposable Omarchy VM running this branch's shell:

  • test/shell.d/sleep-lock-test.sh: 22 passed. The new recovery scenario fails against the base script and passes on this head. ./test/cli stops at vscode generated theme references current theme file, which fails the same way on the base commit, so it is not from this change.
  • With the only output disabled, Hyprland lists just FALLBACK, and the shell locks and reports secure against it. The base script exits 0 in about 570 ms, which matches the secure=true after no-real-screen in the second journal on Undocking with the lid closed suspends with no active output: black screen after resume (clamshell race) #13300.
  • On this head, with the output re-enabled 1.5 s into the wait, the script waits for it and exits 0 at 2.2 s. That is the intended behaviour.
  • I could not reproduce the black screen itself. Without a suspend, re-enabling the output after a lock taken against FALLBACK draws the lock screen normally. So the failure needs a real suspend and resume, which a VM can't do, and the fix is unproven until someone with the hardware tests it.

Defects:

  1. When no output can be recovered, it waits out the whole budget and then reports a false failure. I ran this on the VM: with the only output disabled and nothing to re-enable, this head waited the full 4000 ms budget and then sent "Screen did not lock before suspend… The session was left unlocked (no active display was available before suspend)", while omarchy-shell lock status reported secure: true. The same thing happens to a desktop that idle-suspends after its only monitor was switched off and disconnected, which is a common routine. sync_clamshell has no internal panel to bring back, so every such suspend is held for 12 s at the shipped 15 s logind window and ends with a critical notification that isn't true. The undock_headless_forever test codifies this by mocking {"secure":true} and expecting failure. One way out is to wait only when there is something to recover (an internal panel, or the clamshell flag set), and to word the message after the real condition rather than "left unlocked". Also, omarchy-system-sleep-monitor holds a delay inhibitor, so logind suspends either way. The comments and test describe the new path as failing closed, but it doesn't: it only warns.
  2. has_active_output runs hyprctl monitors -j with no timeout (bin/omarchy-system-sleep-lock:97-101). Every other IPC call in the script is clamped to the remaining budget, and sync_clamshell caps its own at 0.4 s because lid transitions can stall Hyprland IPC. exit 0 can now only be reached after this query answers, so a stalled Hyprland during an undock can hold an already-secured session past logind's window. Running it under timeout, clamped like lock_ipc, and trusting the shell's secure when Hyprland can't be asked would keep the previous behaviour in that case.

Smaller points: the extra request_lock after waiting does nothing once a lock has been requested, because the shell's lock() IPC returns ok without acting when locked is true (shell/plugins/lock/Service.qml:647-650), and a pending lock already retries when the screens change. The loosened assertion "sleep lock checks security after clamshell reconciliation" (test/shell.d/sleep-lock-test.sh:135) no longer checks the order of the two calls. And because the check reads Hyprland's monitor list, it shows that an output is enabled, not that the lock has a surface on it.

Codex found both defects as well. It can read this review's working notes, so its agreement is not guaranteed to be independent. It contributed the point that the inhibitor is a delay inhibitor, so nothing actually fails closed, which I have checked against bin/omarchy-system-sleep-monitor.

#13640 has the same diff as this pull request, opened a day later, and is handled as its own item. #13792 fixes overlay windows after the same kind of output loss and does not compete with this one.

Next: this waits on @AnPod for the two defects. After that, it needs @azzouzidk, who opened #13300, to confirm the new head on the affected Framework 13 by undocking with the lid closed, since a VM can't suspend. The maintainer decides after that.

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.

Undocking with the lid closed suspends with no active output: black screen after resume (clamshell race)

4 participants