Repository navigation
feat(observability): count live unnamed speaker ordinals per session - #23556
Conversation
#23533 (85f080f) defers a live "Speaker N" ordinal until an unnamed voice holds five seconds of non-overlapping placed speech, but nothing measured whether per-session ordinal churn actually fell after the listen roll - David's consecutive Speaker 4-8 lines had no metric. Add omi_live_speaker_ordinals_per_session, a histogram observed once per listen session at teardown. LiveSpeakerOrdinalTracker rides the same final segment stream the collapse monitor sees (routers/listen/transcripts _speaker_detection, after scope stamping and speaker-id assignment) and applies the display deferral's own qualification: a voice key (speaker_id_scope, speaker_id) mints one ordinal at MIN_EVIDENCE_SECONDS of unioned placed speech, and a voice the session named (owner or person, per-segment or in the matcher's final map) never mints one. The companion omi_live_speaker_scope_rotations_total counts scope/epoch rotations over the same sessions, so ordinal churn is separable from real multi-speaker conversations. Both metrics are label-free; the tracker is bounded (128 voices, 512 intervals per voice), never feeds speaker decisions, and its recording never raises into teardown. The pipeline doc's live-speaker-epochs section names the PromQL to watch after listen rolls. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ac6a7ee7ab
ℹ️ 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".
| # After the transcript loop drained and before the matcher's maps clear: | ||
| # the ordinal ledger needs both the final segments and final naming. | ||
| record_live_speaker_ordinals(getattr(self, 'speaker_ordinal_tracker', None), self.speakers) |
There was a problem hiding this comment.
Capture named voices before each matcher generation is cleared
When one listen connection spans multiple conversations, names learned in an earlier conversation can be lost from this metric. SpeakerMatcher.initialize_profiles() calls clear() on a conversation change, which empties both speaker_to_person and _voice_scopes. Since the tracker observes incoming segments before asynchronous matching and only folds in the matcher map here at session teardown, an earlier voice that was subsequently named can remain in _qualified without entering _named. The histogram then counts that named voice as an unnamed ordinal. Snapshot naming before each matcher reset, or notify the tracker when an identity is published.
Useful? React with 👍 / 👎.
| intervals = self._intervals.get(key) | ||
| if intervals is None: | ||
| if len(self._intervals) >= MAX_TRACKED_VOICES: | ||
| return | ||
| intervals = self._intervals[key] = [] |
There was a problem hiding this comment.
Apply the voice limit to the complete tracked inventory
In long-running sessions with repeated provider epochs or new speaker IDs, this guard does not enforce the advertised 128-voice ceiling: it counts only voices still accumulating evidence, and qualification immediately removes each voice from _intervals while retaining it in _qualified. Feeding 1,000 distinct six-second voices therefore retains and reports all 1,000. _named and _scopes also grow before this guard runs. Bound the complete voice/scope inventory rather than just pending intervals so session telemetry cannot grow indefinitely with churn.
Useful? React with 👍 / 👎.
| scope = scope if isinstance(scope, str) else '' | ||
| if scope: | ||
| self._scopes.add(scope) | ||
| key = (scope, speaker_id) |
There was a problem hiding this comment.
Keep display qualification separate across conversations
When a listen connection rolls over to another conversation without changing provider scope, the allocator retains the same speaker ID, but this key combines speech from both conversations using their conversation-relative offsets. For example, three seconds at offsets 10–13 in the first conversation and three seconds at offsets 0–3 in the next qualify as six seconds here, although neither conversation displays an ordinal: Flutter's SpeakerNames.forSegments() applies the five-second floor to the current conversation's segments, and CaptureController replaces that segment list when the conversation changes. Track qualification per conversation/presentation scope before aggregating the session result; otherwise conversation rollovers can increase the reported ordinal count without any visible label being minted.
Useful? React with 👍 / 👎.
| speaker_id = segment.get('speaker_id') | ||
| if isinstance(speaker_id, bool) or not isinstance(speaker_id, int): | ||
| return |
There was a problem hiding this comment.
Exclude Omi's reserved speaker ID from unnamed ordinals
During onboarding, OnboardingHandler.send_current_question() injects synthetic question segments through self.transcripts.enqueue with speaker ID 99, is_user=False, and no person_id. The three current questions together exceed the five-second floor, so this tracker counts Omi itself as an unnamed ordinal even without any qualifying human voice. Both display_participants() and Flutter's SpeakerNames explicitly render this reserved ID as Omi rather than allocating an anonymous label. Exclude OMI_SPEAKER_ID_SENTINEL from qualification so onboarding sessions do not inflate the churn histogram.
Useful? React with 👍 / 👎.
Why
David saw consecutive live lines labelled Speaker 4, 5, 6, 7, 8. #23533 (85f080f) defers live ordinals for short unnamed voices, but we had no metric showing whether per-session "Speaker N" churn actually fell after the listen roll.
What
omi_live_speaker_ordinals_per_session— a label-free histogram observed once per listen session at teardown. The value is the number of distinct visible unnamed speaker ordinals the session minted after fix(speakers): defer short live epoch labels and gate owner evidence #23533's deferral:LiveSpeakerOrdinalTrackerobserves the same final live segment stream the collapse monitor sees (routers/listen/transcripts.py::_speaker_detection, after scope stamping and speaker-id assignment) and applies the display deferral's own qualification — a voice key(speaker_id_scope, speaker_id)mints one ordinal atMIN_EVIDENCE_SECONDS(5 s) of unioned, non-overlapping placed speech; voices the session named (owner or person — per-segment or through the matcher's final map) mint none.omi_live_speaker_scope_rotations_total— companion counter of scope/epoch rotations (provider transitions, reconnect epochs) over the same sessions, so churn is separable from real multi-speaker conversations.routers/listen/runtime.py::_teardown_components, after the transcript loop drains and before the matcher's maps clear).backend/docs/listen_pusher_pipeline.mdxlive-speaker-epochs section names the PromQL to watch after listen rolls.PromQL
rate(omi_live_speaker_ordinals_per_session_sum[1h]) / rate(omi_live_speaker_ordinals_per_session_count[1h])histogram_quantile(0.95, rate(omi_live_speaker_ordinals_per_session_bucket[1h]))rate(omi_live_speaker_scope_rotations_total[1h]) / rate(omi_listen_ws_close_total[1h])Success after the listen roll: ordinals fall while rotations/session holds flat — that is the deferral working, not conversations gaining fewer speakers.
Tests
tests/unit/test_live_speaker_ordinals_metric.py— deferral floor and union semantics (overlap/replay never double-count), named-voice exclusion (segment flags + matcher map at close), scope-rotation counting, unplaced/malformed/id-less segments, bounded inventory, histogram/counter observation, teardown-safe recording, and the_speaker_detectionfeed through a realTranscriptProcessor.Run:
BACKEND_UNIT_TEST_FILE_LIST=<list file> bash test.shinbackend/— new file (11 tests) plus the focused neighbors (test_listen_runtime_regressions,test_listen_ws_close_metric,test_live_speaker_epochs,test_live_transcript_merge,test_audio_timeline_round4,test_speaker_display_no_raw_ids,test_episodes_incremental_live,test_live_speaker_collapse,test_live_speaker_carry): all pass.scripts/typecheck.shclean;scan_async_blockersandcheck_speaker_label_interpolation.pyclean.Line-Count-Exception: backend/routers/listen/transcripts.py | 1670 -> 1673 | three-line ordinal-tracker feed at the existing final-segment observation loop (same choke point the collapse monitor uses)
🤖 Generated with Claude Code