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(missions): speak the sub-agent completion readback in the dispatch language
Ruben Lütkefe16082c4a8c
diff --git a/jarvis/missions/kontrollierer/deliverable.py b/jarvis/missions/kontrollierer/deliverable.pyindex b4dfdfa247..c11344e4ad 100644--- a/jarvis/missions/kontrollierer/deliverable.py+++ b/jarvis/missions/kontrollierer/deliverable.py@@ -80,22 +80,70 @@ _TRANSLIT: Final[dict[str, str]] = {_DELIVERABLES_FOLDER_NAME: Final[str] = "Jarvis-Outputs"-def build_deliverable_summary(mission_dir: Path) -> str:- """Return a TTS-safe German sentence naming the mission's archived files.+#: TTS templates for the deliverable / delivered summaries, keyed by the+#: mission's DISPATCH language. The summary is recycled into+#: ``MissionApproved.summary_de`` / ``summary_en`` and spoken back by the+#: announcer in the language the mission was dispatched in. Before 2026-06-24+#: only the German forms existed, so an English-dispatched file mission read its+#: completion confirmation back in German (the announcer picked ``summary_en``+#: but it carried German text, and the pipeline re-detected German). Keys ``de``+#: and ``en`` only — Spanish dispatch falls back to ``de`` at the spawn layer+#: (the ``Literal["de","en"]`` dispatch contract). "Datei" / "File" stay outside+#: the scrub blacklist so they survive ``scrub_for_voice``.+_DELIVERABLE_TEMPLATES: Final[dict[str, dict[str, str]]] = {+ "de": {+ "one": "Fertig. Datei {name} ist gespeichert.",+ "few": "Fertig. {count} Dateien gespeichert: {joined}.",+ "many": "Fertig. {count} Dateien gespeichert.",+ },+ "en": {+ "one": "Done. File {name} is saved.",+ "few": "Done. {count} files saved: {joined}.",+ "many": "Done. {count} files saved.",+ },+}++_DELIVERED_TEMPLATES: Final[dict[str, dict[str, str]]] = {+ "de": {+ "one": "Fertig. Datei {name} liegt im Ordner {folder}.",+ "few": "Fertig. {count} Dateien im Ordner {folder}: {joined}.",+ "many": "Fertig. {count} Dateien im Ordner {folder} gespeichert.",+ },+ "en": {+ "one": "Done. File {name} is in the folder {folder}.",+ "few": "Done. {count} files in the folder {folder}: {joined}.",+ "many": "Done. {count} files in the folder {folder}.",+ },+}+++def _templates(table: dict[str, dict[str, str]], language: str) -> dict[str, str]:+ """Return the template set for *language*, defaulting to German.++ German is the back-compat default (every pre-2026-06-24 caller and the+ ``Literal["de","en"]`` spawn contract's ``es``-fallback resolve here).+ """+ return table.get(language, table["de"])+++def build_deliverable_summary(mission_dir: Path, *, language: str = "de") -> str:+ """Return a TTS-safe sentence naming the mission's archived files.Args:mission_dir: Path to ``<isolation_root>/mission_<id[:13]>/``.+ language: Dispatch language (``"de"`` / ``"en"``) the sentence is spoken+ in. Defaults to German; an unknown code falls back to German.Returns:Empty string when there are no archived deliverables. Otherwise a- speakable German sentence:+ speakable sentence in *language*, e.g. for German:* 1 file: ``"Fertig. Datei <name> ist gespeichert."``* 2..3 files: ``"Fertig. <n> Dateien gespeichert: A, B."``* 4+ files: ``"Fertig. <n> Dateien gespeichert."``Caller (``Kontrollierer._approve_mission``) ``or``-fallbacks to- ``"Mission abgeschlossen."`` when this returns empty.+ ``"Mission abgeschlossen."`` / ``"Mission completed."`` when empty."""tasks_root = mission_dir / "tasks"if not tasks_root.exists() or not tasks_root.is_dir():@@ -119,13 +167,14 @@ def build_deliverable_summary(mission_dir: Path) -> str:if not names:return ""+ tpl = _templates(_DELIVERABLE_TEMPLATES, language)count = len(names)if count == 1:- return f"Fertig. Datei {names[0]} ist gespeichert."+ return tpl["one"].format(name=names[0])if count <= _MAX_NAMED_FILES:joined = ", ".join(names)- return f"Fertig. {count} Dateien gespeichert: {joined}."- return f"Fertig. {count} Dateien gespeichert."+ return tpl["few"].format(count=count, joined=joined)+ return tpl["many"].format(count=count)def _existing_deliverable_files(mission_dir: Path) -> list[Path]:@@ -415,24 +464,30 @@ def deliver_to_user_folder(return delivered-def build_delivered_summary(delivered: list[Path]) -> str:- """TTS-safe German sentence naming delivered files AND their folder.+def build_delivered_summary(delivered: list[Path], *, language: str = "de") -> str:+ """TTS-safe sentence naming delivered files AND their folder.Unlike :func:`build_deliverable_summary` (which only names the archivebasenames), this also tells the user WHERE the file landed so they can openit. Empty string when nothing was delivered (caller falls back).++ Args:+ delivered: the on-disk paths the deliverables were mirrored to.+ language: Dispatch language (``"de"`` / ``"en"``) the sentence is spoken+ in. Defaults to German; an unknown code falls back to German."""if not delivered:return ""folder = delivered[0].parentnames = [p.name for p in delivered]+ tpl = _templates(_DELIVERED_TEMPLATES, language)count = len(names)if count == 1:- return f"Fertig. Datei {names[0]} liegt im Ordner {folder.name}."+ return tpl["one"].format(name=names[0], folder=folder.name)if count <= _MAX_NAMED_FILES:joined = ", ".join(names)- return f"Fertig. {count} Dateien im Ordner {folder.name}: {joined}."- return f"Fertig. {count} Dateien im Ordner {folder.name} gespeichert."+ return tpl["few"].format(count=count, folder=folder.name, joined=joined)+ return tpl["many"].format(count=count, folder=folder.name)__all__ = [diff --git a/jarvis/missions/kontrollierer/orchestrator.py b/jarvis/missions/kontrollierer/orchestrator.pyindex 13c38cac0e..3bb9807a8b 100644--- a/jarvis/missions/kontrollierer/orchestrator.py+++ b/jarvis/missions/kontrollierer/orchestrator.py@@ -2427,18 +2427,27 @@ class Kontrollierer:logger.warning("deliver_to_user_folder failed for %s", mission_id, exc_info=True)- delivered_summary = build_delivered_summary(delivered)- # Prefer, in order: a read-only task's spoken answer, the delivered-file- # summary (names file + folder), the in-archive basename summary, then- # the generic phrase.- deliverable_summary = build_deliverable_summary(mission_dir)+ # Build BOTH language variants so MissionApproved carries a genuinely+ # English summary_en — the announcer selects the field by the mission's+ # DISPATCH language, so a German-only summary_en made an English-dispatched+ # mission read its completion confirmation back in German (forensic+ # 2026-06-24: the deliverable summary was the deterministic German leak;+ # answer_summary already mirrors the request language via the worker).+ # Prefer, in order: a read-only task's spoken answer (already in the+ # request language), the delivered-file summary (names file + folder),+ # the in-archive basename summary, then the generic phrase.summary_de = (answer_summary- or delivered_summary- or deliverable_summary+ or build_delivered_summary(delivered, language="de")+ or build_deliverable_summary(mission_dir, language="de")or "Mission abgeschlossen.")- summary_en = answer_summary or deliverable_summary or "Mission completed."+ summary_en = (+ answer_summary+ or build_delivered_summary(delivered, language="en")+ or build_deliverable_summary(mission_dir, language="en")+ or "Mission completed."+ )env = EventEnvelope(mission_id=mission_id,source_actor="kontrollierer",diff --git a/tests/missions/kontrollierer/test_approve_materialises_report.py b/tests/missions/kontrollierer/test_approve_materialises_report.pyindex 48723fac76..a200a18b77 100644--- a/tests/missions/kontrollierer/test_approve_materialises_report.py+++ b/tests/missions/kontrollierer/test_approve_materialises_report.py@@ -19,6 +19,7 @@ import pytestimport jarvis.missions.kontrollierer.deliverable as deliv_modimport jarvis.missions.kontrollierer.orchestrator as orch_mod+from jarvis.missions.events import MissionApprovedfrom jarvis.missions.kontrollierer.orchestrator import Kontrollierer_LONG_ANSWER = (@@ -124,6 +125,45 @@ async def test_approve_no_duplicate_report_when_file_deliverable_exists(assert (files / "landing.html").is_file()+def _approved_event(store: _FakeStore) -> MissionApproved:+ """The MissionApproved payload the approve path published (last one)."""+ for env in reversed(store.published):+ payload = getattr(env, "payload", None)+ if isinstance(payload, MissionApproved):+ return payload+ raise AssertionError("no MissionApproved event was published")+++async def test_approve_builds_english_summary_en_for_file_deliverable(+ orch: Kontrollierer,+) -> None:+ """summary_en must be genuinely English (de/en diverge) for a file mission.++ Forensic 2026-06-24: the announcer picks summary_en for an English-dispatched+ mission, but the orchestrator recycled the German-only deliverable summary+ into BOTH fields, so an English request read its completion confirmation back+ in German. With no worker answer (answer_summary empty) the summary comes+ straight from the deliverable builders — the deterministic German leak.+ """+ mission_id = "019edf4c-f827dddd"+ mdir = _mission_dir(orch, mission_id)+ files = mdir / "tasks" / "019edf4c-task1" / "artifacts" / "files"+ files.mkdir(parents=True, exist_ok=True)+ (files / "landing.html").write_text("<html/>", encoding="utf-8")+ # No _task_answers → answer_summary is empty → the deliverable builders run.++ await orch._approve_mission(mission_id, _FakePlan(), prompt="build a landing page")++ approved = _approved_event(orch._manager.store) # type: ignore[attr-defined]+ assert "landing.html" in approved.summary_en+ assert "saved" in approved.summary_en+ assert "Fertig" not in approved.summary_en and "gespeichert" not in approved.summary_en, (+ f"summary_en must be English, got {approved.summary_en!r}"+ )+ # The German field still speaks German — the two diverge as designed.+ assert "Fertig" in approved.summary_de and "Datei" in approved.summary_de++async def test_approve_mirrors_materialised_report_to_user_folder(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:diff --git a/tests/missions/kontrollierer/test_deliverable.py b/tests/missions/kontrollierer/test_deliverable.pyindex 0cb686dd2d..164c93ae55 100644--- a/tests/missions/kontrollierer/test_deliverable.py+++ b/tests/missions/kontrollierer/test_deliverable.py@@ -15,7 +15,10 @@ from __future__ import annotationsfrom pathlib import Path-from jarvis.missions.kontrollierer.deliverable import build_deliverable_summary+from jarvis.missions.kontrollierer.deliverable import (+ build_deliverable_summary,+ build_delivered_summary,+)def test_no_tasks_dir_returns_empty(tmp_path: Path) -> None:@@ -103,3 +106,101 @@ def test_missing_mission_dir_returns_empty(tmp_path: Path) -> None:"""Defensive: a non-existent mission dir must not crash the readback path."""bogus = tmp_path / "does-not-exist"assert build_deliverable_summary(bogus) == ""+++# --- Dispatch-language localisation -----------------------------------------+# Forensic 2026-06-24: a mission dispatched in English read its completion+# confirmation back in German because the deliverable summary was German-only+# and got recycled into BOTH MissionApproved.summary_de and summary_en. The+# announcer then selected summary_en for an English dispatch but it carried+# German text, so the spoken readback was German. The builders must produce a+# genuinely English string when asked for ``language="en"`` so summary_en is+# really English.+++def test_single_file_summary_in_english(tmp_path: Path) -> None:+ """language='en' → an English sentence naming the file, no German words."""+ files = tmp_path / "tasks" / "019e63c5-5855" / "artifacts" / "files"+ files.mkdir(parents=True)+ (files / "landing.html").write_text("<html/>", encoding="utf-8")+ s = build_deliverable_summary(tmp_path, language="en")+ assert "landing.html" in s, f"filename must appear, got {s!r}"+ assert "saved" in s+ assert "Datei" not in s and "gespeichert" not in s, (+ f"English summary must not contain German words: {s!r}"+ )+++def test_two_files_summary_in_english(tmp_path: Path) -> None:+ """language='en' → 'N files' inline list, not the German '2 Dateien'."""+ files = tmp_path / "tasks" / "019e63c5-1234" / "artifacts" / "files"+ files.mkdir(parents=True)+ (files / "landing.html").write_text("<html/>", encoding="utf-8")+ (files / "notes.md").write_text("notes", encoding="utf-8")+ s = build_deliverable_summary(tmp_path, language="en")+ assert "landing.html" in s and "notes.md" in s+ assert "2 files" in s+ assert "Dateien" not in s, f"English summary leaked German plural: {s!r}"+++def test_deliverable_summary_defaults_to_german(tmp_path: Path) -> None:+ """No language arg keeps the historical German output (back-compat)."""+ files = tmp_path / "tasks" / "019e63c5-5855" / "artifacts" / "files"+ files.mkdir(parents=True)+ (files / "landing.html").write_text("<html/>", encoding="utf-8")+ assert "Datei" in build_deliverable_summary(tmp_path)+++def test_delivered_summary_in_english(tmp_path: Path) -> None:+ """build_delivered_summary names the folder in English when asked."""+ folder = tmp_path / "Jarvis-Outputs"+ folder.mkdir()+ f = folder / "report.md"+ f.write_text("x", encoding="utf-8")+ s = build_delivered_summary([f], language="en")+ assert "report.md" in s+ assert "folder" in s and "Jarvis-Outputs" in s+ assert "Datei" not in s and "Ordner" not in s, (+ f"English delivered summary must not contain German words: {s!r}"+ )+++def test_delivered_summary_defaults_to_german(tmp_path: Path) -> None:+ """No language arg keeps the historical German output (back-compat)."""+ folder = tmp_path / "Jarvis-Outputs"+ folder.mkdir()+ f = folder / "report.md"+ f.write_text("x", encoding="utf-8")+ s = build_delivered_summary([f])+ assert "Ordner" in s and "Datei" in s+++# --- End-of-chain seam ------------------------------------------------------+# The announcer selects summary_en for an English dispatch and the speech+# pipeline RE-RESOLVES the spoken language from the summary TEXT+# (resolve_output_language, the 2026-06-23 design: an emitter-stamped tag is+# only a hint so a German chat can't speak an English announcement). The+# localised English summary must (a) BE English words and (b) resolve to "en"+# at that seam — even in the worst case where the surrounding conversation has+# since drifted to German (conversation_language="de") and no pin is set. The+# old German summary failed (a) outright: the user heard German words regardless+# of which TTS voice the resolver picked.+++def test_english_delivered_summary_resolves_to_en_at_pipeline_seam(+ tmp_path: Path,+) -> None:+ from jarvis.core.turn_language import resolve_output_language++ folder = tmp_path / "Jarvis-Outputs"+ folder.mkdir()+ (folder / "report.md").write_text("x", encoding="utf-8")+ en_summary = build_delivered_summary([folder / "report.md"], language="en")++ resolved = resolve_output_language(+ "auto", "en", en_summary, conversation_language="de"+ )+ assert resolved == "en", (+ f"English readback summary must keep 'en' at the pipeline seam, "+ f"got {resolved!r} for {en_summary!r}"+ )