Skip to content

fix(tandem): harden Mobi connection recovery and prevent workflow lockouts - #220

Open
haarisedhi102 wants to merge 8 commits into
andyrozman:andy_tandem_dev4from
haarisedhi102:pump_state
Open

haarisedhi102 wants to merge 8 commits into
andyrozman:andy_tandem_dev4from
haarisedhi102:pump_state

Conversation

@haarisedhi102

@haarisedhi102 haarisedhi102 commented Sep 11, 2026 •

Copy link
Copy Markdown

Tandem Mobi connection hardening, plus the latch/pairing fixes found while testing it.

The matching driver-layer work is jwoglom/pumpX2#153, released in pumpX2 v1.9.3
(this PR pins it).

Scope vs andy_tandem_dev4 (v0.9.7.1)

15 files, +462/−36. pump/common is untouched.

Connection lifecycle (TandemPumpCommunicationManager)

  • plannedDisconnect: veto pumpX2 auto-reconnect during a host-initiated teardown,
    and do not start TandemConnectionFixer for it. RF drops still auto-reconnect.
  • CONNECT_TOTAL_TIMEOUT (180 s) hard cap: if the link drops before service
    discovery, handshakingStartTime stays 0 and neither existing timeout can fire;
    the connect loop held inConnectMode forever and swallowed later attempts.
  • Publish pumpConnectedFlow on every handshake (including pumpX2's internal
    reconnect, which bypasses connect()), publish disconnected on unplanned drops.
  • Clear preventReconnect on a successful handshake. tryToReconnectToPump()
    sets it via forceResetBluetoothHandler(); without this the link recovered but
    isBusy() / isInPreventConnectMode() stayed true (queue logged "busy" forever).
  • communicationListener setter: assign field = value unconditionally; previously
    passing null left a stale listener attached.

Status/error truth (TandemPumpConnector, TandemPumpConnectionManager, TandemService, TandemPumpUtil)

  • Repair a stale pumpConnectedFlow (link up, flow false) on connect and on a
    successful status read.
  • On a successful status read: clear error details and reset a driverStatus
    latched at ErrorCommunicatingWithPump.
  • clearErrorDetails() is a Mobi-only helper: core PumpUtil.clearError() NPEs
    when an error is latched (its errorType setter does pumpErrorType!!).
    pump/common is out of scope here; the only consumer of errorType is
    isConnecting(), which ignores a latched PumpUnreachable.
  • disconnectFromPump() is no longer gated on isConnected(): during a connect
    attempt the driver is Connecting, so a force-disconnect was a no-op and left the
    in-flight connect holding the pumpX2 handler.

Pairing / overview (new since the original branch)

  • Pair teardown now actually tears down the in-flight connect (see above).
  • stopBluetoothHandler() does nothing when the pairing manager owns no handler;
    it used to re-set preventReconnect after the wizard's onFinish cleared it.
  • Pair button: setPairButtonStatus() is called on init, and managementActions
    is included in the pumpRunningState == Unknown overview state, so the button is
    reachable exactly when the pump is not connected.

UI workflow latch (TandemPumpStatus, TandemMobiPumpPlugin, MobiComposeContent)

  • 30-minute TTL backstop on preventQueueExecution (isQueueExecutionPrevented()),
    so a missed release cannot lock the Loop out (previously ~5.4 h with no SMBs).
  • Release the UI workflow locks whenever navigation leaves the Actions/Data screens,
    not only via the toolbar back arrow.

History download (HistoryRetriever, TandemUICommunication)

  • Progress watchdog in both download loops: a stalled/silent stream no longer wedges
    the download and the CommandExecutor for the full timeout.
  • Always rebind the history listener for a download; log (instead of silently
    dropping) history responses when the retriever is not initialised.

Diagnostics

  • Transitions for preventReconnect, preventQueueExecution, isBusy,
    isInPreventConnectMode; connect/disconnect lifecycle; pairing start/finish;
    error-clear payloads. Happy to trim any of this if you prefer.

Not in this PR

  • Fill Cannula mirror / verified-resume UI: kept at the dev_4 version, will be a
    separate follow-up PR.
  • The old concurrency/PumpAvailabilitySync code from my original branch: removed
    by dev_4 already, so it is not part of this diff. pumpConnectedFlow is kept
    current as the backend connection signal.
  • TandemConnectionFixer: still disabled, untouched.

Testing

  • :app:compileFullDebugKotlin and :pump:tandem:compileDebugKotlin pass.
  • On-device (Tandem Mobi, e6179c1-2026.10.26): pairing, re-pair, RF drop and
    return without an app restart, the connected-but-busy latch case, and history
    download progress.

Known limitation (deliberately not fixed here)

  • If a connect attempt never succeeds, nothing retries it: TandemMobiPumpPlugin.connect()
    is not implemented, so the queue's pump.connect() is a no-op, and
    TandemConnectionFixer is disabled. Recovery needs a restart or a re-pair.

@haarisedhi102
haarisedhi102 marked this pull request as ready for review September 11, 2026 14:33
@haarisedhi102

Copy link
Copy Markdown
Author

jwoglom/pumpX2#153

@haarisedhi102 haarisedhi102 changed the title Pump state Pump state tweaks Sep 16, 2026
@haarisedhi102 haarisedhi102 changed the title Pump state tweaks fix(tandem): harden Mobi connection recovery and prevent workflow lockouts Sep 23, 2026
@andyrozman

andyrozman commented Sep 26, 2026 •

Copy link
Copy Markdown
Owner

I am doing latest integration from dev just now (metro stuff that that was introduced). Could you please check your PR afterwards, I would like to see if we can integrate some (or all) of your changes in, since it seems you have done your homework... If possible can you please contact me on discord so that we can talk this changes through?

I hope to do push of changes to branch on sunday or whenever the most obvious problems are fixed..

jwoglom has added some connection fixed in library, problem is that new version it is not yet available with those connection changes...

@haarisedhi102

@haarisedhi102

haarisedhi102 commented Oct 27, 2026 •

Copy link
Copy Markdown
Author

updated to include your changes, would love your feedback on this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants