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: activate pipeline for STT and TTS selections

Ruben Lütke1a3894d0e9cb
diff --git a/jarvis/ui/web/provider_routes.py b/jarvis/ui/web/provider_routes.py
index 21d94ecea2..9afefb5df9 100644
--- a/jarvis/ui/web/provider_routes.py
+++ b/jarvis/ui/web/provider_routes.py
@@ -852,6 +852,47 @@ def _resolve_cfg(request: Request):
return None
+def _select_pipeline_voice_mode(
+ request: Request, *, persist: bool
+) -> tuple[bool, bool]:
+ """Make a successful STT/TTS selection the active voice engine.
+
+ Provider cards are an engine choice, not only dormant configuration:
+ realtime cards already select ``realtime``, so STT and TTS cards must
+ symmetrically select the classic ``pipeline``. Without this coupling the
+ UI can truthfully show a local model as active while the next call still
+ opens a stale realtime provider and never reaches that model.
+
+ Returns ``(voice_mode_persisted, session_restarted)``. A persistence
+ failure is reported in the route response but does not discard the valid
+ live provider switch; this mirrors the realtime-provider route.
+ """
+ voice_mode_persisted = False
+ if persist:
+ try:
+ from jarvis.core.config_writer import set_voice_mode
+
+ set_voice_mode("pipeline")
+ voice_mode_persisted = True
+ except Exception as exc: # noqa: BLE001 — live selection remains valid
+ log.warning(
+ "voice-mode persist failed after pipeline provider switch: %s",
+ exc,
+ )
+
+ cfg = _resolve_cfg(request)
+ if cfg is not None and getattr(cfg, "voice", None) is not None:
+ try:
+ cfg.voice.mode = "pipeline" # type: ignore[attr-defined]
+ except Exception as exc: # noqa: BLE001 — frozen/detached cfg is not an error
+ log.debug("In-memory voice.mode update skipped: %s", exc)
+
+ from jarvis.ui.web.voice_runtime import apply_voice_mode
+
+ session_restarted = apply_voice_mode(request, "pipeline")
+ return voice_mode_persisted, session_restarted
+
+
def _codex_binary_path(request: Request | None = None) -> str | None:
cfg = _resolve_cfg(request) if request is not None else None
if cfg is None:
@@ -3210,15 +3251,22 @@ async def tts_switch(body: SwitchBody, request: Request) -> dict[str, Any]:
)
restart_required = True
+ voice_mode_persisted, session_restarted = _select_pipeline_voice_mode(
+ request, persist=body.persist
+ )
+
await _emit(request, SecretConfigured(key="tts.provider", action="set"))
+ await _emit(request, SecretConfigured(key="voice.mode", action="set"))
_invalidate_section_health_state(request)
return {
"ok": True,
"active": body.provider,
- "persisted": body.persist,
+ "persisted": body.persist and voice_mode_persisted,
+ "voice_mode_persisted": voice_mode_persisted,
"live_switched": live_switched,
"restart_required": restart_required,
+ "session_restarted": session_restarted,
}
@@ -3595,15 +3643,23 @@ async def stt_switch(body: SwitchBody, request: Request) -> dict[str, Any]:
status_code=500, detail=f"STT provider save failed: {exc}"
) from exc
+ voice_mode_persisted, session_restarted = _select_pipeline_voice_mode(
+ request, persist=body.persist
+ )
+ persisted = persisted and voice_mode_persisted
+
await _emit(request, SecretConfigured(key="stt.provider", action="set"))
+ await _emit(request, SecretConfigured(key="voice.mode", action="set"))
_invalidate_section_health_state(request)
return {
"ok": True,
"active": body.provider,
"persisted": persisted,
+ "voice_mode_persisted": voice_mode_persisted,
"live_switched": live_switched,
"restart_required": False,
+ "session_restarted": session_restarted,
}
diff --git a/tests/unit/speech/test_stt_provider_live_switch.py b/tests/unit/speech/test_stt_provider_live_switch.py
index 3fb4f03389..7adf2bf118 100644
--- a/tests/unit/speech/test_stt_provider_live_switch.py
+++ b/tests/unit/speech/test_stt_provider_live_switch.py
@@ -102,12 +102,18 @@ class _LivePipeline:
def __init__(self, cfg: JarvisConfig) -> None:
self.cfg = cfg
self.calls: list[tuple[str, str | None]] = []
+ self.mode_calls: list[str] = []
def set_stt_provider(self, provider: str, *, model: str | None = None) -> bool:
self.calls.append((provider, model))
self.cfg.stt.provider = provider
return True
+ def apply_voice_mode(self, mode: str) -> bool:
+ self.mode_calls.append(mode)
+ self.cfg.voice.mode = mode
+ return True
+
def test_switch_route_applies_to_running_pipeline_without_restart(
web_server: WebServer, monkeypatch: pytest.MonkeyPatch
@@ -115,9 +121,12 @@ def test_switch_route_applies_to_running_pipeline_without_restart(
pipeline = _LivePipeline(web_server.cfg)
web_server.app.state.speech_pipeline = pipeline
writes: list[str] = []
+ mode_writes: list[str] = []
+ web_server.cfg.voice.mode = "realtime"
monkeypatch.setattr(provider_routes, "_is_credential_present", lambda _spec: True)
monkeypatch.setattr("jarvis.brain.app_control.local_readiness_error", lambda _spec: None)
monkeypatch.setattr("jarvis.core.config_writer.set_stt_provider", writes.append)
+ monkeypatch.setattr("jarvis.core.config_writer.set_voice_mode", mode_writes.append)
with TestClient(web_server.app) as client:
response = client.post(
@@ -130,12 +139,17 @@ def test_switch_route_applies_to_running_pipeline_without_restart(
"ok": True,
"active": "openrouter-stt",
"persisted": True,
+ "voice_mode_persisted": True,
"live_switched": True,
"restart_required": False,
+ "session_restarted": True,
}
assert pipeline.calls == [("openrouter-stt", None)]
+ assert pipeline.mode_calls == ["pipeline"]
assert web_server.cfg.stt.provider == "openrouter-stt"
+ assert web_server.cfg.voice.mode == "pipeline"
assert writes == ["openrouter-stt"]
+ assert mode_writes == ["pipeline"]
def test_switch_route_never_requests_restart_when_voice_is_not_running(
@@ -153,4 +167,7 @@ def test_switch_route_never_requests_restart_when_voice_is_not_running(
assert response.status_code == 200, response.text
assert response.json()["live_switched"] is False
assert response.json()["restart_required"] is False
+ assert response.json()["voice_mode_persisted"] is False
+ assert response.json()["session_restarted"] is False
assert web_server.cfg.stt.provider == "openrouter-stt"
+ assert web_server.cfg.voice.mode == "pipeline"
diff --git a/tests/unit/web/test_pipeline_provider_voice_mode.py b/tests/unit/web/test_pipeline_provider_voice_mode.py
new file mode 100644
index 0000000000..e59f5ad7aa
--- /dev/null
+++ b/tests/unit/web/test_pipeline_provider_voice_mode.py
@@ -0,0 +1,69 @@
+"""Pipeline provider cards select the engine that actually uses them."""
+
+from __future__ import annotations
+
+from types import SimpleNamespace
+
+import pytest
+from fastapi.testclient import TestClient
+
+from jarvis.core.bus import EventBus
+from jarvis.core.config import JarvisConfig
+from jarvis.ui.web import provider_routes
+from jarvis.ui.web.server import WebServer
+
+
+class _LivePipeline:
+ def __init__(self, cfg: JarvisConfig) -> None:
+ self.cfg = cfg
+ self.tts: object | None = None
+ self.mode_calls: list[str] = []
+
+ def set_tts(self, provider: object) -> None:
+ self.tts = provider
+
+ def apply_voice_mode(self, mode: str) -> bool:
+ self.mode_calls.append(mode)
+ self.cfg.voice.mode = mode
+ return True
+
+
+def test_local_tts_selection_activates_and_persists_pipeline_mode(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ cfg = JarvisConfig()
+ cfg.voice.mode = "realtime"
+ server = WebServer(cfg, bus=EventBus())
+ pipeline = _LivePipeline(cfg)
+ server.app.state.speech_pipeline = pipeline
+ provider_writes: list[str] = []
+ mode_writes: list[str] = []
+ built = SimpleNamespace(name="piper-local")
+
+ monkeypatch.setattr(provider_routes, "_is_credential_present", lambda _spec: True)
+ monkeypatch.setattr("jarvis.brain.app_control.local_readiness_error", lambda _spec: None)
+ monkeypatch.setattr("jarvis.core.config_writer.set_tts_provider", provider_writes.append)
+ monkeypatch.setattr("jarvis.core.config_writer.set_voice_mode", mode_writes.append)
+ monkeypatch.setattr("jarvis.plugins.tts.build_tts_from_config", lambda _cfg: built)
+
+ with TestClient(server.app) as client:
+ response = client.post(
+ "/api/tts/switch",
+ json={"provider": "piper-local", "persist": True},
+ )
+
+ assert response.status_code == 200, response.text
+ assert response.json() == {
+ "ok": True,
+ "active": "piper-local",
+ "persisted": True,
+ "voice_mode_persisted": True,
+ "live_switched": True,
+ "restart_required": False,
+ "session_restarted": True,
+ }
+ assert provider_writes == ["piper-local"]
+ assert mode_writes == ["pipeline"]
+ assert pipeline.tts is built
+ assert pipeline.mode_calls == ["pipeline"]
+ assert cfg.voice.mode == "pipeline"