Skip to content

fix(people): record where live audio was captured and cut teaching clips there - #20390

Merged
Git-on-my-level merged 18 commits into
mainfrom
lane/diar-integration
Oct 2, 2026
Merged

Git-on-my-level merged 18 commits into
mainfrom
lane/diar-integration

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Oct 2, 2026 •

Copy link
Copy Markdown
Member

Summary

Labeling a speaker teaches a voiceprint only when the clip cut for that label is the audio that was actually spoken. On live conversations it usually is not: text is timed from the provider stream, stored audio from chunk arrival, and reconnects or provider failover pull the two clocks apart. On one hand-labeled account, started_at + segment.start lands within 1 s of the speech for 20% of 1,416 labeled runs and more than 10 s away for 68%. In production the first 13 hours after #20190/#20252 stored 11 of 105 person teaching attempts (text_mismatch 38, insufficient_speech 29).

This PR makes new live conversations carry where each segment's audio was captured, and makes every teaching reader use it.

Change

  • Persist the receiver's capture window on live segments. The receiver already computes a capture-clock window per segment for transient speaker identification and then drops it. Legacy (v2-off) persistence now stores it in two private fields, audio_capture_start / audio_capture_end (absolute Unix seconds). Text, speaker, start/end and ordering are unchanged; the fields are absent when unknown, cleared when a text merge spans a capture gap, kept out of the client schema and stripped from every client frame. AUDIO_TIMELINE_V2 is untouched. New counter omi_live_audio_capture_windows_total{outcome,reason} shows what share of new segments are placeable.
  • One placement module (utils/conversations/audio_placement.py). locate() returns a trusted window only for audio-timeline v2 manifests and sync:-timed segments and refuses otherwise. candidate_window() gives verified readers the capture-clock position when every contributor recorded one with a consistent offset, else the legacy origin. Person teaching, the owner clip, tag-prompt clips and the text search all go through it. A capture window is a better candidate, not proof: every teaching path still runs the 0.9 transcript containment check before publishing.
  • Bounded text-anchored recovery for teaching, default off (SPEAKER_TEACHING_TEXT_PLACEMENT): after a text mismatch, search at most 32 s around the candidate using the verification transcript's word times, re-verify at most 12 s. Containment gate unchanged.
  • Manual merge keeps source clocks. The manual merge writer offset each donor by the prior transcript end plus a wall gap while copying audio at unchanged absolute timestamps, shifting later donors' text early. It now rebases from source wall-clock origins.
  • Conversation-wide resolution never names from unplaced text. Unplaced or abstained segments no longer inherit a cluster's name through a shared old speaker id.

Evidence

Offline replay on one hand-labeled account (aggregates only; one account, so no population claim):

  • Stored live conversations cannot be re-placed from metadata: strict locate() returns 0 of 1,416 runs (it refuses rather than guesses), and bounded text search recovers 13 of 748 mismatched windows, all 13 within 1 s. Old conversations stay as they are; this PR fixes forward.
  • Synthetic replay through the real receiver and persistence: capture windows stored for 0 of 18 segments before, 11 of 18 after (receiver had a window for 14 of 20 inputs; gaps and partial sentence repair clear it by design). All 18 stored payloads are byte-identical to before once the two new fields are removed.
  • A burst/clock-jump fixture shows the capture clock and the stored-chunk clock can still disagree (known metadata 2 of 2, exact stored-audio matches 0 of 2). That is why the capture window is used only behind transcript verification and locate() does not trust it.

Not measured: production availability of capture windows (the new counter will show it) and the change in production store rates.

Tests

  • New: test_live_capture_windows.py, test_live_capture_persistence.py, test_live_capture_lifecycle.py, test_audio_placement.py, test_audio_placement_merge.py, test_teaching_placement.py, test_audio_capture_candidate.py; additions to test_conversation_speakers.py and test_merge_validation.py.
  • BACKEND_UNIT_TEST_FILE_LIST over 19 related files via backend/test.sh: all pass. scripts/typecheck.sh: 0 errors.
  • TranscriptSegment and Conversation JSON schemas compared equal to pre-change snapshots; no generated client changed.
  • Not run: anything against a live backend or device, Docker image build.

Rollout notes

  • Backend, listen and pusher should deploy together: the fields are written on the live path and read by teaching in the backend.
  • No migration or backfill. Existing conversations behave as before (legacy origin candidate).
  • Turn off: LIVE_SPEAKER_CAPTURE_CLOCK=false stops new windows being attached (it also changes the existing live matching path; use its established procedure). The text search is off unless SPEAKER_TEACHING_TEXT_PLACEMENT is set.
  • Watch: omi_live_audio_capture_windows_total persisted share; omi_person_voice_learning_total and the owner sample outcomes for text_mismatch falling on new conversations.

Product invariants affected

none

Failure class

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

Teaching read transcript coordinates as if they addressed stored audio. This records the capture position at write time, routes every teaching reader through one placement gate that refuses unknown clocks for trusted use, and keeps transcript verification in front of every publication. Guards: test_live_capture_persistence.py, test_audio_placement.py, test_audio_capture_candidate.py.

🤖 Generated with Claude Code

Review in cubic

Git-on-my-level and others added 16 commits October 3, 2026 02:06
Rebase donor segments from wall-clock origins so trailing silence and
overlapping captures do not shift labels away from their stored audio.

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

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Devin Fusion <[email protected]>
Keep placement abstentions out of clustering and identity propagation while
reserving their capture IDs and preserving manual receipt authority.

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

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

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Devin Fusion <[email protected]>
…ates

Share conservative audio placement across teaching and preview readers,
reject unknowable clocks, and add default-off bounded text recovery without
weakening transcript quality or manual-authority gates.

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

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Devin Fusion <[email protected]>
Require complete placed audio windows, invalidate stale vectors without
losing retryable clock proof, and validate historical cache suggestions.
Keep live resolution opt-in because offline wrong naming did not improve.

Requires the shared audio_placement module from the placement lane.
Failure-Class: FC-transcript-and-audio-on-independent-clocks

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

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Devin Fusion <[email protected]>
…ripts

Retain known receiver capture windows for downstream placement checks while
keeping legacy transcript coordinates and client frames unchanged. Clear
unprovable merged windows and expose bounded persistence availability metrics.

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

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

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Devin Fusion <[email protected]>
…n it was recorded

Legacy live text is timed from the provider stream and stored audio from
chunk arrival; reconnects and failover pull the clocks apart, so
started_at + segment.start misses the audio for most labeled speech. New live
segments now carry audio_capture_start/end. Person teaching, the owner clip,
tag-prompt clips and the bounded text search use that window as their
candidate position when every contributor recorded one with a consistent
offset, and fall back to the legacy origin otherwise. The candidate stays
behind the existing transcript verification, and locate() still refuses to
treat it as trusted placement.

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

Held back from this integration, not rejected. ed797e3 (kept on
lane/diar-recog) rejects every v1 speaker-embedding cache and can withdraw
automatic names on already-resolved synced recordings when they are
reprocessed, and its live-conversation path only engages for placement that
locate() can prove — which no legacy live conversation has today. It should
land as its own PR once capture-window availability is measured in
production. The smaller fix from that lane (unplaced segments never inherit
a name) stays.

This reverts commit ed797e3.

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

chatgpt-codex-connector Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-02T22:08:42.634003Z 8ddc6a9 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.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

7 issues found across 20 files

Confidence score: 3/5

  • conversation_speakers.py leaves the abstention filter disabled because neither production caller passes the unplaced segment IDs, so those segments can still inherit a resolved identity through a shared speaker ID. Pass the IDs from both callers.
  • service.py can use recovered text spoken by someone else to build the owner's voiceprint. Verify the clip belongs to the owner before pooling it.
  • audio_placement.py rejects common unspaced Chinese and Japanese transcripts before searching because they produce fewer than five tokens. Handle those transcripts without the five-token requirement.
  • listen_pusher_pipeline.mdx says recovery runs with SPEAKER_TEACHING_TEXT_PLACEMENT off, but the implementation requires the flag to be enabled. Update the docs to describe recovery as opt-in.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="backend/docs/listen_pusher_pipeline.mdx">

<violation number="1" location="backend/docs/listen_pusher_pipeline.mdx:1427">
P2: This says recovery runs while `SPEAKER_TEACHING_TEXT_PLACEMENT` is off, but the implementation skips it unless the flag is enabled. Describe the path as opt-in/default-off so operators do not expect recovery without enabling it.</violation>
</file>

<file name="backend/tests/unit/test_live_capture_windows.py">

<violation number="1" location="backend/tests/unit/test_live_capture_windows.py:159">
P2: `b` always has a complete window here, so this test never covers a known persisted window merged with a missing incoming window; parameterize both sides and assert both fields stay absent.</violation>
</file>

<file name="backend/utils/conversations/audio_placement.py">

<violation number="1" location="backend/utils/conversations/audio_placement.py:297">
P2: Text-anchored recovery always returns `insufficient_anchor` for common unspaced Chinese/Japanese transcripts: `_tokens(expected_text)` produces fewer than five tokens, so this guard rejects them before searching. Add language-aware anchoring for non-space-delimited text so those teaching clips can use recovery too.</violation>
</file>

<file name="backend/utils/stt/conversation_speakers.py">

<violation number="1" location="backend/utils/stt/conversation_speakers.py:132">
P1: Neither production caller supplies `abstained_segment_ids`, so this filter stays disabled and unplaced segments can still inherit a resolved identity through their old shared speaker ID. Pass the unplaced/abstained IDs from the resolver or derive them here.</violation>
</file>

<file name="backend/utils/speaker_tag_prompts/service.py">

<violation number="1" location="backend/utils/speaker_tag_prompts/service.py:831">
P1: A different speaker can supply the recovered text: the helper searches nearby audio and verifies text plus dominant-speaker ratio, not owner identity. This line then pools that clip as the owner's voiceprint; require a trusted owner/source-speaker check before accepting recovered audio.</violation>
</file>

<file name="backend/utils/speaker_identification.py">

<violation number="1" location="backend/utils/speaker_identification.py:1022">
P2: Pass `rec_contributors` through the recovery API and use them to derive its candidate window. A conflicting merged scope can otherwise force a legacy-origin search far from the capture-based cut, causing eligible recovery to fail.</violation>
</file>

<file name="backend/utils/speaker_tag_prompts/clips.py">

<violation number="1" location="backend/utils/speaker_tag_prompts/clips.py:82">
P3: In the v2 branch the clip is cut from `placement.window` (transcript-clock, span-validated), but the coverage gate runs against `normalized`, whose `started_at` was shifted to the capture-clock candidate window (`window[0] - start`). When `audio_capture_start/end` exist and the capture clock drifts from the transcript clock, coverage is verified for a window that is never cut and the cut window is never coverage-checked. `locate()` already proved the placement window is covered for `reason == 'v2'`, so the capture-shifted checks can only add false rejections (`coverage/prompt` on the shifted window misses the validated spans) or misfile the `OMI_AUDIO_TIMELINE_COVERAGE_TOTAL` metric. Use the original `conversation` (started_at = placement window) for these checks, as the pre-change code did.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

*,
manual_speakers: Optional[Mapping[int, Identity]] = None,
voiceprints: Optional[Mapping[str, Any]] = None,
abstained_segment_ids: Optional[Set[str]] = None,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1: Neither production caller supplies abstained_segment_ids, so this filter stays disabled and unplaced segments can still inherit a resolved identity through their old shared speaker ID. Pass the unplaced/abstained IDs from the resolver or derive them here.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At backend/utils/stt/conversation_speakers.py, line 132:

<comment>Neither production caller supplies `abstained_segment_ids`, so this filter stays disabled and unplaced segments can still inherit a resolved identity through their old shared speaker ID. Pass the unplaced/abstained IDs from the resolver or derive them here.</comment>

<file context>
@@ -129,6 +129,7 @@ def resolve_conversation_speakers(
     *,
     manual_speakers: Optional[Mapping[int, Identity]] = None,
     voiceprints: Optional[Mapping[str, Any]] = None,
+    abstained_segment_ids: Optional[Set[str]] = None,
 ) -> Optional[SpeakerResolution]:
     """Resolve one speaker_id per voice across the whole conversation.
</file context>

anchor_offset=start - min(float(s.get('start') or 0) for s in run_contributors),
)
if recovered is not None:
pcm, _recovered_transcript = recovered

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1: A different speaker can supply the recovered text: the helper searches nearby audio and verifies text plus dominant-speaker ratio, not owner identity. This line then pools that clip as the owner's voiceprint; require a trusted owner/source-speaker check before accepting recovered audio.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At backend/utils/speaker_tag_prompts/service.py, line 831:

<comment>A different speaker can supply the recovered text: the helper searches nearby audio and verifies text plus dominant-speaker ratio, not owner identity. This line then pools that clip as the owner's voiceprint; require a trusted owner/source-speaker check before accepting recovered audio.</comment>

<file context>
@@ -805,6 +806,31 @@ async def store_owner_voice_sample(
+                    anchor_offset=start - min(float(s.get('start') or 0) for s in run_contributors),
+                )
+                if recovered is not None:
+                    pcm, _recovered_transcript = recovered
+                    wav = pcm_to_wav(pcm)
+                    is_valid = True
</file context>

Comment on lines +1427 to +1428
`invalid_window` and `missing_origin` refuse. Because legacy provider and stored-audio clocks may differ, flagged-off `SPEAKER_TEACHING_TEXT_PLACEMENT` adds a text-anchored
re-cut on `text_mismatch` alone — person teaching only when exactly one fully decoded ≥10 s interval failed, owner on the existing ≥5 s clip — searching ±10 s (≤32 s of audio),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: This says recovery runs while SPEAKER_TEACHING_TEXT_PLACEMENT is off, but the implementation skips it unless the flag is enabled. Describe the path as opt-in/default-off so operators do not expect recovery without enabling it.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At backend/docs/listen_pusher_pipeline.mdx, line 1427:

<comment>This says recovery runs while `SPEAKER_TEACHING_TEXT_PLACEMENT` is off, but the implementation skips it unless the flag is enabled. Describe the path as opt-in/default-off so operators do not expect recovery without enabling it.</comment>

<file context>
@@ -1421,18 +1421,17 @@ REST tries immediately, sockets queue a delayed attempt, and fanout completion
+Legacy person teaching, owner confirmations and speaker-tag preview clips use `utils/speaker_audio.py` through one shared pure gate in `utils/conversations/audio_placement.py`:
+strict `locate` requires a real `started_at` and trusts only a fully validating v2 manifest or a `sync:`-scoped contributor union covering the window; other clocks answer
+`untrusted_clock` and may cut provisional candidates (a legacy preview can still seed from `created_at`) only behind the mandatory transcript verification, while `unplaced`,
+`invalid_window` and `missing_origin` refuse. Because legacy provider and stored-audio clocks may differ, flagged-off `SPEAKER_TEACHING_TEXT_PLACEMENT` adds a text-anchored
+re-cut on `text_mismatch` alone — person teaching only when exactly one fully decoded ≥10 s interval failed, owner on the existing ≥5 s clip — searching ±10 s (≤32 s of audio),
+one STT pass plus one final verification (≤44 audio-seconds under a shared 30 s STT deadline that suppresses internal provider retries), and refusing ambiguous or
</file context>
Suggested change
`invalid_window` and `missing_origin` refuse. Because legacy provider and stored-audio clocks may differ, flagged-off `SPEAKER_TEACHING_TEXT_PLACEMENT` adds a text-anchored
re-cut on `text_mismatch` alone — person teaching only when exactly one fully decoded ≥10 s interval failed, owner on the existing ≥5 s clip — searching ±10 s (≤32 s of audio),
`invalid_window` and `missing_origin` refuse. Because legacy provider and stored-audio clocks may differ, the default-off `SPEAKER_TEACHING_TEXT_PLACEMENT` flag enables a text-anchored
re-cut on `text_mismatch` alone — person teaching only when exactly one fully decoded ≥10 s interval failed, owner on the existing ≥5 s clip — searching ±10 s (≤32 s of audio),



@pytest.mark.parametrize('a_window', [(None, None), (100.0, None)])
def test_unknown_window_on_either_side_stays_absent(a_window):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: b always has a complete window here, so this test never covers a known persisted window merged with a missing incoming window; parameterize both sides and assert both fields stay absent.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At backend/tests/unit/test_live_capture_windows.py, line 159:

<comment>`b` always has a complete window here, so this test never covers a known persisted window merged with a missing incoming window; parameterize both sides and assert both fields stay absent.</comment>

<file context>
@@ -0,0 +1,520 @@
+
+
[email protected]('a_window', [(None, None), (100.0, None)])
+def test_unknown_window_on_either_side_stays_absent(a_window):
+    merged, _ = _merged_window(
+        [
</file context>

return AudioPlacement(None, 'insufficient_anchor')

prefix = _tokens(expected_text)[:TEXT_ANCHOR_MIN_TOKENS]
if len(prefix) < TEXT_ANCHOR_MIN_TOKENS:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: Text-anchored recovery always returns insufficient_anchor for common unspaced Chinese/Japanese transcripts: _tokens(expected_text) produces fewer than five tokens, so this guard rejects them before searching. Add language-aware anchoring for non-space-delimited text so those teaching clips can use recovery too.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At backend/utils/conversations/audio_placement.py, line 297:

<comment>Text-anchored recovery always returns `insufficient_anchor` for common unspaced Chinese/Japanese transcripts: `_tokens(expected_text)` produces fewer than five tokens, so this guard rejects them before searching. Add language-aware anchoring for non-space-delimited text so those teaching clips can use recovery too.</comment>

<file context>
@@ -0,0 +1,356 @@
+        return AudioPlacement(None, 'insufficient_anchor')
+
+    prefix = _tokens(expected_text)[:TEXT_ANCHOR_MIN_TOKENS]
+    if len(prefix) < TEXT_ANCHOR_MIN_TOKENS:
+        return AudioPlacement(None, 'insufficient_anchor')
+
</file context>

Comment thread backend/utils/speaker_identification.py Outdated
and len({segment_group(seg) for seg in ordered_rec}) == 1
):
rec_text = ' '.join(str(seg.get('text') or '').strip() for seg in ordered_rec)
recovered = await recover_teaching_clip(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: Pass rec_contributors through the recovery API and use them to derive its candidate window. A conflicting merged scope can otherwise force a legacy-origin search far from the capture-based cut, causing eligible recovery to fail.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At backend/utils/speaker_identification.py, line 1022:

<comment>Pass `rec_contributors` through the recovery API and use them to derive its candidate window. A conflicting merged scope can otherwise force a legacy-origin search far from the capture-based cut, causing eligible recovery to fail.</comment>

<file context>
@@ -991,8 +1007,36 @@ async def extract_speaker_samples(
+                    and len({segment_group(seg) for seg in ordered_rec}) == 1
+                ):
+                    rec_text = ' '.join(str(seg.get('text') or '').strip() for seg in ordered_rec)
+                    recovered = await recover_teaching_clip(
+                        uid,
+                        conversation,
</file context>

Comment thread backend/models/transcript_segment.py Resolved
if placement.reason != 'v2' or placement.window is None:
return None
outcome = coverage_outcome(conversation, start, end)
outcome = coverage_outcome(normalized, start, end)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P3: In the v2 branch the clip is cut from placement.window (transcript-clock, span-validated), but the coverage gate runs against normalized, whose started_at was shifted to the capture-clock candidate window (window[0] - start). When audio_capture_start/end exist and the capture clock drifts from the transcript clock, coverage is verified for a window that is never cut and the cut window is never coverage-checked. locate() already proved the placement window is covered for reason == 'v2', so the capture-shifted checks can only add false rejections (coverage/prompt on the shifted window misses the validated spans) or misfile the OMI_AUDIO_TIMELINE_COVERAGE_TOTAL metric. Use the original conversation (started_at = placement window) for these checks, as the pre-change code did.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At backend/utils/speaker_tag_prompts/clips.py, line 82:

<comment>In the v2 branch the clip is cut from `placement.window` (transcript-clock, span-validated), but the coverage gate runs against `normalized`, whose `started_at` was shifted to the capture-clock candidate window (`window[0] - start`). When `audio_capture_start/end` exist and the capture clock drifts from the transcript clock, coverage is verified for a window that is never cut and the cut window is never coverage-checked. `locate()` already proved the placement window is covered for `reason == 'v2'`, so the capture-shifted checks can only add false rejections (`coverage/prompt` on the shifted window misses the validated spans) or misfile the `OMI_AUDIO_TIMELINE_COVERAGE_TOTAL` metric. Use the original `conversation` (started_at = placement window) for these checks, as the pre-change code did.</comment>

<file context>
@@ -82,23 +65,27 @@ def conversation_clip_pcm(
+        if placement.reason != 'v2' or placement.window is None:
             return None
-        outcome = coverage_outcome(conversation, start, end)
+        outcome = coverage_outcome(normalized, start, end)
         OMI_AUDIO_TIMELINE_COVERAGE_TOTAL.labels(mode='v2', outcome=outcome).inc()
         if outcome != 'covered':
</file context>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 21e5e74dd2

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +464 to +466
origin = conversations[0].get("started_at")
if origin is not None and curr_started is not None:
offset = (curr_started - origin).total_seconds()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve chronological order after rebasing overlapping merges

When source conversations overlap, this wall-clock offset can be earlier than cumulative_offset, but the donor segments are still appended after every segment from the first conversation. For example, a first transcript spanning 0–100 seconds and a donor beginning five seconds later produces list order (0–100), (5–10); Conversation.get_transcript() preserves that list order, so reprocessing and display place the donor's early speech after later speech. Interleave or sort the merged segments after rebasing.

Useful? React with 👍 / 👎.

Comment on lines +68 to +71
window = candidate_window(conversation, start, end)
if window is None:
return None
placement = locate(conversation, start, end)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Limit capture-window lookup to the selected teaching run

When a selected owner/prompt run overlaps a segment from another capture scope, this implicit lookup considers every overlapping segment rather than only the contributors selected for the clip. A cross-scope duplicate with missing or differently offset capture fields therefore makes capture_window() fail and falls back to started_at + start, cutting the wrong audio after a provider restart; verification then rejects an otherwise valid teaching sample. Pass the selected run's contributors through to both candidate_window() and locate().

Useful? React with 👍 / 👎.

Comment on lines +121 to +124
for key in ('audio_capture_start', 'audio_capture_end'):
value = getattr(self, key)
if value is not None and key not in excluded and (included is None or key in included):
data[key] = value

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Exclude capture windows from client response serialization

Although these fields are declared with exclude=True and omitted from the generated client schema, this serializer explicitly re-adds them whenever a segment has a capture window. FastAPI endpoints returning Conversation models, such as GET /v1/conversations/{conversation_id}, invoke this nested serializer and do not use transcript_segment_for_client, so the supposedly private absolute capture timestamps appear in REST payloads and make runtime responses diverge from the published schema. Use a persistence-specific dump path rather than restoring the fields in the general serializer.

Useful? React with 👍 / 👎.

Comment on lines +296 to +298
prefix = _tokens(expected_text)[:TEXT_ANCHOR_MIN_TOKENS]
if len(prefix) < TEXT_ANCHOR_MIN_TOKENS:
return AudioPlacement(None, 'insufficient_anchor')

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Support non-space-delimited text when anchoring clips

When text-placement recovery is enabled for Chinese or Japanese recordings, _tokens(expected_text) generally returns the entire no-space utterance as one token, so this five-token check always returns insufficient_anchor even when the provider supplied many timed character/word entries; Thai text is similarly fragmented inconsistently by \w. The existing verification path explicitly supports these non-space-delimited languages, but the new placement stage prevents recovery from ever reaching it. Use language-aware character units or derive the anchor from the provider entries for these languages.

Useful? React with 👍 / 👎.

Comment on lines +140 to +142
abs_start, abs_end = window
search_start = max(abs_start - TEXT_SEARCH_PAD_SECONDS, timestamps[0])
search_end = min(abs_end + TEXT_SEARCH_PAD_SECONDS, search_start + TEXT_SEARCH_MAX_SECONDS)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Anchor center-cropped clips with text from inside the crop

For a long segment, both person teaching and owner confirmation center-crop a 10-second interval but pass the full segment text plus a potentially large anchor_offset. Recovery searches only around the cropped interval, while locate_in_verified_words() first looks for the full text's initial five tokens and applies the offset only after finding them. With a 60-second segment cropped to 25–35 seconds, those prefix words are roughly 25 seconds before the crop and outside this bounded search, so recovery deterministically returns text_anchor_missing even for correctly transcribed nearby audio. Build the expected anchor from the cropped excerpt rather than the start of the full segment.

Useful? React with 👍 / 👎.

…re fields out of responses

Independent review follow-ups on the integration:

- Capture windows are storage-only: JSON-mode dumps (API responses) omit
  them, and the third-party webhook projection strips them. They were being
  re-added by the segment serializer on every public read.
- Verified readers cut at the legacy position first, exactly as before. Only
  when that yields no verified speech and the receiver recorded the window
  somewhere materially different (>= 0.25 s) do person and owner teaching try
  once more at the capture window, behind the same transcript verification.
  Capture-first lost teaching under ordinary 0.5 s arrival jitter.
  omi_speaker_capture_retry_total{target,outcome} counts the retries.
- The clip reader and the preview route agree again: legacy origin by
  default, capture only when a teaching retry asks for it.
- An origin-rebased manual merge of overlapping sources is sorted, so the
  transcript stays chronological.

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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7f476679bb

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

*,
manual_speakers: Optional[Mapping[int, Identity]] = None,
voiceprints: Optional[Mapping[str, Any]] = None,
abstained_segment_ids: Optional[Set[str]] = None,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Pass unplaced segment IDs from production resolution callers

When sync assignment marks speech before a pinned live origin as audio_alignment='unplaced', the production _resolve call in speaker_resolution.py still invokes this function without abstained_segment_ids. The default therefore remains empty, allowing an unplaced segment that shares an old speaker ID with an embedded segment to inherit that cluster through by_old_id and receive its person/owner identity. Collect the unplaced IDs at the production call site and pass them here, rather than exercising this safety behavior only in direct unit tests.

Useful? React with 👍 / 👎.

Comment on lines +73 to +75
window = (
capture_window(conversation, start, end) if prefer_capture else provisional_window(conversation, start, end)
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Retry capture placement in the speaker-tag prompt flow

For a live conversation whose provider clock shifted away from the stored chunks, this new capture path is never used by speaker-tag previews: select_prompts and the clip endpoint first reject the legacy window with prompt_window_covered, while verified_clip_pcm and the endpoint call conversation_clip_pcm without prefer_capture=True. Such prompts are skipped or return 404 even when their persisted capture window points to valid, verifiable audio; wire the capture retry through prompt selection and verified preview instead of limiting it to owner-confirmation storage.

Useful? React with 👍 / 👎.

or offset_value < 0
):
return None
window = provisional_window(conversation, start, end)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Center text recovery on the failed capture candidate

When the legacy cut fails and the caller retries a substantially shifted capture window, a subsequent text_mismatch enters this function but the search is centered on the legacy provisional window again. If a reconnect moved the capture clock minutes away, the chunk timestamps lie outside these bounds (often making search_end <= search_start), so bounded recovery cannot correct ordinary residual jitter around the capture candidate. Accept the failed candidate window from the caller, or select the capture window here when that was the attempted cut.

Useful? React with 👍 / 👎.

b._clear_audio_capture_window()
return a, b
a.text = ""
b._merge_audio_capture_window(a)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Clear capture provenance when absorbing a different speaker

When a short unfinished segment from speaker a is absorbed into the longer following segment from speaker b, the survivor keeps b.start but this call expands its capture window backward to include a. If the added duration is within the one-second capture tolerance, capture_window() derives an offset that starts the retry at a's audio and truncates the end of b; for similarly sized turns it can contain only a. Because verification checks whether the resulting transcript is contained in the combined expected text, a five-word prefix from a can still pass and publish a's voiceprint under b's person label. Clear the capture window for this cross-speaker absorption, as the partial-transfer branch already does, unless the surviving transcript interval is rebased consistently.

Useful? React with 👍 / 👎.

…ery before the capture retry

Second review pass:

- Live translation events send stored segment dicts; TranslationEvent now
  projects them through the client-segment helper, so the storage-only
  capture window never reaches a client frame.
- Order of attempts in person and owner teaching is now: legacy cut, its
  bounded text search (opt-in flag), then one retry at the capture window.
  A failed capture retry reports what the legacy cut found instead of
  masking it, and no longer skips a recovery that would have worked.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Git-on-my-level
Git-on-my-level merged commit 3884b81 into main Oct 2, 2026
55 checks passed
@Git-on-my-level
Git-on-my-level deleted the lane/diar-integration branch October 2, 2026 22:12
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