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 follow-up mic open during scrub hold
rubenluetke10-beep33a244096cf3
diff --git a/jarvis/realtime/session.py b/jarvis/realtime/session.pyindex b25c94d47f..da8e655b7b 100644--- a/jarvis/realtime/session.py+++ b/jarvis/realtime/session.py@@ -3824,8 +3824,6 @@ class RealtimeVoiceSession:if delegate_state.result_ready.is_set():delegate_state.bridge_preempted = Truecontinue- self._mark_latency_named("REALTIME_FIRST_AUDIO")- self._output_active = Trueawait self._emit_audio(event.audio)delegate_state.bridge_direct_audio_emitted = Trueelse:@@ -3838,9 +3836,6 @@ class RealtimeVoiceSession:self._note_output_withheld("audio")self._gate.drain()continue- await self._ensure_turn_started()- self._mark_latency_named("REALTIME_FIRST_AUDIO")- self._output_active = Truereleased = await self._gate.push_audio(event.audio,response_id=str(@@ -3975,6 +3970,7 @@ class RealtimeVoiceSession:and not self._surface_spoke_this_turnand not self._output_activeand self._output_samples_sent == 0+ and self._gate.pending_audio_ms <= 0):# Transcript deltas prove the answer exists, but an# audio-mode turn with zero PCM is still silent to the@@ -4121,6 +4117,7 @@ class RealtimeVoiceSession:and not self._scrub_cancelled_for_turnand not self._output_activeand self._output_samples_sent == 0+ and self._gate.pending_audio_ms <= 0):# The Brain produced a grounded answer, but the duplex# provider failed a second time while rendering it. Hand@@ -4352,7 +4349,11 @@ class RealtimeVoiceSession:if trusted_reply and not self._output_transcript:self._output_transcript.append(trusted_reply)await self._complete_surface_turn()- elif self._output_active or self._response_requested_for_turn:+ elif (+ self._output_active+ or self._response_requested_for_turn+ or self._gate.pending_audio_ms > 0+ ):final_chunks = self._gate.finalize(response_id=self._active_provider_response_id)@@ -5318,6 +5319,7 @@ class RealtimeVoiceSession:# Audio is flowing, so the transport is demonstrably alive.or self._output_activeor self._output_samples_sent > 0+ or self._gate.pending_audio_ms > 0)async def _watch_turn_for_stall(self, turn_id: str) -> None:@@ -5746,6 +5748,7 @@ class RealtimeVoiceSession:or self._last_user_textor self._output_transcriptor self._output_samples_sent+ or self._gate.pending_audio_ms > 0or self._executed_tool_names)@@ -5813,6 +5816,7 @@ class RealtimeVoiceSession:or self._scrub_cancelled_for_turnor self._output_activeor self._output_samples_sent > 0+ or self._gate.pending_audio_ms > 0or "".join(self._output_transcript).strip()or turn_id in self._delegate_turnsor self._has_pending_delegate_from_earlier_turn()@@ -8242,6 +8246,17 @@ class RealtimeVoiceSession:pcm = bytes(getattr(chunk, "pcm", b"") or b"")if not pcm:return+ if not self._output_active:+ # This method receives only scrub-cleared or explicitly trusted+ # audio. Raw provider PCM can wait in the transcript gate for+ # seconds and must not engage half-duplex before it reaches here:+ # that mismatch made desktop calls display LISTENING while silently+ # discarding the user's next question. Once a cleared stream starts,+ # its quiet onset and embedded pauses still flow verbatim so the+ # output device never starves.+ await self._ensure_turn_started()+ self._mark_latency_named("REALTIME_FIRST_AUDIO")+ self._output_active = Trueif not self._first_audio_emit_monotonic:self._first_audio_emit_monotonic = time.monotonic()start = self._audio_start_monotonic or self._created_monotonic@@ -8381,7 +8396,12 @@ class RealtimeVoiceSession:# deliberately decides nothing (the two-owner split is how the no-op# fix of 2dff5890 happened).reply_to_cut = bool(- self._output_active or self._response_requested_for_turn+ self._output_active+ or self._response_requested_for_turn+ or (+ self._gate.pending_audio_ms > 0+ and bool(self._active_provider_response_id)+ ))should_interrupt = bool(interrupt_provider and self._session is not None and reply_to_cutdiff --git a/tests/unit/realtime/test_session.py b/tests/unit/realtime/test_session.pyindex b2f29698db..8ba57da3ce 100644--- a/tests/unit/realtime/test_session.py+++ b/tests/unit/realtime/test_session.py@@ -6960,6 +6960,76 @@ async def test_subscription_capability_tuple_survives_three_turns():await sess.end(reason="test")+async def test_scrub_held_provider_audio_cannot_deafen_the_follow_up():+ """Only audio that reaches the speaker may engage half-duplex.++ ChatGPT-Live can resume an old response while its transcript is still+ missing. The scrub gate correctly holds that audio, but the session used+ to mark itself as speaking before the hold. Every microphone frame was+ then discarded even though the desktop already displayed LISTENING: the+ first turn worked and the second question vanished.+ """+ provider = SubscriptionLikeProvider([])+ binaries = []+ sess = _half_duplex_session(provider, binaries=binaries)+ await sess.handle_control({"type": "audio_start", "sample_rate": 16_000})+ session = provider.session++ await session.queue.put(+ RealtimeEvent(+ type="audio_delta",+ audio=_pcm_chunk(),+ provider_turn_id="late-response",+ )+ )+ await _wait_until(lambda: sess._gate.pending_audio_ms > 0) # noqa: SLF001++ assert binaries == []+ assert sess._output_active is False # noqa: SLF001+ assert await _microphone_reaches(sess, session), (+ "scrub-held provider audio muted the second user turn"+ )++ # A real second utterance retires the held stale response. The next response+ # is allowed to speak, and only that cleared PCM engages half-duplex.+ session.isolates_response_generations = True+ await session.queue.put(RealtimeEvent(type="speech_started"))+ await session.queue.put(+ RealtimeEvent(+ type="input_transcript",+ text="What day is tomorrow?",+ is_final=True,+ )+ )+ await session.queue.put(+ RealtimeEvent(+ type="output_transcript_delta",+ text="This is the complete answer to your question.",+ is_final=True,+ provider_turn_id="fresh-response",+ )+ )+ fresh_audio = AudioChunk(+ pcm=b"\x20\x30" * 240,+ sample_rate=24_000,+ timestamp_ns=0,+ )+ await session.queue.put(+ RealtimeEvent(+ type="audio_delta",+ audio=fresh_audio,+ provider_turn_id="fresh-response",+ )+ )+ await _wait_until(lambda: bool(binaries))+ assert binaries == [fresh_audio.pcm]+ assert sess._output_active is True # noqa: SLF001+ assert not await _microphone_reaches(sess, session)++ await sess.end(reason="test")++@pytest.mark.asyncioasync def test_a_boundary_after_a_local_completion_still_reopens_the_microphone():"""The turn-id guard used to swallow the whole reset.@@ -6979,7 +7049,11 @@ async def test_a_boundary_after_a_local_completion_still_reopens_the_microphone(RealtimeEvent(type="input_transcript", text="hello", is_final=True))await session.queue.put(- RealtimeEvent(type="output_transcript_delta", text="Hi there.")+ RealtimeEvent(+ type="output_transcript_delta",+ text="This is the complete answer to your question.",+ is_final=True,+ ))await session.queue.put(RealtimeEvent(type="audio_delta", audio=_pcm_chunk())@@ -7069,7 +7143,11 @@ async def test_the_stall_watchdog_never_fires_between_turns(monkeypatch):RealtimeEvent(type="input_transcript", text="hello", is_final=True))await session.queue.put(- RealtimeEvent(type="output_transcript_delta", text="Hi there.")+ RealtimeEvent(+ type="output_transcript_delta",+ text="This is the complete answer to your question.",+ is_final=True,+ ))await session.queue.put(RealtimeEvent(type="audio_delta", audio=_pcm_chunk())@@ -7549,7 +7627,7 @@ async def test_shadow_transcript_clears_the_gate_without_reaching_the_surface():),RealtimeEvent(type="output_transcript_delta",- text="Here is the answer.",+ text="This is the complete answer to your question.",shadow=True,),]@@ -7585,7 +7663,15 @@ async def test_a_turn_without_a_boundary_releases_the_microphone_fast() -> None:await sess.handle_control({"type": "audio_start", "sample_rate": 24_000})wire = provider.session- # Assistant audio opens the output: the microphone mutes.+ # Cleared assistant audio opens the output: the microphone mutes. Raw PCM+ # that is still awaiting a transcript deliberately stays interruptible.+ wire.queue.put_nowait(+ RealtimeEvent(+ type="output_transcript_delta",+ text="This is the complete answer to your question.",+ is_final=True,+ )+ )wire.queue.put_nowait(RealtimeEvent(type="audio_delta", audio=_pcm_chunk()))for _ in range(50):await asyncio.sleep(0.01)