Skip to content

fix(app): order offline sync results by recording time - #11064

Merged
kodjima33 merged 1 commit into
BasedHardware:mainfrom
aryanorastar:fix/5859-sync-results-order
Aug 4, 2026
Merged

kodjima33 merged 1 commit into
BasedHardware:mainfrom
aryanorastar:fix/5859-sync-results-order

Conversation

@aryanorastar

@aryanorastar aryanorastar commented Aug 3, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fixes #5859.

The main Conversations stream already orders and groups by recording time
(startedAt ?? createdAt). The post-offline-sync processed-conversations list
still sorted its pointers by upload/creation time, so an older recording uploaded
the next morning could appear above a newer conversation.

The shared sync-pointer ordering now uses recording time with a creation-time
fallback, keeping the post-sync list consistent with the main conversation stream.

Verification

  • flutter test test/unit/synced_conversation_pointer_order_test.dart
    • 2 tests passed.
  • Regression coverage includes an older recording uploaded after a newer
    recording and a missing-startedAt fallback.

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 17:53
@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.

No issues found across 2 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Re-trigger cubic

@Git-on-my-level

Copy link
Copy Markdown
Member

Thanks @aryanorastar — clean consistency fix. The main conversation stream (conversation_provider.dart) already orders by startedAt ?? createdAt; this brings the post-offline-sync processed list in line, so an older recording uploaded the next morning no longer appears above a newer conversation.

Extracting sortSyncedConversationPointers() as a top-level function makes the shared ordering directly testable, and the two unit tests cover both the regression (recording-time ordering) and the startedAt-null fallback to createdAt. Dart Analyze & Tests and Android Compile Smoke are green.

Looks good from my side — leaving for a human maintainer to approve/merge.


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

@Git-on-my-level Git-on-my-level added the flutter flutter work label Aug 3, 2026
@aryanorastar

Copy link
Copy Markdown
Collaborator Author

@Git-on-my-level thanks for the positive signal earlier — checks remain green on this head. Ready for human maintainer approve/merge whenever convenient.

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

Post-sync pointer list sorted by createdAt while the main stream orders by startedAt ?? createdAt, so an older recording uploaded later jumped to the top. Fix aligns both. Test included. 5/5 - merging.

@kodjima33
kodjima33 merged commit e736801 into BasedHardware:main Aug 4, 2026
34 checks passed
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. -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

flutter flutter work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Android: Offline sync causes incorrect conversation ordering in stream

3 participants