Skip to content

Drop the Mac battery when the host battery bridge disconnects - #339

Merged
themartiano merged 1 commit into
omacom:mainfrom
omaguix:battery-disconnect
Oct 13, 2026
Merged

themartiano merged 1 commit into
omacom:mainfrom
omaguix:battery-disconnect

Conversation

@rofrol

@rofrol rofrol commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

What changed and why

Fixes #338. When the host battery bridge goes away, the guest agent kept the
last snapshot as status=unknown beside the last AC state. UPower turns an
unknown battery without AC into Discharging, so a disconnect taken while the
Mac ran on battery left the guest claiming the old level on battery; at 10%
or below, Omarchy's Time to recharge! came back while the Mac charged.
The restarted agent blocks in its refresh write until the host side
reconnects, so after the launcher's fifth bridge restart the stale claim
stayed for the rest of the session.

The agent now writes present=0 ac=1 on disconnect (a line the module
already accepts), so the guest shows no battery until the next snapshot.
docs/host-battery.md says so, and the previous agent's hash is added to
guest/migrations/preimages.json so existing VMs take the update instead of
treating the file as customized.

Testing

  • make test: passed (425 Swift tests; Python suites OK; one skipped:
    "staged-QEMU lock inheritance (binary absent)").
  • test_native_battery_bridge and test_tob_parse updated to expect
    present=0 ac=1; test_boot_fix_catalog and test_boot_components pass.
  • Not run: a live UPower check in a VM. The same change is in use in a
    downstream fork.

ðŸĪ– Generated with Claude Code

When the host bridge went away, the guest agent kept the last snapshot as
`status=unknown` beside the last AC state. UPower's display device turns
an unknown battery without AC into Discharging (up-daemon.c), so a
disconnect taken while the Mac ran on battery left the guest claiming
the old level on battery, and Omarchy's battery service, which warns on
Discharging at 10% or below, kept a low-battery episode alive while the
Mac charged. The restarted agent blocks in its refresh write until the
host side reconnects, so after the launcher's fifth bridge restart the
stale claim stayed for the rest of the session.

The Mac's battery is unknown once the bridge is gone, so the agent now
writes `present=0 ac=1` and the guest shows no battery until the next
snapshot. The previous agent is recorded as a preimage so existing VMs
take the update.
rofrol added a commit to omaguix/try-omaguix that referenced this pull request Oct 11, 2026
@themartiano
themartiano merged commit daca5a8 into omacom:main Oct 13, 2026
4 checks passed
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.

Guest keeps a stale battery level as Discharging after the host battery bridge disconnects

2 participants