Repository navigation
Conversation
The low battery warning goes out as critical urgency, and the notification service gives critical popups no expiry at all -- `durationFor` returns 0 for `NotificationUrgency.Critical`, so the `-t 30000` that `omarchy-battery-low` passes is discarded. That is deliberate for an alert nobody should be able to miss, and `omarchy-battery-low` is the only command in `bin/` that sends one, so the low battery toast is the only popup in a stock install that never goes away on its own. Nothing took it down when the condition cleared. Plugging in only reset `notifiedLowBattery` so a later drop could warn again; the toast that was already up stayed there until it was clicked, long after the machine was back on AC. It reads as a stuck notification rather than a stale one, because nothing about it says which charge state it belongs to. `shouldWarnLowBattery` already computes everything the decision needs, so it now reports a `dismiss` alongside `notify`: true when a warning was sent and the battery is no longer low. The service dismisses by summary through `omarchy-notification-dismiss`, mirroring how it sends the warning through `omarchy-battery-low`. `checkBattery` already runs on `UPower.onBatteryChanged`, so this lands as soon as the charger goes in, with the existing 30s poll behind it. A battery that stops reporting dismisses too. It is no longer low in any sense the warning was about, and leaving the toast up would be the same bug.
There was a problem hiding this comment.
Pull request overview
Dismisses persistent low-battery notifications once charging resumes or the battery disappears.
Changes:
- Adds dismissal state to the battery model.
- Invokes notification dismissal and expands model tests.
Tip
If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
BatteryModel.js |
Computes when dismissal is needed. |
Service.qml |
Dispatches low-battery notification dismissal. |
battery-test.sh |
Tests dismissal state transitions. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| assertDeepEqual( | ||
| battery.shouldWarnLowBattery({ isPresent: true, percentage: 0.08, state: discharging }, false, discharging, 10, true), | ||
| { level: 8, notify: false, dismiss: true, notifiedLowBattery: false }, | ||
| 'battery dismisses the warning once charging resumes below the threshold' |
There was a problem hiding this comment.
Fair — the model tests can't see whether the service dispatches anything, and the ordering half of this was a real bug rather than just a coverage gap. Fixed in decb7ff, then finished in dc0d020.
The wiring is now asserted against Service.qml here the way monitor-recovery-test.sh asserts the monitor watcher's, since that's the established pattern for behaviour unreachable from run_node_test: the dispatch, the held dismiss, the replay on exit, the supersede ordering, and that the summary the service dismisses is still the headline bin/omarchy-battery-low sends. That last one is the coupling most likely to rot silently.
I checked each assertion is load-bearing rather than decorative — removing the in-flight guard, either onExited replay, the dismiss dispatch, or moving the pending-clear back above the guard each turns the suite red.
I did not add a graphical acceptance test. agents/skills/acceptance-tests.md calls for running that suite in a disposable VM through the sibling omarchy-iso repo, which I can't exercise, and an unverified acceptance test seemed worse than none. Happy to write the popup-appears/charger-in/popup-disappears path for someone with the ISO harness to run if you want it covered there.
| persisted.notifiedLowBattery = state.notifiedLowBattery | ||
| if (state.notify) sendLowBatteryWarning(state.level) | ||
| else if (state.dismiss) dismissLowBatteryWarning() |
There was a problem hiding this comment.
Right on both counts, and the second was still live. Fixed in dc0d020.
The framing is the useful part: because checkBattery clears notifiedLowBattery before the dismiss is issued, and dismiss is only ever computed from that latch, there's no retry behind any of this. Every early return out of dismissLowBatteryWarning is a permanent failure rather than a deferral, and what it strands is specifically the popup that never expires.
decb7ff covered the warningProcess return. The dismissProcess one was still a drop: pendingDismiss was cleared above that guard, so a request arriving while a dismiss was already running cleared the flag and returned without issuing anything, and nothing asked again.
Both processes now hold the request the same way and replay it from onExited, and the flag is cleared only on the path that actually issues the command — so it means "a dismiss is owed", and survives until one is sent rather than until one is attempted.
Load-bearing checks on the tests: dropping dismissProcess from the guard, moving the clear back above it, or removing either replay each turns the suite red.
`omarchy-battery-low` posts the toast from a spawned process, so the dismiss had a window where it could run first. Plug in during the moment between `sendLowBatteryWarning` starting that process and the notification reaching the server, and `omarchy-notification-dismiss` matches nothing -- then the toast arrives, with the machine already on AC, and stays up exactly as before. The race is narrow but it lands on the one path the change exists to fix, and the popup it strands is the one that never expires. A dismiss requested while the warning is in flight is now held and replayed from `warningProcess.onExited`, so it always runs against a posted toast. This mirrors how `pendingPowerSource` defers a profile switch across a running `powerProfileProcess`. Unplugging again before that warning finishes supersedes the queued dismiss instead: its toast is the current one, so `sendLowBatteryWarning` clears the pending flag before the in-flight early return, not after. The model tests cover the dismiss decision but cannot see whether the service acts on it, so the wiring is asserted against `Service.qml` the way `monitor-recovery-test.sh` asserts the monitor watcher's: the dispatch, the held dismiss, the replay on exit, the supersede ordering, and that the summary the service dismisses is still the headline the command sends. Each assertion fails if the line it covers is removed.
|
The ordering half of this was a real bug, not just a coverage gap — thanks. Fixed in decb7ff.
A dismiss requested while the warning is in flight is now held and replayed from On coverage, you're right that the model tests cannot see whether the service dispatches anything. I've asserted the wiring against I checked each assertion is load-bearing rather than decorative — removing the in-flight guard, the I did not add a graphical acceptance test. |
`checkBattery` clears `notifiedLowBattery` before the dismiss is issued, and `dismiss` is only ever computed from that latch, so a request dropped on the way out is never recomputed by a later poll. There is no retry behind it: the toast that never expires stays up for good. That makes every early return out of `dismissLowBatteryWarning` a permanent failure, not a deferral. Holding the dismiss across an in-flight warning covered one of those returns. The other was still a drop -- `pendingDismiss` was cleared above the `dismissProcess.running` guard, so a request arriving while a dismiss was already running cleared the flag and returned without issuing anything, and nothing ever asked again. Both processes now hold the request the same way and replay it from `onExited`, and `pendingDismiss` is cleared only on the path that actually issues the command. The flag now means "a dismiss is owed", so it survives until one is sent rather than until one is attempted. The tests assert the invariant rather than the shape: the guard covers both processes, both processes replay, and the clear sits on the issuing path. Each fails if the line it covers is removed, including reordering the clear back above the guard.
|
Right on both counts, and the second one was still live — fixed in dc0d020. The framing is the useful part: because decb7ff covered the Tests assert the invariant rather than the shape: the guard covers both processes, both replay on exit, and the clear sits on the issuing path. I checked each is load-bearing — dropping |
|
Reviewed on a disposable Omarchy VM with the shell actually running from this branch ( The premise checks out live rather than on inspection: The one real defect: A factual correction for the body. It says Small one on diagnostics. The bare Two things that are clean. On a battery-less machine — no Two things I could not prove, said plainly rather than implied. The worker is a VM with no battery and no line-power device, so Finally, so you are not surprised: #8895, #8458 and #7688 are all open and all fix #8813 as well, and #8895 conflicts with this one in |
|
Solution for Omabot analysis
You were right not to push it, for the reason you gave. One thing I found while verifying it that bears on your review. So every guard in this state machine works across turns, not within one. It holds here because each entry point — the 30s timer, the Body corrected. Your count is exact, I reproduced all twelve. The claim was wrong and so was the reason I built on it, which is the worse half: I argued for leaving Diagnostics done. Every assertion in the file now carries I mutation-tested the new assertions the way you did the old ones: eight mutations of the service dropping the in-flight guard, dropping either replay branch, dropping one On the two you couldn't prove: agreed on both, and agreed the shell-restart ordering is #7679's rather than something this should grow to cover Noted on #8895, #8458 and #7688. No argument from me about which lands, if #8895 is the better shape, the ordering above is the part I'd want carried across into it, whoever's branch it ends up on. |
The dismiss matches every toast whose summary contains the headline, so a warning posted while one is running is swept away with the toast that dismiss was sent for. Charging then unplugging again inside that window left checkBattery with notifiedLowBattery latched true and nothing on screen, and notify is computed from that latch, so no later poll ever warned again: the battery ran down under the threshold in silence. Hold a warning behind a running dismiss the way a dismiss is already held behind a running warning, and have whichever process was in flight replay what was held. The two commands now never overlap. A warning arriving while another warning is still going out is still dropped rather than held, since a second toast would only duplicate the first. Give the service assertions a failure message each while here, so a broken invariant names itself instead of exiting bare.
184c709 to
bbb1202
Compare
|
Re-reviewed at bbb1202. The race flagged last time is closed. The fix holds. A fresh warning could previously not cancel an in-flight dismiss, so it was swept away with the toast the dismiss was sent for while the latch stayed Since this is the third patch to one race, I traced the whole state machine rather than just the delta. Your note about Tests: Still open, and none of it a regression. Each of these leaves the user exactly where the pre-PR code did, so I do not think any should hold the change up:
On the coverage Copilot asked for: the service-level assertions do pin the ordering now, but they are greps over source shape, so a stray early Two housekeeping notes: the body does not name the issue it closes — this looks like it fixes #8813 — and #8895 is an open PR against the same behaviour, taking the simpler approach without the process ordering. Which of the two lands is the maintainer's call, not mine. Reviews: mine, plus an independent pass by Codex at xhigh reasoning. Codex agreed the state machine is sound for successful commands and normal exits; its independence is not currently guaranteed, so read that as agreement rather than confirmation. It contributed two things I had not reasoned about, which stand on their own: the shell-restart gap above, and the upstream detail that quickshell 0.3.1 sets the process to null before emitting Nothing pushed to your branch: there was no defect I could fix without making a product decision that belongs to the maintainer. |
Video wallpaper support (omacom#6792) added power profile polling to the battery service, and its new properties and refreshPowerProfile landed in the same two spots this branch adds the warning and dismiss state. The two don't interact, so both sides are kept.
|
Automated duplication check: this pull request looks similar to #11415, which covers the same low-battery warning dismissal on AC. I keep that one open and close this one to consolidate review. If you feel this is the wrong decision, please open the PR again with a note on the difference. |
Fixes #8813.
The problem
The low battery warning is sent with critical urgency, and the notification service gives critical popups no expiry at all:
So the
-t 30000thatomarchy-battery-lowpasses is discarded, and nothing dismissed the toast when the condition cleared. Plugging in only resetnotifiedLowBatteryso a later drop could warn again — the toast already on screen stayed up until it was clicked, long after the machine was back on AC.Reproducing
I confirmed the never-expiring half directly on 4.0.1: sending the warning by hand and waiting 45s with its own
-t 30000left the popup in place, with its state file still under~/.local/state/omarchy/notifications/.The change
shouldWarnLowBatteryalready computes everything the decision needs, so it now reports adismissalongsidenotify— true when a warning was sent and the battery is no longer low. The service dismisses by summary throughomarchy-notification-dismiss, mirroring how it sends the warning throughomarchy-battery-low.checkBatteryalready runs onUPower.onBatteryChanged, so the dismissal lands as soon as the charger goes in, with the existing 30s poll as a fallback.A battery that stops reporting dismisses too — it is no longer low in any sense the warning was about, and leaving the toast up would be the same bug.
Ordering the two commands
Both the warning and the dismiss are spawned processes, and
notifications.dismisstakes down every toast whose summary contains the needle, so the two must never overlap. Either direction is unrecoverable, becausecheckBatterylatchesnotifiedLowBatterybefore either command runs and computes bothnotifyanddismissfrom that latch — whatever is dropped is never recomputed by a later poll:true, so no later poll warns again and the battery runs down under the threshold in silence.So each command is issued only once the other process has exited, and held until then. A second warning arriving while one is already going out is dropped rather than held, since it would only duplicate the toast.
Worth knowing if you review this closely:
Process.runningdoes not go true synchronously on assignment — it flips on the next event loop turn. I checked this under quickshell rather than assuming it. Every entry point here (the 30s timer, theUPowersignal,onExited) is a separate turn, so the guards hold, andonExiteddoes readrunning === falseand can spawn the other process from inside the handler.On the expiry policy
I left
durationForalone, but not for the reason I first gave here — an earlier version of this description claimedomarchy-battery-lowwas the only command inbin/sending a critical notification. That is wrong, and I have corrected it. Twelve do:omarchy-battery-low,omarchy-capture-qr,omarchy-capture-screenrecording,omarchy-capture-screenrecording-with-webcam,omarchy-chromium-ytdlp-host,omarchy-crash-watch,omarchy-menu-share,omarchy-migrate-notify,omarchy-system-sleep-lock,omarchy-tailscale-receive,omarchy-tailscale-send,omarchy-windows-vmSeveral pass a
-tthat is discarded exactly as this one was —omarchy-capture-screenrecordingasks for-t 3000and-t 5000on toasts that will never expire. So makingdurationForhonour an explicitexpireTimeoutis a real question, and a bigger one than I implied, affecting every critical notification including the DND-bypass path. I still think it belongs in its own change rather than riding along with a battery fix, but that is your call to make at its actual size, not mine to wave away.Tests
test/shell.d/battery-test.shcovers both layers. Six model cases exercise thedismissdecision (charger in below threshold, recovery above it, nothing to dismiss, battery gone), and service-level assertions cover the dispatch and the ordering the model cannot reach: that the service acts ondismissat all, that it dismisses by the same summaryomarchy-battery-lowsends, that each command is held while the other is in flight, that a held request is retracted when the opposite decision supersedes it, and that both processes replay what was held.Those assertions are source-shape, so I mutation-tested them rather than trusting them: eight mutations of the service — including removing the in-flight guards, dropping either replay branch, and clearing a held request before its guard — each turn the file red, and each is caught by an assertion that names the invariant it broke.
On
test/all, five files (config,runtime-smoke,snapper,theme-install-guards,unowned-system-paths) fail identically on a pristinequattroon my machine, so they are environment-dependent rather than related to this change. Nothing else in the suite changes on this branch.I have not written the graphical acceptance test that would drive a real AC transition end to end; my hardware can post and dismiss the toast, which is the mechanism this change invokes, but I cannot drive the transition itself under the ISO harness.