Skip to content

fix(sync): end the endless record_capture_pending retry for final records - #25770

Open
Git-on-my-level wants to merge 3 commits into
mainfrom
lane/upload-retry-loop
Open

Git-on-my-level wants to merge 3 commits into
mainfrom
lane/upload-retry-loop

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

DESIGN

Reads: no new reads. The sync route's existing provenance read (one conversation document, field-masked) now also projects record_audio_closed, record_audio_partial, record_sealed_at, record_seal_refused_at and record_upload_sessions. The read count stays the same. The payload grows by those fields: record_upload_sessions is a map of up to 128 sessions, but it is normally empty on a closed record. Every other input (intakes/bp_<content>, jobs, artifacts, the coverage memo) is already read today.

Writes: none new. The change adds no Firestore, GCS or Redis writes and no custody write.

  • The terminal path writes nothing to the store while RECORD_TOKEN_LEASE_MODE=off (prod), which the test asserts.
  • The existing rearm_partial wake still runs before the answer on a memo-first hit, unchanged. It writes only when the token lease is serving.
  • The coverage memo write on a miss is unchanged.

Behavior (conservative split, coordinator decision): an unproven coverage answer (a fresh negative or a memo hit) returns HTTP 400 {"code":"record_capture_unprovable","retryable":false} instead of the retryable 503 record_capture_pending only when both of these hold:

  • the cause is audio_bytes_differ, meaning the record holds audio at every instant of the WAL and only the bytes disagree. After the first mismatch the coverage walk continues on time alone, so a WAL that also reaches outside or past the record reports that cause instead;
  • the record is final.

wal_audio_past_record, wal_audio_outside_record, record_unit_exhausted and unknown causes keep the 503, because the server may not hold that audio.

  • A record is final when it is closed and sealed, is not partial, has no record_upload_sessions, no record_seal_refused_at and is not deleted, and both finished_at and the last record_sealed_at are at least 6 h old.
  • Every other case keeps the 503. That includes coverage-check errors, records that can still change and unreadable clocks.
  • The coverage memo stores the cause instead of 1, so a memo hit answers the same way. It is the same Redis key, TTL and write count. A legacy 1 reads as an unknown cause (503), and the previous revision reads a cause value as a miss. The mixed window is bounded by the 300 s TTL.

Expected rates. The baseline was read with ro-prod on 2026-11-19:

  • Unsampled request log, 07:42–07:52Z: POST /v2/sync-local-files on backend-sync answered 503 = 10,239, 409 = 291 and 400 = 13.
  • audio_coverage_unproven is ~94% of the 503s. In the 10% sampled app log there were 941 such lines out of 1,005 record waits.
  • Of the looping records, 70% are already final under this rule (1,099 of the 1,569 rows read).
  • Expected drop: about 0.94 (unproven share) × 0.65 (audio_bytes_differ) ≈ 61% of the 503s if every such record were final. Only about 70% of looping records are final today, so the expected drop is about 0.61 × 0.70 ≈ 43%. That is about 4,400 fewer per 10 min, leaving about 5,800 of 10,239. Records that cross the 6 h line later keep adding to the drop. The new time-only walk can move some former audio_bytes_differ WALs into wal_audio_past_record, which would make the drop slightly smaller.
  • The 400s rise briefly, by about 1 + N for each looping N-file batch (the client isolates a refused batch and re-sends each file once), then decay. Each refused WAL is re-offered at most once a day for 7 days.
  • No paid work, GPU or STT changes. Firestore and Redis cost is unchanged.
  • Storage reads (panel F1, accepted): a fresh coverage miss with differing bytes no longer stops at the first mismatch. It keeps walking the record units that overlap the WAL, so it can tell audio_bytes_differ from past/outside.
    • Cost: one GCS artifact read plus PCM decode per extra overlapping unit, about 0–2 per miss for a 300 s WAL.
    • Volume: fresh misses are about 2.7k per 10 min (2,667 sampled per hour × 10 ÷ 6), and each WAL is memoized for 300 s, so that is at most a few thousand extra GCS reads per 10 min. That is negligible against the 503 requests this removes.
    • Watch it in backend-sync GCS read ops and request latency after deploy.

Production number that proves it: the unsampled backend-sync request-log count of 503 on POST /v2/sync-local-files per 10 min, which the omi_pipeline_upload_admission_503 log metric also tracks. The target is ≤ 6,500 per 10 min within 2 h of serving (expected about 5,800), against 10,239 before. outcome=terminal cause=audio_bytes_differ lines must be present. The sampled outcome=pending reason=audio_coverage_unproven lines should fall by roughly 45% while wal_audio_past_record and wal_audio_outside_record coverage lines stay at about their current level. event=sync_record_upload outcome=terminal lines must be present. The 400 count must decay after the first day.

  • Stop condition: any 200 or 202 release attributable to this path (by construction it has none), or a rise in sync 5xx.
  • Rollback: SYNC_RECORD_COVERAGE_TERMINAL=false.

Problem

The registered-record WAL fence (backend/utils/batch_pipeline/live_upload.py) returned a retryable 503 record_capture_pending for every WAL whose audio it could not prove byte-for-byte against the record. The phone keeps the audio and retries every 30 s. Nothing is lost, but the request storm never ends and the app shows uploads waiting forever.

Measurement (ro-prod, counts and hashed record keys only)

503 per 10 min (unsampled, 07:42–07:52Z) 10,239
record waits, 1 h, 10% sample 6,509: audio_coverage_unproven 6,040 (memo hit 3,373 / miss 2,667), coverage_check_failed 188, record_jobs_missing 143, owner_context_mismatch 130, content_receipt_conflict 8; record_router_missing (intake.py:702) 0
coverage cause (sampled) audio_bytes_differ 65%, wal_audio_past_record 20%, wal_audio_outside_record 15%
distinct looping recordings (1 h sample) 2,352 coverage, 55 jobs-missing, 14 check-failed
record state (2,351 joined via intakes/bp_<key>) 100% completed + record_audio_closed; 0 partial; 83% sealed; 146 discarded; 0 deleted
recording age <1 h 29, 1–6 h 301, 6–24 h 1,042, 1–3 d 461, 3–7 d 241, 7–14 d 239, 14–30 d 38
final under this rule (sealed, settled ≥ 6 h) 70% (1,099 / 1,569 read); ≥ 24 h: 24%

Root cause

  • _covered (live_upload.py, def _covered) compares decoded WAL PCM byte-for-byte with the record's pinned units. Its inputs are the WAL bytes, the job list from intakes/bp_<content>.segment_ids (the read transaction in registered_record_response) and the immutable artifacts.
  • For a sealed, settled record none of those inputs change, so the negative is permanent. Every negative still went to _pending(AUDIO_COVERAGE_UNPROVEN), the retryable 503 at the three AUDIO_COVERAGE_UNPROVEN returns.
  • The 2026-11-11 coverage memo only skips recomputing that negative. It returns the same 503, which is why it did not end the loop.
  • About 65% of the negatives are audio_bytes_differ: independently decoded Opus versus the record's PCM, which the 2026-11-15 handoff note already says cannot compare byte-for-byte.

Why a keep-local 400 and not a release

I checked the shipped app at origin/main app/lib and its history from August through October:

Response App behavior
200, or a 202 whose job completes Releases the WAL. That is safe only when coverage is proven, and here it is not.
400 (current builds) Definitive refusal. The WAL is kept and marked refused, gets no user attention and no Retry, and is re-offered at most daily for 7 days.
400 (mid-October builds) markUploadRejected. The WAL is kept.
400 (August and September builds) Generic error. The WAL is kept pending under the retry budget.
5xx record_capture_pending 30 s per-recording defer, forever.

No build deletes audio on a 400.

I rejected the other options from the brief:

  • "Admit through normal sync": it would start a second GPU/STT job for a record. That breaks this module's one-job invariant, and for the 65% audio_bytes_differ case it would mostly duplicate transcript the record already has.
  • "Gap-fill / retained-ack / WAL handoff": these are the designed custody paths, but they are dark in prod (RECORD_GAP_FILL unset, RECORD_TOKEN_LEASE_MODE=off, RECORD_WAL_HANDOFF_ENABLED=false). Ramping them is a release decision. If they ramp later, any refused WAL whose proof arrives is still accepted on a daily re-offer within the 7 days.

Follow-up (separate change): audio the record lacks

wal_audio_past_record (20%) and wal_audio_outside_record (15%) were about 35% of the sampled coverage negatives. That is roughly 2,100 of 6,040 sampled lines per hour, or about 3,400 of the 10,239 503s per 10 min.

  • In these WALs the phone holds audio the final record lacks, so they keep the retryable 503. A terminal answer would let phones stop re-offering the only copy after 7 days.
  • They need a gap-fill or WAL-handoff path that can admit them. RECORD_GAP_FILL, RECORD_TOKEN_LEASE_MODE and RECORD_WAL_HANDOFF_ENABLED are all off in prod today.
  • Ages: the looping records as a whole started <1 h: 29, 1–6 h: 301, 6–24 h: 1,042, 1–3 d: 461, 3–7 d: 241, 7–14 d: 239, 14–30 d: 38 ago, out of 2,351. I did not split ages by cause: the cause log line carries no record key, and the memo now stores it.
  • When gap fill ramps, update the RECORD_GAP_FILL_PERCENT ramp row and its 2026-11-07 note: they still say _covered, which this PR renamed to _coverage_gap (panel review-20261119t104804-09ff F2).
  • After deploy, the cause= on event=sync_record_coverage plus the remaining reason=audio_coverage_unproven waits measure this backlog.

Change

  • live_upload._coverage_gap returns the static cause (_covered is now a thin wrapper around it). coverage_final(row) and _coverage_unproven(..., cause=) give the terminal 400 only for audio_bytes_differ on final records, on all three coverage-negative returns: memo-first hit, late memo hit and fresh miss. The memo (database/sync_record_wait_cache.py) stores the cause. The 503 stays everywhere else.
  • fsr_metadata.PROVENANCE_FIELDS projects the record finality markers. Before this, the field-masked loaded row lacked them, so the router could not see finality.
    • Side effect: retain_upload and rearm_partial can now see record_audio_closed on this path. Both are no-ops in prod while RECORD_TOKEN_LEASE_MODE=off.
  • Kill switch SYNC_RECORD_COVERAGE_TERMINAL (ops_kill, default true) is registered in the runtime env, charts, flag budget, flag registry and deployment classification.
  • Counter omi_pipeline_record_coverage_terminal_total{cause,memo} is declared in the metric inventory. Terminal answers are not counted in omi_pipeline_record_wait_answers_total or omi_pipeline_record_wait_memo_hits_total, so read those together with the new counter. New log line: event=sync_record_upload outcome=terminal reason=audio_coverage_unproven cause=audio_bytes_differ record=<16 hex> path=coverage memo=….
  • The contract paragraph in listen_pusher_pipeline.mdx is updated, with a change note at changes/2026-11-19-record-coverage-terminal.md.

Tests

  • New backend/tests/unit/test_sync_record_coverage_terminal.py, synthetic data only:
    • a terminal 400 on both memo hit and miss, with no store writes, the counter incremented and a hashed log line;
    • 11 still-changing or unreadable row shapes that keep the 503;
    • the kill switch;
    • a transient check failure that stays 503;
    • proven coverage that still returns the record's 202;
    • datetime and epoch clocks;
    • the projection fields.
    • one test per cause: audio_bytes_differ is terminal; wal_audio_past_record, wal_audio_outside_record, record_unit_exhausted and unknown stay 503, on both memo hit and miss;
    • differing bytes that also reach past or outside the record are classified past/outside;
    • the memo round-trips the cause, and a legacy 1 reads as unknown;
    • the late memo-hit and memo=off returns also answering 400;
    • non-finite and unrepresentable clocks staying 503.
  • Ran through bin/omi-heavy, all passing: the 21 test files that reference the changed modules, plus the flag budget, runtime env validator, pusher config references and scripts/check_feature_flag_registry.py.
  • The --changed selector picked 2,092 files because utils/metrics.py is imported everywhere. I stopped it after 249 passing files with no failure and left the full selection to CI.

Product invariants affected

  • INV-MEM-4: a path-glob match only. This change affects only the WAL upload admission answer. It creates no memory intake, promotion or consolidation route.

Failure-Class: new

🤖 Generated with Claude Code

…ords

A registered record's WAL coverage proof (live_upload._covered) is a pure
function of the WAL bytes, the record's job list and their pinned
artifacts. Once the record is closed and sealed and has settled, every retry
gets the same negative, yet the answer stayed the retryable 503
record_capture_pending, so phones re-sent the same WAL every 30 s forever.
On 2026-11-19 that was ~10.2k 503s per 10 min on POST /v2/sync-local-files,
~94% audio_coverage_unproven, over ~2.35k recordings, all completed and
closed and 70% sealed and unchanged for 6 h or more.

When coverage is unproven (fresh or memo hit) and the record is final
(closed, sealed, not partial, no upload session or seal refusal, not deleted,
finished_at and record_sealed_at both >= 6 h old), answer HTTP 400
record_capture_unprovable (retryable: false). Every shipped app keeps the
WAL on a 400 (refused, no attention, re-offered at most daily for seven
days); none deletes or releases audio on it. Coverage-check errors and
records that can still change keep the 503.

The sync route's provenance projection now carries the record finality
markers so the router sees them on the same single document read.

Kill switch SYNC_RECORD_COVERAGE_TERMINAL (default true); false restores
the 503. Counter omi_pipeline_record_coverage_terminal_total{memo} and log
event=sync_record_upload outcome=terminal.

Failure-Class: new

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-19T10:52:04.584283Z fc2f1fc New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Git-on-my-level and others added 2 commits November 19, 2026 16:27
Panel review-20261119t090057-6d55 follow-ups:
- Non-finite or unrepresentable stored clocks are never final (keep 503).
- Pin the late memo-hit and memo=off coverage returns to the terminal 400.
- Document that past/outside-record audio stays on the phone as a refused
  upload (recoverable only inside the seven-day re-offer window or by an app
  build), that terminal answers leave the wait counters, and the 1 + N 400s
  of an isolated batch.
- Keep the flag budget alphabetical.

Failure-Class: FC-final-record-coverage-negative-retried-forever

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Coordinator decision on #25770 (conservative split): answer the terminal
keep-local 400 record_capture_unprovable only for audio_bytes_differ on a
final record. That cause now means the record holds audio at every instant
of the WAL; after the first mismatch the coverage walk continues on time
alone, so a WAL that also reaches past or outside the record reports that
cause. wal_audio_past_record, wal_audio_outside_record,
record_unit_exhausted and unknown causes keep the retryable 503, because the
server may not hold that audio; admitting it is a separate gap-fill or
handoff follow-up.

The coverage memo stores the static cause instead of 1 so memo hits answer
the same way. A legacy 1 reads as unknown (503); the previous revision reads
a cause as a miss. The terminal counter and log line carry cause=.

Failure-Class: FC-final-record-coverage-negative-retried-forever

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Git-on-my-level

Copy link
Copy Markdown
Member Author

I’m leaving this PR for the sync custody owner. It replaces a retryable coverage response with a terminal keep-local refusal in the same registered-record admission path as #25444 and changes the response handled by #25868. It also continues fetching and decoding record units after a byte mismatch, even with terminal handling switched off. The 24-file change needs a custody and cost review before it can be treated as a small fix. No flag change is needed for this complaint pass.

@Git-on-my-level

Copy link
Copy Markdown
Member Author

When this PR returns to the merge queue, please update its branch against current main and let backend CI run on the refreshed PR. Link the fresh test_pipeline_env_surface_holds_its_budget pass and the tested head or merge SHA in the merge handoff. The November 30 budget audit found overdue entries in this PR’s older GitHub merge ref, so the previous CI run does not establish coverage for the refreshed base.

Quality tracking and merge-ref audit

aryanorastar added a commit that referenced this pull request Nov 27, 2026
## What changed and why

The backend can send a 1,800-second `record_capture_pending` wait after
a cached negative audio-coverage check (#26333). The mobile upload gate
capped all recording waits at 300 seconds, so affected recordings could
retry early even after an app restart.

Honor typed recording waits up to 30 minutes. Preserve the five-minute
cap for header fallback and local backoff. Each wait remains scoped to
the recording session. The existing receipt path still controls when a
local recording can be released.

Related: #21216, #25770, #26333.

## Product invariants affected

- **INV-CAP-1** — the wait changes retry timing only. The affected file
remains readable and pending throughout the deferral, with the existing
server receipt still required for release.

## How it was verified

- The restart regression failed before the patch. The queue issued
another request at six minutes despite a 30-minute response.
- 81 focused Flutter tests passed. The updated loopback HTTP test
separately passed with the full 1,800-second response.
- The backend coverage-wait suite passed 27 tests, including the
1,800-second response.
- Analyzer ratchet and all 27 local preflight checks passed.
- Independent review checked the bounds, persisted values, and unchanged
custody logic.
- Production coverage and historical recording recovery require separate
verification.

## Tests

- `recording_wait_deferrals_test.dart` checks typed and header limits,
default waits, and short backoff.
- `wal_upload_resilience_test.dart` checks a restarted queue, a sibling
session uploading independently, retained audio, and exact expiry.
- `wal_retry_manifest_transport_test.dart` verifies the typed 503 over
loopback HTTP, no request during the restored wait, and a queued receipt
after expiry.

## UI evidence

UI-Evidence: none -- Upload retry timing only.

## Failure class

Failure-Class: none


<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/BasedHardware/omi/pull/26396?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="View guided diff"
src="https://www.cubic.dev/buttons/review-in-cubic-light.svg"></picture></a>
<a
href="https://www.cubic.dev/action/auto-fix/pr/BasedHardware/omi/26396?returnTo=https%3A%2F%2Fgithub.com%2FBasedHardware%2Fomi%2Fpull%2F26396&source=description"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"><img
alt="Turn on auto-fix"
src="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"></picture></a>
<!-- End of auto-generated description by cubic. -->

This branch has not been deployed

No deployments
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