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): answer a presence probe deterministically while a delegated action still runs (BUG-070)
Ruben Lütke968733f12c52
diff --git a/docs/BUGS.md b/docs/BUGS.mdindex 45f1d8f359..8fafcd740b 100644--- a/docs/BUGS.md+++ b/docs/BUGS.md@@ -5052,3 +5052,71 @@ guarantees — and every violation of that assumption is audible. Secondlesson, again: safety bounds sized to "normal" provider behavior(5 s of pending audio) become answer-killers the day the provider isroutinely slower; bound on resource cost, not on optimism.++## BUG-070: User probes the silent wait ("hello?") — the provider greets like a fresh conversation while the delegated answer is still being computed (HIGH, FIXED 2026-07-17)++**Symptom (maintainer report + live session 2026-07-17 09:21, gemini-live).**+Mid-conversation, the answer to a follow-up question starts and dies after+two words; the user probes the silence with a bare greeting, and the+assistant replies with a fresh-conversation greeting as if the whole+exchange never happened. The user hangs up; the real answer never arrives+in any form. The exported transcript shows: user question → two-word+assistant fragment → user "hello?" probe → context-free greeting.++**Evidence (data/jarvis_desktop.log, session 9ef10423, 09:23:26-09:23:57).**+The provider called `jarvis_action` for the user's question (`delegate+call: dispatching user turn to the router brain`, 09:23:26) and kept+speaking natively; the scrub gate released only the first words because+the provider's output transcription ran >10 s behind its audio (the+BUG-069 lag mode — an earlier reply in the same session logged+`mid-reply audio stalled 14718 ms … scrub-gate hold 14671 ms`). Into that+hole the user said a bare greeting; the barge-in killed the native reply;+the provider answered the probe with a fresh greeting (no delegate+dispatch logged — 5 ms turn). The router-brain answer was still in flight+when the user hung up at 09:23:57; `end()` cancelled the delegate task+with no log line — the answer vanished without a trace.++**Root causes (jarvis/realtime/session.py).**+1. A thin presence probe ("hello?", "are you still there?") spoken while+ an earlier turn's delegated action is still executing was handled by+ the provider like any other turn. `_DELEGATE_PENDING_DIRECTIVE`+ already tells the model to say it is still working, but prompt+ compliance is not a correctness boundary (BUG-047 class rule), and the+ live model demonstrably greeted instead.+2. `end()` cancelled still-running delegate tasks silently: a hangup+ during a slow delegated answer discarded the request with no evidence+ in the log (the queued-late-result and flush paths log their losses;+ the still-running case logged nothing).++**Fixes.**+1. *Deterministic presence-check status line.* A final user transcript+ that (a) matches a closed multilingual presence-probe vocabulary+ (`_is_presence_check`: de/en/es greetings and are-you-there cores,+ ≤ 5 words, a lone filler like "ja"/"yes" deliberately excluded) while+ (b) an earlier turn's delegate task is still running+ (`_has_pending_delegate_from_earlier_turn`) and (c) the turn itself+ requires no orchestrator dispatch, is answered by the ORCHESTRATOR:+ one progress line from the closed bridge pool through the surface TTS+ (`error_spoken`), the provider's freestyle response for that turn is+ dropped (`_drop_provider_output_until_user_turn`), and no provider+ response is requested. The late-result flush still speaks the real+ answer once the session is at rest — its injection path clears both+ drop flags. A probe with no pending action stays fully native.+2. *Named loss on hangup.* `end()` now logs one WARNING per turn whose+ delegate task is still running at session end, naming the user request+ whose answer is being cancelled.++**Guards.** `tests/unit/realtime/test_session.py`+(`test_presence_check_vocabulary_matches_probes_only`,+`test_presence_check_during_pending_action_gets_status_line_not_provider`,+`test_presence_check_without_pending_action_stays_native`,+`test_session_end_names_the_delegated_request_it_cancels`).++**Lesson.** When a slow background action leaves the voice channel+silent, the user WILL speak into that silence to test for life — and that+probe is the one turn where a freestyle model answer is guaranteed to be+wrong (it either invents an outcome or resets the conversation). Every+turn category whose only correct answer is known in advance belongs to+the orchestrator, not the model. And: any path that discards work the+user asked for — even legitimately, on hangup — must say so in the log,+or the next forensic starts from nothing.diff --git a/jarvis/realtime/session.py b/jarvis/realtime/session.pyindex bb835885b0..1955d553cb 100644--- a/jarvis/realtime/session.py+++ b/jarvis/realtime/session.py@@ -13,6 +13,7 @@ import asyncioimport inspectimport loggingimport random+import reimport timefrom dataclasses import dataclass, fieldfrom typing import Any@@ -238,6 +239,52 @@ _LATE_DELEGATE_POLL_S = 0.15# are pulled back to the orchestrator; a longer utterance is a new topic._DELEGATE_ANSWER_MAX_TOKENS = 6+# While a delegated action still runs, the wait is silent (or worse: a scrub+# hold has just cut a running answer mid-sentence). A user speaking a bare+# "hello? are you there?" into that silence is probing whether the assistant+# is alive — not opening a new topic. Left to the provider, that probe gets a+# freestyle reply: live forensic 2026-07-17 09:23 — the model greeted like a+# brand-new conversation while the real answer was still being computed, and+# the user hung up before it landed. The pending-action prompt directive+# already forbids this, but prompt compliance is not a correctness boundary+# (BUG-047 class rule), so the orchestrator answers this one turn itself.+# Closed speech-recognition input vocabulary (matching data, not prose), all+# supported languages equal. A miss is safe: the turn simply stays native.+_PRESENCE_CHECK_MAX_WORDS = 5+_PRESENCE_CHECK_RE = re.compile(+ r"^(?:(?:ja|yes|s[ií]|und|and|y)\s+)?" # i18n-allow: input vocabulary+ # i18n-allow: input vocabulary+ r"(?P<greeting>(?:(?:hallo|hello|hola|hey|hi|huhu|servus|moin)\s*)+)?"+ r"(?P<core>"+ r"bist\s+du\s+(?:noch\s+)?(?:da|dran)" # i18n-allow: input vocabulary+ r"|h(?:ö|oe)rst\s+du\s+mich(?:\s+noch)?" # i18n-allow: input vocabulary+ r"|are\s+you\s+(?:still\s+)?there"+ r"|(?:you\s+)?still\s+there"+ r"|(?:can\s+you\s+(?:still\s+)?|do\s+you\s+)hear\s+me"+ r"|(?:sigues|est[áa]s)\s+ah[ií]" # i18n-allow: input vocabulary+ r"|me\s+(?:oyes|escuchas)(?:\s+todav[ií]a)?" # i18n-allow: input vocabulary+ r")?$"+)+++def _is_presence_check(text: str) -> bool:+ """Return True for a bare are-you-still-there probe (closed vocabulary).++ Deliberately strict: a lone filler ("ja", "yes") is an answer, not a+ probe, and anything beyond the tiny word bound is a real utterance the+ provider must handle. At least one greeting or one core phrase must be+ present for a match.+ """+ normalized = " ".join(+ re.sub(r"[^\w\s]", " ", str(text or "").casefold()).split()+ )+ if not normalized or len(normalized.split()) > _PRESENCE_CHECK_MAX_WORDS:+ return False+ match = _PRESENCE_CHECK_RE.fullmatch(normalized)+ return match is not None and bool(+ match.group("greeting") or match.group("core")+ )+def _requires_jarvis_action(text: str) -> bool:"""Compatibility wrapper around the shared Pipeline/Realtime planner."""@@ -1304,6 +1351,15 @@ class RealtimeVoiceSession:and self._delegate_required_for_turn):self._start_deterministic_delegate(self._last_user_text)+ if (+ event.is_final+ and input_observed+ and not self._delegate_required_for_turn+ and not self._response_requested_for_turn+ and self._has_pending_delegate_from_earlier_turn()+ and _is_presence_check(self._last_user_text)+ ):+ await self._speak_pending_action_status()if (event.is_finaland input_observed@@ -2784,6 +2840,39 @@ class RealtimeVoiceSession:return Falsereturn True+ async def _speak_pending_action_status(self) -> None:+ """Answer a bare presence check deterministically while an action runs.++ A thin are-you-there probe spoken into the silent wait for a+ still-running delegated action needs exactly one honest answer: still+ working on it. The provider cannot be trusted to give it (live+ forensic 2026-07-17 09:23: it greeted like a fresh conversation+ instead), so the orchestrator speaks a progress line from the closed+ bridge pool through the surface TTS and drops the provider's+ freestyle response for this turn. The late-result flush still+ delivers the real answer once the session is at rest — both drop+ flags are cleared by that injection path.+ """+ status_text = _pick_delegate_bridge_text(self._language)+ self._response_requested_for_turn = True+ self._drop_provider_output_until_user_turn = True+ # Recording the line as this turn's output keeps the exported+ # transcript honest and keeps the empty-turn recovery from+ # re-dispatching the interjection as a brain turn.+ self._output_transcript.append(status_text)+ log.info(+ "realtime[%s] presence check while an earlier action is still "+ "running — answering with the deterministic progress line",+ self.session_id,+ )+ await self._send_json(+ {+ "type": "error_spoken",+ "text": status_text,+ "language": self._language,+ }+ )+async def _handle_tool_call(self, event: Any) -> None:if self._session is None:return@@ -3669,6 +3758,22 @@ class RealtimeVoiceSession:if self._end_call_timer is not None and not self._end_call_timer.done():self._end_call_timer.cancel()self._end_call_timer = None+ for turn_id, tasks in tuple(self._delegate_tasks_by_turn.items()):+ if not any(not task.done() for task in tasks):+ continue+ # The cancel below kills the in-flight brain turn: the user hung+ # up before its answer existed, and nothing will ever speak it+ # (live forensic 2026-07-17 09:23: a hangup 31 s into a delegated+ # answer discarded it without a trace). Name the lost request so+ # the loss is diagnosable from the log.+ state = self._delegate_turns.get(turn_id)+ request = str(getattr(state, "user_text", "") or "")+ log.warning(+ "realtime[%s] session ended while a delegated action was "+ "still running; its answer was never produced: %s",+ self.session_id,+ safe_preview(request, max_chars=200) or "<unknown request>",+ )for task in tuple(self._delegate_tasks):if not task.done():task.cancel()diff --git a/tests/unit/realtime/test_session.py b/tests/unit/realtime/test_session.pyindex 41e72a95c0..45d386e400 100644--- a/tests/unit/realtime/test_session.py+++ b/tests/unit/realtime/test_session.py@@ -957,7 +957,7 @@ async def test_later_segment_leak_audio_not_emitted():# could ride along before its own transcript is scrubbed. The session# must flush release_available() right after sending a clean transcript# so the gate's _cleared flag never spans into the next segment's audio.- # The leak segment carries 1500 ms of PCM — beyond what the 23-char clean+ # The leak segment carries 1500 ms of PCM — beyond what the 23-char clean# first sentence funds under the BUG-069 coverage budget, so it must stay# buffered until its own (leaking) transcript arrives and drops it.a1 = b"\x11\x22" * 8@@ -2009,13 +2009,13 @@ async def test_scrub_trip_during_delegate_readback_speaks_trusted_reply():Gemini renders an injected trusted result faster than real time while itsoutput transcription lags entirely (live incident 2026-07-16 11:24). Withno transcript delta the whole turn, the gate fails closed at- turn_complete (BUG-069: the mid-turn buffer cap no longer trips first) —+ turn_complete (BUG-069: the mid-turn buffer cap no longer trips first) —and that path used to speak a generic error AFTER the user waited throughthe whole delegated action. The reply text is our own already-deliveredbrain output, so the surface TTS must speak it instead."""reply = "The delegated answer the user must still hear."- # 3 s of 24 kHz 16-bit PCM per chunk — audio arrives, its transcript+ # 3 s of 24 kHz 16-bit PCM per chunk — audio arrives, its transcript# never does, and the turn ends normally.three_seconds = AudioChunk(pcm=b"\x01\x02" * 72_000, sample_rate=24_000, timestamp_ns=0@@ -4343,3 +4343,140 @@ async def test_open_carries_user_agent_instructions_into_session_instructions(# on the next message, exactly as the Settings view promises.updated = provider.session.session_updates[-1]["instructions"]assert "Always speak with a Bavarian accent." in updated+++async def test_presence_check_vocabulary_matches_probes_only():+ from jarvis.realtime.session import _is_presence_check++ # i18n-allow: German/Spanish speech-input fixtures (matching data)+ assert _is_presence_check("Ja, hallo.")+ assert _is_presence_check("Hallo?")+ assert _is_presence_check("hallo hallo")+ assert _is_presence_check("Bist du noch da?")+ assert _is_presence_check("Hey, bist du noch dran?")+ assert _is_presence_check("Hörst du mich?") # i18n-allow: fixture+ assert _is_presence_check("Hello? Are you there?")+ assert _is_presence_check("can you hear me")+ assert _is_presence_check("Hola, ¿sigues ahí?")++ # A lone filler is an answer to an open question, never a probe.+ assert not _is_presence_check("Ja.")+ assert not _is_presence_check("yes")+ # Substantive turns must stay with the provider.+ # i18n-allow: German speech-input fixtures (matching data) below+ assert not _is_presence_check("Kann ich die einfach so kaufen?") # i18n-allow: fixture+ assert not _is_presence_check("hallo kannst du mir das wetter sagen") # i18n-allow: fixture+ assert not _is_presence_check("are you there tomorrow morning as well")+ assert not _is_presence_check("")+++async def test_presence_check_during_pending_action_gets_status_line_not_provider():+ """A bare "hello?" into a running action gets the deterministic line.++ Live forensic 2026-07-17 09:23: a scrub hold silenced the running answer,+ the user probed with a bare greeting, and the provider replied with a+ fresh-conversation greeting while the delegated answer was still being+ computed. The orchestrator must own that turn: progress line through the+ surface TTS, no provider response, no second brain dispatch.+ """+ from jarvis.realtime.session import _DELEGATE_BRIDGE_TEXTS++ gate = asyncio.Event() # never set: the delegated action outlives the test+ brain = FakeBrain(gate=gate)+ jsons = []+ # The live shape (2026-07-17 09:23): the provider itself called+ # jarvis_action, the user barged into the silent wait, and only then did+ # the probe's final transcript arrive on a fresh turn.+ provider = FakeProvider(+ [+ RealtimeEvent(+ type="input_transcript",+ text="Can I just buy it like that?",+ is_final=True,+ ),+ RealtimeEvent(+ type="tool_call",+ call_id="call-1",+ tool_name="jarvis_action",+ tool_args={"request": "Can I just buy it like that?"},+ ),+ RealtimeEvent(type="interrupted"),+ RealtimeEvent(+ type="input_transcript",+ text="Ja, hallo.", # i18n-allow: German speech-input fixture+ is_final=True,+ ),+ ]+ )+ sess = _session(provider, brain=brain, jsons=jsons)++ await sess.handle_control({"type": "audio_start", "sample_rate": 16_000})+ await sess.wait_finished()+ await asyncio.sleep(0.05)++ spoken = [m for m in jsons if m.get("type") == "error_spoken"]+ assert len(spoken) == 1+ pool = {text for texts in _DELEGATE_BRIDGE_TEXTS.values() for text in texts}+ assert spoken[0]["text"] in pool+ # The probe itself never becomes a provider response or a brain turn:+ # the single request belongs to the first (native) turn.+ assert provider.session.response_requests == 1+ assert all("hallo" not in call[0] for call in brain.calls)+ await sess.end(reason="test")+++async def test_presence_check_without_pending_action_stays_native():+ jsons = []+ provider = FakeProvider(+ [+ RealtimeEvent(+ type="input_transcript",+ text="Ja, hallo.", # i18n-allow: German speech-input fixture+ is_final=True,+ ),+ ]+ )+ sess = _session(provider, brain=FakeBrain(), jsons=jsons)++ await sess.handle_control({"type": "audio_start", "sample_rate": 16_000})+ await sess.wait_finished()++ assert [m for m in jsons if m.get("type") == "error_spoken"] == []+ assert provider.session.required_tools == [None]+ await sess.end(reason="test")+++async def test_session_end_names_the_delegated_request_it_cancels(caplog):+ """A hangup mid-action must leave a trace of the answer it discarded."""+ import logging as _logging++ gate = asyncio.Event() # never set: the delegated action never finishes+ brain = FakeBrain(gate=gate)+ provider = FakeProvider(+ [+ RealtimeEvent(+ type="input_transcript",+ text="Write the travel plan to my wiki.",+ is_final=True,+ ),+ RealtimeEvent(type="turn_complete"),+ ]+ )+ sess = _session(provider, brain=brain)++ await sess.handle_control({"type": "audio_start", "sample_rate": 16_000})+ await sess.wait_finished()+ with caplog.at_level(_logging.WARNING, logger="jarvis.realtime.session"):+ await sess.end(reason="hotkey")++ lost = [+ record+ for record in caplog.records+ if "still running" in record.getMessage()+ ]+ assert len(lost) == 1+ assert "travel plan" in lost[0].getMessage()