Skip to content

refactor(ble): Make Kable connect fallback explicitly bounded#5944

Merged
jamesarich merged 2 commits into
meshtastic:mainfrom
jeremiah-k:bugfix/kable-auto-connect-bounded
Jun 25, 2026
Merged

refactor(ble): Make Kable connect fallback explicitly bounded#5944
jamesarich merged 2 commits into
meshtastic:mainfrom
jeremiah-k:bugfix/kable-auto-connect-bounded

Conversation

@jeremiah-k

Copy link
Copy Markdown
Contributor

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 internal autoConnect flag flip. The intended behavior was bounded, but a reader had to trace mutable state to verify that each connect(...) 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, while BleRadioTransport remains responsible for the outer reconnect/backoff loop.

Key Changes

  • Replaced the implicit while (state != Connected) retry structure with an explicit bounded loop.
  • Preserved the existing connection order:
    • direct connect first when a fresh advertisement is available,
    • autoConnect fallback second,
    • advertisement-less devices start on the autoConnect path.
  • Added a final state check so connect(...) cannot report success unless Kable reached Connected.
  • Kept macro reconnect/backoff ownership in BleRadioTransport.
  • Updated KableBleConnection documentation to describe the inner fallback policy.
  • Added focused coverage proving repeated bounded inner failures do not stop the outer reconnect policy from reaching a later successful attempt.

Testing

  • Added BleReconnectPolicyTest coverage for repeated connection failures followed by recovery.
  • Verified the outer reconnect policy continues after repeated failed inner connection attempts.

Migration Notes

  • No user data migration is required.
  • No BLE address format changes are introduced.
  • The outer BLE reconnect/backoff policy remains unchanged.

@github-actions github-actions Bot added bugfix PR tag refactor no functional changes labels Jun 25, 2026
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.
@jeremiah-k jeremiah-k force-pushed the bugfix/kable-auto-connect-bounded branch from 393eff4 to f070db7 Compare June 25, 2026 12:19
@jeremiah-k jeremiah-k marked this pull request as ready for review June 25, 2026 12:31
@jamesarich jamesarich added this pull request to the merge queue Jun 25, 2026
Merged via the queue into meshtastic:main with commit 725133e Jun 25, 2026
22 checks passed
@jeremiah-k jeremiah-k deleted the bugfix/kable-auto-connect-bounded branch June 25, 2026 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix PR tag refactor no functional changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants