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): mirror the frozen turn to the surface on in-place transport rebuild (BUG-085)

Ruben Lütke75b91d98b98e
diff --git a/docs/BUGS.md b/docs/BUGS.md
index d26d671d63..ec381be937 100644
--- a/docs/BUGS.md
+++ b/docs/BUGS.md
@@ -5858,3 +5858,57 @@ bare detector just moves the bug. An interrupt detector needs an energy floor
any state transition that deliberately skips echo suppression (real barge-in)
needs a content-level backstop, because it will eventually be entered by
mistake.
+
+## BUG-085: Realtime session goes permanently DEAF after an in-place transport rebuild — the surface's echo guard swallows every microphone frame (CRITICAL, FIXED 2026-07-18)
+
+**Symptom (live 2026-07-18 16:17, gemini-live, 21-turn conversation).** At
+the ~10-minute Gemini Live session limit the server sent `GoAway`
+(`time_left=50s`) and then aborted the WebSocket with `1008 policy
+violation` — right as turn 21's 35-second reply finished draining from the
+speaker. The BUG-071 in-place rebuild worked: a fresh transport was open
+~2 s later, no error surfaced, the call stayed "alive". But the user then
+spoke for 20 more seconds into a session that heard NOTHING — no
+transcript, no orb/taskbar reaction, no reply — until they hotkey-killed
+the call.
+
+**Root cause — the rebuild froze the turn for the RECORDER but never told
+the SURFACE.** A natural turn boundary sends the surface
+`{"type": "turn_complete"}` and then publishes the turn-completed event;
+`_rebuild_transport` only published the event. The desktop surface's
+half-duplex closure (`jarvis/speech/pipeline.py`) leaves its `speaking`
+echo-guard state only on session JSON (`turn_complete` / `tts_cancel` /
+`thinking` / `hangup`) — and the dead transport can never deliver its own
+`turn_complete`. With `speaking` stuck True, `_send_microphone` routes
+every frame into `DesktopRealtimeBargeInDetector.feed()` and uploads
+nothing. The detector is deliberately conservative (static RMS floor,
+0.97 × 12-frame confirm, BUG-084's adaptive echo floor still elevated from
+35 s of loud playback), so normal-volume "is anyone there?" speech never
+confirms a barge-in: the microphone is swallowed locally, forever. The
+rebuilt transport was healthy — it simply never received a byte.
+
+**Fix (both sides, transport-neutral).**
+
+1. **Session side (`jarvis/realtime/session.py::_rebuild_transport`):**
+ mirror the frozen turn to the surface exactly like a natural boundary —
+ send `{"type": "turn_complete"}` (best-effort) before
+ `_publish_turn_completed()` and the fresh `audio_ready`. The surface
+ drains any salvaged audio tail, closes the output segment, and returns
+ to LISTENING; in single-turn mode this also ends the call exactly as a
+ completed turn should.
+2. **Desktop surface (`jarvis/speech/pipeline.py`, `audio_ready`
+ handler):** defense in depth — a transport that just completed its
+ handshake cannot be mid-output, so a still-open output segment at
+ `audio_ready` is stale pre-rebuild state and is drained + closed before
+ the new sample rate applies.
+
+**Guards.**
+`tests/unit/realtime/test_session.py::test_transport_rebuild_mirrors_the_frozen_turn_to_the_surface`
+(exactly one rebuild-sourced `turn_complete`, ordered before the second
+`audio_ready`).
+
+**Class rule (extends BUG-071's).** An in-place transport rebuild must
+resynchronize EVERY party that tracks per-turn state — the provider session
+object alone is not the session. Any surface state machine that can only be
+released by a message from the (now dead) transport will wedge; whoever
+declares the old turn finished must broadcast that fact to all surfaces,
+not just to the recorder.
diff --git a/jarvis/realtime/session.py b/jarvis/realtime/session.py
index ad116bcd3c..d45a3f3d52 100644
--- a/jarvis/realtime/session.py
+++ b/jarvis/realtime/session.py
@@ -1985,6 +1985,21 @@ class RealtimeVoiceSession:
len(self._pending_tool_events),
)
self._pending_tool_events = []
+ # Mirror the frozen turn to the SURFACE exactly like a natural
+ # boundary does (turn_complete JSON, then publish): the dead
+ # transport can never deliver its own turn_complete, and without it
+ # the desktop surface stays in its half-duplex "assistant is
+ # speaking" echo-guard state forever — every later microphone frame
+ # is fed only to the local barge-in detector, never uploaded, so the
+ # freshly rebuilt transport hears NOTHING and the call sits deaf
+ # until the user hotkey-kills it (BUG-085, live forensic 2026-07-18
+ # 16:17: Gemini's Live-API session limit aborted the connection with
+ # 1008 right as turn 21's reply drained; the rebuild succeeded in
+ # ~2 s but the user spoke into a swallowed microphone for 20 s).
+ try:
+ await self._send_json({"type": "turn_complete"})
+ except Exception: # noqa: BLE001, S110 — surface mirror is best-effort
+ pass
await self._publish_turn_completed()
self._gate = ScrubHoldGate(self._language)
self._output_active = False
diff --git a/jarvis/speech/pipeline.py b/jarvis/speech/pipeline.py
index 4b7a7ef62e..d4728fd935 100644
--- a/jarvis/speech/pipeline.py
+++ b/jarvis/speech/pipeline.py
@@ -6136,6 +6136,18 @@ class SpeechPipeline:
nonlocal semantic_turn_committed, speaking
kind = str(message.get("type", ""))
if kind == "audio_ready":
+ if speaking:
+ # A transport that just completed its handshake cannot be
+ # mid-output: an open segment here is stale state from
+ # before an in-place rebuild whose dead turn never sent
+ # its turn_complete. Left open, the echo guard feeds
+ # every microphone frame only to the local barge-in
+ # detector and the rebuilt session hears nothing
+ # (BUG-085). Drain politely first so a salvaged audio
+ # tail keeps its last words.
+ await playback.finish_turn()
+ _close_output_segment(preserve_echo_tail=True)
+ await self._set_turn_state(TurnTakingState.LISTENING)
playback.set_sample_rate(
int(message.get("output_sample_rate", 24_000) or 24_000)
)
diff --git a/tests/unit/realtime/test_session.py b/tests/unit/realtime/test_session.py
index 3468f4fbde..a79d0f3ea6 100644
--- a/tests/unit/realtime/test_session.py
+++ b/tests/unit/realtime/test_session.py
@@ -4821,6 +4821,63 @@ async def test_mid_turn_stream_end_with_capability_salvages_then_rebuilds():
await sess.end(reason="test")
+async def test_transport_rebuild_mirrors_the_frozen_turn_to_the_surface():
+ """BUG-085: a dead transport never delivers its own turn_complete, so
+ after the in-place rebuild the desktop surface stayed in its half-duplex
+ 'assistant is speaking' echo-guard state forever — every microphone frame
+ was fed only to the local barge-in detector, never uploaded, and the
+ freshly rebuilt session heard nothing (live forensic 2026-07-18 16:17:
+ Gemini's Live-API session limit aborted the connection as turn 21
+ drained; the user spoke into a swallowed microphone for 20 s). The
+ rebuild must mirror the frozen turn to the surface: one turn_complete
+ BEFORE the fresh audio_ready."""
+ provider = RebuildingProvider(
+ [
+ lambda: EndingSession(
+ [
+ RealtimeEvent(
+ type="input_transcript", text="hi", is_final=True
+ ),
+ RealtimeEvent(
+ type="output_transcript_delta", text="Hi there."
+ ),
+ RealtimeEvent(
+ type="audio_delta",
+ audio=AudioChunk(
+ pcm=b"\x01\x02" * 8,
+ sample_rate=24000,
+ timestamp_ns=0,
+ ),
+ ),
+ ]
+ ),
+ lambda: StayOpenSession([]),
+ ]
+ )
+ jsons = []
+ sess = RealtimeVoiceSession(
+ session_id="rebuild-surface-mirror",
+ send_binary=lambda _data: asyncio.sleep(0),
+ send_json=lambda m: jsons.append(m) or asyncio.sleep(0),
+ provider=provider,
+ config=_cfg(),
+ bus=None,
+ )
+ await sess.handle_control({"type": "audio_start", "sample_rate": 16_000})
+ await _wait_until(
+ lambda: len([m for m in jsons if m.get("type") == "audio_ready"]) == 2
+ )
+
+ kinds = [str(m.get("type", "")) for m in jsons]
+ # The scripted first transport dies mid-turn WITHOUT a provider
+ # turn_complete event, so the single one here must come from the rebuild.
+ assert kinds.count("turn_complete") == 1
+ second_ready = [i for i, k in enumerate(kinds) if k == "audio_ready"][1]
+ assert kinds.index("turn_complete") < second_ready
+ await sess.end(reason="test")
+
+
@pytest.mark.asyncio
async def test_transport_death_after_end_call_converts_to_hangup():
"""The user already asked to end the call (end_call acknowledged); a