Repository navigation
Conversation
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]>
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
left a comment
There was a problem hiding this comment.
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_clockapplied once right beforeCreateConversation, andspeech_offsetadded at bothsegment_end_timestampsites, which also repairs theget_closest_conversation_to_timestampslookup. Checked the final-pass interaction specifically:_run_sync_final_passshifts 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
left a comment
There was a problem hiding this comment.
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.
) * 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]>
What changed and why
Fixes #22325.
The legacy offline-sync path (
process_segment) transcribes each VAD file separately.postprocess_wordsstarts that transcript at its first word, butprocess_segmentanchored those times at the VAD file's timestamp. That timestamp is alsostarted_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 andfinished_atstops 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:
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 bylegacy_final_pass_v1), and every deployment that runs withoutBATCH_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.mdxsaid persisted sync segments use the first-word origin. It now describes the file clock.Product invariants affected
none
How it was verified
origin/main(8ed3ad1b1b).retrieve_vad_segmentsnames each filecapture start + VAD start._segments_as_objectssubtracts the first segment's start.process_segmentuses the file timestamp forstarted_at,finished_at, the closest-conversation lookup, the stored audio chunk and capture evidence.assign_in_transactionplaces lines atstarted_at + start, and the playback artifact usesstarted_atas theTranscriptSegment.startbasis.finished_atis 20.5 s early. After it, the line is at 20.5–24.25 s andfinished_atis the last word end.scripts/backend-python-format --checkandpython -m py_compileon the changed Python files. The commit hook's formatter also left them unchanged.ci:full).process_segmenttoo 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_clockhas 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 realpostprocess_words,process_segmentand the strict Firestore intake. It asserts:started_atfinished_atis the last word endWithout the fix the line is stored at 0.0–3.75 s, and
finished_atand 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