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): reject biased-turbo hallucinated wakes via an unbiased confirm pass
Ruben Lütkedaf6ae1ee107
diff --git a/jarvis/plugins/stt/fwhisper.py b/jarvis/plugins/stt/fwhisper.pyindex 98328f5b48..ce49b21403 100644--- a/jarvis/plugins/stt/fwhisper.py+++ b/jarvis/plugins/stt/fwhisper.py@@ -134,27 +134,40 @@ class FasterWhisperProvider:async def transcribe_pcm(self, pcm_bytes: bytes, sample_rate: int = 16_000,language: str | None = None,+ use_bias: bool = True,) -> Transcript:"""Direkter Weg für VAD-Output: int16-PCM-Bytes → Transcript.`language` überschreibt per Call die Default-Sprache. Nützlich für denWake-Detector der auch bei STT-Default "auto" immer auf Deutsch hören soll.++ `use_bias=False` transcribes this ONE call WITHOUT the ``initial_prompt``+ bias, even on a biased instance. The wake backstop uses this for an+ unbiased confirmation pass: a strong biased model can hallucinate the+ primed wake phrase onto a different "Hey X", and the unbiased re-read+ reveals the actually-spoken phrase (forensic 2026-06-24)."""self._ensure_model()audio_np = pcm_bytes_to_np(pcm_bytes)- return await self._transcribe_np(audio_np, sample_rate, language=language)+ return await self._transcribe_np(+ audio_np, sample_rate, language=language, use_bias=use_bias+ )async def _transcribe_np(self, audio_np: np.ndarray, sample_rate: int,language: str | None = None,+ use_bias: bool = True,) -> Transcript:# faster-whisper ist synchron → in Thread shippenimport asyncio- return await asyncio.to_thread(self._transcribe_sync, audio_np, sample_rate, language)+ return await asyncio.to_thread(+ self._transcribe_sync, audio_np, sample_rate, language, use_bias+ )def _transcribe_sync(self, audio_np: np.ndarray, sample_rate: int,language: str | None = None,+ use_bias: bool = True,) -> Transcript:assert self._model is not None# faster-whisper akzeptiert np.ndarray float32 direkt wenn 16 kHz@@ -164,6 +177,9 @@ class FasterWhisperProvider:# Per-Call-Override hat Vorrang vor self._languageeffective_lang = language if language is not None else self._language+ # Per-call bias override: an unbiased confirmation pass (use_bias=False)+ # drops the wake-phrase prompt so a hallucinated echo cannot survive it.+ effective_prompt = self._initial_prompt if use_bias else Nonesegments_iter, info = self._model.transcribe(audio_np,@@ -171,7 +187,7 @@ class FasterWhisperProvider:beam_size=self._beam_size,vad_filter=self._vad_filter,condition_on_previous_text=False,- initial_prompt=self._initial_prompt,+ initial_prompt=effective_prompt,no_speech_threshold=self._no_speech_threshold,)# segments_iter ist generator — durchiterieren materialisiertdiff --git a/jarvis/speech/rolling_whisper_wake.py b/jarvis/speech/rolling_whisper_wake.pyindex 76b9a1efdc..a1ad8fb9a1 100644--- a/jarvis/speech/rolling_whisper_wake.py+++ b/jarvis/speech/rolling_whisper_wake.py@@ -23,6 +23,7 @@ Parameter:from __future__ import annotationsimport asyncio+import difflibimport loggingimport osimport re@@ -96,6 +97,36 @@ def _reliable_wake_transcript()+def _wake_confirmed_unbiased(unbiased_text: str, name: str) -> bool:+ """Reject a biased-Whisper wake that an UNBIASED re-read contradicts.++ A strong model seeded with ``initial_prompt="Hey Ruben"`` can hallucinate the+ primed phrase onto a different "Hey X" (forensic 2026-06-24: live "Hey Jarvis"+ / "Hey John" fired as "Hey Ruben"). Re-transcribed WITHOUT the bias, a real+ wake still resembles ``name`` (or is too garbled to name anything else),+ whereas a hallucination reveals the actually-spoken different "hey <word>".++ Reject ONLY on that positive competing-name signal, so recall is preserved:+ a real but mumbled wake whose unbiased read is garbled (e.g. "Drogen" for a+ quiet "Hey Ruben") carries no competing name and is confirmed. Empirically+ (the user's real clips): confirms 3/3 genuine "Hey Ruben" + rejects+ "Hey Jarvis"/"Hey John". The 0.5 fuzzy floor admits "Ruf" (a real mumbled+ "Ruben", ratio 0.5) while still rejecting jarvis/john/thomas/alexa (all <0.5).+ """+ u = unbiased_text.lower().strip()+ name_l = name.lower().strip()+ tokens = re.findall(r"[a-zäöüß]+", u)+ # The unbiased read still resembles the wake name -> a real wake.+ if any(difflib.SequenceMatcher(None, t, name_l).ratio() >= 0.5 for t in tokens):+ return True+ # The unbiased read clearly heard a DIFFERENT wake-style "hey <word>" -> the+ # bias hallucinated the primed phrase; reject.+ if re.search(r"\b(?:hey|hi|hallo|ok|okay)\s+[a-zäöüß]{3,}", u):+ return False+ # Garbled / no competing name -> benefit of the doubt (preserve recall).+ return True++class RollingWhisperWake:"""Rolling-Window Wake-Detection per Whisper-Transkription."""@@ -183,6 +214,19 @@ class RollingWhisperWake:# 2026-06-24 — these quiet drops were previously a silent ``continue``).self._gated_out = 0+ def _should_confirm_unbiased(self) -> bool:+ """Run the unbiased hallucination-confirm pass for this STT instance?++ Only when (a) the STT is biased — no ``initial_prompt`` means nothing can+ hallucinate the primed phrase — AND (b) the re-read is cheap: a CUDA model+ re-transcribes a window in ~150 ms, whereas a CPU ``base`` model would add+ ~1 s to every wake fire. On the slow CPU path the weak recall also makes+ the bias hallucination rare, so the pass is not worth the latency there.+ """+ biased = bool(getattr(self._stt, "_initial_prompt", None))+ fast = getattr(self._stt, "_device", "cpu") == "cuda"+ return biased and fast+async def detect(self, chunks: AsyncIterator[AudioChunk]) -> AsyncIterator[str]:@@ -351,6 +395,30 @@ class RollingWhisperWake:log.info("rolling-whisper: rms=%.4f text=%r", rms, text)m = self._pattern.search(text)if m:+ # Unbiased hallucination-confirm (forensic 2026-06-24): on the+ # fast GPU path a biased turbo can hallucinate the primed wake+ # phrase onto a different "Hey X" ("Hey Jarvis"/"Hey John" fired+ # as "Hey Ruben"). Re-read the SAME boosted window WITHOUT the+ # bias; drop the hit if the unbiased read names a different wake.+ if self._should_confirm_unbiased():+ try:+ unbiased = await self._stt.transcribe_pcm(+ pcm_bytes, language=self._language, use_bias=False+ )+ except Exception as exc: # noqa: BLE001+ log.warning("unbiased wake-confirm failed: %s", exc)+ unbiased = None+ if unbiased is not None:+ name = m.group(0).split()[-1] if m.group(0).split() else text+ if not _wake_confirmed_unbiased(+ (unbiased.text or "").strip(), name+ ):+ log.info(+ "rolling-whisper: rejected hallucinated wake — "+ "biased=%r unbiased=%r name=%r",+ text, (unbiased.text or "").strip(), name,+ )+ continuelast_trigger_t = nowyield m.group(0)finally:diff --git a/tests/unit/speech/test_rolling_whisper_wake.py b/tests/unit/speech/test_rolling_whisper_wake.pyindex 29c3ed93f2..bf8731ab47 100644--- a/tests/unit/speech/test_rolling_whisper_wake.py+++ b/tests/unit/speech/test_rolling_whisper_wake.py@@ -18,7 +18,40 @@ import asyncioimport numpy as npfrom jarvis.core.protocols import AudioChunk, Transcript-from jarvis.speech.rolling_whisper_wake import RollingWhisperWake+from jarvis.speech.rolling_whisper_wake import (+ RollingWhisperWake,+ _wake_confirmed_unbiased,+)+++# --- unbiased hallucination-confirm (forensic 2026-06-24) ---------------------+# A biased turbo can hallucinate the primed "Hey Ruben" onto a different "Hey X".+# An unbiased re-read of the same window reveals the truth; reject only on a clear+# competing wake-name so recall is preserved.+++def test_confirm_accepts_unbiased_read_that_still_says_the_name() -> None:+ assert _wake_confirmed_unbiased("Hey Ruben", "ruben") is True+++def test_confirm_accepts_mumbled_unbiased_near_name() -> None:+ # A real but quiet "Hey Ruben" the unbiased model heard as "Hey Ruf"+ # (ratio 0.5 vs "ruben") must still confirm — it is not a competing name.+ assert _wake_confirmed_unbiased("Hey, Ruf.", "ruben") is True+++def test_confirm_accepts_garbled_unbiased_with_no_competing_name() -> None:+ # A quiet real wake the unbiased model garbled ("Drogen") names nothing else,+ # so it gets the benefit of the doubt (recall over a false reject).+ assert _wake_confirmed_unbiased("Drogen.", "ruben") is True+++def test_confirm_rejects_unbiased_competing_hey_name() -> None:+ # "Hey Jarvis" / "Hey John" spoken -> biased hallucinates "Hey Ruben"; the+ # unbiased read names the real wake -> reject.+ assert _wake_confirmed_unbiased("Hey Jarvis", "ruben") is False+ assert _wake_confirmed_unbiased("Hey John.", "ruben") is False+ assert _wake_confirmed_unbiased("Hallo Computer", "ruben") is Falsedef _loud_chunk(marker: int, n: int = 1600) -> AudioChunk:@@ -84,6 +117,31 @@ class _PhraseSTT:)+class _BiasAwareSTT:+ """A biased CUDA wake-Whisper for the unbiased-confirm pass: returns+ ``biased_text`` on a normal (biased) call and ``unbiased_text`` when the+ detector re-reads with ``use_bias=False``."""++ def __init__(+ self, biased_text: str, unbiased_text: str, *, confidence: float = 0.9+ ) -> None:+ self._biased = biased_text+ self._unbiased = unbiased_text+ self._confidence = confidence+ self._initial_prompt = "Hey Ruben" # biased -> confirm is eligible+ self._device = "cuda" # fast -> confirm actually runs++ async def transcribe_pcm(+ self,+ pcm: bytes,+ sample_rate: int = 16000,+ language: str | None = None,+ use_bias: bool = True,+ ) -> Transcript:+ text = self._biased if use_bias else self._unbiased+ return Transcript(text=text, language="de", confidence=self._confidence)++async def _feed_until(src: asyncio.Queue, stop: asyncio.Event) -> None:i = 0while not stop.is_set():@@ -330,6 +388,100 @@ async def test_detect_rejects_matching_high_no_speech_transcript() -> None:pass+async def test_detect_rejects_biased_hallucination_via_unbiased_confirm() -> None:+ """A biased turbo that prints 'hey ruben' for a spoken 'hey jarvis' is dropped.++ The unbiased re-read (use_bias=False) names the real wake -> reject. This is+ the false-wake the user hit (2026-06-24): "Hey Jarvis"/"Hey John" fired the+ "Hey Ruben" wake because the bias collapsed every "Hey X" onto the primed name.+ """+ import re++ wake = RollingWhisperWake(+ _BiasAwareSTT(biased_text="hey ruben", unbiased_text="hey jarvis"),+ pattern=re.compile(r"hey\W+ruben", re.IGNORECASE),+ poll_interval_s=0.01,+ cooldown_s=0.0,+ save_debug_wavs=False,+ min_rms=0.0,+ min_peak=0.0,+ )++ src: asyncio.Queue = asyncio.Queue()+ stop_feed = asyncio.Event()++ async def _iter():+ while True:+ chunk = await src.get()+ if chunk is None:+ return+ yield chunk++ async def _first_keyword() -> str:+ async for kw in wake.detect(_iter()):+ return kw+ return ""++ feeder = asyncio.create_task(_feed_until(src, stop_feed))+ try:+ try:+ kw = await asyncio.wait_for(_first_keyword(), timeout=0.7)+ except TimeoutError:+ kw = ""+ assert kw == "", f"hallucinated wake was not rejected: {kw!r}"+ finally:+ stop_feed.set()+ await src.put(None)+ feeder.cancel()+ try:+ await feeder+ except (asyncio.CancelledError, Exception): # noqa: BLE001, S110+ pass+++async def test_detect_confirms_real_wake_when_unbiased_agrees() -> None:+ """A genuine 'hey ruben' the unbiased read also supports still fires."""+ import re++ wake = RollingWhisperWake(+ _BiasAwareSTT(biased_text="hey ruben", unbiased_text="hey ruben"),+ pattern=re.compile(r"hey\W+ruben", re.IGNORECASE),+ poll_interval_s=0.01,+ cooldown_s=0.0,+ save_debug_wavs=False,+ min_rms=0.0,+ min_peak=0.0,+ )++ src: asyncio.Queue = asyncio.Queue()+ stop_feed = asyncio.Event()++ async def _iter():+ while True:+ chunk = await src.get()+ if chunk is None:+ return+ yield chunk++ async def _first_keyword() -> str:+ async for kw in wake.detect(_iter()):+ return kw+ return ""++ feeder = asyncio.create_task(_feed_until(src, stop_feed))+ try:+ kw = await asyncio.wait_for(_first_keyword(), timeout=3.0)+ assert kw.lower() == "hey ruben"+ finally:+ stop_feed.set()+ await src.put(None)+ feeder.cancel()+ try:+ await feeder+ except (asyncio.CancelledError, Exception): # noqa: BLE001, S110+ pass++def test_default_poll_interval_is_responsive() -> None:"""The poll cadence sets the idle gap before a fresh window is transcribed.