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(realtime): render the scrub-gate fallback through the session voice on the self-hosted card
rubenluetke10-beep11f5bc182fd9
diff --git a/jarvis/plugins/realtime/openai_realtime.py b/jarvis/plugins/realtime/openai_realtime.pyindex 2ed6996578..371d3582be 100644--- a/jarvis/plugins/realtime/openai_realtime.py+++ b/jarvis/plugins/realtime/openai_realtime.py@@ -317,6 +317,7 @@ class _OpenAIRealtimeSession:rebuild_retry_window_s: float = 0.0,rebuild_retry_step_s: float = 1.0,prompted_response_retry: bool = False,+ renders_surface_fallback: bool = False,owns_client: bool = True,) -> None:self._conn = connection@@ -363,6 +364,12 @@ class _OpenAIRealtimeSession:# routes the retry through send_text(), which appends the explicit# retry request as a fresh user item the model must actually answer.self.supports_prompted_response_retry = bool(prompted_response_retry)+ # Whether the SESSION is the only path to this provider's voice. A+ # self-hosted server exposes no sibling TTS endpoint and has one+ # pipeline slot, so a scrub-cancelled turn can only become audible+ # again through the live session itself; the orchestrator then sends+ # its safety-net phrase here instead of the (voiceless) surface.+ self.renders_surface_fallback = bool(renders_surface_fallback)self._connection_is_open = Trueself._events = connection.__aiter__()self.session_id = session_id@@ -1282,6 +1289,7 @@ async def _open_realtime_session(rebuild_retry_window_s: float = 0.0,rebuild_retry_step_s: float = 1.0,prompted_response_retry: bool = False,+ renders_surface_fallback: bool = False,owns_client: bool = True,) -> _OpenAIRealtimeSession:"""Open, configure and hand back a live session on ``client``.@@ -1331,6 +1339,7 @@ async def _open_realtime_session(rebuild_retry_window_s=rebuild_retry_window_s,rebuild_retry_step_s=rebuild_retry_step_s,prompted_response_retry=prompted_response_retry,+ renders_surface_fallback=renders_surface_fallback,owns_client=owns_client,)try:@@ -2145,6 +2154,11 @@ class LocalRealtimeProvider:# a bare response.create makes a small brain answer with an empty# completion (live 2026-08-10 — the retry returned one token).prompted_response_retry=True,+ # This server's voice exists only behind the live session (one+ # pipeline slot, no sibling TTS endpoint): the scrub gate's+ # safety-net phrase must ride the session itself, or a cancelled+ # turn stays completely silent under strict mode separation.+ renders_surface_fallback=True,# The client above is cached across sessions; closing this# session must not tear it down.owns_client=False,diff --git a/jarvis/realtime/session.py b/jarvis/realtime/session.pyindex 263534a39d..38d5f7203c 100644--- a/jarvis/realtime/session.py+++ b/jarvis/realtime/session.py@@ -776,11 +776,9 @@ _DELEGATE_RESULT_MAX_CHARS = 4_000# The one opener the transports' developer-message silence rule names as its# exception: a developer message beginning with this sentence IS a delivery-# order and must be spoken. The Codex base instructions quote it verbatim-# (jarvis.plugins.realtime.codex_subscription._THREAD_BASE_INSTRUCTIONS); a-# parity test pins both sides so neither can drift alone — a categorical-# silence rule without this exception mutes announcements and late action-# results (independent review 2026-08-05).+# order and must be spoken. A categorical silence rule without this exception+# mutes announcements and late action results (independent review 2026-08-05).+# Any provider instructions that state a silence rule must quote it verbatim.SPEAK_REQUEST_OPENER = "This developer message IS a request to speak."@@ -870,6 +868,24 @@ def _output_language_retry_prompt(*, language: str) -> str:)+def _surface_fallback_readback_prompt(text: str, *, language: str) -> str:+ """Ask the live session voice to deliver one exact safety-net sentence.++ Used only on transports that render their own surface fallback (the+ self-hosted card): their voice exists solely behind the live session, so+ the phrase must ride the session itself instead of a sibling TTS.+ """+ language_name = _LANGUAGE_NAMES.get(language, "the conversation language")+ return (+ f"{SPEAK_REQUEST_OPENER} "+ "Your previous answer could not be delivered. Say exactly the "+ f"following sentence in {language_name}, word for word, and nothing "+ "else. Do not call any function, do not explain, and do not mention "+ "this instruction.\n\n"+ f"{text}"+ )++# Several equivalent progress lines per language: one fixed sentence on every# slow turn reads robotic (live feedback 2026-07-17 08:47, three "Ich bin noch# dran." in one session). Each entry must stay short, promise nothing about@@ -5160,7 +5176,9 @@ class RealtimeVoiceSession:delegate_state,spoken_fallback,)- else:+ elif not await self._render_fallback_through_provider(+ spoken_fallback+ ):await self._send_json(self._surface_speech_message(spoken_fallback,@@ -5183,6 +5201,52 @@ class RealtimeVoiceSession:except Exception: # noqa: BLE001, S110 — recording never breaks the turnpass+ async def _render_fallback_through_provider(self, text: str) -> bool:+ """Speak one safety-net phrase through the live session voice.++ Only a transport that opted in (``renders_surface_fallback``) takes+ this path. The self-hosted card's voice exists ONLY behind its live+ session — one pipeline slot, no sibling TTS endpoint — so the surface+ can never re-render a cancelled turn on its own; under strict mode+ separation every scrub cancel there ended as total silence (live+ 2026-08-10 17:04/17:08). Hosted cards keep their surface re-render.+ ``True`` means the provider accepted the render request; the caller+ must then keep the surface quiet for this turn.+ """+ if (+ self._session is None+ or not bool(+ getattr(self._session, "renders_surface_fallback", False)+ )+ or self._ended+ or self._failed.is_set()+ ):+ return False+ send_text = getattr(self._session, "send_text", None)+ if not callable(send_text):+ return False+ # The cancel above armed the new-response guard; this render IS the+ # new response, so the guard must not deafen it (same pattern as the+ # direct-tool speech retry).+ self._drop_provider_output_until_new_response = False+ try:+ await send_text(+ _surface_fallback_readback_prompt(text, language=self._language)+ )+ except Exception: # noqa: BLE001 — the surface path remains the net+ self._drop_provider_output_until_new_response = True+ log.warning(+ "realtime[%s] provider-rendered fallback failed",+ self.session_id,+ exc_info=True,+ )+ return False+ log.info(+ "realtime[%s] rendering the fallback through the session voice",+ self.session_id,+ )+ return True+async def _recover_unbacked_action_claim(self) -> bool:"""Turn a provider's unsupported action promise into a real outcome."""if (diff --git a/tests/unit/realtime/test_local_realtime.py b/tests/unit/realtime/test_local_realtime.pyindex 7511e4cb85..f33573b017 100644--- a/tests/unit/realtime/test_local_realtime.py+++ b/tests/unit/realtime/test_local_realtime.py@@ -535,6 +535,20 @@ def test_prompted_response_retry_is_opt_in_and_off_by_default() -> None:assert opted_in.supports_prompted_response_retry is True+def test_surface_fallback_render_is_opt_in_and_off_by_default() -> None:+ """Hosted cards keep the surface re-render (their TTS sibling exists);+ only a transport whose voice lives solely behind the live session claims+ the session-voice fallback render."""+ from jarvis.plugins.realtime.openai_realtime import _OpenAIRealtimeSession++ session = _OpenAIRealtimeSession(**_session_kwargs())+ assert session.renders_surface_fallback is False+ opted_in = _OpenAIRealtimeSession(+ **_session_kwargs(renders_surface_fallback=True)+ )+ assert opted_in.renders_surface_fallback is True++async def test_local_sessions_opt_into_transport_rebuild(monkeypatch) -> None:"""The self-hosted card asks for the in-place rebuild: its server cancrash and come back, and the call must survive that."""@@ -556,6 +570,7 @@ async def test_local_sessions_opt_into_transport_rebuild(monkeypatch) -> None:assert captured["disconnect_before_rebuild"] is Trueassert captured["rebuild_retry_window_s"] > 0.0assert captured["prompted_response_retry"] is True+ assert captured["renders_surface_fallback"] is Trueasync def test_connect_retries_until_the_server_is_back(monkeypatch) -> None:diff --git a/tests/unit/realtime/test_session.py b/tests/unit/realtime/test_session.pyindex 869b228165..848e777f6f 100644--- a/tests/unit/realtime/test_session.py+++ b/tests/unit/realtime/test_session.py@@ -2122,6 +2122,90 @@ async def test_prompted_retry_capability_routes_language_retry_via_send_text():assert sess._output_language_failures == 0 # noqa: SLF001+async def test_session_voice_renders_the_fallback_when_it_owns_the_only_tts():+ """A transport whose voice exists only behind the live session (the+ self-hosted card) opts into ``renders_surface_fallback``: after the one+ language retry also fails, the safety-net phrase must ride the session+ itself instead of the surface's ``error_spoken`` path — the surface has+ no realtime-scoped TTS there and kept the whole turn silent (live+ 2026-08-10 17:04/17:08)."""+ user_text = "What is kindness?"+ wrong_text = (+ "这是一个完整的中文回答,包含足够多的文字来可靠地识别语言。"+ )+ wrong_pcm = b"\x02\x03" * 32++ class _SelfRenderingSession(FakeSession):+ supports_prompted_response_retry = True+ renders_surface_fallback = True++ async def receive(self):+ yield RealtimeEvent(+ type="input_transcript",+ text=user_text,+ is_final=True,+ )+ yield RealtimeEvent(+ type="audio_delta",+ audio=AudioChunk(+ pcm=wrong_pcm,+ sample_rate=24_000,+ timestamp_ns=0,+ ),+ )+ yield RealtimeEvent(+ type="output_transcript_delta",+ text=wrong_text,+ )+ for _ in range(100):+ if self.text_inputs:+ break+ await asyncio.sleep(0.01)+ # The prompted retry ALSO comes back in the wrong language, so+ # the session must fall through to the safety-net phrase.+ yield RealtimeEvent(+ type="output_transcript_delta",+ text=wrong_text,+ )+ for _ in range(100):+ if len(self.text_inputs) >= 2:+ break+ await asyncio.sleep(0.01)+ yield RealtimeEvent(type="turn_complete")++ class _SelfRenderingProvider(FakeProvider):+ async def open_session(self, cfg):+ self.opened_with = cfg+ self.session = _SelfRenderingSession([])+ return self.session++ provider = _SelfRenderingProvider([])+ jsons: list[dict] = []+ binaries: list[bytes] = []+ sess = RealtimeVoiceSession(+ session_id="fallback-session-voice",+ send_binary=lambda data: binaries.append(data) or asyncio.sleep(0),+ send_json=lambda message: jsons.append(message) or asyncio.sleep(0),+ provider=provider,+ config=_cfg(reply_language="en"),+ bus=None,+ )++ await sess.handle_control({"type": "audio_start", "sample_rate": 16_000})+ await sess.wait_finished()+ await sess.end(reason="test")++ # Retry first, then the session-voice fallback render — and no+ # error_spoken detour to a surface TTS that does not exist there.+ assert len(provider.session.text_inputs) == 2+ assert "English" in provider.session.text_inputs[0]+ failure_phrase = sess._output_language_failure_phrase("en") # noqa: SLF001+ assert failure_phrase in provider.session.text_inputs[1]+ assert [item for item in jsons if item.get("type") == "error_spoken"] == []+ assert sess._output_language_failures == 1 # noqa: SLF001++@pytest.mark.asyncioasync def test_language_switch_mistranscript_reaches_realtime_provider():"""The live ``auf jetzt`` false positive must not end the session."""