Skip to content

feat: make auto-reconnect prompt and recover stranded peripherals - #43

Merged
MegaManSec merged 1 commit into
mainfrom
feat/smarter-auto-reconnect
Jun 6, 2026
Merged

feat: make auto-reconnect prompt and recover stranded peripherals#43
MegaManSec merged 1 commit into
mainfrom
feat/smarter-auto-reconnect

Conversation

@MegaManSec

Copy link
Copy Markdown
Owner

What

The auto-reconnect watcher is now prompt and bounded, and per-peripheral handoffs no longer strand a device on neither Mac.

  • Cadence/window: probe at a constant 5s (was 15s) over a 10-min window (was 1h). A stuck Magic device is one the user power-cycles, and it only reconnects within a brief window — so prompt-but-bounded fits better than long-and-slow (and burns far fewer wakeups on a device that is genuinely gone).
  • Event-driven adoption: a device macOS reconnects on its own is adopted via the global connect observer instead of waiting for the next probe tick. The probe timer also gets a small leeway for wakeup coalescing.
  • Handoff rollback: a failed per-peripheral send/take now recovers onto this Mac — immediately when the peer was unreachable, otherwise via the HOLDS_ONE-gated watcher — so it is never left on neither Mac and never yanked from a peer that is actually holding it.
  • Bug fix: a deliberate release whose disconnect notification never arrived left a stale flag that suppressed the next genuine drop reconnect. Intentional-release flags are now timestamped and honored only within a short grace window.

Test plan

  • Builds clean (xcodebuild ... CODE_SIGNING_ALLOWED=NO); swift format applied.
  • Full behavioral verification needs the two-Mac + Magic-peripheral setup (sleep/wake, power-cycle, failed handoff).

The auto-reconnect watcher now probes on a constant 5s cadence (was 15s) over a 10-minute window (was 1 hour): a stuck peripheral is something the user notices and power-cycles, and the reconnect only succeeds within a brief window, so a prompt-but-bounded poll fits better than a long, slow one. The probe timer gains a small leeway for wakeup coalescing, and a peripheral that macOS reconnects on its own is now adopted event-driven via the global connect observer rather than waiting for the next tick.

Per-peripheral handoffs no longer strand a device on neither Mac: a failed send rolls it back onto this Mac (immediately when the peer was unreachable, otherwise via the HOLDS_ONE-gated watcher), and both send and take arm the watcher on failure so a device that needs a power-cycle is recovered once it reappears — only ever reclaiming one the peer isn't holding.

Also fixes a latent bug where a deliberate release whose disconnect notification never arrived left a stale flag that suppressed the next genuine drop's reconnect; intentional-release flags are now timestamped and honored only within a short grace window.
@MegaManSec
MegaManSec merged commit efb1c42 into main Jun 6, 2026
2 checks passed
@MegaManSec
MegaManSec deleted the feat/smarter-auto-reconnect branch June 6, 2026 23:50
@github-actions

github-actions Bot commented Jun 6, 2026

Copy link
Copy Markdown

🎉 This PR is included in version 2.13.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant