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): deterministically delegate the short answer to a delegated clarify question
Ruben Lütke63fd89c93402
diff --git a/jarvis/realtime/session.py b/jarvis/realtime/session.pyindex f5a2844316..642ba057ff 100644--- a/jarvis/realtime/session.py+++ b/jarvis/realtime/session.py@@ -131,6 +131,11 @@ _DELEGATE_PENDING_DIRECTIVE = (# follow-up. The bound only decides how long a result may wait for that silence._LATE_DELEGATE_DELIVERY_TIMEOUT_S = 30.0_LATE_DELEGATE_POLL_S = 0.15+# When a delegated Brain reply ends in a question (clarify or confirmation),+# the user's short elliptical answer ("the readme one", "yes the second")+# matches no planner category on its own. Only answers up to this token count+# are pulled back to the orchestrator; a longer utterance is a new topic.+_DELEGATE_ANSWER_MAX_TOKENS = 6def _requires_jarvis_action(text: str) -> bool:@@ -366,6 +371,7 @@ class RealtimeVoiceSession:self._delegate_turns: dict[str, _DelegateTurnState] = {}self._delegate_history: list[BrainMessage] = []self._delegate_required_for_turn = False+ self._delegate_reply_awaits_answer = Falseself._late_delegate_results: list[_LateDelegateResult] = []self._late_delegate_flush_task: asyncio.Task[None] | None = Noneself._user_speech_active = False@@ -795,6 +801,7 @@ class RealtimeVoiceSession:self._delegate_required_for_turnor turn_plan.requires_orchestratoror self._brain_awaits_voice_confirm()+ or self._answers_open_delegate_question())refresh_tools = getattr(self._tool_bridge, "refresh_from_source", None@@ -1396,6 +1403,17 @@ class RealtimeVoiceSession:passif external_update is None:self._remember_delegate_turn(self._last_user_text, response_text)+ # An out-of-band update between turns must not clear an open+ # clarify question, so the flag is only re-evaluated for real+ # user turns.+ self._delegate_reply_awaits_answer = bool(+ delegate_state is not None+ and delegate_state.result_complete+ and (+ delegate_state.last_reply.rstrip().endswith("?")+ or response_text.rstrip().endswith("?")+ )+ )self._external_update = Noneself._reset_turn_tracking()@@ -1458,6 +1476,21 @@ class RealtimeVoiceSession:return _TOOL_ROLE_DIRECTIVEreturn ""+ def _answers_open_delegate_question(self) -> bool:+ """True when a short reply answers the last delegated clarify question.++ A delegated Brain turn that ended in a question owns the next short+ answer: "the readme one" carries no planner-visible category, and+ relying on the provider to call ``jarvis_action`` with it would make+ prompt compliance the correctness boundary again. A long follow-up is+ treated as a topic change and stays native.+ """+ if not self._delegate_reply_awaits_answer:+ return False+ return (+ len(self._last_user_text.split()) <= _DELEGATE_ANSWER_MAX_TOKENS+ )+def _brain_awaits_voice_confirm(self) -> bool:"""True while the classic brain holds a two-turn ask-tier confirmation.diff --git a/tests/unit/realtime/test_session.py b/tests/unit/realtime/test_session.pyindex 98673c8ee2..55fd2f96d7 100644--- a/tests/unit/realtime/test_session.py+++ b/tests/unit/realtime/test_session.py@@ -1853,6 +1853,113 @@ async def test_bare_answer_without_pending_confirm_stays_native():await sess.end(reason="test")+class _TwoTurnClarifySession(FakeSession):+ """Turn 1 delegates and asks a question; Turn 2 is the user's answer."""++ def __init__(self, second_turn_text, spoken_reply="Which trip do you mean?"):+ super().__init__([])+ self._second_turn_text = second_turn_text+ self._spoken_reply = spoken_reply+ self._text_sent = asyncio.Event()++ async def receive(self):+ yield RealtimeEvent(+ type="input_transcript",+ text="Write the travel plan to my wiki.",+ is_final=True,+ )+ await self._text_sent.wait()+ yield RealtimeEvent(+ type="output_transcript_delta",+ text=self._spoken_reply,+ is_final=True,+ )+ await asyncio.sleep(0)+ yield RealtimeEvent(type="turn_complete")+ await asyncio.sleep(0)+ yield RealtimeEvent(+ type="input_transcript",+ text=self._second_turn_text,+ is_final=True,+ )+ await asyncio.sleep(0.1)++ async def send_text(self, text):+ await super().send_text(text)+ self._text_sent.set()+++class _TwoTurnClarifyProvider(FakeProvider):+ def __init__(self, second_turn_text, spoken_reply="Which trip do you mean?"):+ super().__init__([])+ self._second_turn_text = second_turn_text+ self._spoken_reply = spoken_reply++ async def open_session(self, cfg):+ self.opened_with = cfg+ self.session = _TwoTurnClarifySession(+ self._second_turn_text, self._spoken_reply+ )+ return self.session+++async def test_short_answer_to_delegate_clarify_question_is_delegated():+ brain = FakeBrain(+ replies=("Which trip do you mean?", "Saved the San Francisco trip.")+ )+ provider = _TwoTurnClarifyProvider("The one to San Francisco")+ sess = _session(provider, brain=brain)++ await sess.handle_control({"type": "audio_start", "sample_rate": 16_000})+ await sess.wait_finished()+ await asyncio.sleep(0.12)++ assert [call[0] for call in brain.calls] == [+ "Write the travel plan to my wiki.",+ "The one to San Francisco",+ ]+ await sess.end(reason="test")+++async def test_long_follow_up_after_clarify_question_stays_native():+ brain = FakeBrain(replies=("Which trip do you mean?",))+ provider = _TwoTurnClarifyProvider(+ "Actually tell me a story about a dragon and a knight instead"+ )+ sess = _session(provider, brain=brain)++ await sess.handle_control({"type": "audio_start", "sample_rate": 16_000})+ await sess.wait_finished()+ await asyncio.sleep(0.12)++ assert [call[0] for call in brain.calls] == [+ "Write the travel plan to my wiki.",+ ]+ assert provider.session.required_tools == [None]+ await sess.end(reason="test")+++async def test_short_follow_up_without_open_question_stays_native():+ brain = FakeBrain(replies=("The travel plan was saved.",))+ provider = _TwoTurnClarifyProvider(+ "Thanks a lot", spoken_reply="The travel plan was saved."+ )+ sess = _session(provider, brain=brain)++ await sess.handle_control({"type": "audio_start", "sample_rate": 16_000})+ await sess.wait_finished()+ await asyncio.sleep(0.12)++ assert [call[0] for call in brain.calls] == [+ "Write the travel plan to my wiki.",+ ]+ assert provider.session.required_tools == [None]+ await sess.end(reason="test")++@pytest.mark.asyncioasync def test_automatic_provider_wiki_turn_runs_brain_without_tool_call():brain = FakeBrain(replies=("The Wiki entry was saved.",))