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): a heard cough keeps its answer window, and a corpse cannot stall the rebuild
rubenluetke10-beep6cd5f55b54b3
diff --git a/jarvis/plugins/realtime/codex_subscription.py b/jarvis/plugins/realtime/codex_subscription.pyindex 0690fd1239..bcf9c2fa69 100644--- a/jarvis/plugins/realtime/codex_subscription.py+++ b/jarvis/plugins/realtime/codex_subscription.py@@ -48,6 +48,13 @@ _OPENING_RESPONSE_MAX_S = 6.0# 2.4 s of the question survived and the server answered a fragment). The# model may say "hey", not a paragraph, over a speaking user._OPENING_OVERLAP_MAX_S = 2.0+# A locally DISCARDED utterance (under the endpointer's minimum voiced+# length) keeps its response window this long. The far end heard the sound+# regardless of the local verdict and often answers it; consuming the+# generation at the discard instant refused that answer as ungrounded and+# cut it (the BUG-124 amplifier). Expired lazily - a window nobody answers+# retires on the next authorization check.+_DISCARDED_UTTERANCE_GRACE_S = 4.0# How long after the last audible provider frame a further frame still counts# as the REST of the same answer rather than a new response.#@@ -820,6 +827,11 @@ class _CodexSubscriptionRealtimeSession:# keeps its entitlement, but nothing speaks on it until a FINAL# exists (or the user audibly starts over).opening_bound_cut = False+ # A discarded utterance's still-open response window (see+ # _DISCARDED_UTTERANCE_GRACE_S): the generation it covers and when+ # the discard happened.+ discarded_generation = 0+ discarded_at = 0.0# The grounded utterance whose answer may still be streaming, and# whether the far end has since proven that answer ended. Together# with the last audible frame they decide whether a frame arriving@@ -922,7 +934,24 @@ class _CodexSubscriptionRealtimeSession:shadow_task.cancel()shadow_task = None+ def _expire_discarded_grace() -> None:+ """Retire a discarded utterance's window once nobody answered it."""+ nonlocal consumed_input_generation, discarded_generation+ if discarded_generation and discarded_generation <= consumed_input_generation:+ discarded_generation = 0+ return+ if (+ discarded_generation+ and asyncio.get_running_loop().time() - discarded_at+ > _DISCARDED_UTTERANCE_GRACE_S+ ):+ consumed_input_generation = max(+ consumed_input_generation, discarded_generation+ )+ discarded_generation = 0+def _fresh_local_input_exists() -> bool:+ _expire_discarded_grace()return bool(not self._local_grounding_active()or local_input_generation > consumed_input_generation@@ -987,6 +1016,7 @@ class _CodexSubscriptionRealtimeSession:nonlocal sequence_boundary_pendingnonlocal response_grant, call_response_indexnonlocal silent_line_noted+ _expire_discarded_grace()if response_open:if response_allowed or not _rejected_response_is_stale():return response_allowed@@ -1576,13 +1606,18 @@ class _CodexSubscriptionRealtimeSession:# far end's preview either, which is the fallback for# the REAL utterance around it, nor leave the turn that# ``speech_started`` already announced hanging open.+ # The far end HEARD the sound whatever the local+ # verdict says, so its answer keeps a bounded window+ # instead of being refused on the spot (the BUG-124+ # amplifier: a 200 ms "hm?" got its real answer cut).user_utterance_open = False- consumed_input_generation = max(- consumed_input_generation, local_input_generation- )+ discarded_generation = local_input_generation+ discarded_at = asyncio.get_running_loop().time()log.debug(- "Local endpointer discarded a %d ms utterance; it grounds no response",+ "Local endpointer discarded a %d ms utterance; "+ "its response window stays open %.1f s",int(getattr(payload, "voiced_ms", 0) or 0),+ _DISCARDED_UTTERANCE_GRACE_S,)if not response_open and not completion_emitted:completion_emitted = Truediff --git a/jarvis/realtime/session.py b/jarvis/realtime/session.pyindex be0cd9926e..25e7960913 100644--- a/jarvis/realtime/session.py+++ b/jarvis/realtime/session.py@@ -3936,7 +3936,19 @@ class RealtimeVoiceSession:if old_session is not None:self._harvest_adapter_diagnostics(old_session)try:- await old_session.close()+ # Bounded like end()'s close: a dead codex socket took the+ # full close window live (2026-08-06 17:42, "provider close+ # timed out") and an unbounded await here stalls the WHOLE+ # rebuild the call is waiting on.+ await asyncio.wait_for(+ old_session.close(), timeout=_PROVIDER_CLOSE_BOUND_S+ )+ except TimeoutError:+ log.warning(+ "realtime[%s] provider close timed out during the "+ "transport rebuild; abandoning the dead socket",+ self.session_id,+ )except Exception: # noqa: BLE001, S110 — the transport is already deadpass# Freeze whatever the dead transport left of the open turn into thediff --git a/tests/integration/realtime/scenarios/barge_in_followup.json b/tests/integration/realtime/scenarios/barge_in_followup.jsonindex aa8c98a0f2..40389e55d7 100644--- a/tests/integration/realtime/scenarios/barge_in_followup.json+++ b/tests/integration/realtime/scenarios/barge_in_followup.json@@ -2,12 +2,37 @@"name": "barge_in_followup","description": "Reviewer checklist item 1: interrupt a running answer, ask a follow-up, and the follow-up must be answered (the speech-edge/entitlement regression class).","steps": [- {"speak": "en_zebrastorm"},- {"barge_in": {"after_reply_ms": 700, "then_speak": "en_giraffe"}},- {"wait_reply": {"timeout_s": 20}},- {"speak": "en_glimmerpond"},- {"wait_reply": {"timeout_s": 20}},- {"end": {}}+ {+ "silence_s": 1.0+ },+ {+ "speak": "en_zebrastorm"+ },+ {+ "barge_in": {+ "after_reply_ms": 700,+ "then_speak": "en_giraffe"+ }+ },+ {+ "wait_reply": {+ "timeout_s": 20+ }+ },+ {+ "silence_s": 0.75+ },+ {+ "speak": "en_glimmerpond"+ },+ {+ "wait_reply": {+ "timeout_s": 20+ }+ },+ {+ "end": {}+ }],"asserts": ["turns>=2",diff --git a/tests/integration/realtime/scenarios/delegation.json b/tests/integration/realtime/scenarios/delegation.jsonindex 0eb2047f8b..680b47d594 100644--- a/tests/integration/realtime/scenarios/delegation.json+++ b/tests/integration/realtime/scenarios/delegation.json@@ -2,11 +2,31 @@"name": "delegation","description": "Opt-in (needs --with-delegate): one action-shaped request must dispatch a delegation and speak its result without killing the call. Reviewer checklist item 2.","steps": [- {"speak": "en_giraffe"},- {"wait_reply": {"timeout_s": 20}},- {"speak": "en_tandelbrook"},- {"wait_reply": {"timeout_s": 30}},- {"end": {}}+ {+ "silence_s": 1.0+ },+ {+ "speak": "en_giraffe"+ },+ {+ "wait_reply": {+ "timeout_s": 20+ }+ },+ {+ "silence_s": 0.75+ },+ {+ "speak": "en_tandelbrook"+ },+ {+ "wait_reply": {+ "timeout_s": 30+ }+ },+ {+ "end": {}+ }],"asserts": ["turns>=2",diff --git a/tests/integration/realtime/scenarios/split_reply_pause.json b/tests/integration/realtime/scenarios/split_reply_pause.jsonindex bf1b4c5da5..c34a72dff9 100644--- a/tests/integration/realtime/scenarios/split_reply_pause.json+++ b/tests/integration/realtime/scenarios/split_reply_pause.json@@ -2,11 +2,31 @@"name": "split_reply_pause","description": "A prompt that invites a longer, pause-bearing answer: generation pauses beyond the 1.2s backstop must not produce audible seams or splices (Fix E's live guard).","steps": [- {"speak": "en_zebrastorm"},- {"wait_reply": {"timeout_s": 25}},- {"speak": "de_fahrrad"},- {"wait_reply": {"timeout_s": 25}},- {"end": {}}+ {+ "silence_s": 1.0+ },+ {+ "speak": "en_zebrastorm"+ },+ {+ "wait_reply": {+ "timeout_s": 25+ }+ },+ {+ "silence_s": 0.75+ },+ {+ "speak": "de_fahrrad"+ },+ {+ "wait_reply": {+ "timeout_s": 25+ }+ },+ {+ "end": {}+ }],"asserts": ["turns>=2",diff --git a/tests/integration/realtime/scenarios/three_turns_de.json b/tests/integration/realtime/scenarios/three_turns_de.jsonindex 135ddfbec6..dd24ce6b51 100644--- a/tests/integration/realtime/scenarios/three_turns_de.json+++ b/tests/integration/realtime/scenarios/three_turns_de.json@@ -2,13 +2,42 @@"name": "three_turns_de","description": "The headline multi-turn guard: two German turns, then one English turn, each answered. Pins the 50% one-turn death rate at zero.","steps": [- {"speak": "de_giraffe"},- {"wait_reply": {"timeout_s": 20}},- {"speak": "de_tandelbrook"},- {"wait_reply": {"timeout_s": 20}},- {"speak": "en_bicycle"},- {"wait_reply": {"timeout_s": 20}},- {"end": {}}+ {+ "silence_s": 1.0+ },+ {+ "speak": "de_giraffe"+ },+ {+ "wait_reply": {+ "timeout_s": 20+ }+ },+ {+ "silence_s": 0.75+ },+ {+ "speak": "de_tandelbrook"+ },+ {+ "wait_reply": {+ "timeout_s": 20+ }+ },+ {+ "silence_s": 0.75+ },+ {+ "speak": "en_bicycle"+ },+ {+ "wait_reply": {+ "timeout_s": 20+ }+ },+ {+ "end": {}+ }],"asserts": ["turns>=3",diff --git a/tests/integration/realtime/test_codex_multi_turn.py b/tests/integration/realtime/test_codex_multi_turn.pyindex 5bf91d829b..abca2072c3 100644--- a/tests/integration/realtime/test_codex_multi_turn.py+++ b/tests/integration/realtime/test_codex_multi_turn.py@@ -688,3 +688,73 @@ async def test_a_dead_local_recognizer_still_lets_the_assistant_answer() -> Noneawait _assert_at_rest(session, wire, note="after the turn following a failure")finally:await _end(session)+++async def test_a_hanging_close_does_not_stall_the_transport_rebuild(+ monkeypatch: pytest.MonkeyPatch,+) -> None:+ """The dead transport's socket close took its full window live+ (2026-08-06 17:42) - and the rebuild the call was waiting on stalled+ behind it. The close is a courtesy to a corpse: bounded, then abandoned.+ """+ monkeypatch.setattr(session_mod, "_PROVIDER_CLOSE_BOUND_S", 0.2)++ class _HangingCloseWire(_CodexShapedWire):+ async def close(self) -> None:+ await asyncio.sleep(30.0)++ class _RebuildingProvider(_CodexShapedProvider):+ def __init__(self) -> None:+ super().__init__()+ self.open_count = 0++ async def open_session(self, config: Any) -> _CodexShapedWire:+ self.opened_with = config+ self.open_count += 1+ wire = (+ _HangingCloseWire() if self.open_count == 1 else _CodexShapedWire()+ )+ self.sessions.append(wire)+ return wire++ surface = _Surface()+ provider = _RebuildingProvider()+ session = RealtimeVoiceSession(+ session_id="rebuild-close-bound",+ send_binary=surface.send_binary,+ send_json=surface.send_json,+ providers=[provider],+ config=_config(),+ bus=EventBus(),+ surface="desktop",+ half_duplex=True,+ browser_sample_rate=INPUT_RATE,+ )+ await asyncio.wait_for(+ session.handle_control({"type": "audio_start", "sample_rate": INPUT_RATE}),+ TIMEOUT_S,+ )+ try:+ first_wire = provider.sessions[0]+ since = surface.mark()+ first_wire.push(+ RealtimeEvent(+ type="error",+ error="transport died",+ recoverable=True,+ reconnect_advised=True,+ ),+ RealtimeEvent(type="turn_complete"),+ )+ # The rebuild must complete despite the corpse's 30 s close: a fresh+ # audio_ready proves the new transport opened.+ ready = await surface.wait_json(+ lambda m: m.get("type") == "audio_ready",+ since=since,+ timeout_s=TIMEOUT_S,+ )+ assert ready is not None+ assert provider.open_count == 2, "a second transport must have opened"+ finally:+ await _end(session)diff --git a/tests/unit/realtime/test_codex_subscription.py b/tests/unit/realtime/test_codex_subscription.pyindex 6eeaa10fba..ef247944d3 100644--- a/tests/unit/realtime/test_codex_subscription.py+++ b/tests/unit/realtime/test_codex_subscription.py@@ -3214,3 +3214,102 @@ async def test_a_final_landing_mid_opening_adopts_the_response(audio_events = [e for e in events if e.type == "audio_delta"]assert len(audio_events) == 4, "all audio flowed, none was refused"await session.close()+++async def test_a_discarded_utterance_keeps_its_response_window(+ monkeypatch,+) -> None:+ """The far end hears a 200 ms "hm?" whatever the local endpointer decides,+ and it answers. Consuming the generation at the discard instant refused+ that answer and cut it (the BUG-124 amplifier); within the grace it now+ plays - and after the grace an unanswered window retires."""+ transcriber = _ScheduledInputTranscriber(+ [+ (0.02, InputTranscriptEvent(kind="speech_started")),+ (+ 0.03,+ InputTranscriptEvent(kind="speech_discarded", voiced_ms=200),+ ),+ ]+ )+ client = _Client()+ client.subscription = _ScheduledSubscription(+ [+ (+ 0.2,+ _Notification(+ "thread/realtime/transcript/delta",+ {+ "threadId": "thread-1",+ "role": "assistant",+ "delta": "Did you say something?",+ },+ ),+ ),+ ]+ )+ session = await _provider(+ client, input_transcriber_factory=lambda: transcriber+ ).open_session(RealtimeSessionConfig())++ events = await _collect_until(+ session, stop_after=1, kind="output_transcript_delta", timeout_s=2.0+ )+ delivered = [+ event.text+ for event in events+ if event.type == "output_transcript_delta"+ ]+ assert delivered == ["Did you say something?"], (+ "the answer to a heard-but-discarded sound must play inside the grace"+ )+ await session.close()+++async def test_an_unanswered_discard_window_expires(monkeypatch) -> None:+ monkeypatch.setattr(+ codex_subscription_mod, "_DISCARDED_UTTERANCE_GRACE_S", 0.05+ )+ transcriber = _ScheduledInputTranscriber(+ [+ (0.02, InputTranscriptEvent(kind="speech_started")),+ (+ 0.03,+ InputTranscriptEvent(kind="speech_discarded", voiced_ms=200),+ ),+ ]+ )+ client = _Client()+ client.subscription = _ScheduledSubscription(+ [+ (+ 0.4,+ _Notification(+ "thread/realtime/transcript/delta",+ {+ "threadId": "thread-1",+ "role": "assistant",+ "delta": "A late invented answer.",+ },+ ),+ ),+ ]+ )+ session = await _provider(+ client, input_transcriber_factory=lambda: transcriber+ ).open_session(RealtimeSessionConfig())++ events = await _collect_until(+ session, stop_after=1, kind="output_transcript_delta", timeout_s=1.5+ )+ delivered = [+ event.text+ for event in events+ if event.type == "output_transcript_delta"+ ]+ assert delivered == [], (+ "past the grace a discarded utterance grounds nothing"+ )+ await session.close()