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(voice): the first start after a PC reboot stopped racing itself

rubenluetke10-beepcc8264315bd6
diff --git a/docs/BUGS.md b/docs/BUGS.md
index 8c165207d0..17b4755254 100644
--- a/docs/BUGS.md
+++ b/docs/BUGS.md
@@ -14973,3 +14973,111 @@ a `ValueError`), which is what let the bug through, plus
**Related.** AP-24 (a wedged native engine is replaced, never waited on — the
replacement worked, it was the call that was wrong), AP-22 (the local pass
declines crossably, so the chain behind it always had a provider).
+
+## BUG-214: the first start after a PC reboot left voice dead for minutes (HIGH, FIXED 2026-09-03)
+
+**Symptom.** After a Windows reboot the wake word and dictation were unusable
+for minutes; restarting the app by hand a few minutes later was fine. The wake
+detector's own boot number says it plainly — `Warm-up Phase A (wake-critical)
+per-loader (ms): wake-start=…` across the retained desktop logs:
+
+| when | wake-start | kind |
+|---|---:|---|
+| 2026-08-28 19:41 | 7 562 ms | warm restart |
+| **2026-08-29 09:40** | **53 391 ms** | **first start after reboot** |
+| 2026-08-29 09:43 (3 min later) | 3 531 ms | warm restart |
+| 2026-08-31 19:12 – 19:52 (4×) | 1 907 – 3 203 ms | warm restarts |
+| **2026-09-01 15:05** | **31 641 ms** | **first start after reboot** |
+| 2026-09-01 16:23 – 2026-09-02 17:01 (8×) | 0 – 3 609 ms | warm restarts |
+| **2026-09-03 08:10** | **34 797 ms** | **first start after reboot** |
+
+Dictation was worse. On the 2026-09-03 boot (PC up 08:07:14, app launched
+08:08:28) `Dictation STT warm-up done in 137610 ms` landed at 08:12:59 — the
+local engine was usable **4 min 31 s after power-on**, and every press until
+then crossed to a cloud that answers in 0.57 s. The same model loads in 3.5 s
+warm, measured directly.
+
+**Root cause.** Four independent things, none of them the machine being slow.
+
+1. *A model load nothing would ever adopt.* `start_wake_model_prefetch` fired
+ unconditionally from `desktop_app._run_backend`. Its weights land in a
+ hand-over cache whose only reader is `FasterWhisperProvider._build_model`,
+ and that provider is built only for `heavy_local_whisper` or a plan with
+ `needs_local_whisper`. On a `vosk_kws` / `custom_onnx` / openWakeWord host
+ neither holds, so a cold-disk `base` load plus a priming decode ran for
+ nothing — the silent 08:09:21 → 08:09:59 hole in the log — competing for the
+ disk with the models the user was waiting for, and then sat in a module
+ global for the life of the process.
+2. *The two Vosk wake models loaded one after the other.* `VoskKwsProvider.start`
+ gathers over the model paths and its docstring claims concurrency, but
+ `_ensure_model` holds ONE provider-wide lock around each `Model()` load:
+ en 21.8 s **then** de 11.4 s (warm: 0.5 + 0.7). Loading both languages is
+ deliberate and stays — a phrase and the speaker's language routinely diverge.
+3. *The wake-priority gate was armed only for local Whisper.* `_heavy_backend_bg`
+ holds the server, brain, MCP, workflows and conductor behind the wake model
+ with a 12 s ceiling, and `_wake_model_is_loaded()` already preferred the
+ detector's own `is_warm` — written for exactly this case after the 2026-07-17
+ forensic. It was never reached: the gate was released whenever `stt is None`,
+ which is every non-Whisper wake engine. So it opened BEFORE
+ `VoskKwsProvider.start()` began, and a wiki FTS rebuild of 94 pages, the
+ mission stack, a worktree prune and the session recorder all ran straight
+ through the wake load. The same condition guarded
+ `signal_wake_model_expected()`, so the deferred registry disk scans never
+ yielded either.
+4. *A press during the cold dictation load made it worse.* `LocalFinalSTT`
+ exposed no `is_loading`, so `_await_warmup_or_cold_load` read a 137 s first
+ load as a wedge, gave up at 20 s, cancelled the warm-up and rebuilt the
+ chain — and since cancelling `asyncio.to_thread` does not stop the running
+ thread, the fresh instance spawned a SECOND multi-gigabyte worker onto a card
+ already loading one (the BUG-204 shape). A press also queued on the blocking
+ spawn lock for the whole load.
+
+**Fix.**
+1. `wake_whisper_is_consumed()` (`jarvis/plugins/stt/__init__.py`) resolves the
+ wake plan INSIDE the prefetch thread and skips the load where nothing would
+ adopt it; an unreadable plan prefetches anyway, reproducing the old
+ behaviour rather than risking a slower wake for the hosts that need it.
+2. `detector_gates_the_backend()` (`jarvis/ui/desktop_app.py`) gates on the
+ capability, never an engine name (AP-21): a detector that reports warmth AND
+ will actually be started is one worth waiting for. It also signals
+ `signal_wake_model_expected()` on that path. Every ceiling stays — 12 s on
+ the heavy backend, the ~20 s poll cap, 12 s in `await_wake_model_ready` — so
+ a detector that never warms costs a bounded wait, never a hang.
+3. `LocalFinalSTT.is_loading` tells a slow first load from a hang, and
+ `_ensure_worker(blocking=False)` on the press path answers a queued caller
+ with the crossable `LocalEngineUnavailable` instead of parking a thread for
+ the length of the load. `_join_dictation_warmup` returns immediately while a
+ local engine is still starting and an alternate exists — the load keeps
+ running, the press crosses.
+4. Both slow loads now log their duration, because neither did: the wake-model
+ prefetch and the dictation engine were the two silent stretches of the boot.
+
+Item 2 of the root cause (the serial Vosk load, ~11 s) is deliberately NOT
+fixed here: `Model()` does not go through `vosk_native.native_call`, so two
+concurrent `vosk_model_new` calls have never run in this codebase, and BUG-151's
+history says not to assume. It needs a `model-concurrent` mode in
+`scripts/vosk_native_stress.py` and the same acceptance bar (3 × 180 s clean on
+Windows) before the lock is narrowed.
+
+**Guard.** `tests/unit/stt/test_wake_prefetch_gate.py` (the predicate's truth
+table, including "stt_match still prefetches" and "an unreadable config
+prefetches"), `tests/unit/ui/test_wake_gate_predicate.py` (which detectors gate
+the backend, and that headless/voice-off/second-instance never pay a ceiling),
+and two new cases in `tests/unit/dictation/test_local_final.py` pinning that a
+press during a cold spawn crosses rather than waiting and that exactly one
+worker is ever spawned.
+
+**Verification.** The honest test is a real reboot; every harness in the tree
+(`scripts/measure_desktop_boot.py`, `scripts/ci/check_boot_budget.py`) measures
+an isolated boot on a WARM page cache and cannot see this class. On the next
+cold boot read `wake-start=` (target < 10 000 ms), `Local dictation engine ready
+in …` (target < 30 000 ms), and confirm no `Processing audio with duration
+00:01.000` line appears on a vosk_kws host.
+
+**Related.** BUG-189 (the cold-boot storm and the `wake-start` metric),
+BUG-210 (autostart priority — the 2026-09-01 six-wave fix, which improved this
+but did not close it), BUG-204 (VRAM oversubscription — the shape item 4 could
+reach), AP-21 (gate on capability, never a provider name), AP-24 (a wedged
+native engine is replaced, never waited on), AP-26 (nothing initialises on the
+boot critical path — this removes work from it), AP-30 (every new skip branch
+logs its reason).
diff --git a/jarvis/dictation/local_final.py b/jarvis/dictation/local_final.py
index fdc33e4b20..ecdf2f5935 100644
--- a/jarvis/dictation/local_final.py
+++ b/jarvis/dictation/local_final.py
@@ -137,6 +137,12 @@ class LocalFinalSTT:
self._engine_compute = ""
self._spawn_lock = threading.Lock()
self._call_lock = threading.Lock()
+ #: True while a worker spawn is in flight. Read WITHOUT the lock (a bool
+ #: read is atomic) because the whole point is to answer while the lock is
+ #: held: a cold spawn takes minutes on a contended box (137 s on the
+ #: 2026-09-03 boot), and both a press and the dictation lane's own
+ #: patience check must be able to see "starting" rather than "wedged".
+ self._spawn_in_flight = False
self._next_attempt_at = 0.0
self._last_refusal = ""
@@ -160,6 +166,20 @@ class LocalFinalSTT:
def is_warm(self) -> bool:
return self._worker is not None
+ @property
+ def is_loading(self) -> bool:
+ """True while the worker is coming up — starting, not wedged.
+
+ The dictation lane reads this through the chain's attribute forwarding
+ (``FallbackSTT.__getattr__``) to tell a slow FIRST load from a hung
+ provider. Without it a cold load looked like a wedge: the lane gave up
+ at its 20 s ceiling, cancelled the warm-up and rebuilt the chain — and
+ since cancelling ``asyncio.to_thread`` does not stop the running thread,
+ the fresh instance spawned a SECOND multi-gigabyte worker onto a card
+ already loading one (the BUG-204 shape).
+ """
+ return self._spawn_in_flight
+
@property
def device(self) -> str:
"""``"cuda"`` / ``"cpu"`` of the live worker, ``""`` without one."""
@@ -224,7 +244,7 @@ class LocalFinalSTT:
self._call_lock.release()
def _transcribe_blocking(self, pcm_bytes: bytes, language: str | None) -> Transcript:
- worker = self._ensure_worker()
+ worker = self._ensure_worker(blocking=False)
if worker is None:
raise LocalEngineUnavailable(self._last_refusal or "no local dictation worker")
import numpy as np
@@ -285,49 +305,78 @@ class LocalFinalSTT:
# Worker ownership
# ------------------------------------------------------------------
- def _ensure_worker(self) -> Any:
- """The live worker, spawning one when allowed; ``None`` when declined."""
- with self._spawn_lock:
- if self._worker is not None:
- return self._worker
- now = time.monotonic()
- if now < self._next_attempt_at:
- return None
- self._next_attempt_at = now + _RETRY_AFTER_S
- refusal = self._spawn_refusal()
- if refusal:
- self._last_refusal = refusal
- log.info("Local dictation engine not started: %s", refusal)
- return None
- from jarvis.dictation.local_preview import _spawn_worker_model
+ def _ensure_worker(self, *, blocking: bool = True) -> Any:
+ """The live worker, spawning one when allowed; ``None`` when declined.
+
+ ``blocking=False`` is the PRESS path. A caller that would have to queue
+ behind an in-flight spawn is told so instead of waiting it out, so the
+ chain crosses to the cloud in milliseconds rather than holding a worker
+ thread for the length of a cold model load — 137 s on the 2026-09-03
+ boot, during which every dictation would otherwise have stalled.
+ """
+ if self._worker is not None:
+ return self._worker # set once, never mutated in place
+ if not self._spawn_lock.acquire(blocking=blocking):
+ raise LocalEngineUnavailable(
+ "the local dictation engine is still starting; this call goes "
+ "to the next provider"
+ )
+ try:
+ return self._spawn_worker_locked()
+ finally:
+ self._spawn_lock.release()
+
+ def _spawn_worker_locked(self) -> Any:
+ """Spawn and adopt a worker. Caller holds ``_spawn_lock``."""
+ if self._worker is not None:
+ return self._worker
+ now = time.monotonic()
+ if now < self._next_attempt_at:
+ return None
+ self._next_attempt_at = now + _RETRY_AFTER_S
+ refusal = self._spawn_refusal()
+ if refusal:
+ self._last_refusal = refusal
+ log.info("Local dictation engine not started: %s", refusal)
+ return None
+ from jarvis.dictation.local_preview import _spawn_worker_model
+ started = time.perf_counter()
+ self._spawn_in_flight = True
+ try:
worker = _spawn_worker_model(self._model_name, compute=self._compute)
- if worker is None:
- self._last_refusal = "the dictation worker did not come up"
- return None
- device = str(getattr(worker, "device", "") or "")
- if device == "cpu":
- # A beam-search turbo decode of a 25 s window on a CPU takes
- # longer than the cloud round-trip it would replace; the
- # preview keeps its own CPU floor, the final pass does not.
- worker.close()
- self._last_refusal = (
- "the local engine only runs on the CPU here, which is slower "
- "than the configured provider for a final pass"
- )
- log.info("Local dictation engine declined: %s", self._last_refusal)
- return None
- self._worker = worker
- self._device = device
- self._engine_compute = str(getattr(worker, "compute", "") or "")
- self._last_refusal = ""
- log.info(
- "Local dictation engine ready: %s on %s (%s), out of process.",
- self._model_name,
- self._device,
- self._engine_compute,
+ finally:
+ self._spawn_in_flight = False
+ if worker is None:
+ self._last_refusal = "the dictation worker did not come up"
+ return None
+ device = str(getattr(worker, "device", "") or "")
+ if device == "cpu":
+ # A beam-search turbo decode of a 25 s window on a CPU takes
+ # longer than the cloud round-trip it would replace; the
+ # preview keeps its own CPU floor, the final pass does not.
+ worker.close()
+ self._last_refusal = (
+ "the local engine only runs on the CPU here, which is slower "
+ "than the configured provider for a final pass"
)
- return worker
+ log.info("Local dictation engine declined: %s", self._last_refusal)
+ return None
+ self._worker = worker
+ self._device = device
+ self._engine_compute = str(getattr(worker, "compute", "") or "")
+ self._last_refusal = ""
+ # Timed: a cold load is two orders of magnitude slower than a warm one
+ # (137 s against 3.5 s measured), and the number is the only way to see
+ # from the log which one a boot got.
+ log.info(
+ "Local dictation engine ready in %.0f ms: %s on %s (%s), out of process.",
+ (time.perf_counter() - started) * 1000.0,
+ self._model_name,
+ self._device,
+ self._engine_compute,
+ )
+ return worker
def _spawn_refusal(self) -> str:
"""Why the worker must not be started right now, or ``""``."""
diff --git a/jarvis/plugins/stt/__init__.py b/jarvis/plugins/stt/__init__.py
index a92cd3238b..757cb8c2d9 100644
--- a/jarvis/plugins/stt/__init__.py
+++ b/jarvis/plugins/stt/__init__.py
@@ -1316,11 +1316,52 @@ def build_wake_whisper(
)
+def wake_whisper_is_consumed(app_cfg: Any) -> tuple[bool, str]:
+ """Whether THIS configuration will build a local wake Whisper at all.
+
+ ``(will_it, reason)``. The predicate is the same expression the build site
+ uses (``desktop_app._start_speech_and_orb``): a wake Whisper is only ever
+ constructed for ``[trigger].heavy_local_whisper`` or a plan whose engine
+ needs one. Every other engine — vosk_kws, custom_onnx, openWakeWord, or no
+ wake at all — never builds one, so the prefetched weights are never adopted
+ (the only adopter is ``FasterWhisperProvider._build_model``) and sit in the
+ hand-over cache for the life of the process.
+
+ Cold-boot forensics 2026-09-03: on a vosk_kws host that dead prefetch spent
+ ~50 s of cold disk and one priming decode competing with the wake models and
+ the dictation model it delayed.
+
+ Resolving the plan is cheap and pure (config + a few directory stats), and
+ this runs off the boot path. Any failure answers ``True`` — reproducing
+ today's unconditional behaviour rather than risking a slower wake.
+ """
+ try:
+ import importlib.util as _ilu
+
+ from jarvis.speech.wake_model_fetch import resolve_wake_language
+ from jarvis.speech.wake_phrase import resolve_wake_plan
+
+ trigger = getattr(app_cfg, "trigger", None)
+ if bool(getattr(trigger, "heavy_local_whisper", False)):
+ return True, "trigger.heavy_local_whisper is on"
+ plan = resolve_wake_plan(
+ app_cfg.trigger.wake_word,
+ local_whisper_available=_ilu.find_spec("faster_whisper") is not None,
+ language=resolve_wake_language(app_cfg),
+ )
+ if plan.needs_local_whisper:
+ return True, f"the {plan.engine} wake engine transcribes locally"
+ return False, f"the {plan.engine} wake engine never builds one"
+ except Exception as exc: # noqa: BLE001 — an unreadable plan must not skip the prefetch
+ return True, f"the wake plan could not be resolved ({exc}); prefetching anyway"
+
+
def start_wake_model_prefetch(
stt_cfg: Any,
*,
language: str | None = None,
wake_phrase: str | None = None,
+ app_cfg: Any = None,
) -> Any:
"""Load the fast-first wake Whisper MODEL in a daemon thread, off the boot
critical path (TTU iteration 10, docs/diagnostics/BOOT-TTU-NOTES.md).
@@ -1340,10 +1381,16 @@ def start_wake_model_prefetch(
no torch; the first real torch import (Silero VAD) happens seconds later
in the deferred loaders, so the shield race window stays clear.
+ ``app_cfg``, when given, decides whether this host has a consumer for the
+ weights at all (:func:`wake_whisper_is_consumed`) — the check runs INSIDE
+ the thread, so the caller pays nothing for it. Without it the prefetch
+ behaves exactly as before and always loads.
+
No-op when voice is disabled (``JARVIS_VOICE``) or on any failure —
a prefetch must never break boot. Returns the thread or ``None``.
"""
import threading
+ import time
from jarvis.speech.warmup_prefetch import _voice_disabled
@@ -1352,6 +1399,16 @@ def start_wake_model_prefetch(
def _load() -> None:
try:
+ if app_cfg is not None:
+ consumed, why = wake_whisper_is_consumed(app_cfg)
+ if not consumed:
+ logger.info(
+ "Wake-model prefetch skipped: {} — nothing would adopt "
+ "the weights, and loading them competes with the wake "
+ "model for a cold disk.",
+ why,
+ )
+ return
from jarvis.plugins.stt.fwhisper import prefetch_model
probe = build_wake_whisper(
@@ -1360,12 +1417,22 @@ def start_wake_model_prefetch(
wake_phrase=wake_phrase,
fast_first=True,
)
+ started = time.perf_counter()
prefetch_model(
probe._model_name, # noqa: SLF001 — resolved params, same module family
probe._device, # noqa: SLF001
probe._compute_type, # noqa: SLF001
probe._cpu_threads, # noqa: SLF001
)
+ # Timed because it is invisible otherwise: the load holds no lock
+ # anyone logs and left a 38 s hole in the 2026-09-03 cold boot.
+ logger.info(
+ "Wake-model prefetch done in {:.0f} ms ({}/{}/{}).",
+ (time.perf_counter() - started) * 1000.0,
+ probe._model_name, # noqa: SLF001
+ probe._device, # noqa: SLF001
+ probe._compute_type, # noqa: SLF001
+ )
except Exception as exc: # noqa: BLE001 — a prefetch must never break boot
logger.debug("Wake-model prefetch skipped: {}", exc)
@@ -1386,4 +1453,5 @@ __all__ = [
"start_wake_model_prefetch",
"stt_family_id",
"wake_gpu_probe_cached",
+ "wake_whisper_is_consumed",
]
diff --git a/jarvis/speech/pipeline.py b/jarvis/speech/pipeline.py
index 96965b05d1..7d10ba8e67 100644
--- a/jarvis/speech/pipeline.py
+++ b/jarvis/speech/pipeline.py
@@ -11080,6 +11080,22 @@ class SpeechPipeline:
or getattr(self, "_dictation_warmup_provider", None) is not provider
):
return provider
+ # A local engine that is still COMING UP is not something to wait out
+ # when there is a provider behind it: the first load after a PC reboot
+ # took 137 s (2026-09-03), and a press that waited for it would be far
+ # slower than the cloud round-trip it is holding up. Leave the warm-up
+ # running — cancelling it here is what used to spawn a second engine
+ # onto the same card — and let the chain cross for THIS press.
+ # Without an alternate there is nothing to cross to, so the patient
+ # join stays: an honest wait beats an honest error.
+ if getattr(provider, "is_loading", False) and getattr(
+ provider, "_alternate_names", ()
+ ):
+ log.info(
+ "Dictation STT is still starting its local engine; this press "
+ "goes to the next provider and the load keeps running."
+ )
+ return provider
try:
await self._await_warmup_or_cold_load(task, provider)
return provider
diff --git a/jarvis/ui/desktop_app.py b/jarvis/ui/desktop_app.py
index 8e0507c245..2f65e96450 100644
--- a/jarvis/ui/desktop_app.py
+++ b/jarvis/ui/desktop_app.py
@@ -1371,6 +1371,37 @@ def _silence_health_probe_log() -> None:
logging.getLogger("httpx").addFilter(_health_probe_log_filter)
+def detector_gates_the_backend(pipeline: Any) -> bool:
+ """Whether the heavy backend must wait for THIS wake detector to warm up.
+
+ The boot gate (``_heavy_backend_bg``) holds the server, brain, MCP,
+ workflows and the conductor behind the wake model so the load the user is
+ waiting for is not starved by housekeeping. It used to be armed only when
+ voice boot built a local Whisper — which left every other detector that
+ loads its own models ungated. ``vosk_kws`` loads one Kaldi model per
+ installed language inside ``wake.start()``, so on a cold boot the gate
+ released BEFORE the load began and a wiki FTS rebuild, the mission stack
+ and a worktree prune ran straight through it (BUG-214: en 21.8 s + de
+ 11.4 s, wake ready 2 min 12 s after launch).
+
+ Gate on the CAPABILITY, never on an engine name (AP-21):
+
+ * the detector must REPORT warmth — without ``is_warm`` there is nothing to
+ wait for and waiting would be a guess;
+ * it must actually be STARTED — ``_openwakeword_enabled`` is the same flag
+ ``SpeechPipeline._start_wake`` checks, and the pipeline lowers it for a
+ non-primary instance, so a second instance never taxes the first's boot.
+
+ False keeps the historical behaviour: release the gate at once. Every
+ caller of this still holds its own ceiling, so a detector that never warms
+ costs a bounded wait, never a hang.
+ """
+ detector = getattr(pipeline, "_wake", None)
+ if getattr(detector, "is_warm", None) is None:
+ return False
+ return bool(getattr(pipeline, "_openwakeword_enabled", False))
+
+
class DesktopApp:
"""Orchestrates the pywebview window + backend thread.
@@ -1676,10 +1707,14 @@ class DesktopApp:
# Wake-model prefetch overlaps the heavy backend build and is adopted by
# the later provider warm-up. It is a no-op when voice is disabled and
# must never make the visible desktop startup load-bearing.
+ # ``app_cfg`` lets it skip itself on a host whose wake engine never
+ # builds a Whisper to adopt the weights (vosk_kws, custom_onnx, OWW):
+ # there the load was ~50 s of cold disk for nothing, in front of the
+ # models the user is actually waiting for (BUG-214).
try:
from jarvis.plugins.stt import start_wake_model_prefetch
- start_wake_model_prefetch(self.cfg.stt)
+ start_wake_model_prefetch(self.cfg.stt, app_cfg=self.cfg)
except Exception: # noqa: BLE001, S110 — prefetch never blocks boot
pass
@@ -4173,10 +4208,14 @@ class DesktopApp:
from jarvis.core import runtime_refs as _rr_ready
- if stt is None:
+ if stt is None and not detector_gates_the_backend(pipeline):
self._wake_model_loaded.set()
_rr_ready.signal_wake_model_ready()
else:
+ # Tell the boot-storm housekeeping (deferred registry disk scans)
+ # that a wake model is loading, so it yields disk to it first.
+ # This used to be signalled only on the local-Whisper path.
+ _rr_ready.signal_wake_model_expected()
async def _signal_wake_model_loaded() -> None:
for _ in range(40): # ~20 s cap, then release the gate anyway
diff --git a/tests/unit/dictation/test_local_final.py b/tests/unit/dictation/test_local_final.py
index d6827fe013..cf39c1affa 100644
--- a/tests/unit/dictation/test_local_final.py
+++ b/tests/unit/dictation/test_local_final.py
@@ -7,6 +7,7 @@ No subprocess and no model anywhere here — the worker proxy is a fake with the
from __future__ import annotations
import asyncio
+import threading
from types import SimpleNamespace
from typing import Any
@@ -218,6 +219,60 @@ def test_a_failing_worker_is_replaced_and_the_call_crosses_over(
assert len(_local_ok["args"]) == 2
+def test_a_press_during_a_cold_spawn_crosses_instead_of_waiting_it_out(
+ _local_ok: dict[str, Any], monkeypatch: pytest.MonkeyPatch
+) -> None:
+ """A cold spawn takes minutes on a contended box (137 s measured on the
+ 2026-09-03 boot). A press must not park a worker thread behind it — it
+ crosses to the cloud and comes back to the local engine once it is up."""
+ import jarvis.dictation.local_preview as preview_mod
+
+ release = threading.Event()
+ spawning = threading.Event()
+
+ spawns: list[str] = []
+
+ def _slow_spawn(model_name: str, *, compute: str | None = None) -> _FakeWorker:
+ spawns.append(model_name)
+ spawning.set()
+ release.wait(timeout=5.0)
+ return _FakeWorker()
+
+ monkeypatch.setattr(preview_mod, "_spawn_worker_model", _slow_spawn)
+ stt = LocalFinalSTT()
+
+ warmer = threading.Thread(target=stt.warm_up, name="test-warmup")
+ warmer.start()
+ try:
+ assert spawning.wait(timeout=5.0)
+ assert stt.is_loading is True # starting, not wedged
+
+ with pytest.raises(LocalEngineUnavailable) as caught:
+ asyncio.run(stt.transcribe_pcm(_pcm()))
+ assert "still starting" in str(caught.value)
+ # Crossable, so the chain reaches the cloud rather than ending the press.
+ assert is_crossable_failure(classify_stt_failure(caught.value))
+ finally:
+ release.set()
+ warmer.join(timeout=5.0)
+
+ assert stt.is_warm
+ assert stt.is_loading is False
+ # One spawn, not two: the press never started a second worker on the card.
+ assert len(spawns) == 1
+
+
+def test_is_loading_is_false_when_nothing_is_starting(_local_ok: dict[str, Any]) -> None:
+ """The dictation lane reads this to tell a slow first load from a hang; it
+ must not claim a load that is not happening."""
+ stt = LocalFinalSTT()
+
+ assert stt.is_loading is False
+ asyncio.run(stt.transcribe_pcm(_pcm()))
+ assert stt.is_loading is False
+ assert stt.is_warm
+
+
def test_a_second_caller_replaces_an_abandoned_worker(
_local_ok: dict[str, Any],
) -> None:
diff --git a/tests/unit/stt/test_wake_prefetch_gate.py b/tests/unit/stt/test_wake_prefetch_gate.py
new file mode 100644
index 0000000000..0b8ba4c96d
--- /dev/null
+++ b/tests/unit/stt/test_wake_prefetch_gate.py
@@ -0,0 +1,98 @@
+"""The wake-model prefetch only runs where something adopts the weights.
+
+The prefetch loads a faster-whisper model into a hand-over cache whose only
+reader is ``FasterWhisperProvider._build_model``. A host whose wake engine
+never builds one — vosk_kws, custom_onnx, openWakeWord — therefore paid a full
+cold-disk model load plus a priming decode for weights nobody would ever take,
+in front of the models the user is actually waiting for (BUG-214: ~50 s of the
+2026-09-03 cold boot).
+
+These tests pin the predicate, not the thread: the decision runs inside the
+prefetch thread, so asserting on it directly is what keeps the boot path free
+of the check.
+"""
+
+from __future__ import annotations
+
+from types import SimpleNamespace
+from typing import Any
+
+import pytest
+
+from jarvis.plugins.stt import wake_whisper_is_consumed
+
+
+def _cfg(
+ *,
+ phrase: str = "Hey Nova",
+ engine: str = "auto",
+ language: str = "de",
+ heavy: bool = False,
+) -> SimpleNamespace:
+ """A duck-typed app config — every read in the predicate is a getattr chain."""
+ return SimpleNamespace(
+ trigger=SimpleNamespace(
+ heavy_local_whisper=heavy,
+ wake_word=SimpleNamespace(
+ phrase=phrase,
+ engine=engine,
+ custom_model_path="",
+ sensitivity=0.5,
+ fuzzy_match_ratio=0.8,
+ language=language,
+ ),
+ ),
+ stt=SimpleNamespace(language="auto"),
+ ui=SimpleNamespace(language="de"),
+ )
+
+
+def vosk_installed(tmp_path, monkeypatch) -> None:
+ """A German Vosk model on disk, which makes resolve_wake_plan pick vosk_kws."""
+ monkeypatch.setenv("JARVIS__MEMORY__DATA_DIR", str(tmp_path))
+ (tmp_path / "wake_models" / "vosk" / "de" / "vosk-model-small-de-0.15" / "am").mkdir(
+ parents=True
+ )
+
+
+def no_vosk(tmp_path, monkeypatch) -> None:
+ """No Vosk model anywhere, so an arbitrary phrase falls to stt_match."""
+ monkeypatch.setenv("JARVIS__MEMORY__DATA_DIR", str(tmp_path))
+
+
+def test_a_vosk_host_skips_the_prefetch(vosk_installed) -> None:
+ """The whole point: nothing on a vosk_kws host would adopt the weights."""
+ consumed, reason = wake_whisper_is_consumed(_cfg())
+
+ assert consumed is False
+ assert "vosk_kws" in reason # the reason names the engine, for the log
+
+
+def test_a_transcript_matching_host_still_prefetches(no_vosk) -> None:
+ """stt_match transcribes locally — for it the prefetch is a real win and
+ removing it would be the regression this change must not cause."""
+ consumed, reason = wake_whisper_is_consumed(_cfg())
+
+ assert consumed is True
+ assert reason
+
+
+def test_heavy_local_whisper_prefetches_whatever_the_engine_is(vosk_installed) -> None:
+ """The flag forces a local Whisper, so the weights get a consumer even on a
+ host whose wake plan resolves to vosk."""
+ consumed, reason = wake_whisper_is_consumed(_cfg(heavy=True))
+
+ assert consumed is True
+ assert "heavy_local_whisper" in reason
+
+
[email protected]("broken", [None, object(), SimpleNamespace()])
+def test_an_unreadable_config_prefetches_rather_than_guessing(broken: Any) -> None:
+ """Failing closed here would silently slow down the hosts that need the
+ prefetch. An unreadable plan reproduces today's unconditional behaviour."""
+ consumed, reason = wake_whisper_is_consumed(broken)
+
+ assert consumed is True
+ assert reason
diff --git a/tests/unit/ui/test_wake_gate_predicate.py b/tests/unit/ui/test_wake_gate_predicate.py
new file mode 100644
index 0000000000..dc5d54f916
--- /dev/null
+++ b/tests/unit/ui/test_wake_gate_predicate.py
@@ -0,0 +1,58 @@
+"""Which wake detectors the heavy backend waits for.
+
+The boot gate holds the server, brain, MCP, workflows and the conductor behind
+the wake model so the load the user is waiting for is not starved. It used to be
+armed only when voice boot built a local Whisper, which left ``vosk_kws`` — the
+engine that loads one Kaldi model per installed language — completely ungated:
+on a cold boot the gate opened before the load began (BUG-214).
+
+The predicate is a capability check, never an engine name (AP-21).
+"""
+
+from __future__ import annotations
+
+from types import SimpleNamespace
+from typing import Any
+
+import pytest
+
+from jarvis.ui.desktop_app import detector_gates_the_backend
+
+
+def _pipeline(detector: Any, *, enabled: bool = True) -> SimpleNamespace:
+ return SimpleNamespace(_wake=detector, _openwakeword_enabled=enabled)
+
+
+def test_a_detector_that_reports_warmth_gates_the_backend() -> None:
+ """vosk_kws shape: it owns model loads the STT probes know nothing about."""
+ assert detector_gates_the_backend(_pipeline(SimpleNamespace(is_warm=False))) is True
+ # Still gates once warm — the caller reads warmth separately.
+ assert detector_gates_the_backend(_pipeline(SimpleNamespace(is_warm=True))) is True
+
+
+def test_a_detector_without_a_warm_signal_does_not_gate() -> None:
+ """openWakeWord shape: nothing to wait for, so waiting would be a guess and
+ the backend would pay a ceiling for no reason."""
+ assert detector_gates_the_backend(_pipeline(SimpleNamespace())) is False
+
+
+def test_a_detector_that_will_not_be_started_does_not_gate() -> None:
+ """A second instance lowers ``_openwakeword_enabled``; it must never tax the
+ primary instance's boot with a wait for a detector nobody starts."""
+ pipeline = _pipeline(SimpleNamespace(is_warm=False), enabled=False)
+
+ assert detector_gates_the_backend(pipeline) is False
+
+
+ "pipeline",
+ [
+ SimpleNamespace(), # no detector attribute at all
+ SimpleNamespace(_wake=None, _openwakeword_enabled=True), # voice off
+ SimpleNamespace(_wake=SimpleNamespace(is_warm=False)), # no enabled flag
+ ],
+)
+def test_a_host_without_a_detector_releases_immediately(pipeline: Any) -> None:
+ """Headless, voice-off and half-built pipelines keep today's behaviour: the
+ backend starts at once rather than waiting out a ceiling."""
+ assert detector_gates_the_backend(pipeline) is False