Skip to content

feat: make hardware release scopes explicit and release v0.4.0 - #1

Merged
0then0 merged 1 commit into
mainfrom
feat/explicit-hardware-lifecycle
Oct 31, 2026
Merged

0then0 merged 1 commit into
mainfrom
feat/explicit-hardware-lifecycle

Conversation

@0then0

@0then0 0then0 commented Oct 31, 2026

Copy link
Copy Markdown
Owner

Problem and resulting behavior

Orderly service stop called release(), which defaulted to apply(None, None). Every stop, restart and OS shutdown therefore wrote "no limit" to native thresholds (Linux sysfs, Lenovo conservation mode, Intel BCLM), lifting a saved limit (audit finding BATTERYBRIDGE-001). Daemon-held gates and persistent thresholds were treated the same.

  • ChargeController::release now takes an explicit scope: Overrides (gates, forced discharge, LED, idle assertion) or Everything (plus native thresholds). Each backend implements both deliberately.
  • Stop and restart end temporary modes, release overrides and re-apply the saved threshold. They never clear it. The service cannot tell OS shutdown from a restart, so one policy applies to both.
  • Pause and Reset release everything. Reset is acknowledged only after the hardware accepted it and the empty policy was saved.
  • Enforcement errors release overrides and keep the saved threshold instead of clearing it.
  • Cleanup steps are independent; failures are merged with step names and the first error kind.
  • Sleep preparation steps are independent. After wake, status reports unverified hardware until the first reconciliation.
  • Queued requests get an explicit refusal during shutdown (request read first, 5 s bound).
  • Debian and RPM removal now runs batterybridge reset (starting the service if needed) before stopping it.
  • GUI: an action issued during a running request is refused visibly (BATTERYBRIDGE-002); green palette matching the icon; white tray icon (black template on macOS); selected items stay readable.
  • Icon redrawn; assets/render-icons.py regenerates the committed files byte for byte.
  • Docs: new docs/lifecycle.md; BATTERYBRIDGE-003 (socket group) fixed in docs/service.md.

Persistence of any threshold or gate while the computer is off remains unverified on every device. SIGKILL, power loss and forced OS shutdown run no cleanup.

Validation

  • cargo test --locked: 94 passed.
  • cargo test -p batterybridge-gui --locked: 30 passed.
  • cargo clippy --workspace --all-targets --locked -- -D warnings: clean.
  • cargo fmt --all --check: clean.
  • python3 -m unittest discover -s packaging/tests: 11 passed.
  • python3 -m unittest discover -s packaging/macos/tests: 17 ran, 1 skipped (needs a universal build).
  • Lifecycle tests use fake backends (threshold, gate, both) and the real SysfsController on temporary files. Reverting the error-path change makes three of them fail.

Not run: windows.rs compilation (no Windows target locally), *.ps1 tests, deb/rpm/pkg builds, packaging/linux/test-installer.sh, any hardware write, GUI visual check. No physical device testing was done; nothing here establishes real firmware behavior.

Compatibility and documentation

  • IPC (version 3) and the saved policy format are unchanged.
  • Observable change: stop and removal behavior, CLI status wording (saved limit labelled as configuration, device threshold readback shown separately). Hence version 0.4.0 (Cargo, lockfile, macOS build 7, README links, dated changelog entry).
  • ChargeController::release signature changed (internal workspace trait).
  • README download links point at v0.4.0 assets that exist only after the tag is pushed.
  • CHANGELOG, lifecycle, hardware, service.

Orderly service stop no longer clears saved native thresholds (Linux
sysfs, Lenovo conservation mode, Intel BCLM). ChargeController::release
now takes an explicit scope: Overrides (daemon-held gates, forced
discharge, LED, idle assertion) or Everything (plus native thresholds).
Stop re-applies the saved threshold instead of a temporary top-up;
pause and reset release everything; enforcement errors release
overrides and keep the saved threshold. Cleanup steps are independent
and failures are merged with their step names.

Reset is acknowledged only after hardware accepted it and the empty
policy was saved. Sleep preparation steps are independent and wake
reports unverified state until the first reconciliation. Queued
requests get an explicit refusal during shutdown.

Debian and RPM removal now runs `batterybridge reset` before stopping
the service. The GUI refuses actions during a running request visibly,
uses a green palette matching the icon, and the tray icon is white.
The icon is redrawn and reproducible via assets/render-icons.py.

Adds lifecycle tests with threshold, gate and combined fake backends,
a real sysfs adapter lifecycle test, and docs/lifecycle.md. IPC and
the saved policy format are unchanged.
@0then0
0then0 merged commit 43ac340 into main Oct 31, 2026
8 checks passed
@0then0
0then0 deleted the feat/explicit-hardware-lifecycle branch October 31, 2026 13:34
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.

1 participant