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.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
fix(brain): record provider-down apology in transcript + resolve reply language for de/en/es
Ruben Lütke4732c026beaa
diff --git a/jarvis/brain/manager.py b/jarvis/brain/manager.pyindex e20f356892..7e3b7bf7a9 100644--- a/jarvis/brain/manager.py+++ b/jarvis/brain/manager.py@@ -1591,6 +1591,22 @@ class BrainManager:)self._reply_language = code+ def _resolve_turn_lang(self) -> str:+ """The de/en/es key this turn's output is localized to.++ The single authoritative resolver consumed by every ``ResponseGenerated``+ publish (success replies AND the total-failure apology) so the recorded+ transcript language is consistent and never the binary ``_looks_german``+ gate — which silently tags any non-German reply "en" and so drops Spanish+ (Runtime Output Language doctrine). An explicit pin wins; in auto mode it+ is THIS turn's detected language (set at the top of generate()); an+ undetected/ambiguous turn keeps the German default.+ """+ lang = self._reply_language+ if lang not in _REPLY_LANG_NAMES:+ lang = getattr(self, "_turn_detected_lang", "") or lang+ return lang if lang in _REPLY_LANG_NAMES else "de"+def _next_provider_down_phrase(self) -> str:"""Localized 'I can't reach my model' apology + advance the rotation.@@ -1599,18 +1615,37 @@ class BrainManager:spoken (live complaint 2026-06-01: the grok/Anthropic billing messagewas read aloud while Gemini was the active provider)."""- # An explicit pin wins; in auto mode speak THIS turn's detected language- # (set at the top of generate()) so an English/Spanish "auto" user does- # not hear a German apology on a total failure (Runtime Output Language).- # An undetected/ambiguous turn keeps the German default of- # _provider_down_phrase.- lang = self._reply_language- if lang not in _REPLY_LANG_NAMES:- lang = getattr(self, "_turn_detected_lang", "") or lang- phrase = _provider_down_phrase(lang, self._provider_down_idx)+ phrase = _provider_down_phrase(+ self._resolve_turn_lang(), self._provider_down_idx+ )self._provider_down_idx += 1return phrase+ async def _provider_down_reply(self, trace_uuid: UUID) -> str:+ """Total-failure apology, ALSO surfaced to the transcript.++ Returns the localized provider-down phrase AND publishes it as a+ ``ResponseGenerated`` event so the SessionRecorder records it as the+ turn's ``jarvis_text`` (``recorder.py::_on_response_generated``). Without+ this the recorded turn keeps an empty reply and the voice transcript+ shows the user line with no answer, even though the user heard the+ apology aloud (live forensic 2026-06-20, session 09eef351). The apology+ is deliberately NOT appended to the conversation history — an "I can't+ reach my model" line must not pollute the LLM context for later turns.+ """+ phrase = self._next_provider_down_phrase()+ # _next_provider_down_phrase already localized the phrase via+ # _resolve_turn_lang; resolving again here is deterministic (same pin /+ # detected-language inputs, the rotation index does not affect language)+ # and only tags the transcript's jarvis_lang — NEVER _looks_german, which+ # would mislabel a Spanish apology as English (Runtime Output Language).+ await self._bus.publish(ResponseGenerated(+ trace_id=trace_uuid,+ text=phrase,+ language=self._resolve_turn_lang(),+ ))+ return phrase+def _mandatory_lang_directive(self, name: str) -> str:"""The hard MANDATORY reply-language pin for a named language.@@ -3632,7 +3667,7 @@ class BrainManager:await self._bus.publish(ResponseGenerated(trace_id=trace_id or uuid4(),text=response_text,- language="de" if _looks_german(response_text) else "en",+ language=self._resolve_turn_lang(),))if self._curator is not None:@@ -4453,7 +4488,7 @@ class BrainManager:)else:log.warning("No brain providers available — spoken fallback used.")- return self._next_provider_down_phrase()+ return await self._provider_down_reply(trace_uuid)history = self._history if use_history else []last_exc: Exception | None = None@@ -4820,7 +4855,7 @@ class BrainManager:"Spoken fallback used instead of chain diagnostic: %s",_format_provider_chain_error(provider_errors),)- return self._next_provider_down_phrase()+ return await self._provider_down_reply(trace_uuid)# Robustness net (2026-05-24): a provider (notably Gemini) sometimes# emits a spawn_worker tool_use block as TEXT instead of executing@@ -4888,7 +4923,7 @@ class BrainManager:await self._bus.publish(ResponseGenerated(trace_id=trace_uuid,text=response_text,- language="de" if _looks_german(response_text) else "en",+ language=self._resolve_turn_lang(),))# Fire-and-forget: the curator extracts personal facts from the turndiff --git a/tests/integration/test_fallback_chain.py b/tests/integration/test_fallback_chain.pyindex 9ce673bd87..fe5f674a61 100644--- a/tests/integration/test_fallback_chain.py+++ b/tests/integration/test_fallback_chain.py@@ -9,6 +9,7 @@ import pytestfrom jarvis.brain.manager import BrainManagerfrom jarvis.core.bus import EventBusfrom jarvis.core.config import BrainProviderConfig, JarvisConfig+from jarvis.core.events import ResponseGeneratedfrom tests.fixtures.brain.fake_brain import FakeBrain@@ -62,6 +63,82 @@ async def test_all_providers_fail_returns_clear_error():)+async def test_all_providers_fail_publishes_response_generated_for_transcript():+ """Regression (live 2026-06-20, session 09eef351): the total-failure apology+ must reach the SessionRecorder so the voice transcript shows what Jarvis said.++ The recorder fills ``voice_turns.jarvis_text`` ONLY from a ``ResponseGenerated``+ event (``recorder.py::_on_response_generated``). The total-failure branch of+ ``generate`` returned the apology WITHOUT publishing that event, so the+ recorded turn had an empty ``jarvis_text`` — the UI showed the user line but no+ reply, even though the user clearly heard "ich komme gerade nicht an mein+ Sprachmodell". The spoken apology must be published like any other reply.+ """+ bus = EventBus()+ seen: list[ResponseGenerated] = []++ async def _capture(event: ResponseGenerated) -> None:+ seen.append(event)++ bus.subscribe(ResponseGenerated, _capture)++ config = JarvisConfig()+ manager = BrainManager(config=config, bus=bus, tools={})+ manager._registry._loaded = True++ broken = FakeBrain(text_response="x", fail_on_call=0)+ manager._brain_cache[("claude-subscription", "xyz")] = broken+ manager._build_fallback_chain = lambda level: [("claude-subscription", "xyz")]++ reply = await manager.generate("hi", use_history=False)++ assert manager._last_turn_all_failed is True+ assert reply.strip()+ assert len(seen) == 1, "total-failure apology was not published for the transcript"+ assert seen[0].text == reply+ # The transcript language must be a real localized key, never empty — a+ # regression that publishes the right text with language="" stays honest.+ assert seen[0].language in ("de", "en", "es")+++async def test_success_reply_language_is_resolved_not_looks_german():+ """A successful reply's ResponseGenerated.language must honor the resolved+ turn language (de/en/es), not the binary _looks_german gate that silently+ tags every non-German reply "en" and so drops Spanish (Runtime Output+ Language doctrine). A Spanish-pinned user's reply must be tagged "es".+ """+ bus = EventBus()+ seen: list[ResponseGenerated] = []++ async def _capture(event: ResponseGenerated) -> None:+ seen.append(event)++ bus.subscribe(ResponseGenerated, _capture)++ config = JarvisConfig()+ config.brain.primary = "gemini"+ config.brain.providers["gemini"] = BrainProviderConfig(model="gemini-flash")+ manager = BrainManager(config=config, bus=bus, tools={})+ manager._registry._loaded = True+ manager._reply_language = "es" # user pinned Spanish++ manager._brain_cache[("gemini", "gemini-flash")] = FakeBrain(+ text_response="Hola, ¿qué tal?"+ )+ manager._build_fallback_chain = lambda level: [("gemini", "gemini-flash")]++ reply = await manager.generate("hola", use_history=False)++ assert reply.strip()+ assert len(seen) == 1+ assert seen[0].language == "es", (+ "success reply tagged with _looks_german binary instead of the resolved "+ "turn language — Spanish dropped to English"+ )++@pytest.mark.asyncioasync def test_router_picks_deep_for_research_intent():"""Integration: deep-Intent → deep_model in Chain zuerst."""