omi icon indicating copy to clipboard operation
omi copied to clipboard

WAL state machine: recordings marked corrupted stay pending in UI but are never retried

Open axAilotl opened this issue 7 months ago • 1 comments

Describe the bug A phone WAL that flips from WalStatus.miss to WalStatus.corrupted can become a permanent zombie recording: it still appears in the app as a pending recording, but the background uploader no longer retries it.

This is a separate issue from live reconnect gaps. It is a WAL state-machine mismatch between the UI and the retry logic.

To Reproduce

  1. Create a phone-side WAL in WalStatus.miss (for example by causing live streaming to miss audio and save a local WAL).
  2. Let the app attempt upload.
  3. Hit one of the pre-upload corrupted transitions in LocalWalSyncImpl, for example:
    • filePath == null
    • resolved file path is null
    • file missing on disk
    • unexpected exception while preparing the file for upload
  4. Refresh the sync UI / reopen the app.

Current behavior

  • The recording still appears in the UI as pending.
  • deleteAllPendingWals() also treats it as pending.
  • But background auto-upload and normal retry paths only select WalStatus.miss.
  • Result: the WAL is stranded forever unless the user manually deletes it or some other code mutates it back.

Expected behavior One of these should be true, consistently:

  • recoverable file-access errors should stay retryable and continue uploading automatically, or
  • the app should distinguish fatal/unrecoverable corruption from retryable transient errors, and only show true retryable items as pending.

Right now it does neither.

Code-backed root cause

  1. UI pending list includes corrupted. app/lib/providers/sync_provider.dart:41-42

    List<Wal> get pendingWals =>
        _allWals.where((w) => w.status == WalStatus.miss || w.status == WalStatus.corrupted || w.isSyncing).toList();
    
  2. Delete-all-pending also includes corrupted. app/lib/services/wals/local_wal_sync.dart:470-472

    final pendingWals = _wals.where((w) => w.status == WalStatus.miss || w.status == WalStatus.corrupted).toList();
    
  3. But syncAll() only retries miss. app/lib/services/wals/local_wal_sync.dart:504

    var wals = _wals.where((w) => w.status == WalStatus.miss && w.storage == WalStorage.disk).toList();
    
  4. Auto-upload also only picks miss. app/lib/providers/sync_provider.dart:158-160

    final phoneWals = _allWals
        .where((w) => w.status == WalStatus.miss && (w.storage == WalStorage.disk || w.storage == WalStorage.mem))
        .toList();
    
  5. Startup orphan recovery also only picks miss. app/lib/services/wals/local_wal_sync.dart:435-439

    .where((w) =>
        w.status == WalStatus.miss && w.storage == WalStorage.disk && w.conversationId != null && w.retryCount < 3)
    
  6. corrupted is assigned in pre-upload file preparation. app/lib/services/wals/local_wal_sync.dart:551-588

    • filePath == null
    • fullPath == null
    • !file.existsSync()
    • broad catch (e) while preparing file access

That means a WAL can move into a state that the user still sees as pending, but no retry path ever touches again.

Important distinction The upload-batch network/server failure path does not directly cause this bug. The batch upload catch keeps WALs retryable. This issue is specifically about the pre-upload corrupted transitions and the fact that corrupted is then excluded from retry paths.

Suggested fixes

  • Best fix: split corrupted into at least two states:
    • fatalMissingOrInvalid
    • retryableFileAccessError
  • Or, before retry selection, revalidate corrupted WALs and flip them back to miss when the file is actually present and readable.
  • Or, include recoverable corrupted WALs in retry queues with bounded backoff.
  • If some corrupted WALs are truly unrecoverable, give the UI a distinct non-pending state or a clear delete/ignore action instead of leaving them mixed into Pending forever.

Related issues

  • #6977 — stale BLE live-stream path can create missing-middle-audio gaps
  • #6171 — reconnect/manual-recovery UX issue
  • #5733 — umbrella capture-loss issue

user ID (can we access the user info to validate the bug?): Not included here.

Smartphone + device (please complete the following information):

  • Device: phone-side WAL path; not tied to one hardware model
  • OS: not pinned here
  • Browser: N/A
  • App Version: not pinned here
  • Device version: N/A

Additional context This is the classic "pending forever" / zombie recording symptom: visible to the user, counted as pending, but never retried by background sync.

axAilotl avatar Apr 23 '26 17:04 axAilotl

Update after more user testing and checking john-gitdev/omi:retry-sync:

For recordings that retry on app reopen, I no longer think corrupted is the primary state. Auto-upload and LocalWalSyncImpl.syncAll() only select WalStatus.miss, so a WAL that retries on reopen is almost certainly still miss.

Current best root-cause read for the retrying/phantom pending files:

  1. local_wal_sync.dart batches overlap by one file. With steps = 3, current code sets left = right - steps and then loops j <= right, so each batch contains 4 files and adjacent batches share one WAL. The retry-sync branch changes this to left = right - steps + 1, which matches the intended batch size.

  2. Upload result handling is batch-level, not per-file. If the server returns a partial failure, the app keeps every WAL in that local batch as miss, even if only one file/segment was the real failure. With the overlap bug, one bad file can repeatedly poison neighboring good files and make them appear as phantom pending/retrying recordings.

  3. Backend Opus decode currently aborts a whole file on the first bad frame decode. In backend/routers/sync.py, decode_opus_file_to_wav() catches a decode exception and breaks. The retry-sync branch changes that to continue, so a single bad frame does not kill the rest of the file. That is consistent with user reports of files existing and retrying, but not getting processed.

So I would describe the root cause for the retrying miss case as:

A single malformed/undecodable audio frame or bad file can cause server-side partial failure, and the app maps that failure back to an overlapping batch rather than the specific failed file/segment. This strands healthy WALs in miss and causes repeated retries.

This issue is still valid, but it covers a different symptom: Pending rows that are corrupted and therefore do not retry. The confusing UI state comes from pendingWals = miss || corrupted || isSyncing, while missing-duration and retry paths only count miss.

axAilotl avatar Apr 23 '26 19:04 axAilotl