feat: add exponential backoff and attempt limits to BLE reconnection#18
Open
regulapati-n wants to merge 1 commit into
Open
feat: add exponential backoff and attempt limits to BLE reconnection#18regulapati-n wants to merge 1 commit into
regulapati-n wants to merge 1 commit into
Conversation
Replace immediate, unlimited BLE reconnection with exponential backoff (1s → 2s → 4s → 8s → 16s → 32s → 60s cap) and a 10-attempt limit. Previously, when a remembered WHOOP device disconnected, the app would immediately call connect() again with no delay and no upper bound. This caused rapid reconnect loops that drain battery on both phone and band, especially when the device is out of range. Changes: - GooseBLEClient.swift: add reconnectAttemptCount, reconnectNextRetryAt @published properties and backoff constants (base 1s, multiplier 2x, max 60s, 10 attempts) - GooseBLEClient+Commands.swift: add scheduleReconnectWithBackoff() with exponential delay calculation and resetReconnectBackoff(); wire reset into clearRememberedDevice() - GooseBLEClient+CentralDelegate.swift: replace immediate reconnect in didDisconnectPeripheral with backoff; add backoff retry in didFailToConnect; reset counter in didConnect on success - DeviceView.swift: add ReconnectBackoffBanner showing attempt count, countdown timer, and Retry Now / Stop Retrying buttons Diagnostic log events added: - reconnect.backoff.scheduled (attempt, delay, reason) - reconnect.backoff.reset (previous attempt count) - reconnect.gave_up (after max attempts exhausted)
8 tasks
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.
Summary
Added exponential backoff and a 10-attempt circuit breaker to the BLE reconnection logic in
GooseBLEClient. Previously, the app reconnected immediately and indefinitely after any disconnect, which can drain battery when the peripheral is out of range.Changes Made
GooseBLEClient.swift: Added reconnection state properties (reconnectAttemptCount,reconnectNextRetryAt,reconnectBackoffWorkItem) and backoff constants (1.0s base delay, doubling multiplier, capped at 60s, max 10 attempts).GooseBLEClient+Commands.swift: AddedscheduleReconnectWithBackoff(_:reason:)andresetReconnectBackoff().GooseBLEClient+CentralDelegate.swift: Integrated backoff scheduling intodidDisconnectPeripheralanddidFailToConnect, and reset ondidConnect.DeviceView.swift: Added aReconnectBackoffBannershowing countdown and attempt count, with manual override buttons ("Retry Now" and "Stop Retrying").