Skip to content

Count the battery's time to full to the charge limit sysfs enforces - #16685

Open
ThatRetiredDude wants to merge 2 commits into
omacom:quattrofrom
ThatRetiredDude:battery-charge-limit
Open

ThatRetiredDude wants to merge 2 commits into
omacom:quattrofrom
ThatRetiredDude:battery-charge-limit

Conversation

@ThatRetiredDude

@ThatRetiredDude ThatRetiredDude commented Oct 26, 2026 •

Copy link
Copy Markdown

Current quattro already prefers numeric sysfs thresholds over UPower's hwdb defaults (since #20379), but several threshold-selection bugs remain when Dell exposes stored Custom settings outside Custom mode, when UPower 1.91+ omits charge-threshold-enabled for disabled limits, or when a dual-battery system falls back to another battery's BAT* threshold.

Fixes #16653. Addresses the threshold half of #7374 and the phantom threshold reporting in #17137 (firmware charge control and panel toggle availability remain separate).

Problem

  • Dell non-Custom modes: Dell drivers still report stored Custom numbers in charge_control_{start,end}_threshold while charge_types has Standard, Adaptive, or another mode active, causing omarchy-battery-status to display an inactive limit and shorten "Time to full".
  • Disabled UPower hwdb defaults: When sysfs has no readable threshold (missing or failing with ENXIO/ENODEV), quattro checks upower_threshold_enabled != "no". UPower 1.91+ omits charge-threshold-enabled entirely when disabled, so empty upower_threshold_enabled still matches and lets the hwdb 75-80% defaults leak through.
  • Dual-battery fallback mismatch: Falling back to a BAT* glob when the selected battery has its own sysfs directory can display another battery's threshold while computing the selected battery's time to 100%, and upower_threshold_start of 0 wasn't stripped on the UPower fallback path.

Change

  • Keep quattro's read_sysfs_number helper and upower_threshold_* / limit_* metadata intact.
  • Ignore Dell charge_control_*_threshold values when charge_types lists Custom and another mode is active ([Custom] is not selected).
  • Require upower_threshold_enabled == "yes" before falling back to UPower's thresholds, and fall back when sysfs has no readable numeric value (whether the file is missing or fails to read) so a failed sysfs read doesn't hide an explicitly enabled UPower limit while still suppressing disabled/omitted UPower defaults.
  • Clear unset limits (end <= 0 or >= 100, start <= 0 or >= end) consistently across sysfs, UPower, and BAT* fallback.
  • Restrict the BAT* fallback to cases where UPower did not resolve an existing sysfs battery directory (-z $native_path || ! -d $battery_path) and compute charge_limit afterward so threshold and time always agree.

Tests

Extended test/shell.d/battery-status-test.sh to cover:

  • Sysfs limit winning over UPower's enabled 75-80% default.
  • Dell charge_types ignoring thresholds in Standard mode and reporting them in Custom mode.
  • Stripping a 0 start threshold and treating an end threshold of 100 as no limit.
  • Existing-but-unreadable sysfs attribute falling back to an enabled UPower limit and suppressing an omitted/disabled UPower limit.
  • A resolved battery without its own limit (or with 100) neither shortening its time to full nor borrowing another battery's BAT* threshold.

The change was written with AI models under my direction. I reviewed it myself, and the battery-status tests pass with the change.

@greptile-apps

greptile-apps Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5RetriggerView in Greptile

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

Summary

Makes the reported charge limit and time to full follow the selected battery’s sysfs settings.

  • Battery status follows the charge limit the battery actually uses.

Both earlier, unnumbered findings are addressed: known-unlimited batteries skip the fallback, and tests cover UPower-only limits with the feature on and off.

Reviews (6) · Last reviewed commit: "Handle unreadable sysfs reads and avoid ..." · Reviewed by Greptile

Comment thread bin/omarchy-battery-status Resolved
Comment thread test/shell.d/battery-status-test.sh Resolved
@ThatRetiredDude

Copy link
Copy Markdown
Author

updated. Both findings are addressed in 8689541:

Unlimited batteries inheriting another limit (P1): a battery that reports its own threshold, or reports having none, no longer falls back to the BAT* scan. Only a battery that says nothing about its limit borrows one. Added a regression test with an unlimited BAT1 next to a BAT0 limited to 60%, and it fails on the previous commit.
UPower-only limits lacked coverage (P2): added the no-sysfs case and checked it both ways. With UPower’s limit enabled, time to full counts to it and it’s reported. With the limit disabled, it’s ignored.

test/shell.d/battery-status-test.sh passes.

@omarchybot

Copy link
Copy Markdown
Collaborator

This fixes the cause: the script now takes the battery's own sysfs limit over UPower's hwdb 75/80, trusts UPower's pair only when it says the limit is on, and treats an end of 0 or 100 as no limit. I pushed one commit on top, ending at 053864c. On a ThinkPad with only an end limit, sysfs reads 0/80, and with sysfs now winning that showed "Holding at 0-80%". A start of 0 now counts as no start, so it shows "Holding at 80%". The commit also makes the disabled-UPower test delete the charge-threshold-enabled line instead of writing no, because UPower 1.91.5 prints that line only while the limit is on (checked in up_device_to_text in the shipped libupower-glib). Your yes check already matches that output.

What was checked. Everything ran on a disposable Omarchy worker with UPower 1.91.5, testing this branch both as it is and merged onto current quattro:

Codex Medium and muse-wonder (pi, thinking high) reviewed it. Before the push, I asked both, without giving them my answer, to compare this branch with #9612, #17138 and #17202. Both picked this one:

Neither reviewer found anything in the others worth folding in here. Their second round, on this head, found nothing. Independence is not guaranteed, since both read the same workspace.

Still open, none of it for this branch. The power panel's Model.js decides "Holding" from UPower's state alone. So the T14 G6, the T14s and the MacBook can still show a hold in the panel even though this script no longer reports a limit for them. That is #10196's fix, which is why #7374 and #10193 are not linked here. The BAT* fallback for a battery with no limit of its own is unchanged from quattro.

This is verified and waits on the maintainer: choosing among the four competing pull requests is their call.

@spencerbull

Copy link
Copy Markdown
Contributor

Reviewed 053864cbdda62a7f48b846064d148b15dda4f6d6 against its merge base and current quattro, with the DX13260 findings from #17137. Codex XHigh (GPT-6.1 Sol, xhigh) also reviewed the complete diff, callers, driver source and saved evidence. It identified the Dell mode issue below as a P2 regression; I checked that finding against the source and base/head probes. The reviews share a workspace and supplied evidence, so independence is not guaranteed.

P2 — Custom configuration is not always the active Dell limit. At bin/omarchy-battery-status:93-100, any numeric sysfs threshold wins; line 115 then uses it as the charging target. Dell's charge_control_end_threshold_show() reads BAT_CUSTOM_CHARGE_END without checking which charging mode is active, while charge_types selects Standard, Adaptive or Custom separately. UPower's Dell path explicitly selects Custom to enable those values. A stored 50/80 Custom configuration therefore is not evidence of an active 80% ceiling while Standard is selected. A source-derived Standard-mode fixture with UPower 0/100, 30Wh stored, 60Wh full and 10W charge changes from a 3h estimate on the base to threshold 50-80% and 1h48m on this head. Adaptive and Custom produce the same result because this command never reads the mode. These are fixture results backed by the driver contract, not a physically observed cutoff on the DX13260.

The reporting logic needs to establish mode applicability for drivers whose numeric thresholds only apply in Custom mode, and the “sysfs enforces” claim needs to match that distinction. A blanket rule that Standard disables thresholds for every vendor would be wrong. I have not pushed a speculative cross-vendor guard: the available DX13260's mode and threshold reads fail, so it cannot validate a functioning Dell mode transition. The author and maintainer need to settle that guard and confirm it on a Dell whose interface works, with Custom and Standard/Adaptive coverage in the existing battery-status test.

The #17137 fix itself holds: replaying its UPower metadata against the DX13260's actual ENXIO threshold files makes the base print 75–80% and this head omit it. That remains reporting proof, not working firmware charge control. For failed sysfs reads with an enabled UPower flag, restoring the cached pair is not a demonstrated fix: it can also restore an unverified limit. Whether a real ceiling remains active during such a failure needs hardware evidence, so I have left that precedence policy unchanged.

The other findings are pre-existing: the BAT* fallback can borrow another pack's limit when the selected battery has no data, and the panel's Model.js can infer Holding independently of the script's threshold. Neither is introduced by this PR. The UPower-only enabled/disabled coverage mentioned in the inline bot comment is already present at lines 169–183; no duplicate test is needed.

Battery-status, power-model, system-power and CLI checks passed at this unchanged head and its clean integration onto cbd0029fddcfcae0b73cf1c01a1c6031eae98f99. The sysfs-precedence test failed with the fix reverted. This review added thirteen base/head boundary probes on the hardware worker. The earlier graphical no-battery check skipped because its SSH environment lacked compositor variables; no live-panel or physical cutoff verification is claimed. No commits or branch changes were pushed. This waits on the Dell mode-applicability correction and confirmation above.

🤖 Generated by GPT-6.1 Sol High in T3 Code through the Codex harness. Reviewed by Codex XHigh (GPT-6.1 Sol).

@ThatRetiredDude

Copy link
Copy Markdown
Author

Thanks @spencerbull, good catch on Dell. Pushed a fix: when the battery exposes charge_types with a Custom option and another mode is active, the sysfs thresholds are now ignored, so Standard/Adaptive/etc. report no threshold and time to full counts to 100%. In Custom mode the thresholds are reported as before. Added both cases to battery-status-test.sh; the Standard-mode case fails without the change and the whole file passes with it.

Agreed that #17137 is reporting only. This PR doesn't try to fix the firmware refusing the write.

@omarchybot omarchybot removed the verified Omarchy Triage has verified that this issue is ready for final review label Nov 10, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Re-reviewed 3a43d460b82c1b7c5314a9b80a7858bacd0a06ae. The Dell correction handles Standard and Adaptive without reporting the stored Custom limit, and retains that limit in Custom mode. The guard also leaves thresholds alone when the driver's mode list has no Custom option, consistent with the kernel's charge-type interface.

On a disposable Omarchy worker, thirteen reporting cases passed on the submitted head and its clean integration with quattro at c6be7abb9e518edc40f81be1b8ea0008e9b8b790. These covered the Dell modes, end-only and zero-start limits, unrestricted batteries, enabled/disabled UPower, failed sysfs reads and a second battery. The base reproduces the wrong readings; restoring its battery-status command makes the regression test fail. The script was then restored byte for byte. CLI, battery-status, power-model, system-power and compositor-backed no-battery checks passed. The integrated power-model check required selecting the worker's installed Node on the SSH path.

The captures show the actual power panel opened through its normal IPC, using controlled UPower and sysfs inputs: 40%, 20Wh stored, 50Wh full, 20W charging, Dell Standard selected, stored Custom thresholds 50/90 and cached UPower thresholds 75/80. The base displays 1h; this head displays 1h 30m. Custom mode separately displayed 1h 15m. This verifies reporting; it does not verify a physical charge cutoff or repair #17137's firmware refusal.

Before: base battery-status logic makes the panel display 1h in the Standard-mode fixture

After: this head makes the same panel display 1h 30m in the Standard-mode fixture

Codex High (GPT-6) performed this review and found no additional defect to change. The configured Opus 5.5 High review terminated without returning a report, although its availability probe answered. There is no completed second opinion on this head, so verified and ready remain withheld. No commits were pushed. This waits on the maintainer for the remaining review and the competing fixes #9612 and #17202.

@rand0mdud3

Copy link
Copy Markdown

Ran the branch against a real limit on a pre-T2 Mac, because this board is an edge case the tests don't cover: charge_control_end_threshold = 80 and charge_control_start_threshold = 0, both from the DKMS applesmc (the real SMC BCLM), on linux-omarchy 7.2.15-2.

$ bash bin/omarchy-battery-status            # at 79.7 %, state holding
Battery 79%  ·  Holding at 80%  ·  95Wh      # this branch
Battery 79%  ·  Holding at 0-80%  ·  95Wh    # quattro
$ bash bin/omarchy-battery-status --shell
percentage 79% / state holding / rate 0W / time (empty) / cycles 11

Two things that checks: a start of 0 is correctly treated as no start rather than being printed as 0-80%, and time stays empty while holding instead of inventing a figure. test/shell.d/battery-status-test.sh passes here too (6/6, exit 0).

One caveat about what this machine can and cannot show: UPower on this board reports ChargeThresholdSupported=false with ChargeStartThreshold/ChargeEndThreshold = 0/0, so the sysfs-over-UPower preference is not actually stressed here — sysfs wins because UPower says nothing at all. The machine that discriminates is @andyholst's MacBookAir5,2 in #11593 (comment): charge_control_end_threshold = 100 while UPower reports ChargeThresholdSupported=true with the hwdb 75/80. On this branch that unit should show no threshold at all and time to full counted to 100 %, where quattro shows a phantom 75-80 % limit. If they can run the branch's bin/omarchy-battery-status and paste one line, that is the decisive case for the change rather than a second sample of the easy one.

Worth noting for the same reasons: this unit is why the start-of-0 branch matters at all — a driver exposing charge_control_start_threshold with 0 is not hypothetical, and quattro renders it as 0-80%.

@omarchybot

Copy link
Copy Markdown
Collaborator

Rechecked unchanged head 3a43d460b82c1b7c5314a9b80a7858bacd0a06ae after the new Mac report. On a fresh disposable Omarchy worker, replaying its 0/80 holding inputs reports 80% with an empty time. Replaying the Air's sysfs 100 with disabled UPower 75/80 reports no threshold and counts to full; the base instead reports 75-80%. Both cases fail again with the base command restored. These are reporting fixtures drawn from the comments, not new physical hardware confirmation.

The branch integrates cleanly with quattro at 40556923f740728bba176ca4035a25d9e203ff21. CLI, battery-status, power-model, system-power and the compositor-backed no-battery check pass there, along with the thirteen existing reporting probes. No commits were pushed.

Codex High (GPT-6) performed this pass and found no additional defect to change. The configured Opus 5.5 High returned a weekly usage-limit message instead of a second review; its availability probe also failed. The panel's muse-wonder availability probe answered, but the panel cannot replace the required primary reviewer. There is still no completed second opinion on this head, so verified and ready remain withheld. This waits on the maintainer for that review and the unresolved competing fixes #9612 and #17202.

@ancientastronauttheorist

ancientastronauttheorist commented Nov 21, 2026 •

Copy link
Copy Markdown

Physical-hardware confirmation of the "sysfs 100 + UPower 75/80" case, on a stock kernel (no DKMS applesmc).

Machine: MacBookPro12,1 (13-inch, Early 2015, pre-T2), Omarchy 4.5.0-3, linux-omarchy 7.2.15-1, UPower 1.91.5. The in-tree applesmc on 7.2.15 now exposes charge_control_end_threshold on this board. Earlier reports on this model (#10193) found no such file.

$ grep . /sys/class/power_supply/BAT0/charge_control_*
/sys/class/power_supply/BAT0/charge_control_end_threshold:100
                                  # no charge_control_start_threshold file
$ upower -i .../battery_BAT0 | grep charge-
    charge-start-threshold:        75%
    charge-end-threshold:          80%
    charge-threshold-supported:    yes
                                  # no charge-threshold-enabled line

Live, on battery, same moment:

quattro this PR (3a43d46)
--shell threshold 75-80% (omitted)
status line Battery 66% · 2h 44m left · 14.7W / 60Wh identical

Then on AC, charging at 68% (UPower: energy 41.17 Wh, energy-full 60.40 Wh), both scripts sampled together every 20 s:

rate quattro this PR
20.9 W 20m to full, threshold 75-80% 55m to full, no threshold
33.5 W 13m to full, threshold 75-80% 34m to full, no threshold
35.4 W 12m to full, threshold 75-80% 32m to full, no threshold

At 35.4 W, quattro counts to the hwdb 80%: (0.80 × 60.40 − 41.17) / 35.4 ≈ 12 min. This PR counts to full: (60.40 − 41.17) / 35.4 ≈ 32 min, which is correct for a battery with no limit. On this machine, quattro underestimates time to full by about 2.7×.

Above 80% the time disappears entirely. On a later replug at ~79%, UPower's reading jumped to 82% within seconds. The installed panel, which reads quattro's --shell output, then showed Time to full – while charging at 23 W, because a charge "to 80%" has no time left above 80%.

The estimates in both versions are jumpy on this Mac (29m to 2h 12m within seconds at 78%). That is because the script prefers the instantaneous sysfs current_now, which swings between 0.6 and 2.2 A here while charging. This is not introduced by this PR, just worth knowing.

test/shell.d/battery-status-test.sh passes 10/10 on this machine.

The #10193 case, live. I charged to 100%, unplugged for about 7 minutes, and plugged back in at about 91–93% (UPower's reading moved around in that range). The SMC did not resume charging, which is normal Apple hysteresis:

$ upower -i .../battery_BAT0          # on AC, 10 s after plug-in
    state:               fully-charged
    energy-rate:         0 W
    percentage:          92.9963%
$ grep . /sys/class/power_supply/BAT0/{status,current_now,charge_control_end_threshold}
status:Full
current_now:0
charge_control_end_threshold:100
quattro this PR
status line Battery 92% · Holding at 75-80% · 60Wh Battery 92% · Fully charged · 60Wh
--shell state holding fully-charged
--shell threshold 75-80% (omitted)

So on this Mac, quattro reports a 92% battery as held at a 75–80% limit that does not exist. This PR reports it as fully charged, which matches the hardware. Related: #10196's panel gate keys off this script's threshold field, so on its own it would still let the false hold through here. With this PR it would not.

Measurements were taken on my machine with Claude Code's help. Filed by Claude Opus 5.5 via Claude Code.

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

Copy link
Copy Markdown
Collaborator

Rechecked 3a43d460b82c1b7c5314a9b80a7858bacd0a06ae after the MacBookPro12,1 report. On a fresh disposable Omarchy worker, CLI and the battery-status, power-model, system-power and compositor-backed no-battery checks pass on its clean integration with quattro at e4635a4eea887d5c8dbd70427386f570c37a2a61.

Twenty reporting cases pass on the submitted head and that integration. The new Mac inputs reproduce the base's missing time estimate above 80% and false “holding” state during fully-charged hysteresis; this head reports the remaining charge time and preserves fully-charged, respectively. The base and restored base command reproduce those errors. These are software replays of the contributor's measurements, with no new physical-hardware claim. The existing worker before/after panel captures cover this same head.

Codex High (GPT-6), Opus 5.5 High and muse-wonder via pi (thinking high) reviewed this pass and found no actionable defect. Both additional reviewers completed their reviews this time. Their agreement is based on shared source and supplied evidence, so independence is not guaranteed. Comparison with #9612 and #17202 still finds their unrestricted/disabled-UPower and source-mixing cases unresolved; neither contributes an improvement missing here. Both old Greptile findings have been answered with the commits that fixed them. This addresses #17137's phantom reporting; firmware charge control and the panel's separate holding inference remain separate work.

verified is now applied. The ready gate refused because Tests and Check translation structure require maintainer approval on this head. This waits for those workflows to be approved and pass. No commits were pushed.

@omarchybot omarchybot removed the verified Omarchy Triage has verified that this issue is ready for final review label Nov 27, 2026
Ignore Dell charge_control thresholds when charge_types is outside Custom mode, require UPower's charge-threshold-enabled to be explicitly yes when falling back without sysfs (since UPower 1.91+ omits the line when disabled), keep batteries with their own limit/no-limit from borrowing another BAT* limit, and omit a start threshold of 0.
@omarchybot

Copy link
Copy Markdown
Collaborator

Codex (GPT-6.2 Sol, high effort) and Opus 5.5 High and muse-wonder via pi, thinking high reviewed the rebased head 67c99767 and its battery-status fixtures by reading the source. The reviewers shared the source and review brief, which limits independence. Current quattro already prefers numeric sysfs thresholds. This change still matters when UPower reports disabled defaults or Dell exposes saved Custom settings while another mode is active. On threshold selection, #17202 can still combine a cached UPower start with an end-only sysfs limit.

Two cases from the source review still need runtime checks. An existing sysfs attribute that fails to read can hide an enabled UPower limit, and the fallback to another battery can show that battery’s threshold while calculating the selected battery’s time to 100%. Please update the description for the current base and reference #17137 without closing it. Suppressing its phantom threshold addresses the reporting symptom, and the panel can still offer the control that the firmware rejects.

The worker isolation check failed, so the current head still needs runtime and panel verification. GitHub is waiting for approval to run Tests and Check translation structure.

…hreshold

Fall back to an explicitly enabled UPower limit when an existing sysfs threshold attribute fails to read (while still suppressing omitted/disabled UPower defaults), and restrict the BAT* fallback to unresolved battery paths so a selected battery never displays another battery's threshold while timing to 100%.
@omarchybot

Copy link
Copy Markdown
Collaborator

Recommend: Hold — the current head needs worker verification and maintainer approval for the two CI workflows.

At b22d993584, a failed sysfs read now falls back to an explicitly enabled UPower limit, and a battery with a resolved sysfs path no longer borrows another pack’s cap. If that path can’t be resolved, the remaining BAT* fallback can still supply an unidentified pack’s cap to the time estimate. The source review favors this PR for threshold selection over #17202, whose fallback can still pick up disabled UPower defaults.

GPT-6 High in Codex, Opus 5.5 High and muse-wonder via pi, thinking high checked the source and fixtures. The reviewers shared the source and brief, which limits independence. The worker isolation check blocked runtime and panel verification. Tests and Check translation structure are awaiting approval.

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 "Time to full" counts to 100% when the battery's charge limit stops charging earlier

5 participants