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): stop the shape gate's own spelling assumptions from eating real wakes
rubenluetke10-beepecd3d3cfc904
diff --git a/docs/BUGS.md b/docs/BUGS.mdindex 81bef8ab00..c9f1e3c5eb 100644--- a/docs/BUGS.md+++ b/docs/BUGS.md@@ -8487,3 +8487,94 @@ a process that has already settled once; for a process that just started itanswers "is this CLI drawing itself?", and every caller that conflates the twofails silently in exactly the seconds after a restart — which is when thefeature is used.++---++## BUG-123: the wake word needs three tries — the SHAPE gate carries its own spelling assumptions (HIGH, FIXED 2026-08-04)++**Symptom (maintainer field report).** "I had to say it very often." Simple+names are no better than invented ones: "even with an easy name like Ben it+often fails." The status line meanwhile showed the raw i18n key+`VOICE_STATE.CONNECTING` instead of a label (separate defect, same screenshot —+the built `dist/` predated the locale key by 33 minutes).++**Evidence — the live log said "heard it, threw it away".** On this install+(2026-08-04 17:01-17:02, phrase "Hey Claude", engine `vosk_kws`, en model):++```+candidates=2 suppressed_confirm=2 fired=0 <- two calls heard and rejected+17:02:05 vosk-kws: verify OK (shape) ... free ear heard 'hey khloe' ... fired=1+```++Three calls, one fire. And not one line said WHY the first two died: the+"neither spelled nor shaped like a call" branch of `_verify_window` was the only+rejection that logged at DEBUG, so the most common suppression in production was+also the one invisible in production.++**Root cause — AP-27, one level below where it was last fixed.** The free-decode+SHAPE gate (`candidate_shape_ok`) exists precisely because a spelling rule cannot+judge an out-of-vocabulary wake word. Two of its four questions turned out to+rest on spelling assumptions of their own. Replaying each phrase through the real+en model with a German and a US voice:++| phrase | spoken (German voice) | free ear heard | verdict |+|---|---|---|---|+| Hey Ben | Hey Ben | `have you been` (3 tokens, conf 1.00) | suppressed |+| Hey Ruben | Hey Ruben | `have you been` (3 tokens, conf 1.00) | suppressed |+| Hey Atlas | Hey Atlas | `have you at last` (4 tokens, conf 1.00) | suppressed |++* **The token count** assumes the free ear spends ONE token on the wake prefix.+ A short function word in a foreign accent is re-tokenised — `hey` -> `have+ you` — so a genuine two-token call arrives as three or four and is charged+ against the phrase's own budget. Every non-native speaker of the model's+ language hits this, which for an international product is the normal case.+* **The confidence veto** assumes the wake word is out-of-vocabulary, and reads+ the decoder's certainty as proof that some OTHER word was said. Every name+ that IS an ordinary word inverts it: "Ben" -> `been`, "Claude" -> `cloud`,+ both at conf 1.00. That is exactly the maintainer's "even easy names fail" —+ easy names are easy because they are real words.++Neither premise can be repaired by moving a threshold, and a spelling floor low+enough to rescue `hey khloe` (0.55 against "claude") is far below what unrelated+speech scores. Same shape as BUG-037: the rule that suppresses ghosts also+rejects genuine wakes.++**Fix — the two contested questions stop being vetoes.** They now yield+`SHAPE_UNDECIDED` and hand the candidate to the ACOUSTIC COMPETITION that+already gates every shape acceptance (re-score against an explicit+`"<prefix> [unk]"` alternative — a purely acoustic judgement that never reads a+spelling, AP-27-safe). The two duration-based questions — "not spoken longer+than the phrase could be" and "a name-sized body exists where the name belongs"+— stay HARD rejections: they measure how much sound was made, never what it was,+so no accent or vocabulary can invert them. No calibrated threshold moved.++The authoritative confirm now also REPORTS this rejection class through the+rate-limited `_log_suppression`, so "heard and thrown away" is distinguishable+from "never heard" without a debug build.++**Measured, real en model, synthesised German + US voice** (`_verify_window`+end to end, 16 genuine calls / 30 unrelated utterances incl. the recorded live+false-wake transcripts):++| | genuine calls | ordinary speech | near-homophone NAMES |+|---|---|---|---|+| before | 12/16 fire | 0/30 false | 7/22 accepted |+| after | **16/16 fire** | **0/30 false** | 12/22 accepted |++The cost is confined to near-homophone names ("Hey Bell" firing "Hey Ben") — a+class that already leaked and that no offline small model can separate by a+single final consonant. Ordinary speech and bare interjections are unchanged.+This also closed the previously-open one-breath case (BUG-037 follow-up, strict+xfail since 2026-07-25): "Hey Claude, what is the weather today" now fires,+because trailing command words make the candidate contested instead of vetoed.++**Honest limit.** The 2026-07 calibration corpora (250/1650 real captured+windows) are no longer on disk; the numbers above come from a smaller+synthesised corpus. The change deliberately moves no threshold, so the+calibrated bounds remain exactly as measured then.++**Guards.** `tests/unit/plugins/wake/test_vosk_wake_word_agnostic.py`+(contested-vs-hard verdicts, the German prefix split, a contested shape that+LOSES the competition), `tests/unit/plugins/wake/test_vosk_kws_provider.py`+(the fake's competitor grammar now models the measured decoder instead of+answering "phrase" unconditionally).diff --git a/docs/local-wakeword/WAKE-RELIABILITY-DEEPDIVE.md b/docs/local-wakeword/WAKE-RELIABILITY-DEEPDIVE.mdindex 9fb13a19db..52bc7b2aff 100644--- a/docs/local-wakeword/WAKE-RELIABILITY-DEEPDIVE.md+++ b/docs/local-wakeword/WAKE-RELIABILITY-DEEPDIVE.md@@ -201,3 +201,55 @@ words outside the model lexicon ride the free-decode fuzzy path — besteffort, (c) the definitive sub-200 ms class remains a trained neural KWS.Guards: `tests/unit/plugins/wake/test_vosk_kws_provider.py`,`tests/unit/speech/test_wake_plan_vosk.py` (chain + live-arming regression).++## The shape gate's own spelling assumptions (2026-08-04, BUG-123 / AP-27)++The free-decode SHAPE gate was introduced (2026-07-13) because no spelling rule+can judge an out-of-vocabulary wake word. Two of its four questions turned out to+be spelling rules in disguise, and they cost roughly two thirds of all wakes for+a non-native speaker.++Measured against the real `vosk-model-small-en-us-0.15`, one German and one US+voice, per phrase — what the FREE ear produces for a GENUINE call:++```+"Hey Ben" (de voice) -> "have you been" 3 tokens, every conf 1.00+"Hey Ruben" (de voice) -> "have you been" 3 tokens, every conf 1.00+"Hey Atlas" (de voice) -> "have you at last" 4 tokens, every conf 1.00+"Hey Claude" (de voice) -> "harry claude" spelled -> fired+"Hey Ben" (us voice) -> "hey ben" spelled -> fired+```++* **Token count.** A wake PREFIX is a short function word; in a foreign accent+ the free decoder re-tokenises it (`hey` -> `have you`). A genuine two-token+ call then exceeds the phrase's own token budget. The rule assumed the decoder+ tokenises the phrase the way the phrase is written.+* **Confidence.** The rule reads certainty as "the ear knew some OTHER word" —+ true only while the wake word is out-of-vocabulary. A name that IS a word+ ("Ben" -> `been`, "Claude" -> `cloud`) is recognised outright at conf 1.00,+ so the rule rejects hardest exactly the easy names users pick first.++Both now yield `SHAPE_UNDECIDED` and are decided by the **acoustic competition**+(re-score against an explicit `"<prefix> [unk]"` alternative) instead of vetoing+the candidate. Measured discrimination of that competition on the same audio:+the phrase survives for **8/8 genuine calls and 0/20 unrelated utterances**+(including the recorded live false-wake transcripts `hi servers sichern`,+`ein jahr bis`). <!-- i18n-allow: forensic quotes of utterances under test -->++The two duration-based questions stay HARD rejections — they measure how much+sound was made, never what it was, so no accent or vocabulary can invert them.++End to end through the real `_verify_window`: genuine calls **12/16 -> 16/16**,+ordinary speech **0/30 false accepts, unchanged**, near-homophone NAMES+("Hey Bell" for "Hey Ben") 7/22 -> 12/22 — the one class that pays, and one that+a small offline model cannot separate by a single final consonant anyway.++Two side effects worth knowing:++* The natural one-breath call — "Hey Claude, what is the weather today" — fires+ again; its command words now make the candidate contested rather than vetoed+ (open as a strict xfail since 2026-07-25).+* The authoritative confirm reports the "heard it, could not confirm it"+ rejection through the rate-limited suppression log. Before, it was the only+ rejection class that logged at DEBUG, so the live log could not tell a+ suppressed wake from a wake that was never heard.diff --git a/jarvis/plugins/wake/vosk_kws_provider.py b/jarvis/plugins/wake/vosk_kws_provider.pyindex 439f2d8357..63d41d25d3 100644--- a/jarvis/plugins/wake/vosk_kws_provider.py+++ b/jarvis/plugins/wake/vosk_kws_provider.py@@ -25,12 +25,13 @@ Two-stage detection, AP-27-safe:must contain a real wake prefix immediately followed by a sound-close core.This keeps ASR spelling/splitting tolerance (for example, "joe avis" for"Jarvis") without letting a high-confidence grammar hallucination turn- unrelated room speech into a wake. A shape-only acceptance (the free ear- could not spell the word but what it heard looks like a wake call) must- additionally win the acoustic competition against an explicit- "<prefix> [unk]" grammar alternative, or a call of a DIFFERENT name fires- too (live 2026-07-17). Infrastructure errors fail OPEN so a broken confirm- cannot eat a real wake.+ unrelated room speech into a wake. When the free ear could not spell the+ word, the word-agnostic SHAPE of what it heard decides instead — and any+ shape that is either a clean wake shape or merely contested (a re-tokenised+ prefix, a name the decoder knows as an ordinary word) must win the acoustic+ competition against an explicit "<prefix> [unk]" grammar alternative, or a+ call of a DIFFERENT name fires too (live 2026-07-17). Infrastructure errors+ fail OPEN so a broken confirm cannot eat a real wake.A raw-energy gate (word-agnostic RMS at the match site, AP-27) rejectsnear-silent candidates before the confirm. The detector never emits@@ -228,6 +229,40 @@ _SHAPE_MIN_CORE_BODY_S = 0.20# split case is covered by the spelling path and must not be paid for twice._SHAPE_TOKEN_SLACK = 0+# --- three-way shape verdict (AP-27, forensic 2026-08-04) -------------------+# Two of the four shape questions turned out to rest on a SPELLING assumption+# after all, which is the AP-27 trap one more level down. Measured on this box+# against the real en model, one German and one US voice per phrase:+#+# "Hey Ben" spoken de -> free ear "have you been" (3 tokens, all conf 1.00)+# "Hey Atlas" spoken de -> free ear "have you at last"(4 tokens, all conf 1.00)+# "Hey Ruben" spoken de -> free ear "have you been" (3 tokens, all conf 1.00)+#+# Both broken premises are visible in that one line:+# * the TOKEN COUNT assumes the free ear spends one token on the wake prefix.+# A short function word in a foreign accent is re-tokenised ("hey" ->+# "have you"), so a genuine two-token call arrives as three or four and is+# charged against the phrase's own budget.+# * the CONFIDENCE veto assumes the wake word is out-of-vocabulary. Every+# name that IS an ordinary word ("Ben" -> "been", "Claude" -> "cloud")+# makes the free ear certain, and the rule reads that certainty as proof+# that some OTHER word was said.+# Live consequence on this install (2026-08-04 17:01-17:02): 3 candidates,+# 2 suppressed, 1 fired — the user says the wake word three times.+#+# Neither premise can be repaired by moving a threshold, so the two questions+# stop being VETOES and become a reason to ask the acoustic competition —+# the purely acoustic judgement that already gates every shape acceptance.+# Measured on the same synthesised corpus (8 genuine calls, 20 unrelated+# utterances incl. the recorded live false-wake transcripts): the competitor+# grammar keeps the phrase for 8/8 genuine calls and 0/20 unrelated ones.+#+# The other two questions stay HARD rejections: they measure how much sound was+# made, never what it was, so no accent or vocabulary can invert them.+SHAPE_WAKE = "wake" # looks like a call — competition confirms as before+SHAPE_UNDECIDED = "undecided" # tokenisation/confidence contradicts — competition decides+SHAPE_SPEECH = "speech" # too much sound, or no name-sized body: never a wake+# --- acoustic competition for the SHAPE path (live forensic 2026-07-17) -----# The shape gate accepts anything that LOOKS like a wake call — which a call of# a DIFFERENT name also does. Live: "hey nova" confirmed (shape) for the phrase@@ -387,14 +422,14 @@ def sound_confirm(free_text: str, phrase: str, *, ratio: float = _CONFIRM_RATIO)return False-def candidate_shape_ok(+def candidate_shape_verdict(local_words: Sequence[dict],phrase: str,*,max_voiced_s_per_token: float = _SHAPE_MAX_VOICED_S_PER_TOKEN,max_other_word_conf: float = _SHAPE_MAX_OTHER_WORD_CONF,min_core_body_s: float = _SHAPE_MIN_CORE_BODY_S,-) -> bool:+) -> str:"""Does the free ear's output AT the candidate span look like a wake call?Word-agnostic by construction (AP-27): it reads only how much was said at@@ -402,43 +437,47 @@ def candidate_shape_ok(spelled. ``local_words`` are the free decode's word dicts (``word``,``start``, ``end``, ``conf``) already localised to the phrase span.- Four word-agnostic questions, all scaled by the configured phrase:-- 1. **Not more words than the phrase has.** A wake call is the phrase; a- forced grammar hit on conversation carries the surrounding words too.- (A free decoder that SPLITS the name into two tokens — "Jarvis" ->- "joe avis" — is already accepted by ``sound_confirm``'s core_sizes- tolerance, so this gate does not need to pay for that case with the- extra false accepts a token slack costs.)- 2. **Not spoken for longer than the phrase could be.** The grammar happily- stretches the phrase across flowing speech; a real call cannot last- longer than its own tokens do.- 3. **The free ear is not SURE it heard another core word.** This is the- positive signal an out-of-vocabulary wake word leaves behind: the free- decoder does not know the core, so it guesses and its confidence drops.- Ordinary speech ("engineering", "google") it recognises outright. A- known wake prefix is deliberately excluded from this confidence check.- 4. **A name was actually spoken.** Strip the known wake prefixes and the- REMAINING voiced duration — the core body — must be at least a syllable.- Without this, the three bounds above describe a bare interjection just- as well as a wake call, and "hey ho" fires (live 2026-07-13). Note this- still never reads the name's SPELLING: it only asks whether a- name-sized sound exists where the name belongs.-- Empty input rejects: the grammar claimed the phrase where the free ear- heard no speech at all.+ Four word-agnostic questions, all scaled by the configured phrase. Two of+ them are HARD (``SHAPE_SPEECH`` — nothing may overrule them), two only make+ the candidate ``SHAPE_UNDECIDED`` and hand it to the acoustic competition:++ 1. **Not spoken for longer than the phrase could be.** HARD. The grammar+ happily stretches the phrase across flowing speech; a real call cannot+ last longer than its own tokens do. Pure duration — no accent, no+ vocabulary and no tokenisation can invert it.+ 2. **A name was actually spoken.** HARD. Strip the known wake prefixes and+ the REMAINING voiced duration — the core body — must be at least a+ syllable. Without this the other bounds describe a bare interjection+ just as well as a wake call, and "hey ho" fires (live 2026-07-13). It+ never reads the name's SPELLING: it only asks whether a name-sized+ sound exists where the name belongs.+ 3. **Not more words than the phrase has.** UNDECIDED. A wake call is the+ phrase; a forced grammar hit on conversation carries the surrounding+ words too. But the count assumes the free ear tokenises the phrase the+ way the phrase is written, and a wake PREFIX in a foreign accent is+ routinely re-tokenised ("hey" -> "have you", measured 2026-08-04), so a+ genuine call arrives over budget. (A SPLIT name — "Jarvis" -> "joe+ avis" — is already accepted by ``sound_confirm``'s core_sizes+ tolerance.)+ 4. **The free ear is not SURE it heard another core word.** UNDECIDED.+ This is the signal an out-of-vocabulary wake word leaves behind: the+ free decoder does not know the core, so it guesses and its confidence+ drops. But a name that IS an ordinary word ("Ben" -> "been") is+ recognised outright, and then certainty means the opposite of what this+ rule reads into it. A known wake prefix is excluded from the check.++ Empty input is ``SHAPE_SPEECH``: the grammar claimed the phrase where the+ free ear heard no speech at all."""if not local_words:- return False+ return SHAPE_SPEECHn_tokens = max(1, len(normalize_phrase_for_match(phrase)))- if len(local_words) > n_tokens + _SHAPE_TOKEN_SLACK:- return Falsevoiced_s = sum(max(0.0, float(w.get("end", 0.0)) - float(w.get("start", 0.0)))for w in local_words)if voiced_s > max_voiced_s_per_token * n_tokens:- return False+ return SHAPE_SPEECH# A confidently recognised wake prefix is expected evidence, not proof the# decoder heard some OTHER word. Apply the confidence discriminator only# to the unknown core body. Otherwise a perfect ``hey`` confidence rejects@@ -455,19 +494,45 @@ def candidate_shape_ok(]confidence_words = local_words if phrase_is_all_prefix else core_wordsif not confidence_words:- return False- top_conf = max(float(w.get("conf", 0.0)) for w in confidence_words)- if top_conf > max_other_word_conf:- return False+ return SHAPE_SPEECH# A phrase that IS nothing but prefixes ("Hey", "Hallo") has no core to# demand, so it must not be gated on a core duration.- if phrase_is_all_prefix:- return True- core_body_s = sum(- max(0.0, float(w.get("end", 0.0)) - float(w.get("start", 0.0)))- for w in core_words- )- return core_body_s >= min_core_body_s+ if not phrase_is_all_prefix:+ core_body_s = sum(+ max(0.0, float(w.get("end", 0.0)) - float(w.get("start", 0.0)))+ for w in core_words+ )+ if core_body_s < min_core_body_s:+ return SHAPE_SPEECH+ contested = len(local_words) > n_tokens + _SHAPE_TOKEN_SLACK+ top_conf = max(float(w.get("conf", 0.0)) for w in confidence_words)+ if top_conf > max_other_word_conf:+ contested = True+ return SHAPE_UNDECIDED if contested else SHAPE_WAKE+++def candidate_shape_ok(+ local_words: Sequence[dict],+ phrase: str,+ *,+ max_voiced_s_per_token: float = _SHAPE_MAX_VOICED_S_PER_TOKEN,+ max_other_word_conf: float = _SHAPE_MAX_OTHER_WORD_CONF,+ min_core_body_s: float = _SHAPE_MIN_CORE_BODY_S,+) -> bool:+ """True only for an UNCONTESTED wake shape (see ``candidate_shape_verdict``).++ Kept as the narrow boolean question — "does this look like a wake call on+ its own?" — so the shape rules stay independently testable. The verify path+ consumes the three-way verdict, because a contested shape is decided by the+ acoustic competition rather than thrown away.+ """+ return candidate_shape_verdict(+ local_words,+ phrase,+ max_voiced_s_per_token=max_voiced_s_per_token,+ max_other_word_conf=max_other_word_conf,+ min_core_body_s=min_core_body_s,+ ) == SHAPE_WAKEclass VoskKwsProvider:@@ -1183,22 +1248,55 @@ class VoskKwsProvider:# must additionally WIN the acoustic competition — a purely acoustic# judgement that never reads a spelling, so (a)'s recall contract is# untouched: a free ear that spelled the phrase still fires instantly.+ #+ # And (b) carried two SPELLING assumptions of its own (measured+ # 2026-08-04, see the SHAPE_* note): that the free ear spends one token+ # on the wake prefix, and that it cannot confidently spell the name.+ # A foreign accent breaks the first ("hey" -> "have you") and an+ # ordinary-word name breaks the second ("Ben" -> "been"), so both now+ # yield SHAPE_UNDECIDED and let the SAME acoustic competition decide+ # instead of vetoing the wake outright. The two duration-based+ # questions stay hard rejections — they measure how much sound was+ # made, never what it was.ok = sound_confirm(free_local, self._phrase, ratio=self._confirm_ratio)- by_shape = False- if not ok and candidate_shape_ok(local_words, self._phrase):- ok = by_shape = self._shape_competition_ok(pcm, model_path)+ shape = "" if ok else candidate_shape_verdict(local_words, self._phrase)+ if not ok and shape in (SHAPE_WAKE, SHAPE_UNDECIDED):+ ok = self._shape_competition_ok(pcm, model_path)if not ok:self._stat_suppressed_shape_competition += 1- log_method = log.info if ok else log.debug- log_method(- "vosk-kws: verify %s (%s) — free ear heard %r at the candidate span "- "(conf=%.2f) vs phrase %r",- "OK" if ok else "SUPPRESSED",- ("shape" if by_shape else "spelled") if ok else "neither",- free_local[:60],- conf,- self._phrase,- )+ if ok:+ log.info(+ "vosk-kws: verify OK (%s) — free ear heard %r at the candidate "+ "span (conf=%.2f) vs phrase %r",+ "spelled" if not shape else shape,+ free_local[:60],+ conf,+ self._phrase,+ )+ elif fail_open:+ # The authoritative confirm REPORTS its rejections: this branch —+ # "heard it, could not confirm it" — is the one a "sometimes it does+ # not react" report turns on, and it used to be DEBUG-only, so the+ # live log could not tell it from "never heard" at all (this+ # install, 2026-08-04: two suppressed candidates, zero explanatory+ # lines). The visual-only early check stays quiet: it rejects by+ # design on truncated audio and would drown this out.+ self._log_suppression(+ "free ear heard %r at the span (re-score conf %.2f, shape=%s) — "+ "neither spelled nor sounded like a call of %r",+ free_local[:60],+ conf,+ shape or "n/a",+ self._phrase,+ )+ else:+ log.debug(+ "vosk-kws: early check rejected — free ear heard %r (shape=%s) "+ "vs phrase %r",+ free_local[:60],+ shape or "n/a",+ self._phrase,+ )return okdef _shape_competition_ok(self, pcm: bytes, model_path: str | None) -> bool:@@ -1556,8 +1654,12 @@ def vosk_model_supports_phrase(model_path: str, phrase: str) -> bool:__all__ = [+ "SHAPE_SPEECH",+ "SHAPE_UNDECIDED",+ "SHAPE_WAKE","VoskKwsProvider","candidate_shape_ok",+ "candidate_shape_verdict","sound_confirm","vosk_model_supports_phrase",]diff --git a/tests/unit/plugins/wake/test_vosk_kws_provider.py b/tests/unit/plugins/wake/test_vosk_kws_provider.pyindex 1691971c7b..d95beb7f8c 100644--- a/tests/unit/plugins/wake/test_vosk_kws_provider.py+++ b/tests/unit/plugins/wake/test_vosk_kws_provider.py@@ -144,12 +144,22 @@ class _FakeRecognizer:``model.grammar_conf`` (the verify re-score input). Free mode (nogrammar): FinalResult returns ``model.free_text`` with timed words in thesame span — the knob the confirm-path tests turn.++ Competition mode (the three-alternative "<phrase> / <prefix> [unk] / [unk]"+ grammar): returns ``model.competition_text``, defaulting to the phrase.+ Measured against the real en model (2026-08-04, one German and one US+ voice): the competitor grammar keeps the phrase for 8/8 genuine calls and+ for 0/20 unrelated utterances, so a test whose free ear heard unrelated+ speech scripts "[unk]" here — otherwise the mock, not the decoder, would be+ deciding the precision assertions."""def __init__(self, model, rate, grammar=None): # noqa: ANN001self._model = modelself._grammar = grammarself._chunks = 0+ alternatives = json.loads(grammar) if grammar else []+ self._is_competition = len(alternatives) == 3def SetWords(self, flag): # noqa: ANN001, N802pass@@ -171,6 +181,12 @@ class _FakeRecognizer:return json.dumps({"text": ""})def FinalResult(self): # noqa: N802+ if self._is_competition and self._model.competition_text is not None:+ text = self._model.competition_text+ return json.dumps({+ "text": text,+ "result": _timed_words(text, self._model.grammar_conf),+ })if self._grammar is not None:phrase = self._model.phrase.lower()return json.dumps({@@ -190,6 +206,9 @@ class _FakeModel:self.free_text = "hey nova"self.grammar_conf = 0.95self.fire_after = 3+ # None = the competitor grammar also lands on the phrase (the genuine+ # case). A test that scripts unrelated speech sets "[unk]" here.+ self.competition_text = None@pytest.fixture()@@ -282,6 +301,9 @@ async def test_confirm_rejection_suppresses_the_fire(fake_vosk) -> None:for _ in range(50):if fake_vosk["model"] is not None:fake_vosk["model"].free_text = fake_vosk_model_free_text+ # ...and what the competitor grammar does with that same audio:+ # measured 0/20 on unrelated speech, it lands on "[unk]".+ fake_vosk["model"].competition_text = "[unk]"returnawait asyncio.sleep(0.01)@@ -474,6 +496,11 @@ def test_free_words_outside_the_span_cannot_confirm(fake_vosk) -> None:p._ensure_model()m = fake_vosk["model"]m.free_text = "ganz andere worte hier hey nowa" # i18n-allow: utterance under test+ # The words AT the span are unrelated, so the competitor grammar prefers+ # "[unk]" over the phrase for that audio (measured 0/20 on real unrelated+ # utterances) — the shape route cannot rescue what the spelling route+ # rejected here.+ m.competition_text = "[unk]"# free words start at 0.5s and stride 0.35s -> "hey nowa" sits ~1.9-2.6s,# far outside the grammar span (0.5-1.15s +-0.3) -> localised confirm# sees only unrelated words and rejects.@@ -548,6 +575,7 @@ async def test_rejected_candidate_storm_is_backpressured()p._ensure_model()fake_vosk["model"].free_text = "unrelated room speech"+ fake_vosk["model"].competition_text = "[unk]"verify_calls = 0fresh_rec_calls = 0diff --git a/tests/unit/plugins/wake/test_vosk_wake_word_agnostic.py b/tests/unit/plugins/wake/test_vosk_wake_word_agnostic.pyindex 2021cca9a2..704116f277 100644--- a/tests/unit/plugins/wake/test_vosk_wake_word_agnostic.py+++ b/tests/unit/plugins/wake/test_vosk_wake_word_agnostic.py@@ -32,8 +32,11 @@ import numpy as npimport pytestfrom jarvis.plugins.wake.vosk_kws_provider import (+ SHAPE_SPEECH,+ SHAPE_UNDECIDED,VoskKwsProvider,candidate_shape_ok,+ candidate_shape_verdict,sound_confirm,)@@ -379,32 +382,26 @@ def test_the_competition_grammar_derives_from_the_configured_phrase() -> None:# --- the wake spoken in ONE breath with the command (2026-07-25) -------------- reason=(- "OPEN, measured 2026-07-25: a wake spoken in one breath with the "- "command loses BOTH confirm routes. Narrowing the shape window to the "- "phrase span fixes it but costs precision — the token-count bound "- "relies on surrounding words being counted, so the narrower window "- "makes the room-speech fixture land ON the token count and ACCEPT. "- "Needs corpus calibration (250/1650 windows), not a fixture."- ),- strict=True,-)def test_a_wake_followed_immediately_by_the_command_still_fires(monkeypatch) -> None:"""The natural way people address an assistant must not be the hard case.The shape gate localises the free ear's words to the phrase span, and thatwindow extends 0.3 s PAST the phrase. So any command word starting inside- that trailing slack is counted into the candidate, pushes the token count- over the phrase's own (``_SHAPE_TOKEN_SLACK`` is 0) and disables the shape- path outright. For an out-of-vocabulary name the spelling path cannot cover- that gap either, so BOTH confirm routes fail at once — an isolated call plus- a pause fires, while the same call followed by the request does not.-- Kept as a STRICT xfail rather than deleted: it is the executable statement- of the defect, so whoever calibrates the corpus can see exactly what has to- start passing — and if a future change makes it pass by accident, strict- mode flags that too.+ that trailing slack is counted into the candidate and pushes the token+ count over the phrase's own (``_SHAPE_TOKEN_SLACK`` is 0). For an+ out-of-vocabulary name the spelling path cannot cover that gap either, so+ BOTH confirm routes used to fail at once — an isolated call plus a pause+ fired, the same call followed by the request did not.++ Fixed 2026-08-04 without moving any bound: an over-budget token count now+ makes the candidate ``SHAPE_UNDECIDED`` instead of vetoing it, and the+ acoustic competition decides. That is a purely acoustic judgement, so the+ earlier objection — narrowing the shape WINDOW costs precision because the+ token bound relies on surrounding words being counted — no longer applies:+ the surrounding words are still counted, they just no longer get the last+ word. Precision is held by+ ``test_room_speech_across_the_phrase_span_is_still_rejected`` (hard-rejected+ on duration) and by the competition tests above."""p = VoskKwsProvider("Hey Ruben", model_path="fake", keyword="ruben")@@ -474,6 +471,121 @@ def test_a_bare_interjection_plus_a_command_is_still_not_a_wake() -> None:) is False+# --- the shape gate's own spelling assumptions (measured 2026-08-04) ---------+#+# Live on the maintainer's install (17:01-17:02): 3 candidates, 2 suppressed,+# 1 fired — "I have to say it three times". Replaying the phrases through the+# real en model with a German and a US voice showed the free ear's output for a+# genuine call, and with it the two assumptions the shape gate still made.+++ ("phrase", "heard"),+ (+ # A German-accented wake PREFIX is re-tokenised into confidently known+ # filler, so a two-token call arrives as three or four tokens.+ ("Hey Ben", [_w("have", 0.48, 0.69, conf=1.0),+ _w("you", 0.69, 0.78, conf=1.0),+ _w("been", 0.78, 1.08, conf=1.0)]),+ ("Hey Ruben", [_w("have", 0.48, 0.72, conf=1.0),+ _w("you", 0.72, 0.89, conf=1.0),+ _w("been", 0.94, 1.23, conf=1.0)]),+ ("Hey Atlas", [_w("have", 0.48, 0.66, conf=1.0),+ _w("you", 0.66, 0.75, conf=1.0),+ _w("at", 0.75, 0.88, conf=1.0),+ _w("last", 0.88, 1.14, conf=1.0)]),+ # A name that IS an ordinary word: the free ear spells it confidently,+ # which the confidence rule read as proof of some OTHER word.+ ("Hey Ben", [_w("hey", 0.48, 0.72, conf=1.0),+ _w("ben", 0.72, 1.05, conf=1.0)]),+ ("Hey Claude", [_w("hey", 0.48, 0.69, conf=1.0),+ _w("cloud", 0.69, 1.17, conf=1.0)]),+ ),+)+def test_a_contested_shape_is_undecided_not_a_veto(phrase, heard) -> None:+ """Neither assumption may THROW AWAY a candidate on its own."""+ assert candidate_shape_verdict(heard, phrase) == SHAPE_UNDECIDED+ # ...and the narrow boolean question still answers "not on its own".+ assert candidate_shape_ok(heard, phrase) is False+++ ("phrase", "heard"),+ (+ # Too much sound for the phrase's own tokens: flowing speech.+ ("Hey Ruben", [_w("herr", 0.20, 1.00), _w("oben", 1.00, 2.00)]),+ # Nothing name-sized where the name belongs ("hey ho", live 2026-07-13).+ ("Hey Ruben", [_w("hey", 0.40, 0.62), _w("ho", 0.62, 0.74)]),+ # The free ear heard no speech at all at the span.+ ("Hey Ruben", []),+ ),+)+def test_the_duration_questions_stay_hard_rejections(phrase, heard) -> None:+ """The two bounds that measure SOUND, not words, can never be overruled."""+ assert candidate_shape_verdict(heard, phrase) == SHAPE_SPEECH+++def test_a_german_prefix_split_wake_fires_through_the_competition(monkeypatch) -> None:+ """The live bug: "Hey Ben" heard as "have you been" was thrown away.++ Measured against the real en model: the German voice's "Hey Ben" free-decodes+ to "have you been" (3 confidently known tokens), which failed the token+ count AND the confidence rule, while "been" is too far from "ben" for the+ spelling path. Both routes closed on a genuine call.+ """+ p = VoskKwsProvider("Hey Ben", model_path="fake", keyword="ben")+ grammar = {+ "text": "hey ben",+ "result": [+ {"word": "hey", "start": 0.48, "end": 0.78, "conf": 1.0},+ {"word": "ben", "start": 0.78, "end": 1.08, "conf": 1.0},+ ],+ }+ free = {+ "text": "have you been",+ "result": [+ _w("have", 0.48, 0.69, conf=1.0),+ _w("you", 0.69, 0.78, conf=1.0),+ _w("been", 0.78, 1.08, conf=1.0),+ ],+ }++ monkeypatch.setattr(p, "_take_verify_rec", _stub_take(grammar, free))+ assert p._verify_window(_loud_window(), fail_open=True) is True+++def test_a_contested_shape_that_loses_the_competition_does_not_fire(+ monkeypatch,+) -> None:+ """Undecided means the DECODER decides — not that the candidate is waved in.++ Measured on real audio: the competitor grammar keeps the phrase for 8/8+ genuine calls and 0/20 unrelated utterances, so this is where room speech+ that survives the two duration bounds is stopped.+ """+ p = VoskKwsProvider("Hey Ben", model_path="fake", keyword="ben")+ grammar = {+ "text": "hey ben",+ "result": [+ {"word": "hey", "start": 0.48, "end": 0.78, "conf": 1.0},+ {"word": "ben", "start": 0.78, "end": 1.08, "conf": 1.0},+ ],+ }+ free = {+ "text": "have you been",+ "result": [+ _w("have", 0.48, 0.69, conf=1.0),+ _w("you", 0.69, 0.78, conf=1.0),+ _w("been", 0.78, 1.08, conf=1.0),+ ],+ }+ competition = {"text": "hey [unk]", "result": []}++ monkeypatch.setattr(p, "_take_verify_rec", _stub_take(grammar, free, competition))+ assert p._verify_window(_loud_window(), fail_open=True) is False+ assert p.stats()["suppressed_shape_competition"] == 1++# --- diagnosability: a suppressed wake must leave a trace (2026-07-25) --------