Skip to content

fix(ios): salvage incidental BLE cleanups from reverted keepalive - #11576

Merged
Git-on-my-level merged 2 commits into
mainfrom
fix/ios-ble-incidental-cleanups
Aug 20, 2026
Merged

Git-on-my-level merged 2 commits into
mainfrom
fix/ios-ble-incidental-cleanups

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Aug 14, 2026 •

Copy link
Copy Markdown
Member

Summary

Related: #11547 (reverted), #11567 (revert), #10573 (draft; RSSI-on-demand overlap inside a much larger DFU/GATT rewrite — not a substitute for this salvage). Related: #5491, #6570. Not a fix for #11307.

Product invariants affected

none

Failure class (fixes)

Failure-Class: none

Test plan

  • cd app && bash test.sh test/unit/native_ble_transport_resync_test.dart test/services/devices/transports/native_ble_transport_test.dart — 6 passed (silent CCCD retried once then left dead; Bee UUID arms the watch; existing resubscribe tests)
  • Diagnostics screen: RSSI graph still updates; leaving the screen stops the 3s poll
  • Idle connected wearable: no 3s readRSSI keep-alive
  • Kill/relaunch with a restored peripheral: reconnectStalePeripherals will re-issue connect
  • Battery history: small fluctuations do not write every notification

Review in cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 7 files

Confidence score: 3/5

  • In app/ios/Runner/Ble/OmiBleManager.swift, the restoration reconnect path can miss retries if a re-issued connection fails before the 200 ms closure executes, so iOS suspension may leave peripherals stuck disconnected until manual recovery; persist a reconnect deadline and flush overdue reconnect work during restoration/powered-on handling to make retries resilient.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="app/ios/Runner/Ble/OmiBleManager.swift">

<violation number="1" location="app/ios/Runner/Ble/OmiBleManager.swift:603">
P2: When a restored peripheral fails its re-issued connection before the 200 ms closure runs, iOS can suspend the process and lose the retry. Persist a reconnect deadline and flush due work from restoration, powered-on, failure, and foreground recovery callbacks.

(Based on your team's feedback about durable BLE reconnect deadlines.)</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread app/ios/Runner/Ble/OmiBleManager.swift Resolved
// State-restored peripherals have already connected in a prior
// process lifetime; mark them so reconnectStalePeripherals will
// re-issue connect instead of treating them as scan strangers.
everConnected.insert(uuid)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: When a restored peripheral fails its re-issued connection before the 200 ms closure runs, iOS can suspend the process and lose the retry. Persist a reconnect deadline and flush due work from restoration, powered-on, failure, and foreground recovery callbacks.

(Based on your team's feedback about durable BLE reconnect deadlines.)

View Feedback

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At app/ios/Runner/Ble/OmiBleManager.swift, line 603:

<comment>When a restored peripheral fails its re-issued connection before the 200 ms closure runs, iOS can suspend the process and lose the retry. Persist a reconnect deadline and flush due work from restoration, powered-on, failure, and foreground recovery callbacks.

(Based on your team's feedback about durable BLE reconnect deadlines.) </comment>

<file context>
@@ -561,6 +597,10 @@ extension OmiBleManager: CBCentralManagerDelegate {
+                // State-restored peripherals have already connected in a prior
+                // process lifetime; mark them so reconnectStalePeripherals will
+                // re-issue connect instead of treating them as scan strangers.
+                everConnected.insert(uuid)
                 uuids.append(uuid)
 
</file context>

Git-on-my-level and others added 2 commits August 15, 2026 02:51
Stop the 3s readRSSI keep-alive (poll only while diagnostics is
subscribed), mark CoreBluetooth-restored peripherals as everConnected,
throttle battery-history writes, and retry a silent audio CCCD once
after reconnect. Audio notify UUIDs live next to the constants in
models.dart; no Dart reconnect-policy mirror.

Salvaged from #11547 as called out in #11567.

Failure-Class: none
Co-authored-by: Cursor <[email protected]>
…veness timer on disconnect

- Rehydrate lastPersistedBatteryLevel/AtMs from the newest persisted
  history entry so the first battery notification after a process
  restart is throttled against the prior persisted sample.
- Cancel _audioLivenessTimer and reset _audioSilenceResubscribes at the
  top of disconnect(), matching dispose() and _handleConnectionState(false),
  so a stale watch cannot fire into a later connection.
@Git-on-my-level
Git-on-my-level force-pushed the fix/ios-ble-incidental-cleanups branch from a632aea to 0b4cb2b Compare August 14, 2026 20:06
@Git-on-my-level

Copy link
Copy Markdown
Member Author

Addressed the Cubic review round on 0b4cb2b3:

  • Battery throttle baseline after restart (OmiBleManager.swift): fixed — shouldPersistBatteryReading now lazily rehydrates lastPersistedBatteryLevel/lastPersistedBatteryAtMs from the newest persisted history entry, so the first battery notification after a relaunch is throttled against the prior persisted sample instead of bypassing the check. Thread resolved.
  • disconnect() stale liveness timer (native_ble_transport.dart): fixed — disconnect() now cancels _audioLivenessTimer and resets _audioSilenceResubscribes at the top, matching dispose() and _handleConnectionState(false), so a pending watch from a prior connection cannot fire into a later one and force a spurious CCCD re-subscribe. Thread resolved.
  • Durable persisted reconnect deadlines (OmiBleManager.swift:603): not adopted. The 200 ms retry closure flagged there is pre-existing code outside this PR's diff, and a persisted reconnect-deadline subsystem flushed from four callbacks is the reconnect-policy/backoff rework this PR explicitly excludes per the Revert "fix(ios): stop background audio keep-alive and back off BLE timeouts" #11567 revert scoping (the 200ms→60s backoff family). Foreground recovery for restored peripherals is already covered by reconnectStalePeripherals(), which this PR strengthens. Worth a separate PR if wanted.

Verification: focused suites native_ble_transport_resync_test.dart + native_ble_transport_test.dart pass locally (6/6); xcrun swiftc -parse clean; CI on the new head: Dart Analyze & Tests, Formatting, Android Compile Smoke, Hygiene all pass.

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Salvages the independently-verifiable pieces mdmohsin7 named in the #11567 revert, with unit coverage; holding the merge until the on-device BLE test-plan items are checked.

@Git-on-my-level
Git-on-my-level merged commit 290db6c into main Aug 20, 2026
27 checks passed
@Git-on-my-level
Git-on-my-level deleted the fix/ios-ble-incidental-cleanups branch August 20, 2026 04:57
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