Skip to content

fix(listen): recover a taught person's lost speaker embedding - #10453

Merged
kodjima33 merged 1 commit into
BasedHardware:mainfrom
aryanorastar:fix/10434-recover-person-embedding
Jul 24, 2026
Merged

kodjima33 merged 1 commit into
BasedHardware:mainfrom
aryanorastar:fix/10434-recover-person-embedding

Conversation

@aryanorastar

@aryanorastar aryanorastar commented Jul 24, 2026 •

Copy link
Copy Markdown
Collaborator

What

A taught person can become permanently unmatchable, so the user sees only their own voice recognised — no matter how many times they teach anyone else.

Refs #10434.

Root cause

extract_speaker_samples stores the sample, then extracts the speaker embedding inside a try/except that only logs:

try:
    embedding = await run_blocking(sync_executor, extract_embedding_from_bytes, wav_bytes, "sample.wav")
    await run_blocking(db_executor, users_db.set_person_speaker_embedding, uid, person_id, embedding_list)
except Exception as emb_err:
    logger.error(f"Failed to extract/store speaker embedding: {emb_err} ...")

When that fails, the person keeps their (quality-verified) samples with no embedding, and nothing ever recomputes it. The listen loader requires a stored embedding, so it skips that person on every later session — and maybe_migrate_person_samples returns early for anyone already at v3, so re-teaching doesn't rescue them either.

The asymmetry that makes the symptom so lopsided: the user's own profile already self-heals from exactly this state — if its stored embedding is missing it re-extracts from the profile audio and writes it back (speakers.py, the has_speech_profile branch). People had no equivalent. Hence: own voice always recognised, everyone else never.

Fix

Give people the same fallback. When a person has samples but no stored embedding, rebuild it from their first stored sample and persist it.

Deliberately scoped so it does not reopen the quality gate. Recovery only runs for speech_samples_version >= 3. Those samples already passed verify_and_transcribe_sample when stored (the transcript that gates v3 is produced by that verification), so this restores a lost embedding rather than resurrecting a rejected one. The migrations intentionally drop embeddings for samples that fail quality, and that behaviour is untouched — which matters, because the failure mode of getting this wrong is misidentification, worse than non-identification.

Failures stay contained: one unreadable sample returns None and the remaining speakers still load.

Tests

backend/tests/unit/test_speaker_person_embedding_recovery.py:

  • recovers a v3 person whose embedding was lost, and persists it so the next session matches from storage instead of re-extracting
  • the recovered vector is shaped for compare_embeddings (matches under SPEAKER_MATCH_THRESHOLD), not merely non-None
  • a person with no samples is not recovered and storage is never touched
  • a storage/extraction failure is contained

Suites: test_speaker_id_pipeline.py + the new file → 112 passed.

Scope, honestly

This closes one deterministic path to the reported symptom — the one I could establish from the code. I can't see the reporter's account state, so I can't confirm it's the only contributor. A person can also stay unmatchable if migration fails repeatedly (maybe_migrate_person_samples returns the person unchanged on failure), which is a separate question about whether quality-rejected samples should ever be retried — a product call I've deliberately not made here.

Product invariants affected

none (verified with scripts/pr-preflight --suggest)

Failure-Class: none

No registered class covers "a derived artifact is lost by a swallowed exception and never rebuilt"; the durable guard is the recovery path plus its tests.

Review in cubic

extract_speaker_samples stores a person's speech sample, then extracts the speaker
embedding inside a try/except that only logs. When that extraction fails, the person
keeps quality-verified samples with no embedding and nothing ever recomputes it: the
listen session's loader requires a stored embedding, so it skips that person on every
later session and they can never be matched, however many times the user teaches them.

The user's own profile already self-heals from exactly this state — if its stored
embedding is missing it re-extracts from the profile audio and writes it back. People
had no equivalent, which is why a user sees their own voice recognised and no one
else's (BasedHardware#10434).

Give people the same fallback: when a person has samples but no stored embedding,
rebuild it from their first stored sample and persist it. Scoped to
speech_samples_version >= 3, whose samples already passed verify_and_transcribe_sample
when stored, so this restores a lost embedding without reopening the quality gate that
deliberately drops bad samples. Failures stay contained so one unreadable sample cannot
break loading the other speakers.

Refs BasedHardware#10434.

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

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@Git-on-my-level

Copy link
Copy Markdown
Member

Thanks for this — clean fix and a great root-cause writeup. The asymmetry between the user-profile self-heal path and the person path is exactly the kind of latent bug that's easy to miss, and your _recover_person_embedding mirrors the existing has_speech_profile fallback nicely.

A few observations from review:

  • Correctness: Using samples[0] for recovery is reasonable — these are v3+ samples that already passed verify_and_transcribe_sample, so you're restoring a lost embedding without reopening the quality gate, as noted. The persistence write-back via self.host.persistence.call(user_db.set_person_speaker_embedding, ...) matches the teach path (speaker_identification.py), so subsequent sessions match from storage instead of re-extracting. Good.
  • Containment: The try/except with typed logging and return None means a recovery failure won't break loading of other speakers — matches the surrounding load_and_run style.
  • Tests: Good coverage of the success/no-samples/failure-contained paths and the vector-shape assertion via compare_embeddings. The ENCRYPTION_SECRET/OPENAI_API_KEY env defaults follow the existing test convention in the repo.
  • Checks: The material backend gates (Backend unit suite, Listen Pusher Stack Gauntlet, Hermetic Backend E2E, Hermetic Merge Gate) are green. A few auxiliary checks (Hygiene, Formatting, Detect Changes) show cancelled on a re-run — these should clear on the next push or a check re-run.

This touches user-data persistence (speaker embeddings for taught people), so I'm flagging it for human maintainer sign-off before merge rather than approving directly. The implementation looks sound to me.


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

@Git-on-my-level Git-on-my-level added the needs-maintainer-review Needs a human maintainer to sign off before merge label Jul 24, 2026

@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.

Backend bug fix (refs #10434): recover a taught person's lost speaker embedding from their v3 samples, mirroring the own-profile self-heal. Scoped, dedicated test, all backend gates green.

@kodjima33
kodjima33 merged commit f33d177 into BasedHardware:main Jul 24, 2026
36 of 39 checks passed
undivisible added a commit to undivisible/omi that referenced this pull request Aug 1, 2026
This PR tagged the *embedding* llm_inferred and claimed that made an
inferred enrolment undoable. It did not. extract_speaker_samples stores
the speech sample first, at speech_samples_version 3, and
SpeakerMatcher._recover_person_embedding exists to rebuild a missing
embedding from samples[0] whenever a person has v3 samples and none
stored -- that is the BasedHardware#10453 self-heal. So clearing an inferred
embedding meant the next listen session rebuilt it from the same
unvetted sample. The mistake resurrected itself, silently.

Attribution now travels with the sample as well, as a path-keyed set on
the person document rather than a third array parallel to speech_samples
and speech_sample_transcripts: those two already have to be padded and
popped in lockstep, and another index-alignment invariant is another way
for them to drift the way BasedHardware#10453 did.

Recovery refuses to rebuild from an inferred sample. Passing
verify_and_transcribe_sample proves the audio is clean, not that it
belongs to the person a model named. The user-taught path is untouched
and its existing test still passes unmodified.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-maintainer-review Needs a human maintainer to sign off before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants