Skip to content

[P0] Single recovery owner for recording sync: every wake trigger drains eligible WALs #9752

Closed

Description

@Git-on-my-level

Decision

Ship one self-contained Flutter PR that gives recording sync a single recovery owner: every wake trigger (startup, foreground, connectivity restored, device connected, cooldown elapsed, user retry) routes through one singleflight coordinator that reconciles and drains eligible WALs.

No backend changes. No protocol changes. No new identity. No flags, shadow mode, or rollout gates — the behavior is client-local and deterministic, so it ships enforced, covered by a hermetic fault harness that runs in app/test.sh forever.

This directly fixes the dominant live failure: recoverable audio sits on the phone until an unrelated event (usually a Bluetooth reconnect) accidentally wakes the right code path (#7373, #9471, the stranded-backlog half of #7240).

Root cause (verified in current code)

Recovery triggers are scattered, and each covers only a slice:

  • app/lib/services/capture/capture_controller.dart — onConnectionStateChanged (line ~2184) retries orphan recovery only if the startup pass was skipped while offline (_orphanRecoveryDone guard). A connectivity recovery after a successful startup pass triggers nothing. Orphan recovery itself covers only orphaned WALs, not a general drain.
  • app/lib/services/wals/sync_reconciler.dart — SyncReconciler.poke() resolves only uploaded WALs (job polling), on a foreground-only timer.
  • app/lib/providers/sync_provider.dart — syncWals() (line ~459) is the general drain, but it is user/UI-triggered; the auto-sync path (line ~381, gated on SharedPreferencesUtil().autoSyncOfflineRecordings) fires from its own call sites.

No component owns the contract "when the world changes in our favor, eligible WALs drain." That is the bug class behind #7373 and #9471 — not a retry bug, an ownership hole.

The change

1. Add RecordingTransferCoordinator

New file: app/lib/services/wals/recording_transfer_coordinator.dart.

enum WakeTrigger { startup, foregrounded, connectivityRestored, deviceConnected, cooldownElapsed, userRetry }

One public entrypoint: Future<void> wake(WakeTrigger trigger).

Required semantics (these are the contract — implement exactly):

  1. Singleflight. At most one drain pass runs at a time. A wake() arriving during a pass sets a pending bit; the pass re-runs once after completing. N concurrent wakes → at most 2 passes, never parallel drains.
  2. Reconcile before offering bytes. Each pass first resolves uploaded WALs via the existing SyncReconciler path, then drains eligible (miss/retryable) WALs via the existing syncAll path. Never re-upload a WAL whose job is still resolving.
  3. Failure is retryable, never silent, never synced. A failed pass returns WALs to their retryable state (existing local_wal_sync.dart semantics — do not change them) and schedules a cooldownElapsed wake with backoff. It must never surface a synced UI state.
  4. Auto-sync preference gates upload only. With autoSyncOfflineRecordings off, a wake still runs discovery/reconciliation and reports truthful pending state; it uploads nothing automatically. userRetry uploads regardless.
  5. Foreground-only by design. No Dart background timers. iOS/Android background execution is explicitly out of scope (bug: Background sync stalls on iOS when screen is off — 1000+ files queue #7221 stays open; this PR does not close it).

Constructor takes injectable seams — connectivity stream, clock, and the reconcile/drain functions — so the test harness runs the production coordinator with fake transport and time. No string-tripwire tests.

2. Rewire every trigger through it

Replace the scattered logic with one-line coordinator.wake(...) calls:

  • App startup (after WAL service init, where recoverOrphanedWals is invoked today) → wake(startup).
  • ConnectivityService().onConnectionChange false→true (in capture_controller.dart) → wake(connectivityRestored) — unconditionally, deleting the _orphanRecoveryDone guard as a recovery gate.
  • Foreground/resume (where SyncReconciler.onForeground() is called) → wake(foregrounded).
  • Device connect / device inventory change → wake(deviceConnected).
  • User-initiated retry in sync_provider.dart → wake(userRetry).

SyncProvider keeps presentation (progress, counts, UI state) but stops being a recovery trigger owner.

3. What must NOT change

  • WAL states (inProgress, miss, uploaded, synced, corrupted) and their meaning in wal.dart.
  • Upload/ack semantics in local_wal_sync.dart (202 stores job id, only terminal completed acknowledges).
  • SyncReconciler's job-polling behavior (it becomes a callee of the coordinator, not a peer trigger).
  • No new user-facing strings (no l10n changes), no backend or API changes, no new persistence except the retry-cooldown timestamp if needed.

Out of scope (do not expand this PR)

Recording-session UUIDs, receipt levels, capture-manifest/ledger extensions, a durable reconciliation endpoint, last-copy retention changes, UI label redesign, and OS-owned background execution. If any of these prove worth doing, write a new issue against the then-current code. #7221 remains open.

Required tests

New file: app/test/services/wals/recording_transfer_coordinator_test.dart. All hermetic (fake connectivity stream, fake clock, fake drain/reconcile seams around the real coordinator), all discovered by app/test.sh.

# Case Asserts
1 Connectivity restored, no Bluetooth event drain pass starts from connectivityRestored alone (the #7373 regression test)
2 Connectivity restored after a successful startup pass drain still starts (kills the _orphanRecoveryDone guard bug)
3 5 concurrent wakes during an in-flight pass exactly 1 additional pass, never parallel
4 Drain fails mid-pass WALs retryable, no synced state, cooldownElapsed wake scheduled with backoff
5 Restart with pending backlog startup wake resumes the drain; no WAL skipped or drained twice
6 autoSyncOfflineRecordings off wake reconciles + reports pending truthfully, uploads nothing; userRetry still uploads
7 Wake during reconcile of uploaded WALs those WALs are not re-offered for upload

Each acceptance checkbox below names its test. A criterion without a passing named test is not met.

Real-path verification (attach evidence to the PR)

With a physical Omi device and a dev app build:

  1. Start a recording, enable airplane mode mid-capture, confirm WAL goes local-durable.
  2. Disable airplane mode without touching Bluetooth; confirm from logs that a connectivityRestored wake fires and the drain starts within one pass.
  3. Kill and relaunch the app with a pending backlog; confirm startup wake resumes the drain to synced.

Record commands, log lines, and WAL/job ids in the PR description per the Definition of Done.

Acceptance criteria

Related issues

Activity

  1. added
    p0
    maintainer
    capture
    on Jul 14, 2026
  2. changed the title [-][P0] End-to-end recording trust contract: durable receipts, recovery, and fault harness[/-] [+][P0] Single recovery owner for recording sync: every wake trigger drains eligible WALs[/+] on Jul 14, 2026
  3. added a commit that references this issue on Jul 15, 2026
    e180476
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    capturemaintainerp0

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions