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): stop the desktop UI hanging forever on "Getting ready to listen"

Ruben Lütkec82a4891d52e
diff --git a/jarvis/ui/desktop_app.py b/jarvis/ui/desktop_app.py
index 3c2427c4a5..3219da46d0 100644
--- a/jarvis/ui/desktop_app.py
+++ b/jarvis/ui/desktop_app.py
@@ -2616,6 +2616,27 @@ class DesktopApp:
logger.debug(
"could not schedule voice-offline alert", exc_info=True
)
+ # UI un-stick (permanent "Getting ready to listen" bug): the frontend's
+ # startup banner + top-left "STARTING…" status clear ONLY when a
+ # VoiceBootStatus(ready=True) is published. A crash in pipeline
+ # construction here would otherwise publish NO status at all (warm-up
+ # never runs), so the banner sticks forever even though the user can
+ # already type. Voice is genuinely offline, so emit ready=True with an
+ # honest "voice_unavailable" detail to release the UI — text works,
+ # voice does not until restart. Guarded so the un-stick never re-crashes
+ # boot. (A slower, pipeline-independent backstop also lives in the
+ # WebServer's voice-ready watchdog for the warm-up-hang case.)
+ try:
+ from jarvis.core.events import VoiceBootStatus as _VBS
+ if bus is not None:
+ loop.create_task(
+ bus.publish(_VBS(ready=True, detail="voice_unavailable")),
+ name="voice-offline-ready-signal",
+ )
+ except Exception: # noqa: BLE001 — the un-stick must never crash boot
+ logger.debug(
+ "could not publish voice-unavailable ready signal", exc_info=True
+ )
def _install_focus_route(self, server: WebServer) -> None:
"""Replaces the placeholder ``/api/window/focus`` with a real call.
diff --git a/jarvis/ui/web/server.py b/jarvis/ui/web/server.py
index 3d24f461fa..2e63ea37df 100644
--- a/jarvis/ui/web/server.py
+++ b/jarvis/ui/web/server.py
@@ -435,6 +435,44 @@ class WebServer:
return app
+ async def _voice_ready_watchdog(self, deadline_s: float = 45.0) -> None:
+ """Guarantee the UI never hangs on "starting up" forever.
+
+ The startup banner + "STARTING…" status flip to listening ONLY when a
+ ``VoiceBootStatus(ready=True)`` arrives (mirrored by /api/voice/status).
+ The pipeline emits it at the end of warm-up — but if construction crashes
+ or an un-timed model download/load wedges warm-up, that event is never
+ published and the banner sticks forever even though the user can already
+ type (permanent "Getting ready to listen"). This backstop fires once,
+ well past a healthy cold boot (voice-usable budget ≤ 20 s, AP-26), and
+ force-releases the UI. A genuine ready flips ``_voice_ready`` first, in
+ which case this is a silent no-op. ``detail="watchdog_timeout"`` marks the
+ signal as a degraded release (voice may be offline until restart), not a
+ real "you can speak now".
+ """
+ try:
+ await asyncio.sleep(deadline_s)
+ except asyncio.CancelledError:
+ return
+ if self._voice_ready:
+ return
+ logger.warning(
+ "Voice-ready watchdog fired after %.0fs — the speech pipeline never "
+ "signalled ready (a construction crash or a wedged warm-up load). "
+ "Force-releasing the UI from 'starting up'; voice may be offline until "
+ "restart.",
+ deadline_s,
+ )
+ # Set the endpoint mirror first so /api/voice/status is correct even if
+ # the bus publish below fails; the WS event then updates live tabs.
+ self._voice_ready = True
+ try:
+ await self.bus.publish(
+ VoiceBootStatus(ready=True, detail="watchdog_timeout")
+ )
+ except Exception as exc: # noqa: BLE001 — mirror already set; never crash
+ logger.debug("watchdog VoiceBootStatus publish failed: %s", exc)
+
def _setup_board(self, app: FastAPI) -> None:
"""Initialize the board store + aggregator + evaluator + BioGenerator.
@@ -1631,6 +1669,19 @@ class WebServer:
_boot_mark("uvicorn_serve")
+ # Voice-ready UI backstop (permanent "starting up" bug): the frontend's
+ # startup banner + top-left "STARTING…" status clear ONLY on a
+ # VoiceBootStatus(ready=True). If the speech pipeline crashes during
+ # construction or an un-timed model load wedges warm-up, that event never
+ # fires and the UI hangs forever. Arm a watchdog that force-releases the UI
+ # after a generous deadline — but only when voice is meant to warm up
+ # (else _voice_ready is already seeded True and there is nothing to wait
+ # for, e.g. JARVIS_VOICE=0 / headless).
+ if not self._voice_ready:
+ self._voice_ready_watchdog_task = asyncio.create_task(
+ self._voice_ready_watchdog(), name="voice-ready-watchdog"
+ )
+
# Phase-6 mission stack — MissionManager with a DB path derived from
# the config's memory data_dir (same folder as data/jarvis.db, its
# own file data/missions.db). Recovery runs in start().
@@ -2509,6 +2560,19 @@ class WebServer:
except Exception as exc: # noqa: BLE001
logger.opt(exception=exc).warning("Board-aggregator shutdown error")
self._board_aggregator_task = None
+ # Voice-ready backstop watchdog: usually already finished (it fires once
+ # and returns), but cancel it if a shutdown lands inside its deadline so
+ # it is never orphaned as a pending task at loop close.
+ _watchdog_task = getattr(self, "_voice_ready_watchdog_task", None)
+ if _watchdog_task is not None:
+ _watchdog_task.cancel()
+ try:
+ await asyncio.wait_for(_watchdog_task, timeout=2.0)
+ except (TimeoutError, asyncio.CancelledError):
+ pass
+ except Exception as exc: # noqa: BLE001
+ logger.opt(exception=exc).debug("voice-ready watchdog shutdown: {}", exc)
+ self._voice_ready_watchdog_task = None
if self._bio_scheduler is not None:
try:
await self._bio_scheduler.stop()
diff --git a/tests/unit/ui/web/test_voice_status_route.py b/tests/unit/ui/web/test_voice_status_route.py
index 73f73050f1..bfafb17eb3 100644
--- a/tests/unit/ui/web/test_voice_status_route.py
+++ b/tests/unit/ui/web/test_voice_status_route.py
@@ -70,3 +70,51 @@ async def test_voice_status_tracks_latest_state() -> None:
assert srv._voice_ready is True
await bus.publish(VoiceBootStatus(ready=False))
assert srv._voice_ready is False
+
+
+async def test_voice_ready_watchdog_force_releases_stuck_ui(monkeypatch) -> None:
+ """Permanent "starting up" backstop: if warm-up never signals ready (a crash
+ during pipeline construction or a wedged model load), the watchdog fires
+ after its deadline and force-releases the UI so the banner cannot hang
+ forever. The forced signal carries detail="watchdog_timeout" (a degraded
+ release, not a genuine "you can speak now")."""
+ monkeypatch.delenv("JARVIS_VOICE", raising=False)
+ bus = EventBus()
+ srv = WebServer(JarvisConfig(), bus=bus)
+ assert srv._voice_ready is False
+
+ seen: list[VoiceBootStatus] = []
+
+ async def _collect(evt: VoiceBootStatus) -> None:
+ seen.append(evt)
+
+ bus.subscribe(VoiceBootStatus, _collect)
+
+ await srv._voice_ready_watchdog(deadline_s=0.01)
+
+ assert srv._voice_ready is True
+ assert any(e.ready and e.detail == "watchdog_timeout" for e in seen)
+
+
+async def test_voice_ready_watchdog_is_noop_when_already_ready(monkeypatch) -> None:
+ """A healthy boot flips _voice_ready before the deadline; the watchdog then
+ does nothing — it must NOT emit a spurious watchdog_timeout event."""
+ monkeypatch.delenv("JARVIS_VOICE", raising=False)
+ bus = EventBus()
+ srv = WebServer(JarvisConfig(), bus=bus)
+ await bus.publish(VoiceBootStatus(ready=True, detail="listening"))
+ assert srv._voice_ready is True
+
+ seen: list[VoiceBootStatus] = []
+
+ async def _collect(evt: VoiceBootStatus) -> None:
+ seen.append(evt)
+
+ bus.subscribe(VoiceBootStatus, _collect)
+
+ await srv._voice_ready_watchdog(deadline_s=0.01)
+
+ assert srv._voice_ready is True
+ assert not any(e.detail == "watchdog_timeout" for e in seen)