Repository navigation
fix(tandem): stabilize the Mobi BLE link across reconnects and busy operations - #153
Merged
Merged
Conversation
…iates down The Mobi renegotiates the BLE connection down to its power-saving profile (interval=30ms, latency=29, timeout=2s) ~15s after connect. The 2s supervision timeout causes frequent CONNECTION_TIMEOUT drops. Re-assert CONNECTION_PRIORITY_HIGH when onConnectionUpdated reports a degraded profile (latency > 0), but skip while a bolus is in flight (the pump rejects the connection-parameter update with INSUFFICIENT_AUTHORIZATION mid-bolus). The in-progress bolus is tracked via PumpStateSupplier.inProgressBolusId.
Contributor
Author
Owner
|
Going to merge this but make it configurable behind a flag |
jwoglom
pushed a commit
that referenced
this pull request
Sep 25, 2026
All behavior changes from #153 are now disabled by default and enabled via TandemPump.enablePeriodicConnectionPriorityReassert(). This includes the periodic and onConnectionUpdated HIGH priority re-asserts, the busy-state tracking (including PumpStateSupplier.inProgressBolusId updates), and the related connection lifecycle changes (address-filtered scan race, scan stops on connect/disconnect, connection-failure retry, ignoring failed connection updates while disconnected, getInstance rebind, resetInstance teardown, and Timber tree uproot). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K4GJkadU6xRduN5FPLmcYT
jwoglom
pushed a commit
that referenced
this pull request
Sep 25, 2026
Only the connection-priority re-assert behavior (periodic timer, onConnectionUpdated re-assert, and the busy-state tracking that feeds it) stays behind enablePeriodicConnectionPriorityReassert(). The scan race, scan stops, connection-failure retry, ignoring failed connection updates while disconnected, getInstance rebind, resetInstance teardown, and Timber uproot are unconditional again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K4GJkadU6xRduN5FPLmcYT
jwoglom
added a commit
that referenced
this pull request
Sep 25, 2026
fix(tandem): stabilize the Mobi BLE link across reconnects and busy operations
jwoglom
pushed a commit
that referenced
this pull request
Sep 25, 2026
All behavior changes from #153 are now disabled by default and enabled via TandemPump.enablePeriodicConnectionPriorityReassert(). This includes the periodic and onConnectionUpdated HIGH priority re-asserts, the busy-state tracking (including PumpStateSupplier.inProgressBolusId updates), and the related connection lifecycle changes (address-filtered scan race, scan stops on connect/disconnect, connection-failure retry, ignoring failed connection updates while disconnected, getInstance rebind, resetInstance teardown, and Timber tree uproot). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K4GJkadU6xRduN5FPLmcYT
jwoglom
pushed a commit
that referenced
this pull request
Sep 25, 2026
Only the connection-priority re-assert behavior (periodic timer, onConnectionUpdated re-assert, and the busy-state tracking that feeds it) stays behind enablePeriodicConnectionPriorityReassert(). The scan race, scan stops, connection-failure retry, ignoring failed connection updates while disconnected, getInstance rebind, resetInstance teardown, and Timber uproot are unconditional again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K4GJkadU6xRduN5FPLmcYT
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.
What this fixes
This is the driver-layer half of the Tandem Mobi disconnection work; the app-side
half is andyrozman/AndroidAPS#220.
The Mobi renegotiates the BLE link down to its power-saving profile (interval
30 ms, latency 29, timeout 2 s) about 15 s after connect. The 2 s supervision
timeout causes frequent
CONNECTION_TIMEOUTdrops. This PR keeps the link on theHIGH profile, and stops that maintenance from interfering with operations the
pump rejects parameter updates during.
After these changes I have had no disconnections for more than a week.
Changes (all in
TandemBluetoothHandler)Connection priority
CONNECTION_PRIORITY_HIGHwhenonConnectionUpdatedreports adegraded profile (checked on interval/latency/timeout, not latency alone).
hook misses. Started when authentication completes, stopped on disconnect.
Don't re-assert while the pump is busy — the pump rejects the parameter
update with
INSUFFICIENT_AUTHORIZATIONmid-operation:BolusPermissionResponse/CurrentBolusStatusResponse(DELIVERING/REQUESTINGrefresh it), cleared onBOLUS_PERMISSION_REVOKEDand after a 10-minute stale expiry so a missedterminal response cannot pin the link to the power-saving profile.
FillCannulaStateStreamResponseandLoadStatusResponse, with a 10-minutestale expiry.
HistoryLogResponse/HistoryLogStreamResponse,with a 30-second stale expiry (a re-assert mid-download made the pump drop the
link and wedged the host's history retriever).
Reconnect and teardown hygiene
resetInstance()now tears the outgoing handler down (stop()) before droppingit; nulling the field alone left abandoned instances' pending autoConnects and
periodic work running, producing duplicate connections and multiplied logs.
getInstance()rebinds the live host so callbacks reach it.autoConnect(can take minutes) with a low-latencyaddress-filtered scan (discovers in seconds);
onDiscoveredPeripheralthenconnects directly.
immediateConnectToPeripheral5 s after a failed connection; blessed'ssingle internal retry could leave no pending connection.
stopScan()on connect and on disconnect to clear a lingering scanner.onConnectionUpdatedfailures while not connected (expected noise duringteardown, not an emergency).
Robustness
setNotifyfor characteristics thefirmware does not expose (e.g. older t:slim X2) instead of waiting forever on a
callback that will never come.
resetInstance()/recreatecycles were multiplying every log line.
Testing
Used with AAPS on a Tandem Mobi over ~2 weeks of logs, exercising pairing,
reconnect, bolus, fill and history-download flows. No disconnections observed
after the changes.