Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
@ fix(stt): stop a wrong language tag deleting words from a transcript
Ruben Lütke5d1cbb3f2e8e
diff --git a/jarvis/core/turn_language.py b/jarvis/core/turn_language.pyindex a535fbed48..77c11f1be7 100644--- a/jarvis/core/turn_language.py+++ b/jarvis/core/turn_language.py@@ -35,6 +35,7 @@ __all__ = ["is_substantive_turn","normalize_language_tag","resolve_output_language",+ "resolve_transcript_language","resolve_turn_language",]@@ -163,6 +164,54 @@ def resolve_turn_language(return default+def resolve_transcript_language(reported: object, text: str) -> str:+ """Which language a TRANSCRIPT may be run through text rules as.++ Sibling of :func:`resolve_turn_language`, and deliberately stricter: that+ one answers "which language do we SPEAK back", where a wrong guess sounds+ odd; this one answers "whose word list may DELETE tokens from what the user+ said", where a wrong guess removes content and reports success. Returns a+ code (``de`` / ``en`` / ``es``) or ``"unknown"`` — and ``"unknown"`` means+ *run no language's rules*, never *pick a default*.++ Precedence, and the order is the whole point:++ 1. **A tag we cannot place stays unplaced.** ``detect_text_language`` only+ knows three languages, so letting it overrule a "French" or "ja" tag+ would relabel that utterance as whichever of the three it scored highest+ on and then run THAT language's word lists over it. ``unknown`` is the+ honest answer for ~95 of the 100 recognition languages STT supports.+ 2. **Otherwise the TEXT outranks a tag that contradicts it.** The cloud+ Whisper APIs report a language on every request and report it+ confidently when it is wrong — the live history has German utterances+ tagged "English", and ``[stt].language`` pins make the provider echo the+ pin back for speech in any language at all (forensic 2026-06-10). A+ filler list applied on that word deletes function words from a sentence+ it has no business touching: German "um" is the English hesitation+ sound, so "Kümmere dich um das Update" came back as "Kümmere dich das+ Update" — grammatically broken, and the cleanup reported a clean success+ (2026-07-30). # i18n-allow: verbatim German transcript under test+ 3. **Ambiguous text defers to the tag.** Text too short or too neutral to+ place ("ok", a bare proper noun) leaves the provider's reading standing.++ Pure set lookups, no IO — safe on the voice critical path.+ """+ lowered = str(reported or "").strip().lower()+ tag_code = normalize_language_tag(lowered)+ if not (text or "").strip():+ return tag_code+ detected = detect_text_language(text)+ if detected != "unknown" and (+ # Nothing to contradict: no tag at all, or one that says "I could not+ # tell".+ lowered in ("", "auto", "unknown", "und")+ # A tag we CAN place, which the text disagrees with.+ or (tag_code != "unknown" and tag_code != detected)+ ):+ return detected+ return tag_code++def is_substantive_turn(text: str) -> bool:"""True if *text* is long enough to (re)define the conversation language.diff --git a/jarvis/dictation/cleanup.py b/jarvis/dictation/cleanup.pyindex a5f57d4ea0..57419941a4 100644--- a/jarvis/dictation/cleanup.py+++ b/jarvis/dictation/cleanup.py@@ -66,9 +66,23 @@ from dataclasses import dataclass#: is a content word in ANY language this module serves does not belong in a#: list applied on a provider's word. The longer spellings ("erm", "ahh",#: "ehh") stay: no language spells a word that way.+#:+#: DE-MINED again on 2026-07-30: "um" left the English table for exactly the+#: same reason, and it was the most damaging entry of the family. It is the+#: canonical English hesitation sound AND one of the highest-frequency German+#: prepositions ("um fünf Uhr", "es geht um", "kümmere dich um"), so a German+#: utterance tagged English lost the preposition out of the MIDDLE of the+#: sentence: "Kümmere dich um das Update" was delivered as "Kümmere dich das+#: Update". # i18n-allow: verbatim German transcript under test+#: One dropped function word there is a fraction of a percent of the text, so+#: the destruction ceiling never fires and nothing is reported — the sentence+#: simply arrives ungrammatical and the router acts on a mangled instruction.+#: English dictation keeps "umm"/"ummm" (no language spells a word that way);+#: a bare spoken "um" now survives into English text, which is the cheap half+#: of this trade and visible to the person who said it.FILLER_WORDS: dict[str, tuple[str, ...]] = {"en": (- "uh", "uhh", "uhhh", "um", "umm", "ummm",+ "uh", "uhh", "uhhh", "umm", "ummm","erm", "ahh","hm", "hmm", "hmmm", "mhm", "mm", "mmm",),diff --git a/jarvis/plugins/stt/transcript_filter.py b/jarvis/plugins/stt/transcript_filter.pyindex fbeb5d6571..bead48d20b 100644--- a/jarvis/plugins/stt/transcript_filter.py+++ b/jarvis/plugins/stt/transcript_filter.py@@ -282,6 +282,41 @@ def apply_phonetic_fixes(text: str, language: str | None) -> str:return out+def resolve_language(text: str, language: str | None) -> str | None:+ """Which language's word lists may run on ``text``. ``None`` = none of them.++ The provider's word is a HINT here, never the verdict. Cloud Whisper+ endpoints answer with a language on every request and answer confidently+ when they are wrong, and a ``[stt].language`` pin makes them echo the pin+ back for speech in any language at all. Every rule that keys off this+ string DELETES tokens, so a wrong tag is not a cosmetic mislabel — it runs+ one language's filler list over another language's sentence and removes+ words that carry meaning there (the German preposition "um" is the English+ hesitation sound; see ``FILLER_WORDS`` in :mod:`jarvis.dictation.cleanup`).++ So the decision goes through the canonical resolver+ (:func:`jarvis.core.turn_language.resolve_transcript_language`) — the same+ one the dictation lane uses — rather than being re-derived here (CLAUDE.md+ §1: no layer re-derives the language). Fails soft: if that module cannot be+ imported, the provider's tag is normalised on its own, which is the+ behaviour this function replaced.+ """+ try:+ from jarvis.core.turn_language import resolve_transcript_language++ code = resolve_transcript_language(language, text)+ return None if code == "unknown" else code+ except Exception as exc: # noqa: BLE001 — degrade to the tag alone+ log.debug("Transcript language resolution unavailable (%s).", exc)+ try:+ from jarvis.dictation.cleanup import normalize_language++ return normalize_language(language)+ except Exception as exc: # noqa: BLE001 — degrade to the neutral rules+ log.debug("Language normalisation unavailable (%s).", exc)+ return None++def _delegated_cleanup(text: str, *, language: str | None, remove_fillers: bool) -> tuple[str, str]:@@ -331,16 +366,14 @@ def clean_stt_text(out = collapse_repetitions(out)out = repair_stutters(out)- # One resolved language for the two rule sets that need one, taken from- # the cleanup module so "German" / "de-DE" / "de" mean the same thing- # here as they do there.- lang: str | None = None- try:- from jarvis.dictation.cleanup import normalize_language-- lang = normalize_language(language)- except Exception as exc: # noqa: BLE001 — degrade to the neutral rules- log.debug("Language normalisation unavailable (%s).", exc)+ # One resolved language for the two rule sets that need one. Resolved+ # from the tag AND the text (see :func:`resolve_language`), so a+ # confidently wrong provider tag can no longer point one language's+ # word list at another language's sentence. The repaired text is what+ # gets read, not the raw payload: the character normalisation above is+ # what makes a German umlaut spell as one codepoint, and the detector+ # scores umlauts.+ lang = resolve_language(out, language)out = apply_phonetic_fixes(out, lang)out, reason = _delegated_cleanup(@@ -369,5 +402,6 @@ __all__ = ["collapse_repetitions","normalize_characters","repair_stutters",+ "resolve_language","strip_wrapping_quotes",]diff --git a/jarvis/speech/pipeline.py b/jarvis/speech/pipeline.pyindex 7c95c00c11..43a1428082 100644--- a/jarvis/speech/pipeline.py+++ b/jarvis/speech/pipeline.py@@ -959,38 +959,25 @@ def resolve_dictation_language(*, pinned: str, reported: str, text: str) -> str:return pintag = str(reported or "")try:- from jarvis.core.turn_language import (- detect_text_language,- normalize_language_tag,- )-- lowered = tag.strip().lower()- tag_code = normalize_language_tag(lowered)- # No text to reason from (a hangup transcribed nothing): the tag is the- # only signal there is, but it still leaves as a code when it has one.- if not text:- return tag_code if tag_code != "unknown" else tag- detected = detect_text_language(text)- if detected != "unknown" and (- # Nothing to contradict: no tag at all, or one that says "I could- # not tell".- lowered in ("", "auto", "unknown", "und")- # A tag we CAN place, which the text disagrees with.- or (tag_code != "unknown" and tag_code != detected)- ):- log.debug(- "dictation language resolved from the transcript: %s "- "(the provider reported %r)",- detected,- tag,- )- return detected- # The tag stands — as a CODE when it has one. Reaching this line is the- # NORMAL case (the provider agreed with the text), which is exactly why- # handing the provider's own spelling on from here disarmed the guards- # on nearly every dictation.- if tag_code != "unknown":- return tag_code+ from jarvis.core.turn_language import resolve_transcript_language++ # Points 2 and 3 above live in the canonical resolver, which the voice+ # lane's transcript filter reads too — one decision, not two copies+ # that drift the first time either is touched (CLAUDE.md §1).+ code = resolve_transcript_language(tag, text)+ if code != "unknown":+ if code != normalize_language_tag(tag):+ log.debug(+ "dictation language resolved from the transcript: %s "+ "(the provider reported %r)",+ code,+ tag,+ )+ # The tag stands as a CODE whenever it has one. Reaching that case+ # is the NORMAL one (the provider agreed with the text), which is+ # exactly why handing the provider's own spelling on from here+ # disarmed the guards on nearly every dictation.+ return codeexcept Exception: # noqa: BLE001 — a detection hiccup is not fatallog.debug("dictation language detection failed", exc_info=True)return tagdiff --git a/tests/unit/core/test_turn_language.py b/tests/unit/core/test_turn_language.pyindex 1962916b38..bfad7c723e 100644--- a/tests/unit/core/test_turn_language.py+++ b/tests/unit/core/test_turn_language.py@@ -22,6 +22,7 @@ from jarvis.core.turn_language import (detect_text_language,normalize_language_tag,resolve_output_language,+ resolve_transcript_language,resolve_turn_language,)@@ -214,3 +215,54 @@ def test_conversation_language_used_as_default_for_ambiguous_substantive() -> Noassert resolve_output_language("auto", None, "Spotify Netflix Berlin", conversation_language="de") == "de"+++# ---------------------------------------------------------------------------+# resolve_transcript_language — whose word list may DELETE tokens (2026-07-30)+# ---------------------------------------------------------------------------+#+# Stricter than resolve_turn_language on purpose: that one picks the language we+# answer IN, where a wrong guess merely sounds odd. This one picks the language+# whose filler/phonetic tables are run OVER what the user said, where a wrong+# guess removes words and reports success. So it never invents a default — an+# unplaceable tag resolves to "unknown", meaning "run no rules at all".+++def test_a_wrong_provider_tag_loses_to_the_text() -> None:+ # The live shape: a cloud Whisper endpoint answering "English" for German+ # speech. Trusting the tag ran the English filler list over the sentence and+ # deleted the preposition "um" out of its middle.+ assert resolve_transcript_language(+ "English", "Kümmere dich um das Update" # i18n-allow: fixture under test+ ) == "de"+++def test_a_pinned_tag_echoed_back_loses_to_the_text() -> None:+ # `[stt].language = "de"` makes the provider echo "german" for speech in any+ # language at all (forensic 2026-06-10).+ assert resolve_transcript_language("german", "Please open the report") == "en"+++def test_an_agreeing_tag_stands_as_a_code() -> None:+ assert resolve_transcript_language("German", "Mach bitte das Licht an") == "de"+++def test_an_unplaceable_tag_stays_unknown_rather_than_guessing() -> None:+ # detect_text_language only knows de/en/es, so letting it overrule a French+ # tag would relabel French as whichever of the three it scored highest on and+ # then run THAT language's rules over it. "unknown" = run nothing.+ assert resolve_transcript_language("French", "Je pense que c'est bien") == "unknown"+++def test_ambiguous_text_leaves_the_tag_standing() -> None:+ assert resolve_transcript_language("English", "Spotify Berlin") == "en"+++def test_no_tag_at_all_is_answered_from_the_text() -> None:+ for tag in ("", None, "auto", "unknown"):+ assert resolve_transcript_language(tag, "Mach bitte das Licht an") == "de"+++def test_no_text_at_all_falls_back_to_the_tag() -> None:+ assert resolve_transcript_language("German", "") == "de"+ assert resolve_transcript_language("", "") == "unknown"diff --git a/tests/unit/dictation/test_cleanup.py b/tests/unit/dictation/test_cleanup.pyindex 3e5ba8ebbe..b933f2bfbd 100644--- a/tests/unit/dictation/test_cleanup.py+++ b/tests/unit/dictation/test_cleanup.py@@ -25,7 +25,7 @@ from jarvis.dictation.cleanup import (("text", "language", "expected"),[(- "Uh, I think we should um ship it tomorrow.",+ "Uh, I think we should umm ship it tomorrow.","en","I think we should ship it tomorrow.",),@@ -83,9 +83,10 @@ def test_content_words_are_never_removed(text: str, language: str) -> None:def test_filler_inside_a_word_is_not_touched() -> None:- """Whole-word matching only — "umbrella" must not lose its "um"."""- text = "The umbrella and the ehrenamt are fine."- assert clean_transcript(text, language="en").text == text+ """Whole-word matching only — "kommen" must not lose its "mm"."""+ # i18n-allow: German fixture under test (§1 list #4)+ text = "Wir kommen gleich, das Hemd ist da."+ assert clean_transcript(text, language="de").text == text# --------------------------------------------------------------------------@@ -113,6 +114,31 @@ def test_german_text_tagged_english_keeps_its_pronouns() -> None:assert result.text == text+ "text",+ [+ # i18n-allow: German fixtures under test (§1 list #4)+ "Kümmere dich um das Update.",+ "Erinnere mich um fünf Uhr an den Termin.",+ "Es geht um die Rechnung von gestern.",+ "Ich gehe um das Haus herum.",+ ],+)+def test_german_preposition_um_survives_an_english_tag(text: str) -> None:+ """The 2026-07-30 report: a preposition vanished out of the sentence middle.++ "um" is the canonical English hesitation sound and one of the most common+ German prepositions, so a German utterance tagged "English" came back+ without it — "Kümmere dich um das Update" as "Kümmere dich das Update".+ One function word is a small fraction of the text, so the destruction+ ceiling never fired: the sentence arrived ungrammatical, reported clean,+ and the router acted on the mangled instruction.+ """+ result = clean_transcript(text, language="English")+ assert result.removed_words == 0+ assert result.text == text++def test_german_eh_survives_a_spanish_tag() -> None:"""The mirror hole: Spanish "eh" against German "eh" ("anyway")."""text = "Das mache ich eh morgen, das ist eh klar." # i18n-allow: fixture (§1 #4)@@ -129,6 +155,7 @@ def test_german_eh_survives_a_spanish_tag() -> None:("eh", "en", "ordinary German for 'anyway'"),("eh", "es", "ordinary German for 'anyway'"),("ah", "en", "a spoken interjection that carries meaning of its own"),+ ("um", "en", "one of the most common German prepositions"),],)def test_a_filler_must_be_meaningless_in_every_supported_language(@@ -147,15 +174,15 @@ def test_a_filler_must_be_meaningless_in_every_supported_language(def test_all_filler_input_is_refused_rather_than_emptied() -> None:- result = clean_transcript("um uh umm", language="en")+ result = clean_transcript("umm uh uhh", language="en")assert result.applied is Falseassert result.reason == "ceiling"- assert result.text == "um uh umm"+ assert result.text == "umm uh uhh"def test_absolute_cap_refuses_a_short_sentence_losing_too_many_words() -> None:# 8 words, 4 of them filler -> past the absolute cap for short texts.- text = "um uh umm uhh the plan is ready"+ text = "umm uh uhh mhm the plan is ready"result = clean_transcript(text, language="en")assert result.applied is Falseassert result.reason == "ceiling"@@ -171,13 +198,13 @@ def test_short_sentence_with_two_fillers_is_still_cleaned() -> None:def test_long_text_uses_the_proportional_ceiling() -> None:body = " ".join(["word"] * 40)- result = clean_transcript(f"um {body}", language="en")+ result = clean_transcript(f"umm {body}", language="en")assert result.applied is Trueassert result.removed_words == 1def test_ceiling_is_configurable() -> None:- text = " ".join(["um"] * 5 + ["word"] * 15) # 25 % filler in 20 words+ text = " ".join(["umm"] * 5 + ["word"] * 15) # 25 % filler in 20 wordslenient = clean_transcript(text, language="en", max_removed_fraction=0.9)strict = clean_transcript(text, language="en", max_removed_fraction=0.01)assert lenient.applied is True@@ -235,14 +262,14 @@ def test_language_NAMES_are_accepted_not_just_codes(def test_cleanup_runs_when_the_provider_reports_a_language_name() -> None:- result = clean_transcript("Uh, I think we should um ship it.", language="English")+ result = clean_transcript("Uh, I think we should umm ship it.", language="English")assert result.applied is Trueassert result.text == "I think we should ship it."def test_unknown_language_is_a_no_op_not_an_english_guess() -> None:"""Applying English rules to French speech is how content gets eaten."""- text = "Euh, je pense que um c'est bien."+ text = "Euh, je pense que umm c'est bien."result = clean_transcript(text, language="fr")assert result.applied is Falseassert result.reason == "no_rules"@@ -250,10 +277,10 @@ def test_unknown_language_is_a_no_op_not_an_english_guess() -> None:def test_disabled_returns_the_raw_text() -> None:- result = clean_transcript("um hello", language="en", remove_fillers=False)+ result = clean_transcript("umm hello", language="en", remove_fillers=False)assert result.applied is Falseassert result.reason == "disabled"- assert result.text == "um hello"+ assert result.text == "umm hello"def test_empty_input() -> None:@@ -268,16 +295,16 @@ def test_empty_input() -> None:def test_leading_capital_is_restored_after_removing_the_first_word() -> None:- result = clean_transcript("Um, the meeting is at four.", language="en")+ result = clean_transcript("Umm, the meeting is at four.", language="en")assert result.text == "The meeting is at four."def test_lowercase_stays_lowercase() -> None:- result = clean_transcript("um the meeting is at four", language="en")+ result = clean_transcript("umm the meeting is at four", language="en")assert result.text == "the meeting is at four"def test_punctuation_is_pulled_back_onto_the_previous_word() -> None:- result = clean_transcript("We should go um, tomorrow please.", language="en")+ result = clean_transcript("We should go umm, tomorrow please.", language="en")assert " " not in result.textassert " ," not in result.textdiff --git a/tests/unit/dictation/test_tidy_transcript.py b/tests/unit/dictation/test_tidy_transcript.pyindex c0e374825c..9cbdc545f6 100644--- a/tests/unit/dictation/test_tidy_transcript.py+++ b/tests/unit/dictation/test_tidy_transcript.py@@ -55,7 +55,7 @@ def test_filler_removal_no_longer_glues_the_following_ellipsis() -> None:def test_a_space_before_a_lone_period_is_still_pulled_back() -> None:"""The narrowed rule must not stop doing the job it was written for."""- result = clean_transcript("The meeting is at four um.", language="en")+ result = clean_transcript("The meeting is at four umm.", language="en")assert result.text == "The meeting is at four."diff --git a/tests/unit/plugins/stt/test_openrouter_stt.py b/tests/unit/plugins/stt/test_openrouter_stt.pyindex 95a7a1fd53..46cb01fff7 100644--- a/tests/unit/plugins/stt/test_openrouter_stt.py+++ b/tests/unit/plugins/stt/test_openrouter_stt.py@@ -189,7 +189,7 @@ async def test_gateway_artifacts_are_cleaned_and_the_raw_text_is_kept() -> None:owns a user switch for filler removal — still transcribes from it."""payload = {- "text": '"Um, turn on the light. Thank you. Thank you. Thank you."',+ "text": '"Umm, turn on the light. Thank you. Thank you. Thank you."',"language": "English",}diff --git a/tests/unit/plugins/stt/test_transcript_filter.py b/tests/unit/plugins/stt/test_transcript_filter.pyindex cfb6a401dc..4754986ca3 100644--- a/tests/unit/plugins/stt/test_transcript_filter.py+++ b/tests/unit/plugins/stt/test_transcript_filter.py@@ -17,6 +17,7 @@ from jarvis.plugins.stt.transcript_filter import (collapse_repetitions,normalize_characters,repair_stutters,+ resolve_language,strip_wrapping_quotes,)@@ -162,7 +163,7 @@ def test_no_phonetic_source_is_a_real_word_elsewhere() -> None:def test_english_filler_and_quotes_in_one_pass() -> None:- raw = '"Uh, I think we should um ship it."'+ raw = '"Uh, I think we should umm ship it."'assert clean_stt_text(raw, language="en") == "I think we should ship it."@@ -194,7 +195,7 @@ def test_empty_and_blank_input_is_returned_unchanged() -> None:def test_a_transcript_of_only_filler_survives_the_destruction_ceiling() -> None:"""The delegated ceiling: rules that leave nothing behind are a defect."""- assert clean_stt_text("um uh umm", language="en") == "um uh umm"+ assert clean_stt_text("umm uh uhh", language="en") == "umm uh uhh"def test_cleanup_never_raises_on_a_broken_rule(@@ -207,3 +208,55 @@ def test_cleanup_never_raises_on_a_broken_rule("jarvis.plugins.stt.transcript_filter.collapse_repetitions", _boom)assert clean_stt_text("turn on the light", language="en") == "turn on the light"+++# ----------------------------------------------------------------------+# The provider's language tag is a hint, not the verdict (2026-07-30)+# ----------------------------------------------------------------------+#+# Every rule keyed off that string DELETES tokens, and the cloud endpoints+# report a language confidently when it is wrong ("English" for German speech;+# a `[stt].language` pin echoed back for speech in any language). So the filter+# resolves the language from the tag AND the repaired text, through the same+# canonical resolver the dictation lane uses.+++ "text",+ [+ # i18n-allow: German speech under test (§1 list #4)+ "Kümmere dich um das Update",+ "Erinnere mich um fünf Uhr an den Termin",+ "Es geht um die Rechnung von gestern",+ ],+)+def test_german_speech_mistagged_english_keeps_its_prepositions(text: str) -> None:+ """The reported defect: a preposition vanished from the sentence middle.++ Two independent guards now stop it — "um" left the English filler table,+ and a tag the text contradicts no longer selects that table at all — so the+ sentence survives whichever spelling of "English" the provider sends.+ """+ for tag in ("en", "English", "english", "en-US"):+ assert clean_stt_text(text, language=tag) == text+++def test_a_mistagged_transcript_resolves_to_the_language_it_is_in() -> None:+ assert resolve_language("Mach bitte das Licht an", "English") == "de" # i18n-allow: fixture+++def test_an_agreeing_tag_is_kept() -> None:+ assert resolve_language("Turn on the lights please", "English") == "en"+++def test_a_language_we_have_no_rules_for_stays_a_no_op() -> None:+ # Neither the French tag nor the French text may resolve to one of the+ # three tables — that is how "je" would be judged by German rules.+ assert resolve_language("Je pense que c'est bien", "French") is None+++def test_english_fillers_still_go_when_the_text_agrees() -> None:+ assert (+ clean_stt_text("Uh, I think we should umm ship it.", language="en")+ == "I think we should ship it."+ )diff --git a/tests/unit/plugins/stt/test_transcript_filter_parity.py b/tests/unit/plugins/stt/test_transcript_filter_parity.pyindex 4f176dcd5d..3de1a097e3 100644--- a/tests/unit/plugins/stt/test_transcript_filter_parity.py+++ b/tests/unit/plugins/stt/test_transcript_filter_parity.py@@ -28,7 +28,7 @@ from jarvis.plugins.stt import gemini_api, groq_api, openai_api, openrouter_stt#: One payload carrying three artifact classes at once: an outer quote pair the#: model added, a hesitation sound, and a decoder repetition loop.-DIRTY_TEXT = '"Um, turn on the light. Thank you. Thank you. Thank you."'+DIRTY_TEXT = '"Umm, turn on the light. Thank you. Thank you. Thank you."'CLEAN_TEXT = "Turn on the light. Thank you."#: Modules in the package that are not providers.