Skip to content

Follow battery state when the plug flag disagrees - #20055

Open
acrogenesis wants to merge 11 commits into
omacom:quattrofrom
acrogenesis:fix/power-panel-battery-state-quattro
Open

acrogenesis wants to merge 11 commits into
omacom:quattrofrom
acrogenesis:fix/power-panel-battery-state-quattro

Conversation

@acrogenesis

Copy link
Copy Markdown
Member

What changes

The power widget follows the battery's reported direction for its icon, status and time estimate. The global plug flag still selects the AC or battery power profile.

A USB-C port on a 16-inch M1 Max could stay online after unplugging, causing the bar to show a charging bolt as the battery drained. When the charger was reconnected, UPower could report Charging with a stale 0 W rate. The widget now shows Charging during that transition, preserves a confirmed charge hold through brief load changes and bounds how often unconfirmed direction changes can extend the rate timer.

This builds on #13016 and preserves Jader Feijo's original commit 39470b123. The follow-up credits z23 for the battery-state precedence from #12259.

Fixes #12005.

Verification

  • test/shell.d/power-test.sh passes, including Qt regression tests for reconnects, explicit and rate-based holds, stale wattage, native UPower update order, delayed percentage and repeated direction changes.
  • The headless shell runtime smoke test passes with the changes integrated into quattro at 6169f05c8.
  • The M1 Max plug cycle showed the bolt disappearing on unplug and returning 1.65 seconds after AC came online. The bolt was back while UPower still reported 0 W. The final revision reproduced the recorded sequence in Qt and loaded successfully in the live bar.
  • The final Astra Max review found no further actionable issues.

Screenshots

The live before and after captures show the charging bolt disappearing on unplug and returning on reconnect. The screenshots are available locally.

jaderfeijo and others added 11 commits September 23, 2026 10:25
The panel treated "charger plugged in" as "charging". When a charger
can't cover the machine's draw, UPower reports on-battery: no while the
battery reports Discharging, and the panel showed a draining battery as
"Charging" / "Time to full" with the bolt icon.

Keep trusting plug status for 30s after a plug change, since the battery
state lags behind it, then follow the battery's own state.

Fixes omacom#13015

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
setProfile picked the ac/battery state key from root.discharging, which now follows the battery's own state. On a charger too weak to cover the load it saved the choice as the battery preset, so the battery service applied it after unplugging, and the menu's autodetect path saved the same choice under ac. omarchy-powerprofiles-set documents UPower.onBattery as the key every entry point uses, so the panel uses it too and root.discharging stays presentation only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Resolves the conflict in test/shell.d/power-test.sh by taking quattro's side of the source-text assertions, which omacom#16334 removed on purpose, including the three this branch added. The drawingFromBattery model tests stay.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Resolves the conflict in shell/plugins/panels/power/Model.js, where omacom#19046 added a rateFresh argument to batteryIcon beside this branch's new drawingFromBattery helper: both are kept. Panel.qml merged on its own, so omacom#19046's chargeRateFresh reset now follows the settled discharging state rather than UPower.onBattery alone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
omacom#19046 reset chargeRateFresh from onDischargingChanged, which on quattro followed UPower.onBattery. Here discharging also follows the settled battery state, so every Charging/Discharging flip on a weak charger restarted the 90 s window and kept a stalled-rate charge limit from being recognised for as long as the flips continued. Drive the reset from onOnBatteryChanged instead, so it still runs only when external power arrives or leaves.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Codex Medium <noreply@openai.com>
Co-Authored-By: muse-wonder via pi, thinking high <noreply@pi.dev>
Use the battery's own direction for the power widget. Keep the
charge-rate timer tied to plug changes and also start it when the
battery begins charging with the plug flag already online. On the
affected M1 Max, UPower reported Charging at 0 W before its rate
caught up, with OnBattery unchanged through the real plug event.
Repeated direction changes leave a running timer's deadline intact.

Build on Jader Feijo's original omacom#13016 commit 39470b1 and use the
battery-state precedence from z23's omacom#12259 commit 7159a14.

Co-authored-by: z23 <z23@users.noreply.github.com>
Remember the battery level of a settled, rate-based charge hold
while the source and level remain stable. A brief change in
direction at that level no longer starts another rate timer.

Give each unconfirmed charging transition the full grace period,
even if the previous period has yet to expire. This covers a
second connection while UPower's source flag stays stuck.
Remember explicit holds as well as settled rate-based holds.
Preserve confirmed evidence until the battery level moves or a
new charging rate arrives, since a new direction can arrive
before the telemetry from the previous direction has changed.

Restart settling when a delayed percentage change invalidates
a hold. Keep the timer and evidence together in ChargeRate and
exercise real Qt signal ordering in the focused power suite.
Reevaluate a remembered hold when the time estimate catches
up with a rate sampled while Charging. Do not carry a rate
notification delivered while Discharging into a new charge.

Allow one unconfirmed renewal at a battery level. Known source
changes and new charging measurements can start another window,
but repeated direction flips alone cannot defer a hold forever.
Use a newly reported positive time estimate to corroborate a
charging rate applied before the direction in the same UPower
update. Keep rate notifications from an earlier discharge from
clearing the hold on their own.

Treat the first Charging state after a real source change as
part of the same plug, leaving the renewal available for the
first later reconnect hidden from the source flag.
Retain quattro's removal of the old standalone no-battery
fixture. The power transitions and headless runtime checks
passed against this merge.
@acrogenesis
acrogenesis marked this pull request as ready for review November 24, 2026 19:50
@greptile-apps

greptile-apps Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable issues were found.

Summary

The power widget now follows the battery’s reported direction while power profiles still follow the plug flag.

  • The power widget follows the battery’s reported direction.
  • The charge hold stays visible through brief battery-state changes.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[UPower battery state] --> B[Icon and status]
  A --> C[ChargeRate]
  D[Rate and percentage changes] --> C
  C --> E[Charging or holding]
  E --> B
  F[UPower.onBattery] --> G[AC or battery profile]
  F --> C
Loading

Reviews (1) · Last reviewed commit: "Integrate the reviewed power widget fix ..." · Reviewed by Greptile

@omarchybot omarchybot added the bug Something isn't working label Nov 25, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed head 9140b2e965337362d1c80fff223bb865142d09c8 against quattro, including the panel's icon, status and time/rate bindings, profile storage, #12005, and the full diffs of #12259, #13016, #17881 and #19843. These are competing fixes, so this stays open.

The core immediate battery-state precedence is already proposed in the older #12259. I have queued this PR's additions for evaluation in that PR's session, preserving Adrian Rangel's credit: a reconnect while the plug flag stays unchanged gets a fresh rate grace period, repeated direction changes cannot extend it indefinitely, and confirmed charge holds survive brief changes in direction. The larger charge-hold state machine addresses additional threshold behavior and needs its scope weighed separately.

GPT-6 in Codex (driver effort not exposed), Opus 5.5 High, and muse-wonder via pi (thinking high) reviewed the source. Both second reviewers favor carrying an older fix forward over this one; Opus favors #13016's 30-second plug-settle window, while muse-wonder favors oldest #12259's immediate state precedence. Their independence from the driver is not guaranteed. That transition tradeoff remains the maintainer's decision.

CI is green at this head. No worker tests or physical plug cycle ran in this session: verification stops at the competing-fix decision. This waits on the maintainer; no verification label was added.

@acrogenesis

acrogenesis commented Nov 25, 2026 •

Copy link
Copy Markdown
Member Author

Thanks for comparing the patches, @omarchybot. I’d keep #20055 as the candidate because it covers both halves of the failure I reproduced on a 16-inch M1 Max.

I tried #12259’s battery-state approach in a local widget. It corrected the unplugged indicator. On reconnect, the bolt could still take about 10 seconds to return. One trace showed the battery switching to Charging at 0 W while OnBattery stayed false throughout. The older widget interpreted that rate as Holding, and #13016’s plug-triggered timers would never start in that trace. #20055 follows the battery direction and starts the rate grace period even when the plug flag stays stuck. The AC/battery profile selection still follows the plug flag.

In a separate physical cycle, the bolt returned with UPower’s Charging update, 1.65 seconds after AC came online and 8.84 seconds before the first positive rate. We replayed the recorded transition against the final code in Qt. The committed regression tests also cover a reconnect near timer expiry, a genuine hold interrupted by load, and UPower updates arriving out of order.

The extra hold logic addresses two regressions from rearming the rate timer on a state change. A confirmed hold is recognized again as soon as the battery returns to the limit after a brief load spike. Direction changes alone can extend an unconfirmed window only once at the same battery level. This builds on z23’s state-precedence work in #12259 and keeps Jader’s original #13016 commit in the history.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Power widget shows "Charging" while battery is discharging: icon/label trust UPower.onBattery and ignore device.state

3 participants