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.

fix(wake): stop overlay-bar flicker + ghost activations from custom-model fire flood

Ruben Lütkea1f13c44752f
diff --git a/jarvis/speech/pipeline.py b/jarvis/speech/pipeline.py
index 2c11e8481c..c2622714cc 100644
--- a/jarvis/speech/pipeline.py
+++ b/jarvis/speech/pipeline.py
@@ -117,7 +117,11 @@ from jarvis.speech.hangup import (
from jarvis.speech.pending_buffer import PendingPromptBuffer
from jarvis.speech.persona import PhrasePicker, iter_all_start_ack
from jarvis.speech.rolling_whisper_wake import RollingWhisperWake
-from jarvis.speech.wake_verifier import verify_wake_with_stt
+from jarvis.speech.wake_verifier import (
+ CUSTOM_WAKE_MIN_RMS,
+ pcm_tail_rms,
+ verify_wake_with_stt,
+)
from jarvis.telemetry.latency import LatencyPhase, LatencyTracker
from jarvis.trigger.hotkey import HotkeyTrigger
@@ -3960,6 +3964,22 @@ class SpeechPipeline:
log.exception("Wake-Loop Fehler: %s", exc)
await asyncio.sleep(0.5)
+ def _should_show_optimistic_candidate(self) -> bool:
+ """Whether an unverified OWW hit may pop the overlay bar immediately.
+
+ The optimistic reveal exists so a genuine "Hey Jarvis" feels instant on
+ the precise pretrained model, where false candidates are rare and a
+ reject costs one brief bar flash. A user-trained custom_onnx model
+ fires on breath/ambient speech many times a minute (user GIF
+ 2026-07-02: the bar popped open/closed on auto-repeat), so for that
+ engine the bar appears only AFTER the STT verify confirms the wake —
+ a ~1 s later reveal instead of a constant flicker.
+ """
+ if self._state != PipelineState.IDLE:
+ return False
+ plan = getattr(self, "_wake_plan", None)
+ return not (plan is not None and getattr(plan, "engine", "") == "custom_onnx")
+
async def _verify_oww_hit(self, pcm_snapshot: bytes) -> bool:
"""Second-stage gate: ask the utterance STT whether the few seconds
leading up to an OpenWakeWord hit actually contained "hey/hi/hallo +
@@ -3992,6 +4012,30 @@ class SpeechPipeline:
plan = getattr(self, "_wake_plan", None)
if plan is not None and not getattr(plan, "verify_prefix", True):
return True
+ # A user-trained custom_onnx model is a WEAK discriminator (live
+ # forensic 2026-07-01/02: scores up to 1.000 on breath/ambient/other
+ # speech, 15 fires in 25 s at the worst). Its hits get the strict
+ # treatment throughout this gate.
+ custom_model_hit = (
+ plan is not None and getattr(plan, "engine", "") == "custom_onnx"
+ )
+ # Silence gate (custom only, BEFORE any STT round-trip): a hit whose
+ # trailing audio is essentially silent is a breath/noise false fire by
+ # definition — there is no speech an STT could confirm. Suppressing it
+ # here (a) kills the "fires out of nowhere" storm at zero cost and
+ # (b) stops the fire flood from hammering the verify STT into
+ # 429/timeouts (live 2026-07-02: that flood-induced outage is what
+ # opened the degrade-open hole and produced ghost activations).
+ if custom_model_hit and pcm_snapshot:
+ tail_rms = pcm_tail_rms(pcm_snapshot)
+ if tail_rms < CUSTOM_WAKE_MIN_RMS:
+ log.info(
+ "wake-verify: suppressed — near-silent audio "
+ "(rms %.4f < %.3f) on a custom-model hit; skipping STT",
+ tail_rms,
+ CUSTOM_WAKE_MIN_RMS,
+ )
+ return False
if self._utterance_stt is None:
log.warning(
"require_hey_prefix=True but no utterance STT — accepting OWW hit"
@@ -4010,28 +4054,32 @@ class SpeechPipeline:
)
if matched:
return True
- # A user-trained custom_onnx model is a WEAK discriminator (live
- # forensic 2026-07-01: scores up to 1.000 on breath/ambient/other
- # speech, several activations per minute). For that engine a WORKING
- # STT that heard no wake phrase — an empty transcript or a known
- # silence-hallucination boilerplate — is evidence of a false fire and
- # must SUPPRESS. The pretrained hey_jarvis path keeps its documented
- # degrade-open behaviour (its false fires happen on real speech, so an
- # empty transcript there really does mean the STT failed, forensic
- # 2026-06-28). A genuine STT OUTAGE (text is None) degrades open for
- # BOTH engines: a dead provider must never brick the wake (AP-22).
- custom_model_hit = (
- plan is not None and getattr(plan, "engine", "") == "custom_onnx"
- )
- # Degrade OPEN on a persistent verify-STT failure (Groq 429/503/
- # timeout after retries). OWW already fired strongly on audio we DID
- # capture, so an unreachable STT is a provider problem, not evidence
- # about what the user said. Accepting here keeps the wake alive
- # through a single-provider outage (AP-22 / open-source resilience:
- # one dead provider must never brick a core path, and recovery must be
- # reachable in-app, never via a restart). The documented honesty cost
- # is the occasional false positive while the STT is down.
+ # For a custom-model hit, a WORKING STT that heard no wake phrase —
+ # an empty transcript or a known silence-hallucination boilerplate —
+ # is evidence of a false fire and must SUPPRESS. The pretrained
+ # hey_jarvis path keeps its documented degrade-open behaviour (its
+ # false fires happen on real speech, so an empty transcript there
+ # really does mean the STT failed, forensic 2026-06-28).
+ #
+ # Persistent verify-STT failure (Groq 429/503/timeout after retries):
+ # - hey_jarvis: degrade OPEN. Candidates are rare, so an unreachable
+ # STT is a provider problem, not evidence about what the user said;
+ # accepting keeps the wake alive through an outage (AP-22).
+ # - custom_onnx: FAIL CLOSED (live 2026-07-02, 3 ghost activations
+ # overnight). The fire flood of a weak model eventually hits an STT
+ # timeout, and degrade-open then activates Jarvis although nobody
+ # spoke. The session a wake opens needs that same STT to hear
+ # anything (it would be a deaf session), and hotkey/orb-click remain
+ # as in-app activation paths — honest degradation, not a bricked
+ # wake.
if text is None:
+ if custom_model_hit:
+ log.info(
+ "wake-verify: suppressed — verify STT unreachable on a "
+ "custom-model hit (fail-closed: the session would be deaf "
+ "without STT; hotkey/orb-click still activate)"
+ )
+ return False
log.info(
"wake-verify: verify STT unreachable on a strong OWW hit — "
"accepting (degrade-open; an STT outage must not brick the "
@@ -4229,7 +4277,9 @@ class SpeechPipeline:
# (WakeCandidateDetected never opens a session turn),
# so a rejected candidate costs a brief bar flash, not
# a phantom session — retracted just below on reject.
- show_candidate = self._state == PipelineState.IDLE
+ # Custom-model candidates never reveal optimistically
+ # (constant flicker, see the helper's docstring).
+ show_candidate = self._should_show_optimistic_candidate()
if show_candidate:
await self._publish_event(
WakeCandidateDetected(
diff --git a/jarvis/speech/wake_verifier.py b/jarvis/speech/wake_verifier.py
index ae6250483e..ccd69cd5d2 100644
--- a/jarvis/speech/wake_verifier.py
+++ b/jarvis/speech/wake_verifier.py
@@ -19,12 +19,47 @@ import asyncio
import logging
from typing import Any, Protocol
+import numpy as np
+
from jarvis.speech.rolling_whisper_wake import DEFAULT_PATTERN
log = logging.getLogger("jarvis.wake.verifier")
WAKE_PREFIX_PATTERN = DEFAULT_PATTERN
+# Silence gate for user-trained custom_onnx wake hits (live forensic
+# 2026-07-02): such models fire on breath/near-silence many times a minute,
+# and each fire used to cost a full STT verify round-trip — the flood drove
+# the verify STT into 429/timeouts, whose degrade-open then produced ghost
+# activations. A hit whose trailing audio is essentially silent is a false
+# fire by definition and is suppressed BEFORE any STT call. Same normalised-
+# RMS convention and threshold as ``RollingWhisperWake``'s ``min_rms`` gate
+# (real speech on the reference headset is rms 0.01-0.02).
+CUSTOM_WAKE_MIN_RMS = 0.003
+# Window measured from the END of the capture buffer: the wake word must sit
+# immediately before the model fired. Long enough for any natural two-word
+# phrase, short enough that earlier room speech cannot mask a silent fire.
+CUSTOM_WAKE_RMS_TAIL_S = 1.5
+
+
+def pcm_tail_rms(
+ pcm_bytes: bytes,
+ sample_rate: int = 16_000,
+ tail_s: float = CUSTOM_WAKE_RMS_TAIL_S,
+) -> float:
+ """Normalised RMS ([-1, 1] scale) of the last ``tail_s`` seconds of int16 PCM.
+
+ Pure helper — no I/O. Empty input reads as 0.0; a torn trailing byte is
+ dropped rather than raising.
+ """
+ usable = len(pcm_bytes) // 2 * 2
+ if usable == 0:
+ return 0.0
+ samples = np.frombuffer(pcm_bytes[:usable], dtype=np.int16)
+ tail_samples = max(1, int(tail_s * sample_rate))
+ tail = samples[-tail_samples:].astype(np.float32) / 32768.0
+ return float(np.sqrt(np.mean(tail * tail) + 1e-12))
+
# A genuine "Hey Jarvis" must not be silently dropped just because the cloud
# STT was momentarily rate-limited (Groq 429) mid-session — that is the exact
# silent-drop the user reported as "Hey Jarvis stopped working". One retry with
diff --git a/tests/unit/speech/test_wake_prefix_gating.py b/tests/unit/speech/test_wake_prefix_gating.py
index 95410a0231..e72bf48597 100644
--- a/tests/unit/speech/test_wake_prefix_gating.py
+++ b/tests/unit/speech/test_wake_prefix_gating.py
@@ -50,6 +50,13 @@ class _FakeSTT:
PCM_2S_16K = b"\x00\x00" * 16_000 * 2
+# 2 s of a full-scale-ish square wave (rms ~0.09 normalised) — clears the
+# custom-model silence gate so tests exercise the transcript logic behind it.
+_LOUD_SAMPLE = (3000).to_bytes(2, "little", signed=True) + (-3000).to_bytes(
+ 2, "little", signed=True
+)
+LOUD_PCM_2S_16K = _LOUD_SAMPLE * 16_000
+
def _bare_pipeline(
*,
@@ -188,15 +195,19 @@ async def test_gate_degrades_open_when_stt_persistently_fails(monkeypatch) -> No
# ---------------------------------------------------------------------------
# custom_onnx hits: the verify transcript is the REAL discriminator.
#
-# Live forensic 2026-07-01 (false-positive storm): a user-trained custom model
-# scored breath/ambient/other speech up to 1.000 and activated several times a
-# minute even at threshold 0.50, with NO second-stage check (verify_prefix was
-# False for custom models). The fix: custom_onnx hits run the STT verify against
-# the phrase's own fuzzy matcher, and — unlike the precise pretrained hey_jarvis
-# model — "the STT worked but heard no wake phrase" (empty transcript or a known
-# silence-hallucination) SUPPRESSES instead of degrading open, because this
-# model demonstrably fires on breath/noise. A genuine STT outage still degrades
-# open (AP-22: a dead provider must never brick the wake path).
+# Live forensic 2026-07-01/02 (false-positive storm + flicker GIF): a
+# user-trained custom model scored breath/ambient/other speech up to 1.000 and
+# fired many times a minute even at threshold 0.50 (15 fires in 25 s at 07:37).
+# The verify layer therefore treats a custom-model hit as guilty until proven:
+# - near-silent audio suppresses BEFORE any STT call (the fire flood was
+# hammering the verify STT into 429/timeouts),
+# - "the STT worked but heard no wake phrase" (empty transcript or a known
+# silence-hallucination) suppresses,
+# - and an STT OUTAGE also suppresses (fail-closed): the very session a wake
+# would open needs that same STT to hear anything, so degrading open only
+# produced deaf ghost activations (3 overnight on 2026-07-02) — hotkey and
+# orb-click remain the in-app activation paths, so the wake is not bricked.
+# The precise pretrained hey_jarvis path keeps its documented degrade-open.
# ---------------------------------------------------------------------------
@@ -215,7 +226,7 @@ async def test_gate_custom_model_accepts_matching_phrase() -> None:
stt = _FakeSTT("hey nico wie spät ist es") # i18n-allow
pipe = _custom_pipeline(stt)
- assert await pipe._verify_oww_hit(PCM_2S_16K) is True
+ assert await pipe._verify_oww_hit(LOUD_PCM_2S_16K) is True
assert stt.calls == 1
@@ -225,7 +236,7 @@ async def test_gate_custom_model_accepts_sound_folded_spelling() -> None:
stt = _FakeSTT("Hey Niko")
pipe = _custom_pipeline(stt)
- assert await pipe._verify_oww_hit(PCM_2S_16K) is True
+ assert await pipe._verify_oww_hit(LOUD_PCM_2S_16K) is True
async def test_gate_custom_model_rejects_other_speech() -> None:
@@ -234,7 +245,31 @@ async def test_gate_custom_model_rejects_other_speech() -> None:
stt = _FakeSTT("und dann habe ich ihm gesagt dass das morgen fertig wird") # i18n-allow
pipe = _custom_pipeline(stt)
+ assert await pipe._verify_oww_hit(LOUD_PCM_2S_16K) is False
+ assert stt.calls == 1
+
+
+async def test_gate_custom_model_suppresses_silence_before_stt() -> None:
+ """Flood-breaker (live 2026-07-02): most custom-model false fires happen on
+ breath/near-silence; each used to cost a full STT verify round-trip, and the
+ resulting request flood drove the STT into 429/timeouts (which then opened
+ the degrade-open hole). Near-silent audio is suppressed WITHOUT any STT
+ call — same rms convention/threshold as RollingWhisperWake's silence gate."""
+ stt = _FakeSTT("Hey Nico") # would match if called — must NOT be called
+ pipe = _custom_pipeline(stt)
+
assert await pipe._verify_oww_hit(PCM_2S_16K) is False
+ assert stt.calls == 0, "silence must be suppressed before the STT round-trip"
+
+
+async def test_gate_hey_jarvis_has_no_silence_gate() -> None:
+ """The silence gate is custom_onnx-only: the pretrained hey_jarvis path
+ keeps verifying silent-ish buffers via STT (its 2026-06-28 forensics rely
+ on the transcript, not on energy)."""
+ stt = _FakeSTT("Hey Jarvis")
+ pipe = _bare_pipeline(require_hey_prefix=True, utterance_stt=stt)
+
+ assert await pipe._verify_oww_hit(PCM_2S_16K) is True
assert stt.calls == 1
@@ -248,7 +283,7 @@ async def test_gate_custom_model_rejects_empty_transcript(monkeypatch) -> None:
stt = _FakeSTT("")
pipe = _custom_pipeline(stt)
- assert await pipe._verify_oww_hit(PCM_2S_16K) is False
+ assert await pipe._verify_oww_hit(LOUD_PCM_2S_16K) is False
assert stt.calls == 1
@@ -258,22 +293,62 @@ async def test_gate_custom_model_rejects_hallucination_boilerplate() -> None:
stt = _FakeSTT("Vielen Dank.") # i18n-allow
pipe = _custom_pipeline(stt)
- assert await pipe._verify_oww_hit(PCM_2S_16K) is False
+ assert await pipe._verify_oww_hit(LOUD_PCM_2S_16K) is False
-async def test_gate_custom_model_degrades_open_on_stt_outage(monkeypatch) -> None:
- """A genuine STT outage (every attempt raises) still degrades open for
- custom models — one dead provider must never brick the wake (AP-22)."""
+async def test_gate_custom_model_fails_closed_on_stt_outage(monkeypatch) -> None:
+ """REGRESSION (live 2026-07-02, 3 ghost activations overnight): the fire
+ flood of a weak custom model eventually hits a verify-STT timeout/429, and
+ the old degrade-open then activated Jarvis although nobody spoke. For a
+ custom-model hit an STT outage now SUPPRESSES (fail-closed): the session a
+ wake opens needs that same STT anyway (it would be a deaf session), and
+ hotkey/orb-click remain as in-app activation paths — so this does not brick
+ the wake (AP-22 honoured by honest degradation, not by guessing)."""
import jarvis.speech.wake_verifier as wv
monkeypatch.setattr(wv, "_WAKE_VERIFY_BACKOFF_S", 0.0, raising=False)
stt = _RaisingSTT(RuntimeError("groq 503"))
pipe = _custom_pipeline(stt)
- assert await pipe._verify_oww_hit(PCM_2S_16K) is True
+ assert await pipe._verify_oww_hit(LOUD_PCM_2S_16K) is False
assert stt.calls >= 1
+# ---------------------------------------------------------------------------
+# Optimistic overlay reveal: suppressed for custom_onnx candidates.
+#
+# The optimistic bar exists so a genuine "Hey Jarvis" feels instant on the
+# precise pretrained model (false candidates are rare — a reject costs one
+# brief flash). A custom model fires many times a minute, so the same
+# optimism made the bar pop open/closed on auto-repeat (user GIF 2026-07-02).
+# For custom_onnx the bar appears only AFTER the verify confirms the wake.
+# ---------------------------------------------------------------------------
+
+
+def test_optimistic_candidate_shown_for_pretrained_when_idle() -> None:
+ from jarvis.speech.pipeline import PipelineState
+
+ pipe = _bare_pipeline(require_hey_prefix=True, utterance_stt=None)
+ pipe._state = PipelineState.IDLE
+ assert pipe._should_show_optimistic_candidate() is True
+
+
+def test_optimistic_candidate_hidden_for_custom_model() -> None:
+ from jarvis.speech.pipeline import PipelineState
+
+ pipe = _custom_pipeline(None)
+ pipe._state = PipelineState.IDLE
+ assert pipe._should_show_optimistic_candidate() is False
+
+
+def test_optimistic_candidate_hidden_when_not_idle() -> None:
+ from jarvis.speech.pipeline import PipelineState
+
+ pipe = _bare_pipeline(require_hey_prefix=True, utterance_stt=None)
+ pipe._state = PipelineState.ACTIVE
+ assert pipe._should_show_optimistic_candidate() is False
+
+
# ---------------------------------------------------------------------------
# Real construction: require_hey_prefix flows from config into the pipeline.
# ---------------------------------------------------------------------------
diff --git a/tests/unit/speech/test_wake_verifier.py b/tests/unit/speech/test_wake_verifier.py
index 048bf8a130..b15be2f09c 100644
--- a/tests/unit/speech/test_wake_verifier.py
+++ b/tests/unit/speech/test_wake_verifier.py
@@ -21,6 +21,8 @@ from dataclasses import dataclass
import pytest
from jarvis.speech.wake_verifier import (
+ CUSTOM_WAKE_MIN_RMS,
+ pcm_tail_rms,
transcript_has_hey_prefix,
verify_wake_with_stt,
)
@@ -209,6 +211,42 @@ async def test_verify_passes_through_language_override() -> None:
assert stt.calls == [(len(PCM_2S_16K), 16_000, "en")]
+# ---------------------------------------------------------------------------
+# pcm_tail_rms — the energy probe behind the custom-model silence gate. Same
+# normalised-RMS convention as RollingWhisperWake (silence << 0.003 << speech).
+# ---------------------------------------------------------------------------
+
+
+def _square_wave_pcm(seconds: float, amplitude: int, sample_rate: int = 16_000) -> bytes:
+ pair = amplitude.to_bytes(2, "little", signed=True) + (-amplitude).to_bytes(
+ 2, "little", signed=True
+ )
+ return pair * int(seconds * sample_rate / 2)
+
+
+def test_pcm_tail_rms_silence_is_below_gate() -> None:
+ assert pcm_tail_rms(b"\x00\x00" * 16_000 * 2) < CUSTOM_WAKE_MIN_RMS
+
+
+def test_pcm_tail_rms_speechlike_audio_clears_gate() -> None:
+ # amplitude 500/32768 ~ 0.015 rms — the quiet end of real speech on the
+ # reference headset (rms 0.01-0.02), still comfortably above the gate.
+ assert pcm_tail_rms(_square_wave_pcm(2.0, 500)) > CUSTOM_WAKE_MIN_RMS
+
+
+def test_pcm_tail_rms_only_measures_the_tail_window() -> None:
+ """Speech followed by a silent tail must read as silence: the wake word has
+ to be IN the tail window right before the model fired, not minutes ago."""
+ loud_then_silent = _square_wave_pcm(1.5, 3000) + b"\x00\x00" * (16_000 * 2)
+ assert pcm_tail_rms(loud_then_silent, tail_s=1.5) < CUSTOM_WAKE_MIN_RMS
+
+
+def test_pcm_tail_rms_handles_empty_and_odd_input() -> None:
+ assert pcm_tail_rms(b"") == 0.0
+ # Odd byte count (torn int16) must not raise.
+ assert pcm_tail_rms(b"\x01") >= 0.0
+
+
# ---------------------------------------------------------------------------
# Timeout cap — a wake-verify must never block the wake path for the full cloud
# STT client timeout (Groq default 30 s). A verify that takes seconds is