fix(ble): standing-connect reconnect regime for WHOOP — survive suspension (#1413) - #1421
Merged
Conversation
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.
Ports OuraLiveSource's #1286 standing-connect fix to
BLEManager(thanks @justinjor-bit — detailed report + overnight strap log on real 5/MG).Bug:
BLEManager's two involuntary-reconnect paths (didDisconnectPeripheral,didFailToConnect) armed aDispatchQueue.main.asyncAfterbackoff. That timer doesn't fire in a suspended app AND — the real damage — after a failed connect the app held nothing outstanding with CoreBluetooth, so iOS had no reason to wake it. Measured: the reconnect fired 10h46m50s late on a 5/MG; the night was spent unreachable, then drained in the foreground the next morning.standingConnectdid not exist inBLEManager. (Distinct from state restoration #1213/#1215 — that's termination+relaunch; this is mere suspension, the common overnight case.)Fix: mirror Oura's regime.
Keep the short timed backoff for the first
standingConnectAfterAttempts(3) failures — the app is awake, a 3s/6s retry fixes a transient blip.After that, hand off to a standing
central.connect— no timeout, stays outstanding indefinitely, lets iOS wake the app when the strap re-advertises, including from suspension.standingConnectFastFailureS/standingConnectRetryFloorguards stop a near-instant failure hot-looping.Both call-sites route through the shared
scheduleReconnect()(the disconnect path is where the night died).BLE-safe:
central.connectis the same callconnectFromSystem's targeted path already makes — no new outbound command, nothing written to the strap. Peripheral resolved viapreferredPeripheralUUID→retrievePeripherals(robust even if the droppedCBPeripheralwere released), else the held peripheral, else the scanning fallback. An intentionaldisconnect()clears the marker and cancels the pending standing connect.iOS/macOS only: Android's
WhoopConnectionServiceruns a foreground service (not suspended; timed backoffs fire), so no twin.Tests:
BLEManagerReconnectPolicyTestsmirrorsOuraReconnectPolicyTests— the purereconnectSteppolicy (3s/6s backoff, hand-off at attempt 3, immediate re-issue on a slow failure, floored timer only on an instant one). No strap needed for the policy.Validation caveat: BLE path — app-build only proves it compiles (dispatched). Whether a standing
central.connectreally survives suspension is a hardware question, and @justinjor-bit has real 5/MG hardware (5AM/WS50_r00) and offered to confirm. I'd hold the merge for that hardware run. It also pairs with the #1414 fuse fix (that reduces the drops; this fixes the recovery).