Skip to content

fix(app): fall back to phone capture after BLE disconnect - #11066

Closed
aryanorastar wants to merge 5 commits into
BasedHardware:mainfrom
aryanorastar:fix/7194-ble-disconnect-phone-fallback
Closed

aryanorastar wants to merge 5 commits into
BasedHardware:mainfrom
aryanorastar:fix/7194-ble-disconnect-phone-fallback

Conversation

@aryanorastar

@aryanorastar aryanorastar commented Aug 3, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Relates to #11078.

Retargeted 2026-08-04: this PR was originally opened against #7194, but maintainers (@mdmohsin7, @Git-on-my-level) flagged that #7194 is specifically about on-device offline recording (a separate, existing-but-flaky path), and that a phone-capture fallback is a different behavior. This PR now tracks against #11078, filed to scope that phone-fallback behavior on its own. Using "Relates to" rather than "Fixes" since the approach for #11078 itself is still pending maintainer confirmation — see the also-still-open deviceRecord state-gating issue raised in review.

When an active supported wearable recording lost Bluetooth, the app stopped
receiving device audio but did not start its existing automatic phone-mic batch
fallback. The missing interval was therefore lost until the wearable reconnected.

The capture controller now starts the existing automatic phone batch writer on
an unexpected BLE disconnect during an active supported recording. The batch is
finalized before device streaming resumes on reconnect, and manual stops,
unsupported devices, inactive sessions, and already-active batch sessions do
not trigger the fallback.

Verification

  • flutter test test/unit/batch_recording_phone_test.dart
    • 20 tests passed, including the BLE-disconnect fallback policy matrix.
  • dart format --output=none --set-exit-if-changed test/unit/batch_recording_phone_test.dart
    • Passed.
  • flutter analyze lib/providers/device_provider.dart lib/services/capture/capture_controller.dart lib/utils/batch_recording.dart test/unit/batch_recording_phone_test.dart
    • No new diagnostics in changed logic; the command reports one existing
      unnecessary_import in device_provider.dart.

Invariants

No product invariants are affected.

Failure-Class: none

Review in cubic

@aryanorastar
aryanorastar requested a review from mdmohsin7 as a code owner August 3, 2026 18:05
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@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.

All reported issues were addressed across 4 files

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

Re-trigger cubic

@Git-on-my-level Git-on-my-level added needs-maintainer-review Needs a human maintainer to sign off before merge flutter flutter work labels Aug 3, 2026

@Git-on-my-level Git-on-my-level left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for this — the direction is right and the predicate/test structure is clean. There's a blocking issue before this can land.

The fallback won't trigger for active BLE device streaming.

onRecordingDeviceDisconnected() gates on recordingState == RecordingState.record, but active BLE device streaming uses RecordingState.deviceRecord (set in _initiateDeviceAudioStreaming). No path transitions a live device recording into .record — that state is only used by the phone-mic flows (streamRecording, _startPhoneMicBatch, _resumeMicRecording). So when a wearable drops mid-stream, shouldFallbackToPhoneOnDeviceDisconnect evaluates isRecording: false and returns early. The exact scenario this PR targets is missed.

The fix should check the device-record lane:

isRecording: recordingState == RecordingState.deviceRecord ||
    recordingState == RecordingState.record,

(and possibly .interrupted if a socket drop preceded the BLE disconnect).

Two secondary points:

  1. The predicate checks phoneMicSupportsTranscribeLater (iOS/Android) but not deviceSupportsTranscribeLater. If the intent is to fall back only for supported wearable types, adding the device-side check (deviceSupportsTranscribeLater) would keep the fallback scoped.

  2. In the reconnect hand-off, ServiceManager.instance().phoneMic.stop() is fire-and-forget. The comment says the phone batch is finalized before device streaming resumes, but since stop() isn't awaited the ordering isn't guaranteed. If stop() can be made awaitable (or the hand-off serialized), that would make the transition deterministic.

The unit tests cover the predicate matrix nicely but don't exercise the RecordingState integration, which is why they pass despite the mismatch. Adding a test that verifies the fallback triggers from deviceRecord would catch this.

Flagging for maintainer review since this touches the core capture state machine.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@mdmohsin7 mdmohsin7 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The tagged issue actually means recording on the device offline when not connected to bluetooth. Right now it does record offline but it breaks sometimes. This PR is not the right fix for this

@aryanorastar

Copy link
Copy Markdown
Collaborator Author

@mdmohsin7 thanks — understood. I’ll treat this PR as the wrong approach for #7194 if the intended behavior is on-device offline recording when BLE is disconnected (which already exists but is flaky), rather than falling back to phone capture.

@Git-on-my-level your deviceRecord gate finding is still correct for the fallback design this PR attempted, but I’m pausing further work on that path until we confirm product intent with @mdmohsin7.

Please confirm preferred next step:

  1. Close this PR and open a new one that hardens on-device offline recording, or
  2. Keep a phone-fallback path as a separate, explicitly scoped issue.

Happy to take whichever you prefer.

@aryanorastar

Copy link
Copy Markdown
Collaborator Author

Retargeting this PR per @mdmohsin7's feedback above: #7194 is specifically about on-device offline recording continuing when BLE is disconnected (which already exists but is flaky) — this PR implements a different behavior, falling back to phone-mic capture while BLE is down, which isn't the right fix for #7194.

Filed #11078 to scope and track the phone-capture-fallback behavior on its own, distinct from #7194, and updated this PR's description to reference it ("Relates to #11078" rather than an auto-closing keyword, since the approach itself is still pending maintainer confirmation).

@Git-on-my-level's deviceRecord state-gating finding from your review still stands and is called out in the new issue — that needs to be fixed here before this can land regardless of which issue it tracks against.

Not closing or merging anything — just re-pointing this at the correct issue for continued review.

@aryanorastar

Copy link
Copy Markdown
Collaborator Author

Pushed an update for the remaining CHANGES_REQUESTED on this PR:

  • Fix fallback predicate to treat (and ) as the active recording lane.
  • Gate fallback with wearable Transcribe Later support in addition to phone support.
  • Serialize reconnect/device handoff by waiting for phone-batch teardown via an completer (no more fire-and-forget stop ordering).
  • Added unit coverage for the RecordingState->predicate mapping ().

Could you re-review and dismiss the Changes requested once CI is green?

@aryanorastar

Copy link
Copy Markdown
Collaborator Author

Update pushed for CHANGES_REQUESTED:

  • deviceRecord/Interrupted treated as active lane for disconnect fallback
  • supportsBatch gated with wearable Transcribe Later support
  • reconnect/device handoff serialized by waiting for phone-batch onStop completer
  • added unit test for RecordingState -> predicate mapping

Please re-review / dismiss once CI is green.

@aryanorastar

Copy link
Copy Markdown
Collaborator Author

Closing as superseded.

Sorry for the tip/history confusion on this branch.

@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Hey @aryanorastar 👋

Thank you so much for taking the time to contribute to Omi! We truly appreciate you putting in the effort to submit this pull request.

After careful review, we've decided not to merge this particular PR. Please don't take this personally — we genuinely try to merge as many contributions as possible, but sometimes we have to make tough calls based on:

  • Project standards — Ensuring consistency across the codebase
  • User needs — Making sure changes align with what our users need
  • Code best practices — Maintaining code quality and maintainability
  • Project direction — Keeping aligned with our product principles and locked invariants

Before your next PR, please skim:

  • PRODUCT.md — product north star
  • Product invariants — locked rules (shared chat, memory tiers, agent control plane, integrations, brand)

If this was declined for direction or taste, maintainers should cite an invariant ID or open a proposed one — ask if that citation is missing.

Your contribution is still valuable to us, and we'd love to see you contribute again in the future! If you'd like feedback on how to improve this PR or want to discuss alternative approaches, please don't hesitate to reach out.

Thank you for being part of the Omi community!

mdmohsin7 added a commit that referenced this pull request Aug 5, 2026
#11134)

## Summary

Reverts #11084 (`75e4e1789d`), which added
`CaptureController.onRecordingDeviceDisconnected()` and the
`DeviceProvider` hook that starts a **phone-mic batch recording whenever
the wearable disconnects mid-session**.

## Why

**This behaviour was already reviewed and rejected.** #11066 proposed
the same phone-side fallback and received `CHANGES_REQUESTED` from the
app maintainer:

> The tagged issue actually means recording on the device offline when
not connected to bluetooth. Right now it does record offline but it
breaks sometimes. This PR is not the right fix for this

#11066 was closed, and #11078 was opened specifically so a phone-side
fallback could be scoped on its own merits. **#11078 is still open and
unapproved.**

**The PR description did not match its diff.** #11084 is titled
"preserve on-device offline batch across BLE disconnect" and its body
states it "prevents the phone-mic fallback from triggering". Before
#11084 there was no such fallback to prevent:
`onRecordingDeviceDisconnected` did not exist and nothing called it, and
`_startPhoneMicBatch` was reachable only from user-initiated paths. The
PR introduced the feature together with a guard for it; the
Implementation section listed neither the new method nor the
`device_provider.dart` call site.

**The guard does not cover Omi hardware.** It reads:

```dart
final bool isOnDeviceOfflineBatchActive = SharedPreferencesUtil().batchModeEnabled &&
    _recordingDevice != null &&
    (_recordingDevice!.type == DeviceType.limitless || _offlineSessionStartSeconds != 0);
```

It consults `batchModeEnabled`, but ring-buffer capture is keyed on
firmware (`WalSyncs.isRingBufferFirmware`, 3.0.20+) and is independent
of that pref. With batch mode off, an Omi on 3.0.20+ keeps writing to
its on-device ring while the phone starts its own mic batch — the same
interval is captured twice and syncs as duplicate conversations, plus an
unrequested mic activation and the battery cost.

#11084 did address the technical review notes from #11066
(`deviceRecord` state, awaited stop hand-off,
`deviceSupportsTranscribeLater`). The product objection was not
addressed.

## Scope

Revert only. #11064 and #11085 from the same batch are left in place —
#11064 is a genuine sort fix, and #11085 needs a real fix rather than a
revert (its `filterFullySyncedConversations` never releases a WAL
retired to `WalStatus.outsideRecoveryWindow` by #10995, so those
conversations stay filtered out of the synced list; tracked separately).

#7194 remains open on its actual subject: on-device offline recording
that works but is flaky across disconnects.

## Verification

```
flutter analyze lib/services/capture/capture_controller.dart lib/utils/batch_recording.dart \
  lib/providers/device_provider.dart test/unit/batch_recording_phone_test.dart
  -> 1 info (unnecessary_import at device_provider.dart:4), confirmed pre-existing on main; 0 new

flutter test test/unit/batch_recording_phone_test.dart test/providers/capture_provider_test.dart \
  test/providers/sync_provider_fully_synced_conversations_test.dart \
  test/unit/synced_conversation_pointer_order_test.dart
  -> 89 tests, all passed

grep shouldFallbackToPhoneOnDeviceDisconnect | onRecordingDeviceDisconnected |
     isRecordingDuringDeviceDisconnect | _phoneMicBatchStopCompleter
  -> no matches remain under app/

make preflight -> 11 checks passed
```

Clean revert: no later commit touched `capture_controller.dart`,
`batch_recording.dart`, `device_provider.dart`, or
`batch_recording_phone_test.dart` between #11084 and `84e4c1828b`.

## Product invariants affected

none

## Failure class (fixes)

No `fix:` commits; no declaration required.


<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/BasedHardware/omi/pull/11134?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>
<!-- End of auto-generated description by cubic. -->
pull Bot pushed a commit to Mu-L/omi that referenced this pull request Aug 5, 2026
Reverts 75e4e17 (BasedHardware#11084), which added `onRecordingDeviceDisconnected()`
and the `device_provider` hook that starts a phone-mic batch recording
whenever the wearable drops mid-session.

The same behaviour was proposed in BasedHardware#11066 and rejected by the app
maintainer: BasedHardware#7194 asks for on-device offline recording to keep working
across a disconnect, not for the phone to start recording in its place.
BasedHardware#11066 was closed and BasedHardware#11078 was opened to scope a phone-side fallback on
its own merits; BasedHardware#11078 is still open and unapproved.

BasedHardware#11084 landed the feature anyway, described as a guard against it. Its
guard is also wrong for Omi hardware: it consults `batchModeEnabled`, but
ring-buffer capture is keyed on firmware (`isRingBufferFirmware`, 3.0.20+)
and is independent of that pref. With batch mode off, an Omi on 3.0.20+
keeps writing to its ring while the phone starts its own mic batch, so the
same interval is captured twice and syncs as duplicate conversations.

Verification:
  flutter analyze lib/services/capture/capture_controller.dart \
    lib/utils/batch_recording.dart lib/providers/device_provider.dart \
    test/unit/batch_recording_phone_test.dart
    -> 1 pre-existing info (unnecessary_import, already on main), 0 new
  flutter test test/unit/batch_recording_phone_test.dart \
    test/providers/capture_provider_test.dart \
    test/providers/sync_provider_fully_synced_conversations_test.dart \
    test/unit/synced_conversation_pointer_order_test.dart
    -> 89 tests, all passed
  grep for shouldFallbackToPhoneOnDeviceDisconnect / onRecordingDeviceDisconnected
  / isRecordingDuringDeviceDisconnect / _phoneMicBatchStopCompleter -> no matches

Failure-Class: none
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

flutter flutter work needs-maintainer-review Needs a human maintainer to sign off before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants