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): off-boot lazy Vosk provision + in-app download route

Ruben Lütke4def35c83d48
diff --git a/jarvis/ui/desktop_app.py b/jarvis/ui/desktop_app.py
index 904809a831..f79f5c06ea 100644
--- a/jarvis/ui/desktop_app.py
+++ b/jarvis/ui/desktop_app.py
@@ -1745,6 +1745,28 @@ class DesktopApp:
loop.create_task(_bootstrap_workflows(), name="workflow-bootstrap")
loop.create_task(_bootstrap_conductor(), name="conductor-bootstrap")
+ # One-shot: provision the Vosk wake model if missing, off the boot
+ # path (AP-26). Runs behind the live wake listener (this whole
+ # function already waited on ``self._wake_model_loaded`` above), so
+ # a fresh install that skipped/failed the installer prefetch still
+ # self-heals without editing jarvis.toml. Never fatal — the wake
+ # word degrades honestly until the model lands.
+ async def _provision_wake_model() -> None:
+ try:
+ from jarvis.core.config import load_config
+ from jarvis.speech import wake_model_fetch as _wmf
+
+ lang = load_config().stt.language
+ if not _wmf.vosk_model_present(lang):
+ await asyncio.to_thread(_wmf.ensure_vosk_model, lang)
+ except Exception: # noqa: BLE001 — a background probe never crashes boot
+ from loguru import logger as _wmf_log
+ _wmf_log.opt(exception=True).debug(
+ "Off-boot wake-model provision skipped."
+ )
+
+ loop.create_task(_provision_wake_model(), name="wake-model-provision")
+
loop.create_task(_heavy_backend_bg(), name="heavy-backend")
loop.call_soon(self._start_virtual_cursor)
loop.run_forever()
diff --git a/jarvis/ui/web/settings_routes.py b/jarvis/ui/web/settings_routes.py
index 0f86d34929..8980276654 100644
--- a/jarvis/ui/web/settings_routes.py
+++ b/jarvis/ui/web/settings_routes.py
@@ -667,6 +667,32 @@ async def set_wake_activation(body: WakeActivationBody, request: Request) -> dic
return {"ok": True, "enabled": bool(body.enabled), "restart_required": True}
[email protected]("/wake-word/download-model")
+async def download_wake_model(request: Request) -> dict[str, object]:
+ """Provision (or repair) the per-language Vosk wake model in-app.
+
+ Recoverable-in-app contract (CLAUDE.md §3): a user whose Vosk model is
+ absent/dead gets a working reliable wake engine without editing jarvis.toml.
+ Never 500s on a fetch failure — returns a clear message and the runtime lazy
+ net (``_heavy_backend_bg``'s one-shot provision) remains the backstop.
+ """
+ from jarvis.speech import wake_model_fetch as wmf
+
+ cfg = _config(request)
+ language = getattr(getattr(cfg, "stt", None), "language", None)
+ out = await asyncio.to_thread(wmf.ensure_vosk_model, language)
+ present = wmf.vosk_model_present(language)
+ return {
+ "ok": out is not None,
+ "present": present,
+ "message": (
+ "Wake model ready." if present
+ else "Could not download the wake model right now; it will retry "
+ "automatically. The wake word uses the fallback path until then."
+ ),
+ }
+
+
# ---------------------------------------------------------------------------
# Push-to-talk hotkey (editable). GET current + safe suggestions; PUT to change.
# Persisted to jarvis.toml [trigger].hotkey; applies on the next voice bootstrap
diff --git a/tests/unit/web/test_wake_download_route.py b/tests/unit/web/test_wake_download_route.py
new file mode 100644
index 0000000000..ee65c85f69
--- /dev/null
+++ b/tests/unit/web/test_wake_download_route.py
@@ -0,0 +1,42 @@
+"""POST /api/settings/wake-word/download-model triggers a non-fatal fetch."""
+import pytest
+from fastapi import FastAPI
+from fastapi.testclient import TestClient
+
+from jarvis.ui.web.settings_routes import router as settings_router
+
+
+def client(monkeypatch):
+ import jarvis.speech.wake_model_fetch as wmf
+ monkeypatch.setattr(wmf, "ensure_vosk_model", lambda *a, **k: object())
+ monkeypatch.setattr(wmf, "vosk_model_present", lambda *a, **k: True)
+ app = FastAPI()
+ app.include_router(settings_router)
+ return TestClient(app)
+
+
+def test_download_model_ok(client):
+ r = client.post("/api/settings/wake-word/download-model")
+ assert r.status_code == 200
+ body = r.json()
+ assert body["ok"] is True
+ assert body["present"] is True
+
+
+def test_download_model_failure_is_non_fatal(monkeypatch):
+ """A fetch failure must never 500 -- it reports ok=False with a clear message."""
+ import jarvis.speech.wake_model_fetch as wmf
+
+ monkeypatch.setattr(wmf, "ensure_vosk_model", lambda *a, **k: None)
+ monkeypatch.setattr(wmf, "vosk_model_present", lambda *a, **k: False)
+ app = FastAPI()
+ app.include_router(settings_router)
+ client = TestClient(app)
+
+ r = client.post("/api/settings/wake-word/download-model")
+ assert r.status_code == 200
+ body = r.json()
+ assert body["ok"] is False
+ assert body["present"] is False
+ assert body["message"]