Skip to content

fix(sync): keep synced transcript times on the VAD file clock - #22326

Merged
kodjima33 merged 3 commits into
BasedHardware:mainfrom
apoorvdarshan:fix/sync-transcript-vad-file-clock
Oct 19, 2026
Merged

kodjima33 merged 3 commits into
BasedHardware:mainfrom
apoorvdarshan:fix/sync-transcript-vad-file-clock

Conversation

@apoorvdarshan

@apoorvdarshan apoorvdarshan commented Oct 19, 2026 •

Copy link
Copy Markdown
Collaborator

What changed and why

Fixes #22325.

The legacy offline-sync path (process_segment) transcribes each VAD file separately. postprocess_words starts that transcript at its first word, but process_segment anchored those times at the VAD file's timestamp. That timestamp is also started_at, the stored audio chunk's timestamp and the capture-evidence origin. Whenever the file opens before the first word, every synced line lands that many seconds early and finished_at stops the same amount short of the last word. The closest-conversation lookup and the time-based merge use the same shifted times.

VAD regions under 120 s apart are merged into one file (capped at 300 s), so a cough, door or TV burst before speech can put the first word tens of seconds, up to minutes, into the file.

The fix:

  • carries the first word's offset with the transcript, on the main path and on the dark empty-recovery path
  • uses it for the end time and the merge lookup
  • adds it back to each line before the conversation is built

The final pass keeps its first-word clock, and intake shifts its output the same way. Existing rows are not rewritten.

The batch lane already makes this correction in utils/batch_pipeline/projection.py ("undo the grouper's first-word normalization"). The legacy path still handles uploads that batch intake hands back (for example content an earlier legacy job claimed, or a target owned by legacy_final_pass_v1), and every deployment that runs without BATCH_PIPELINE_ENABLED.

This is not the cause of #20358 (a ~15 min shift). That report is about the capture start the phone assigns (#21695). This shift happens inside one VAD file, so the 300 s cap bounds it.

backend/docs/listen_pusher_pipeline.mdx said persisted sync segments use the first-word origin. It now describes the file clock.

Product invariants affected

none

How it was verified

  • Traced on origin/main (8ed3ad1b1b). retrieve_vad_segments names each file capture start + VAD start. _segments_as_objects subtracts the first segment's start. process_segment uses the file timestamp for started_at, finished_at, the closest-conversation lookup, the stored audio chunk and capture evidence. assign_in_transaction places lines at started_at + start, and the playback artifact uses started_at as the TranscriptSegment.start basis.
  • Replayed the grouping and the anchor arithmetic in a standalone script (copied logic, no repo imports). Before the fix the line is stored at 0.0–3.75 s and finished_at is 20.5 s early. After it, the line is at 20.5–24.25 s and finished_at is the last word end.
  • Local checks only (compute policy on this machine): scripts/backend-python-format --check and python -m py_compile on the changed Python files. The commit hook's formatter also left them unchanged.
  • I didn't run pytest locally. The regression test is written to fail without the fix; it and the full backend suites run in Omi's CI (ci:full).
  • The first CI run failed the backend pyright step: the inline shift made process_segment too complex for pyright to analyze. The shift now lives in _shift_to_vad_file_clock, called at the same point.

Tests

backend/tests/unit/test_sync_capture_pipeline.py::test_late_first_word_stays_on_the_vad_file_clock has a main case and an empty-recovery case. It runs the real VAD export (a cough at 20 s and speech at 40 s merge into one file that starts at 20 s), the real postprocess_words, process_segment and the strict Firestore intake. It asserts:

  • the stored line is at 20.5–24.25 s from started_at
  • finished_at is the last word end
  • the merge lookup window ends there

Without the fix the line is stored at 0.0–3.75 s, and finished_at and the lookup end are 20.5 s early.

Existing tests are unaffected. Their placeholder words have no timestamp or start at 0.0, so the offset is 0 and nothing moves.

UI evidence

UI-Evidence: none -- backend-only change; the process_segment regression test covers the stored times.

Failure class (fixes)

Failure-Class: FC-transcript-and-audio-on-independent-clocks

Line-count exception

Line-Count-Exception: backend/utils/sync/pipeline.py | 3556 -> 3584 | the offset and shift helpers sit beside process_segment, which uses them

🤖 Generated with Claude Code

postprocess_words starts a transcript at its first word, but
process_segment anchored those times at the VAD file's start, which is
also started_at, the stored audio chunk's timestamp and the capture
evidence origin. When a VAD file opens before the first word, for
example a cough merged with speech less than 120 s later, every synced
line lands that many seconds early, finished_at stops short of the last
word, and the merge lookup searches too early a window.

Carry the first word's offset with the transcript (main and empty
recovery paths), use it for the end time, and add it back to each line
before the conversation is built.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@apoorvdarshan apoorvdarshan added the ci:full Maintainer-granted: run full CI on this fork PR label Oct 19, 2026
apoorvdarshan and others added 2 commits October 19, 2026 08:23
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The inline file-clock shift pushed process_segment over pyright's
code-flow complexity limit, so the backend type-check failed with "Code
is too complex to analyze". Move the shift into _shift_to_vad_file_clock
next to _first_word_offset. The same lines are shifted at the same point,
so behaviour is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@Git-on-my-level Git-on-my-level left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The production change here is correct and nicely scoped.

Verified the root cause on this head: _segments_as_objects in backend/utils/stt/pre_recorded.py normalizes every segment to the first word's start, while started_at, the stored audio chunk and capture evidence all use the VAD file's timestamp — so any file that opens on pre-speech noise (regions under 120 s apart merge) had every synced line landing that many seconds early.

  • backend/utils/sync/pipeline.py — _first_word_offset (no-start-timing words yield 0.0, so the shift is a no-op there), _shift_to_vad_file_clock applied once right before CreateConversation, and speech_offset added at both segment_end_timestamp sites, which also repairs the get_closest_conversation_to_timestamps lookup. Checked the final-pass interaction specifically: _run_sync_final_pass shifts only deep copies for evidence and converts its output back to the first-word clock, so the offset is applied exactly once — no double shift on the sync-enabled path.
  • backend/tests/unit/test_sync_capture_pipeline.py — the new parametrized test covers both the main path and the dark empty-recovery path and asserts started_at, segment times, finished_at and the merge-lookup arguments; both parametrizations pass locally. Nice test.
  • backend/docs/listen_pusher_pipeline.mdx — the doc hunk matches the new behavior.

One local failure (test_job_finalized_event_shares_segment_correlation) is my sandbox's redis lacking eval inside finalize_sync_job, a surface this diff doesn't touch; CI's backend unit suite is green on this head.

USER IMPACT: synced conversations whose audio opens with a cough/noise burst before speech will now show transcript lines at the moment they were actually spoken instead of up to a few minutes early; nothing changes for files that start with speech.

Non-blocking follow-up: legacy speaker-identity evidence slicing (speaker_identity.py, the collect_speaker_audio call) still uses unshifted segment times against full-file audio — a pre-existing mismatch this PR doesn't touch and the final-pass path already avoids; worth a small follow-up if that lane ever resurfaces.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Legacy offline-sync path anchored transcript times to the VAD file timestamp instead of the first word, causing early-shifted sync lines; fixes anchor + adds test. 5/5.

@kodjima33
kodjima33 merged commit 8824c0a into BasedHardware:main Oct 19, 2026
55 checks passed
Git-on-my-level added a commit that referenced this pull request Oct 19, 2026
)

* fix(backend): restore pyright-clean main after #22207 and #22326

Main's backend unit shards fail the enforced pyright lane:

- database/desktop_previews.py (#22207): 16 reportUnnecessaryIsInstance
  errors. The runtime guards stay; they move into validators that take
  `object` (_payload, _string, _expected_generation, _datetime), so the
  checks are meaningful to pyright. Public signatures, error messages and
  check order are unchanged.
- utils/sync/pipeline.py:process_segment (#22326 on top of #22452):
  "code is too complex to analyze". Behaviour-neutral split: the two
  identical cap-hold defer blocks become one hold_for_cap closure, and the
  final-pass / speaker-identification block moves to
  _assign_segment_speakers with the same exception handling.

Failure-Class: none

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(backend): repair unit tests that drifted from main across merges

Five unit files fail on current main. Each one passed on its own PR's base
and broke when main moved underneath it; none is a product regression.

- test_request_context.py (#19738): tested the JIT budget surface that
  #22209 removed from llm_gateway/gateway/request_context.py. Keep the
  request-id tests; drop the tests for removed code.
- test_users_joan_followup_tombstone_guard.py (#19867): called
  delete_person_endpoint, but the joan followup route is
  delete_followup_question_endpoint.
- test_developer_from_segments_idempotency.py (#21265): process fakes
  rejected the trigger=CLIENT_FINALIZE kwarg the router passes since #19788.
- test_external_tools_sanitization.py (#19406): the stubbed utils package
  lacked utils.generated_compute (#21488) and utils.model_text. Stub the
  default-off gate as disabled and load the stdlib-only model_text for real.
- test_batch_upload_storage.py: the database.vector_db stub lacked
  delete_action_item_vectors_batch, which merge_conversations imports since
  #15953.

Failure-Class: none

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:full Maintainer-granted: run full CI on this fork PR python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Offline sync stores transcript lines early when a VAD file opens before the first word

3 participants