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(dictation): persist translation toggle before live apply

rubenluetke10-beepa003c36023dd
diff --git a/jarvis/ui/web/dictation_routes.py b/jarvis/ui/web/dictation_routes.py
index 6e1b000789..c710dc3aa4 100644
--- a/jarvis/ui/web/dictation_routes.py
+++ b/jarvis/ui/web/dictation_routes.py
@@ -1101,14 +1101,6 @@ async def put_settings(body: SettingsBody, request: Request) -> dict[str, Any]:
except Exception as exc: # noqa: BLE001 — pydantic ValidationError and friends
raise HTTPException(status_code=400, detail=f"Invalid setting: {exc}") from exc
- # In-memory first so a running pipeline sees the change even if the write
- # fails (a read-only config file must not silently drop the setting).
- for key in updates:
- try:
- setattr(dictation, key, getattr(validated, key))
- except Exception as exc: # noqa: BLE001 — frozen model is not an error
- log.debug("in-memory dictation.%s update skipped: %s", key, exc)
-
persisted = False
if body.persist:
from jarvis.core import config_writer
@@ -1122,6 +1114,23 @@ async def put_settings(body: SettingsBody, request: Request) -> dict[str, Any]:
persisted = True
except Exception as exc: # noqa: BLE001
log.warning("dictation settings persist failed: %s", exc)
+ # A live-only change looks successful until the next restart, when
+ # the old value returns from disk. That is worse than refusing the
+ # save: the settings screen would explicitly promise durability it
+ # did not achieve. Apply nothing live and make the failure visible
+ # to every client (desktop, CLI, or another REST consumer).
+ raise HTTPException(
+ status_code=500,
+ detail="Dictation settings could not be saved. No live setting was changed.",
+ ) from exc
+
+ # Apply only after the durable write succeeds. ``persist=false`` remains a
+ # deliberate live-only API operation; the desktop always sends true.
+ for key in updates:
+ try:
+ setattr(dictation, key, getattr(validated, key))
+ except Exception as exc: # noqa: BLE001 — frozen model is not an error
+ log.debug("in-memory dictation.%s update skipped: %s", key, exc)
# The polish pass caches what it learned about this host: the resolved
# provider chain, every credential it read, the local endpoints that did not
diff --git a/tests/unit/ui/web/test_dictation_polish_routes.py b/tests/unit/ui/web/test_dictation_polish_routes.py
index 0ebe6d1503..28bf5ccb11 100644
--- a/tests/unit/ui/web/test_dictation_polish_routes.py
+++ b/tests/unit/ui/web/test_dictation_polish_routes.py
@@ -581,3 +581,63 @@ def test_a_saved_translation_setting_survives_the_restart_too(
assert body.status_code == 200
assert ("translate", True) in written
assert ("translate_target", "zh") in written
+
+
+def test_switching_translation_off_round_trips_through_disk_and_reload(
+ app: FastAPI, monkeypatch: pytest.MonkeyPatch, tmp_path: Path
+) -> None:
+ """The false value is data, not an omitted optional field.
+
+ This is the restart regression in its complete shape: start from an enabled
+ file, send the same payload as the desktop switch, then construct a fresh
+ config from disk. Mocking the writer or asserting only the live object would
+ miss the exact failure the user sees after relaunching the app.
+ """
+ from jarvis.core import config_writer
+ from jarvis.core.config import load_config
+
+ config_file = tmp_path / "jarvis.toml"
+ config_file.write_text("[dictation]\ntranslate = true\n", encoding="utf-8")
+ real_set = config_writer.set_dictation_setting
+ monkeypatch.setattr(
+ config_writer,
+ "set_dictation_setting",
+ lambda key, value, **_kw: real_set(key, value, path=config_file),
+ )
+ app.state.config.dictation.translate = True
+
+ response = TestClient(app).put(
+ "/api/dictation/settings", json={"translate": False}
+ )
+
+ assert response.status_code == 200
+ assert response.json()["persisted"] is True
+ assert response.json()["settings"]["translate"] is False
+ assert load_config(config_file).dictation.translate is False
+
+
+def test_failed_translation_save_is_not_applied_only_until_restart(
+ app: FastAPI, monkeypatch: pytest.MonkeyPatch
+) -> None:
+ """A failed disk write must not masquerade as a successful switch.
+
+ Previously the live config changed first and the write failure was reduced
+ to ``persisted=false`` in an otherwise successful response. The UI ignored
+ that flag, so the toggle looked off until restart loaded the still-on file.
+ """
+ from jarvis.core import config_writer
+
+ app.state.config.dictation.translate = True
+
+ def _fail_write(*_args: Any, **_kwargs: Any) -> None:
+ raise PermissionError("simulated write denial")
+
+ monkeypatch.setattr(config_writer, "set_dictation_setting", _fail_write)
+
+ response = TestClient(app).put(
+ "/api/dictation/settings", json={"translate": False}
+ )
+
+ assert response.status_code == 500
+ assert "could not be saved" in response.json()["detail"]
+ assert app.state.config.dictation.translate is True