Skip to content

Report an unavailable battery cycle count as unknown - #12484

Open
mateuseap wants to merge 5 commits into
omacom:quattrofrom
mateuseap:fix/battery-cycle-count
Open

mateuseap wants to merge 5 commits into
omacom:quattrofrom
mateuseap:fix/battery-cycle-count

Conversation

@mateuseap

Copy link
Copy Markdown

Changes made

  • Report an unavailable battery cycle count as unknown in bin/omarchy-battery-status: firmware without an ACPI _BIX cycle-count field still reads back the kernel's own 0, and the power panel rendered that as a real "Charge cycles: 0" because Panel.qml's root.batteryInfo.cycles || "—" fallback never fires for the truthy string "0". The field is now omitted unless a pack reports a positive count, so the panel shows its existing unknown value, matching what UPower reports for the same battery.
  • Take the first pack reporting a positive count rather than whichever BAT* sorts first, so a second battery's real count is not hidden by a sibling that reports nothing.
  • Read the sysfs value as data: the count is parsed numerically, so surrounding whitespace and leading zeros no longer change the reported value.
  • Extend test/shell.d/battery-status-test.sh with regression coverage for unusable values (0, negative, non-numeric), for real counts including padded and leading-zero forms, and for the two-pack case.

Fixes #12463

Firmware without an ACPI _BIX cycle-count field still reads back the kernel's own 0, which the power panel rendered as a real 'Charge cycles: 0'. Take the first pack reporting a positive count and omit the field otherwise, so the panel falls back to its unknown value like UPower does.
@llstrk

llstrk commented Sep 25, 2026

Copy link
Copy Markdown

Automated AI review

Community review: Independent automated community review, unaffiliated with the Omarchy team, intended to help prepare PRs for their review.

Verified: the single-battery fix works as described. On firmware without _BIX, the kernel still exposes cycle_count as 0. The previous script printed cycles\t0, and because Model.js stores values as strings, Panel.qml's cycles || "—" fallback never fired for "0". At this head, 0, -1 and non-numeric values produce no cycles line, so the panel shows its existing unknown value. Real counts are still reported. All other --shell lines were byte-identical to the base in every synthetic case tested.

Verified: hiding 0 follows the kernel's own contract, not only UPower's convention:

  • drivers/acpi/battery.c (v7.2, v7.2.5) fills cycle_count only from the _BIX layout, zero-initialises the battery struct and always lists the property.
  • Documentation/ABI/testing/sysfs-class-power defines cycle_count 0 as "cycle_count info is not available". This also covers the tradeoff raised in Power panel reports fabricated 'Charge cycles: 0' on _BIF-only firmware #12463, where a new battery would show unknown instead of 0.
  • UPower 1.90.10 and 1.91.4 map counts <= 0 to unknown (N/A).

Verified: the new tests discriminate. They pass at this head and fail against the base script at cycle_count=0. They also fail against the [[ $cycles -gt 0 ]] form suggested in the issue (through the data-not-code canary) and against a filter that checks only the first pack.

Cycle count can describe a different pack than the rest of the panel

Every other --shell field comes from the pack UPower lists first: percentage, state, size and time from upower -i "$battery", and the rate from $battery_path. The cycle count instead comes from the first BAT*/cycle_count with a positive value, whichever pack that is.

Synthetic two-pack case, with UPower selecting BAT0:

sysfs cycle_count     base output    head output
BAT0=0,  BAT1=450     cycles 0       cycles 450   (BAT1's count beside BAT0's details)
BAT0=-1, BAT1=450     cycles -1      cycles 450
BAT0=300, BAT1=450    cycles 300     cycles 300

Impact: on a dual-battery machine where the selected pack reports no count, for example a newly replaced internal pack beside an external one, the panel shows the sibling's real count as if it belonged to the selected pack. The base already read BAT* independently of UPower's selection, so cross-pack mixing is not entirely new. The PR widens it to the unknown-count case, and the new two-pack test asserts that behavior.

Suggested change: read the count from the pack the rest of the output describes, keeping the > 0 rule. For example, filter "$battery_path/cycle_count", or parse charge-cycles: from the existing $battery_info (UPower already reports N/A for <= 0). The two-pack test would then expect no cycles line when BAT0 reports 0. If a cross-pack count is intended, labelling which pack it belongs to would avoid the mismatch.


Review information

Test scope: reviewed commit c52bb9c. Source review of the script, test, Panel.qml and Model.js, the Linux v7.2 and v7.2.5 ACPI battery driver, the sysfs formatter and ABI documentation, and UPower 1.90.10 and 1.91.4. Sandboxed runs of the repository test and of both scripts against synthetic sysfs trees with a stubbed upower. No real battery hardware was used, and the panel was assessed from source, not rendered.

AI process: Opus 5.5 Medium coordination and synthesis, independent Opus 5.5 Xhigh and GPT 6 Sol Xhigh technical assessments, Opus 5.5 Medium editorial check.

Opt out: To stop receiving these reviews, reply to this comment saying so.

@omarchybot omarchybot added bug Something isn't working verified Omarchy Triage has verified that this issue is ready for final review labels Sep 27, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed at c52bb9c, and the fix holds up. Nothing was pushed to this branch.

Reproduced on a disposable Omarchy worker VM, with a stubbed upower and a fake /sys/class/power_supply/BAT0: with cycle_count set to 0, omarchy-battery-status --shell from quattro prints cycles 0, and from this head it prints no cycles line, so the panel falls back to —. A real count (450) and a missing file behave the same on both. The new test/shell.d/battery-status-test.sh passes on this head and fails with the script reverted to quattro's ("battery status hides an unusable cycle count", cycle_count=0). ./test/cli is green.

The full ./test/shell run had four failing files, none of them touched here: ascii-test.sh and branding-about-animation-test.sh fail the same way on current quattro, and locate-test.sh and omarchy-kernel-migration-test.sh fail only because this branch forked before quattro updated those tests (273c340, faffb8e). A merge of quattro would clear the last two. The power panel itself was not checked in a running session, since the worker has no battery; the change only removes the key, and Panel.qml:437 already shows — when it is missing.

Second opinion from Codex Medium: it found no defects or style problems, and agreed the change is proportionate. Beyond agreeing, it pointed to the kernel's ACPI battery driver, which leaves cycle_count at its zeroed default when firmware only implements _BIF, and to the sysfs power-supply ABI, which defines 0 as unavailable. UPower treats any value of 0 or below as unknown. So the 0 on this hardware is the kernel saying "unknown", not a reading. It also noted that awk's int() would read something like 12junk as 12. sysfs only ever gives integer text, so that is not a problem here. Its agreement is not guaranteed to be independent of this review.

This is labelled verified. It is not labelled ready yet because the worker's shell suite was not fully green, for the reasons above. No CI ran on this pull request. Merging is the maintainer's call.

@omarchybot omarchybot removed the verified Omarchy Triage has verified that this issue is ready for final review label Oct 10, 2026
omarchybot and others added 2 commits October 11, 2026 03:20
quattro now reads the cycle count from the battery UPower resolved before falling back to BAT*. Keep that order and apply this branch's rule to both reads: a count of 0, negative or non-numeric is unavailable, so the resolved battery's 0 falls through to the first BAT* with a real count and otherwise prints nothing.

quattro's test fixture no longer has a BAT0 under the main battery, so the cycle-count tests now drive the resolved CMB0 pack, and cover a real count on it winning over a sibling's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With only BAT1 present, replacing the fallback's filter with head -1 still passed. A BAT0 reporting 0 ahead of BAT1's 450 is the case the filter exists for.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Codex Medium <noreply@openai.com>
@omarchybot omarchybot added the verified Omarchy Triage has verified that this issue is ready for final review label Oct 11, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

This branch had stopped merging into quattro, so I merged quattro into it and pushed two commits (3190dae, b2ad663). It now merges cleanly.

Why it conflicted. quattro changed bin/omarchy-battery-status in e1b0e5e (#14431). It now reads cycle_count from the battery UPower picked, which may not be called BAT* (Apple Silicon's macsmc-battery, or CMB0), and only falls back to the BAT* glob after that. The resolution keeps that order and applies this PR's rule to both reads. A count that is 0, negative or not a number counts as unavailable. If the picked battery has no real count, the first BAT* pack that has one is used. If none does, no cycles line is printed and the panel shows —. quattro also replaced the test's BAT0 fixture, so the new tests now write to the picked CMB0 pack. They also check two more things: a BAT0 reporting 0 is skipped in favour of BAT1's 450, and a real count on the picked battery beats a sibling's.

Checked on a disposable Omarchy worker VM, at b2ad663:

  • test/shell.d/battery-status-test.sh passes.
  • With the script reverted to quattro's, it fails at cycle_count=0.
  • With the fallback filter replaced by head -1, it fails on the two-pack case.
  • ./test/cli is green.

The full ./test/shell run has 11 failing files, none of them battery-related. The tree differs from quattro only in this PR's two files, and 10 of the 11 fail the same way on quattro's tip. The eleventh, remote-session-service-test.sh, passes when run alone on this head.

Second opinion from Codex Medium, over two rounds. It agreed the resolution keeps both intents, and that the change is proportionate. It found that the fallback test no longer covered skipping an unusable first BAT* pack, which b2ad663 adds. Its second round found nothing open. It also noted again that awk's int() reads 12junk as 12, which is harmless for sysfs integers. Its agreement is not guaranteed to be independent of this review.

One open question from the earlier community review: when the picked battery reports no count, the panel can show a sibling pack's count next to the picked battery's other details. quattro's change to prefer the picked battery covers the usual case. Whether to fall back to a sibling at all is the maintainer's call. This PR keeps the fallback the author chose.

It is labelled verified again. It is not labelled ready because the worker's shell suite is not fully green, for the reasons above. No CI ran on this pull request. This now waits on the maintainer.

@greptile-apps

greptile-apps Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The PR appears safe to merge.

Summary

Reports unavailable battery cycle counts as unknown.

  • Battery status shows cycle counts only when a pack reports a positive value.

No actionable issues were found.

Reviews (2) · Last reviewed commit: "Trim the cycle-count tests to the two th..." · Reviewed by Greptile

@jandrusk

Copy link
Copy Markdown

Small correct fix for the "0" truthiness trap. Clean; ready.

@omarchybot omarchybot removed the verified Omarchy Triage has verified that this issue is ready for final review label Nov 3, 2026
omarchybot and others added 2 commits November 17, 2026 01:43
quattro's omacom#17265 added a test for an unreadable current_now at the same spot this branch's cycle-count tests sit. Keep both, cycle-count tests first, since they still rely on CMB0's power_now, which quattro's test removes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
quattro's AGENTS.md asks a bug fix for the test that fails on the base branch and passes with the fix, in proportion to the change. Keep the resolved battery reporting 0, which is the bug, and a 0 pack ahead of a sibling's real count, which is what the fallback's filter is for. Drop the cases that pass without the fix or guard nothing: the resolved battery winning over a sibling, a count already covered by the native-path test, the command-substitution probe neither version could ever evaluate, and the padded, negative and non-numeric forms sysfs does not emit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Codex Medium <noreply@openai.com>
Co-Authored-By: Muse Wonder High <noreply@meta.com>
@omarchybot omarchybot added verified Omarchy Triage has verified that this issue is ready for final review ready Good to merge labels Nov 17, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

This branch had stopped merging into quattro again, so I merged quattro into it and pushed two commits (ae7310c, 85d2288). It merges cleanly now, and the fix to bin/omarchy-battery-status is unchanged.

The conflict was in test/shell.d/battery-status-test.sh. quattro's #17265 added a test for an unreadable current_now at the same spot as this PR's cycle-count tests. Both are kept, with the cycle-count tests first, because they still need CMB0's power_now, which the #17265 test removes.

The tests are now two cases. quattro's AGENTS.md asks a bug fix for the test that fails without the fix, kept in proportion to the change, and both reviewers below flagged the earlier 42 lines against it. What stays:

  • the picked battery reporting 0 prints no cycles line, which is this bug;
  • a BAT0 reporting 0 ahead of BAT1's 450 gives 450, which is what the fallback's filter is for.

What went: cases that pass without the fix (the picked battery's count beating a sibling's, and a real count already covered by the native-path test), the command-substitution probe, which neither version could ever run, and padded, negative and non-numeric values, which sysfs does not produce. The PR description's last bullet still lists those cases.

Checked on a disposable Omarchy worker VM, at 85d2288:

  • My own reproduction, a BAT0 on _BIF-only firmware with cycle_count at 0: quattro prints cycles 0, this head prints no cycles line, and with the script reverted it prints cycles 0 again. A real count (450) comes through unchanged on all three.
  • battery-status-test.sh passes. It fails with the script reverted to quattro's, and fails on the two-pack case with only the fallback's filter swapped back to head -1.
  • ./test/cli is green.
  • The full ./test/shell run had 10 failing files, none battery-related. Five of them fail the same way on quattro's tip. The other five (channel-switch, screenrecording-process, ssh-reconnect, t3code-install, update-hangup) pass when run alone, on this head and on quattro alike.

The power panel itself was not checked in a running session, because the worker has no battery. Panel.qml:463 already shows — when the key is missing.

Second opinion from Codex Medium and muse-wonder (via pi, thinking high), over two rounds:

  • Round one found the script change correct. Both models traced the one reader of cycles, Panel.qml:463, and found an omitted key falls back to —. Both confirmed quattro still prints cycles 0. Both raised the test proportion above.
  • Round two, on the trimmed tests, found nothing open: neither case passes vacuously, and nothing they leave behind affects the next test.

Their agreement with this review is not guaranteed to be independent.

Still open for the maintainer, as #12463 asked: a battery whose firmware has a real _BIX cycle count and is genuinely new also reads 0, and will now show —, the same as UPower. #13292, #15204 and #17639 rewrite these same lines for other reasons, so whichever lands second will conflict.

This is labelled verified and ready. The Tests and Check translation structure workflows have not run on this head, because they are waiting for a maintainer to approve them. It now waits on the maintainer.

@omarchybot omarchybot removed ready Good to merge verified Omarchy Triage has verified that this issue is ready for final review labels Nov 27, 2026
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 panel reports fabricated 'Charge cycles: 0' on _BIF-only firmware

4 participants