Skip to content

fix(backend): reject pronouns/fillers as auto-detected speaker names (#5223) - #7807

Merged
kodjima33 merged 1 commit into
mainfrom
watchdog/issue-5223-speaker-name-stopwords
Jun 11, 2026
Merged

kodjima33 merged 1 commit into
mainfrom
watchdog/issue-5223-speaker-name-stopwords

Conversation

@kodjima33

Copy link
Copy Markdown
Collaborator

Bug

#5223 / #5250: phantom speaker contacts named "It", "You", "Them" keep being created and reappear after deletion.

The toggle half of those reports ("Auto Create Speakers off but still creating") was already fixed end-to-end on main by 041f6b2 (June 1). This PR fixes the remaining half: even with the toggle ON (the default), junk pronoun contacts are still created for everyone.

Root cause

detect_speaker_from_text (backend/utils/speaker_identification.py) matches introduction patterns like \b(I am|I'm|...)\s+([A-Z][a-zA-Z]*)\b and returns whatever capitalized word follows. Run-on / smart-cased transcripts trigger it constantly:

  • "And I am It was great" → contact "It"
  • "I'm You know, the guy" → contact "You"
  • "Yeah, I'm Them and the others" → contact "Them"

(Reproduced against the real patterns — these exact phrases yield exactly the reported phantom names.) The realtime /v4/listen path then calls create_person with that name; the next conversation recreates any contact the user deleted.

Fix

Add SPEAKER_NAME_STOPWORDS (pronouns, demonstratives, question words, common fillers) and reject a captured name when it's a stopword, continuing to the next pattern. Real introductions are unaffected ("I am John", "I'm Will", "Soy Carlos", "Je m'appelle Sophie" all still detect — verified).

Covers both creation/assignment paths (realtime transcribe.py and offline sync.py) since both go through detect_speaker_from_text.

Tests

  • 7 parametrized regression cases for the phantom-name transcripts (all → None)
  • Positive guard test that genuine introductions still detect
  • File tests/unit/test_speaker_id_pipeline.py is already in test.sh (runs in CI)
  • Verified locally by exercising the patterns + stopword logic directly (pytest not installed locally); black clean

🤖 automated by hourly watchdog; opened for review, not merged.

Fixes #5223
Fixes #5250

🤖 Generated with Claude Code

…5223)

detect_speaker_from_text's introduction regexes ("I am X", "I'm X", ...)
capture whatever capitalized word follows, so run-on transcripts like
"I'm It was great" / "I'm You know..." / "I'm Them and..." produced
phantom speaker contacts named "It", "You", "Them" — exactly the junk
reported in #5223/#5250. Deleting them didn't help: the next conversation
recreated them.

Add a stopword guard: a captured name that is a pronoun, demonstrative,
question word, or common filler is rejected and pattern matching
continues. Real introductions ("I am John", "I'm Will", "Soy Carlos")
are unaffected. Applies to both creation paths (realtime /v4/listen and
offline sync) since both go through detect_speaker_from_text.

Adds parametrized regression tests for the reported phantom names.
@greptile-apps

greptile-apps Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds a SPEAKER_NAME_STOPWORDS frozenset and a single-line guard in detect_speaker_from_text to prevent pronouns, demonstratives, and common filler words captured by introduction-pattern regexes from being returned as speaker names — fixing the phantom contact bug (#5223).

  • speaker_identification.py: 81 stopword entries (frozenset for O(1) lookup) covering English pronouns, question words, and high-frequency fillers; detect_speaker_from_text now skips any match whose lowercased name hits the set, then continues to the next pattern rather than returning early.
  • test_speaker_id_pipeline.py: 7 parametrized regression cases for the exact phantom-name transcripts from the bug report, plus a positive guard test confirming real introductions ("I am John", "My name is Alice") are unaffected.

Confidence Score: 4/5

Safe to merge — the change is narrowly scoped to one guard condition and both creation paths benefit automatically since they share detect_speaker_from_text.

The logic is correct, the lookup is efficient, and the regression tests directly cover the reported phantom-name transcripts. The only non-trivial concern is that a handful of stopwords (notably 'her') coincide with legitimate given names in non-English languages, which could produce silent false negatives for a small set of users — but this is a very niche edge case and does not affect the main fix.

No files require special attention; speaker_identification.py is the primary change and its logic is straightforward.

Important Files Changed

Filename Overview
backend/utils/speaker_identification.py Adds SPEAKER_NAME_STOPWORDS frozenset and a single-line guard in detect_speaker_from_text to reject pronouns/fillers captured by intro patterns; logic is correct and lookup is O(1), but a handful of stopwords (e.g. 'her', 'good', 'well') coincide with rare real surnames or cross-language names
backend/tests/unit/test_speaker_id_pipeline.py Adds 7 parametrized regression cases covering the phantom-name transcripts from #5223, a positive guard test for real introductions, and a standalone positive-detection test; coverage is solid for the targeted fix

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["detect_speaker_from_text(text)"] --> B["Iterate patterns_to_check"]
    B --> C{"re.search(pattern, text)"}
    C -- "No match" --> B
    C -- "Match" --> D["name = match.groups()[-1]"]
    D --> E{"name AND len >= 2?"}
    E -- "No" --> B
    E -- "Yes" --> F{"name.lower() in STOPWORDS?"}
    F -- "Yes - pronoun/filler" --> B
    F -- "No - real name" --> G["return name.capitalize()"]
    B -- "Exhausted" --> H["return None"]
Loading

Reviews (1): Last reviewed commit: "fix(backend): reject pronouns/fillers as..." | Re-trigger Greptile

Comment on lines +246 to +248
'her',
'his',
'hers',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 'her' (and 'him') block real given names cross-language

'her' is a common Vietnamese given name (e.g. "Tôi là Her") and 'him' appears in some cultures as well. Because detect_speaker_from_text applies all patterns without language filtering, a Vietnamese speaker whose name is "Her" would match the Vietnamese pattern and then have that name silently dropped by the stopword guard. The tradeoff is reasonable for the English use-case, but worth noting for future expansion of the stopword list — words that are pronouns in one language may be names in another.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! Is there a plan to make detect_speaker_from_text language-aware so that the stopword set can be scoped to the detected language?

Comment on lines +283 to +286
def test_real_name_after_stopword_guard(self):
"""Genuine introductions still detect after the stopword guard."""
assert detect_speaker_from_text("I am John") == "John"
assert detect_speaker_from_text("My name is Alice") == "Alice"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Positive guard test duplicates existing POSITIVE_CASES entries without parametrization

test_real_name_after_stopword_guard hardcodes "John" and "Alice", both of which already appear in POSITIVE_CASES and are exercised by test_positive_detection. The intent — confirming real names survive the stopword check — is good, but near-miss stopword names (e.g. a name starting with "He", "So", or "Will") would be more valuable additions to POSITIVE_CASES rather than a separate non-parametrized method.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@kodjima33
kodjima33 merged commit ab587af into main Jun 11, 2026
3 checks passed
@kodjima33
kodjima33 deleted the watchdog/issue-5223-speaker-name-stopwords branch June 11, 2026 05:56
@undivisible undivisible added the AI label Aug 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

2 participants