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(realtime): stop the speech edge from swallowing the head of the answer it earns

rubenluetke10-beep6e91a8b02326
diff --git a/jarvis/realtime/session.py b/jarvis/realtime/session.py
index a74cadc36f..cfa3d0daf2 100644
--- a/jarvis/realtime/session.py
+++ b/jarvis/realtime/session.py
@@ -4637,7 +4637,19 @@ class RealtimeVoiceSession:
async def _begin_user_speech_turn(self) -> None:
"""Close an interrupted reply before the next transcript opens a turn."""
- self._drop_provider_output_until_new_response = True
+ # Withhold ONLY when there is a reply to interrupt. Arming this on
+ # every speech edge silently swallowed the HEAD of any answer the
+ # server began before the local transcript landed — on a transport
+ # whose local recognizer needs a network round trip that beheaded
+ # the first reply of a call into a mid-sentence entry and re-added
+ # seconds of perceived latency (live 2026-08-05 20:12: 105 audio
+ # events dropped between the speech edge and the final transcript;
+ # the user heard the answer only from "…ich bin ganz entspannt").
+ # The rare late continuation of an already-closed turn playing into
+ # the user's new utterance is the accepted trade: it becomes an
+ # audible barge-in (output active) and is cut on the next edge.
+ if self._output_active or self._response_requested_for_turn:
+ self._drop_provider_output_until_new_response = True
if self._turn_id and self._turn_has_activity():
self._mark_latency_named(
"REALTIME_CANCEL",
diff --git a/tests/unit/realtime/test_session.py b/tests/unit/realtime/test_session.py
index 11d15587ac..73aa9728d2 100644
--- a/tests/unit/realtime/test_session.py
+++ b/tests/unit/realtime/test_session.py
@@ -6928,3 +6928,39 @@ async def test_silent_provider_audio_does_not_advance_liveness_or_echo_horizon()
assert sess._last_output_audio_at >= stamped_at
assert sess._echo_playback_horizon > horizon
await sess.end(reason="test")
+
+
+async def test_speech_edge_without_a_playing_reply_does_not_withhold_audio():
+ """A fresh utterance must not swallow the head of the answer it earns.
+
+ The speech edge armed the barge-in withhold unconditionally; on a
+ transport whose local recognizer needs a network round trip, the server's
+ answer regularly BEGINS before the final transcript lands, so its first
+ seconds were dropped and playback entered mid-sentence (live 2026-08-05
+ 20:12: 105 withheld audio events, the reply audible only from its middle).
+ """
+ sess = RealtimeVoiceSession(
+ session_id="s-speech-edge",
+ send_binary=lambda _pcm: asyncio.sleep(0),
+ send_json=lambda _message: asyncio.sleep(0),
+ provider=FakeProvider([]),
+ config=_cfg(),
+ bus=None,
+ )
+
+ await sess._begin_user_speech_turn()
+ assert sess._drop_provider_output_until_new_response is False
+
+ # With a reply audibly playing the same edge IS a barge-in: withhold.
+ sess._output_active = True
+ await sess._begin_user_speech_turn()
+ assert sess._drop_provider_output_until_new_response is True
+
+ # And a requested-but-not-yet-audible response counts the same way.
+ sess._output_active = False
+ sess._drop_provider_output_until_new_response = False
+ sess._response_requested_for_turn = True
+ await sess._begin_user_speech_turn()
+ assert sess._drop_provider_output_until_new_response is True
+ await sess.end(reason="test")