Skip to content

feat(macos): back off reconnect attempts to 5 min and retry on network change#16

Merged
MegaManSec merged 1 commit into
mainfrom
feat/reconnect-backoff
Jun 8, 2026
Merged

feat(macos): back off reconnect attempts to 5 min and retry on network change#16
MegaManSec merged 1 commit into
mainfrom
feat/reconnect-backoff

Conversation

@MegaManSec

Copy link
Copy Markdown
Owner

What

When disconnected from a saved light, the auto-reconnect poll retried every 15 s indefinitely. This adds two things:

  • Exponential backoff — a dropped connection now retries on a backoff that doubles from 15 s to a 5 min ceiling: 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).
  • Network-change reset — an NWPathMonitor watches 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

  • The single repeating 15 s timer becomes a self-rearming one-shot poll (scheduleNextPoll / pollTick) so the cadence can vary per tick.
  • Backoff resets to its 15 s floor on a successful connect, a user action (select / reconnect / disconnect), or a network change.
  • Duplicate path updates are de-duped by a path signature, and pollTick won't stack a retry onto an in-flight attempt (.connecting always resolves within ~10 s, so this can't stall the poll).

Testing

  • swift build — clean
  • swift test — 15/15 pass

…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 MegaManSec merged commit 0cf1821 into main Jun 8, 2026
2 checks passed
@MegaManSec MegaManSec deleted the feat/reconnect-backoff branch June 8, 2026 10:12
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).
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