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): a turn that broke in two places names both causes

Haraldd4a9cca7243a
diff --git a/jarvis/voice/action_phrases.py b/jarvis/voice/action_phrases.py
index ac5b76bf5f..4c4f72ed16 100644
--- a/jarvis/voice/action_phrases.py
+++ b/jarvis/voice/action_phrases.py
@@ -886,6 +886,11 @@ def _is_speakable_observation(text: str | None) -> bool:
#: regex table, not a translator (AP-11: no LLM on this path). An unknown
#: reason — any third-party plugin's own text — is passed through verbatim,
#: because a foreign-language cause still beats no cause at all.
+#: Sentence boundary for a merged cause. Splits only on a full stop that is
+#: followed by whitespace, so a dotted token inside one cause (a file name,
+#: a skill id) stays whole.
+_REASON_SENTENCE_RE = re.compile(r"(?<=[.!?])\s+")
+
_REASON_FAMILIES: tuple[tuple[re.Pattern[str], dict[str, str]], ...] = (
(
re.compile(
@@ -958,8 +963,43 @@ def localize_failure_reason(reason: str | None, language: str) -> str:
if not text:
return ""
lang = str(language or "").strip().lower()
+ # A merged failure carries ONE sentence per broken tool, so the families
+ # are matched sentence by sentence. Run whole, the first family's trailing
+ # ``.*`` swallows every later cause and the user hears one of the two
+ # things that broke — the exact opposite of the standing rule that a
+ # failure names its cause.
+ #
+ # That trailing ``.*`` still earns its keep WITHIN one cause: a family
+ # sentence often drags a machine tail behind it ("Installed skills: a, b,
+ # c"), and none of that is speakable. So once a family has matched, a
+ # following sentence is kept only if it is a cause in its own right.
+ # Before the first match nothing is dropped: an unrecognized reason is a
+ # third party's own wording and still beats no cause at all.
+ spoken: list[str] = []
+ matched = False
+ for sentence in _REASON_SENTENCE_RE.split(text):
+ sentence = sentence.strip()
+ if not sentence:
+ continue
+ localized = _localize_one_reason(sentence, lang)
+ if localized is None:
+ if not matched:
+ spoken.append(sentence)
+ continue
+ matched = True
+ spoken.append(localized)
+ return " ".join(spoken)
+
+
+def _localize_one_reason(sentence: str, lang: str) -> str | None:
+ """Map ONE reported cause onto its localized wording.
+
+ Returns ``None`` when no family owns the sentence — the caller decides
+ whether an unrecognized sentence is a cause of its own or the machine tail
+ of the cause before it.
+ """
for pattern, templates in _REASON_FAMILIES:
- match = pattern.match(text)
+ match = pattern.match(sentence)
if match is None:
continue
# Same language resolution as ``action_phrase``: an unknown code falls
@@ -969,7 +1009,7 @@ def localize_failure_reason(reason: str | None, language: str) -> str:
if not subject:
continue
return template.format(subject=subject)
- return text
+ return None
def extract_speakable_reason(error: str | None, output: object = None) -> str | None:
diff --git a/tests/unit/voice/test_localize_failure_reason.py b/tests/unit/voice/test_localize_failure_reason.py
index 2fd5a380a5..7b7a14bcd7 100644
--- a/tests/unit/voice/test_localize_failure_reason.py
+++ b/tests/unit/voice/test_localize_failure_reason.py
@@ -115,3 +115,26 @@ def test_the_localized_cause_fits_the_failure_phrase() -> None:
)
assert "is not connected" not in spoken, "no English clause left in a German line"
assert "Plugins" in spoken, "the actionable part survives"
+
+
+def test_every_cause_of_a_merged_failure_is_localized() -> None:
+ """Two tools broke, so the user hears two causes — not the first one.
+
+ ``_merged_failure`` folds one sentence per broken tool into a single
+ reason. Matching that blob as a whole let the first family's trailing
+ ``.*`` eat every later cause.
+ """
+ spoken = localize_failure_reason(
+ "Google Calendar is not connected. Gmail is not connected.", "de"
+ )
+ assert "Google Calendar" in spoken
+ assert "Gmail" in spoken
+ assert "is not connected" not in spoken, "both causes speak German"
+
+
+def test_a_second_cause_survives_an_unrecognized_first_one() -> None:
+ spoken = localize_failure_reason(
+ "The printer jammed. Gmail is not connected.", "de"
+ )
+ assert "The printer jammed." in spoken, "a foreign cause is passed through"
+ assert "Gmail" in spoken and "Plugins" in spoken