Skip to content

feat(sleep): dynamic lid-close — battery suspend-then-hibernate, AC suspend, docked ignore - #12125

Open
ansonboby wants to merge 3 commits into
omacom:quattrofrom
ansonboby:feat/lid-dynamic-sleep
Open

ansonboby wants to merge 3 commits into
omacom:quattrofrom
ansonboby:feat/lid-dynamic-sleep

Conversation

@ansonboby

Copy link
Copy Markdown

Summary

Lid-close used a static suspend-then-hibernate everywhere (or nothing upstream). This makes it dynamic with zero daemons:

  • Battery: suspend-then-hibernate, hibernate after 20min (lid-open wakes instantly for short closes, no overnight drain)
  • AC: plain suspend (lid-open always wakes; power is free)
  • Docked: ignore (clamshell stays awake, matching omarchy-system-lid-close)
  • Safety: HibernateOnACPower=no keeps manual suspend-then-hibernate on AC in suspend

Why AC stays in suspend

Waking from true hibernate via lid-open needs firmware LID wakeup from S4. Tested HP 250 G9 exposes no LID0 power/wakeup and no /proc/acpi/wakeup LID row — only PWRB wakes from S4. Suspend keeps the fast lid-open path on AC; after 20min on battery the power button is required (noted in config comments).

Changes

  • default/systemd/logind.conf.d/99-omarchy-lid-sleep.conf (new)
  • default/systemd/sleep.conf.d/10-omarchy-suspend-then-hibernate.conf (new, 20min + HibernateOnACPower=no)
  • bin/omarchy-hibernation-setup installs both before resume marker (retryable), removes superseded manual 99-suspend-then-hibernate.conf
  • bin/omarchy-hibernation-remove cleans both up
  • test/shell.d/lid-sleep-policy-test.sh (new, 13 assertions)

Test plan

  • bash -n on both scripts clean
  • New test 13/13 pass; existing lid-close-test.sh + bin-style-test.sh still pass
  • Live: lid-close suspend verified in journal (suspend deep, lid-open wakes); hibernate path needs reviewer with swap to confirm 20min transition

…uspend, docked ignore

Battery lid-close suspends first (lid-open wakes instantly) then hibernates
after 20min to stop drain; AC stays in suspend where lid-open always wakes
(most firmware, incl. tested HP 250 G9, exposes no LID wakeup from S4 —
only PWRB wakes from hibernate); docked stays awake for clamshell, matching
omarchy-system-lid-close. HibernateOnACPower=no keeps manual
suspend-then-hibernate on AC in suspend too. Installed/removed by
omarchy-hibernation-setup/remove; supersedes the manual
99-suspend-then-hibernate.conf drop-in.

@Jamesking56 Jamesking56 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs a migration script for people who have it enabled already.

… policy

Setup installs the lid policy only on fresh runs; machines that already
have hibernation hit the early exit first. Backfill both drop-ins for
them, remove the superseded manual file, and reload logind (reboot
fallback). No-op when hibernation is absent or policy already matches.
@ansonboby

Copy link
Copy Markdown
Author

Added migration migrations/1789568195.sh for machines with hibernation already enabled (they hit setup's early exit before the new policy install):

  • No-op when /etc/mkinitcpio.conf.d/omarchy_resume.conf lacks the resume hook (fresh installs get the policy from setup), or when both drop-ins already match source
  • Installs both 99-omarchy-lid-sleep.conf and 10-omarchy-suspend-then-hibernate.conf via atomic staged install, removes superseded 99-suspend-then-hibernate.conf
  • systemctl reload systemd-logind (no session teardown); falls back to omarchy-state set reboot-required if reload fails. sleep.conf needs no reload (read per suspend)
  • Fails loudly (stays pending) if sources are missing or sudo is unavailable, so it retries via omarchy-migrate

Test: extended test/shell.d/lid-sleep-policy-test.sh (+7 assertions, 20/20 pass); also verified functionally with mocked paths — no-op when absent, installs + removes legacy + reloads when present, idempotent on rerun, exit 1 when source missing.

@omarchybot omarchybot added the enhancement New feature or request label Sep 27, 2026
@ansonboby

Copy link
Copy Markdown
Author

Re-review request — the migration you asked for is in at b6d6ae23.

This needs a migration script for people who have it enabled already.

That is migrations/1789568195.sh:

  • no-op when /etc/mkinitcpio.conf.d/omarchy_resume.conf lacks the resume hook (fresh installs get the policy from setup), or when both drop-ins already match source;
  • installs 99-omarchy-lid-sleep.conf and 10-omarchy-suspend-then-hibernate.conf through the atomic staged install, and removes the superseded 99-suspend-then-hibernate.conf;
  • systemctl reload systemd-logind with no session teardown, falling back to omarchy-state set reboot-required if the reload can't take.

Worth noting why a migration was needed at all: omarchy-hibernation-setup returns as soon as it sees the resume marker, so machines already configured never reach the new install step — neither a re-run nor --force gets there. Same shape turned up on #11948 this week, which now carries its own migration for the same reason.

Verified against current quattro: lid-sleep-policy-test.sh 20/20, PR MERGEABLE/CLEAN, no failing checks. The CHANGES_REQUESTED from Sep 16 is the only thing still blocking it, and that's not something I can dismiss myself.

@rand0mdud3

Copy link
Copy Markdown

Policy concern from the 11,x hibernate trenches: this makes battery lid-close suspend-then-hibernate with no model gating, but hibernate resume is broken on MacBookPro11,x — #11351 (11,5: frozen lock screen, dead input, no journal) plus a bricked-11,4 confirmation, and #7848 (11,3: resume kills the GPU session). On those machines this policy turns an unattended 20-minute lid-close into a lost session.

Suggest gating the battery suspend-then-hibernate path on models with known-good resume (or at minimum exempting 11,x until resume works there). The migration already branches per-machine state for hibernation presence; a DMI-based exemption would fit the same shape.

…e is broken

MacBookPro11,x loses the session when it resumes from hibernate: omacom#11351 (11,5 resumes to a frozen lock screen with dead input), omacom#7848 (11,3 kills the GPU session), plus a bricked 11,4 report. The new battery policy sends an unattended lid-close into hibernate after 20 minutes, so on those machines it trades a drained battery for a lost session.

Gate the policy on DMI via omarchy-hw-match, matching the precedent in migrations/1784401744.sh, and install a battery-suspend variant instead. Both delivery paths need the gate: setup for new machines, and the migration for machines that configured hibernation before the policy existed. The migration compares against the model-appropriate source, so a machine that already received the hibernate variant is repaired.

Reported by rand0mdud3.
@ansonboby

Copy link
Copy Markdown
Author

You're right, and this was a real regression rather than a theoretical one — thank you for connecting it to the resume bugs. Fixed in 8102ff31.

Battery lid-close now stays in suspend on models whose hibernate resume is known-broken, via omarchy-hw-match "MacBookPro11," (the same matcher migrations/1784401744.sh already uses for model-specific behavior). The new 99-omarchy-lid-sleep-no-hibernate.conf is identical apart from HandleLidSwitch=suspend, so AC and docked behavior are unchanged and there's no hibernate transition to fall off.

The gate is in both delivery paths, because only one of them reaches any given machine: omarchy-hibernation-setup for new setups, and 1789568195.sh for machines that configured hibernation earlier and hit setup's "already set up" early exit. A migration that delivered this policy to an 11,x would have been the worst kind of surprise. The migration also picks the model-appropriate source, so an 11,x that already received the hibernate variant during the window this was up gets corrected on the next run rather than staying broken.

I went with a denylist rather than the allowlist you suggested, and want to flag that as the one judgment call: gating on "models with known-good resume" would need a per-model resume database Omarchy doesn't have, and it would quietly drop the overnight-drain protection from the long tail of laptops that do resume fine. Exempting only models with a filed bug keeps the improvement where it's been observed working and removes it exactly where it costs a session. 11,3 (#7848), 11,4 (the bricked machine you cite) and 11,5 (#11351) all fall under one MacBookPro11, match. If other models turn out to have the same problem, it's a one-line addition to the pattern — and if a model's resume is only sometimes broken, that's probably also a denylist entry rather than an allowlist.

Covered by test/shell.d/lid-sleep-policy-model-gate-test.sh (15 assertions), which drives the migration for real against a stubbed DMI probe rather than grepping it: an 11,x gets the suspend variant, a healthy machine keeps suspend-then-hibernate, a machine left on the wrong variant is repaired, and a machine without hibernation gets nothing.

The trade, for the record: on these three models an overnight lid-close now drains battery instead of risking the session. Given "frozen lock screen, dead input, no journal" I'd take the dead battery, but that's the thing to revisit if resume is ever fixed on pre-T2 Macs.

@greptile-apps

greptile-apps Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 2/5

[High risk] Modifies system power management and sleep behavior.

The PR is not safe to merge until policy installation handles missing directories and removal cannot leave logind using a hibernation action after swap is removed.

Findings

  1. P1 Missing directories block installation ▶
  2. P1 Active lid policy remains stale ▶
  3. P1 Interrupted removal strands lid policy ▶

Summary

The PR adds battery-, AC-, and dock-aware lid-close policies, selects a suspend-only variant for MacBookPro11 models, and installs the policies through setup and a migration.

  • Installation needs to handle absent drop-in directories.
  • Setup and removal need to keep logind’s active policy in sync with changes on disk.

Reviews (1) · Last reviewed commit: "fix(sleep): keep lid-close in suspend on..."

Comment on lines +144 to +145
if ! install_root_file "$OMARCHY_PATH/default/systemd/sleep.conf.d/10-omarchy-suspend-then-hibernate.conf" \
/etc/systemd/sleep.conf.d/10-omarchy-suspend-then-hibernate.conf 0644; then

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Missing directories block installation

If /etc/systemd/sleep.conf.d does not exist, setup tries to create a temporary file inside it and exits before writing the resume marker. The migration uses the same approach, so retrying it fails again. Neither path can install the lid-close policy until the directory is created. Create the destination directories before staging the files.

Comment on lines +51 to +55
# Remove lid-close / suspend-then-hibernate policy installed by setup.
# Logind re-reads on reboot; sleep.conf is read per suspend, so no reload needed.
echo "Removing lid-close sleep policy"
sudo rm -f /etc/systemd/logind.conf.d/99-omarchy-lid-sleep.conf
sudo rm -f /etc/systemd/sleep.conf.d/10-omarchy-suspend-then-hibernate.conf

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Active lid policy remains stale

Removal deletes the swapfile and policy files but does not reload logind or request a reboot. Until the next reboot, logind can still use suspend-then-hibernate, so closing the lid on battery can request hibernation after the swapfile is gone. Fresh setup has the reverse delay: its new lid policy is not active until reboot. Apply or schedule the logind change in both paths, as the migration does.

Comment on lines +53 to +55
echo "Removing lid-close sleep policy"
sudo rm -f /etc/systemd/logind.conf.d/99-omarchy-lid-sleep.conf
sudo rm -f /etc/systemd/sleep.conf.d/10-omarchy-suspend-then-hibernate.conf

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Interrupted removal strands lid policy

If removal is interrupted after it deletes the resume marker but before it deletes these policy files, a retry exits at the missing-marker check. The lid can remain configured for suspend-then-hibernate even though the swapfile has already been removed. Make policy cleanup reachable on a retry without the marker.

@jandrusk

Copy link
Copy Markdown

Interesting lid-close policy PR: battery → suspend-then-hibernate (20m), AC → suspend, docked → ignore, with MacBookPro11,x gated to plain suspend (#11351). Migration included for existing hibernation setups.

Product call on making this the default everywhere — related open issues on docked lid-close / lock blank treating externals as undocked (#15207, #15152). Also overlaps the broader hibernation fix set (#13768, #13908, #14520).

I'm +1 on the MacBookPro11 gate; the global policy change needs a maintainer decision.

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants