Skip to content

Stop a stalled charge reading as a charge-limit hold - #7895

Closed
chessing234 wants to merge 3 commits into
omacom:quattrofrom
chessing234:fix/pending-charge-not-a-hold
Closed

chessing234 wants to merge 3 commits into
omacom:quattrofrom
chessing234:fix/pending-charge-not-a-hold

Conversation

@chessing234

Copy link
Copy Markdown
Contributor

Fixes #7803.

pending-charge only means "AC is present and the EC is not charging the pack". A threshold hold reports it, but so does a failed battery, an insufficient supply, and charge_behaviour=inhibit-charge. Two implementations collapsed that to "a charge limit is holding it":

  • shell/plugins/panels/power/Model.js returned true for PendingCharge unconditionally and never read a threshold value at all, driving the Charge limit / Holding pair, the Threshold mode label, and the battery icon.
  • bin/omarchy-battery-status guarded on a threshold existing but not on the level, while the charging branch two lines below already applied percentage >= threshold_end.

Both now claim a hold only when a limit is really configured and the level has reached its band. Model.js gets the threshold string the panel already reads from omarchy-battery-status --shell, so the QML side stops classifying on state alone. A stall with no hold behind it prints Not charging rather than falling through to the left branch, which has no time estimate to print.

Two details worth calling out:

The reporter's machine also hits #7374 — upower's hwdb default supplies a 75-80 limit it never set — so the level check, not the 100 check, is what fixes it there. The two are independent; this holds either way.

Evidence

Rebuilt the reporter's X1 Yoga as a fake OMARCHY_POWER_SUPPLY_PATH plus a upower stub: dead pack at 0%, pending-charge, sysfs 0/100, upower reporting the hwdb 75-80. Before:

Battery 0%  ·  Holding at 75-80%  ·  0W / 58Wh

byte-for-byte what the issue reports. After:

Battery 0%  ·  Not charging  ·  0W / 58Wh

and a genuine hold is untouched — same machine at 80% in a real 75-80 band still prints Battery 80% · Holding at 75-80% · 0W / 58Wh.

Same on the JS side, driving Model.js directly: chargeThresholdActive on that pack went true → false and modeLabel went Threshold → Charging, while a pack at 80% with a 75-80% limit still returns true.

Tests are in both suites — seven new cases in battery-status-test.sh, six in power-test.sh, covering the unheld stall, the below-band stall, the real hold, the 100 end, and the 0 start. I checked they have teeth by reverting the fix and confirming each file fails.

test/shell.d/{battery-status,power,power-present,battery,system-power,bin-style}-test.sh all pass.

What I did not run

I developed this on macOS, so I could not run the graphical acceptance suite, and I have not seen the change in the running Quickshell UI — agents/skills/visual-verification.md asks for that and I can't provide it. The panel behaviour is exercised through Model.js under node instead; the QML change is three call sites gaining a fourth argument.

One behaviour I can't verify on hardware: batteryInfo starts empty, so during the first refresh cycle after the panel opens a genuine hold reads as "Time to full" for a moment before the threshold arrives. Previously it read as a hold immediately. I think that's the right trade — it's the same data the Charge limit value was already waiting on — but a second opinion from someone with a limit set would be worth having.

This was AI-assisted; the diagnosis in #7803 did the hard part.

upower's pending-charge means only that AC is present and the EC is not
charging the pack. A failed battery, an insufficient supply and
charge_behaviour=inhibit-charge all report it, so classifying it as a hold on
its own labels a dead pack at 0% "Holding at 75-80%".

Claim a hold only when a limit is really configured and the level has reached
its band, which is the discriminator the charging branch already applied. Say
"Not charging" otherwise: there is no time estimate for a stall, so the plain
line would print an empty "left".
Model.chargeThresholdActive read pending-charge as a hold unconditionally,
without ever consulting a threshold value, so the panel showed "Charge limit:
Holding" and a "Threshold" mode label on a pack no limit was holding.

Pass down the threshold string the panel already reads from
omarchy-battery-status and require both a configured limit and a level inside
its band, matching the rule the command now applies.
Copilot AI balanced review requested due to automatic review settings August 23, 2026 14:08

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

Refines battery hold detection so stalled charging is not incorrectly reported as a configured charge-limit hold.

Changes:

  • Gates pending-charge holds on configured thresholds and battery level.
  • Propagates threshold data into the power panel model.
  • Adds shell and model regression 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 4 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
bin/omarchy-battery-status Refines hold detection and adds “Not charging” output.
shell/plugins/panels/power/Model.js Parses thresholds and uses them for pending-charge classification.
shell/plugins/panels/power/Panel.qml Passes threshold data into model helpers.
test/shell.d/battery-status-test.sh Adds battery-status regression scenarios.
test/shell.d/power-test.sh Adds threshold model tests.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

return (start > 0 ? start : end) / 100
}

function chargeThresholdActive(device, onBattery, states, threshold) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

all three hold branches require a configured threshold now, matching omarchy-battery-status.

Comment on lines +52 to +57
return Model.batteryIcon(device, root.discharging, upowerStates(), root.batteryInfo.threshold)
}

function modeLabel() {
var device = UPower.displayDevice
return Model.modeLabel(device, root.discharging, upowerStates())
return Model.modeLabel(device, root.discharging, upowerStates(), root.batteryInfo.threshold)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

no running quickshell here — the model tests cover unheld stall vs a real threshold hold. visual check still needed on a machine with the panel.

omarchy-battery-status gates all three of its hold branches on a configured
limit; the panel gated only pending charge, so the two layers disagreed on
the same battery. A stalled charge and a pack reporting FullyCharged short
of full still read as "Charge limit" in the panel with no limit set, which
is the case this branch was opened to remove.

Gate the stalled-charge branch on the limit and on the level reaching it,
and the FullyCharged branch on the limit, matching the shell script's
thresholds exactly.

modeLabel then had to read the state: a worn pack reporting FullyCharged at
80% no longer takes the Threshold branch, and the percentage alone cannot
tell it apart from a charge in progress. The icon already read the state,
so the two were free to disagree.
@chessing234

Copy link
Copy Markdown
Contributor Author

the Model.js one is right and it was the more important half of the branch — omarchy-battery-status gates all three hold branches on a configured limit, and the panel gated only pending charge, so the two layers described the same battery differently.

both branches are gated now: stalled charging on the limit and on the level reaching it (matching threshold_end < 99 && percentage >= threshold_end), FullyCharged on the limit (matching percentage < 99).

that shook out one more: with no limit set, a worn pack reporting FullyCharged at 80% used to take the Threshold branch, and modeLabel only ever checked percentage >= 1, so it fell through to "Charging". the icon already read the state; the label now does too. power-test.sh is at 35 assertions and green.

on Panel.qml — you are right about the guidance and I cannot meet it. no Hyprland/Quickshell on this machine, so the panel was never opened. what the diff does there is pass an existing root.batteryInfo.threshold through to three Model calls; the classification it feeds is pure JS and unit-tested above, but the rendered icon and label are unverified and I would rather say so than tick the box.

@x3m

x3m commented Aug 28, 2026

Copy link
Copy Markdown

Confirming this on hardware, including the panel-rendering half you flagged as unverified.

Machine: ASUS Zenbook 14 UX3405CA, omarchy 4.0.1-1, quickshell 0.3.1, upower 1.91.3, Arch. Single BAT0, 75Wh. It is also a #7374 machine: sysfs has charge_control_end_threshold = 100 and no charge_control_start_threshold at all, while upower reports charge-start-threshold: 75% / charge-end-threshold: 80% out of hwdb. So no limit is configured on this laptop, and the pack really does charge to 100%.

What stock 4.0.1 does

Plugged in at 17%, drawing about 30W, the panel showed:

Battery
THRESHOLD
Battery size    75Wh    Charge limit    75-80%
Charge cycles     18    Battery state   Holding

It is the timeToFull >= 8 * 60 * 60 clause firing, not changeRate <= 0.2. upower's EnergyRate for this pack oscillates wildly while charging — samples taken minutes apart from busctl get-property ... DisplayDevice:

Percentage EnergyRate TimeToFull
16% 1.139 W 199103 s (55h)
17% 0.757 W 296165 s (82h)
18% 32.465 W 6819 s
20% 4.081 W 52891 s (14h41m)
20% 31.995 W 6796 s

Every dip in that estimate pushes TimeToFull past eight hours and flips the panel to Threshold. Worth noting for the issue description: this is not only a plug-in transient. I set a watcher polling every 2s and it caught the condition again with no AC change in between (saw_unplug=0) — the pack was simply charging. So on hardware with a noisy rate estimate the panel oscillates between "Charging" and "Holding at 75-80%" for the whole low-charge part of a charge cycle.

That clause had no test coverage before this PR — power-test.sh only exercised the changeRate path.

Your branch fixes it

Driving both Model.js copies under node with the exact values captured at one of those hits (state=Charging, percentage=0.20, changeRate=4.081, timeToFull=52891, threshold string "75-80%" as the panel passes it):

STOCK   chargeThresholdActive=true   modeLabel=Threshold
PATCHED chargeThresholdActive=false  modeLabel=Charging

if (fraction < band.end) return false is what catches it here. A genuine hold at 80% in a real 75-80 band still returns true.

The rendered panel

You wrote that you never opened the panel in a running Quickshell. I did.

I applied this PR's three non-test files onto a copy of the released 4.0.1 tree (not master) — git apply took it clean, so it is not master-only — and relaunched the shell against that copy, then screenshotted the panel while the watcher held the false-positive condition. Under state=Charging, 20%, rate=4.081W, timeToFull=52891s, the patched panel renders:

Battery
PUMPING POWER                      (charging bolt icon, bar at 20%)
Battery size    75Wh    Time to full    14h 41m
Charge cycles     18    Charging        4.1W

Charging, not Threshold. Same machine, same upower state, stock renders the Holding block quoted above. The icon takes the charging glyph correctly too, so the fourth argument reaches all three call sites as intended. Journal shows no QML warnings from the power panel on the patched shell.

test/shell.d/power-test.sh and test/shell.d/battery-status-test.sh both pass here.

Two honest caveats

  1. Because this is a Power panel shows UPower's hwdb charge limit (75-80%) instead of the real asusctl-set limit, and a bogus 0 cycle count #7374 machine, chargeHoldBand("75-80%") accepts a band that the hardware never had. Your level check is what saves it at 20%, exactly as you predicted in the description — but once this pack charges past 80%, a rate dip would still read as a hold on a limit that does not exist. That is Power panel shows UPower's hwdb charge limit (75-80%) instead of the real asusctl-set limit, and a bogus 0 cycle count #7374's territory, not this PR's; nothing here regresses it.
  2. The patched panel still prints Time to full 14h 41m during a dip. That is upower's estimate, unchanged and out of scope — just noting it so nobody reads the screenshot as a remaining bug in this change.

I did not run the graphical acceptance suite either.

AI-assisted, on my own hardware.

@chessing234

Copy link
Copy Markdown
Contributor Author

@dhh @ryanrhughes ready for review

@chessing234

Copy link
Copy Markdown
Contributor Author

folded into #12115 with the other battery/bar panel fixes.

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.

pending-charge treated as a charge-limit hold without checking the level: a failed battery reports "Holding at 75-80%" at 0%

3 participants