feat(macos): back off reconnect attempts to 5 min and retry on network change#16
Merged
Conversation
…k change The auto-reconnect poll retried a dropped light every 15 s forever. A dropped connection now retries on an exponential backoff that doubles from 15 s to a 5 min ceiling (15 -> 30 -> 60 -> 120 -> 240 -> 300 s), so a bulb that's powered off or out of range isn't probed every 15 s indefinitely. The connected health-check cadence is unchanged (still 15 s). The single repeating timer becomes a self-rearming one-shot poll so its cadence can vary per tick. The backoff resets to its 15 s floor on a successful connect, a user action (select / reconnect / disconnect), or a network change. Add an NWPathMonitor so joining or switching Wi-Fi resets the backoff and brings the next attempt forward (~0.5 s) instead of waiting out a backoff grown to minutes while away. Duplicate path updates are de-duped by signature, and pollTick won't stack a retry onto an in-flight attempt.
MegaManSec
added a commit
that referenced
this pull request
Jun 8, 2026
…off (#18) After PR #16 added exponential reconnect backoff (up to 5 min), a disconnected bulb could sit on a multi-minute backoff with no way to hurry it short of hitting Reconnect. Opening the menu-bar dropdown only called `refreshIfConnected`, a no-op while disconnected. Treat opening a UI surface as a fresh chance to reach the bulb: rename the shared open handler to `refreshOnOpen`, and when we're mid auto-reconnect (dropped but not manually disconnected) reset the backoff and pull the next attempt forward (~0.5 s) — the same bring-forward `handlePathChange` already uses on a network change. A connected light still just re-reads its values, and a deliberate disconnect is left untouched, so opening the menu never resurrects it. Wired into both open events that shared the old method: the menu-bar dropdown (`menuWillOpen`) and the controls window's `onAppear` (under auto-sync).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
When disconnected from a saved light, the auto-reconnect poll retried every 15 s indefinitely. This adds two things:
15 -> 30 -> 60 -> 120 -> 240 -> 300 s. A bulb that's powered off or out of range is no longer probed every 15 s forever. The connected health-check cadence is unchanged (still 15 s).NWPathMonitorwatches the network path; joining or switching Wi-Fi resets the backoff and brings the next attempt forward (~0.5 s), so you don't wait out a multi-minute backoff after rejoining a network.How
scheduleNextPoll/pollTick) so the cadence can vary per tick.pollTickwon't stack a retry onto an in-flight attempt (.connectingalways resolves within ~10 s, so this can't stall the poll).Testing
swift build— cleanswift test— 15/15 pass