omarchy icon indicating copy to clipboard operation
omarchy copied to clipboard

Low-battery warning storm: notification every ~3s when AC online status flaps (latch resets on onBatteryChanged)

Open calumol opened this issue 3 months ago • 4 comments

What happened

While my laptop was sitting at the lock screen discharging through the low-battery range, the shell sent "Time to recharge!" every ~3.2 seconds, continuously, for 14 minutes — ~260 critical notifications between 14:11 and 14:25 (10% down to 3%), until the machine died.

Notification state files (one per popup, timestamped) show the cadence:

14:11:45 +  0.0s Time to recharge! | Battery is down to 10%
14:11:50 +  4.2s Time to recharge! | Battery is down to 10%
14:11:53 +  3.3s Time to recharge! | Battery is down to 10%
...continues every ~3.2s through 10% → 9% → 8% → ... → 3%...
14:25:29 +  3.0s Time to recharge! | Battery is down to 3%

Root cause

The journal shows the AC adapter's reported online status was flapping every ~3.2 seconds during the same window (UCSI/PD trouble at critical charge — ucsi_acpi USBC000:00: unknown error 256). The ACAD udev events alternate between the plugged and unplugged rules at that cadence:

14:11:52 (udev-worker): ACAD: ... omarchy-wifi-powersave off' failed with exit code 1.
14:11:52 (udev-worker): ACAD: ... omarchy-wifi-powersave on' failed with exit code 1.
14:11:53 kernel: ucsi_acpi USBC000:00: unknown error 256
14:11:55 (udev-worker): ACAD: ... omarchy-wifi-powersave off' ...
14:11:55 (udev-worker): ACAD: ... omarchy-wifi-powersave on' ...

In shell/plugins/services/battery/BatteryModel.js, the notified-latch is recomputed as notifiedLowBattery: low on every check:

var low = isDischarging(device, onBattery, dischargingState) && level <= threshold
return { level: level, notify: low && !alreadyNotified, notifiedLowBattery: low }

and Service.qml calls checkBattery() from onOnBatteryChanged. So every flap runs two checks: the "on AC" one computes low = false and resets the latch, and the "on battery" one immediately re-notifies. One critical notification per flap cycle, forever.

Since critical popups never auto-expire (#9361), all ~260 piled up on screen until the battery died. Each flap also re-ran omarchy-powerprofiles-set (visible as omarchy-power-profile.service start/stop churn every ~3s).

Expected

One warning per low-battery episode. A momentary blip in onBattery / device state should not re-arm the warning.

Suggested fix

Any (or all) of:

  • Hysteresis on the latch: only clear notifiedLowBattery once the battery is genuinely recovering (level > threshold, or charging state sustained for e.g. 30s) — not on any instant where low computes false.
  • Rate-limit sendLowBatteryWarning (e.g. at most once per 5 minutes).
  • Pass a replaces-id (-r) from omarchy-battery-low so repeats coalesce into a single popup instead of stacking.

System

  • Framework Laptop 13 (AMD Ryzen 7 7840HS / Radeon 780M)
  • Omarchy 4.0.0.r1846.g946704f-1, quickshell 0.3.1-1, kernel 7.1.9-arch1-2

Related: #9361 (critical toasts never expire — the aggravator that made this a wall of popups), #8813 (low-battery toast persists after charger connect).

calumol avatar Sep 01 '26 20:09 calumol

Opened a fix in https://github.com/omacom/omarchy/pull/9883

shouldWarnLowBattery now keeps the low-battery latch across transient AC-online flaps and only clears it after the level recovers above the threshold, so onOnBatteryChanged cannot re-arm a critical toast storm. Regression coverage is in test/shell.d/battery-test.sh.

fresh3nough avatar Sep 02 '26 20:09 fresh3nough

Reviewed against current quattro (988f44e). The mechanism you describe is still there, and I confirmed it by reading the source. I did not reproduce it, because it needs a flapping AC adapter that a test VM does not have.

  • shell/plugins/services/battery/BatteryModel.js:14-19 sets the latch to notifiedLowBattery: low on every check. When onBattery goes false, low is false and the latch clears.
  • shell/plugins/services/battery/Service.qml:118-119 runs checkBattery() on every onBatteryChanged, so the next swing back to battery sends a new warning. The warningProcess.running guard only stops two warnings overlapping; it does not stop one warning per flap.

#9883 fixes this and already names this issue as one it closes. It keeps the latch set through AC flaps and through a missing reading, and clears it only once the level is back above the threshold. That fixes the cause and the change is small (11 lines in the model plus tests). That pull request gets its own review and worker run.

For whoever lands the battery work: #11415 and #14218 also change this function. They add a dismiss computed as !low && alreadyNotified, which uses the same moment-to-moment low that flaps. Either one would conflict with #9883, and on its own would turn this storm into a dismiss and re-show loop.

Only one model checked this. Claude Opus 5.5 did the review. The second reviewer, Codex Medium, did not run, because the day's review budget was used up.

This is waiting on the maintainer's decision about #9883.

omarchybot avatar Oct 09 '26 12:10 omarchybot

This also happens with a charger that works: plugging it in is enough. On an Apple MacBook Air (M1, 2020), the kernel's macsmc-ac supply goes online, offline and online again within half a second while the charger negotiates, and UPower passes each change on as OnBattery. The battery itself stays Discharging the whole time.

Today, under 10%, that sent a second "Time to recharge!" half a second after I plugged the charger in:

Time Event
13:48:02 "Battery is down to 10%", discharging
13:52:30 Charger plugged in: macsmc logs the negotiation (Elec Cause 0x8020, then Not charging:0)
13:52:30.5 "Battery is down to 9%"
13:53:11 UPower reports charging

I then recorded UPower's signals (gdbus monitor --system --dest org.freedesktop.UPower) while unplugging the charger and plugging it back in, at 28%:

14:06:20.808  line_power_macsmc_ac    Online: true
14:06:20.818  UPower                  OnBattery: false
14:06:20.978  line_power_macsmc_ac    Online: false
14:06:20.993  UPower                  OnBattery: true
14:06:21.254  line_power_macsmc_ac    Online: true
14:06:21.270  UPower                  OnBattery: false
14:06:22.711  battery_macsmc_battery  State: 1 (charging), 2 (discharging) until then

udevadm monitor shows the same POWER_SUPPLY_ONLINE 1 → 0 → 1 on macsmc-ac coming from the kernel, so UPower is only passing it on.

With the current code, the check on OnBattery: false clears notifiedLowBattery, and the check 175 ms later on OnBattery: true finds the battery discharging under the threshold and warns again. Both plug-ins I looked at did this, so on this machine plugging the charger in under 10% brings a new warning telling you to recharge.

The two latch fixes, #9883 and #10081, were closed without being merged. #11161 and #17881 read the battery's own state instead of onBattery, which would happen to avoid this sequence since the battery stays Discharging through the flap. They keep notifiedLowBattery: low, though, so the latch still clears on the first check that isn't discharging. Clearing it only once the level is back above the threshold, as #9883 did, would cover both cases.

omarchy-dev 4.0.0.r7708.g748fa3c, quickshell 0.3.2.r7.g2b4501a-8, UPower 1.91.5, linux-aurora 7.2.11.

isc avatar Nov 11 '26 13:11 isc

Reproduced the repeat-warning bug on a disposable Omarchy worker using synthetic UPower signals through the real shell and notification service: four warnings on current quattro, one with the latch fix, and four again with the fix reverted. Physical USB-PD negotiation on either laptop remains untested.

#19293 keeps the warning latched through AC flaps, temporary charging states and missing readings. It re-arms only once the displayed charge rises above 10%. The live shell also warned again after recovering to 11% and falling back to 10%. The fix credits @fresh3nough's earlier #9883.

The CLI suite and focused battery and notification tests passed. GPT-6 in Codex (effort not exposed) ran these checks; Opus 5.5 High and muse-wonder via pi, thinking high reviewed the final revision and found no remaining defects. Their agreement does not guarantee an independent review.

Before: four warning cards from four low-battery checks separated by AC flaps.

Before: four low-battery warnings from synthetic AC flaps

After: the same sequence leaves one warning card.

After: one low-battery warning through the same synthetic AC flaps

Waiting on the maintainer's review of #19293.

omarchybot avatar Nov 18 '26 03:11 omarchybot