Skip to content

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.

chore: auto-save WIP via Claude stop-hook safety net (2026-07-01 18:36)

Ruben Lütke5eed4cb7d1bd
diff --git a/jarvis/core/config.py b/jarvis/core/config.py
index a6814785e8..5c6e803cef 100644
--- a/jarvis/core/config.py
+++ b/jarvis/core/config.py
@@ -257,6 +257,17 @@ class STTConfig(BaseModel):
wake_model: str = "base"
wake_device: str = "cpu"
wake_compute_type: str = "int8"
+ # When True (default) AND a CUDA GPU is present AND the post-wake utterance
+ # STT is NOT itself using the GPU, a CUSTOM wake phrase (the transcription-
+ # based ``stt_match`` path) runs on the strong ``large-v3-turbo`` model on the
+ # GPU instead of the small ``base`` model on the CPU. Live-log evidence
+ # (2026-06-30): the base/cpu wake model WEDGED repeatedly under app CPU/GIL
+ # contention (tens of seconds of total deafness -> "say it 2-3 times") and
+ # mis-transcribed the wake name. The GPU model transcribes a window in ~150 ms
+ # so it never blows the wedge timeout, and hears the proper noun accurately.
+ # Set False to force the validated base/cpu + phrase-bias config back — the
+ # escape hatch if the strong model ever over-triggers on a particular voice.
+ wake_high_accuracy: bool = True
language: str = "auto"
# Vocabulary biasing passed to Whisper's ``prompt`` field — the same
# mechanism dictation tools like a dictation app use to keep proper nouns and
diff --git a/jarvis/plugins/stt/__init__.py b/jarvis/plugins/stt/__init__.py
index 78b1c8cf26..183ec177d7 100644
--- a/jarvis/plugins/stt/__init__.py
+++ b/jarvis/plugins/stt/__init__.py
@@ -342,20 +342,30 @@ def build_wake_whisper(
and model == "base"
and device == "cpu"
and cuda_available
+ and bool(getattr(stt_cfg, "wake_high_accuracy", True))
):
- # CUSTOM WAKE PHRASE: keep the validated base/cpu + phrase-bias config;
- # do NOT upgrade to the turbo model. The strong turbo runs WITHOUT the
- # initial_prompt bias (the bias hallucinates on silence on the strong
- # model), but without that bias it MANGLES a short custom phrase — live
- # forensic 2026-06-29: "Hey Nico" -> "cuf ich" -> the wake never fired.
- # base/cpu+bias is the validated custom-phrase config (83% recall / ~0%
- # false on real WAVs), so a user-set custom wake word stays on it.
- # (Default "Hey Jarvis" / OWW paths carry no bias and still get the fast
- # turbo upgrade above.) This makes the background hot-swap a no-op for a
- # custom phrase: the rebuilt model stays "base", so the caller keeps it.
+ # CUSTOM WAKE PHRASE on a CUDA box: upgrade to the strong turbo model on
+ # the GPU BUT KEEP the phrase bias. Mission 2026-06-30, live-log evidence
+ # (data/jarvis_desktop.log): the base/cpu model WEDGED repeatedly ("5
+ # consecutive transcribe failures -> rebuilding the wedged wake model" —
+ # up to 40 s of total deafness) and mis-transcribed the wake name under
+ # app CPU/GIL contention, so the wake needed 2-3 tries. The turbo model on
+ # the GPU transcribes a ~1.8 s window in ~150 ms, so it NEVER blows the
+ # transcribe timeout (this is what eliminates the wedge) and hears the
+ # proper noun accurately. The bias is KEPT (turbo WITHOUT bias mangles a
+ # short custom phrase — "Hey Nico" -> "cuf ich"); the earlier "bias
+ # hallucinates the phrase onto SILENCE on the strong model" concern does
+ # NOT apply here because the rolling wake path only transcribes windows
+ # that already passed its rms/peak gates — it never feeds a silent window
+ # to the model, and the no_speech_prob + confidence + strict-adjacency
+ # matcher gates remain the false-wake guards. The utterance STT is a
+ # separate provider (often cloud), so the wake owning the GPU does not
+ # contend with it. Reversible: wake_high_accuracy=False forces base/cpu.
+ model, device, compute = "large-v3-turbo", "cuda", "int8_float16"
logger.info(
- "Wake-Whisper: custom phrase -> staying on base/cpu (bias ON); turbo "
- "upgrade skipped (turbo-without-bias mangles short custom phrases)."
+ "Wake-Whisper: custom phrase on CUDA -> GPU turbo (large-v3-turbo/cuda) "
+ "WITH bias — fast (~150 ms, no wedge) + accurate. Set "
+ "[stt].wake_high_accuracy=false to force base/cpu."
)
elif fast_first and model == "base" and device == "cpu" and cuda_available:
logger.info(
diff --git a/jarvis/speech/rolling_whisper_wake.py b/jarvis/speech/rolling_whisper_wake.py
index 3967784d7f..e65f7b5431 100644
--- a/jarvis/speech/rolling_whisper_wake.py
+++ b/jarvis/speech/rolling_whisper_wake.py
@@ -71,9 +71,14 @@ _DEBUG_WAVS_ENV = os.environ.get("JARVIS_WAKE_DEBUG_WAVS", "").strip().lower() i
# timed out at 8 s, abandoned, retried, hung again, forever; an app restart did
# not even clear it. The timeout only BOUNDS a hang; it never RECOVERS. A run of
# failures with zero successes is the wedge signature (a legitimate VAD-probe
-# overlap clears in 1-2 polls and resets the counter on the next success), so a
-# small threshold self-heals fast without firing on a transient overlap.
-_WEDGE_RECOVER_AFTER_FAILS = 5
+# overlap clears in 1-2 polls and resets the counter on the next success).
+# 2026-06-30 (live logs showed the base/cpu model wedging dozens of times a day,
+# each dead window swallowing spoken wakes -> "say it 2-3 times"): lowered 5 -> 2
+# so the deaf window is as short as possible. Two consecutive failures with zero
+# successes in between is already an unambiguous wedge; a lone transient overlap
+# clears on the very next successful poll and resets the counter, so 2 does not
+# fire spuriously.
+_WEDGE_RECOVER_AFTER_FAILS = 2
def _save_wav(pcm_bytes: bytes, sample_rate: int, path: Path) -> None:
diff --git a/tests/unit/plugins/stt/test_wake_whisper_build.py b/tests/unit/plugins/stt/test_wake_whisper_build.py
index 46a804633b..bc2a99ada0 100644
--- a/tests/unit/plugins/stt/test_wake_whisper_build.py
+++ b/tests/unit/plugins/stt/test_wake_whisper_build.py
@@ -42,20 +42,43 @@ def test_build_wake_whisper_uses_wake_fields_not_utterance_model() -> None:
assert p._compute_type == "int8"
-def test_build_wake_whisper_custom_phrase_keeps_base_cpu_bias_on_cuda() -> None:
- # Forensic 2026-06-29: turbo WITHOUT the phrase bias MANGLES a short custom
- # wake phrase ("Hey Nico" -> "cuf ich" -> the wake never fired). The strong
- # turbo model is still unbiased there, and unbiased recall on a custom proper
- # noun is poor (2-13% vs 83% with the initial_prompt bias). So a CUSTOM wake
- # phrase stays on the validated base/cpu + bias config even on a CUDA box; it
- # does NOT upgrade to turbo-without-bias (which is why the background hot-swap
- # is a no-op for it — the rebuilt model stays "base"). Supersedes the
- # 2026-06-24 "turbo drops bias" decision, which only validated false-wakes (0)
- # and missed that turbo-without-bias also wrecks custom-phrase recall.
+def test_build_wake_whisper_custom_phrase_upgrades_to_gpu_turbo_with_bias() -> None:
+ # Mission 2026-06-30 (live-log evidence, data/jarvis_desktop.log): the
+ # base/cpu wake model WEDGES repeatedly ("5 consecutive transcribe failures ->
+ # rebuilding the wedged wake model" — up to 40 s of total deafness) and
+ # mis-transcribes even clear speech under app CPU/GIL contention, so a custom
+ # wake ("Hey Nico") needs 2-3 tries. The utterance STT is cloud (Groq), so the
+ # GPU sits idle. Fix: a custom phrase on a CUDA box now runs on the strong
+ # turbo model — ~150 ms per window so it NEVER blows the transcribe timeout
+ # (kills the wedge) and hears the proper noun accurately. The phrase bias is
+ # KEPT (the earlier "turbo without bias mangles Hey Nico -> cuf ich" finding);
+ # the earlier "bias hallucinates the phrase onto silence" concern does NOT
+ # apply on the rolling wake path, which gates on rms/peak/no_speech and so
+ # never feeds a silent window to the model. Reversible via wake_high_accuracy.
p = build_wake_whisper(STTConfig(), wake_phrase="Hey Ruben", cuda_available=True)
+ assert p._model_name == "large-v3-turbo"
+ assert p._device == "cuda"
+ assert p._initial_prompt == "Hey Ruben" # bias KEPT — needed to hear the name
+
+
+def test_build_wake_whisper_custom_phrase_gpu_upgrade_is_reversible() -> None:
+ # wake_high_accuracy = False forces the validated base/cpu + bias config back
+ # (the escape hatch if the strong model ever over-triggers on a given voice).
+ cfg = STTConfig(wake_high_accuracy=False)
+ p = build_wake_whisper(cfg, wake_phrase="Hey Ruben", cuda_available=True)
+ assert p._model_name == "base"
+ assert p._device == "cpu"
+ assert p._initial_prompt == "Hey Ruben"
+
+
+def test_build_wake_whisper_custom_phrase_fast_first_stays_base_for_quick_boot() -> None:
+ # The boot path builds fast-first (base/cpu, ~3 s, no CUDA JIT) so the wake is
+ # hear-ready immediately; the GPU turbo swaps in via the background hot-swap.
+ p = build_wake_whisper(
+ STTConfig(), wake_phrase="Hey Ruben", cuda_available=True, fast_first=True
+ )
assert p._model_name == "base"
assert p._device == "cpu"
- assert p._initial_prompt == "Hey Ruben" # bias KEPT — needed to hear the name
def test_build_wake_whisper_default_phrase_gets_turbo_no_bias_on_cuda() -> None:
diff --git a/tests/unit/speech/test_rolling_whisper_wake_wedge.py b/tests/unit/speech/test_rolling_whisper_wake_wedge.py
new file mode 100644
index 0000000000..a3fb788ed7
--- /dev/null
+++ b/tests/unit/speech/test_rolling_whisper_wake_wedge.py
@@ -0,0 +1,112 @@
+"""The wedged-model self-heal must fire FAST so the wake is not deaf for long.
+
+Live-log evidence (2026-06-30, data/jarvis_desktop.log): the base/cpu wake model
+wedged (``model.transcribe`` hung) dozens of times a day. Each wedge left the
+wake totally deaf until a run of consecutive transcribe failures triggered a
+model rebuild — at the old threshold of 5 that dead window ran long enough to
+swallow several spoken wakes ("say it 2-3 times"). Recovering after just 2
+consecutive failures (with zero successes in between — the unambiguous wedge
+signature) shortens the deaf window while a single transient overlap, which
+clears on the next successful poll, never trips it.
+"""
+from __future__ import annotations
+
+import asyncio
+import re
+
+import numpy as np
+
+from jarvis.core.protocols import AudioChunk
+from jarvis.speech.rolling_whisper_wake import (
+ _WEDGE_RECOVER_AFTER_FAILS,
+ RollingWhisperWake,
+)
+
+
+def _loud_chunk(marker: int, n: int = 1600) -> AudioChunk:
+ val = 12000 + (marker % 80) * 100
+ arr = np.full(n, val, dtype=np.int16)
+ return AudioChunk(pcm=arr.tobytes(), sample_rate=16000, timestamp_ns=0)
+
+
+def test_wedge_recover_threshold_is_snappy() -> None:
+ assert _WEDGE_RECOVER_AFTER_FAILS <= 2, (
+ "a wedged wake model must self-heal within ~2 failures so the wake is not "
+ "deaf for tens of seconds"
+ )
+
+
+class _HangingSTT:
+ """Every transcribe hangs forever; records how many times recover() ran and
+ at which failure count it first fired."""
+
+ def __init__(self) -> None:
+ self.calls = 0
+ self.recovered = 0
+ self.calls_at_first_recover: int | None = None
+
+ async def transcribe_pcm(self, pcm, sample_rate=16000, language=None): # noqa: ANN001
+ self.calls += 1
+ await asyncio.Event().wait() # the wedge — abandoned by the per-call timeout
+
+ def recover(self) -> None:
+ self.recovered += 1
+ if self.calls_at_first_recover is None:
+ self.calls_at_first_recover = self.calls
+
+
+async def test_wedge_self_heals_within_the_snappy_threshold() -> None:
+ stt = _HangingSTT()
+ wake = RollingWhisperWake(
+ stt,
+ pattern=re.compile(r"nico", re.IGNORECASE),
+ poll_interval_s=0.01,
+ cooldown_s=0.0,
+ save_debug_wavs=False,
+ min_rms=0.0,
+ min_peak=0.0,
+ transcribe_timeout_s=0.02, # fast so the wedge is detected quickly
+ )
+ src: asyncio.Queue = asyncio.Queue()
+ stop = asyncio.Event()
+
+ async def _iter():
+ while True:
+ chunk = await src.get()
+ if chunk is None:
+ return
+ yield chunk
+
+ async def _feed() -> None:
+ i = 0
+ while not stop.is_set():
+ await src.put(_loud_chunk(i))
+ i += 1
+ await asyncio.sleep(0.002)
+
+ async def _drive() -> None:
+ async for _kw in wake.detect(_iter()):
+ pass
+
+ feeder = asyncio.create_task(_feed())
+ drive = asyncio.create_task(_drive())
+ try:
+ for _ in range(300):
+ if stt.recovered >= 1:
+ break
+ await asyncio.sleep(0.02)
+ assert stt.recovered >= 1, "a wedged model never self-healed"
+ assert stt.calls_at_first_recover is not None
+ assert stt.calls_at_first_recover <= 2, (
+ f"self-heal took {stt.calls_at_first_recover} failures — too slow"
+ )
+ finally:
+ stop.set()
+ await src.put(None)
+ drive.cancel()
+ feeder.cancel()
+ for t in (drive, feeder):
+ try:
+ await t
+ except (asyncio.CancelledError, Exception): # noqa: BLE001, S110
+ pass