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): cut subscription action dead air
Ruben Lütkeb3bb40eb87d2
diff --git a/jarvis/brain/turn_planner.py b/jarvis/brain/turn_planner.pyindex 12b0869e07..44e9a38d9b 100644--- a/jarvis/brain/turn_planner.py+++ b/jarvis/brain/turn_planner.py@@ -246,6 +246,19 @@ _ASSISTANT_DAYPLAN_RE = re.compile(r"\bque (?:haces|estas haciendo)\b"r"(?:[^.?!]{0,24}?\b(?:hoy|manana|ahora)\b)?")++# German ASR commonly collapses the English loanword "laggt" into "legt" and+# the game noun "Spiel" shares its spelling with the imperative "spiel". Both+# are weak action matches, but inside a declarative subject phrase or a noun+# phrase they describe the conversation/game instead of asking Jarvis to act.+# Strip only those weak spans; an explicit command elsewhere in the utterance+# still routes through the orchestrator.+_GERMAN_NONCOMMAND_ACTION_SPAN_RE = re.compile(+ r"\b(?:es|das)\s+leg(?:t|te)\b|"+ r"\b(?:im|am|beim|vom|zum|das|ein|eine|dieses|" # i18n-allow: German speech-input matching data+ r"mein|dein|sein|ihr|unser|euer)\s+" # i18n-allow: German speech-input matching data+ r"spiel(?:s|e|en)?\b" # i18n-allow: German speech-input matching data+)# Calendar trivia: asking which day/weekday/date it is (today/tomorrow/...)# is answerable by the realtime model itself — the session instructions carry# the current local date — yet the time word ("morgen", "tomorrow") used to@@ -576,6 +589,7 @@ def plan_turn(# i18n-allow: names the German idiom tokens under suppressionweak_scan_text = _ASSISTANT_DAYPLAN_RE.sub(" ", normalized)weak_scan_text = _DATE_TRIVIA_RE.sub(" ", weak_scan_text)+ weak_scan_text = _GERMAN_NONCOMMAND_ACTION_SPAN_RE.sub(" ", weak_scan_text)action_intent = bool(_ACTION_FALLBACK_RE.search(weak_scan_text))if capability_registry is not None:diff --git a/jarvis/realtime/session.py b/jarvis/realtime/session.pyindex 0801e663fe..06ff5c54fc 100644--- a/jarvis/realtime/session.py+++ b/jarvis/realtime/session.py@@ -277,12 +277,14 @@ class _LoopLagProbe:)-# A realtime bridge is useful only for a genuinely long delegated turn. Starting-# a second provider response after two seconds made ordinary 5-7 second searches-# slower: the trusted result had to wait for the interim response lifecycle to-# end. Keep the classic speech-pipeline acknowledgement timing unchanged; this-# longer threshold belongs only to the realtime provider bridge.+# A realtime bridge is useful only for a genuinely long delegated turn. Providers+# with native tools can keep the longer threshold because their normal action+# path already stays inside the live model. A capability-limited provider must+# hand every action to the slower orchestrator, so waiting six seconds before it+# even acknowledges the request creates subscription-only dead air. Its earlier+# bridge is safe: ready results pre-empt the bridge lifecycle below._DELEGATE_BRIDGE_DELAY_S = 6.0+_CAPABILITY_LIMITED_DELEGATE_BRIDGE_DELAY_S = 1.0# 20 messages, not 8: a failed screen action typically costs the user several# correction turns, and each background completion adds a context note. With 8,# the original task was trimmed out exactly when the recovery turn needed it@@ -677,6 +679,8 @@ class _DelegateTurnState:dispatch_started: bool = Falsebridge_delivery_started: bool = Falsebridge_preempted: bool = False+ bridge_direct_speech: bool = False+ bridge_direct_audio_emitted: bool = False# The progress line chosen for THIS bridge run; the transcript validator# matches against it (and the closed per-language pool) so a varied line# can never smuggle free-form model output past the withhold.@@ -2604,9 +2608,24 @@ class RealtimeVoiceSession:and delegate_state.bridge_delivery_startedand not delegate_state.delivery_started):- # Pair the audio with the withheld bridge transcript. It- # is released only after exact deterministic validation.- delegate_state.bridge_audio_chunks.append(event.audio)+ if delegate_state.bridge_direct_speech:+ # The adapter guarantees that this is the exact+ # orchestrator-selected phrase, so it can stream+ # immediately instead of waiting for a completed+ # model transcript. Non-authoritative providers stay+ # on the buffered validation path below.+ if delegate_state.result_ready.is_set():+ delegate_state.bridge_preempted = True+ continue+ self._mark_latency_named("REALTIME_FIRST_AUDIO")+ self._output_active = True+ await self._emit_audio(event.audio)+ delegate_state.bridge_direct_audio_emitted = True+ else:+ # Pair model-generated audio with its withheld+ # transcript. It is released only after exact+ # deterministic validation.+ delegate_state.bridge_audio_chunks.append(event.audio)continueif self._must_withhold_provider_output():self._gate.drain()@@ -2777,8 +2796,11 @@ class RealtimeVoiceSession:)bridge_valid = bool(bridge_completed- and _normalized_bridge_text(bridge_text)- in allowed_bridge_lines+ and (+ delegate_state.bridge_direct_speech+ or _normalized_bridge_text(bridge_text)+ in allowed_bridge_lines+ ))bridge_may_speak = bool(bridge_valid@@ -2801,7 +2823,10 @@ class RealtimeVoiceSession:self.session_id,)bridge_was_audible = bool(- bridge_may_speak+ (+ bridge_may_speak+ or delegate_state.bridge_direct_audio_emitted+ )and not delegate_state.bridge_preemptedand self._output_samples_sent > 0)@@ -4959,10 +4984,15 @@ class RealtimeVoiceSession:the bridge lifecycle."""try:+ bridge_delay_s = (+ _CAPABILITY_LIMITED_DELEGATE_BRIDGE_DELAY_S+ if not bool(getattr(self._provider, "supports_direct_tools", True))+ else _DELEGATE_BRIDGE_DELAY_S+ )try:await asyncio.wait_for(turn_state.result_ready.wait(),- timeout=_DELEGATE_BRIDGE_DELAY_S,+ timeout=bridge_delay_s,)except TimeoutError:pass@@ -4974,29 +5004,48 @@ class RealtimeVoiceSession:if self._delegate_bridge_must_stand_down(turn_id, turn_state):returnsend_text = getattr(self._session, "send_text", None)- if not callable(send_text):+ send_speech = getattr(self._session, "send_speech", None)+ authoritative_speech = bool(+ callable(send_speech)+ and getattr(+ self._session,+ "direct_speech_is_authoritative",+ False,+ )+ )+ if not authoritative_speech and not callable(send_text):returnturn_state.bridge_delivery_started = Trueturn_state.bridge_preempted = False+ turn_state.bridge_direct_speech = False+ turn_state.bridge_direct_audio_emitted = Falseturn_state.bridge_expected_text = _pick_delegate_bridge_text(self._language)turn_state.bridge_transcript_parts.clear()turn_state.bridge_audio_chunks.clear()- # ``send_text`` starts a distinct provider response. The trusted- # result must wait for THIS boundary, not a boundary observed before- # the bridge began.+ # The bridge renderer starts a distinct provider response. The+ # trusted result must wait for THIS boundary, not one observed+ # before the bridge began.turn_state.provider_boundary_seen = Falseturn_state.provider_ready.clear()drop_before_bridge = self._drop_provider_output_until_new_responseself._drop_provider_output_until_new_response = Falsetry:- await send_text(- _delegate_bridge_prompt(- language=self._language,- exact_text=turn_state.bridge_expected_text,+ if authoritative_speech:+ turn_state.bridge_direct_speech = True+ self._register_spoken_reference(+ turn_state.bridge_expected_text,+ slot=f"bridge:{turn_id}",+ )+ await send_speech(turn_state.bridge_expected_text)+ else:+ await send_text(+ _delegate_bridge_prompt(+ language=self._language,+ exact_text=turn_state.bridge_expected_text,+ ))- )except Exception: # noqa: BLE001 — a broken bridge must not hurt the actionturn_state.bridge_delivery_started = Falseself._drop_provider_output_until_new_response = drop_before_bridgediff --git a/tests/unit/brain/test_turn_planner.py b/tests/unit/brain/test_turn_planner.pyindex 35b7210d44..28478156be 100644--- a/tests/unit/brain/test_turn_planner.py+++ b/tests/unit/brain/test_turn_planner.py@@ -347,6 +347,33 @@ def test_guarded_non_action_words_stay_native(utterance: str) -> None:assert plan_turn(utterance).path is TurnPath.NATIVE_REALTIME+ "utterance",+ [+ "Es legt immer noch krass.", # i18n-allow: exact German ASR fixture+ "Es laggt im Spiel immer noch krass.", # i18n-allow: German fixture+ "Das Spiel ist gut.", # i18n-allow: German speech-input fixture+ ],+)+def test_german_game_and_lag_reports_stay_native(utterance: str) -> None:+ """ASR-homophone reports must not pay the orchestrator latency penalty."""+ assert plan_turn(utterance).path is TurnPath.NATIVE_REALTIME+++ "utterance",+ [+ "Spiel Musik.", # i18n-allow: German speech-input fixture+ "Leg einen Termin an.", # i18n-allow: German speech-input fixture+ "Öffne das Spiel.", # i18n-allow: German speech-input fixture+ "Du spielst jetzt Musik.", # i18n-allow: German speech-input fixture+ "Du legst jetzt einen Termin an.", # i18n-allow: German fixture+ ],+)+def test_german_game_and_lay_commands_still_use_orchestrator(utterance: str) -> None:+ assert plan_turn(utterance).path is TurnPath.ORCHESTRATOR++@pytest.mark.parametrize("utterance",[diff --git a/tests/unit/realtime/test_session.py b/tests/unit/realtime/test_session.pyindex e8de5649d5..0b453532e6 100644--- a/tests/unit/realtime/test_session.py+++ b/tests/unit/realtime/test_session.py@@ -3147,6 +3147,77 @@ async def test_slow_deterministic_delegate_speaks_a_bridge_line(monkeypatch):await sess.end(reason="test")+async def test_capability_limited_provider_acknowledges_delegate_early(monkeypatch):+ """A capability-limited provider streams its trusted acknowledgement early."""+ monkeypatch.setattr("jarvis.realtime.session._DELEGATE_BRIDGE_DELAY_S", 60.0)+ monkeypatch.setattr(+ "jarvis.realtime.session._CAPABILITY_LIMITED_DELEGATE_BRIDGE_DELAY_S",+ 0.01,+ )+ monkeypatch.setattr(+ "jarvis.realtime.session._pick_delegate_bridge_text",+ lambda language: "I'm still working on it.",+ )++ speech_requested = asyncio.Event()+ first_audio = asyncio.Event()++ class _AuthoritativeSpeechSession(FakeSession):+ direct_speech_is_authoritative = True++ async def receive(self):+ yield RealtimeEvent(+ type="input_transcript",+ text="Write this to my wiki.",+ is_final=True,+ )+ await speech_requested.wait()+ yield RealtimeEvent(+ type="audio_delta",+ audio=AudioChunk(+ pcm=b"\x01\x00" * 240,+ sample_rate=24_000,+ timestamp_ns=0,+ ),+ )+ await asyncio.Event().wait()++ async def send_speech(self, text):+ self.text_inputs.append(text)+ speech_requested.set()++ class _CapabilityLimitedProvider(FakeProvider):+ supports_direct_tools = False++ async def open_session(self, cfg):+ self.opened_with = cfg+ self.session = _AuthoritativeSpeechSession([])+ return self.session++ class _AudioMessages(list[bytes]):+ def append(self, data: bytes) -> None:+ super().append(data)+ first_audio.set()++ gate = asyncio.Event()+ provider = _CapabilityLimitedProvider([])+ binaries = _AudioMessages()+ sess = _session(+ provider,+ brain=FakeBrain(replies=("Stored.",), gate=gate),+ binaries=binaries,+ )++ await sess.handle_control({"type": "audio_start", "sample_rate": 16_000})+ await asyncio.wait_for(first_audio.wait(), timeout=1)++ assert provider.session.text_inputs == ["I'm still working on it."]+ assert binaries+ assert sess._echo_guard.is_echo("I'm still working on it.")+ await sess.end(reason="test")++@pytest.mark.asyncioasync def test_varied_bridge_line_passes_validation_and_is_persisted(monkeypatch):"""A non-default pool line must clear the withhold and reach the record.