Problem
4 users are generating ~1,197 errors/day from scipy.cdist dimension mismatch in speaker identification:
ValueError: XA and XB must have the same number of columns (i.e. feature dimension.)
Crash site: compare_embeddings() in speaker_embedding.py when comparing 256-dim (v3 model) vs 512-dim (v1/v2 model) embeddings.
Root Cause (verified via Firestore query)
The v2→v3 speaker embedding migration (speaker_sample_migration.py:186-190) has a bug: when a contact has no speech_samples (0 audio files), it sets speech_samples_version=3 but leaves the old 512-dim embedding untouched.
Verified on affected user 0hqtnbQeNR...:
| Contact |
emb_dim |
version |
speech_samples |
Status |
| Kat |
512 |
3 |
0 |
BUG — v3 tag, old embedding |
| John P. |
512 |
NOT SET |
0 |
Legacy, never migrated |
| Chris Bond |
256 |
3 |
1 |
Correct — re-extracted |
| Vince |
256 |
3 |
1 |
Correct — re-extracted |
The migration path: if not samples: update_version(3); return — bumps version without clearing or re-extracting the old embedding. Same bug exists in v1→v2 path (line 73-77).
Fix
PR #6240:
compare_embeddings() returns 2.0 (max distance) on dimension mismatch — crash prevention
- Migration clears
speaker_embedding when no samples exist (both v1→v2 and v2→v3)
- Hardening: transcribe.py and sync.py skip loading embeddings for contacts without speech_samples
Files to Modify
backend/utils/stt/speaker_embedding.py — dimension guard in compare_embeddings()
backend/utils/speaker_sample_migration.py — clear stale embedding in no-samples path
backend/routers/transcribe.py — skip loading embeddings without speech_samples
backend/routers/sync.py — same hardening
by AI for @beastoin
Problem
4 users are generating ~1,197 errors/day from
scipy.cdistdimension mismatch in speaker identification:Crash site:
compare_embeddings()inspeaker_embedding.pywhen comparing 256-dim (v3 model) vs 512-dim (v1/v2 model) embeddings.Root Cause (verified via Firestore query)
The v2→v3 speaker embedding migration (
speaker_sample_migration.py:186-190) has a bug: when a contact has no speech_samples (0 audio files), it setsspeech_samples_version=3but leaves the old 512-dim embedding untouched.Verified on affected user
0hqtnbQeNR...:The migration path:
if not samples: update_version(3); return— bumps version without clearing or re-extracting the old embedding. Same bug exists in v1→v2 path (line 73-77).Fix
PR #6240:
compare_embeddings()returns 2.0 (max distance) on dimension mismatch — crash preventionspeaker_embeddingwhen no samples exist (both v1→v2 and v2→v3)Files to Modify
backend/utils/stt/speaker_embedding.py— dimension guard incompare_embeddings()backend/utils/speaker_sample_migration.py— clear stale embedding in no-samples pathbackend/routers/transcribe.py— skip loading embeddings without speech_samplesbackend/routers/sync.py— same hardeningby AI for @beastoin