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): keep the session open while a yes/no confirmation is pending
Ruben Lütke1994b7bac673
diff --git a/jarvis/brain/manager.py b/jarvis/brain/manager.pyindex c0f496ec53..fc2c1b6648 100644--- a/jarvis/brain/manager.py+++ b/jarvis/brain/manager.py@@ -655,6 +655,47 @@ def _is_instructional_question(user_text: str) -> bool:return bool(_INSTRUCTIONAL_QUESTION_RE.search(user_text or ""))+# Definitional "what IS X" guard for the deterministic skill match. A plugin+# skill's voice trigger is an un-anchored bare-name pattern (e.g. ``(github|…)``)+# that fires on ANY mention — including when the app is merely the SUBJECT of a+# knowledge question ("was ist GitHub?", "what is Stripe?"). Such a turn must be+# ANSWERED, not captured by the skill (live skill-routing eval 2026-06-24: both+# negative controls over-fired here). Precision over recall: suppress ONLY when+# the matched trigger token is the predicate of a copula in a definitional+# opener — so a real data request that merely starts with "was ist" ("was ist+# in meinem Posteingang?", token "posteingang") is NOT suppressed, because there+# the token does not sit directly after the copula (the "in"/"mein" data context+# breaks the predicate run).+_DEFINITIONAL_OPENER_RE = re.compile(+ r"^\s*(?:was\s+(?:ist|sind|bedeutet|war|waren)"+ r"|wof[üu]r\s+(?:ist|steht|braucht|nutzt|benutzt|verwendet)"+ r"|erkl[äa]r(?:e|st|en)?\b"+ r"|what(?:'s|\s+is|\s+are|\s+does)\b"+ r"|tell\s+me\s+(?:about|what)\b"+ r")",+ re.IGNORECASE,+)+# Copula → (optional adverb, but NOT a data-context word) → optional article →+# the matched token. ``%s`` is filled with the re.escape'd trigger token.+_DEFINITIONAL_PREDICATE_TMPL = (+ r"\b(?:ist|sind|war|waren|is|are|was|were|bedeutet|means)\s+"+ r"(?:(?!\b(?:in|auf|an|aus|von|mein|meine|meinem|meinen|my|on|from|of)\b)"+ r"\w+\s+){0,2}"+ r"(?:ein(?:e|er|en)?\s+|a\s+|an\s+|the\s+)?%s\b"+)+++def _is_definitional_question_about(user_text: str, token: str) -> bool:+ """True when ``user_text`` is a definitional question whose subject IS the+ matched trigger ``token`` — so firing that skill would be wrong."""+ if not user_text or not token:+ return False+ if not _DEFINITIONAL_OPENER_RE.match(user_text):+ return False+ pat = re.compile(_DEFINITIONAL_PREDICATE_TMPL % re.escape(token), re.IGNORECASE)+ return bool(pat.search(user_text))++# Opinion / advice / recommendation / decision questions, and casual# question-openers ("ich hab da mal eine Frage"). These are CONVERSATION, not# work: the brain answers them inline — they must NEVER force-spawn a worker,@@ -3177,6 +3218,17 @@ class BrainManager:if res is None:return Noneskill = res[0]+ # Definitional-question guard: a bare-name plugin trigger must not+ # capture a "was ist <App>?" knowledge turn (2026-06-24 eval).+ matched_token = res[1].group(0) if res[1] is not None else ""+ if _is_definitional_question_about(user_text, matched_token):+ log.info(+ "skill %s matched token %r but the turn is a definitional "+ "question about it — not captured (answer it instead)",+ getattr(skill, "name", "?"),+ matched_token,+ )+ return Noneif self._skill_is_blocked(skill):log.info("skill %s matched but is block-tier — turn not captured",@@ -3212,6 +3264,24 @@ class BrainManager:"clearly wrong.")+ def _drop_run_skill_when_inline_injected(self, tools: Any) -> Any:+ """Hide ``run-skill`` once a matched skill's instructions are already on+ the turn context (``_skill_injected_inline``).++ With the instructions inline (AD-S4) no tool call is needed; keeping+ run-skill visible only tempts a weak model into a redundant, garbled+ run-skill call — the gemini-fast ``<call:tool.run-skill ...>`` text leak+ (forensic 2026-06-24). Dropping it makes skill execution provider- and+ model-agnostic: every model just follows the injected instructions, no+ tool call required. No-op when the skill was not inline-injected, or the+ tool set is not a dict (intelligent-router lead path).+ """+ if not getattr(self, "_skill_injected_inline", False):+ return tools+ if not isinstance(tools, dict):+ return tools+ return {k: v for k, v in tools.items() if k != "run-skill"}+def _render_skill_turn_injection(self, user_text: str) -> str | None:"""Render the matched skill's instructions for direct turn injection.@@ -3220,7 +3290,12 @@ class BrainManager:them in this very turn (guaranteed invocation). Publishes``SkillInvoked``. Falls back to the steering hint when renderingfails (the model can still call run-skill itself).++ Sets ``_skill_injected_inline`` True ONLY when the real instructions+ were injected (not the hint fallback) so the caller can hide run-skill+ for the turn (provider-agnostic execution, no tool-call leak)."""+ self._skill_injected_inline = Falseskill = self._skill_turn_matchif skill is None:return None@@ -3246,6 +3321,10 @@ class BrainManager:)return self._render_skill_turn_hint()self._publish_skill_invoked(name, source=self._skill_turn_source)+ # The real instructions are now inline — the model needs no run-skill+ # call; the caller drops that tool so a weak model cannot leak a garbled+ # tool call (provider-agnostic skill execution).+ self._skill_injected_inline = Truereturn (f"[Skill instructions for `{name}` — the user's request matched ""this installed skill]\n"@@ -4228,6 +4307,17 @@ class BrainManager:except RuntimeError:log.debug("Curator-Task nicht scheduled (kein Event-Loop)")+ def has_pending_voice_confirm(self) -> bool:+ """True while a two-turn voice confirmation is awaiting the user's yes/no.++ The speech pipeline consults this in ``_finish_after_response`` to keep+ the session open until the answer lands — otherwise (in single-turn mode)+ the turn finalizes and hangs up before the user can say "ja" (forensic+ 2026-06-26). Mirrors how ``_background_mission_in_flight`` keeps a running+ mission's session alive.+ """+ return self._pending_voice_confirm is not None+def _arm_voice_confirm(self, descriptor: dict[str, Any], user_text: str) -> None:"""Turn N: record a deferred consequential action awaiting yes/no.@@ -5430,6 +5520,12 @@ class BrainManager:self._apply_plugin_relevance(user_text, self._tools)))+ # Skill inline-injected (AD-S4): drop run-skill so a weak model+ # cannot make a redundant, garbled run-skill tool call — the+ # gemini-fast ``<call:tool.run-skill ...>`` text leak. The+ # instructions already ride on the turn context, so execution is+ # provider-/model-agnostic (no tool call needed).+ _turn_tools = self._drop_run_skill_when_inline_injected(_turn_tools)# AI Pointer: on a deictic pointer turn the cursor crop is already the# only attached image, so drop the redundant ``inspect-pointer`` PULL# tool (calling it produced an empty spoken answer — observed live).diff --git a/jarvis/speech/pipeline.py b/jarvis/speech/pipeline.pyindex b9a40f26f4..367ec4a080 100644--- a/jarvis/speech/pipeline.py+++ b/jarvis/speech/pipeline.py@@ -2371,7 +2371,9 @@ class SpeechPipeline:event.text,)return- is_preamble = getattr(event, "kind", None) == "preamble"+ event_kind = getattr(event, "kind", None)+ is_preamble = event_kind == "preamble"+ is_progress = event_kind == "progress"# 2026-05-26 cross-surface voice incoherence guard. After an# interrupt-priority announcement (typically a MissionFailed# readback) the user has just heard a terminal statement; a@@ -2402,9 +2404,21 @@ class SpeechPipeline:# the missing reverse — Jarvis must not start speaking while the USER# holds the floor. Only non-interrupt announcements are gated; an# interrupt is a deliberate barge and still punches through.+ current_turn_state = getattr(self, "_turn_state", TurnTakingState.IDLE)+ if (+ event.priority != "interrupt"+ and is_progress+ and current_turn_state+ not in {TurnTakingState.IDLE, TurnTakingState.LISTENING}+ ):+ log.info(+ "Progress announcement dropped — foreground turn active (%s): %r",+ getattr(current_turn_state, "value", current_turn_state),+ event.text[:80],+ )+ returnif event.priority != "interrupt" and (- getattr(self, "_turn_state", TurnTakingState.IDLE)- in _USER_HOLDS_FLOOR_STATES+ current_turn_state in _USER_HOLDS_FLOOR_STATES):# A preamble or a "still on it" heartbeat (kind="progress") is only# meaningful in the moment — once the user holds the floor it is@@ -2412,10 +2426,10 @@ class SpeechPipeline:# after the mission answer; events.py: progress = "droppable when# stale"). Completion/readback below owes the user information and is# deferred instead.- if is_preamble or getattr(event, "kind", None) == "progress":+ if is_preamble or is_progress:log.info("Announcement dropped — user holds the floor (%s): %r",- getattr(event, "kind", None) or "normal",+ event_kind or "normal",event.text[:80],)return@@ -4509,6 +4523,23 @@ class SpeechPipeline:self._input_suppressed_until_ns = max(previous, until_ns)log.info("TTS-Echo-Sperre aktiv: %.1fs (%s).", seconds, reason)+ def _voice_confirm_pending(self) -> bool:+ """True while the brain is awaiting a spoken yes/no for a deferred+ ``ask``-tier tool — keep the session open so the answer is not cut off+ (analogous to ``_background_mission_in_flight``). Forensic 2026-06-26: an+ ask-tier tool asked "really do that?" and the session then ended before+ the user could answer. Defensive: a brain callback without the probe (the+ echo fake, an older build) reports no pending confirm and never crashes+ the hangup decision."""+ brain = getattr(self, "_brain", None)+ probe = getattr(brain, "has_pending_voice_confirm", None)+ if not callable(probe):+ return False+ try:+ return bool(probe())+ except Exception: # noqa: BLE001 — the hangup decision must never crash+ return False+async def _finish_after_response(self, *, barged: bool = False) -> bool:"""Schliesst normale Voice-Turns; Barge-in darf weiterlaufen.@@ -4528,6 +4559,7 @@ class SpeechPipeline:bargedor self._continue_listening_after_responseor self._background_mission_in_flight()+ or self._voice_confirm_pending()):await self._set_turn_state(TurnTakingState.LISTENING)return True@@ -6846,6 +6878,14 @@ class SpeechPipeline:return doneplayer = getattr(self, "_player", None)last_write = getattr(player, "last_write_ns", 0) if player is not None else 0+ owner_missing = object()+ owner_task_id = (+ getattr(player, "last_write_owner_task_id", owner_missing)+ if player is not None+ else owner_missing+ )+ if owner_task_id is not owner_missing and owner_task_id != id(play_task):+ last_write = 0if last_write <= 0:# No first frame yet: the synthesize / first-frame window. A slow# TTS provider must NOT be misread as a device wedge — that falsediff --git a/tests/unit/brain/test_voice_confirm_flow.py b/tests/unit/brain/test_voice_confirm_flow.pyindex 5c92eab2a2..cceb7f541f 100644--- a/tests/unit/brain/test_voice_confirm_flow.py+++ b/tests/unit/brain/test_voice_confirm_flow.py@@ -67,6 +67,16 @@ def test_arm_records_pending_with_trace_and_language() -> None:assert mgr._pending_voice_confirm.tool_name == "gmail"+def test_has_pending_voice_confirm_reflects_state() -> None:+ """The speech pipeline consults this to keep the session open while a+ yes/no is awaited — otherwise the turn finalizes and (in single-turn mode)+ the session hangs up before the user can answer (forensic 2026-06-26)."""+ mgr = _manager(_FakeExecutor())+ assert mgr.has_pending_voice_confirm() is False+ _arm(mgr, uuid4())+ assert mgr.has_pending_voice_confirm() is True++@pytest.mark.asyncioasync def test_resume_confirm_executes_and_reports_done() -> None:executor = _FakeExecutor(success=True)diff --git a/tests/unit/speech/test_session_stays_open_during_voice_confirm.py b/tests/unit/speech/test_session_stays_open_during_voice_confirm.pynew file mode 100644index 0000000000..12cc0b9a37--- /dev/null+++ b/tests/unit/speech/test_session_stays_open_during_voice_confirm.py@@ -0,0 +1,92 @@+"""The voice session must stay open while a two-turn confirmation is pending.++Forensic 2026-06-26: a voice "switch the subagent brain to antigravity" was an+``ask``-tier tool, so the brain spoke "really do that? say yes or no" and armed a+pending voice-confirm. But ``_finish_after_response`` only kept the session open+for ``_continue_listening_after_response`` / a background mission / a barge — it+had no idea a yes/no was awaited, so in single-turn mode the turn finalized and+the session hung up before the user could answer. These tests pin the same+courtesy that ``_background_mission_in_flight`` gives a running mission.+"""+from __future__ import annotations++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]+++class _BrainWithConfirm:+ """A brain callback exposing the pending-confirm probe (the real BrainManager+ shape). Callable so the pipeline's other paths still work."""++ def __init__(self, pending: bool) -> None:+ self.pending = pending++ def has_pending_voice_confirm(self) -> bool:+ return self.pending++ async def __call__(self, *a: object, **k: object) -> str: # pragma: no cover+ return ""+++def _pipeline() -> SpeechPipeline:+ return SpeechPipeline(tts=FakeTTS(), bus=EventBus(), enable_whisper_wake=False)+++async def test_finish_after_response_stays_listening_while_confirm_pending() -> None:+ pipe = _pipeline()+ pipe._continue_listening_after_response = False # single-turn mode+ pipe._brain = _BrainWithConfirm(pending=True)++ # A yes/no is awaited → keep the floor so the answer can land.+ assert await pipe._finish_after_response(barged=False) is True+ assert pipe._turn_state == TurnTakingState.LISTENING+ assert pipe._session_end_reason is None+++async def test_finish_after_response_hangs_up_once_confirm_resolved() -> None:+ pipe = _pipeline()+ pipe._continue_listening_after_response = False # single-turn mode+ brain = _BrainWithConfirm(pending=True)+ pipe._brain = brain++ assert await pipe._finish_after_response(barged=False) is True++ # Manager cleared the pending state after the user answered — single-turn+ # mode must hang up normally again on the next finalize.+ brain.pending = False+ assert await pipe._finish_after_response(barged=False) is False+ assert pipe._session_end_reason is not None+++async def test_finish_after_response_defensive_when_brain_lacks_probe() -> None:+ """A brain callback without ``has_pending_voice_confirm`` (the echo fake, an+ older build) must not crash the hangup decision — it reports no pending."""+ pipe = _pipeline()+ pipe._continue_listening_after_response = False+ # default self._brain is the plain echo coroutine — no probe method.+ assert await pipe._finish_after_response(barged=False) is False+ assert pipe._session_end_reason is not None