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 trailing silence from holding the microphone shut

rubenluetke10-beep84e52c4e9987
diff --git a/jarvis/realtime/session.py b/jarvis/realtime/session.py
index b2c02641f0..280fe2b3b9 100644
--- a/jarvis/realtime/session.py
+++ b/jarvis/realtime/session.py
@@ -6456,12 +6456,24 @@ class RealtimeVoiceSession:
except Exception: # noqa: BLE001, S110 — best-effort telemetry
pass
self._note_audio_flow(pcm, chunk)
- self._last_output_audio_at = time.monotonic()
+ # The chunk is FORWARDED either way — a live media track's embedded
+ # pauses must reach the player as real PCM or the output stream
+ # starves and the voice chops (measured 2026-08-02: six cuts in one
+ # answer). But only AUDIBLE audio may advance the liveness stamp and
+ # the echo horizon: silence cannot echo into the microphone, and
+ # stamping it as live output held the half-duplex gate deaf for the
+ # whole trailing-silence stretch after every reply (live 2026-08-04:
+ # 2-3 s of post-reply deafness per turn). Energy only, never
+ # transcript content (AP-27).
+ audible = _pcm16_peak(pcm) >= _EMBEDDED_SILENCE_PEAK
+ if audible:
+ self._last_output_audio_at = time.monotonic()
self._output_samples_sent += len(pcm) // 2
- # Real provider audio: advance the echo guard's playback horizon by
- # this chunk's audible duration (BUG-089).
rate = max(1, int(getattr(chunk, "sample_rate", 0) or 24_000))
- self._advance_echo_horizon((len(pcm) / 2) / rate)
+ if audible:
+ # Real audible provider audio: advance the echo guard's playback
+ # horizon by this chunk's duration (BUG-089).
+ self._advance_echo_horizon((len(pcm) / 2) / rate)
await self._send_binary(pcm)
def _note_audio_flow(self, pcm: bytes, chunk: Any) -> None:
diff --git a/tests/unit/realtime/test_session.py b/tests/unit/realtime/test_session.py
index 5e8d7c9bda..11d15587ac 100644
--- a/tests/unit/realtime/test_session.py
+++ b/tests/unit/realtime/test_session.py
@@ -6891,3 +6891,40 @@ async def test_a_recoverable_handshake_failure_stays_silent():
"the classic pipeline owns this call; nothing should be announced"
)
await sess.end(reason="test")
+
+
+async def test_silent_provider_audio_does_not_advance_liveness_or_echo_horizon():
+ """Embedded/trailing silence is forwarded to the player but must not be
+ stamped as live output: silence cannot echo into the microphone, and
+ dating the echo horizon forward for it held the half-duplex gate deaf for
+ seconds after every reply (live 2026-08-04)."""
+ from types import SimpleNamespace
+
+ sess = RealtimeVoiceSession(
+ session_id="s-silence-liveness",
+ send_binary=lambda _pcm: asyncio.sleep(0),
+ send_json=lambda _message: asyncio.sleep(0),
+ provider=FakeProvider([]),
+ config=_cfg(),
+ bus=None,
+ )
+ loud = SimpleNamespace(
+ pcm=(1200).to_bytes(2, "little", signed=True) * 480, sample_rate=24_000
+ )
+ quiet = SimpleNamespace(pcm=b"\x00" * 960, sample_rate=24_000)
+
+ await sess._emit_audio(loud)
+ stamped_at = sess._last_output_audio_at
+ horizon = sess._echo_playback_horizon
+ assert stamped_at > 0.0
+ assert horizon > 0.0
+
+ await sess._emit_audio(quiet)
+ assert sess._last_output_audio_at == stamped_at
+ assert sess._echo_playback_horizon == horizon
+
+ await sess._emit_audio(loud)
+ assert sess._last_output_audio_at >= stamped_at
+ assert sess._echo_playback_horizon > horizon
+ await sess.end(reason="test")