Skip to content

Make installed sleep hooks executable and scope keyboard-backlight to ASUS - #14066

Open
gladimdim wants to merge 6 commits into
omacom:quattrofrom
gladimdim:fix/system-sleep-hooks
Open

gladimdim wants to merge 6 commits into
omacom:quattrofrom
gladimdim:fix/system-sleep-hooks

Conversation

@gladimdim

@gladimdim gladimdim commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Split out of #9816 so these can land independently of its ASUS sleep-configuration changes (#9816 has since been closed).

Problem

  1. Sleep hooks installed non-executable (hibernation setup installs keyboard-backlight system-sleep hook non-executable, so it never runs #7618). omarchy-hibernation-setup and omarchy-toggle-hybrid-gpu used to copy keyboard-backlight and force-igpu into /usr/lib/systemd/system-sleep with cp -p from files committed as 644. systemd-sleep only runs executables, so both hooks were silently skipped: the ASUS keyboard LEDs stayed lit into S4 (which keyboard-backlight exists to prevent), and force-igpu never detached the dGPU before hibernate. Seen on an ASUS ROG Strix G834JZ, where a critical-battery hibernate needed a power-button hold and the installed hook was -rw-r--r--.

    quattro (feb0557) has since made both installers install the hooks root-owned 0755, and migration 1788662350 replaces copies a user could write. It leaves root-owned copies alone, though, and cp -p from the root-owned packaged source produced exactly that: a root-owned 644 hook. Those stay inert, and simply making them executable would switch on old code.

  2. The keyboard-backlight hook turns off any keyboard and never restores it (Hibernate pre-sleep hook kills keyboard backlight permanently (no post-resume restore) #12657). It zeroed the first *kbd_backlight* LED of any vendor before hibernate and had no post branch, so a ThinkPad's keyboard stayed dark after resume, and after reboots once systemd-backlight saved the 0.

Solution

  • keyboard-backlight only touches ASUS keyboard LEDs (asus*kbd_backlight*, so asus::kbd_backlight and names such as asus:rgb:kbd_backlight). It saves their brightness in /run (in RAM, so part of the hibernation image) and restores it on post. If the level can't be saved, the LED still goes off, because a hang on power-off is worse than a dark keyboard, and the failure is logged. Its paths are fixed; tests run a rewritten copy.
  • Migration 1790960338 (runs after 1788662350):
    • replaces an installed keyboard-backlight or force-igpu that matches a version Omarchy shipped (sha256 of every version in quattro's history) with the current hook;
    • stages the new hook beside the old one (hidden, so systemd-sleep skips it), installs it 0755 and renames it into place through sudo, so a failed copy leaves the shipped version for a retry to recognize;
    • leaves a copy of the current hook, or anything an administrator wrote, alone: content and mode;
    • hashes hooks the user can't read as root, and exits on any failure so omarchy-migrate retries.
  • The hooks are executable in the repo.

Replacing an old force-igpu turns on the current one, which acts only while /etc/supergfxd.conf is in Integrated mode, and it is only installed when the user chose Integrated through omarchy-toggle-hybrid-gpu.

Not covered

Non-ASUS keyboards that the old hook already darkened keep the 0 that systemd-backlight saved until the user presses the brightness keys once. Telling that apart from a user who chose 0 isn't possible, so this PR doesn't touch systemd-backlight state.

Testing

  • test/shell.d/system-sleep-hooks-test.sh covers:
    • Hook: suspend ignored; only ASUS LEDs switched off, including another ASUS LED name; restore on resume; suspend-then-hibernate; a failed save (still off, logged, nothing restored); an empty saved level.
    • Migration: shipped 644 copies of both hooks replaced through a staged rename under (stubbed) sudo; a failed rename leaves the shipped hook, removes its stage, explains, and fails; a stage that can't be created explains and fails; rerun is a no-op with no privileged calls; current and customized hooks keep their content and mode.
    • Removing the stage cleanup, the shipped-hash check, a listed hash, or the wider LED glob each makes it fail.
  • test/shell.d/system-sleep-ownership-migration-test.sh: the compound-sleep check now runs a rewritten copy of the hook (same assertions); passes.
  • Every version of both hooks in quattro's history was checked against the migration's list.
  • On the ROG Strix G834JZ (asus::kbd_backlight, from asus-nb-wmi), the hook run by hand as root: pre hibernate saved 2 and turned the LED off, post hibernate restored 2 and removed the state. That's the hook, not a full hibernate cycle.
  • ./test/shell and ./test/cli: the only failures (9 shell files, one vscode-theme check) fail identically on quattro.

Fixes #12657
Fixes #7618

🤖 Generated with Claude Code

gladimdim and others added 2 commits October 2, 2026 19:49
… them

omarchy-hibernation-setup and omarchy-toggle-hybrid-gpu used to copy
keyboard-backlight and force-igpu into /usr/lib/systemd/system-sleep with
cp -p from files committed as 644. systemd-sleep only executes files with
the executable bit, so both hooks were silently skipped: the keyboard LEDs
stayed lit into S4, which keyboard-backlight exists to prevent on ASUS
keyboards, and force-igpu never detached the dGPU before hibernate.

Seen on an ASUS ROG Strix G834JZ, where a critical-battery
suspend-then-hibernate went straight to hibernate and the machine had to be
power-cycled: /usr/lib/systemd/system-sleep/keyboard-backlight was
-rw-r--r--.

The installers now install the hooks 0755, and migration 1788662350
replaces copies a user could write. It leaves root-owned copies alone,
which is what cp -p from the root-owned packaged source produced, so those
stay 644. Add a migration that makes them executable, mark the hooks
executable in the repo, and cover both with a shell test.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The hook zeroed the first *kbd_backlight* LED before hibernate and had no
post branch, so on non-ASUS laptops (tpacpi::kbd_backlight on a ThinkPad)
the keyboard stayed dark after resume, and systemd-backlight then saved
the 0 so it stayed dark after reboots too (omacom#12657).

Only touch asus*::kbd_backlight* LEDs, which are the ones with the S4
hang, save their brightness in /run (part of the hibernation image), and
put it back on post. If the level can't be saved the LED still goes off,
since a hang on power-off is worse than a dark keyboard, and the failure
is logged. The migration now replaces installed copies that still match a
shipped version, so making old copies executable no longer spreads the
bug, and repairs the root-owned copies through sudo.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@greptile-apps

greptile-apps Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[High impact] The PR appears safe to merge; no outstanding findings or new actionable issues remain.

Summary

The PR makes packaged sleep hooks executable, limits keyboard-backlight handling to ASUS LEDs with restoration after resume, and migrates recognized older installed hooks through staged replacement.

  • The latest change corrects the migration’s hash list and explanatory comment.
  • Both previous findings are addressed: replacement is staged before rename, and the tests cover a non-executable force-igpu copy.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Installed sleep hook] --> B{Matches an older shipped hash?}
  B -- No --> C[Leave content and mode unchanged]
  B -- Yes --> D[Stage current hook as executable]
  D --> E{Rename succeeds?}
  E -- Yes --> F[Replacement complete]
  E -- No --> G[Remove stage; retain old hook for retry]
Loading

Reviews (4) · Last reviewed commit: "Correct the shipped-hash list and the 17..." · Reviewed by Greptile

Comment thread migrations/1788695343.sh Resolved
Comment thread test/shell.d/system-sleep-hooks-test.sh Resolved
gladimdim and others added 3 commits October 2, 2026 19:58
Copying over the installed hook in place could leave a partial file if the
copy failed. A retry no longer recognized it as a shipped version, so it
only made it executable and marked the migration done. Stage the new hook
beside the old one and rename it into place, and cover force-igpu's repair
in the test.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
asus*::kbd_backlight* missed names such as asus:rgb:kbd_backlight, which
the old *kbd_backlight* glob covered, so match asus*kbd_backlight*. The
LED and state directories were environment overrides only the tests
needed; a root-run hook shouldn't read those, so the tests now run a copy
rewritten to fake directories, as the ownership test did.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Making root-owned 644 copies executable as they were would switch on old
code: earlier force-igpu copies call supergfxctl with no timeout and miss
the hibernate phase of suspend-then-hibernate. Replace any copy of a
shipped keyboard-backlight or force-igpu with the current hook, staged and
renamed through sudo, and leave current or administrator-written hooks,
content and mode, alone. Hooks the user can't read are hashed as root, and
failures exit so omarchy-migrate retries.

The migration moves to a current timestamp, after the migrations that
shipped since it was first written.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@jandrusk

jandrusk commented Oct 6, 2026

Copy link
Copy Markdown

Thorough work on the shipped-hash migration. Two things to help review:

I checked migration 1790960338: no collision with quattro or any open PR.

@omarchybot

Copy link
Copy Markdown
Collaborator

Thanks for splitting this out of #9816. This pull request does two things, and they end up in different places.

The keyboard-backlight fix for #12657 competes with #11669 and #13729. All three rewrite default/systemd/system-sleep/keyboard-backlight, so only one can land. #13729 already carries the fix and is waiting on the maintainer: it took the ASUS-only scoping from this pull request, and a ThinkPad X1 Carbon owner confirmed with a real hibernate that it no longer leaves tpacpi::kbd_backlight at 0. The oldest of the three, #11669, is also still open. One case this hook covers that #13729 does not: #13729 acts only when the first *kbd_backlight* LED is an ASUS one, and turns off only that LED, while this hook turns off and restores every asus*kbd_backlight* LED. That would matter on a laptop exposing two ASUS keyboard LEDs, or a non-ASUS keyboard LED that sorts first. No report so far shows such a machine, so I have not treated it as a defect in #13729. It is noted for the maintainer's choice between them.

The force-igpu repair for #7618 is something none of the other pull requests do. I checked every version of both hooks on quattro against the installers that copied them and migration 1788662350. Only one installed combination is still inert today: a root-owned, non-executable force-igpu with hash de620729…, copied with sudo cp -p between January and February while the source was 0644 (248a7a611, f3f36e252). 1788662350 replaces the d604e7c4… version and the f313a81e… keyboard hook whatever their owner, and fixes the mode of a copy matching the current source, but leaves de620729… alone. This migration replaces it. #12504's migration recognises only cbcd9972… and cb619d71…, so it misses it too. The repository mode changes don't affect installed hooks, since both installers now write them with 0755.

Two smaller points in migrations/1790960338.sh, neither of which breaks anything:

  • The 21bceaa6… keyboard hash (line 23) is this branch's own hook from a24708c6e and was never shipped. The description says the list is every version in quattro's history.
  • The header comment (lines 8–10) says 1788662350 leaves root-owned copies alone. It does replace the two legacy hashes and fix the mode of a current copy. What it leaves inert is de620729….

What was checked: the diff, the hook history on quattro and dev, the old installers, migration 1788662350, and the competing hooks in #11669, #13729 and #12504. I did not run this pull request on a worker: while #13729 carries the keyboard fix, this branch as it stands won't be the one to merge.

Second opinion: Codex Medium read the same pull requests without my conclusion. It found no functional defect at 8ce5d268 and found the same two comment and hash inaccuracies. It found the same de620729… gap. It also pointed out that #12504's migration misses that version, which I then confirmed. It preferred this hook over #13729 because of the first-LED case above, and also judged that the force-igpu repair belongs in a change of its own. Its independence from this review is not guaranteed.

Waiting on the maintainer: choosing which pull request carries #12657, and whether the force-igpu repair for #7618 should go forward on its own, for example with this pull request narrowed to that migration.

@omarchybot

Copy link
Copy Markdown
Collaborator

Thanks for the follow-up in ad114982. Both smaller points from the last review are fixed: the keyboard-backlight hash list in migrations/1790960338.sh now holds exactly the two versions in quattro's history (f313a81e… and 79215eed…; I re-hashed every version to check), so this branch's own hook is treated as current rather than shipped, and the header comment now describes 1788662350 accurately, including the de620729… force-igpu copy it leaves inert.

What was checked: the new commit against quattro's hook history and migration 1788662350. Nothing was run on a worker, for the same reason as before.

Second opinion: none this time. Codex Medium answers a ping, but omabot's daily review budget was spent, so the reviewer could not re-confirm the classification at this head. Until it does, this pull request's classification is recorded as unsettled; the earlier agreement that it is a bug fix still stands from the last review.

Still waiting on the maintainer: nothing else changed. #13729 still carries the keyboard-backlight fix for #12657 and is waiting on the maintainer, and #11669 is still open, so the choice between the three and whether the force-igpu repair for #7618 should go forward on its own remain theirs.

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

Labels

None yet

Projects

None yet

3 participants