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): a model can never hang up unless the user asked to
rubenluetke10-beepd5cc38c2875c
diff --git a/jarvis/live/tools.py b/jarvis/live/tools.pyindex 1543e18f83..795934acc8 100644--- a/jarvis/live/tools.py+++ b/jarvis/live/tools.py@@ -247,15 +247,22 @@ class LiveTools:return {"success": False, "error": "Tool arguments must be an object."}name, args = str(args["name"]), innerif name == "end_call":- if self._pending and self._affirmation_locale() is not None:+ from jarvis.speech.hangup import user_asked_to_hang_up++ if not user_asked_to_hang_up(self.user_text):# Live 2026-10-01: after "Ja" to a pending approval the model# called end_call instead of confirm_action and the call dropped.- return {+ refusal: dict = {"success": False,- "error": "The user approved a pending action; they did not ask to hang up.",- "approval_ids": list(self._pending),- "next_step": "Call confirm_action with the approval_id.",+ "error": "The user did not ask to hang up. Stay on the call.",}+ if self._pending:+ refusal["approval_ids"] = list(self._pending)+ refusal["next_step"] = (+ "If the user approved, call confirm_action with the approval_id."+ )+ log.info("Live end_call refused: the user's turn holds no hang-up request")+ return refusalself.end_requested = Truereturn {"success": True, "status": "closing_voice"}if name == "discover_tools":diff --git a/jarvis/realtime/session.py b/jarvis/realtime/session.pyindex d8a0887c3a..b5fb0487f7 100644--- a/jarvis/realtime/session.py+++ b/jarvis/realtime/session.py@@ -11642,6 +11642,33 @@ class RealtimeVoiceSession:)async def _handle_end_call(self, event: Any) -> None:+ from jarvis.speech.hangup import user_asked_to_hang_up++ if not user_asked_to_hang_up(self._last_user_text):+ # A model tool call alone never ends the call (live 2026-10-01:+ # "Ja" to an approval became end_call). An explicit command that+ # arrives after a speculative call still ends it via HANGUP_RE.+ log.info(+ "realtime[%s] end_call refused: the user's turn holds no hang-up request",+ self.session_id,+ )+ if self._session is not None and self._session_takes_tool_results():+ try:+ await self._session.send_tool_result(+ str(getattr(event, "call_id", "") or ""),+ "end_call",+ {+ "success": False,+ "error": "The user did not ask to hang up. Stay on the call.",+ },+ )+ except Exception: # noqa: BLE001 — the call simply stays open+ log.warning(+ "realtime[%s] end_call refusal could not be sent",+ self.session_id,+ exc_info=True,+ )+ returnif self._session is not None and self._session_takes_tool_results():try:await self._session.send_tool_result(diff --git a/jarvis/speech/hangup.py b/jarvis/speech/hangup.pyindex 9df876d126..5849d243a3 100644--- a/jarvis/speech/hangup.py+++ b/jarvis/speech/hangup.py@@ -147,10 +147,13 @@ _SEMANTIC_CLOSING_RE = re.compile(r"|i (?:have|need) to go|let's stop here|you can go now"r"|wir sind (?:durch|fertig)(?: für heute)?" # i18n-allowr"|ich bin (?:durch|fertig)(?: für heute)?" # i18n-allow- r"|das war'?s(?: für heute)?|das ist alles|mehr brauche ich nicht" # i18n-allow+ r"|das war'?s(?: für heute)?|das war alles(?: für heute)?" # i18n-allow+ r"|das ist alles|mehr brauche ich nicht" # i18n-allow+ r"|that'?s it(?: for (?:now|today))?"r"|keine weiteren fragen|ich muss (?:los|gehen)|du kannst gehen" # i18n-allowr"|eso es todo(?: por (?:ahora|hoy))?|hemos terminado|ya terminamos"r"|no necesito nada más|no tengo más preguntas|me tengo que ir"+ r"|cuelga|adiós|adios|hasta luego"r")"r"(?:[\s,.!]+(?:thanks|thank you|danke|gracias|jarvis))*[\s.!]*", # i18n-allowre.IGNORECASE,@@ -168,6 +171,19 @@ def supports_semantic_hangup(user_text: str | None) -> bool:return _SEMANTIC_CLOSING_RE.fullmatch(text) is not None+def user_asked_to_hang_up(user_text: str | None) -> bool:+ """Gate for a model's ``end_call``: the user's own words must ask for it.++ A model tool call alone never ends a call. Live 2026-10-01: the user+ answered "Ja" to an approval and the model called end_call, dropping the+ call and the approved task. A missed hang-up costs one repeat; a false one+ kills the session, so only an explicit command or a complete closing+ speech act counts.+ """+ text = user_text or ""+ return bool(HANGUP_RE.search(text)) or supports_semantic_hangup(text)++def strip_end_signal(text: str | None) -> str:"""Remove the sentinel and trim surrounding whitespace.@@ -211,4 +227,5 @@ __all__ = ["matched_hangup_pattern","strip_end_signal","supports_semantic_hangup",+ "user_asked_to_hang_up",]diff --git a/tests/unit/realtime/test_session.py b/tests/unit/realtime/test_session.pyindex 3d3d81946a..5894a2f6ee 100644--- a/tests/unit/realtime/test_session.py+++ b/tests/unit/realtime/test_session.py@@ -1992,6 +1992,39 @@ async def test_end_call_tool_finishes_after_turn_complete():assert turn_completes, "the model finishes its goodbye before the hang-up"+async def test_end_call_after_a_plain_yes_is_refused():+ # Live 2026-10-01: the user approved an action with "Ja" and the model+ # called end_call. A model tool call alone must never end the call.+ provider = FakeProvider(+ [+ RealtimeEvent(type="input_transcript", text="Ja", is_final=True),+ RealtimeEvent(type="tool_call", call_id="c-end", tool_name="end_call"),+ RealtimeEvent(type="output_transcript_delta", text="Okay."),+ RealtimeEvent(type="turn_complete"),+ ]+ )+ jsons = []+ sess = RealtimeVoiceSession(+ session_id="no-hangup-on-yes",+ send_binary=lambda _data: asyncio.sleep(0),+ send_json=lambda m: jsons.append(m) or asyncio.sleep(0),+ provider=provider,+ config=_cfg(),+ bus=None,+ tool_bridge=FakeToolBridge(),+ )++ await sess.handle_control({"type": "audio_start", "sample_rate": 16_000})+ await asyncio.sleep(0.3)++ refusals = [r for r in provider.session.tool_results if r[0] == "c-end"]+ assert refusals and refusals[0][2]["success"] is False+ assert sess.hangup_reason != "voice_pattern"+ assert not _hangup_jsons(jsons)+ await sess.end(reason="client_stop")++@pytest.mark.asyncioasync def test_ordinary_speech_does_not_hang_up(monkeypatch):monkeypatch.setattr(diff --git a/tests/unit/speech/test_hangup.py b/tests/unit/speech/test_hangup.pyindex 885386dedf..f6c41b59cf 100644--- a/tests/unit/speech/test_hangup.py+++ b/tests/unit/speech/test_hangup.py@@ -11,6 +11,7 @@ from jarvis.speech.hangup import (is_legacy_farewell,strip_end_signal,supports_semantic_hangup,+ user_asked_to_hang_up,)@@ -171,3 +172,20 @@ def test_semantic_closure_requires_positive_user_evidence(text: str) -> None:])def test_task_completion_and_quoted_closings_are_not_session_closure(text: str) -> None:assert not supports_semantic_hangup(text)++[email protected]("text", [+ "Leg auf", "auflegen bitte", "Tschüss Jarvis", "hang up", "Goodbye", # i18n-allow+ "Danke, das war alles", "That's it for today", "Cuelga", "Adiós", # i18n-allow+])+def test_end_call_gate_accepts_the_users_own_closing(text: str) -> None:+ assert user_asked_to_hang_up(text)++[email protected]("text", [+ "", None, "Ja", "Ja.", "Yes", "Sí", "Okay", "Alles klar", "Mach das", # i18n-allow+ "Danke", "Thanks", "Hey George, hallo", # i18n-allow+])+def test_end_call_gate_refuses_a_model_hang_up_without_user_evidence(text) -> None:+ # Live 2026-10-01: the model answered a spoken "Ja" with end_call.+ assert not user_asked_to_hang_up(text)