Skip to content

fix(sync): bind safety WALs to live recording intervals - #19424

Merged
Git-on-my-level merged 16 commits into
mainfrom
fix/sync-live-capture-dedup
Sep 27, 2026
Merged

Git-on-my-level merged 16 commits into
mainfrom
fix/sync-live-capture-dedup

Conversation

@Git-on-my-level

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

Copy link
Copy Markdown
Member

Summary

One pendant recording could show up twice: the live conversation from /v4/listen, and a second conversation created when the phone uploaded its local safety copy of the same audio without a conversation id. No user content or identifiers are included here.

Root cause

  • The phone writes every live pendant frame into a local safety WAL while streaming it (app/lib/services/capture/capture_controller.dart:1807). That WAL was stamped with the live conversation id only after ConversationProcessingStarted (capture_controller.dart:3167). The stamp window required timerStart to fall between session start and now (app/lib/services/wals/local_wal_sync.dart:784). Session start is recorded only when the transcription socket is published (capture_controller.dart:1318), which is after frames have already started, and WAL timerStart is backdated from the frame count, so the main chunk often sat before the window and stayed unstamped. _finalizeAndStampSession also awaited the disk flush and then returned without stamping when a device update rolled the session during that await (capture_controller.dart:3346). An unstamped WAL uploaded with no conversation_id (app/lib/backend/http/api/conversations.dart:797).
  • Sync attaches to a live conversation only when given an explicit conversation id. Temporal lookup skips rows that are not auto-mergeable, and live rows have no sync_content_revision (backend/utils/sync/assignment.py:65, backend/utils/sync/assignment.py:164).

Fix

  • Stamp each safety WAL with the client recording id (activeRecordingId / recording_session_id) when the WAL is created, after the previous session's tail is flushed, and send it as an optional recording_session_id on /v2/sync-local-files. Conversation-id stamping stays. A WAL that already carries this recording id is stamped even when its backdated timerStart is before session start, and a session roll during the flush no longer skips that stamp. A WAL from a different recording is left alone.
  • For uploads carrying the client recording id and audio interval, intake binds only when exactly one conversation in the authenticated user's collection matches the recording_session_id, source, device, and lock state, and the WAL overlaps that conversation and fits within a bounded interval: up to 5 seconds before started_at for socket startup or clock skew, and up to 60 seconds after finished_at for trailing silence (less than the 120-second silence-rollover gap). It then uses the existing explicit-target path, including live-target transcript dedupe. A single long, exact-text line in a mixed WAL batch is also dropped when its timestamp differs by at most 2 seconds and its duration is within the existing 25% ratio; broader clock-offset matches retain the batch gate. A query capped at six rows binds nothing when more than five candidates exist, so truncation cannot imply uniqueness. A unique resolved target is authoritative even when it differs from a locally stamped conversation id from another silence-rollover generation. Missing/ambiguous matches, provenance or interval mismatches, and lookup failures (logged with a bounded HMAC UID hash) clear an unverifiable local stamp and keep the unbound sync path. Omitting the new recording proof keeps the existing stamped-target behavior for old clients.
  • Same-source replay handling uses this recording-session binding. The capture-group same-source refusal is restored to origin/main. Old app versions omit the new fields and continue through today's unbound sync path with the existing same-source refusal. The separate Jev capture shadow continues to measure same-device pairs and remains shadow-only.

The phone change ships with the next mobile release. On the first listen generation, the phone's activeRecordingId is sent as client_conversation_id and is the id listen stores as external_data.recording_session_id. Silence rollover deliberately mints a new server recording id while the phone id may continue. A WAL that truly spans a rollover remains unbound rather than being assigned to either generation; later-generation WALs whose id differs from the server id fall back to ordinary sync. Binding for that later generation remains a documented residual until the client receives and sends the server id.

Gap-only STT option for David's decision

For a bound safety WAL, the server could map existing live transcript word timestamps into the WAL's audio timeline, subtract covered intervals with a small guard band, and send only uncovered audio ranges to paid batch STT. This could save most batch STT minutes when live recognition covered nearly all speech. The server would need reliable clock alignment, VAD and gap boundaries, and a fallback to full-WAL STT when timing is uncertain; otherwise words near gaps, late live results, or speech missed by live STT could be lost. This PR leaves paid STT input unchanged pending David's ruling.

Verification

  • Focused backend/test.sh run passed 263 tests across test_sync_recording_session_target.py, test_sync_silent_failure.py, test_sync_cross_job_assignment.py, test_sync_cloud_tasks.py, and test_developer_from_segments_idempotency.py. Focused Flutter tests passed 88 tests across six WAL/upload/provider files. Backend Pyright reported 0 errors. scripts/pr-preflight --pr-body-file and OMI_PR_BODY_FILE=.local/pr-body-fix-sync-live-capture-dedup.md make preflight each passed 53 checks. The merged main branch had a stale desktop meeting fixture that claimed five minutes with only 60 seconds of transcript span; updating that fixture to span five minutes makes its 42-test file pass.
  • The selector tests cover bounded skew, trailing silence, adjacent-candidate ambiguity, query truncation, and redacted lookup logging. Intake tests cover one repeated line in a mixed WAL batch and preserve a loosely aligned repeat. Coordinator target-selection tests cover matching stamp and resolution, mismatched stamp with resolved target winning, and no safe resolution with or without a stamp; old clients retain a stamp when recording proof is absent.
  • Not verified on a device or against production data.

Line-Count-Exception: app/lib/services/capture/capture_controller.dart | 3812 -> 3831 | reason: recording-session bind stays in the existing session start and stamp path
Line-Count-Exception: app/lib/services/wals/local_wal_sync.dart | 1572 -> 1613 | reason: safety WAL creation and conversation stamp learn the recording id in place
Line-Count-Exception: backend/routers/sync.py | 2187 -> 2221 | reason: optional recording identity and audio interval are threaded through existing v2 sync dispatch
Line-Count-Exception: backend/utils/sync/pipeline.py | 2687 -> 2730 | reason: interval-bounded recording-session lookup runs before the existing explicit-target intake

Failure-Class: FC-same-speech-captured-twice-surfaces-twice

Product invariants affected

none

🤖 Generated with Claude Code

Review in cubic

Git-on-my-level and others added 4 commits September 27, 2026 16:58
Failure-Class: FC-same-speech-captured-twice-surfaces-twice

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-authored-by: Cursor <[email protected]>
Failure-Class: FC-same-speech-captured-twice-surfaces-twice

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-authored-by: Cursor <[email protected]>
Failure-Class: FC-same-speech-captured-twice-surfaces-twice

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-authored-by: Cursor <[email protected]>
@mintlify

mintlify Bot commented Sep 27, 2026 •

Copy link
Copy Markdown

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated
omi 🟢 Ready View Preview Sep 27, 2026, 7:44 PM

💡 Tip: Enable Automations to automatically generate PRs for you.

The opened and reopened events did not start the PR workflows.

Failure-Class: FC-same-speech-captured-twice-surfaces-twice

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@BasedHardware BasedHardware deleted a comment from github-actions Bot Sep 27, 2026
@BasedHardware BasedHardware deleted a comment from github-actions Bot Sep 27, 2026
@Git-on-my-level Git-on-my-level changed the title fix(sync): bind live safety WALs to their recording session fix(sync): bind live safety WALs to their recording session. Sep 27, 2026
@Git-on-my-level Git-on-my-level changed the title fix(sync): bind live safety WALs to their recording session. fix(sync): bind live safety WALs to their recording session Sep 27, 2026
Keep both the same-device grouping tests and the capture-shadow tests so the pull request can merge and CI can run.

Failure-Class: FC-same-speech-captured-twice-surfaces-twice

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Git-on-my-level and others added 2 commits September 27, 2026 19:47
Unit tests stub google.cloud before importing the sync pipeline, so a module-level Firestore import failed collection.

Failure-Class: FC-same-speech-captured-twice-surfaces-twice

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The Cloud Tasks payload allowlist is exact, so the new field was rejected before a task could be captured.

Failure-Class: FC-same-speech-captured-twice-surfaces-twice

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Git-on-my-level Git-on-my-level changed the title fix(sync): bind live safety WALs to their recording session fix(sync): bind safety WALs to live recording intervals Sep 27, 2026
Git-on-my-level and others added 2 commits September 27, 2026 21:10
Bind only when the full WAL interval belongs to the matching live generation, and restore the same-source refusal.

Failure-Class: FC-same-speech-captured-twice-surfaces-twice

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Git-on-my-level
Git-on-my-level merged commit 0a3aa8a into main Sep 27, 2026
61 checks passed
@Git-on-my-level
Git-on-my-level deleted the fix/sync-live-capture-dedup branch September 27, 2026 20:25
Itaxh1 added a commit to Itaxh1/omi that referenced this pull request Oct 2, 2026
BasedHardware#19424 stamps a WAL by its recording id even when its start, backdated from its
frame count, falls before the session window. Confirmation still only looked
inside the window, so a fully transcribed first chunk stayed behind and was
uploaded again. With the transcript's spans in hand, every WAL stamped with the
conversation is judged by them.

Refs BasedHardware#20364
Git-on-my-level added a commit that referenced this pull request Oct 3, 2026
…ipt covers (#20376)

* fix(app): release the pendant backup only for audio the saved transcript covers

A conversation with any saved text released every safety WAL in its session, so
audio the server never saved was deleted for good. Confirmation now takes the
saved transcript's time spans: a WAL is released only when a saved segment
overlaps it (with 30 s slack) or it ended before the conversation started. The
rest stays on the phone and is uploaded for repair.

Closes #20364

* fix(app): judge backdated stamped backups by the saved transcript

#19424 stamps a WAL by its recording id even when its start, backdated from its
frame count, falls before the session window. Confirmation still only looked
inside the window, so a fully transcribed first chunk stayed behind and was
uploaded again. With the transcript's spans in hand, every WAL stamped with the
conversation is judged by them.

Refs #20364

* fix(app): take the session start as origin for a row without started_at

The server sets started_at on every conversation it creates, but a row
without one used its createdAt, which can sit minutes away from the audio
and shift every span.

The scenario tests now wait for the expected WAL state, in memory and in
the saved index, before asserting and before the recovery pass, and fail
with the WAL state if it never arrives.

* fix(app): anchor the saved transcript to the phone's clock

Saved segment times count from the server's conversation start, but the
copies carry phone time, so a clock difference beyond the 30 s slack
moved the release boundary: a server clock ahead released audio the
transcript missed, and one behind re-uploaded audio it covered.

The controller now records when each live segment last arrived and, at
confirmation, takes the median of arrival minus segment end as the
transcript's start on the phone. Without live segments it falls back to
the server's start, as before.

The full-release scenarios now also assert that copies exist before the
conversation closes.

* fix(app): keep each closing conversation's segment arrivals until its own event

The arrival times that anchor a saved transcript to the phone's clock were held in
one slot, so a conversation that closed before the previous ConversationEvent
arrived replaced them. They are now kept per conversation id and taken by the
matching event. #20365's change keys the rest of the close state the same way.

* fix(app): retain safety audio when transcript coverage is uncertain

Timestamp overlap and pre-conversation timing do not prove delivery.
Keep uncertain copies for recovery and measure accepted repair uploads.
Fence deletion against account changes and shared-file/id collisions.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(app): avoid duplicate speech while retaining covered safety audio

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(app): avoid duplicate repair uploads during natural speech pauses

Treat transcript gaps and WAL edges up to 30 seconds as pauses because
coverage now suppresses automatic repair without deleting local audio.
Exercise conversational utterances and larger missing stretches in replay.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>

---------

Co-authored-by: David Zhang <[email protected]>
Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
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