omi icon indicating copy to clipboard operation
omi copied to clipboard

iOS background BLE timeouts leave live transcription unavailable for minutes to hours

Open axAilotl opened this issue 3 months ago • 4 comments

A full-day trace from the production iOS app with a freshly paired stock CV1 on firmware 3.0.21 recorded seven native CoreBluetooth connection_timeout failures, all while app_state=background. The observed reconnect gaps ranged from about 3.9 seconds to 7,335.3 seconds (roughly 2 hours 2 minutes), including another gap of about 929.6 seconds; no new pairing-loss events occurred. Durable device storage prevented audio loss, but live transcription remained unavailable until the app returned and recovered. Expected behavior is for the iOS restoration/background route to retain or promptly re-establish the BLE audio path without requiring a foreground app relaunch or pendant reset.

axAilotl avatar Aug 10 '26 03:08 axAilotl

Was the device in range when it was not reconnected for 2 hours? Because ideally iOS would automatically reconnect if its in range (since we use state restoration)

mdmohsin7 avatar Aug 11 '26 08:08 mdmohsin7

@Git-on-my-level — need human response. Clarifying the range question and the product contract, because the original evidence set mixed two kinds of testing.

The earlier seven long intervals include both deliberate out-of-range excursions and failures experienced locally/in range. Those movement boundaries were not timestamped precisely enough to claim that the full two-hour interval was an in-range BLE reconnect delay. It is equally incorrect to dismiss the issue merely because the user sometimes left range.

A separate clean two-hour in-range control on 2026-08-11 showed zero BLE transitions and a continuously connected/ready BLE audio path while the remote transcription service failed repeatedly. That specific result belongs to #11306 and demonstrates an independent remote-STT failure. It does not remove the BLE recovery requirement here.

Expected behavior

Going in and out of phone range is normal pendant use, not an invalid test condition:

  • Out of range: the pendant must continue durable offline recording without losing audio.
  • Back in range: iOS state restoration/reconnect must reclaim the peripheral automatically, restore audio notification flow, resume live transcription, and drain/sync the offline backlog.
  • Recovery must not require relaunching the app, resetting/power-cycling the pendant, forgetting/re-pairing Bluetooth, or keeping the phone screen open.
  • The end-to-end invariant is reliability regardless of current connectivity: live when connected, durable capture while disconnected, and automatic convergence after reconnection.

Current-main code path relevant to missed background recovery

Current main still delays its first unexpected-disconnect reconnect using a 200 ms DispatchQueue.main.asyncAfter (disconnect handler). It also relies on restoration callbacks to rediscover/reconnect the restored peripheral (restoration path).

Draft PR #10573 identifies two directly relevant boundaries:

  1. iOS can suspend the app before delayed reconnect work executes, so it moves the first retry into the disconnect callback synchronously.
  2. A restored peripheral was not eligible for the reconnect sweep until a fresh didConnect, so it makes restored devices reclaimable earlier.

The PR's own physical validation still reports that a hard Bluetooth toggle can remain disconnected for 34 seconds until foreground, even though durable recording preserves the backlog. That is useful fallback behavior, but not yet the automatic recovery contract above.

Verification needed

Please preserve and test this as a transition contract, with timestamps for:

  1. last in-range audio packet;
  2. start/end of the out-of-range interval;
  3. BLE connection restored;
  4. audio notifications restored;
  5. first live transcript after return;
  6. offline backlog fully drained; and
  7. sequence continuity / zero missing audio.

The exact duration of an excursion changes the expected backlog size, not the requirement. This issue should not be closed or discounted solely because the pendant left phone range; that is a supported operating mode the offline ring exists to handle.

axAilotl avatar Aug 12 '26 02:08 axAilotl

Additional field evidence (2026-08-13): same BLE timeout class, plus why iOS bills this as all-day battery

This is a second-device observation of the same connection_timeout / background-recovery failure, with extra telemetry for the battery side of staying alive. It does not resolve the earlier in-range vs out-of-range timeline question; it adds a pocket-carry day where the app never suspended.

Setup

  • iPhone 15 Pro Max, iOS 26.6 (23G71)
  • TestFlight com.friend-app-with-wearable.ios12 1.0.543 (992) (not App Store)
  • Stock Omi CV 1, firmware 3.0.21 (same SKU/firmware as the original report)
  • Location permission: While Using the App (not Always). In-app locationEnabled was also false.
  • Hardware blue LED on (pendant recording) and iOS green mic indicator on (AVAudioSession held) for long stretches with the phone in pocket / screen off.
  • iOS Battery UI for the day: 51% attributed to Omi, 4m on screen / 16h 19m background, “ran in the background 4h 10m longer than usual.”

devicectl device sysdiagnose currently fails immediately with CoreDeviceCLISupport.DiagnoseError error 0 on this phone, so there is no Apple powerlog archive. The numbers below are from the app container, Crashlytics breadcrumbs, iOS resource diagnostics (bug_type 145 / 298), and a 45s Instruments Power Profiler attach to the live Runner process while charging.

Same BLE signature as this issue

Last 20 persisted disconnects on this pendant (ring buffer in app prefs):

  • 19/20 reason=connection_timeout (CBError code 6), appState=background
  • RSSI -91 to -97, rssiTrend gap/sudden/fading
  • Several holds of 0.7–2.6s then retry in 1–2s (reconnect storm, not a parked connect())
  • One ~4.9h background hold (connectionDurationMs ≈ 17_575_269) that then timed out at RSSI -93
  • Lifetime counters on this peripheral: 983 reconnects, 137 fail-to-connect

Crashlytics breadcrumbs on the same install logged repeated Omi Device Disconnected from 03:09 through the afternoon local time, which matches the 16h iOS background-attribution window.

That is the keep-alive described in the current disconnect handler: 200ms asyncAfter then centralManager.connect on every non-manual drop, including timeouts (OmiBleManager.swift reconnect). The “zero CPU/radio cost while waiting” comment is true for a single parked connect while out of range. It is false for timeout storms at RSSI ≈ -95: connect → fail in ~1s → connect again, with the process remaining in the bluetooth-central background mode.

Why this also drains the phone battery (not just live STT)

Three independent keep-alives were stacked. Location Always is not one of them.

  1. Audio session never released. Green mic indicator + UIBackgroundModes includes audio. Home starts flutter_foreground_task whenever OS location permission is always or whileInUse, and only stops it in HomePage.dispose (not on background):
final permission = await Geolocator.checkPermission();
if (permission == LocationPermission.always || permission == LocationPermission.whileInUse) {
  await ForegroundUtil.initializeForegroundService();
  await ForegroundUtil.startForegroundTask();
}

On this phone the foreground-task prefs were still backgroundServiceAction=API_START with the stored notification copy “Your Omi Device is connected / Transcription service is running in the background.” That is enough for iOS to keep the process executing and to show 16h of Background time even with 4m On Screen.

  1. Capture path stays armed (streamDeviceRecording on Home init with the persisted device). Wearable battery characteristic was sampled every 5.0s from 16:32–19:19 (2000 samples; pendant 96% → 86%). WAL metadata was still being rewritten at 19:18.

  2. BLE auto-reconnect never backs off, as above.

iOS resource diagnostics (not inferred)

Disk writes (Runner.diskwrites_resource, 2026-08-12 15:48–21:08, same 1.0.543/992 binary):

  • 1074 MB dirtied over 19199s (55.96 KB/s, limit 12.43 KB/s)
  • Heaviest stack: app binary → libcopyfile → kernel (WAL/audio file copies), plus libremovefile
  • Primary state: 61/83 samples Non-Frontmost, thread QoS Background, e-core, 80/83 samples on battery
  • Footprint 428 MB → 849 MB (max 957 MB), 65 threads
  • Advisory: ThermalPressure 10, Battery 3
  • Sampled coalition energy in that report: 38.15 mWh CPU-side (so the Settings 51% is mostly preventing suspend + radio + audio, not Dart burning a core)

Jetsam (2026-08-13 19:21): largestProcess = Runner. Process active (not suspended), ~637 MB resident (rpages=40862 at 16 KB pages), lifetime max ~947 MB, 100 FDs, freeze_skip_reason: out-of-slots.

Live Power Profiler attach to pid 25191 for ~45s (phone was on charger, so system %/hr is 0 and not useful): Core Location energy table was empty (consistent with While Using). Process still retired ~150–300M CPU instructions/s and ~40–50 KB Wi‑Fi TX every ~5s.

Product contract this adds

The original issue is live-transcription unavailability after background BLE timeouts. On this device the same keep-alive also:

  • holds an audio session (green mic) while the user is not in the UI
  • copies ~1 GB of capture files over a few hours
  • grows to ~1 GB RSS and cannot be frozen
  • shows up in Settings as all-day background battery

Out-of-range durable recording is still required. What should not be required is an unbounded 200ms reconnect storm plus a Home-started foreground/audio task merely because location permission exists.

Suggested fix split (do not mix)

  1. This issue: backoff / pause BLE reconnect in background after repeated connection_timeout; make restoration reconnect synchronous as in draft PR #10573; do not claim parked-connect cost while the timeout loop is hot.
  2. Battery / suspend: do not start flutter_foreground_task unless capture is actually running; release AVAudioSession when not recording; stop the 5s battery-characteristic poll and WAL copy storm when the user is not in a live session. Related tracker: #5491.

Happy to attach redacted disconnect JSON (no user identifiers) if useful. Not attaching sysdiagnose/prefs — those contain account and location history, and CoreDevice could not capture a sysdiagnose from this phone anyway.

Git-on-my-level avatar Aug 13 '26 23:08 Git-on-my-level

@Git-on-my-level — the 2026-08-13 clean Factory control produced a stronger failure of the same end-to-end recovery contract.

Setup was the isolated Factory iOS bundle, CV1 firmware 3.0.21 with read-only black-box counters/trace, and normal in/out-of-range use. No firmware flash, pendant reset, trace clear, or storage mutation occurred before collection.

The fresh pendant trace covers the complete boot from approximately 11:44:39.880 EDT through 22:12:

  • BLE disconnected at 11:51:20.783.
  • Hardware AAD sleep began at 11:51:21.853 while disconnected and with no storage transfer.
  • BLE reconnected at 11:51:30.121.
  • The pendant then crossed BLE state repeatedly through the day (12 connects / 11 disconnects total), including later reconnects at 13:00, 17:43, 18:38–18:41, 19:50–19:51, and 21:28.
  • Despite user speech and those reconnections, the trace recorded 1 AAD sleep and 0 AAD wakes across the remaining ~10 hours.
  • Final producer counters stopped at 20,035 encoded frames / 4,007 mic buffers. The SD remained powered, ready, and healthy: zero SD failures, remounts, storage rejections, or dropped frames.
  • The phone had no new durable file after the 11:46 run boundary, the ring was empty at the checkpoint, and no live attempt after the initial window produced a transcript.

This proves the observed red/blue transitions did not restore capture. The failure occurred before both BLE delivery and durable storage: the mic/PDM entered AAD sleep and never resumed.

There is also an independent loss boundary in unmodified production 3.0.21. Its pusher stores audio only when current_connection == NULL. When a BLE connection exists but the audio CCCD subscription is absent, the final branch dequeues and discards the frame instead of storing it: 3.0.21 transport pusher. Thus “blue/GATT connected” can suppress offline durability without proving live audio is flowing.

The stock AAD path arms a GPIO edge and then waits indefinitely for that signal to call exit_hw_aad(): 3.0.21 AAD sleep/wake path. This run shows that wake transition can fail permanently until a reset.

So this issue is not only “iOS may reconnect slowly.” The required invariant is:

  1. a BLE connection is not capture readiness until fresh audio frames arrive;
  2. durable recording must continue whenever live delivery is not proven, including connected-without-subscription;
  3. reconnection must restore the CCCD/audio path and verify frame liveness; and
  4. AAD needs a bounded recovery/watchdog path so a missed WAKE edge cannot erase the rest of the day.

The full 278-event app export and an independent 287-event CoreBluetooth pull are preserved locally; both report protocol v2, firmware 3.0.21, no trace overwrite, and no SD hardware fault.

axAilotl avatar Aug 14 '26 02:08 axAilotl