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): keep native audio after an empty-turn re-ask interrupt
Harald6fc9423a1929
diff --git a/jarvis/plugins/realtime/gemini_live.py b/jarvis/plugins/realtime/gemini_live.pyindex c46c78bece..dd57f87b91 100644--- a/jarvis/plugins/realtime/gemini_live.py+++ b/jarvis/plugins/realtime/gemini_live.py@@ -71,12 +71,16 @@ _STEERING_ORDER = ("language", "turn", "standing")# already in this connection's fixed system instruction — declares developer# messages silent configuration that the model must never acknowledge, with# exactly one opener as the exception. This header deliberately does NOT use-# that opener, and restates the silence so a model whose connect-time rule has-# faded still stays quiet.+# that opener (or the model would speak the configuration). It must still+# leave the user's last utterance answerable: on Gemini Live the delta+# travels as a realtime text input at the final-transcript boundary, and+# "do not answer it" made the model close the whole turn in silence+# (live 2026-08-19: every greeting recovered through the Brain chain)._STEERING_HEADER = ("Developer message — silent configuration update. It is NOT something the "- "user said and NOT a request to speak. Apply it from now on: do not "- "acknowledge it, do not answer it, and do not mention it."+ "user said. Do not acknowledge this message, do not mention it, and do not "+ "treat it as a new request. Apply it from now on. If the user has just "+ "spoken, answer THEM now under these rules.")diff --git a/jarvis/realtime/session.py b/jarvis/realtime/session.pyindex 044b76d784..ff9538f125 100644--- a/jarvis/realtime/session.py+++ b/jarvis/realtime/session.py@@ -7479,7 +7479,9 @@ class RealtimeVoiceSession:A direct-tool turn is retried only from its retained result; the userrequest is never replayed because that could repeat a side effect.Delegate-owned turns already have their own result lifecycle and are- likewise never redispatched.+ likewise never redispatched. A second empty ``turn_complete`` while+ the re-ask watchdog is live is not a mute — Vertex Live emits that+ edge for the re-ask text itself and still speaks afterwards."""turn_id = self._turn_idif (@@ -7603,13 +7605,31 @@ class RealtimeVoiceSession:# First net: ask the live model itself (a native turn the planner left# native has nothing the Brain chain could add except latency). The- # Brain chain is the second net — on a second empty boundary, or when- # the re-ask never produces a response at all.+ # Brain chain is the second net — when the re-ask watchdog expires+ # with the provider still mute. A second empty boundary while that+ # watchdog is live is the Gemini Live interrupt artifact of our own+ # text (live 2026-08-19: native audio arrived 0.65 s later and was+ # discarded because Brain recovery started at 0.14 s).if await self._reask_provider_for_empty_turn(turn_id):return True+ if self._empty_turn_reask_owns_turn(turn_id):+ log.info(+ "realtime[%s] empty boundary after re-ask is owned by the "+ "watchdog (turn %s) — not recovering through the Brain chain yet",+ self.session_id,+ turn_id,+ )+ return Trueself._recover_empty_turn_via_brain(turn_id)return True+ def _empty_turn_reask_owns_turn(self, turn_id: str) -> bool:+ """True while the empty-turn re-ask watchdog still owns ``turn_id``."""+ if not turn_id or self._empty_turn_reask_turn_id != turn_id:+ return False+ task = self._empty_turn_reask_task+ return task is not None and not task.done()+async def _reask_provider_for_empty_turn(self, turn_id: str) -> bool:"""Ask the live model again before paying a Brain-chain recovery.@@ -7621,7 +7641,9 @@ class RealtimeVoiceSession:provider-neutral: a transport without ``send_text`` simply skips tothe Brain chain. Returns True when the re-ask was sent; the watchdogthen owns the turn until audio arrives or the readback budget runs- out.+ out. A later empty boundary for the same turn must not short-circuit+ that wait — Vertex Live interrupts the re-ask text itself ~0.14 s+ later and still produces the spoken answer after that."""if not turn_id or self._empty_turn_reask_turn_id == turn_id:return Falsediff --git a/tests/unit/realtime/test_gemini_live.py b/tests/unit/realtime/test_gemini_live.pyindex c3fffeeab6..2cc8790d48 100644--- a/tests/unit/realtime/test_gemini_live.py+++ b/tests/unit/realtime/test_gemini_live.py@@ -327,8 +327,11 @@ async def test_changed_turn_directive_reaches_the_model_as_a_text_turn() -> Noneassert len(sent) == 1text = sent[0]["text"]assert _TURN_DIRECTIVE in text- # A developer message, explicitly not a request to speak.+ # A developer message, not a new user request — but the user's last+ # utterance must still be answered (live 2026-08-19: "do not answer it"+ # closed every greeting as silence).assert "silent configuration" in text+ assert "answer THEM now" in text# The rebuilt instruction block never travels; only the delta does.assert "x" * 100 not in textassert len(text) < 1_000diff --git a/tests/unit/realtime/test_session.py b/tests/unit/realtime/test_session.pyindex d4c4fcaebf..a7a47a6c3f 100644--- a/tests/unit/realtime/test_session.py+++ b/tests/unit/realtime/test_session.py@@ -4885,12 +4885,81 @@ async def test_empty_provider_turn_is_reasked_natively_before_any_brain_call():@pytest.mark.asyncio-async def test_direct_mode_recovers_provider_turn_that_has_no_output():+async def test_empty_turn_reask_keeps_native_audio_after_a_second_empty_boundary():+ """A second empty boundary after re-ask is the interrupt, not a mute.++ Live 2026-08-19 (vertex-live): every greeting sent a steering delta, the+ provider closed empty, the re-ask went out, and 0.14 s later another+ empty ``interrupted``+``turn_complete`` fired. Brain recovery started+ immediately and withheld the native 2.1 s reply that arrived 0.65 s+ after the re-ask. "Hallo" then took 15 s to first audio. The watchdog+ owns that wait; native audio that still comes must be spoken.+ """+ user_text = "Hello there."+ native_reply = "Hello. I am ready."+ spoken_audio = AudioChunk(+ pcm=b"\x01\x02" * 8,+ sample_rate=24_000,+ timestamp_ns=0,+ )+ brain = FakeBrain(replies=("never spoken",))+ provider = ScriptedTextTurnsProvider(+ [+ RealtimeEvent(+ type="input_transcript",+ text=user_text,+ is_final=True,+ ),+ RealtimeEvent(type="turn_complete"),+ ],+ [+ RealtimeEvent(type="interrupted"),+ RealtimeEvent(type="turn_complete"),+ RealtimeEvent(+ type="output_transcript_delta",+ text=native_reply,+ is_final=True,+ ),+ RealtimeEvent(type="audio_delta", audio=spoken_audio),+ RealtimeEvent(type="turn_complete"),+ ],+ )+ jsons: list[dict] = []+ binaries: list[bytes] = []+ bus = FakeBus()+ sess = _session(+ provider,+ brain=brain,+ tool_mode="direct",+ jsons=jsons,+ binaries=binaries,+ bus=bus,+ )++ await sess.handle_control({"type": "audio_start", "sample_rate": 16_000})+ await asyncio.wait_for(sess.wait_finished(), timeout=2)++ assert brain.calls == [], "the second empty must not start the Brain chain"+ assert len(provider.session.text_inputs) == 1+ assert "without any spoken answer" in provider.session.text_inputs[0]+ assert binaries == [spoken_audio.pcm]+ completed = [event for event in bus.events if isinstance(event, VoiceTurnCompleted)]+ assert len(completed) == 1+ assert completed[0].jarvis_text == native_reply+ await sess.end(reason="test")+++async def test_direct_mode_recovers_provider_turn_that_has_no_output(monkeypatch):"""A substantive user turn must never complete as successful silence.- The provider drops the turn, ignores the re-ask with a second empty- boundary, and only then does the Brain chain run — exactly once.+ The provider drops the turn and the re-ask stays mute (a second empty+ boundary, then nothing). The watchdog — not that second boundary —+ starts the Brain chain, exactly once."""+ import jarvis.realtime.session as session_module++ monkeypatch.setattr(session_module, "_DELEGATE_READBACK_WAIT_S", 0.1)user_text = "Tell me a joke about penguins."recovered_reply = "We could build a tiny game together."spoken_audio = AudioChunk(@@ -4908,7 +4977,8 @@ async def test_direct_mode_recovers_provider_turn_that_has_no_output():),RealtimeEvent(type="turn_complete"),],- # The re-ask is answered with a second empty boundary ...+ # The re-ask is answered with a second empty boundary and then+ # stays mute; the watchdog, not this edge, owns the Brain fallback.[RealtimeEvent(type="turn_complete")],# ... and the delegate result is then rendered natively.[@@ -4934,7 +5004,7 @@ async def test_direct_mode_recovers_provider_turn_that_has_no_output():)await sess.handle_control({"type": "audio_start", "sample_rate": 16_000})- await asyncio.wait_for(sess.wait_finished(), timeout=2)+ await asyncio.wait_for(sess.wait_finished(), timeout=3)assert [call[0] for call in brain.calls] == [user_text]assert len(provider.session.text_inputs) == 2