refactor(ble): Make Kable connect fallback explicitly bounded#5944
Merged
jamesarich merged 2 commits intoJun 25, 2026
Merged
Conversation
KableBleConnection.connect used a while(state != Connected) loop with an internal autoConnect flag flip. The two-attempt invariant (direct connect then autoConnect fallback) was implicit — a reader had to trace the flag to verify termination. Replace with for(attempt in 1..2) making the bounded retry structural. Behavior unchanged: direct connect first, autoConnect fallback second, throw after both fail.
Add a focused BleReconnectPolicy regression that models repeated bounded Kable connect cycles returning Failed before a later stable recovery attempt. The test proves the outer reconnect loop continues through those inner failures, resets after the stable recovery outcome, and only uses a finite maxFailures value to terminate the test.
393eff4 to
f070db7
Compare
jamesarich
approved these changes
Jun 25, 2026
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.
Overview
This pull request makes the BLE Kable connection fallback policy explicit inside
KableBleConnection.connect(...).Before this change, the direct-connect → autoConnect fallback behavior was encoded as a
while (state != Connected)loop with an internalautoConnectflag flip. The intended behavior was bounded, but a reader had to trace mutable state to verify that eachconnect(...)call only attempts the direct path and then the autoConnect fallback.This change makes that invariant structural: each
connect(...)call performs at most two inner Kable attempts, whileBleRadioTransportremains responsible for the outer reconnect/backoff loop.Key Changes
while (state != Connected)retry structure with an explicit bounded loop.connect(...)cannot report success unless Kable reachedConnected.BleRadioTransport.KableBleConnectiondocumentation to describe the inner fallback policy.Testing
BleReconnectPolicyTestcoverage for repeated connection failures followed by recovery.Migration Notes