Skip to content

fix: make live capture uploads durable and self-healing - #19199

Merged
Git-on-my-level merged 12 commits into
BasedHardware:mainfrom
Git-on-my-level:fix/silent-upload-death
Sep 26, 2026
Merged

Git-on-my-level merged 12 commits into
BasedHardware:mainfrom
Git-on-my-level:fix/silent-upload-death

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Sep 26, 2026 •

Copy link
Copy Markdown
Member

fix: make live capture uploads durable and self-healing

What changed and why

Make pendant capture durable until transcript confirmation, recover WAL delivery in bounded background passes, and surface prolonged upload/transcript silence instead of treating socket reachability as delivery. Add server-side reconciliation and observability so abandoned in_progress rows are finalized independently of a live listen session and empty/discarded rows stay out of default conversation lists.

Product invariants affected

  • INV-TASK-2: the kept-conversation title fallback does not change task candidate or acceptance authority.
  • INV-MEM-4: the finalization fallback and zombie reconciler reuse the existing conversation processing path and do not introduce a memory writer or promotion route.

Line-Count-Exception: app/lib/services/capture/capture_controller.dart | 3753 -> 3807 | capture session ownership must retain the transcript-confirmed WAL lifecycle, connected-socket byte watchdog, and reconnect repair handoff at the existing socket/event owner
Line-Count-Exception: app/lib/services/wals/local_wal_sync.dart | 1437 -> 1572 | the phone WAL owner must enforce bounded retention, ID-less live-drain eligibility, and terminal upload refusal state at the existing persistence and upload boundary
Line-Count-Exception: backend/database/conversation_finalization_jobs.py | 2462 -> 2512 | server-recovery admission must read the active recording-session lease inside the existing atomic finalization-intent transaction
Line-Count-Exception: backend/utils/conversations/process_conversation.py | 3335 -> 3360 | the kept-versus-discarded verdict and deterministic title fallback must remain atomic at the existing final conversation assembly boundary

Capability changes

  1. No data loss while connected: pendant Opus frames remain in the phone WAL even while the listen socket is connected. Socket writes are no longer delivery acknowledgements; safety WALs are pruned only after a transcript-bearing conversation result, and interrupted sessions wake a repair drain.
  2. Background drain: the transfer coordinator permits bounded connectivity, socket-reconnect, and data-stall passes while backgrounded. Those passes skip device discovery, upload recent phone WALs even before lifecycle ID stamping, and use an iOS UIApplication background-task lease; Android keeps its existing foreground-service lease.
  3. Retry-budget self-heal: connectivity restoration resets exhausted retry budgets for transient disk WALs before the next drain.
  4. Server zombie GC: API startup and the existing five-minute reconciliation loop run the bounded, CAS-fenced self-heal primitive in heal mode for all UIDs when durable listen finalization is enabled. This reuses existing admission/refusal checks and needs no schema or index migration.
  5. Discarded/empty rows: v1 and legacy Flutter list defaults now exclude discarded rows, explicit inclusion remains supported, and kept completed conversations receive a deterministic title when structure generation returns none.
  6. Truthful surfacing: capture health distinguishes bytes sent from transcript observed, detects repeated bytes-without-transcript sessions and local WAL backlog older than two hours with no upload progress, emits shared analytics, shows a persistent existing-style banner, and gives the banner a transfer retry action.
  7. Server observability: every managed listen teardown still increments the bounded aggregate outcome metric; zero-transcript outcomes now also emit a per-UID product event with bounded source/platform dimensions and recording correlation.

Review fixes

  • CI integration fixes: WAL display-state coverage now treats B5 uploadRejected alongside the pre-existing terminal statuses when a stale syncing flag remains set, while non-terminal statuses retain syncing precedence. The trust-boundary callee inventory now pins the reviewed read-only active-recording-session lease lookup; all conversation writes remain routed through _apply_snapshot_bound_projection.
  • B1 — RESOLVED after r2 partial — bounded WAL retention: all phone-local unsynced safety copies are capped together at 720 minute-sized WALs (about twelve hours), including live, logged-out/retired, and foreign-account buckets. At the cap, the oldest retained WAL is evicted before newer audio is admitted; logout/account-switch churn coverage proves no durable bucket can bypass the cap.
  • B2 — ID-less background drain: recency, not conversation-ID stamping, controls live-capture drain eligibility. A recent ID-less WAL uploads after a background connectivity wake and does not claim an existing conversation manifest.
  • B3 — connected-socket watchdog: every socket send reports its byte count to a periodic two-minute bytes-since-last-transcript watchdog. A socket that remains connected indefinitely now triggers the bytes_sent_no_transcript telemetry, transfer retry, and persistent warning without waiting for close.
  • B4 — RESOLVED after r2 partial — live-session recovery fence: every accepted decoded frame reaches the one-minute-throttled lease renewal path, so a ten-minute session keeps its five-minute lease current. Session opening writes the recording-session binding and conversation marker in one Firestore transaction; SERVER_RECOVERY reads that identity-bound lease in its admission transaction and refuses an unexpired in_progress owner.
  • B5 — RESOLVED after r2 partial — HTTP refusal retries: only 400, 403, and 413 move WALs to terminal uploadRejected; 401 remains retryable and a reset after re-login makes it automatically eligible again. Manual syncWal() honors an explicit retry for every terminal WAL state, while automatic connectivity wakes continue to leave permanent refusals parked and user-reviewable.
  • B6 — metric compatibility revert: restored OMI_AUDIO_TIMELINE_REJECTS_TOTAL, per-segment rejected increments, and the deleted round-4 compatibility assertion. Existing series semantics are unchanged.
  • B7 — iOS lease expiration: native background-task expiration and .invalid task creation notify Dart. Dart clears its refcount, so the next acquire() creates a fresh native lease; a standalone Swift state-machine test and Dart pairing tests cover both paths.
  • SF8 — bounded zero-transcript telemetry: per-UID Listen Socket Zero Transcript events coalesce for five minutes, use a 16-hex SHA-256 recording correlation, and keep at most 10,000 UID entries. The aggregate Prometheus outcome counter increments before coalescing and remains authoritative.

How it was verified

  • backend/.venv/bin/python -m pytest backend/tests/unit/test_release_probe_discard_gate.py — 6 passed, exit 0.
  • backend/.venv/bin/python -m pytest backend/tests/unit/test_conversations_status_filter_cap.py backend/tests/unit/test_live_session_transcript_outcome.py backend/tests/unit/test_selfheal_sweep.py backend/tests/unit/test_stale_processing_periodic_scheduling.py — 58 passed, exit 0.
  • /Users/dazheng/.local/share/mise/installs/flutter/3.44.5/bin/flutter test test/backend/http/conversations_default_filter_test.dart test/providers/sync_provider_sync_wal_wake_test.dart test/services/capture/capture_wedge_monitor_test.dart test/services/wals/recording_transfer_coordinator_test.dart test/services/wals/sync_transfer_keep_alive_test.dart — 78 passed, exit 0.
  • /Users/dazheng/.local/share/mise/installs/flutter/3.44.5/bin/flutter test test/services/capture/capture_coordinator_test.dart test/unit/local_wal_sync_test.dart test/unit/wal_recovery_test.dart test/widgets/capture_recovery_banner_test.dart — 139 passed, exit 0.
  • xcrun swiftc -parse app/ios/Runner/AppDelegate.swift — exit 0.
  • /Users/dazheng/.local/share/mise/installs/flutter/3.44.5/bin/dart format --line-length 120 <touched Dart files> and /Users/dazheng/.local/bin/black --line-length 120 --skip-string-normalization <touched Python files> — clean, exit 0.
  • scripts/pr-preflight --pr-body-file PR_BODY.md — 48 selected checks passed in 138.59s, exit 0.
  • backend/.venv/bin/python -m pytest backend/tests/unit/test_selfheal_recovery.py backend/tests/unit/test_recording_sessions.py backend/tests/unit/test_live_session_transcript_outcome.py — 89 passed, exit 0.
  • backend/.venv/bin/python -m pytest backend/tests/unit/test_audio_timeline_round4.py — 8 passed, exit 0.
  • /Users/dazheng/.local/share/mise/installs/flutter/3.44.5/bin/flutter test test/unit/local_wal_sync_test.dart test/unit/wal_upload_resilience_test.dart test/services/capture/capture_wedge_monitor_test.dart test/widgets/capture_recovery_banner_test.dart — 109 passed, exit 0.
  • /Users/dazheng/.local/share/mise/installs/flutter/3.44.5/bin/flutter test test/services/wals/sync_transfer_keep_alive_test.dart — 7 passed, exit 0.
  • ruby ios/test/sync_transfer_background_lease_test.rb — 1 test, 2 assertions, exit 0.
  • xcodebuild -list -project app/ios/Runner.xcodeproj — project parsed and both app targets include the lease source, exit 0.
  • backend/.venv/bin/python -m pytest backend/tests/unit/test_stale_processing_emulator_concurrency.py — 8 skipped locally because FIRESTORE_EMULATOR_HOST is absent; the live-lease and session-creation/recovery races are wired into the emulator gauntlet.
  • cd app && mise exec -- flutter test test/unit/local_wal_sync_owner_uid_test.dart test/unit/local_wal_sync_test.dart — 41 passed, exit 0.
  • cd backend && ./.venv/bin/python -m pytest tests/unit/test_recording_sessions.py tests/unit/test_listen_receiver_opus_frame_capacity.py tests/unit/test_listen_multichannel_mix_buffer_leak.py tests/unit/test_listen_reconnect_continuity.py tests/unit/test_listen_process_pending_shutdown.py tests/unit/test_conversation_finalization_jobs.py tests/unit/test_stale_processing_emulator_concurrency.py — 125 passed, 8 emulator-only skipped, exit 0.
  • cd app && mise exec -- flutter test test/unit/wal_upload_resilience_test.dart test/unit/local_wal_sync_test.dart test/unit/wal_unsupported_audio_terminal_test.dart test/providers/sync_provider_terminal_wal_state_test.dart — 67 passed, exit 0.

The requested ~/workspace/omi/backend/.venv/bin/python interpreter is not present on this host, so backend tests used the equivalent worktree-local backend/.venv/bin/python. No live service was called, and no device/native runtime acceptance was attempted.

Tests

  • Connected pendant socket frames remain durable and transcript confirmation is the only prune condition.
  • Interrupted sessions, socket reconnect, data-stall, connectivity restore, retry reset, background live-only drain, and iOS lease pairing are covered hermetically.
  • Upload-silence and bytes-sent-without-transcript episodes assert telemetry, persistence, resolution, and retry behavior.
  • Conversation list defaults, deterministic kept-title fallback, explicit discard behavior, zero-transcript per-UID telemetry, unrestricted periodic zombie reconciliation, and periodic scheduling are covered by backend unit tests.

Failure class (fixes)

Failure-Class: FC-accepted-session-completes-silently-without-payload
Line-Count-Exception: backend/routers/listen/receiver.py | 1617 -> 1627 | per-UID zero-transcript telemetry coalescing and throttled live-session lease renewal must live with the accepted-socket outcome owner

@Git-on-my-level
Git-on-my-level marked this pull request as ready for review September 26, 2026 16:55
@Git-on-my-level
Git-on-my-level merged commit d949aae into BasedHardware:main Sep 26, 2026
47 of 49 checks passed
Git-on-my-level added a commit that referenced this pull request Sep 30, 2026
…#19921)

## What changed and why

This raises the production `conversation-finalization` Cloud Tasks queue
from 4 to 16 `max-concurrent-dispatches` in `deploy-backend-stack`, and
updates `backend/docs/listen_finalization_jobs.mdx` to match. No test
pins the value 4.

Since #19199 (deployed on backend-sync revision `a90b225`, 2026-09-26
~17Z), every listen finalization and every self-heal `SERVER_RECOVERY`
job has gone through this queue to `POST
/v1/conversation-finalization-jobs/run` on backend-sync. Before that the
queue saw about 10 attempts per 3 hours. Since then it sees 5–10k per 3
hours. At 4 concurrent dispatches it is saturated. Measured in Cloud
Monitoring (`cloudtasks.googleapis.com/queue/*`, queue
`conversation-finalization`):

| window | queue depth (6h max) | task_attempt_delays p50 | p99 |
| --- | --- | --- | --- |
| 09-24 to 09-26 14Z | 0–3 | 0 s | ≤16 s |
| 09-26 20Z to 09-30 08Z | 248–728 | 211–380 s | ~521 s |

The replay reconciler (`claim_finalization_replay`) re-mints a queued
job's dispatch generation once it has been queued for more than
`LISTEN_FINALIZATION_RECONCILE_STALE_SECONDS` (default 300 s). A median
queue delay of ~370 s is longer than that window, so most jobs are
re-enqueued before their first task runs. The original task is then
acked as `stale_generation`. In 2026-09-29 12Z backend-sync logs there
were 3,190 finalization requests: 1,690 stale-generation acks, 1,010
completions and 475 recovery terminals. About half the dispatch capacity
was spent acknowledging duplicates, and every user conversation waited
about 6 minutes before finalization started.

16 dispatches leave headroom for the current load of about 0.9
requests/s with a mean handler time of about 5 s. The handler is
I/O-bound, and backend-sync keeps at least 5 instances at concurrency
20.

## Rollout

The live queue was raised to 16 by an operator on 2026-09-30. Until this
merges, every full prod deploy resets it to 4. The value is applied only
by a full prod backend deploy (`deploy_targets == 'all'`). To take
effect before that, an operator can run `gcloud tasks queues update
conversation-finalization --location=us-central1
--project=based-hardware --max-concurrent-dispatches=16`. After the
change, check that `task_attempt_delays` p50 falls below 300 s and that
stale-generation acks stop.

## Product invariants affected

none

## Failure class (fixes)

Failure-Class: none

## Verification

- Config-only change to the composite action's `gcloud tasks queues
update/create` arguments. No expression contexts changed.
- `scripts/pr-preflight` for this branch.

🤖 Generated with [Claude Code](https://claude.com/claude-code)


<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/BasedHardware/omi/pull/19921?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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant