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): heartbeat the pump arbitration wait + deracify the cross-family tests
Ruben Lütked40f9d731ac2
diff --git a/jarvis/realtime/session.py b/jarvis/realtime/session.pyindex 50b7abc9f1..1757a02501 100644--- a/jarvis/realtime/session.py+++ b/jarvis/realtime/session.py@@ -1433,10 +1433,23 @@ class RealtimeVoiceSession:name=f"rt-rebuild-request-{self.session_id}",)try:- done, _pending = await asyncio.wait(- {transport_task, request_task},- return_when=asyncio.FIRST_COMPLETED,- )+ while True:+ # Bounded wait, deliberately: a bare FIRST_COMPLETED+ # wait here can leave the loop with NO timer armed,+ # and on the Python 3.11 Windows proactor loop a+ # Task.cancel() landing in that state can be LOST+ # (BUG-081's general form) — the pump then survives+ # even the loop's shutdown cancel-all and the process+ # hangs in an infinite IOCP poll. The 1 s heartbeat+ # guarantees the task resumes, at which point any+ # pending cancellation is finally delivered.+ done, _pending = await asyncio.wait(+ {transport_task, request_task},+ return_when=asyncio.FIRST_COMPLETED,+ timeout=1.0,+ )+ if done:+ breakif request_task in done:target_session, detail = request_task.result()self._transport_rebuild_requests.task_done()diff --git a/tests/unit/realtime/test_session.py b/tests/unit/realtime/test_session.pyindex fb95f7539d..080e51f39a 100644--- a/tests/unit/realtime/test_session.py+++ b/tests/unit/realtime/test_session.py@@ -4928,20 +4928,29 @@ async def test_gemini_live_spending_cap_crosses_family_without_retrying():)await sess.handle_control({"type": "audio_start", "sample_rate": 16_000})- await _wait_until(lambda: openai.open_calls == 1)-- assert gemini.open_calls == 1- assert sess.active_provider == "openai-realtime"- assert not sess.failed- assert [m for m in jsons if m.get("type") == "provider_error"] == []- fallback = next(- m- for m in jsons- if m.get("type") == "provider_fallback"- and m.get("provider") == "gemini-live"- )- assert fallback["status"] == "no_credits"- await sess.end(reason="test")+ try:+ # Wait for the COMPLETED fallback (active_provider flipped), never for+ # open_calls alone: open_session returning is one await ahead of+ # _open assigning self._provider, and the py3.11 Windows CI leg lost+ # that race deterministically. The finally matters just as much — an+ # assert that fires while the pump still lives leaves a task behind+ # whose shutdown cancel can be LOST on the 3.11 proactor loop+ # (BUG-081's general form), wedging the whole job until its timeout.+ await _wait_until(lambda: sess.active_provider == "openai-realtime")++ assert gemini.open_calls == 1+ assert openai.open_calls == 1+ assert not sess.failed+ assert [m for m in jsons if m.get("type") == "provider_error"] == []+ fallback = next(+ m+ for m in jsons+ if m.get("type") == "provider_fallback"+ and m.get("provider") == "gemini-live"+ )+ assert fallback["status"] == "no_credits"+ finally:+ await sess.end(reason="test")@pytest.mark.asyncio@@ -4979,13 +4988,18 @@ async def test_openai_insufficient_quota_event_crosses_to_gemini():)await sess.handle_control({"type": "audio_start", "sample_rate": 16_000})- await _wait_until(lambda: gemini.open_calls == 1)-- assert openai.open_calls == 1- assert sess.active_provider == "gemini-live"- assert not sess.failed- assert [m for m in jsons if m.get("type") == "provider_error"] == []- await sess.end(reason="test")+ try:+ # Same discipline as the gemini-cap test above: wait for the+ # completed flip, and always end the session even when an assert+ # fires, so no live pump task survives into loop teardown.+ await _wait_until(lambda: sess.active_provider == "gemini-live")++ assert openai.open_calls == 1+ assert gemini.open_calls == 1+ assert not sess.failed+ assert [m for m in jsons if m.get("type") == "provider_error"] == []+ finally:+ await sess.end(reason="test")@pytest.mark.asyncio