Skip to content

power-ab: stop measurements on unavailable battery samples - #226

Merged
derekross merged 7 commits into
derekross:mainfrom
Gr-linkk:power-ab-valid-samples
Nov 12, 2026
Merged

derekross merged 7 commits into
derekross:mainfrom
Gr-linkk:power-ab-valid-samples

Conversation

@Gr-linkk

@Gr-linkk Gr-linkk commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

A failed voltage/current sysfs read previously became an empty CSV field, which awk counted as zero. This could understate drain when a cached battery provider rejects stale telemetry. Failed charge reads could also leave incomplete charge measurements.

Collect and validate each sample before emitting its CSV row. Retry invalid or unavailable voltage/current once after a one-second pause, then record the failure as a CSV comment and stop through the existing restoration trap without generating a misleading summary. Optional average-current and charge fields stay empty on a failed or malformed read rather than ending the run.

Validation: the production sampler regression covers signed and zero current, missing/malformed required fields, retry delay and recovery, optional-field failures, CSV diagnostics and EXIT-trap execution. It passes after merging current main. Repository tests/all, package tests, Bash syntax, repository policy and whitespace checks pass. No phone operations or hardware qualification performed.

Branch refresh (2026-11-11): normal merge of main at 92074ca. Retained main's complete suite list and moved the sampler regression into the existing one-suite-per-line block, as suggested in review, to avoid repeated conflicts with additions to the neighbouring loop. The accepted sampler and regression code remain unchanged. Main's sleep preflight and pre-detach checks are preserved. Derek's short phone run remains outstanding; no new diagnostics or features are included.

Scope note: this is a bounded measurement correctness fix, not Pixel 6 display or battery enablement. Local Oriole backlight and battery functional prototypes survive, but their startup packages rely on private pinned modules, loaders and safety services absent from current main. They require a separate kernel/package integration effort; their recorded hardware results do not qualify this upstream tree. This patch does not establish snapshot coherence or freshness when a provider silently returns old data.

Do not count failed sysfs reads as zero current or retain incomplete charge samples. Validate exposed properties before writing a row and exit through the restoration trap on failure. Keep absent optional properties supported.

Test the production sampler against missing and malformed properties, signed current and EXIT cleanup. The regression fails on the base and passes with this fix.

Co-Authored-By: OpenAI Codex <noreply@openai.com>
@derekross

Copy link
Copy Markdown
Owner

Thanks, the bug is real: an empty voltage or current field is averaged as zero and makes the drain look smaller than it is. Two things before it lands. First, power-ab normally runs with --detach, which sends stderr to /dev/null, so with the cable out nobody sees "stopping": please write the reason into the CSV as a # line, as the rtcwake and suspend failures already do. Second, only voltage_now and current_now feed the means; the charge summaries already skip empty fields and current_avg isn't used, so I'd rather keep those three empty on a failed read than end a multi-hour run over them. A single retry for the two required reads would also help after a resume. Please rebase after #225 or vice versa (same line in tests/all), and I'll do a short run on a phone before merging.

@derekross

Copy link
Copy Markdown
Owner

Thanks, Gr-linkk, this covers everything: the reason lands in the CSV so a detached run explains itself, the optional fields stay empty instead of ending the run, and the two required reads get one retry, all with tests. One optional tweak: the retry comes straight after the failed read, so after a resume a sleep 1 before it would give the gauge a moment. I'll do the short run on a phone as promised and then squash it with a clean message.

Gr-linkk and others added 2 commits November 3, 2026 15:05
Give the gauge time to recover after resume before retrying a failed required sample.

Co-Authored-By: Codex <noreply@openai.com>
@derekross

Copy link
Copy Markdown
Owner

Thanks, @Gr-linkk. The sleep 1 is in exactly the right place, only before the retry, and the test now proves it's there. I'll do the short run on my phone and then squash with a hand-written message, since the branch has two merge commits.

Keep current main test coverage and the sampler regression when resolving
the tests/all conflict. The sampler still needs this fix; main retains
unchecked voltage/current reads. Preserve the merged preflight and tool
help updates without changing their behavior.

Co-Authored-By: Codex <noreply@openai.com>
@derekross

Copy link
Copy Markdown
Owner

Thanks, @Gr-linkk. I checked the refresh: the change to tools/power-ab and the test are line for line what I accepted on the 5th, #592's sleep preflight and its checks before detaching are intact, and the sampler test now sits on its own line in tests/all, clear of the loop that everyone else appends to. It merges onto today's main without a conflict and CI is green.

Nothing more is needed from you. What's left is mine: the short run on my Pixel 7 Pro (a baseline run with the cable out, and one s2idle phase for the read after a wake). Once that's done I'll squash it with a hand-written message, since the branch carries merge commits.

Resolve tests/all by retaining main including build-packages-host-tools
and the sampler regression on its own line. The accepted sampler and its
regression remain byte-identical; preserve main preflight/detach checks.

Co-Authored-By: Codex <noreply@openai.com>
@derekross

Copy link
Copy Markdown
Owner

Thanks, @Gr-linkk. I checked the new head: tools/power-ab and the sampler test are byte for byte what I accepted, the merge only brought main's suite list into tests/all, and the test passes on the branch merged onto today's main. CI is green.

Nothing is needed from you. One small thing I may adjust myself when I merge: the test's line in tests/all sits directly above the loop line that every new suite appends to, and git counts a change on the neighbouring line as the same hunk, so it still collides with those pull requests. Main now has a "one suite per line" block further down for this, and I'd move the line there.

What's left is still mine: the short run on my Pixel 7 Pro (a baseline with the cable out and one s2idle phase for the read after a wake). Then I'll squash it with a hand-written message.

Retain main's complete suite list and move the sampler regression into
the one-suite-per-line block requested in review. This avoids conflicts
with additions to the neighbouring loop without changing the sampler.

Co-Authored-By: Codex <noreply@openai.com>
@derekross

Copy link
Copy Markdown
Owner

Thank you for the new head, @Gr-linkk: tools/power-ab is still blob 0751b4f8, the one I accepted, and the test's line is now in the "one suite per line" block, which is where I'd have moved it.

The Pixel 7 Pro run is done (Omarchy 4.5.0-3, uname -r 7.3.0-rc6-omamobile-g1a9d1d4e9289, 2026-11-11, this head's tools/power-ab run detached on the phone):

  • baseline, 2 × 120 s: 232 rows, every row with all seven fields, no empty voltage or current, no # power-ab: stop line. The cable went back in part-way through the first phase, so this run shows the sampler on the real gauge and nothing about drain; I'm not using its numbers.
  • s2idle --suspend systemd, 2 × 300 s, cable out throughout, the modem off for that boot: the phone slept at 22:31:52 and its RTC alarm woke it at 22:36:51 (PM: suspend entry (s2idle) to suspend exit, woken by the s2mpg12-pmic interrupt, suspend_stats success 1, fail 0). The CSV has 291 rows, all whole, and the B-end row written right after the wake has every field, which is the read your retry is for. No stop line, and no UFS line after the wake.

So the sampler holds on the phone it was written against. Merging, with the message written by hand.

@derekross
derekross merged commit 569b203 into derekross:main Nov 12, 2026
2 checks passed
robertzas pushed a commit to robertzas/omarchy-mobile that referenced this pull request Nov 14, 2026
…zero (derekross#226)

A failed voltage_now or current_now read became an empty CSV field, which the summary's awk averaged as zero, so the drain looked smaller than it was. The sampler now validates each required value, retries once after a second (for the read right after a wake), and otherwise writes the reason into the CSV as a # line and exits through the restore trap, so a detached run explains itself; the optional charge and average fields stay empty on a failed read. tests/power-ab/samples.py runs the real sample() against files.

Tested on the Pixel 7 Pro (7.3.0-rc6-omamobile-g1a9d1d4e9289, 2026-11-11): a baseline run of 232 whole rows, and an s2idle run with the cable out where the RTC alarm woke the phone after 299 s and the row written right after the wake was whole; no stop line in either.

Co-Authored-By: Codex <noreply@openai.com>
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.

2 participants