Skip to content

fix(app): stop retrying a recording the server refuses for good (#10975) - #10995

Merged
kodjima33 merged 2 commits into
mainfrom
watchdog/issue-10975-sync-lookback-terminal
Aug 2, 2026
Merged

kodjima33 merged 2 commits into
mainfrom
watchdog/issue-10975-sync-lookback-terminal

Conversation

@kodjima33

@kodjima33 kodjima33 commented Aug 2, 2026 •

Copy link
Copy Markdown
Collaborator

/v2/sync-local-files answers 422 backfill_lookback_exceeded for a capture
older than SYNC_BACKFILL_MAX_AGE_SECONDS (30 days in
backend/deploy/runtime_env.yaml). uploadLocalFilesV2 had no 422 branch, so
that response fell past every case to Exception('Upload failed unexpectedly')
— a generic, retryable failure. The batch handler clears isSyncing and leaves
the WAL miss, which is exactly the state syncAll() selects from, so the
same bytes are re-offered on every sync pass forever while the row reads
"Waiting to sync" and never explains anything. Anyone draining a backlog older
than a month — the long-offline case sync exists for — pays that upload
repeatedly for a rejection that can never succeed.

Classify the bounded code at the HTTP boundary into a typed
SyncRecoveryWindowExceededException, and give the recording a terminal status
(WalStatus.outsideRecoveryWindow) that leaves the retry pool and renders its
own reason instead of an unexplained failure.

Which recordings that terminal applies to is the load-bearing part. The backend
decides the lookback from the OLDEST capture in the upload
(classify_sync_lane measures now - oldest_capture_at), and a batch mixes
ages, so a rejection only proves that one recording is out of range — retiring
the whole batch would strand recordings the server would still accept. So
_retireOutsideRecoveryWindow retires exactly the proven capture and every
recording at least as old as it, which is sound (nothing older can be inside a
window that one fell outside of) and drains a long backlog in one pass instead
of costing another doomed upload per recording. The rest of the batch stays
miss and re-forms without the poison on the next drain.

Only the sync attempt is terminal: the local audio file is kept, the row stays
visible and individually deletable, and Clear All still removes it. No Retry
affordance is offered, because a manual retry cannot succeed either.

Deliberately not addressed here: whether the 30-day cliff should exist at all
(decision 1 in #10975) — that is a product/ops call, and widening the window
later would need its own pass to re-arm recordings already marked terminal.

Second instance of FC-permanent-write-rejection-retried-forever, and the first
outside backend/database/: a rejection no retry of the same payload can
satisfy must move the row to a terminal path rather than replaying it forever.

Tested:

  • flutter test test/unit/wal_upload_resilience_test.dart — new group drives
    the production state machine through the injected uploader seam: the batch
    and single-recording paths both land on outsideRecoveryWindow, retryCount
    stays 0, getMissingWals() is empty, a second syncAll() is a no-op, the
    audio file still exists, and a generic failure still stays miss. Two cases
    pin the scoping: a mixed-age batch retires only the proven-oldest and leaves
    its newer members retryable, and a recording held out of the batch by its
    conversation grouping but older than the proven capture retires in the same
    pass. Mutating the bound to retire the whole batch fails both (+15 -2), so
    they are not tautological.
  • flutter test test/widgets/sync_row_recovery_window_test.dart — pumps the
    real WalListItem: the row renders "Too old to sync — Omi can't accept it"
    and offers no Retry, while a retry-exhausted recording still shows both
    "Failed — tap Retry" and its Retry button.
  • flutter test test/unit/sync_rate_limit_response_test.dart — the classifier
    matches both sync routes' real 422 bodies and does not widen to other 422s,
    other statuses, or unparseable bodies.
  • flutter test test/providers/sync_provider_terminal_wal_state_test.dart,
    test/unit/wal_sync_display_state_test.dart — provider partitioning and the
    display-state mapping.
  • Full suite bash test.sh: 1009 passed, 0 failed.
  • make preflight: 11/11 manifest checks pass.

Not verified against a live 30-day-old recording — that needs a real month-old
WAL against prod, which this change could not reproduce.

Fixes #10975

Failure-Class: FC-permanent-write-rejection-retried-forever

@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 111 files

Confidence score: 5/5

  • In app/lib/l10n/app_localizations_te.dart, the Telugu string uses past tense (“did not accept”) instead of persistent inability (“can’t accept”), which can mislead users about whether the action is still possible; update the translation to the present/ability form to align intent and avoid UX confusion.
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/lib/l10n/app_localizations_te.dart">

<violation number="1" location="app/lib/l10n/app_localizations_te.dart:9825">
P3: The Telugu translation 'Omi దీన్ని అంగీకరించలేదు' renders as a past-tense 'Omi did not accept this', which reads as a completed rejection rather than the intended persistent inability ('Omi can't accept it' in the English template). For the status line shown to the user, wording that conveys inability to accept would be more faithful to the template. Consider adjusting the verb to a non-past negative form.</violation>
</file>

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

Re-trigger cubic

'ఆ మైక్రోఫోన్‌కు కనెక్ట్ కాలేకపోయాము. అది iPhone సెట్టింగ్‌లలో కనెక్ట్ అయిందని నిర్ధారించుకోండి.';

@override
String get syncStatusTooOld => 'సింక్ చేయడానికి చాలా పాతది — Omi దీన్ని అంగీకరించలేదు';

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P3: The Telugu translation 'Omi దీన్ని అంగీకరించలేదు' renders as a past-tense 'Omi did not accept this', which reads as a completed rejection rather than the intended persistent inability ('Omi can't accept it' in the English template). For the status line shown to the user, wording that conveys inability to accept would be more faithful to the template. Consider adjusting the verb to a non-past negative form.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At app/lib/l10n/app_localizations_te.dart, line 9825:

<comment>The Telugu translation 'Omi దీన్ని అంగీకరించలేదు' renders as a past-tense 'Omi did not accept this', which reads as a completed rejection rather than the intended persistent inability ('Omi can't accept it' in the English template). For the status line shown to the user, wording that conveys inability to accept would be more faithful to the template. Consider adjusting the verb to a non-past negative form.</comment>

<file context>
@@ -9820,4 +9820,7 @@ class AppLocalizationsTe extends AppLocalizations {
       'ఆ మైక్రోఫోన్‌కు కనెక్ట్ కాలేకపోయాము. అది iPhone సెట్టింగ్‌లలో కనెక్ట్ అయిందని నిర్ధారించుకోండి.';
+
+  @override
+  String get syncStatusTooOld => 'సింక్ చేయడానికి చాలా పాతది — Omi దీన్ని అంగీకరించలేదు';
 }
</file context>

`/v2/sync-local-files` answers `422 backfill_lookback_exceeded` for a capture
older than `SYNC_BACKFILL_MAX_AGE_SECONDS` (30 days in
`backend/deploy/runtime_env.yaml`). `uploadLocalFilesV2` had no 422 branch, so
that response fell past every case to `Exception('Upload failed unexpectedly')`
— a generic, retryable failure. The batch handler clears `isSyncing` and leaves
the WAL `miss`, which is exactly the state `syncAll()` selects from, so the
same bytes are re-offered on every sync pass forever while the row reads
"Waiting to sync" and never explains anything. Anyone draining a backlog older
than a month — the long-offline case sync exists for — pays that upload
repeatedly for a rejection that can never succeed.

Classify the bounded `code` at the HTTP boundary into a typed
`SyncRecoveryWindowExceededException`, and give the recording a terminal status
(`WalStatus.outsideRecoveryWindow`) that leaves the retry pool and renders its
own reason instead of an unexplained failure.

Which recordings that terminal applies to is the load-bearing part. The backend
decides the lookback from the OLDEST capture in the upload
(`classify_sync_lane` measures `now - oldest_capture_at`), and a batch mixes
ages, so a rejection only proves that one recording is out of range — retiring
the whole batch would strand recordings the server would still accept. So
`_retireOutsideRecoveryWindow` retires exactly the proven capture and every
recording at least as old as it, which is sound (nothing older can be inside a
window that one fell outside of) and drains a long backlog in one pass instead
of costing another doomed upload per recording. The rest of the batch stays
`miss` and re-forms without the poison on the next drain.

Only the sync attempt is terminal: the local audio file is kept, the row stays
visible and individually deletable, and Clear All still removes it. No Retry
affordance is offered, because a manual retry cannot succeed either.

Deliberately not addressed here: whether the 30-day cliff should exist at all
(decision 1 in #10975) — that is a product/ops call, and widening the window
later would need its own pass to re-arm recordings already marked terminal.

Second instance of FC-permanent-write-rejection-retried-forever, and the first
outside `backend/database/`: a rejection no retry of the same payload can
satisfy must move the row to a terminal path rather than replaying it forever.

Tested:
- `flutter test test/unit/wal_upload_resilience_test.dart` — new group drives
  the production state machine through the injected uploader seam: the batch
  and single-recording paths both land on `outsideRecoveryWindow`, `retryCount`
  stays 0, `getMissingWals()` is empty, a second `syncAll()` is a no-op, the
  audio file still exists, and a generic failure still stays `miss`. Two cases
  pin the scoping: a mixed-age batch retires only the proven-oldest and leaves
  its newer members retryable, and a recording held out of the batch by its
  conversation grouping but older than the proven capture retires in the same
  pass. Mutating the bound to retire the whole batch fails both (+15 -2), so
  they are not tautological.
- `flutter test test/widgets/sync_row_recovery_window_test.dart` — pumps the
  real `WalListItem`: the row renders "Too old to sync — Omi can't accept it"
  and offers no Retry, while a retry-exhausted recording still shows both
  "Failed — tap Retry" and its Retry button.
- `flutter test test/unit/sync_rate_limit_response_test.dart` — the classifier
  matches both sync routes' real 422 bodies and does not widen to other 422s,
  other statuses, or unparseable bodies.
- `flutter test test/providers/sync_provider_terminal_wal_state_test.dart`,
  `test/unit/wal_sync_display_state_test.dart` — provider partitioning and the
  display-state mapping.
- Full suite `bash test.sh`: 1009 passed, 0 failed.
- `make preflight`: 11/11 manifest checks pass.

Not verified against a live 30-day-old recording — that needs a real month-old
WAL against prod, which this change could not reproduce.

Fixes #10975

Failure-Class: FC-permanent-write-rejection-retried-forever
@kodjima33
kodjima33 force-pushed the watchdog/issue-10975-sync-lookback-terminal branch from 30d47ac to 81fafb8 Compare August 2, 2026 00:55
The `backfill_lookback_exceeded` handler retires only the recordings the
rejection proves are outside the window, and deliberately leaves the batch's
newer members `miss` so they re-form into a batch without the poison. But it
returned without clearing the `isSyncing` flag those survivors were stamped
with before the upload, unlike the rate-limit and generic-failure handlers
next to it. A survivor therefore rendered as `WalSyncDisplayState.syncing` —
"Syncing…" with no end — for the rest of the session, and dropped out of
`pendingDeletableWals`, so the user could neither wait it out nor delete it.
The single-recording path had the same hole whenever the retired set came back
empty (the WAL was not `miss`+`disk`).

Tested: the existing mixed-age batch case now asserts the survivors are not
left in flight; it fails (+0 -1) without the lib hunks and passes with them.
Full suite `flutter test`: 1009 passed, 0 failed. `flutter analyze` on the
changed files: no new issues.

Failure-Class: FC-permanent-write-rejection-retried-forever
@kodjima33

Copy link
Copy Markdown
Collaborator Author

Follow-up commit `a7e573b5cb`: the backfill_lookback_exceeded handler returned without clearing isSyncing on the batch members it deliberately leaves retryable, so a survivor rendered as WalSyncDisplayState.syncing ("Syncing…", never ending) for the rest of the session and dropped out of pendingDeletableWals — neither waitable nor deletable. Same hole on the single-recording path when the retired set came back empty. Both now clear the in-flight flags, mirroring the rate-limit handler beside them.

Tested: the existing mixed-age batch case now asserts the survivors are not left in flight and fails (+0 -1) with only the lib hunks reverted; flutter test full suite 1009 passed / 0 failed; flutter analyze on the changed files clean; scripts/pr-preflight 11/11.

🤖 automated by hourly watchdog

@kodjima33
kodjima33 merged commit 8a12cfd into main Aug 2, 2026
27 checks passed
@kodjima33
kodjima33 deleted the watchdog/issue-10975-sync-lookback-terminal branch August 2, 2026 02:24
mdmohsin7 added a commit that referenced this pull request Aug 2, 2026
Four conflicts, all in the sync layer this branch rewrites:

- local_wal_sync.dart — #10995 added a SyncRecoveryWindowExceededException
  handler beside the rate-limit one. Kept both: this branch's `break` on a
  rate limit (the cooldown is account-global, so every remaining batch would
  hit it too) and main's `continue` for the recovery-window retirement, whose
  log payload drops the now-gone `lane` field.
- sync_provider.dart — main only reformatted the lane getters this branch
  deletes; took the deletion.
- sync_lane_aware_gating_test.dart — main's change was formatter reflow, and
  the file's source-scrape asserts the very lane gating this branch removes.
  Stays deleted.
- wal_upload_resilience_test.dart — kept main's settable `uploadFailure` fake
  (its new recovery-window case needs it) with this branch's uploader
  signature.

Also updated main's new sync_row_recovery_window_test.dart to the
claimLiveCapture signature.

Verified: cd app && ./test.sh -r compact -> 1014 passed
          cd app && bash scripts/analyze_ratchet.sh -> 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. -->
@undivisible undivisible added the AI label Aug 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Offline sync: a recording older than 30 days fails with no explanation and burns its retry budget

2 participants