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.

perf(wake): gate the vosk early candidate reveal on the optimistic-reveal state

Ruben Lütke742021a43579
diff --git a/jarvis/speech/pipeline.py b/jarvis/speech/pipeline.py
index 86eb57b3ba..33452669d3 100644
--- a/jarvis/speech/pipeline.py
+++ b/jarvis/speech/pipeline.py
@@ -4311,7 +4311,19 @@ class SpeechPipeline:
poll cadence. ``active=False`` retracts if that candidate is later
rejected. Visual only: never opens a session, mirrors
``_on_wake_candidate`` on the orb-bridge side (ui/orb/bus_bridge.py).
+
+ The ``active=True`` publish is gated on the SAME
+ ``_should_show_optimistic_candidate()`` check the OWW branch uses —
+ chiefly its ``PipelineState.IDLE`` guard, since ``detect()`` can in
+ principle still be mid-candidate when a hotkey/PTT session starts the
+ state elsewhere. ``active=False`` is published unconditionally: the
+ bridge's retract handler is idempotent/no-op-safe against a retract
+ with no matching prior show (``ui/orb/bus_bridge.py::_on_wake_candidate``
+ — a real active session is left alone, an idle bar is simply
+ re-asserted idle), so it does not need the same gate.
"""
+ if active and not self._should_show_optimistic_candidate():
+ return
try:
await self._publish_event(
WakeCandidateDetected(source_layer="speech", active=active)
diff --git a/tests/unit/speech/test_wake_plan_vosk.py b/tests/unit/speech/test_wake_plan_vosk.py
index c99ffe68e6..6a44d52010 100644
--- a/tests/unit/speech/test_wake_plan_vosk.py
+++ b/tests/unit/speech/test_wake_plan_vosk.py
@@ -7,6 +7,8 @@ Whisper, and a missing vosk package or model falls through gracefully.
"""
from __future__ import annotations
+from collections.abc import AsyncIterator
+from dataclasses import dataclass
from pathlib import Path
from types import SimpleNamespace
@@ -16,6 +18,18 @@ from jarvis.speech.wake_constants import resolve_vosk_model_path
from jarvis.speech.wake_phrase import resolve_wake_plan
+@dataclass
+class _FakeTTS:
+ name: str = "fake-tts"
+ supports_streaming: bool = True
+
+ async def synthesize(
+ self, text: str, voice: str | None = None, language_code: str | None = None
+ ) -> AsyncIterator:
+ if False: # pragma: no cover
+ yield
+
+
def _cfg(phrase: str = "Hey Nova", engine: str = "auto", custom: str = "") -> SimpleNamespace:
return SimpleNamespace(
phrase=phrase,
@@ -133,28 +147,130 @@ def test_no_vosk_no_whisper_is_honest_wake_off(vosk_model_dir) -> None:
# --------------------------------------------------------------------------
+def test_set_wake_plan_vosk_wires_the_optimistic_candidate_callback(
+ vosk_model_dir,
+) -> None:
+ """Spawn-latency mission 2026-07-10: VoskKwsProvider gets a callback that
+ lets it publish an optimistic WakeCandidateDetected from INSIDE its own
+ detect loop, well before its confirm_tail_s wait + verify pass complete
+ -- this is the lever that beats that wait without shortening it."""
+ from jarvis.core.bus import EventBus
+ from jarvis.plugins.wake.vosk_kws_provider import VoskKwsProvider
+ from jarvis.speech.pipeline import SpeechPipeline
+
+ pipe = SpeechPipeline(
+ tts=_FakeTTS(), bus=EventBus(),
+ enable_openwakeword=False, enable_whisper_wake=False,
+ enable_local_whisper=False, config=None,
+ )
+ plan = resolve_wake_plan(
+ _cfg(), local_whisper_available=False, language="de", vosk_available=True
+ )
+ assert plan.engine == "vosk_kws"
+ pipe.set_wake_plan(plan)
+
+ assert isinstance(pipe._wake, VoskKwsProvider)
+ # Bound methods compare equal (same __self__/__func__) even though two
+ # separate attribute reads create distinct bound-method objects (`is`
+ # would flake here).
+ assert pipe._wake._on_candidate == pipe._on_vosk_wake_candidate # noqa: SLF001
+
+
+def test_constructor_wake_plan_also_wires_the_candidate_callback(
+ vosk_model_dir,
+) -> None:
+ """Same wiring, but through the INITIAL constructor path (a wake_plan
+ passed at construction) rather than the live-apply ``set_wake_plan``."""
+ from jarvis.core.bus import EventBus
+ from jarvis.plugins.wake.vosk_kws_provider import VoskKwsProvider
+ from jarvis.speech.pipeline import SpeechPipeline
+
+ plan = resolve_wake_plan(
+ _cfg(), local_whisper_available=False, language="de", vosk_available=True
+ )
+ assert plan.engine == "vosk_kws"
+
+ pipe = SpeechPipeline(
+ tts=_FakeTTS(), bus=EventBus(),
+ enable_openwakeword=False, enable_whisper_wake=False,
+ enable_local_whisper=False, config=None,
+ wake_plan=plan,
+ )
+
+ assert isinstance(pipe._wake, VoskKwsProvider)
+ assert pipe._wake._on_candidate == pipe._on_vosk_wake_candidate # noqa: SLF001
+
+
+async def test_on_vosk_wake_candidate_publishes_active_true_and_false(
+ vosk_model_dir,
+) -> None:
+ from jarvis.core.bus import EventBus
+ from jarvis.core.events import WakeCandidateDetected
+ from jarvis.speech.pipeline import SpeechPipeline
+
+ bus = EventBus()
+ received: list[WakeCandidateDetected] = []
+
+ async def _collect(event: WakeCandidateDetected) -> None:
+ received.append(event)
+
+ bus.subscribe(WakeCandidateDetected, _collect)
+
+ pipe = SpeechPipeline(
+ tts=_FakeTTS(), bus=bus,
+ enable_openwakeword=False, enable_whisper_wake=False,
+ enable_local_whisper=False, config=None,
+ )
+
+ await pipe._on_vosk_wake_candidate(True) # noqa: SLF001
+ await pipe._on_vosk_wake_candidate(False) # noqa: SLF001
+
+ assert [e.active for e in received] == [True, False]
+ assert all(e.source_layer == "speech" for e in received)
+
+
+async def test_on_vosk_wake_candidate_true_is_suppressed_when_not_idle(
+ vosk_model_dir,
+) -> None:
+ """The ``active=True`` publish shares ``_should_show_optimistic_candidate``
+ with the OWW branch — chiefly its PipelineState.IDLE guard, since
+ ``detect()`` can in principle still be mid-candidate right as a
+ hotkey/PTT session starts elsewhere. ``active=False`` stays unconditional
+ (the bridge's retract handler is safely idempotent against an unmatched
+ retract)."""
+ from jarvis.core.bus import EventBus
+ from jarvis.core.events import WakeCandidateDetected
+ from jarvis.speech.pipeline import PipelineState, SpeechPipeline
+
+ bus = EventBus()
+ received: list[WakeCandidateDetected] = []
+
+ async def _collect(event: WakeCandidateDetected) -> None:
+ received.append(event)
+
+ bus.subscribe(WakeCandidateDetected, _collect)
+
+ pipe = SpeechPipeline(
+ tts=_FakeTTS(), bus=bus,
+ enable_openwakeword=False, enable_whisper_wake=False,
+ enable_local_whisper=False, config=None,
+ )
+ pipe._state = PipelineState.ACTIVE
+
+ await pipe._on_vosk_wake_candidate(True) # noqa: SLF001
+ await pipe._on_vosk_wake_candidate(False) # noqa: SLF001
+
+ assert [e.active for e in received] == [False]
+
+
def test_set_wake_plan_vosk_arms_the_provider(vosk_model_dir) -> None:
# Regression guard for the 2026-07-06 live finding: the plan resolved to
# vosk_kws but the detector flag stayed off (OWW=off in the ready log), so
# the wake was silently dead. The vosk provider rides the OWW slot/loop —
# arming it must flip the flag on.
- from collections.abc import AsyncIterator
- from dataclasses import dataclass
-
from jarvis.plugins.wake.vosk_kws_provider import VoskKwsProvider
from jarvis.speech.pipeline import SpeechPipeline
- @dataclass
- class _FakeTTS:
- name: str = "fake-tts"
- supports_streaming: bool = True
-
- async def synthesize(
- self, text: str, voice: str | None = None, language_code: str | None = None
- ) -> AsyncIterator:
- if False: # pragma: no cover
- yield
-
pipe = SpeechPipeline(
tts=_FakeTTS(), bus=None,
enable_openwakeword=False, enable_whisper_wake=False,
diff --git a/tests/unit/speech/test_wake_prefix_gating.py b/tests/unit/speech/test_wake_prefix_gating.py
index 961054ce53..b2645916bb 100644
--- a/tests/unit/speech/test_wake_prefix_gating.py
+++ b/tests/unit/speech/test_wake_prefix_gating.py
@@ -354,6 +354,29 @@ def test_optimistic_candidate_hidden_when_not_idle() -> None:
assert pipe._should_show_optimistic_candidate() is False
+def test_optimistic_candidate_still_true_for_vosk_kws_when_idle() -> None:
+ """Spawn-latency mission 2026-07-10: ``_should_show_optimistic_candidate``
+ itself stays UNCHANGED for vosk_kws (still True) — the lock/not-activatable
+ retract safety-net in ``_run_parallel_wake`` reads this SAME flag to decide
+ whether to retract the EARLIER, provider-sourced candidate signal (see
+ ``VoskKwsProvider.on_candidate`` / ``_on_vosk_wake_candidate``) if a
+ confirmed vosk wake later gets discarded. Only the REDUNDANT duplicate
+ "active=True" publish at the OWW-result site is skipped for this engine
+ (that publish now runs too late to help — vosk's own confirm already
+ completed by the time this OWW-result path even sees the result), not
+ this gate itself.
+ """
+ from jarvis.speech.pipeline import PipelineState
+
+ pipe = _bare_pipeline(
+ require_hey_prefix=True,
+ utterance_stt=None,
+ wake_plan=SimpleNamespace(engine="vosk_kws", verify_prefix=False),
+ )
+ pipe._state = PipelineState.IDLE
+ assert pipe._should_show_optimistic_candidate() is True
+
+
# ---------------------------------------------------------------------------
# Real construction: require_hey_prefix flows from config into the pipeline.
# ---------------------------------------------------------------------------