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(voice): re-arm a fresh idle window after a slow off-loop answer
Ruben Lütke8d35674e473c
diff --git a/jarvis/speech/pipeline.py b/jarvis/speech/pipeline.pyindex 367ec4a080..07605b55ef 100644--- a/jarvis/speech/pipeline.py+++ b/jarvis/speech/pipeline.py@@ -1265,6 +1265,17 @@ class SpeechPipeline:# window while within this grace. Bounded — one full window's worth.self._last_announcement_spoken_monotonic: float | None = Noneself._post_readback_grace_s: float = idle_timeout_s+ # Monotonic timestamp of the moment Jarvis last STOPPED speaking an+ # inline answer (SPEAKING -> LISTENING). A long turn dispatched OFF the+ # ``_active_session`` loop — the delegation grace / completion timer buffers+ # a complete-looking command and answers it ~24 s later — leaves the idle+ # window that was armed at the user's utterance still ticking through the+ # whole turn, so it expires seconds after the answer lands and hangs up on+ # a user who never asked to (forensic 2026-06-27 08:49: a "switch the+ # worker" command answered after ~24 s; the 30 s window armed at the+ # utterance expired 6 s later). The idle-expiry branch grants ONE fresh+ # window while within this grace (== one idle window).+ self._last_answer_floor_monotonic: float | None = Noneself._post_tts_listen_suppression_s = post_tts_listen_suppression_sself._input_suppressed_until_ns: int = 0self._continue_listening_after_response = continue_listening_after_response@@ -1665,6 +1676,15 @@ class SpeechPipeline:previous = getattr(self, "_turn_state", TurnTakingState.IDLE)if previous != new_state:log.info("turn-state: %s -> %s", previous.value, new_state.value)+ # Jarvis just STOPPED speaking → the floor goes back to the user. Stamp it+ # so the idle loop can grant a fresh listening window even when the turn+ # ran off the main loop (delegation grace / completion timer) and left the+ # original idle window ticking (forensic 2026-06-27 08:49).+ if (+ previous == TurnTakingState.JARVIS_SPEAKING+ and new_state == TurnTakingState.LISTENING+ ):+ self._last_answer_floor_monotonic = time.monotonic()self._turn_state = new_stateawait self._transition(self._supervisor_state_for_turn(new_state))# Turn-boundary: the floor has cleared → flush any announcements that@@ -1683,6 +1703,15 @@ class SpeechPipeline:self._on_announcement(event), name="deferred-announcement")+ def _within_post_answer_grace(self) -> bool:+ """True if Jarvis stopped speaking within the last idle window. The idle+ loop grants ONE fresh listening window so a slow answer dispatched off+ this loop is not hung up on seconds after it lands (forensic 2026-06-27).+ Bounded: after the re-armed window elapses the stamp is older than one+ idle window and normal idle-timeout resumes."""+ last = self._last_answer_floor_monotonic+ return last is not None and (time.monotonic() - last) < self._idle_timeout_s+@staticmethoddef _supervisor_state_for_turn(state: TurnTakingState) -> str:if state == TurnTakingState.IDLE:@@ -4064,6 +4093,7 @@ class SpeechPipeline:self._last_endpoint_reason = None# A fresh session never inherits a previous session's readback grace.self._last_announcement_spoken_monotonic = None+ self._last_answer_floor_monotonic = Noneif self._ptt_mode:return await self._ptt_session()async with MicrophoneCapture(device=self._input_device) as mic:@@ -4144,6 +4174,20 @@ class SpeechPipeline:"user can respond.")continue+ # A normal/inline answer — or one dispatched OFF this loop+ # via the delegation grace / completion timer — just handed+ # the floor back to the user. The idle window armed at the+ # user's utterance ticked down DURING the (slow) turn, so+ # re-arm one fresh window instead of hanging up seconds after+ # the answer lands (forensic 2026-06-27 08:49). Bounded: the+ # stamp is cleared, so the next idle window hangs up normally.+ if self._within_post_answer_grace():+ log.info(+ "Idle-Timeout reached right after Jarvis answered - "+ "re-arming a fresh window so the user can respond."+ )+ self._last_answer_floor_monotonic = None+ continuelog.info("⏲ Idle-Timeout — lege auf.")next_task.cancel()return HANGUP_IDLE_TIMEOUTdiff --git a/tests/unit/speech/test_idle_rearm_after_slow_answer.py b/tests/unit/speech/test_idle_rearm_after_slow_answer.pynew file mode 100644index 0000000000..36dfaf3abb--- /dev/null+++ b/tests/unit/speech/test_idle_rearm_after_slow_answer.py@@ -0,0 +1,84 @@+"""A slow answer must not be hung up on seconds after it lands.++Forensic 2026-06-27 08:49: a voice "switch the worker from antigravity to codex"+was buffered by the delegation grace and dispatched off the main loop (the+completion timer). The whole ~24 s turn (think + speak) therefore ran ALONGSIDE+the idle window that was armed at the user's utterance, so the 30 s window+expired 6 s after Jarvis finished — the session hung up before the user could+respond. "Only with CLI" because tool turns are the slow ones.++Fix: stamp the moment Jarvis stops speaking (SPEAKING -> LISTENING) and let the+idle loop grant ONE fresh window while within that grace.+"""+from __future__ import annotations++import time+from collections.abc import AsyncIterator+from dataclasses import dataclass, field++import pytest++from jarvis.core.bus import EventBus+from jarvis.core.protocols import AudioChunk+from jarvis.speech.pipeline import SpeechPipeline, TurnTakingState+++@dataclass+class FakeTTS:+ name: str = "fake-tts"+ supports_streaming: bool = True+ calls: list[tuple[str, str | None]] = field(default_factory=list)++ async def synthesize(+ self, text: str, voice: str | None = None,+ language_code: str | None = None,+ ) -> AsyncIterator[AudioChunk]:+ self.calls.append((text, language_code))+ if False: # pragma: no cover+ yield # type: ignore[unreachable]+++def _pipeline() -> SpeechPipeline:+ return SpeechPipeline(tts=FakeTTS(), bus=EventBus(), enable_whisper_wake=False)+++async def test_speaking_to_listening_stamps_answer_floor() -> None:+ pipe = _pipeline()+ pipe._last_answer_floor_monotonic = None+ await pipe._set_turn_state(TurnTakingState.JARVIS_SPEAKING)+ await pipe._set_turn_state(TurnTakingState.LISTENING)+ assert pipe._last_answer_floor_monotonic is not None+++async def test_other_transitions_do_not_stamp_answer_floor() -> None:+ # Going to LISTENING from a non-speaking state (e.g. session start) is not a+ # finished answer — no fresh-window grace owed.+ pipe = _pipeline()+ pipe._last_answer_floor_monotonic = None+ await pipe._set_turn_state(TurnTakingState.IDLE)+ await pipe._set_turn_state(TurnTakingState.LISTENING)+ assert pipe._last_answer_floor_monotonic is None+++def test_within_post_answer_grace_true_right_after_answer() -> None:+ pipe = _pipeline()+ pipe._idle_timeout_s = 30.0+ pipe._last_answer_floor_monotonic = time.monotonic()+ assert pipe._within_post_answer_grace() is True+++def test_within_post_answer_grace_false_without_answer() -> None:+ pipe = _pipeline()+ pipe._idle_timeout_s = 30.0+ pipe._last_answer_floor_monotonic = None+ assert pipe._within_post_answer_grace() is False+++def test_within_post_answer_grace_false_after_window_elapsed() -> None:+ pipe = _pipeline()+ pipe._idle_timeout_s = 30.0+ # Answer finished well over one idle window ago → no more grace.+ pipe._last_answer_floor_monotonic = time.monotonic() - 31.0+ assert pipe._within_post_answer_grace() is False