Skip to content

Dismiss the low battery warning when charging resumes - #8838

Closed
Eyasuk wants to merge 5 commits into
omacom:quattrofrom
Eyasuk:dismiss-low-battery-warning-on-charge
Closed

Eyasuk wants to merge 5 commits into
omacom:quattrofrom
Eyasuk:dismiss-low-battery-warning-on-charge

Conversation

@Eyasuk

@Eyasuk Eyasuk commented Aug 28, 2026 •

Copy link
Copy Markdown

Fixes #8813.

The problem

The low battery warning is sent with critical urgency, and the notification service gives critical popups no expiry at all:

// shell/plugins/notifications/Service.qml
case NotificationUrgency.Critical:
  return 0

So the -t 30000 that omarchy-battery-low passes is discarded, and nothing dismissed the toast when the condition cleared. Plugging in only reset notifiedLowBattery so 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

  1. Run down to 10% on battery. The "Time to recharge!" toast appears.
  2. Plug in the charger.
  3. The toast stays on screen indefinitely.

I confirmed the never-expiring half directly on 4.0.1: sending the warning by hand and waiting 45s with its own -t 30000 left the popup in place, with its state file still under ~/.local/state/omarchy/notifications/.

The change

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 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.dismiss takes down every toast whose summary contains the needle, so the two must never overlap. Either direction is unrecoverable, because checkBattery latches notifiedLowBattery before either command runs and computes both notify and dismiss from that latch — whatever is dropped is never recomputed by a later poll:

  • A dismiss racing ahead of its warning matches nothing, and the toast that lands just behind it never expires.
  • A warning posted while a dismiss is running is swept away with the toast that dismiss was sent for. The latch is already 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.running does 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, the UPower signal, onExited) is a separate turn, so the guards hold, and onExited does read running === false and can spawn the other process from inside the handler.

On the expiry policy

I left durationFor alone, but not for the reason I first gave here — an earlier version of this description claimed omarchy-battery-low was the only command in bin/ 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-vm

Several pass a -t that is discarded exactly as this one was — omarchy-capture-screenrecording asks for -t 3000 and -t 5000 on toasts that will never expire. So making durationFor honour an explicit expireTimeout is 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.sh covers both layers. Six model cases exercise the dismiss decision (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 on dismiss at all, that it dismisses by the same summary omarchy-battery-low sends, 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 pristine quattro on 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.

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.
Copilot AI balanced review requested due to automatic review settings August 28, 2026 23:07

Copilot AI left a comment

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.

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.

Comment on lines +31 to +34
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'

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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.

Comment on lines 34 to +36
persisted.notifiedLowBattery = state.notifiedLowBattery
if (state.notify) sendLowBatteryWarning(state.level)
else if (state.dismiss) dismissLowBatteryWarning()

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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.
@Eyasuk

Eyasuk commented Aug 28, 2026

Copy link
Copy Markdown
Author

The ordering half of this was a real bug, not just a coverage gap — thanks. Fixed in decb7ff.

omarchy-battery-low posts the toast from a spawned process, so there was a window where the dismiss could win: plug in between sendLowBatteryWarning starting that process and the notification reaching the server, and omarchy-notification-dismiss matched nothing — then the toast arrived, already on AC, and stayed up exactly as before. Narrow, but it lands on the one path this 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, mirroring how pendingPowerSource defers a profile switch across a running powerProfileProcess. Unplugging again before the warning finishes supersedes the queued dismiss instead — its toast is the current one — so sendLowBatteryWarning clears the flag before the in-flight early return rather than after.

On coverage, you're right that the model tests cannot see whether the service dispatches anything. I've asserted the wiring against Service.qml the way monitor-recovery-test.sh asserts the monitor watcher's, since that is the established pattern here for behaviour that isn't reachable 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, the onExited replay, the dismiss dispatch, or moving the supersede-clear below the early return 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 here, and an unverified acceptance test seemed worse than none. If a maintainer wants the full popup-appears/charger-in/popup-disappears path covered there, I'm happy to write it for someone with the ISO harness to run — say the word and I'll add it.

`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.
@Eyasuk

Eyasuk commented Aug 28, 2026

Copy link
Copy Markdown
Author

Right on both counts, and the second one 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 is 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, not until one is attempted.

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 dismissProcess from the guard, moving the clear back above it, or removing either replay each turns the suite red. Full test/all is otherwise unchanged by the branch; the four files that fail (config, snapper, theme-install-guards, unowned-system-paths) fail identically on a pristine quattro here.

@Eyasuk
Eyasuk marked this pull request as draft August 29, 2026 11:30
@Eyasuk
Eyasuk marked this pull request as ready for review August 29, 2026 11:30
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed on a disposable Omarchy VM with the shell actually running from this branch (quickshell -n -p .../pr-8838/shell), reviewed twice: once by me, Claude Opus 5 in Claude Code, and once by Codex at xhigh reasoning as an independent second opinion. Codex's independence is not currently guaranteed, so where it only agreed with something I had already written down I say so — the sharpest half of the first finding below is its contribution rather than mine. battery-test.sh passes at 16 assertions on your tree, as do battery-status-test.sh, notifications-test.sh and notification-send-test.sh.

The premise checks out live rather than on inspection: omarchy-battery-low 8 posts {"summary":"Time to recharge!","urgency":2,"expireTimeout":30000} and the toast is still up 40 seconds later, and omarchy-notification-dismiss "Time to recharge!" takes it down. And your assertions are load-bearing, which I confirmed by mutating rather than by reading — on the worker, deleting only the else if (state.dismiss) dismissLowBatteryWarning() call, narrowing the guard to warningProcess.running alone, deleting one of the two onExited replays, and moving pendingDismiss = false below the early return each turn the file red, and removing dismiss from the model turns it red with a readable expected-versus-actual. That is a materially better test than a source-shape suite usually is.

The one real defect: sendLowBatteryWarning cannot cancel a dismiss that is already in flight, and the cost is a warning the user never sees. dismissLowBatteryWarning waits for dismissProcess, but sendLowBatteryWarning at Service.qml:63-69 clears pendingDismiss and checks only warningProcess.running, so it will post a fresh warning while a dismiss is still running. Warning A is up; the charger goes in and dismiss D starts; the charger comes out before D lands, and warning B is posted. If B reaches popupModel before D's IPC call, the substring loop at shell/plugins/notifications/Service.qml:912-923 takes down both A and B. The part I had not carried far enough, and Codex did: checkBattery has already set the latch true for B, so notify is low && !alreadyNotified — false — on every subsequent 30-second poll. The user is then sitting below 10% with no warning on screen and no way to get one until they charge back above the threshold and drop again. Narrow window, but the failure is silent and it is the opposite of what this change is for. Your comment at :61-62 reasons about the warningProcess direction of this and gets it right; it is the dismissProcess direction that is open. I have not pushed a fix: closing it properly means a pending-warning hold symmetric to pendingDismiss, which is a design addition to a state machine you have deliberately shaped, not a contained bug fix.

A factual correction for the body. It says omarchy-battery-low "is the only command in bin/ that sends a critical notification, which makes the low battery toast the only popup in a stock install that never expires on its own." Twelve commands on quattro send -u critical: 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 and omarchy-windows-vm. Several pass a -t that is discarded exactly as yours was — omarchy-capture-screenrecording:25,69,219 asks for -t 3000 and -t 5000 on toasts that will never expire. This does not make the change wrong, and leaving durationFor alone is still defensible, but the reason given for leaving it alone is that only one caller is affected, and that is not the case. Worth correcting so the maintainer weighs the policy question at its real size.

Small one on diagnostics. The bare grep … >/dev/null assertions are not vacuous — set -euo pipefail makes a miss exit the file and test/shell reports it — but they lose the message. Reverting the production change on the worker turned the file red with a bare exit 1 and no not ok line naming what broke, where the Node assertions in the same file print a proper expected-versus-actual. monitor-recovery-test.sh does set the precedent you cite, so this is house-consistent rather than wrong; appending || fail "…" would cost nothing and tell the next person which invariant they broke.

Two things that are clean. On a battery-less machine — no /sys/class/power_supply entries, DisplayDevice reporting battery-missing-symbolic — the change throws no QML TypeError and the bar comes up normally; worth checking, since a TypeError in this service would take the whole bar down for everyone. And the BatteryModel.js change breaks nothing: Service.qml:34 is the only consumer of that return shape in the tree, and every return path now defines dismiss.

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 UPower.onBattery never changes there and I could not drive the actual AC transition — what is proven live is the mechanism your code invokes, not your trigger. And neither this PR nor its alternatives covers the shell-restart ordering: PersistentProperties persists across a QML reload but not across a process restart, while the critical popup is restored from ~/.local/state/omarchy/notifications/, so after a restart on AC the latch starts false and nothing dismisses the restored toast. That is #7679's territory rather than yours, and I have flagged it to the maintainer as pre-existing rather than as something this PR should grow to cover.

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 Service.qml. Which one lands is the maintainer's call, not mine — I have reviewed this one on its own merits and given them the comparison.

@Eyasuk

Eyasuk commented Aug 29, 2026 •

Copy link
Copy Markdown
Author

Solution for Omabot analysis
The defect is real, and I've fixed it in bbb1202. The trace is exactly right, the sweep taking down B is survivable on its own, but the latch already reading true for B is what makes it permanent, and silent.

sendLowBatteryWarning now holds behind a running dismiss the way a dismiss already holds behind a running warning, and both processes replay whatever was held through one runPendingBatteryNotification(). Each function retracts the other's held request, so at most one is ever pending, charging again drops a held warning, unplugging again drops a held dismiss. The one asymmetry I kept is deliberate: a warning arriving while another warning is still going out is still dropped rather than held, because that second toast would only duplicate the first. Only the dismiss direction needs the queue, because only the dismiss destroys someone else's toast.

You were right not to push it, for the reason you gave.

One thing I found while verifying it that bears on your review. Process.running does not go true synchronously on assignment ,it flips on the next event loop turn. I checked under quickshell rather than assuming:

t1 immediately after assign: false
t2 next event loop turn:     true
t4 onExited:                 false

So every guard in this state machine works across turns, not within one. It holds here because each entry point — the 30s timer, the UPower signal, onExited, is its own turn, and the same probe confirms onExitedreadsrunning === falseand can spawn the other process from inside the handler, which is what the replay depends on. Worth stating out loud because the natural reading ofif (dismissProcess.running)` is that it covers a same-turn double call, and it does not. Nothing reachable does that, so it stays correct, but a future edit that calls both from one handler would quietly break it.

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 durationFor alone on the grounds that only one caller was affected, and that isn't true. The body now lists all twelve, points at the discarded -t in omarchy-capture-screenrecording, and says plainly that the policy question is real and bigger than I implied. I still think it belongs in its own change rather than riding along with a battery fix, but that's the maintainer's call at its actual size, not something I get to wave away.

Diagnostics done. Every assertion in the file now carries || fail "…" naming the invariant. It paid for itself immediately , I got an off-by-one in a grep -A range while writing the new tests, and instead of a bare exit 1 it said not ok - battery service clears the held warning only when it issues one, which told me straight away it was my range and not the code.

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 onExited, clearing a held request above its guard instead of below each turns the file red, each killed by an assertion that names the invariant. 18 assertions now, and the service parses and instantiates clean under quickshell.

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 PersistentProperties not surviving a process restart while the popup is restored from disk is a different bug with a different fix, and bolting it on here would just make both harder to review. Thanks for flagging it as pre-existing rather than parking it on this PR.

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.
@Eyasuk
Eyasuk force-pushed the dismiss-low-battery-warning-on-charge branch from 184c709 to bbb1202 Compare August 29, 2026 21:14
@omarchybot

Copy link
Copy Markdown
Collaborator

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 true — the battery then ran down under the threshold in silence. sendLowBatteryWarning now holds behind a running dismiss the way a dismiss already held behind a running warning, and runPendingBatteryNotification replays whichever side was held. The two commands can no longer overlap.

Since this is the third patch to one race, I traced the whole state machine rather than just the delta. notifiedLowBattery has exactly one reader and one writer, both in checkBattery (Service.qml:37-38), so the edge-triggering is complete and a dropped request really is permanent — which is what makes the ordering load-bearing. Across the four writers of pendingDismiss and pendingWarningLevel, each function clears the other's before setting its own, so the "only ever one of the two is held" comment at Service.qml:87 holds and the if/else if in the replay is belt-and-braces rather than load-bearing. For successful commands and normal process exits I could not construct an ordering of the 30s poll, the UPower change, and either process exit that leaves a stale toast on screen or a latch stuck true with nothing showing.

Your note about Process.running checks out, both halves. I ran both under quickshell on a disposable Omarchy VM with a real compositor rather than reasoning about it: running reads false inside its own onExited and the guarded restart from inside the handler does spawn a second run, and running does not read true on the turn you assign it — it flips on the next one. The second half is the sharp edge, and the design survives it only because nothing here reads a flag it set in the same turn: checkBattery and runPendingBatteryNotification each dispatch exactly one of the two commands, and the latch is written before dispatch, so a second checkBattery in the same turn computes notify and dismiss both false. Worth saying out loud, because that is the invariant a later edit would break without noticing.

Tests: test/shell.d/battery-test.sh — 18 passed, 0 failed, run on a worker VM through the shell-test wrapper with the compositor actually serving this branch. I did not run the graphical acceptance suite.

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:

  • A shell restart that straddles the transition. PersistentProperties survives a config reload, not a new process, so notifiedLowBattery starts false after omarchy-restart-shell or a reboot — while the critical toast is restored from disk, and durationFor returns 0 for critical so it comes back with no deadline. Restart with the toast up and the battery no longer low, and alreadyNotified is false, so no dismiss is ever computed and the toast stays for good. If the battery is still low at the first poll it self-heals, because the fresh warning re-latches and the eventual dismiss sweeps every matching summary including the restored one. Reconciling at startup is a product call — it would mean issuing a dismiss on shell start — so I have not touched it.
  • A battery-low hook that hangs. omarchy-battery-low runs omarchy-hook synchronously after posting, so warningProcess never exits and a held dismiss is never replayed. Same class: quickshell clears running without emitting exited when a command fails to start, which would strand a held request the same way.
  • omarchy-notification-dismiss goes through omarchy-shell -q, and -q returns success even on an IPC timeout, so dismissProcess exiting is not by itself evidence the toast came down.

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 return at the top of dismissLowBatteryWarning would leave all of them green. Your eight mutations cover the invariants you named; that gap is the honest limit of the approach, and the acceptance test you say you cannot drive is what would close it.

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 exited, which is the source-level reason my runtime probe came back false. I rejected its point that the dismiss can take down an unrelated app's toast whose summary happens to contain "Time to recharge!" — true, but that is how omarchy-notification-dismiss has always matched, and not something this change introduces.

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.
@bjarneo

bjarneo commented Sep 21, 2026

Copy link
Copy Markdown
Member

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.

@bjarneo bjarneo closed this Sep 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Low-battery notification remains after charger is connected

4 participants