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.

feat(wake): provision the Vosk model in setup prefetch

Ruben Lütke7a7364a20656
diff --git a/jarvis/setup/prefetch.py b/jarvis/setup/prefetch.py
index 79101e718b..e7773ff49f 100644
--- a/jarvis/setup/prefetch.py
+++ b/jarvis/setup/prefetch.py
@@ -40,6 +40,20 @@ def _load_config() -> Any:
return load_config()
+def _ensure_vosk(language: str | None, **kw: Any) -> Any:
+ """Seam for tests — heavy import stays out of module import."""
+ from jarvis.speech.wake_model_fetch import ensure_vosk_model
+
+ return ensure_vosk_model(language, **kw)
+
+
+def _vosk_language() -> str | None:
+ try:
+ return _load_config().stt.language
+ except Exception: # noqa: BLE001 — config read must never brick prefetch
+ return None
+
+
def _whisper_models_needed() -> list[str]:
"""The faster-whisper model names the CURRENT config would load at runtime.
@@ -79,12 +93,23 @@ def prefetch_all(echo: Callable[[str], None] = print) -> int:
"on first use"
)
+ # Any-word wake model (vosk_kws): fetch the per-language model once so a
+ # custom wake word resolves to the reliable engine instead of stt_match.
+ lang = _vosk_language()
+ try:
+ out = _ensure_vosk(lang, echo=echo)
+ if out is None:
+ failed = True
+ except Exception as exc: # noqa: BLE001 — honest note, never fatal
+ failed = True
+ echo(f"wake model: could not provision ({exc}); it will retry at first run")
+
if not _faster_whisper_available():
echo(
"local Whisper models: skipped (faster-whisper not installed - "
"cloud STT is the default)"
)
- return 0
+ return 1 if failed else 0
for name in _whisper_models_needed():
echo(f"downloading speech model '{name}' (one-time, cached for every later start)")
diff --git a/tests/unit/setup/test_prefetch.py b/tests/unit/setup/test_prefetch.py
index 6780791cf0..ff5cd990ba 100644
--- a/tests/unit/setup/test_prefetch.py
+++ b/tests/unit/setup/test_prefetch.py
@@ -6,6 +6,8 @@ def test_reports_bundled_wakeword(monkeypatch) -> None:
lines: list[str] = []
monkeypatch.setattr(prefetch, "_wakeword_bundle_present", lambda: True)
monkeypatch.setattr(prefetch, "_faster_whisper_available", lambda: False)
+ # Hermetic: the vosk wake-model seam must not touch the real config or network.
+ monkeypatch.setattr(prefetch, "_ensure_vosk", lambda *_a, **_kw: object(), raising=False)
rc = prefetch.prefetch_all(echo=lines.append)
assert rc == 0
assert any("wake-word models" in line for line in lines)
@@ -18,6 +20,7 @@ def test_downloads_wake_model_when_faster_whisper_present(monkeypatch) -> None:
monkeypatch.setattr(prefetch, "_faster_whisper_available", lambda: True)
monkeypatch.setattr(prefetch, "_download_whisper_model", downloaded.append)
monkeypatch.setattr(prefetch, "_whisper_models_needed", lambda: ["base"])
+ monkeypatch.setattr(prefetch, "_ensure_vosk", lambda *_a, **_kw: object(), raising=False)
rc = prefetch.prefetch_all(echo=lambda _line: None)
assert rc == 0
assert downloaded == ["base"]
@@ -31,6 +34,7 @@ def test_download_failure_is_nonfatal(monkeypatch) -> None:
monkeypatch.setattr(prefetch, "_faster_whisper_available", lambda: True)
monkeypatch.setattr(prefetch, "_download_whisper_model", _boom)
monkeypatch.setattr(prefetch, "_whisper_models_needed", lambda: ["base"])
+ monkeypatch.setattr(prefetch, "_ensure_vosk", lambda *_a, **_kw: object(), raising=False)
lines: list[str] = []
rc = prefetch.prefetch_all(echo=lines.append)
assert rc == 1
diff --git a/tests/unit/setup/test_prefetch_vosk.py b/tests/unit/setup/test_prefetch_vosk.py
new file mode 100644
index 0000000000..dca2dfb7e1
--- /dev/null
+++ b/tests/unit/setup/test_prefetch_vosk.py
@@ -0,0 +1,56 @@
+"""prefetch_all: provisions the per-language Vosk (any-word wake) model too."""
+from jarvis.setup import prefetch
+
+
+def _cfg(language: str | None):
+ return type("C", (), {"stt": type("S", (), {"language": language})()})()
+
+
+def test_prefetch_calls_vosk_ensure(monkeypatch):
+ seen = {}
+
+ def fake_ensure(language, **kw):
+ seen["lang"] = language
+ return object()
+
+ monkeypatch.setattr(prefetch, "_ensure_vosk", fake_ensure, raising=False)
+ monkeypatch.setattr(prefetch, "_faster_whisper_available", lambda: False)
+ monkeypatch.setattr(prefetch, "_load_config", lambda: _cfg("de"))
+ lines = []
+ rc = prefetch.prefetch_all(echo=lines.append)
+ assert seen.get("lang") == "de"
+ assert rc == 0
+
+
+def test_vosk_none_result_marks_prefetch_failed(monkeypatch):
+ """A non-fatal fetch miss (offline mirror, etc.) must flip the honest rc."""
+ monkeypatch.setattr(prefetch, "_ensure_vosk", lambda *_a, **_kw: None, raising=False)
+ monkeypatch.setattr(prefetch, "_faster_whisper_available", lambda: False)
+ monkeypatch.setattr(prefetch, "_load_config", lambda: _cfg("en"))
+ rc = prefetch.prefetch_all(echo=lambda _line: None)
+ assert rc == 1
+
+
+def test_vosk_exception_is_nonfatal(monkeypatch):
+ """An unexpected raise from the fetch seam must never abort prefetch."""
+
+ def _boom(*_a, **_kw):
+ raise OSError("mirror down")
+
+ monkeypatch.setattr(prefetch, "_ensure_vosk", _boom, raising=False)
+ monkeypatch.setattr(prefetch, "_faster_whisper_available", lambda: False)
+ monkeypatch.setattr(prefetch, "_load_config", lambda: _cfg("en"))
+ lines = []
+ rc = prefetch.prefetch_all(echo=lines.append)
+ assert rc == 1
+ assert any("wake model" in line for line in lines)
+
+
+def test_vosk_language_guards_config_read_failure(monkeypatch):
+ """A broken config read must never brick prefetch — resolves to None."""
+
+ def _raise_cfg():
+ raise RuntimeError("config missing")
+
+ monkeypatch.setattr(prefetch, "_load_config", _raise_cfg)
+ assert prefetch._vosk_language() is None