Skip to content

Keep UPower rate when sysfs power reads fail or are non-numeric - #12755

Closed
anandude wants to merge 6 commits into
omacom:quattrofrom
anandude:fix-battery-sysfs-fallback
Closed

anandude wants to merge 6 commits into
omacom:quattrofrom
anandude:fix-battery-sysfs-fallback

Conversation

@anandude

@anandude anandude commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #12735.

Problem

omarchy battery status shows 0W while discharging, even though UPower knows the real rate (time-left is correct, only wattage is wrong). On affected machines /sys/class/power_supply/BAT0/power_now exists, so [[ -r ... ]] passes — but the read itself fails with ENODEV, leaving an empty value that awk turns into 0, clobbering the good 5.5W from UPower. Same hazard in the current_now/voltage_now branch.

Change

  • bin/omarchy-battery-status: only override the UPower rate when the sysfs read actually succeeds and is numeric (cat ... 2>/dev/null + ^[0-9]+$ guard, as suggested in the issue), for both the power_now and the current_now/voltage_now branches. Otherwise the UPower value stands.
  • test/shell.d/battery-status-test.sh: two new scenarios — a power_now node whose read fails (fake cat refusing power_now, standing in for the ENODEV kernel read) and a non-numeric current_now — both asserting the UPower rate survives.

Verification

  • bash test/shell.d/battery-status-test.sh: pass (new assertions included)
  • Negative control: the new assertions fail against the pre-fix script (not ok - battery status keeps the UPower rate when power_now fails to read) and pass with the fix
  • ./test/all: CLI suite fully green; shell suite shows only the 5 pre-existing environment failures (missing omarchy-pkgs checkout, omasnap, Qt portal) — confirmed identical on the clean tree

Fixes #6895

Fixes #15373

@llstrk

llstrk commented Sep 21, 2026

Copy link
Copy Markdown

Verified: At 1b88c708, failed or malformed sysfs reads preserve the UPower rate, while valid unsigned readings, including zero, still override it. No important production regression was confirmed in the tested scope.

Synthetic results with UPower fixed at 5.5W:

Input Baseline PR
power_now read fails, no current/voltage pair 0W 5.5W
power_now contains unknown 0W 5.5W
Power read fails, valid 0.9 A × 12 V pair 0W 10.8W
Valid power_now=0 0W 0W

Read failures above use readable directories producing EISDIR, not a physical battery returning ENODEV. The targeted battery-status test passes on the PR; the new assertion rejects the baseline command.

Optional test improvement: Add a non-numeric power_now case alongside the new non-numeric current_now case. Removing only the power_now numeric guard in a diagnostic copy left the current test green, although power_now=unknown again produced 0W instead of the UPower rate.


Review information

Test scope: Baseline/head CLI tests with stubbed UPower and synthetic sysfs, plus source inspection. No physical battery, live UPower daemon, desktop rendering, or full-suite validation. The included fake-cat test does not make the baseline's Bash read fail; the directory-based controls independently exercise that failure path.

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

Automated AI review: Astra initial inspection, independent Fable 5.1 and separate Astra reviews, followed by verification of claims against targeted evidence.

@anandude

Copy link
Copy Markdown
Contributor Author

Thanks for the thorough verification, and good catch on the gap — you were right that only the current_now guard had a test to itself.

Added a non-numeric power_now case in 370a3b6. I ran your diagnostic both ways to confirm each guard now earns its keep independently:

  • power_now guard removed → new power_now is non-numeric assertion goes red (power_now=unknown yields 0W again)
  • current_now guard removed → the existing sysfs is non-numeric assertion goes red
  • With both guards in place: battery-status-test.sh fully green, plus bin-style-test.sh and the CLI suite

The valid-0 behavior from your table is unchanged — 0 matches ^[0-9]+$, so a genuine zero reading still overrides UPower, as it should.

@llstrk

llstrk commented Sep 22, 2026

Copy link
Copy Markdown

Verified: At 370a3b61, the optional non-numeric power_now coverage note in the earlier review is resolved. The author's two guard-removal results reproduce in diagnostic copies:

Battery-test variant Original 1b88c708 Current 370a3b61
Unmodified command Pass Pass
Remove only power_now numeric guard Pass Fails the new non-numeric power assertion
Remove only current_now numeric guard Fails the existing non-numeric assertion Fails the same assertion

Verified: Production code is unchanged since 1b88c708. Synthetic checks still preserve UPower after failed or malformed reads when no usable current/voltage pair exists, use a valid fallback pair, and let genuine zero readings override UPower. No new production issue was confirmed in this scope.


Review information

Test scope: Battery-status tests, current-head bin-style test, and synthetic CLI checks with stubbed UPower. Read failures used directory-backed EISDIR and a failing command stub, not physical ENODEV. No physical battery, live UPower, desktop rendering, or full CLI-suite validation.

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

Automated AI review: Fresh independent Fable 5.1 High and Astra Xhigh follow-up reviews, with Astra coordination and verification against their separately executed evidence.

@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed at 370a3b61 and reproduced on a disposable Omarchy worker. The fix does what it says, and I found nothing to change.

Reproduction. I linked BAT0/power_now to /proc/self/mem, a node that passes [[ -r ]] but whose read() fails, which is the nearest stand-in for the ENODEV in #12735 short of the HP itself. Current quattro (821ae589) prints 0W there. So does this branch with the script change reverted. This head prints UPower's 5.5W. The same holds for a failing current_now, a directory in place of power_now, and unknown in either node. Valid readings still win over UPower: a good power_now, a good current × voltage pair (also when power_now fails), and a genuine 0.

Tests on the worker. battery-status-test.sh and bin-style-test.sh pass. The new ENODEV assertion fails with the fix reverted. ./test/cli is green. The full ./test/shell run has two failures, in ascii-test.sh and branding-about-animation-test.sh. This PR doesn't touch either file, and both fail on current quattro too.

One behaviour change for the maintainer to know about. The kernel ABI lets drivers report current_now (and on some drivers power_now) as a negative value while discharging. On quattro such a machine shows -10.8W. With this PR, ^[0-9]+$ rejects the negative reading, so it shows UPower's positive rate instead: correct, but without the live sysfs reading. #13362 and #13967 both add sign handling to these same lines. Whichever lands second will conflict here, and if a sign-aware version is wanted, the guard would need to accept -?[0-9]+.

Second opinion: none this run. The configured reviewer, Codex Medium, answers, but omabot's daily review budget was already spent, so no second model looked at this. This is one model's review, backed by the worker run above. Because of that it is labelled verified and not ready. It waits on a second-opinion round, then on the maintainer.

@ujo4eva

ujo4eva commented Oct 7, 2026

Copy link
Copy Markdown

Heads up that this overlaps with #12649 — same bug, same block, same fix. Both are open against quattro and both are triaged, so it's probably worth collapsing to one before a maintainer picks between them.

I'd suggest #12649 as the one to keep, and I'm genuinely happy either way:

  • It accepts a negative power_now (^-?[0-9]+$ vs ^[0-9]+$ here). Some ECs report power_now negative during charge/discharge transitions, and that regex silently drops those to UPower's rate — the same class of bug this PR is fixing, one step later.
  • It covers the current_now/voltage_now branch too. The identical empty-read hole exists there, and Keep UPower rate when sysfs power read fails with ENODEV #12649 has a regression case for it; this PR only tests power_now.

One note on the test harness, since the approaches look different: you simulate the bad read with a fake cat on PATH, #12649 uses an empty file. Both are fine — the script only ever observes an empty string, so it cannot tell them apart. I checked the same code path against /proc/self/mem and a directory to confirm that's actually true rather than just plausible.

Either way, thanks for picking this up. [[ -r ]] implying a successful read is a genuinely easy trap, and getting a second independent report on it is what made the case obvious.

@ujo4eva

ujo4eva commented Oct 12, 2026

Copy link
Copy Markdown

Mine (#12649) is the same bug on the same block, and @jandrusk is right over there that these should collapse to one before a maintainer has to pick between them. I'd rather we pick for them.

Proposal: I'll close #12649 in favour of this one if you'll take two additions —

  1. Signed regex. ^[0-9]+$ rejects negative current_now, which the kernel ABI reports while discharging — omarchybot's review already flagged this as a behaviour change for the maintainer. -?[0-9]+$ keeps those readings live while still rejecting empty and non-numeric. Same class of bug one level down: a valid reading silently discarded.

  2. The two empty-read regression tests from Keep UPower rate when sysfs power read fails with ENODEV #12649 (empty power_now, empty current_now). Your fake-cat harness is fine — the script only ever observes an empty string either way, so it can't tell the two apart. Together with your non-numeric cases, each guard then earns its keep on both failure shapes.

In exchange, this branch is genuinely the better base: on a failed power_now read it falls through to current_now × voltage_now rather than skipping to UPower, which #12649 doesn't do.

If you'd rather not take the sign change, no hard feelings — I'll leave both open and let the maintainer decide.

@anandude

Copy link
Copy Markdown
Contributor Author

Done in 3b4e922 — took both additions:

  1. Signed regex. All three guards now use ^-?[0-9]+$, so negative current_now/power_now stay live as in the pre-fix script instead of silently falling back to UPower.
  2. Empty-read tests. Added empty power_now (falls through to current_now x voltage_now → 10.8W, documenting this branch's better base), empty-both → UPower 7.3W, and empty current_now alone → UPower 7.3W. Also pinned numeric power_now (20.5W) and a negative current_now case (-10.8W).

bash test/shell.d/battery-status-test.sh green. Over to you on closing #12649.

@omarchybot omarchybot removed the verified Omarchy Triage has verified that this issue is ready for final review label Oct 14, 2026
@ujo4eva

ujo4eva commented Oct 14, 2026

Copy link
Copy Markdown

Thanks, 3b4e922 is exactly what I hoped for. One snag before I close #12649: this branch predates #14431 (Apple Silicon convergence), which reworked both the script and the test fixtures. Git merges it cleanly, but battery-status-test.sh fails on the merge result:

  1. The ENODEV upower stub needs a power supply: yes line. Battery selection now requires it, so the script exits before reading power_now.
  2. The later scenarios write to $tmp_dir/power/BAT0/…, but the shared fixture is now macsmc-battery/CMB0, so the test aborts with "No such file or directory".
  3. quattro now takes the absolute value of the rate, so the negative current_now case should expect 10.8W, not -10.8W.

The signed regex turns out to matter more than we thought: #14431 notes Apple Silicon reports negative power_now while discharging, so ^[0-9]+$ would have dropped every live reading on Macs.

Could you rebase onto quattro? Once it's green there, I'll close #12649.

@omarchybot omarchybot added the verified Omarchy Triage has verified that this issue is ready for final review label Oct 14, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed at db0ba2ff and reproduced on a disposable Omarchy worker. The fix holds on current quattro.

Brought up to quattro. As @ujo4eva found, the branch predated #14431, so the new tests failed on the merge result. I merged quattro in (5694e49f) and fitted the tests to its fixtures in aced4d8f: the ENODEV upower stub now says power supply: yes, the later cases use the shared CMB0 battery in place of BAT0, and the negative current_now case expects 10.8W, since quattro now shows the absolute rate. The script change merged without conflict and is yours, unchanged. db0ba2ff gives the non-numeric current_now case a valid voltage_now. Without one, quattro never tried current × voltage, so that test passed with the fix reverted.

Reproduction. With UPower at 5.5W, current quattro reports 0W when power_now fails to read (a link to /proc/self/mem, or a directory) or reads unknown, and when current_now fails with no power_now. This head reports UPower's 5.5W in each case. When power_now fails but current and voltage are valid, it reports the live 10.8W. Valid readings are unchanged: 20.5W, a genuine 0, and a negative current. battery-status-test.sh and bin-style-test.sh pass on the head and fail with the script reverted to quattro's, and ./test/cli is green.

Second opinion: Codex Medium. It found the current_now test gap fixed above. Its second round, at this head, found nothing open.

Competing fix. #12649 fixes the same bug in the same lines. It is older and already labelled ready. Asked to choose between the two without my answer, Codex Medium picked this one for a concrete case #12649 misses. When power_now exists but fails to read, #12649 never tries current_now × voltage_now, so it shows UPower's lagging rate where this shows the live one, and on quattro the time left follows that rate too. I agree, but the agreement may not be independent, because the reviewer can read this session. This also carries #12649's empty-read cases and its signed-reading regex, and @ujo4eva has offered to close #12649 in its favour. Choosing between them is the maintainer's call, so this one is verified but not ready while #12649 holds that label.

This also fixes #6895, the same ENODEV report, which is now linked. It waits on the maintainer.

@omarchybot omarchybot removed the verified Omarchy Triage has verified that this issue is ready for final review label Oct 14, 2026
@anandude
anandude force-pushed the fix-battery-sysfs-fallback branch from db0ba2f to 19bef4e Compare October 15, 2026 08:30
@anandude

Copy link
Copy Markdown
Contributor Author

Rebased onto current quattro (19bef4e) — carried omarchybot's merge forward through the i18n status-line changes that landed since db0ba2f:

  • Guards unchanged from the verified merge: signed ^-?[0-9]+$ on all three reads, fallthrough from empty power_now to live current x voltage, captured vars passed to awk (no re-read between guard and use).
  • Tests: ENODEV fake-cat, non-numeric current_now (with valid voltage_now, so it fails reverted), non-numeric power_now, numeric power_now wins, empty fallthrough, empty-both and empty-current_now to UPower, negative current_now accepted (abs display). Kept the Danish language tests, which the intermediate merge had dropped.

Verified here: battery-status-test.sh green in full, and the new block fails against the pristine script (first assertion goes red). @ujo4eva — over to you on closing #12649.

@greptile-apps

greptile-apps Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

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

Summary

Keeps UPower’s battery rate unless sysfs supplies a successful numeric reading.

  • Battery status keeps UPower’s rate when sysfs readings aren’t usable.

Reviews (7) · Last reviewed commit: "Merge quattro into fix-battery-sysfs-fal..." · Reviewed by Greptile

Comment thread bin/omarchy-battery-status Resolved
Comment thread test/shell.d/battery-status-test.sh Resolved
A sysfs node can exist yet fail to read (ENODEV on some hardware),
and an unreadable or non-numeric value must never clobber the good
UPower rate with 0W. Only numeric reads override UPower, for both the
power_now and the current_now/voltage_now branches; an empty power_now
falls through to the live current x voltage reading. Signed readings
stay live (Apple Silicon signs power_now by direction) and the display
shows the absolute value.
@anandude
anandude force-pushed the fix-battery-sysfs-fallback branch from 19bef4e to 27cb65a Compare October 15, 2026 08:36
@anandude

Copy link
Copy Markdown
Contributor Author

Update: pushed a true rebase instead (27cb65a, parented on 246f33a) — the previous sync commit carried upstream's own changes in its diff and still merged dirty. The PR diff is now just the guard change plus the regression tests, and GitHub reports it mergeable. Same verified content: signed guards with captured vars, ENODEV/non-numeric/empty/signed cases, Danish tests intact.

@omarchybot

Copy link
Copy Markdown
Collaborator

Re-reviewed at 27cb65a6, the rebase onto current quattro (246f33a2), and reproduced again on a disposable Omarchy worker. The script change is the same as in db0ba2ff, the revision verified before, and the fix still holds.

Reproduction. With UPower at 5.5W, quattro reports 0W when power_now fails to read (a link to /proc/self/mem, or a directory), reads unknown, or is empty, and when current_now fails with no power_now. This head reports 5.5W in each case. When power_now fails but current and voltage are valid, it reports the live 10.8W. Valid readings come out the same on both: 20.5W, a genuine 0W, a negative power_now (15W) and a negative current_now (10.8W). battery-status-test.sh and bin-style-test.sh pass on the head, battery-status-test.sh fails with the script reverted to quattro's, and ./test/cli is green. The Danish-language tests from quattro are still there.

One small thing: the rebase drops quattro's two-line comment explaining why sysfs overrides UPower at all (UPower's energy-rate lags the kernel by tens of seconds). Behaviour is unaffected, but the new comment only explains the guards, so the reason for preferring sysfs is no longer written down.

No second opinion this time. The reviewer, Codex Medium, is reachable, but today's review budget was used up before it got to this head. That covers both the review and the classification, so the bug classification is unsettled at this revision and verified is not back on. The review above is one model's alone. The next pass will ask the reviewer again.

Competing fix. #12649 still carries ready for the same bug. @ujo4eva has said they will close it in favour of this one once this is green on quattro. Until one of them is closed, which to merge is the maintainer's call.

This waits on the second opinion and then the maintainer.

@omarchybot omarchybot removed the bug Something isn't working label Oct 15, 2026
The rebase onto quattro dropped the two lines explaining why the sysfs
reading is preferred at all (UPower's energy-rate lags the kernel by tens
of seconds). Keep them ahead of the guards, which explain the other half.
@anandude

Copy link
Copy Markdown
Contributor Author

Addressed the one note from the last pass — pushed 6cbf99a, which restores the two lines explaining why the sysfs reading is preferred at all (UPower's energy-rate lags the kernel by tens of seconds). They now sit ahead of the guards that explain the failure cases, so the file states both why we override UPower and when we must not.

Comment-only change: the executable content is identical to 27cb65a6, which you already verified.

Re-ran test/shell.d/battery-status-test.sh at 6cbf99a (with OMARCHY_PATH set): 10/10 pass.

On the competing fix, that's fine by me: #12649's author has offered to close it once this is green on quattro.

@omarchybot omarchybot added the ready Good to merge label Oct 17, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Re-reviewed at 6cbf99a7 and reproduced again on a disposable Omarchy worker. Your new commit only puts back the two lines on why sysfs is preferred over UPower, which was the one note from last time. Apart from that comment, the code is the same as 27cb65a6.

Reproduction. With UPower at 5.5W, quattro shows 0W when power_now can't be read (a link to /proc/self/mem, or a directory), when it reads unknown, when it is empty, and when current_now can't be read and there is no power_now. This head shows UPower's 5.5W in each of those cases. If power_now fails but current and voltage are valid, it shows the live 10.8W. Valid readings come out the same on both: 20.5W, a real 0W, and a negative power_now shown as 15W. battery-status-test.sh (9 passed) and bin-style-test.sh pass on the head. battery-status-test.sh fails when the script is reverted to quattro's. ./test/cli is green. quattro has moved to cce8b1c9 since your rebase, but neither file has changed there, and the branch still merges cleanly.

Second opinion: Codex Medium. It found no defects at this head and agreed the change is proportionate. It also confirmed that the newest commit only adds those two comment lines. It agreed with my reading, but its independence is not guaranteed.

Competing fix. #12649 is older and fixes the same bug in the same block. This one is the one to keep: when power_now can be opened but holds nothing usable, #12649 stays in that branch and never tries current_now × voltage_now, so it shows UPower's rate where this branch shows the live reading. Codex Medium named the same case separately. @ujo4eva has offered to close #12649 once this is green on quattro, and it now is.

Nothing is left for you to do. This now waits on a maintainer.

@anandude

Copy link
Copy Markdown
Contributor Author

Recording where this stands, since the tie-break against the other PRs fixing the same 0W read is one case.

verified/ready again after the last pass, and green on quattro (cce8b1c9).

Against the other fixes for the same bug, the one difference I could find is a power_now that is readable but yields nothing numeric while current_now/voltage_now are valid. Measured just now on one stub harness (UPower 5.5W; sysfs 3.0A × 3.6V = 10.8W):

power_now this PR #12649
readable, unknown 10.8W 5.5W
readable, 20500000 20.5W 20.5W
absent 10.8W 10.8W
readable, empty read (ENODEV-style) 10.8W 5.5W

Both clear the reported 0W. Here the numeric check is part of the branch condition, so that case falls through to current_now × voltage_now and keeps the live reading where UPower's energy-rate would otherwise lag.

Happy either way — the maintainer's call.

@omarchybot omarchybot added verified Omarchy Triage has verified that this issue is ready for final review ready Good to merge and removed verified Omarchy Triage has verified that this issue is ready for final review ready Good to merge labels Oct 20, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Re-reviewed at a7e7c26d and ran it on a disposable Omarchy worker. The new commit only adds tests, so the script is unchanged from 6cbf99a7. The new tests cover voltage_now being unreadable or not a number when there is no power_now.

Reproduction. With UPower at 5.5W, no power_now and a valid current_now, quattro's script shows 0W when voltage_now reads unknown, when it is empty, and when it can't be read at all (a directory). This head shows UPower's 5.5W in all three cases. With a valid 12V it shows the live 10.8W, the same as quattro. battery-status-test.sh (9 passed), bin-style-test.sh and ./test/cli are green on the head. battery-status-test.sh fails when the script is put back to quattro's version. quattro has moved since the rebase, but neither file has changed there and the branch still merges cleanly.

Second opinion: Codex Medium. It found no defects in the new commit or the PR as a whole. It traced the test setup to confirm the new cases reach the voltage_now check and can't pass without it, and it judged the addition proportionate. It agreed with my reading, but its independence is not guaranteed.

Nothing is left for you to do. This waits on a maintainer.

quattro's omacom#16272 added full-battery and sparse-reading tests at the same spot in battery-status-test.sh; both blocks are kept, quattro's first, since the sysfs-failure block builds its own fixtures in fail_dir.

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

Copy link
Copy Markdown
Collaborator

quattro picked up #16272 today, which added full-battery tests at the same place in test/shell.d/battery-status-test.sh as yours, so this stopped merging. I pushed d762f4b6, a merge of quattro into your branch. It keeps both test blocks, quattro's first; your fail_dir block sets up its own fixtures, so the two don't touch. The script change merged without conflict and is the same as before, now on top of #16272's new status line.

Reproduction, on a disposable Omarchy worker at d762f4b6. With UPower at 5.5W, quattro shows 0W when power_now can't be read, reads unknown, or is missing while current_now can't be read. This head shows UPower's 5.5W in those cases, and the live 10.8W when power_now fails but current and voltage are valid. Valid readings, including a negative current_now and a real 0W, come out the same on both. battery-status-test.sh (10 passed), bin-style-test.sh and ./test/cli pass. With the script put back to quattro's version, the new test fails.

Second opinion: Codex Medium. It checked that the merge loses nothing from either side, that the two blocks don't share state, and that the guards still work with #16272's handling of negative rates and the idle check. It found no defects. It agreed with my reading, but its independence is not guaranteed. Asked separately to compare this PR with #15541 and #15389, which fix the same bug, it picked this one, the oldest: #15541 behaves the same way, and #15389 still lets a non-numeric reading through as 0W. This PR's classification as a bug was re-checked at the current head, and both models agreed.

One optional change. Omarchy's AGENTS.md asks for tests in proportion to the change: a bug fix gets the test that fails on the base branch and passes with the fix. The fix is about 14 lines, and the test block adds 121 lines in a dozen scenarios. If you want to trim it, keeping the power_now read failure and one non-numeric case would still prove the fix. The comment on the empty-power_now case also points at a "#12649 comparison", and #12649 is now closed. Nothing here is a defect, and I haven't changed your tests.

This waits on a maintainer.

…mment

The issue it points at is closed, so the comparison cannot be followed up.
@omarchybot omarchybot added verified Omarchy Triage has verified that this issue is ready for final review ready Good to merge and removed verified Omarchy Triage has verified that this issue is ready for final review labels Oct 23, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Thanks for dropping the stale #12649 reference. That commit, 419834d0, only changes a test comment, but the head moved, so I checked the PR again.

On a disposable Omarchy worker at 419834d0, with UPower at 5.5W: today's quattro (967bbdd7) shows 0W when power_now can't be read, reads unknown, or is missing while current_now can't be read. This head shows UPower's 5.5W in those cases, and the live 10.8W when power_now fails but current and voltage are valid. Valid readings, including a negative current_now and a real 0W, come out the same on both. battery-status-test.sh (10 passed), bin-style-test.sh and ./test/cli pass, and the new test fails with the script put back to quattro's version. The branch still merges cleanly into quattro.

Second opinion: Codex Medium and muse-spark-1.3-contributor (High). Neither found a defect in the new commit or the whole change. They agreed with my reading, but their independence from it isn't guaranteed. muse-spark had no shell, so it read the files but couldn't confirm the commit or look at the other PRs.

Related. #15373 is the same bug on an HP Spectre x360: power_now passes -r but reading it fails with ENODEV. This PR fixes it, so I've linked it here to close when this merges. #15377, #15389 and #15541 are newer fixes for the same bug. Codex was asked separately which one should go forward and picked this one, the oldest. On the worker, #15377 still shows 0W when power_now reads unknown. Reading its diff, #15389 only checks that a reading isn't empty, so unknown gets through there too. #15541 handles the same cases as this PR.

This waits on a maintainer.

@omarchybot omarchybot removed verified Omarchy Triage has verified that this issue is ready for final review ready Good to merge labels Oct 28, 2026
Resolve the conflict in test/shell.d/battery-status-test.sh by keeping the sysfs fallback tests and dropping the source-text check that quattro removed in omacom#16334.

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

Copy link
Copy Markdown
Collaborator

This branch had stopped merging cleanly into quattro: #16334 deleted the source-text check at the end of test/shell.d/battery-status-test.sh, and #16278 added a case above it. So I merged quattro (7eedd173) into the branch and pushed it as 6083e287. The conflict was only in the test file. I kept your sysfs test block and dropped the rg check quattro had removed. bin/omarchy-battery-status merged without conflicts, and your fix there is unchanged.

On a disposable Omarchy worker at 6083e287, with UPower at 5.5W: today's quattro still shows 0W when power_now can't be read, reads unknown, or is missing while current_now can't be read. This head shows UPower's 5.5W in those cases, and the live 10.8W when power_now fails but current and voltage are valid. battery-status-test.sh (9 passed), bin-style-test.sh and ./test/cli pass, and the new test fails with the script put back to quattro's version. CI is green.

Second opinion: Codex Medium and muse-wonder (via pi, thinking high). Both checked the merge and the whole change against current quattro, and neither found a defect. They also checked how the fix meets #16278's new full-battery check. Both noted that the rate this PR keeps feeds that check, so a discharging battery at 100% on AC still isn't shown as fully charged when power_now fails. They agreed with my reading, but their independence from it isn't guaranteed.

Related. #15377, #15389 and #15541 are still open, and all are newer fixes for the same bug. #15389 has a new commit, but it still only checks that a reading isn't empty, so unknown still gets through as 0W. That leaves this, the oldest, as the one to go forward.

This waits on a maintainer.

@omarchybot omarchybot removed ready Good to merge verified Omarchy Triage has verified that this issue is ready for final review labels Nov 2, 2026
@anandude

anandude commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

Closing as superseded — upstream fixed this independently in #17265 ("Keep UPower's battery rate when sysfs has no live reading"), merged 2026-11-01 as 4761d7b2.

The guard that landed is the same one this branch carries: read_sysfs_number() returns a value only when the read succeeds and the contents match ^-?[0-9]+$, and the power_now → current_now × voltage_now fallthrough is otherwise identical. The difference is shape — upstream folds it into a helper rather than testing each read inline.

Upstream also pinned the regression this PR was written for: test/shell.d/battery-status-test.sh now removes power_now and asserts UPower's rate survives ("an unreadable current_now leaves UPower's rate in place").

That is also why this finally went conflicted — quattro now carries the fix, so the same two branches of the if clash. There is no rebase that keeps this diff meaningful.

The one case upstream's test does not exercise explicitly is a node that exists but fails to read (ENODEV) together with non-numeric contents. The helper handles both, so that is a test-coverage gap rather than a behaviour one, and it would be a far smaller PR against the current file if it is worth pinning at all.

Thanks to everyone who reported and re-tested on real hardware while this was open.

@anandude anandude closed this Nov 6, 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

4 participants