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-02 17:59)

Ruben Lütke85b099fdb609
diff --git a/jarvis/speech/pipeline.py b/jarvis/speech/pipeline.py
index bcde924301..475595d9e5 100644
--- a/jarvis/speech/pipeline.py
+++ b/jarvis/speech/pipeline.py
@@ -1096,12 +1096,15 @@ class SpeechPipeline:
# When a wake_plan is set, its matcher drives the phrase match so a
# custom phrase ("Computer") is detected instead of "jarvis".
if enable_whisper_wake and self._stt is not None:
+ _poll = self._wake_poll_interval()
if self._wake_matcher is not None:
self._whisper_wake = RollingWhisperWake(
- self._stt, pattern=self._wake_matcher
+ self._stt, pattern=self._wake_matcher, poll_interval_s=_poll
)
else:
- self._whisper_wake = RollingWhisperWake(self._stt)
+ self._whisper_wake = RollingWhisperWake(
+ self._stt, poll_interval_s=_poll
+ )
else:
self._whisper_wake = None
# require_hey_prefix may arrive either as an explicit kwarg or from
@@ -1570,6 +1573,22 @@ class SpeechPipeline:
if callable(setter):
setter(int(ms))
+ def _wake_poll_interval(self) -> float:
+ """The stt_match wake poll interval, derived from the user's Sensitivity
+ slider (``[trigger.wake_word].sensitivity``). Higher sensitivity polls
+ more often, so a spoken wake is picked up sooner. Defensive: any missing
+ field falls back to the balanced default. This is what makes the slider
+ actually DO something on the local-Whisper transcript path (it never
+ scored against the openWakeWord threshold the slider used to feed)."""
+ from jarvis.speech.wake_phrase import sensitivity_to_poll_interval
+
+ ww = getattr(getattr(self, "_config", None), "trigger", None)
+ ww = getattr(ww, "wake_word", None)
+ try:
+ return sensitivity_to_poll_interval(getattr(ww, "sensitivity", 0.5))
+ except (TypeError, ValueError):
+ return sensitivity_to_poll_interval(0.5)
+
def set_wake_plan(self, plan: Any) -> None:
"""Live-apply a resolved WakeWordPlan — no app/pipeline restart.
@@ -1642,7 +1661,9 @@ class SpeechPipeline:
if self._stt is not None:
self._openwakeword_enabled = False
self._whisper_wake = RollingWhisperWake(
- self._stt, pattern=self._wake_matcher
+ self._stt,
+ pattern=self._wake_matcher,
+ poll_interval_s=self._wake_poll_interval(),
)
self._whisper_wake_enabled = True
else:
diff --git a/jarvis/speech/rolling_whisper_wake.py b/jarvis/speech/rolling_whisper_wake.py
index b07f35d990..4f51ba964a 100644
--- a/jarvis/speech/rolling_whisper_wake.py
+++ b/jarvis/speech/rolling_whisper_wake.py
@@ -120,6 +120,17 @@ _BUSY_HANG_RECOVER_S = 20.0
# it never blocks transcription, so nothing that could be a wake is skipped.
_MATCH_MIN_SPEECH_RMS = 0.006
+# Latency: skip the bias-echo confirm's SECOND transcription when the matched
+# window is clearly LOUD. A window at real speaking volume is genuine speech,
+# never a silence echo, so the ~0.5 s unbiased re-transcription (measured
+# 0.56 s on a warm base/cpu wake model, live log 2026-07-02) is pure delay
+# there. Below this level the confirm still runs (the borderline band, where a
+# quiet primed hallucination is plausible). This roughly halves wake latency on
+# a normal, clearly-spoken wake — every genuine wake in the live log peaked at
+# rms 0.027-0.12, well above this bar. Silence is handled earlier and more
+# cheaply by the raw energy gate (``_MATCH_MIN_SPEECH_RMS``).
+_ECHO_CONFIRM_SKIP_RMS = 0.02
+
def _save_wav(pcm_bytes: bytes, sample_rate: int, path: Path) -> None:
"""Writes int16 PCM as a valid WAV file."""
@@ -177,7 +188,7 @@ class RollingWhisperWake:
# the bar within one snappier poll. The gates skip silence cheaply, so the
# extra polls only transcribe when a window actually passes the audio
# gates — negligible extra cost, a visibly faster reaction.
- poll_interval_s: float = 0.2,
+ poll_interval_s: float = 0.12,
cooldown_s: float = 5.0, # longer cooldown → less over-triggering
sample_rate: int = 16_000,
# 2026-04-22 (3rd iteration): RMS/peak gates back down to low. The
@@ -333,7 +344,7 @@ class RollingWhisperWake:
}
async def _is_prompt_echo(
- self, match: Any, window_text: str, pcm_bytes: bytes
+ self, match: Any, window_text: str, pcm_bytes: bytes, *, window_rms: float
) -> bool:
"""True when a matched candidate is the bias prompt ECHOING, not speech.
@@ -365,6 +376,11 @@ class RollingWhisperWake:
bias = getattr(self._stt, "bias_prompt", None)
if not bias:
return False # unprimed model -> echoes are impossible
+ # Latency fast-path: a clearly-loud window is real speech, not a silence
+ # echo — accept without the ~0.5 s second transcription. Below the bar
+ # the confirm still runs (the borderline band).
+ if window_rms >= _ECHO_CONFIRM_SKIP_RMS:
+ return False
window_tokens = normalize_phrase_for_match(window_text)
matched_tokens = normalize_phrase_for_match(match.group(0))
if len(window_tokens) > len(matched_tokens):
@@ -821,7 +837,9 @@ class RollingWhisperWake:
# the primed phrase may be the initial_prompt echoing on
# noise (ghost activations, live 2026-07-02). One unbiased
# second pass over the same window separates the two.
- if await self._is_prompt_echo(m, text, pcm_bytes):
+ if await self._is_prompt_echo(
+ m, text, pcm_bytes, window_rms=rms
+ ):
self._stat_suppressed_echo += 1
continue
self._stat_matched += 1
diff --git a/jarvis/speech/wake_phrase.py b/jarvis/speech/wake_phrase.py
index a54ed2a167..8e8955ab49 100644
--- a/jarvis/speech/wake_phrase.py
+++ b/jarvis/speech/wake_phrase.py
@@ -65,6 +65,27 @@ def sensitivity_to_threshold(sensitivity: float) -> float:
return PRODUCTION_WAKE_THRESHOLD + span * ((s - 0.5) / 0.5)
+# stt_match responsiveness: the openWakeWord threshold above is meaningless for
+# the local-Whisper transcript path (it does not score against a threshold), so
+# a custom-phrase user moving the Sensitivity slider felt NOTHING. Map the same
+# 0..1 slider onto how OFTEN that path re-transcribes the rolling window: a
+# higher sensitivity polls more often, so a spoken wake is picked up sooner.
+_POLL_INTERVAL_SLOW = 0.20 # sensitivity 0.0 — calmest, least CPU
+_POLL_INTERVAL_FAST = 0.08 # sensitivity 1.0 — snappiest reaction
+
+
+def sensitivity_to_poll_interval(sensitivity: float) -> float:
+ """Map a 0..1 sensitivity onto the stt_match wake poll interval (seconds).
+
+ Linear: 0.0 -> 0.20 s (calm), 1.0 -> 0.08 s (snappy). Higher sensitivity =>
+ shorter interval => the wake word is noticed sooner. This is the slider's
+ *felt* effect on the transcript-match path; the heavy latency win (skipping
+ the second confirming transcription on a clearly-loud wake) is unconditional.
+ """
+ s = max(0.0, min(1.0, float(sensitivity)))
+ return _POLL_INTERVAL_SLOW + (_POLL_INTERVAL_FAST - _POLL_INTERVAL_SLOW) * s
+
+
class _FuzzyMatch:
"""Minimal ``re.Match`` stand-in: only ``.group(0)`` is contracted."""
@@ -462,5 +483,6 @@ __all__ = [
"compile_wake_matcher",
"custom_model_matches_phrase",
"resolve_wake_plan",
+ "sensitivity_to_poll_interval",
"sensitivity_to_threshold",
]
diff --git a/tests/unit/speech/test_rolling_whisper_wake_echo_confirm.py b/tests/unit/speech/test_rolling_whisper_wake_echo_confirm.py
index 673b32ced1..243d1e9f03 100644
--- a/tests/unit/speech/test_rolling_whisper_wake_echo_confirm.py
+++ b/tests/unit/speech/test_rolling_whisper_wake_echo_confirm.py
@@ -22,7 +22,11 @@ from jarvis.speech.wake_phrase import compile_wake_matcher
def _loud_chunk(marker: int, n: int = 1600) -> AudioChunk:
- arr = np.full(n, 12000 + (marker % 5) * 100, dtype=np.int16)
+ # Borderline speaking volume (rms ~0.012): above the silence energy gate but
+ # BELOW the loud-skip bar (0.02), so the bias-echo confirm actually runs.
+ # A clearly-loud window intentionally skips the confirm for latency, so the
+ # echo logic under test here is exercised in the band where it still fires.
+ arr = np.full(n, 400 + (marker % 5) * 3, dtype=np.int16)
return AudioChunk(pcm=arr.tobytes(), sample_rate=16000, timestamp_ns=0)
diff --git a/tests/unit/speech/test_rolling_whisper_wake_silence_ghost.py b/tests/unit/speech/test_rolling_whisper_wake_silence_ghost.py
index 3986f64ffd..98b1c6a00e 100644
--- a/tests/unit/speech/test_rolling_whisper_wake_silence_ghost.py
+++ b/tests/unit/speech/test_rolling_whisper_wake_silence_ghost.py
@@ -185,6 +185,26 @@ async def test_confirm_error_does_not_drop_a_loud_wake() -> None:
assert await _first_yield(stt, _chunk(12000), phrase="Hey Mythos") is not None
+async def test_loud_wake_skips_the_confirm_for_low_latency() -> None:
+ """LATENCY: a clearly-loud wake (real speaking volume) must fire WITHOUT the
+ ~0.5s second confirming transcription — the confirm is a borderline-band
+ tool and the energy gate already rules out silence. If the confirm ran here,
+ the empty unbiased transcript would SUPPRESS; it fires, and the unbiased
+ pass is never called. This is what takes a normal wake from ~2s to ~0.5s."""
+ stt = _BiasedSTT(biased="Hey Nico", unbiased="")
+ assert await _first_yield(stt, _chunk(12000)) is not None
+ assert stt.unbiased_calls == 0, "confirm ran on a clearly-loud wake (latency cost)"
+
+
+async def test_borderline_quiet_wake_still_runs_the_confirm() -> None:
+ """Below the loud-skip bar the confirm still guards silence: a borderline
+ exact-phrase candidate (rms ~0.012, above the energy gate, below the loud
+ bar) whose unprimed ear hears nothing is suppressed."""
+ stt = _BiasedSTT(biased="Hey Nico", unbiased="")
+ assert await _first_yield(stt, _chunk(400)) is None
+ assert stt.unbiased_calls >= 1, "confirm was skipped on a borderline window"
+
+
async def test_genuine_quiet_wake_still_fires() -> None:
"""Regression guard: a genuine quiet wake (rms ~0.009, the quiet-mic
contract level) whose unprimed ear also hears speech must still fire — the