Skip to content

Hold a cooldown before repeating the low battery warning - #10189

Closed
JoeBeeton wants to merge 1 commit into
omacom:quattrofrom
JoeBeeton:fix/battery-low-notification-cooldown
Closed

JoeBeeton wants to merge 1 commit into
omacom:quattrofrom
JoeBeeton:fix/battery-low-notification-cooldown

Conversation

@JoeBeeton

@JoeBeeton JoeBeeton commented Sep 4, 2026 •

Copy link
Copy Markdown

Problem

The low battery warning is guarded only by a notifiedLowBattery latch in shell/plugins/services/battery/Service.qml, and that latch clears the moment the battery stops discharging.

With a charger too weak to climb past the 10% threshold, the battery flips between charging and discharging every few seconds. Each flip clears the latch, so the next 30-second poll fires a fresh toast — the warning repeats indefinitely while the battery hovers on the threshold. Reported on a laptop whose charger cannot outpace draw at 10%.

Fix

Gate the warning on a one-minute cooldown in addition to the latch. shouldWarnLowBattery now takes lastNotifiedAt, now, and cooldown, and returns the updated timestamp; the service persists it in PersistentProperties alongside the existing latch, so it survives a shell reload.

The latch is kept, so a normal steady drain still warns exactly once — the cooldown only matters when the latch keeps getting reset.

Tests

  • test/shell.d/battery-test.sh — three new cases: the warning is held inside the cooldown, fires again once it expires, and the timestamp is preserved when no battery is present. All pass; the new cases fail against the unfixed model.
  • Full ./test/shell: only pre-existing environmental failures (missing omarchy-pkgs checkout for config-test.sh and unowned-system-paths-test.sh; snapper-test.sh not executable).

Behaviour was also checked in an isolated Quickshell harness loading the real service with only UPower stubbed, reproducing the reported scenario — 8% battery flipping in and out of discharging once a second:

  • Before: 11 toasts in 21s of flapping.
  • After: 2 toasts in 75s of flapping, exactly 60s apart.

🤖 Generated with Claude Code

https://claude.ai/code/session_012ThTCkRCbS5EHykvTgfUSW

The warning was guarded only by a latch that clears as soon as the battery
stops discharging. A charger too weak to climb past the threshold flips the
battery in and out of discharging every few seconds, clearing the latch each
time, so every poll fired a fresh toast.

Gate the warning on a one-minute cooldown as well as the latch, persisted
alongside it so it survives a shell reload.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ThTCkRCbS5EHykvTgfUSW
@JoeBeeton

Copy link
Copy Markdown
Author

Closing this in favour of #10081, which reported the same bug a day earlier and fixes it better.

We landed on the same root cause independently — notifiedLowBattery: low clears the latch on any moment UPower doesn't report discharging, so a charger too weak to climb past the threshold re-arms the warning on every poll. #10081 fixes it with hysteresis (level >= threshold + 10), holding the latch until the battery genuinely recovers. That's the better fix: this PR's one-minute cooldown still re-warns while you hover at 10%, where hysteresis stays quiet until you're actually charging, and it does it in a smaller diff with no persisted state.

One data point from here that may be useful when reviewing #10081, since it's the same code path. I reproduced the fault in an isolated Quickshell harness loading the real service with only UPower stubbed, flipping an 8% battery in and out of discharging once a second:

  • unfixed: 11 toasts in 21s of flapping
  • with a cooldown: 2 toasts in 75s

Hysteresis should drive that to a single toast for the whole episode. Worth confirming the latch also survives a pending-charge/unknown state at a still-low level, which is the case that flaps most on a weak charger.

@JoeBeeton JoeBeeton closed this Sep 7, 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.

1 participant