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): subagent voice switch validates via apply_provider_switch + honest readback

Ruben Lütke453c07c3bd47
diff --git a/jarvis/brain/manager.py b/jarvis/brain/manager.py
index fc2c1b6648..6f35b8d2a5 100644
--- a/jarvis/brain/manager.py
+++ b/jarvis/brain/manager.py
@@ -1214,6 +1214,27 @@ _SUBAGENT_SWITCH_CONFIRM: dict[str, str] = {
"en": "Done — your sub-agent will run on {p} from your next mission.",
"es": "Listo — tu sub-agente usará {p} desde tu próxima misión.",
}
+# Honest spoken failure phrases for a deterministic subagent switch that the
+# validated apply_provider_switch refused (missing credential / unknown). Never
+# a false "done"; always names what failed. de/en/es (Runtime Output Language).
+_SUBAGENT_SWITCH_FAIL: dict[str, dict[str, str]] = {
+ "missing_credential": {
+ "de": "{p} ist nicht verbunden — richte es zuerst ein, dann stelle ich um.",
+ "en": "{p} isn't connected — set it up first, then I'll switch.",
+ "es": "{p} no está conectado — configúralo primero y luego cambio.",
+ },
+ "other": {
+ "de": "Das konnte ich nicht auf {p} umstellen.",
+ "en": "I couldn't switch the sub-agent to {p}.",
+ "es": "No pude cambiar el sub-agente a {p}.",
+ },
+}
+
+
+def _subagent_switch_failure_phrase(result: dict, display: str, lang: str) -> str:
+ kind = str(result.get("error_kind") or "other")
+ table = _SUBAGENT_SWITCH_FAIL.get(kind, _SUBAGENT_SWITCH_FAIL["other"])
+ return table.get(lang, table["de"]).format(p=display)
# General self-control (2026-06-22). Not every settings change can have its own
# deterministic gate — the gates (language, sub-agent) are high-precision
@@ -2711,47 +2732,40 @@ class BrainManager:
return None
return match.target
- def _apply_subagent_provider_switch(self, word: str) -> str:
- """Execute a recognised sub-agent provider switch deterministically.
-
- The brain LLM used to escalate "switch the sub-agent provider to X" to a
- worker mission, because ``brain.sub_jarvis.provider`` has no settable
- self-mod tool (2026-06-22 forensic). This runs BEFORE the force-spawn /
- LLM path: map the spoken word to a canonical slug, then persist via the
- 3-layer ``config_writer.set_sub_jarvis_provider`` (TOML + config-soll pin
- + ENV) so the drift-guard cannot revert it. The running worker re-resolves
- the provider per mission (``_live_subagent_provider``), so it applies to
- the NEXT mission without a restart. Returns the spoken confirmation, or
- "" for an unknown provider word (caller falls through to the brain).
+ async def _apply_subagent_provider_switch(self, word: str) -> str:
+ """Execute a recognised sub-agent provider switch through the ONE
+ validated path (app_control.apply_provider_switch) instead of persisting
+ blindly. Maps the spoken word to a canonical slug, runs the same
+ credential validation the REST endpoint uses (Codex/Antigravity OAuth,
+ key presence), persists across all 3 layers (TOML + config-soll pin + ENV)
+ so the drift-guard cannot revert it, and renders an HONEST readback: the
+ real target on success, a named reason on failure, never a false "done".
+ Returns "" for an unknown word (caller falls through to the brain).
+ Forensic 2026-06-27: the old blind-persist path said "Erledigt" for an
+ unconnected provider and even when the persist threw.
"""
canonical = _SUBAGENT_VOICE_TO_CANONICAL.get(word.strip().lower())
if canonical is None:
return ""
- # Best-effort in-memory cfg agreement (a frozen model is not an error).
- try:
- from jarvis.core.config import BrainTierConfig
+ from jarvis.brain.app_control import apply_provider_switch, resolve_running_cfg
- self._config.brain.sub_jarvis = BrainTierConfig(provider=canonical)
- except Exception as exc: # noqa: BLE001
- log.debug("in-memory cfg.brain.sub_jarvis update skipped: %s", exc)
- # Persist across all 3 layers (TOML + config-soll drift-pin + ENV) — the
- # generic TOML-only write would be rolled back by the drift-guard.
try:
- from jarvis.core import config_writer
-
- config_writer.set_sub_jarvis_provider(canonical)
- except Exception as exc: # noqa: BLE001
- log.warning(
- "sub-agent provider persist failed (in-memory switch applied): %s",
- exc,
+ result = await apply_provider_switch(
+ "subagent", canonical, cfg=resolve_running_cfg()
)
- log.info(
- "sub-agent provider switched to %r via deterministic voice gate",
- canonical,
- )
+ except Exception as exc: # noqa: BLE001 — never crash the turn
+ log.warning("sub-agent voice switch failed: %s", exc)
+ result = {"ok": False, "error_kind": "other", "error": str(exc)}
+
lang = self._resolve_turn_lang()
- template = _SUBAGENT_SWITCH_CONFIRM.get(lang, _SUBAGENT_SWITCH_CONFIRM["de"])
- return template.format(p=_SUBAGENT_DISPLAY.get(canonical, canonical))
+ if result.get("ok"):
+ new = str(result.get("new_provider") or canonical)
+ display = _SUBAGENT_DISPLAY.get(new, new)
+ log.info("sub-agent provider switched to %r via deterministic voice gate", new)
+ template = _SUBAGENT_SWITCH_CONFIRM.get(lang, _SUBAGENT_SWITCH_CONFIRM["de"])
+ return template.format(p=display)
+ display = _SUBAGENT_DISPLAY.get(canonical, canonical)
+ return _subagent_switch_failure_phrase(result, display, lang)
def _detect_cancel_intent(self, text: str) -> bool:
"""True when the user wants to cancel a running OpenClaw task."""
@@ -5005,7 +5019,7 @@ class BrainManager:
# directly instead of escalating to a worker mission (2026-06-22 forensic).
subagent_switch = self._detect_subagent_switch_intent(user_text)
if subagent_switch:
- confirmation = self._apply_subagent_provider_switch(subagent_switch)
+ confirmation = await self._apply_subagent_provider_switch(subagent_switch)
if confirmation:
await self._record_response_side_effects(
user_text=user_text,
diff --git a/tests/unit/brain/test_subagent_voice_switch_validated.py b/tests/unit/brain/test_subagent_voice_switch_validated.py
new file mode 100644
index 0000000000..e7284fdef1
--- /dev/null
+++ b/tests/unit/brain/test_subagent_voice_switch_validated.py
@@ -0,0 +1,74 @@
+"""The deterministic subagent voice switch must validate + speak honestly.
+
+Forensic 2026-06-27: the voice gate path persisted blindly (no credential check)
+and said "Erledigt" even on failure — unlike the REST endpoint and
+app_control._switch_subagent, which validate. This routes it through the one
+validated apply_provider_switch and renders an honest readback.
+"""
+from __future__ import annotations
+
+from types import SimpleNamespace
+from uuid import UUID
+
+import pytest
+
+from jarvis.brain.manager import BrainManager
+from jarvis.core.bus import EventBus
+from jarvis.core.config import JarvisConfig
+
+
+class _FakeExecutor:
+ async def execute_confirmed(self, trace_id: UUID, **_): # pragma: no cover
+ return SimpleNamespace(success=True, output="ok", error=None)
+
+ async def cancel_pending(self, trace_id: UUID): # pragma: no cover
+ return True
+
+
+def _manager() -> BrainManager:
+ cfg = JarvisConfig()
+ cfg.brain.primary = "fake"
+ return BrainManager(config=cfg, bus=EventBus(), tools={}, tool_executor=_FakeExecutor())
+
+
+async def test_voice_subagent_switch_success_speaks_real_target(monkeypatch) -> None:
+ mgr = _manager()
+
+ async def _ok(tier, provider, *, cfg, persist=True):
+ assert tier == "subagent"
+ assert provider == "openai-codex" # "codex" mapped to canonical
+ return {"ok": True, "new_provider": "openai-codex", "requires_restart": True}
+
+ monkeypatch.setattr("jarvis.brain.app_control.apply_provider_switch", _ok)
+ monkeypatch.setattr("jarvis.brain.app_control.resolve_running_cfg", lambda: mgr._config)
+
+ out = await mgr._apply_subagent_provider_switch("codex")
+ assert "Codex" in out # the DISPLAY name of the real target
+
+
+async def test_voice_subagent_switch_failure_is_honest(monkeypatch) -> None:
+ mgr = _manager()
+
+ async def _fail(tier, provider, *, cfg, persist=True):
+ return {
+ "ok": False, "error_kind": "missing_credential",
+ "error": "Codex is not connected — run 'codex login' first.",
+ }
+
+ monkeypatch.setattr("jarvis.brain.app_control.apply_provider_switch", _fail)
+ monkeypatch.setattr("jarvis.brain.app_control.resolve_running_cfg", lambda: mgr._config)
+
+ out = await mgr._apply_subagent_provider_switch("codex")
+ assert out # never silent
+ low = out.lower()
+ assert "erledigt" not in low and "done" not in low # NOT a false success
+ assert "codex" in low # names what failed
+
+
+async def test_voice_subagent_switch_unknown_word_falls_through(monkeypatch) -> None:
+ mgr = _manager()
+ # an unmapped spoken word returns "" so the caller falls through to the brain
+ assert await mgr._apply_subagent_provider_switch("flibberprovider") == ""