Skip to content

Dismiss stale low battery warnings - #11415

Closed
gaburn wants to merge 1 commit into
omacom:quattrofrom
gaburn:fix/stale-battery-warning
Closed

gaburn wants to merge 1 commit into
omacom:quattrofrom
gaburn:fix/stale-battery-warning

Conversation

@gaburn

@gaburn gaburn commented Sep 12, 2026 •

Copy link
Copy Markdown

Summary

  • dismiss the persistent low-battery notification once the battery recovers or stops discharging
  • preserve one-shot warning behavior while the battery remains low
  • add regression coverage for recovery to a full charge

Root cause

Low-battery notifications use critical urgency, which intentionally gives them an infinite lifetime. The battery service reset its notification bookkeeping after recovery but never dismissed the visible critical toast.

Testing

  • bash ./test/shell.d/battery-test.sh
  • bash ./test/shell.d/notifications-test.sh
  • visually verified the warning is removed through the shell notification dismissal path

Fixes #8813

Critical battery notifications do not expire, so explicitly dismiss the warning when the battery recovers or stops discharging.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed and reproduced. The fix works for the case it describes, and it fixes #8813, which is now linked.

Reproduction. I ran it on a worker built from the Omarchy ISO, with the real shell and notification service and a mock UPower on the system bus. In the mock, the battery dropped to 8% while discharging, and then either the charger was connected or the battery recovered to 100%.

  • On quattro (821ae58), the Time to recharge! toast was still on screen 40 seconds after the charger was connected.
  • On this head (f3e758b), the toast was gone within 5 seconds of connecting the charger, and also within 5 seconds of recovering to 100% while still discharging.
  • On this head with shell/plugins/services/battery/ reverted, the toast stayed, just as on quattro.

Tests, on the worker. On the head, test/shell.d/battery-test.sh passed 8 of 8, notifications-test.sh passed 135 of 135, and ./test/cli passed. Merged into current quattro, the full shell suite has the same six failures as quattro alone. One ./test/cli failure (the vscode theme test) is also on quattro. None of these are in the code this pull request touches.

One gap, not caused by this change. If the shell restarts or the machine reboots while the warning is up, the critical toast is restored from ~/.local/state, but notifiedLowBattery is not, since PersistentProperties only survives a reload. Connecting the charger after that leaves the restored toast on screen. I reproduced this on the worker with this head, and quattro behaves the same way. It does not block this fix. It could be a follow-up that dismisses a stale warning on the first check after the shell starts.

Second opinion. It did not run. The reviewer's daily limit was used up, so this review is Claude Opus 5.5's alone.

Related. Three other open pull requests also deal with this warning. #11959 dismisses it on a charger connect only, with no test. #12666 makes the warning normal urgency with a 12 second timeout, bundled with an unrelated toast-width change. #12115 includes a dismiss-and-retry version inside a large multi-area change. This one covers both a charger connect and a recovery, and it has a test. Which one lands is the maintainer's choice.

Next. This waits on a second-opinion review and then on the maintainer. Nothing is needed from the author.

@omarchybot

Copy link
Copy Markdown
Collaborator

Since the last review, quattro has moved, and the open pull requests for #8813 have been compared again with a second opinion. On the evidence of that comparison, this one should not be the fix brought forward.

The case this one misses. The low-battery warning is a critical toast, and the shell stores every toast on screen under ~/.local/state/omarchy/notifications/ and puts it back after a shell restart or a reboot. Critical toasts never expire (durationFor in shell/plugins/notifications/Service.qml returns 0 for them), and popupExpired treats 0 as never. The notifiedLowBattery flag this change relies on is kept in PersistentProperties, which survives a QML reload but not a restart. So if the battery runs flat at the warning, then charges, then boots, the warning comes back with the flag reset to false, and dismiss: !low && alreadyNotified never fires. That is probably the most common way to see a stale warning, and my last comment had reproduced it on a worker with this head. Newer pull requests do cover it: #13041 honours the explicit -t 30000 that omarchy-battery-low sends, so a restored warning expires, and #14739 and #14218 dismiss it from the battery service even when the flag is false.

Which one. The second opinion, Codex Medium, was given all seven open fixes (#11415, #11959, #12666, #13041, #14218, #14739 and #14825) without my conclusion. It independently found the same restart case, and it picked #13041 as the one to bring forward. I checked its reasoning against the source and it holds. However, #13041 is a change of policy, not just a fix: it makes any critical notification that asks for a timeout expire, so the battery warning would leave after 30 seconds even while the battery is still low. Whether that is acceptable is the maintainer's call. If it is not, #14739 and #14218 are the battery-side alternatives. Codex also pointed out their costs: #14739 starts a dismiss process every 30 seconds while the battery is healthy, and #14218 only looks for the restored toast during a fixed window of three checks.

Not run. Because this pull request is not the one to bring forward, it was not run on a worker this time. It now conflicts with quattro only in test/shell.d/battery-test.sh, against #15027, and keeping both sides resolves it. Nothing was pushed.

Next. This waits on the maintainer to choose among the open fixes. Nothing is needed from the author now. If this approach is chosen, it needs the restart case handled before it can be ready.

@jandrusk

Copy link
Copy Markdown

Same dismiss-low-battery cluster as #14739 / #14825 / #14218 / #11959 (issue #14639). This one also clears on recovery-to-full, not only AC. Maintainers should pick one dismiss PR and close the rest; #12666's timeout/urgency half is separate.

@omarchybot

Copy link
Copy Markdown
Collaborator

Closing in favour of #16562, which fixes the low battery warning staying up on the new notification engine (#15932). Thank you for working on this. Your change pointed at the right moment to take the warning down, and #16562 credits it.

#16562 matches the warning on its sender and icon rather than the English title, so it also works in other languages. It also covers the warning restored after a restart and one held behind an open notification deck.

@omarchybot omarchybot closed this Oct 25, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

A correction to the note above: #16562 has since taken the simpler route #14639 proposed. It sends the warning as a normal toast that expires after 30 seconds instead of dismissing it from the battery service. It still credits this pull request.

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.

Low-battery notification remains after charger is connected

3 participants