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(wake): stale custom model no longer hijacks a newly chosen wake phrase
Ruben Lütkeb85b657919c6
diff --git a/jarvis/speech/wake_phrase.py b/jarvis/speech/wake_phrase.pyindex 79de7d3ccf..9e1ef9f64e 100644--- a/jarvis/speech/wake_phrase.py+++ b/jarvis/speech/wake_phrase.py@@ -199,6 +199,27 @@ def _canonical_keyword(phrase: str) -> str:return "_".join(core) if core else "wake"+def custom_model_matches_phrase(model_path: str, phrase: str) -> bool:+ """True when a trained wake-model FILE belongs to ``phrase``.++ The trainer names models after their phrase (``hey_nico.onnx`` for+ "Hey Nico"), so ownership is decided by comparing the sound-folded core+ tokens of the phrase against the sound-folded tokens of the file stem.+ Sound-folding keeps spelling variants of the same word together+ ("Hey Niko" still owns ``hey_nico.onnx``). An empty phrase owns nothing.++ Why this exists (live bug 2026-07-02): ``custom_model_path`` stays in the+ config when the user changes the wake phrase in Settings, and the resolver+ used to let ANY custom path win — the stale model then kept detecting the+ OLD word and the new phrase was deaf ("only Hey Nico still works").+ """+ core = [sound_fold(t) for t in phrase_core_for_match(phrase)]+ if not core:+ return False+ stem_tokens = {sound_fold(t) for t in normalize_phrase_for_match(Path(model_path).stem)}+ return all(token in stem_tokens for token in core)++# ---------------------------------------------------------------------------# Engine resolution# ---------------------------------------------------------------------------@@ -268,9 +289,24 @@ def resolve_wake_plan(cfg: Any, *, local_whisper_available: bool) -> WakeWordPlamatcher = compile_wake_matcher(phrase, fuzzy_ratio=fuzzy)canonical = _canonical_keyword(phrase)- # 1. Explicit custom ONNX (or any custom path on a non-stt engine).+ # 1. Custom ONNX model. Auto-adopted ONLY when it belongs to the+ # configured phrase; an explicit engine="custom_onnx" still forces it+ # regardless of its filename (the user's own training, their own naming).+ # Live bug 2026-07-02: the phrase was changed to "Hey Fable" in Settings,+ # but the stale hey_nico.onnx path left in config used to win here+ # unconditionally — the NICO model stayed the detector and the new phrase+ # was deaf. A stale model falls through to the normal any-phrase path and+ # is kept in config so switching the phrase back re-adopts it.+ custom_missing = False+ custom_stale = Falseif custom_path:- if Path(custom_path).is_file():+ if not Path(custom_path).is_file():+ custom_missing = True+ log.warning("Custom wake ONNX not found: %s", custom_path)+ # fall through — try STT match, else degrade.+ elif engine_pref == "custom_onnx" or custom_model_matches_phrase(+ custom_path, phrase+ ):return WakeWordPlan(phrase=phrase,engine="custom_onnx",@@ -290,12 +326,20 @@ def resolve_wake_plan(cfg: Any, *, local_whisper_available: bool) -> WakeWordPla# tolerates ASR spelling drift ("Niko" for "Nico").verify_prefix=True,)- log.warning("Custom wake ONNX not found: %s", custom_path)- # fall through — try STT match, else degrade.+ else:+ custom_stale = True+ log.info(+ "Custom wake model '%s' belongs to a different phrase — "+ "resolving '%s' through the normal engine chain.",+ Path(custom_path).name,+ phrase,+ )# 2. Known pretrained openWakeWord model (CPU, instant, offline).known = match_known_oww_model(phrase)- if engine_pref in ("auto", "openwakeword") and known and not custom_path:+ if engine_pref in ("auto", "openwakeword") and known and (+ not custom_path or custom_stale+ ):model_path = resolve_oww_model_path(known)if model_path is not None:return WakeWordPlan(@@ -319,12 +363,21 @@ def resolve_wake_plan(cfg: Any, *, local_whisper_available: bool) -> WakeWordPlaor (engine_pref == "openwakeword" and not known))if want_stt and local_whisper_available:- degraded = bool(custom_path) or (engine_pref == "openwakeword" and not known)- if custom_path:+ # A STALE custom model (belongs to another phrase) is NOT a degrade:+ # the transcript match IS the regular path for the new phrase, and the+ # model stays configured for when the user switches back.+ degraded = custom_missing or (engine_pref == "openwakeword" and not known)+ if custom_missing:message = (f"Custom ONNX not found ({custom_path}); ""using local-Whisper transcript match instead.")+ elif custom_stale:+ message = (+ f"Custom wake model '{Path(custom_path).name}' belongs to a "+ f"different phrase; '{phrase}' uses the local-Whisper "+ "transcript match."+ )else:message = f"Custom phrase '{phrase}' via local-Whisper transcript match."return WakeWordPlan(@@ -370,6 +423,7 @@ __all__ = ["WakeMatcher","WakeWordPlan","compile_wake_matcher",+ "custom_model_matches_phrase","resolve_wake_plan","sensitivity_to_threshold",]diff --git a/tests/unit/speech/test_wake_custom_model.py b/tests/unit/speech/test_wake_custom_model.pyindex cb6e44e6c5..542ac2ae16 100644--- a/tests/unit/speech/test_wake_custom_model.py+++ b/tests/unit/speech/test_wake_custom_model.py@@ -14,10 +14,15 @@ from __future__ import annotationsfrom types import SimpleNamespace-def _cfg(model_path: str, sensitivity: float = 0.5) -> SimpleNamespace:+def _cfg(+ model_path: str,+ sensitivity: float = 0.5,+ phrase: str = "Hey Nico",+ engine: str = "custom_onnx",+) -> SimpleNamespace:return SimpleNamespace(- phrase="Hey Nico",- engine="custom_onnx",+ phrase=phrase,+ engine=engine,custom_model_path=model_path,sensitivity=sensitivity,fuzzy_match_ratio=0.8,@@ -51,6 +56,111 @@ def test_custom_onnx_threshold_scales_strict_to_sensitive(tmp_path) -> None:assert 0.25 <= sensitive <= 0.35+# ---------------------------------------------------------------------------+# A stale custom model must NOT hijack a NEW wake phrase.+#+# Live bug 2026-07-02: the user changed the wake phrase to "Hey Fable"+# (engine Auto) in Settings, but jarvis.toml still carried+# custom_model_path=hey_nico.onnx from the earlier trained phrase — and the+# resolver's "any custom path wins" rule kept the NICO model as the detector,+# so the new phrase was deaf ("only Hey Nico still works"). Rule now:+# a custom model is auto-adopted only when it BELONGS to the configured+# phrase (model filename tokens, sound-folded); an explicit+# engine="custom_onnx" still forces it (user's own naming is their choice).+# ---------------------------------------------------------------------------+++def test_stale_custom_model_does_not_hijack_new_phrase(tmp_path) -> None:+ from jarvis.speech.wake_phrase import resolve_wake_plan++ model = tmp_path / "hey_nico.onnx"+ model.write_bytes(b"onnx")+ plan = resolve_wake_plan(+ _cfg(str(model), phrase="Hey Fable", engine="auto"),+ local_whisper_available=True,+ )+ assert plan.engine == "stt_match", plan+ # The regular any-phrase path, not a degraded fallback.+ assert plan.degraded is False+ assert plan.matcher.search("hey fable") is not None+ assert "different phrase" in plan.message.lower()+++def test_matching_custom_model_still_adopted_on_auto(tmp_path) -> None:+ from jarvis.speech.wake_phrase import resolve_wake_plan++ model = tmp_path / "hey_nico.onnx"+ model.write_bytes(b"onnx")+ plan = resolve_wake_plan(+ _cfg(str(model), phrase="Hey Nico", engine="auto"),+ local_whisper_available=True,+ )+ assert plan.engine == "custom_onnx"+ assert plan.oww_model_path == str(model)+++def test_sound_folded_spelling_still_owns_the_model(tmp_path) -> None:+ # "Hey Niko" vs hey_nico.onnx: sound-folding makes the tokens compare+ # equal, so a spelling variant of the SAME word keeps the trained model.+ from jarvis.speech.wake_phrase import resolve_wake_plan++ model = tmp_path / "hey_nico.onnx"+ model.write_bytes(b"onnx")+ plan = resolve_wake_plan(+ _cfg(str(model), phrase="Hey Niko", engine="auto"),+ local_whisper_available=True,+ )+ assert plan.engine == "custom_onnx"+++def test_explicit_custom_engine_keeps_arbitrarily_named_model(tmp_path) -> None:+ # engine="custom_onnx" is the user's explicit choice — a model file named+ # differently from the phrase (their own training, their own naming) must+ # still be honoured.+ from jarvis.speech.wake_phrase import resolve_wake_plan++ model = tmp_path / "my_wake.onnx"+ model.write_bytes(b"onnx")+ plan = resolve_wake_plan(+ _cfg(str(model), phrase="Friday", engine="custom_onnx"),+ local_whisper_available=True,+ )+ assert plan.engine == "custom_onnx"+ assert plan.oww_model_path == str(model)+++def test_stale_custom_model_lets_pretrained_phrase_through(tmp_path) -> None:+ # A stale custom model must not block the pretrained path either: with the+ # phrase set (back) to "Hey Jarvis", the bundled hey_jarvis model wins.+ from jarvis.speech.wake_phrase import resolve_wake_plan++ model = tmp_path / "hey_nico.onnx"+ model.write_bytes(b"onnx")+ plan = resolve_wake_plan(+ _cfg(str(model), phrase="Hey Jarvis", engine="auto"),+ local_whisper_available=True,+ )+ assert plan.engine == "openwakeword"+ assert plan.oww_keyword == "hey_jarvis"+ assert plan.degraded is False+++def test_stale_custom_model_without_whisper_degrades_honestly(tmp_path) -> None:+ # Mismatching model + no local Whisper: fall through to the bundled+ # offline fallback with a clear message — never a silent dead listener.+ from jarvis.speech.wake_phrase import resolve_wake_plan++ model = tmp_path / "hey_nico.onnx"+ model.write_bytes(b"onnx")+ plan = resolve_wake_plan(+ _cfg(str(model), phrase="Hey Fable", engine="auto"),+ local_whisper_available=False,+ )+ assert plan.engine == "openwakeword"+ assert plan.oww_keyword == "hey_rhasspy"+ assert plan.degraded is True++def test_custom_onnx_requires_prefix_verify(tmp_path) -> None:# Live forensic 2026-07-01 (false-positive storm): a user-trained custom# model is a WEAK discriminator — it scored breath/ambient/other speech up