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(voice): keep voice identity and the full answer on scrub-cancel fallbacks
Ruben Lütke4de8928b473e
diff --git a/jarvis/plugins/tts/fallback_tts.py b/jarvis/plugins/tts/fallback_tts.pyindex c0113820cb..5df26a5e1e 100644--- a/jarvis/plugins/tts/fallback_tts.py+++ b/jarvis/plugins/tts/fallback_tts.py@@ -99,6 +99,19 @@ class FallbackTTS:label, getattr(tts, "name", "?"), exc,)+ def list_voices(self, language: str | None = None) -> list[str]:+ """Voices of the ACTIVE primary — the provider a passed ``voice`` hits.++ Completes the ``TTSProvider`` protocol for this wrapper; callers use+ it to capability-gate a per-utterance voice hint. The fallback's+ catalogue is irrelevant here because ``_synthesize_fallback`` never+ forwards the caller's voice.+ """+ try:+ return list(self._primary.list_voices(language) or [])+ except Exception: # noqa: BLE001 — an unlistable catalogue means "no match"+ return []+async def synthesize(self,text: str,diff --git a/jarvis/realtime/session.py b/jarvis/realtime/session.pyindex 1955d553cb..c3d4af6af3 100644--- a/jarvis/realtime/session.py+++ b/jarvis/realtime/session.py@@ -1553,11 +1553,7 @@ class RealtimeVoiceSession:self.session_id,)await self._send_json(- {- "type": "error_spoken",- "text": text_only_answer,- "language": self._language,- }+ self._surface_speech_message(text_only_answer))if await self._recover_empty_provider_turn():continue@@ -1710,11 +1706,7 @@ class RealtimeVoiceSession:delegate_state.surface_fallback_spoken = Trueself._drop_provider_output_until_user_turn = Trueawait self._send_json(- {- "type": "error_spoken",- "text": fallback_text,- "language": self._language,- }+ self._surface_speech_message(fallback_text))final_chunks = self._gate.finalize()if self._gate.hard_leak_pending():@@ -1868,6 +1860,25 @@ class RealtimeVoiceSession:return ""return scrub_for_voice(raw, language=self._language).cleaned.strip()+ def _surface_speech_message(self, text: str) -> dict[str, Any]:+ """Build one ``error_spoken`` payload for the surface's classic TTS.++ The session's active realtime voice rides along as a hint so the+ classic last mile can keep the call's voice identity (live forensic+ 2026-07-17 10:04: Fenrir's aborted readback was re-spoken by Charon).+ The pipeline capability-gates the hint against the configured TTS's+ ``list_voices()``, so a foreign voice name never reaches a provider+ that would reject it.+ """+ message: dict[str, Any] = {+ "type": "error_spoken",+ "text": text,+ "language": self._language,+ }+ if self._active_voice:+ message["voice"] = self._active_voice+ return message+async def _cancel_unsafe_output(self,*,@@ -1916,14 +1927,17 @@ class RealtimeVoiceSession:self._output_active = Falseself._output_samples_sent = 0spoken_fallback = fallback_text or self._gate.fallback_phrase()+ # The turn's answer is what the user actually hears. Keeping the+ # aborted partial provider transcript here poisoned the NEXT turn:+ # ResponseGenerated / VoiceTurnCompleted / the delegate history all+ # carried a half sentence ("…Im Kalender"), so the follow-up turn no+ # longer knew what was really said and contradicted it (live forensic+ # 2026-07-17 10:04). Late provider output cannot re-append after this:+ # _drop_provider_output_until_new_response withholds it upstream.+ self._output_transcript.clear()+ self._output_transcript.append(spoken_fallback)try:- await self._send_json(- {- "type": "error_spoken",- "text": spoken_fallback,- "language": self._language,- }- )+ await self._send_json(self._surface_speech_message(spoken_fallback))except Exception: # noqa: BLE001, S110 — surface may already be gonepass# Keep the transcript honest (BUG-056): the 15:13 session recorded a@@ -2208,13 +2222,7 @@ class RealtimeVoiceSession:if self._input_turn_observed:fallback_text = self._gate.fallback_phrase()self._output_transcript.append(fallback_text)- await self._send_json(- {- "type": "error_spoken",- "text": fallback_text,- "language": self._language,- }- )+ await self._send_json(self._surface_speech_message(fallback_text))return Falseif self._direct_tool_results:@@ -2262,24 +2270,12 @@ class RealtimeVoiceSession:fallback_text = action_phrase("cu_done", self._language)self._output_transcript.append(fallback_text)- await self._send_json(- {- "type": "error_spoken",- "text": fallback_text,- "language": self._language,- }- )+ await self._send_json(self._surface_speech_message(fallback_text))return Falseif self._brain is None:fallback_text = self._gate.fallback_phrase()self._output_transcript.append(fallback_text)- await self._send_json(- {- "type": "error_spoken",- "text": fallback_text,- "language": self._language,- }- )+ await self._send_json(self._surface_speech_message(fallback_text))return Falseself._delegate_required_for_turn = True@@ -2865,13 +2861,7 @@ class RealtimeVoiceSession:"running — answering with the deterministic progress line",self.session_id,)- await self._send_json(- {- "type": "error_spoken",- "text": status_text,- "language": self._language,- }- )+ await self._send_json(self._surface_speech_message(status_text))async def _handle_tool_call(self, event: Any) -> None:if self._session is None:@@ -3346,11 +3336,7 @@ class RealtimeVoiceSession:exc_info=True,)await self._send_json(- {- "type": "error_spoken",- "text": turn_state.last_reply,- "language": self._language,- }+ self._surface_speech_message(turn_state.last_reply))returnawait self._verify_delegate_readback(turn_id, turn_state)@@ -3405,13 +3391,7 @@ class RealtimeVoiceSession:self.session_id,_DELEGATE_READBACK_WAIT_S,)- await self._send_json(- {- "type": "error_spoken",- "text": reply,- "language": self._language,- }- )+ await self._send_json(self._surface_speech_message(reply))def _start_delegate(self,diff --git a/jarvis/sessions/formatter.py b/jarvis/sessions/formatter.pyindex a47fd91acf..5dcb9c3010 100644--- a/jarvis/sessions/formatter.py+++ b/jarvis/sessions/formatter.py@@ -22,9 +22,10 @@ Copy-Paste-Konsum gedacht.from __future__ import annotationsfrom collections.abc import Iterable-from dataclasses import dataclass+from dataclasses import dataclass, replacefrom datetime import UTC, datetime+from .constants import SPOKEN_KIND_WITHHELDfrom .models import VoiceEventRow, VoiceSessionRow, VoiceTurnRow@@ -109,7 +110,36 @@ def _jarvis_outputs_for_turn())- return sorted(items, key=lambda it: (it.ts_ms, it.seq))+ return sorted(_fold_withheld_twins(items), key=lambda it: (it.ts_ms, it.seq))+++def _fold_withheld_twins(items: list[_JarvisOutput]) -> list[_JarvisOutput]:+ """Drop a ``withheld`` documentation event whose text a reply re-spoke.++ A scrub cancel publishes the withheld provider rendering AND hands the same+ text to the surface TTS, which confirms it as a real reply — two events,+ one utterance (live forensic 2026-07-17 10:04). Rendering both makes the+ transcript read as Jarvis repeating itself verbatim. The audible reply+ wins; the twin's abort detail is folded onto it so the markdown export+ keeps the forensic trace. A withheld event with no spoken twin still+ renders — it is then the only honest record of what the user heard.+ """+ reply_texts = {it.text for it in items if it.is_reply}+ folded_details: dict[str, str] = {}+ kept: list[_JarvisOutput] = []+ for it in items:+ if not it.is_reply and it.kind == SPOKEN_KIND_WITHHELD and it.text in reply_texts:+ if it.detail:+ folded_details.setdefault(it.text, it.detail)+ continue+ kept.append(it)+ result: list[_JarvisOutput] = []+ for it in kept:+ if it.is_reply and it.detail is None and it.text in folded_details:+ result.append(replace(it, detail=folded_details.pop(it.text)))+ else:+ result.append(it)+ return resultdef format_session_markdown(diff --git a/tests/unit/realtime/test_session.py b/tests/unit/realtime/test_session.pyindex 45d386e400..e781953e40 100644--- a/tests/unit/realtime/test_session.py+++ b/tests/unit/realtime/test_session.py@@ -4242,6 +4242,72 @@ async def test_scrub_cancel_records_spoken_fallback_on_the_spoken_track():assert spoken[0].text == sess._gate.fallback_phrase()+async def test_scrub_cancel_replaces_the_partial_transcript_with_the_spoken_fallback():+ """The turn's answer is what the user actually hears. Live forensic+ 2026-07-17 10:04: the aborted provider rendering left a half sentence+ ("…Im Kalender") as the turn text, so the NEXT turn's delegate history no+ longer knew what was really said and contradicted it. The cancel must+ replace the partial transcript with the spoken fallback."""+ provider = FakeProvider([])+ sess = RealtimeVoiceSession(+ session_id="scrub-cancel-transcript",+ send_binary=lambda _data: asyncio.sleep(0),+ send_json=lambda _message: asyncio.sleep(0),+ provider=provider,+ config=_cfg(),+ surface="desktop",+ )+ await sess.handle_control({"type": "audio_start", "sample_rate": 16_000})+ sess._output_transcript.append("Tomorrow looks relaxed. Your calendar")++ full_reply = (+ "Tomorrow looks relaxed. Your calendar only holds blocked slots, "+ "no real appointments."+ )+ await sess._cancel_unsafe_output(+ reason="output transcript exceeded safe audio buffer",+ fallback_text=full_reply,+ )++ assert "".join(sess._output_transcript) == full_reply+ await sess.end(reason="test")+++async def test_scrub_cancel_fallback_carries_the_active_voice_hint():+ """Voice-identity continuity (live forensic 2026-07-17 10:04: Fenrir's+ aborted readback was re-spoken by Charon): the surface fallback names the+ session's active voice so the pipeline TTS can keep speaking with it."""+ provider = FakeProvider([])+ sent: list[dict] = []++ def _capture_json(message):+ sent.append(message)+ return asyncio.sleep(0)++ sess = RealtimeVoiceSession(+ session_id="scrub-cancel-voice-hint",+ send_binary=lambda _data: asyncio.sleep(0),+ send_json=_capture_json,+ provider=provider,+ config=_cfg(),+ surface="desktop",+ )+ await sess.handle_control({"type": "audio_start", "sample_rate": 16_000})+ sess._active_voice = "Fenrir"++ await sess._cancel_unsafe_output(+ reason="output transcript exceeded safe audio buffer",+ fallback_text="Full grounded reply.",+ )++ fallbacks = [m for m in sent if m.get("type") == "error_spoken"]+ assert fallbacks and fallbacks[-1]["text"] == "Full grounded reply."+ assert fallbacks[-1]["voice"] == "Fenrir"+ await sess.end(reason="test")++# ---------------------------------------------------------------------------# User agent-instructions (the Ruben.md-equivalent file) in the realtime path# ---------------------------------------------------------------------------diff --git a/tests/unit/sessions/test_formatter.py b/tests/unit/sessions/test_formatter.pyindex ce33603140..b1f8a0d5d3 100644--- a/tests/unit/sessions/test_formatter.py+++ b/tests/unit/sessions/test_formatter.py@@ -364,3 +364,68 @@ def test_spoken_track_is_grouped_under_its_own_turn() -> None:turn2_section = out.split("## Turn 2")[1]assert "Bin noch dran." in turn2_sectionassert "Bin noch dran." not in out.split("## Turn 2")[0]+++# --- Withheld twin of a spoken reply (scrub-cancel fallback) ----------------+++def test_plain_folds_withheld_twin_into_the_spoken_reply() -> None:+ # A scrub cancel documents the withheld provider rendering AND hands the+ # same text to the surface TTS, which confirms it as a reply — two events,+ # one utterance (live forensic 2026-07-17 10:04). The plain transcript+ # must not read as Jarvis repeating itself verbatim.+ answer = "Morgen schaut es entspannt aus, dein Kalender ist frei."+ turns = [_turn(0, "Was kann ich morgen machen?", answer)]+ events = [+ _spoken("turn-0", answer, "reply", ts_ms=1_717_780_005_000),+ _spoken(+ "turn-0",+ answer,+ "withheld",+ ts_ms=1_717_780_005_005,+ detail="output transcript exceeded safe audio buffer",+ ),+ ]++ out = format_session_plain(_session(), turns, events)++ assert out.count(f"Jarvis: {answer}") == 1+++def test_markdown_keeps_the_abort_detail_when_folding_the_withheld_twin() -> None:+ answer = "Morgen schaut es entspannt aus, dein Kalender ist frei."+ turns = [_turn(0, "Was kann ich morgen machen?", answer)]+ events = [+ _spoken("turn-0", answer, "reply", ts_ms=1_717_780_005_000),+ _spoken(+ "turn-0",+ answer,+ "withheld",+ ts_ms=1_717_780_005_005,+ detail="output transcript exceeded safe audio buffer",+ ),+ ]++ out = format_session_markdown(_session(), turns, events)++ assert out.count(answer) == 1+ # The forensic abort reason survives on the surviving reply line.+ assert "output transcript exceeded safe audio buffer" in out+++def test_withheld_event_without_a_spoken_twin_still_renders() -> None:+ # When the surface never confirmed a fallback playback, the withheld event+ # is the only honest record of the aborted answer — it must stay visible.+ turns = [_turn(0, "Was kann ich morgen machen?", "")]+ events = [+ _spoken(+ "turn-0",+ "Der Anfang der Antwort, der abgebrochen wurde.",+ "withheld",+ detail="unsafe output transcript (detectors: secret)",+ ),+ ]++ out = format_session_plain(_session(), turns, events)++ assert "Jarvis: Der Anfang der Antwort, der abgebrochen wurde." in out