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): keep engine mode user-controlled

Ruben Lütke3fca6e2a5960
diff --git a/jarvis/ui/web/frontend/src/hooks/useVoiceMode.ts b/jarvis/ui/web/frontend/src/hooks/useVoiceMode.ts
index 61b14bb845..d0c70c11ec 100644
--- a/jarvis/ui/web/frontend/src/hooks/useVoiceMode.ts
+++ b/jarvis/ui/web/frontend/src/hooks/useVoiceMode.ts
@@ -86,12 +86,9 @@ export function useVoiceMode() {
onSettled: () => qc.invalidateQueries({ queryKey: ["voice-mode"] }),
});
- // Activating a realtime provider CARD (ApiKeysView's ProviderCategory, the
- // "Set active" action on a Realtime tier card) flips `[voice].mode`
- // server-side too (provider_routes.py::realtime_switch, Feature A4) — that
- // write bypasses this hook's own mutation, so the "Active" badge would
- // otherwise go stale until an unrelated refetch. Listen for the event the
- // card activation already dispatches and refresh here.
+ // A realtime provider card changes the provider, never `[voice].mode`.
+ // Refresh because this response also carries the selected provider/model
+ // shown in the runtime status; the engine mode itself remains user-controlled.
useEffect(() => {
function onRealtimeSwitched() {
qc.invalidateQueries({ queryKey: ["voice-mode"] });
diff --git a/jarvis/ui/web/provider_routes.py b/jarvis/ui/web/provider_routes.py
index ba7937ba28..b09a022c4f 100644
--- a/jarvis/ui/web/provider_routes.py
+++ b/jarvis/ui/web/provider_routes.py
@@ -865,47 +865,6 @@ 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:
@@ -3284,22 +3243,16 @@ 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 and voice_mode_persisted,
- "voice_mode_persisted": voice_mode_persisted,
+ "persisted": body.persist,
"live_switched": live_switched,
"restart_required": restart_required,
- "session_restarted": session_restarted,
+ "session_restarted": False,
}
@@ -3676,23 +3629,16 @@ 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,
+ "session_restarted": False,
}
@@ -3701,14 +3647,13 @@ async def realtime_switch(body: SwitchBody, request: Request) -> dict[str, Any]:
"""Switch the active realtime provider.
The desktop and browser runtimes resolve ``voice.mode`` plus the selected
- provider whenever a voice session opens. An active desktop call is closed
- and reopened against the new selection; no application restart is required.
+ provider whenever a voice session opens. An active realtime call is closed
+ and reopened against the new provider; no application restart is required.
Realtime is cross-family (AP-22), so validation is registry/tier based.
- Activating a realtime provider also makes Realtime the ACTIVE voice mode
- (``[voice].mode``) — the "Active" badge reads ``[voice].mode``, not
- ``[brain.realtime].provider``, so without this the badge could never
- follow an activation (Feature A4).
+ Provider selection and voice-engine selection are intentionally independent.
+ This route never changes ``[voice].mode``; only the explicit voice-mode
+ settings action may switch between Pipeline and Realtime.
"""
spec = get_spec(body.provider)
if spec is None:
@@ -3774,7 +3719,6 @@ async def realtime_switch(body: SwitchBody, request: Request) -> dict[str, Any]:
except Exception as exc: # noqa: BLE001 - provider gate returns a safe 409
raise HTTPException(status_code=409, detail=str(exc)) from exc
- voice_mode_write_ok = True
if body.persist:
try:
from jarvis.core.config_writer import set_realtime_provider
@@ -3786,13 +3730,6 @@ async def realtime_switch(body: SwitchBody, request: Request) -> dict[str, Any]:
raise HTTPException(
status_code=500, detail=f"TOML write failed: {exc}"
) from exc
- try:
- from jarvis.core.config_writer import set_voice_mode
-
- set_voice_mode("realtime")
- except Exception as exc: # noqa: BLE001 — best-effort, mirrors set_realtime_provider above
- voice_mode_write_ok = False
- log.warning("voice-mode persist failed after realtime switch: %s", exc)
cfg = _resolve_cfg(request)
if cfg is not None and getattr(cfg, "brain", None) is not None:
@@ -3806,14 +3743,7 @@ async def realtime_switch(body: SwitchBody, request: Request) -> dict[str, Any]:
realtime_cfg.provider = body.provider
except Exception as exc: # noqa: BLE001 — frozen/detached cfg is not an error
log.debug("In-memory realtime.provider update skipped: %s", exc)
- if cfg is not None and getattr(cfg, "voice", None) is not None:
- try:
- cfg.voice.mode = "realtime" # 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)
-
await _emit(request, SecretConfigured(key="brain.realtime.provider", action="set"))
- await _emit(request, SecretConfigured(key="voice.mode", action="set"))
from jarvis.ui.web.voice_runtime import reconnect_realtime
@@ -3825,13 +3755,7 @@ async def realtime_switch(body: SwitchBody, request: Request) -> dict[str, Any]:
return {
"ok": True,
"active": body.provider,
- # True only when persist was requested AND both writes (provider +
- # voice mode) actually landed — previously this reported
- # body.persist unconditionally even when the voice-mode write above
- # failed and was only logged, so the UI showed "persisted" for a
- # switch that silently left [voice].mode stale on disk.
- "persisted": body.persist and voice_mode_write_ok,
- "voice_mode_persisted": voice_mode_write_ok,
+ "persisted": body.persist,
"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 7adf2bf118..05685eabeb 100644
--- a/tests/unit/speech/test_stt_provider_live_switch.py
+++ b/tests/unit/speech/test_stt_provider_live_switch.py
@@ -139,22 +139,22 @@ 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,
+ "session_restarted": False,
}
assert pipeline.calls == [("openrouter-stt", None)]
- assert pipeline.mode_calls == ["pipeline"]
+ assert pipeline.mode_calls == []
assert web_server.cfg.stt.provider == "openrouter-stt"
- assert web_server.cfg.voice.mode == "pipeline"
+ assert web_server.cfg.voice.mode == "realtime"
assert writes == ["openrouter-stt"]
- assert mode_writes == ["pipeline"]
+ assert mode_writes == []
def test_switch_route_never_requests_restart_when_voice_is_not_running(
web_server: WebServer, monkeypatch: pytest.MonkeyPatch
) -> None:
+ initial_mode = web_server.cfg.voice.mode
monkeypatch.setattr(provider_routes, "_is_credential_present", lambda _spec: True)
monkeypatch.setattr("jarvis.brain.app_control.local_readiness_error", lambda _spec: None)
@@ -167,7 +167,6 @@ 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"
+ assert web_server.cfg.voice.mode == initial_mode
diff --git a/tests/unit/web/test_pipeline_provider_voice_mode.py b/tests/unit/web/test_pipeline_provider_voice_mode.py
index e59f5ad7aa..ec9d9d6701 100644
--- a/tests/unit/web/test_pipeline_provider_voice_mode.py
+++ b/tests/unit/web/test_pipeline_provider_voice_mode.py
@@ -1,4 +1,4 @@
-"""Pipeline provider cards select the engine that actually uses them."""
+"""Pipeline provider cards never change the user's voice-engine selection."""
from __future__ import annotations
@@ -28,7 +28,7 @@ class _LivePipeline:
return True
-def test_local_tts_selection_activates_and_persists_pipeline_mode(
+def test_local_tts_selection_preserves_realtime_mode(
monkeypatch: pytest.MonkeyPatch,
) -> None:
cfg = JarvisConfig()
@@ -57,13 +57,12 @@ def test_local_tts_selection_activates_and_persists_pipeline_mode(
"ok": True,
"active": "piper-local",
"persisted": True,
- "voice_mode_persisted": True,
"live_switched": True,
"restart_required": False,
- "session_restarted": True,
+ "session_restarted": False,
}
assert provider_writes == ["piper-local"]
- assert mode_writes == ["pipeline"]
+ assert mode_writes == []
assert pipeline.tts is built
- assert pipeline.mode_calls == ["pipeline"]
- assert cfg.voice.mode == "pipeline"
+ assert pipeline.mode_calls == []
+ assert cfg.voice.mode == "realtime"
diff --git a/tests/unit/web/test_realtime_provider_category.py b/tests/unit/web/test_realtime_provider_category.py
index 66b76a1d86..b6364f9975 100644
--- a/tests/unit/web/test_realtime_provider_category.py
+++ b/tests/unit/web/test_realtime_provider_category.py
@@ -102,10 +102,6 @@ def test_realtime_switch_persists_with_key(monkeypatch):
monkeypatch.setattr(
config_writer, "set_realtime_provider", lambda name, **kw: writes.append(name)
)
- # Feature A4 also flips [voice].mode inside this route; mock it too so the
- # test never touches the real jarvis.toml (isolation defect otherwise).
- monkeypatch.setattr(config_writer, "set_voice_mode", lambda mode, **kw: None)
-
app = _app()
client = TestClient(app)
resp = client.post(
@@ -122,11 +118,8 @@ def test_realtime_switch_persists_with_key(monkeypatch):
assert app.state.config.brain.realtime.provider == "openai-realtime"
-def test_realtime_switch_sets_voice_mode(monkeypatch):
- """Feature A4: activating a realtime provider must flip [voice].mode to
- "realtime" too — the "Active" badge reads [voice].mode, not
- [brain.realtime].provider, so persisting only the provider can never move
- it (the original bug this feature fixes)."""
+def test_realtime_switch_preserves_pipeline_mode(monkeypatch):
+ """Provider selection configures Realtime without activating the engine."""
monkeypatch.setattr(cfg_mod, "get_secret", _only_openai_key)
monkeypatch.setattr(config_writer, "set_realtime_provider", lambda name, **kw: None)
voice_mode_writes: list[str] = []
@@ -135,19 +128,19 @@ def test_realtime_switch_sets_voice_mode(monkeypatch):
)
app = _app()
+ app.state.config.voice.mode = "pipeline"
client = TestClient(app)
resp = client.post(
"/api/realtime/switch", json={"provider": "openai-realtime", "persist": True}
)
assert resp.status_code == 200
- assert voice_mode_writes == ["realtime"]
- assert app.state.config.voice.mode == "realtime"
+ assert voice_mode_writes == []
+ assert app.state.config.voice.mode == "pipeline"
def test_realtime_switch_reconnects_the_active_voice_session(monkeypatch):
monkeypatch.setattr(cfg_mod, "get_secret", _only_openai_key)
monkeypatch.setattr(config_writer, "set_realtime_provider", lambda _name: None)
- monkeypatch.setattr(config_writer, "set_voice_mode", lambda _mode: None)
reasons: list[str] = []
class LivePipeline:
@@ -156,6 +149,7 @@ def test_realtime_switch_reconnects_the_active_voice_session(monkeypatch):
return True
app = _app()
+ app.state.config.voice.mode = "realtime"
app.state.speech_pipeline = LivePipeline()
client = TestClient(app)
@@ -169,30 +163,6 @@ def test_realtime_switch_reconnects_the_active_voice_session(monkeypatch):
assert reasons == ["realtime_provider:openai-realtime"]
-def test_realtime_switch_reports_voice_mode_not_persisted_on_write_failure(monkeypatch):
- """Bug: the [voice].mode write failure was only logged, but the response
- still reported persisted=True unconditionally — the UI showed "saved"
- for a switch that silently left [voice].mode stale on disk."""
- monkeypatch.setattr(cfg_mod, "get_secret", _only_openai_key)
- monkeypatch.setattr(config_writer, "set_realtime_provider", lambda name, **kw: None)
-
- def _boom(mode, **kw):
- raise RuntimeError("disk full (simulated)")
-
- monkeypatch.setattr(config_writer, "set_voice_mode", _boom)
-
- app = _app()
- client = TestClient(app)
- resp = client.post(
- "/api/realtime/switch", json={"provider": "openai-realtime", "persist": True}
- )
- assert resp.status_code == 200
- body = resp.json()
- assert body["ok"] is True
- assert body["persisted"] is False
- assert body["voice_mode_persisted"] is False
-
-
def test_realtime_switch_without_key_is_409(monkeypatch):
monkeypatch.setattr(cfg_mod, "get_secret", lambda *a, **kw: None)
client = TestClient(_app())