Skip to content

Do not save or restore 0 in omarchy-brightness-keyboard - #19832

Closed
AxxzyWasTaken wants to merge 1 commit into
omacom:quattrofrom
AxxzyWasTaken:fix/brightness-keyboard-no-clobber-zero
Closed

AxxzyWasTaken wants to merge 1 commit into
omacom:quattrofrom
AxxzyWasTaken:fix/brightness-keyboard-no-clobber-zero

Conversation

@AxxzyWasTaken

Copy link
Copy Markdown

Problem

When omarchy-brightness-keyboard off runs while the keyboard backlight is already at 0, it saves 0 to ${XDG_RUNTIME_DIR:-/tmp}/omarchy-brightness-keyboard-$device and runs brightnessctl -d "$device" set 0.

On the next wake, omarchy-brightness-keyboard restore reads that saved 0 and writes 0 back to the LED device, overwriting whatever lit the keyboard in the meantime:

  • Ambient-light / lid daemons such as aurora-kbd-light blank /sys/class/leds/*kbd_backlight/brightness to 0 on lid close or display sleep, fade the backlight back up on wake/lid-open, and treat an external write of 0 while awake as the user manually turning the backlight off (off until turned on). Saving and restoring 0 causes omarchy-system-wake to slam the freshly restored backlight back to 0 and permanently latch auto-backlight off until manually re-enabled.
  • Even without an external daemon, if the backlight was off before blanking and the user raises it while locked, restore turns it back off on wake.

Fix

  • In bin/omarchy-brightness-keyboard:
    • Only treat a positive integer (^[1-9][0-9]*$) as a saved or savable backlight level.
    • When off sees the backlight is already 0, neither save a record nor call brightnessctl set 0 (leaving an already-off backlight off across lock/unlock without clobbering anything that lights it later).
    • Treat any stale 0 record like an empty record: off removes and replaces it if the backlight is lit (or just removes it if already 0), and restore discards it without writing 0.
  • Add unit tests in test/shell.d/brightness-keyboard-test.sh covering already-off off/restore without writes or clobbering, and stale 0 records on both off and restore.

Verification

  • bash test/shell.d/brightness-keyboard-test.sh (12/12 passing)
  • bash test/shell.d/brightness-keys-test.sh (10/10 passing)
  • bash test/shell.d/brightness-display-test.sh (17/17 passing)
  • bash -n bin/omarchy-brightness-keyboard test/shell.d/brightness-keyboard-test.sh

@greptile-apps

greptile-apps Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The brightness change appears safe to merge; the previous missing-test finding remains outstanding.

Findings

  1. P2 Backlight fix lacks a test ▶

Summary

Updates omarchy-brightness-keyboard to save and restore only positive brightness levels.

  • Keyboard wake no longer writes a saved zero back to the backlight.

No new findings were accepted.

Reviews (3) · Last reviewed commit: "Do not save or restore 0 in omarchy-brig..." · Reviewed by Greptile

@omarchybot omarchybot added the bug Something isn't working label Nov 22, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed the full diff, blank/wake callers, saved-state users, and regression tests at 6cea1bcf5308a8cff3f858e56949378272f2960f against quattro. This overlaps #19134: both prevent blanking an already-dark keyboard from saving zero and overwriting a level set before wake. This PR additionally removes or replaces zero records left by older code, and tests that neither off nor restore writes those zeros.

I am handing that existing-record handling and its regression cases to #19134 for incorporation with credit to @AxxzyWasTaken, keeping the fix with the earlier contribution. The handling on both off and restore matters: changing only restore would still let a stale zero record cause off to blank a newly lit keyboard.

GPT-6 High in Codex, Opus 5.5 High, and muse-wonder via pi (thinking high) reviewed the source. Both review models found no concrete defect here, but disagreed about the carrier: Opus preferred #19134, while muse-wonder preferred this PR for its existing-zero coverage. Their agreement is not guaranteed to be independent. No tests ran in this session because this competing fix is being left for the maintainer to choose between; physical backlight and Aurora behaviour remain unverified on this head. This PR remains open awaiting that decision.

omarchybot added a commit to aeries0x/omarchy that referenced this pull request Nov 22, 2026
A blank taken before this fix can leave a saved zero. Treat it as no record in both off and restore: off must save a newly lit level before blanking it, and restore must leave an externally set level alone. Incorporate the existing-record handling and regression coverage from omacom#19832 into the earlier fix.

Co-Authored-By: AxxzyWasTaken <axxzytte@gmail.com>
Co-Authored-By: GPT-6 (effort not exposed) <noreply@openai.com>
When the keyboard backlight is already at 0 (for example, turned off by an ambient-light or lid daemon such as aurora-kbd-light, or manually off), `omarchy-brightness-keyboard off` previously recorded 0 and wrote 0 again. On the next wake, `restore` then wrote 0 over whatever had lit the backlight in the meantime, turning it back off and latching auto-backlight daemons off until manually re-enabled.

Only treat positive integer levels as savable or restorable: leave an already-off backlight unrecorded and untouched on `off`, and treat any stale 0 record like an empty record on both `off` and `restore`.
@AxxzyWasTaken

Copy link
Copy Markdown
Author

Rebased onto quattro (e3802fd9c) to resolve the conflict from #19904 removing test/shell.d/brightness-keyboard-test.sh. bin/omarchy-brightness-keyboard is unchanged (7ca514013) and re-verified against all 11 regression cases locally.

@AxxzyWasTaken
AxxzyWasTaken force-pushed the fix/brightness-keyboard-no-clobber-zero branch from 6cea1bc to 7ca5140 Compare November 23, 2026 13:05
Comment on lines +43 to +46
if [[ ! $saved_level =~ ^[1-9][0-9]*$ ]]; then
rm -f "$saved"
level="$(brightnessctl -d "$device" get)"
if [[ $level =~ ^[0-9]+$ ]] && ! echo "$level" >"$saved"; then
if [[ $level =~ ^[1-9][0-9]*$ ]] && ! echo "$level" >"$saved"; 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.

P2 Backlight fix lacks a test

This changes how off and restore handle zero, but the described brightness-keyboard-test.sh is missing and no existing test exercises these branches. AGENTS.md requires a regression test for a bug fix that changes logic, so this requirement must be met before merging. Add a focused test that fails before the fix and passes afterward, checking that an initially dark keyboard stays untouched and stale zero records cause no brightness writes.

File Used: AGENTS.md (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@omarchybot

Copy link
Copy Markdown
Collaborator

Compared 7ca514013b9aa59a259d3227cdd27f97163ce087 with #19134 at 090ec876d122b21930459c963ce6691e50bd72b0: every executable line in omarchy-brightness-keyboard is identical; only the explanatory comment differs. The earlier PR now includes the existing-zero-record handling and regression cases from this contribution, crediting @AxxzyWasTaken as co-author.

GPT-6 in Codex (effort not exposed) checked both current diffs, the complete command files, and the blank/wake callers. The duplicate-close check refused to close this because the configured second reviewer, Opus 5.5 High, did not answer; its availability probe also failed. This head received no second review in this session.

No worker tests ran because the session stopped at that unresolved duplicate/competing-fix decision. The current diff contains no regression test, and Greptile's missing-test finding remains open. Both PRs remain open for the maintainer; #19134 also currently has a merge conflict. No changes were pushed.

aeries0x pushed a commit to aeries0x/omarchy that referenced this pull request Nov 23, 2026
A blank taken before this fix can leave a saved zero. Treat it as no record in both off and restore: off must save a newly lit level before blanking it, and restore must leave an externally set level alone. Incorporate the existing-record handling from omacom#19832 into the earlier fix.

Co-Authored-By: AxxzyWasTaken <axxzytte@gmail.com>
Co-Authored-By: GPT-6 (effort not exposed) <noreply@openai.com>
@AxxzyWasTaken

Copy link
Copy Markdown
Author

Closing in favor of #19134, which already includes the identical fix and tests and is now conflict-free.

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.

2 participants