Skip to content

Parse the battery report once instead of once per field - #9435

Open
VykosMolt wants to merge 5 commits into
omacom:quattrofrom
VykosMolt:perf/battery-status-forks
Open

VykosMolt wants to merge 5 commits into
omacom:quattrofrom
VykosMolt:perf/battery-status-forks

Conversation

@VykosMolt

@VykosMolt VykosMolt commented Aug 31, 2026 •

Copy link
Copy Markdown

The battery status command now reads the selected UPower report in one pass instead of running a separate awk process for each field. Each field keeps its first match, including explicit zero thresholds and missing values that need the existing sysfs fallback.

The merge with current quattro preserves machine-battery discovery, Apple Silicon native paths, signed live power readings, time estimates derived from live energy and power, battery-specific charge limits, and translated output. The parser supplies the new energy fields to those calculations.

Validation: all 11 focused battery checks pass, including Apple Silicon discovery, live-power duration, charge limits, fallback estimates, Danish output and threshold ordering. The process-count regression fails on current upstream, where awk runs 14 times; the candidate stays within six. Independent comparisons against current upstream also preserve output for ordinary, missing-field, zero-first duplicate and empty reports. Diff checks against the current base pass. The earlier timing measurements describe the previous source version; no new timing or physical-hardware result is claimed.

AI-assisted implementation and automated verification.

omarchy-battery-status ran `upower -i` and then handed the same report to eight
separate awk invocations, one per field, each one reading to its first match and
exiting. The power panel re-runs the command every five seconds while it is
open.

One awk pass now reads all eight. Each field still takes the first line that
matches it, which is what the separate `exit` in each pass was doing, and the
two threshold fields still come back empty when the report does not carry them,
so the sysfs fallback below them is unchanged.

Finding the battery went from `upower -e | grep BAT | head -n 1` to one awk with
an `exit`, for the same reason.

On this machine, with `--shell`:

  quattro   22 processes   46.5 ms
  patched   14 processes   34.5 ms

Output is byte-identical in both modes.
@omarchybot omarchybot added the enhancement New feature or request label Sep 27, 2026
@greptile-apps

greptile-apps Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The battery parser change appears safe to merge.

Summary

omarchy-battery-status now extracts the selected UPower report’s fields with one awk call.

  • The battery status command gathers report fields in one pass.

VykosMolt accepted the known upstream startup/removal race pending #14656 and the notification issue pending #14668. Both corrective PRs await integration.

Reviews (3) · Last reviewed commit: "Merge current quattro and keep one-pass ..." · Reviewed by Greptile

Comment on lines +463 to +468
if home_in_use(provider, home):
raise AccountError(f"A running {PROVIDERS[provider]['name']} session uses {account['label']}. Quit it first, then remove the account.")
# Only the account's own directory goes. Its links point into the primary
# home, and rmtree removes a link without following it.
if home.resolve().parent == (accounts_root() / provider).resolve():
shutil.rmtree(home, ignore_errors=True)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Login deleted during startup

remove() can delete an account while a new session is starting. The launcher reads the selected home without taking the registry lock. If removal checks /proc after that read but before the launcher exports CODEX_HOME or the other provider home, it finds no session and deletes the login the launcher is about to use. Coordinate startup and removal with a shared lock or a session record.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This finding concerns the shared upstream implementation. The tested fix is in #14656. Startup and removal now coordinate with a stable per-home claim acquired before exposing the selected home. Independent source review and the final branch account, real mise dispatch, autoswitch, usage, panel, and CLI suites pass. Keeping this thread open while that corrective PR awaits integration.

Comment thread test/shell.d/battery-status-test.sh Resolved
// is one toast, not a stack of identical ones. The image and click target
// count too: every screen recording toast shares its text but previews and
// opens a different file.
var DUPLICATE_ROLES = ["app", "summary", "body", "image", "execArgv"]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Critical alerts can disappear

isDuplicatePopup() ignores urgency and expireTimeout. A normal notification with the same text can replace a critical alert from the same app. removeDuplicatePopups() dismisses the critical alert and deletes its saved copy, while the normal replacement expires. Compare these fields too so alerts with different lifetimes are not treated as duplicates.

Suggested change
var DUPLICATE_ROLES = ["app", "summary", "body", "image", "execArgv"]
var DUPLICATE_ROLES = ["app", "summary", "body", "image", "execArgv", "urgency", "expireTimeout"]

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The shared notification fix is now in #14668. Duplicate identity includes urgency and expiration, with strict numeric roles and missing/zero distinctions. All 147 logic, 17 notification-command, and 117 CLI checks pass. The installed desktop also preserves the original critical notification after an identical normal alert expires; identical normal alerts with different requested lifetimes expire independently. Actual screenshots and IDs were inspected. Keeping this thread open while the corrective PR awaits integration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants