Skip to content

Rebuild headlines from live packs when a dead pack poisons DisplayDevice - #12789

Open
ujo4eva wants to merge 2 commits into
omacom:quattrofrom
ujo4eva:fix/battery-dead-pack-liveness
Open

ujo4eva wants to merge 2 commits into
omacom:quattrofrom
ujo4eva:fix/battery-dead-pack-liveness

Conversation

@ujo4eva

@ujo4eva ujo4eva commented Sep 21, 2026

Copy link
Copy Markdown

Draft, stacked on #10392 — please review after #10392 + #12649 land, then I will rebase.

Rationale: #6845 was closed as a dup of #10392, but #10392 only switches headlines to DisplayDevice when >1 pack. That inherits the #7916 lie: a dead T460s pack reporting 0V / 0Wh stored but its old energy_full=20.65Wh drags DisplayDevice to 49% / 9.6h-to-full while the live 20.94Wh pack sits near full. This draft ports only the cbe0705 liveness layer from #6845 (by @geirolafs, reported by @hilather), adapted to #10392's conditional-DisplayDevice structure.

Scope (thin by design):

Tests: new battery-status-dual-battery-test.sh — dead-first T480 shape, two-live cycles 7 / 5, T460s #7916 numbers (97%, 20Wh, 14m). Existing battery-status-test.sh green (added missing type fixture).

Fixes #7916 (script side; Panel.qml glyph side was #7917).
Extracted from #6845.

UPower's composite DisplayDevice sums every present pack's advertised
energy-full, so a dead T460s pack reporting 0V/0Wh but old energy_full
drags the panel to 49% / 10h-to-full while the live pack sits near full
(omacom#7916). Split packs by electrical liveness (voltage, stored energy, or
current — never energy_full) and rebuild percentage, capacity, and time
from the live packs. Per-pack cycle counts and scope=Device exclusion
included. Watt-sum loop deliberately deferred to a later micro-PR.

Co-authored-by: geirolafs <geirolafs@users.noreply.github.com>
@jandrusk

jandrusk commented Oct 8, 2026

Copy link
Copy Markdown

Noting an overlap for when this gets rebased: #13292 (open) also changes how bin/omarchy-battery-status picks its device on dual-bay ThinkPads. It skips a phantom BAT0 with energy-full: 0 Wh. That's the same T460s/T480 class as #7916, and it will touch the same lines as the liveness layer here, so it'd be good to line the two up (or fold one into the other) alongside #10392 and #12649.

@greptile-apps

greptile-apps Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; the previous bounds issue is fixed and no new actionable issues were found.

Summary

The PR rebuilds battery figures from live packs when a dead pack distorts the combined readings.

  • Multi-pack battery status skips dead packs when rebuilding its headline.
  • Battery status lists valid cycle counts from each live pack.

Reviews (2) · Last reviewed commit: "Cap a live pack's energy at its full whe..." · Reviewed by Greptile

Comment thread bin/omarchy-battery-status Resolved
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed at 3fc484a. The problem is real, and this is the approach that fixes #7916. It can't be verified for merge yet: it conflicts with quattro in both bin/omarchy-battery-status and test/shell.d/battery-status-test.sh, and it is stacked on #10392, which is still open. Nothing was pushed here, since you've said you'll rebase once #10392 lands.

What was checked. I ran a reproduction of the T460s readings from #7916 (dead BAT0 at 0 V and 0 Wh stored but still advertising 20.65 Wh full, live BAT1 at 20.4/20.94 Wh, charging at 2.2 W) on a disposable Omarchy worker, against three scripts:

So #10392 alone leaves #7916 wrong, and this change fixes it. battery-status-dual-battery-test.sh passes on this head and fails with the script reverted to its merge base. battery-status-test.sh passes. The rest of the suite was not run, because this head is not what would merge. The hardware itself can't be reproduced on a worker, so once the PR is rebased, the fix will also need confirming on the reporter's machine.

Compared with #13292. It picks the first BAT with a nonzero energy-full, so in the case above it still selects the dead BAT0, which advertises 20.65 Wh. This PR is older and covers that case, so it is the one to take forward for the dead pack.

Defects at this head, verified against the source. Each still matters after the rebase:

  • bin/omarchy-battery-status:143 does not clamp the rebuilt percentage, and the charging time at :148 can go negative. With a live pack reading energy_now 22.00 Wh over energy_full 20.94 Wh it prints 105% and -28m (Greptile's point; it holds).
  • :145 always overwrites time_remaining, even when the rebuild computes nothing. At a 0 W rate, UPower's estimate becomes blank. Any rate above 0 is also used as is, so a 0.1 W trickle turns a 0.54 Wh gap into about 5h 24m. quattro falls back to UPower below 0.2 W and treats a signed rate by its magnitude.
  • When DisplayDevice is missing, :36-38 falls back to the first BAT, which may be the dead pack. The percentage and size are then rebuilt, but the state and rate still come from the dead pack.
  • The liveness check at :80-95 counts a pack as dead when none of its five attributes can be read as a nonzero number. On a two-pack machine, a live pack with sparse or temporarily unreadable telemetry is then dropped from the percentage, size and cycles. The all-dead fallback only rescues it when every pack reads dead.

What the rebase needs to keep from quattro:

  • battery selection by /battery_ with power supply: yes, so non-BAT names like macsmc_battery and CMB0 still work (grep BAT at :22 and :30 would regress them)
  • read_sysfs_number for sysfs reads
  • time derived as minutes and passed through format_duration, so it stays translated
  • time to full counted to the charge limit, not to 100%

Second opinion. It came from Codex Medium and muse-wonder via pi (thinking high). Both agreed the problem is real, that #10392 and #13292 each leave the #7916 case wrong, and that this PR should win over #13292. The first review was by Claude Opus 5.5 in Claude Code, and their agreement isn't guaranteed independent of it. They raised the low-rate, missing-DisplayDevice and sparse-telemetry findings above, and I checked each against the source.

What happens next. This waits on the maintainer to decide on #10392. Once that lands, it's on you to rebase onto quattro, drop the duplicated DisplayDevice switch, and address the points above.

@omarchybot omarchybot added the bug Something isn't working label Nov 2, 2026
energy_now and energy_full are read separately, so a capacity update in
between can leave a pack reporting more than its full, which showed a
negative time to full while charging.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed again at bd8fcb7. The new commit fixes the out-of-bounds figures from the last review. The rest of that review still stands, and the branch still conflicts with quattro.

What was checked. The new commit was read, not run. bin/omarchy-battery-status:141 caps each live pack's energy at its full before the packs are summed. That keeps the rebuilt percentage at or under 100% and stops time to full from going negative, including when only one of two packs over-reads. The new test catches the cap being removed through its time assertion, which prints -4m without it, as you said. Its percentage assertion passes either way, though, because 21.1 Wh over 20.94 Wh truncates to 100%. A fixture of about 22 Wh would make both assertions catch it. That's minor.

Still open from the last review, unchanged at this head:

  • :149-164 still replaces UPower's time estimate whenever the rebuild runs. At a 0 W rate the time goes blank, and a trickle under 0.2 W is still used as is.
  • With no DisplayDevice, state and rate still come from the first BAT, which can be the dead pack (:36-38).
  • A live pack with sparse or unreadable telemetry still counts as dead when its sibling reads live (:80-95).
  • It conflicts with quattro in bin/omarchy-battery-status and test/shell.d/battery-status-test.sh. It also still carries the DisplayDevice switch from Report combined battery percentage from UPower DisplayDevice #10392, which is still open.

Second opinion. Codex Medium and muse-wonder via pi (thinking high) reviewed the new commit. Both agreed the cap is correct and proportionate and that the points above still stand. That agreement isn't guaranteed independent of the first review, which was by Claude Opus 5.5 in Claude Code. They were the ones who noticed the percentage assertion can't fail, and I checked that arithmetic.

Classification. This round, the two models classifying the PR disagreed. I read it as a bug fix, because it corrects the wrong figures from #7916. Codex Medium read it as an enhancement. Only an agreement counts, so no class label was added at this head.

What happens next. This waits on the maintainer, both to decide on #10392 and to settle the classification. Once #10392 lands, it's on you to rebase onto quattro, drop the duplicated DisplayDevice switch, and address the points above. The fix will then need confirming on the reporter's machine.

@omarchybot omarchybot removed the bug Something isn't working label Nov 17, 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.

Power panel reports dead BAT0 (0% / 0W / Holding) on dual-battery ThinkPads

3 participants