Skip to content

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.

fix(realtime): do not abort an in-flight music play as a stalled turn (BUG-157)

Harald00aaa15b78b7
diff --git a/docs/BUGS.md b/docs/BUGS.md
index 5d9db10fb2..aff70ad6bf 100644
--- a/docs/BUGS.md
+++ b/docs/BUGS.md
@@ -10928,3 +10928,61 @@ pipeline and every OS.
`test_smalltalk_is_not_music_connected_data`);
`tests/unit/brain/test_factory_supervisor_gateway.py`
(`test_catalog_carries_the_per_args_risk_tier_hook`).
+
+
+## BUG-157: asking for a song during a realtime call is aborted as "took too long" — the stall watchdog treats an in-flight native play as a dead transport (HIGH, FIXED 2026-08-19)
+
+**Symptom (Windows live forensic, 18:17, `vertex-live` /
+`gemini-live-2.5-flash-native-audio`, hybrid).** The user asked for a
+modern 2026 track. Jarvis said it would take a moment, then 20 s later
+spoke "Das hat zu lange gedauert, also habe ich abgebrochen." The song <!-- i18n-allow: quoted live German reply under forensic analysis -->
+never started. The UI error was
+`RealtimeTurnStalled`: "The realtime provider produced nothing for 20s
+on an open turn; the turn was closed locally."
+
+**Timeline (`data/jarvis_desktop.log` + flight recorder, session
+`128fbac6-d7ae-4fef-9810-4de3179f9889`).**
+
+| Time | What happened |
+|---|---|
+| 18:17:22 | Wake `nova`. Handshake 10.4 s |
+| 18:17:49 | Final: play a cool modern 2026 song. Native `youtube_music` `play` / `aktuelle Hits 2026` |
+| 18:17:52 | Instant ack on the surface channel ("still a moment") |
+| 18:17:53 | YouTube search HTTP 200 — the tool is still running |
+| 18:18:09 | Stall watchdog: 20.3 s since the last provider event (the function call itself). `ActionExecuted` never published |
+| 18:18:16 | Spoken timeout. User hangup |
+
+Earlier the same evening, `youtube_music` play took 17.9 s and 21.2 s
+and succeeded. 21 s is already longer than `_TURN_STALL_TIMEOUT_S`.
+
+**Root cause.** BUG-154 taught the *empty-turn* recovery that
+`_native_tools_in_flight` is evidence. The *stall* watchdog did not
+learn it. `_turn_stall_is_excusable` allowed only delegate holds, user
+speech, and provider audio. A native function call blocks the live
+model (ADR-0034): Vertex Live emits nothing until `send_tool_result`.
+The last `_note_turn_activity` was the `tool_call` event. Twenty
+seconds later the watchdog closed the turn, spoke the timeout, and
+left the still-running play with no turn to finish — the track is
+cut off / never starts.
+
+The surface instant-ack does not increment `_output_samples_sent`, so
+it does not excuse the stall either.
+
+**Fix.** `_turn_stall_is_excusable` (and a race guard in
+`_recover_stalled_turn`) treat `_native_tools_in_flight` the same way
+the empty-turn nets already do. The 20 s clock starts after the tool
+returns, when the provider actually owes audio again.
+
+**Class rule.** Provider silence during a native execute is the
+function-call block, not a dead socket. An in-flight tool already owns
+the turn. Do not abort the user's song (or any other native action) to
+reopen the microphone.
+
+**Parity.** Session-level stall watchdog, every realtime transport
+(`openai-realtime` / `gemini-live` / `vertex-live`). Direct and
+delegate already excuse a pending Brain turn via
+`_turn_has_pending_delegate`. Classic pipeline has its own stall
+guard and does not use this watchdog.
+
+**Guards.** `tests/unit/realtime/test_stall_native_tool.py`
+(`test_in_flight_native_tool_is_not_a_stalled_turn`).
diff --git a/jarvis/realtime/session.py b/jarvis/realtime/session.py
index 72229ee233..7738747a35 100644
--- a/jarvis/realtime/session.py
+++ b/jarvis/realtime/session.py
@@ -2946,6 +2946,12 @@ class RealtimeVoiceSession:
voice = active_voice() or voice
except Exception as exc: # noqa: BLE001 - a voice preference never costs a session
log.debug("Mode voice not applied to the realtime session: %s", exc)
+ # An empty pin used to leave ``_active_voice`` blank. Surface TTS then
+ # fell through to Charon while the live socket used Google's
+ # undocumented default — a second, often different-gender speaker
+ # on every progress / fallback line (BUG-155). The adapter's
+ # declared default is the same name both paths will speak.
+ voice = voice or str(getattr(provider, "default_voice", "") or "")
return model, voice
@staticmethod
@@ -7019,6 +7025,12 @@ class RealtimeVoiceSession:
or self._output_active
or self._output_samples_sent > 0
or self._gate.pending_audio_ms > 0
+ # A native tool call blocks the live model (ADR-0034). The
+ # transport emits nothing until send_tool_result. youtube_music
+ # play regularly takes 18-28 s — longer than
+ # _TURN_STALL_TIMEOUT_S — so this silence is work, not a wedge
+ # (live 2026-08-19 18:17, session 128fbac6, BUG-157).
+ or self._native_tools_in_flight
)
async def _watch_turn_for_stall(self, turn_id: str) -> None:
@@ -7058,6 +7070,12 @@ class RealtimeVoiceSession:
"""Close a wedged turn honestly: say what happened, then reopen the mic."""
from jarvis.voice.action_phrases import action_phrase # noqa: PLC0415
+ # Race: the poll saw a quiet turn, then a native execute started.
+ # Aborting now would cut the action the user is still waiting for.
+ if self._native_tools_in_flight:
+ self._note_turn_activity()
+ return
+
pending_update = self._external_update
log.warning(
"realtime[%s] turn %s produced no audio, transcript, tool call or "
diff --git a/tests/unit/realtime/test_stall_native_tool.py b/tests/unit/realtime/test_stall_native_tool.py
new file mode 100644
index 0000000000..c57b19d8ee
--- /dev/null
+++ b/tests/unit/realtime/test_stall_native_tool.py
@@ -0,0 +1,87 @@
+"""BUG-157: an in-flight native play is not a stalled realtime turn."""
+
+from __future__ import annotations
+
+import asyncio
+
+import pytest
+
+from jarvis.realtime.protocol import RealtimeEvent
+from tests.unit.realtime.test_session import (
+ FakeBrain,
+ FakeToolBridge,
+ ScriptedTextTurnsProvider,
+ _session,
+)
+
+
+async def test_in_flight_native_tool_is_not_a_stalled_turn(monkeypatch):
+ """Live 2026-08-19 18:17 session 128fbac6: youtube_music play was still
+ running when the 20 s stall watchdog closed the turn and spoke
+ "that took too long". The live model is blocked on the function call
+ (ADR-0034), so provider silence during execute is work, not a wedge."""
+ import jarvis.realtime.session as session_module
+
+ monkeypatch.setattr(session_module, "_DELEGATE_READBACK_WAIT_S", 0.2)
+ monkeypatch.setattr(session_module, "_INSTANT_ACK_GRACE_S", 5.0)
+
+ class _SlowBridge(FakeToolBridge):
+ def __init__(self):
+ super().__init__()
+ self.started = asyncio.Event()
+ self.release = asyncio.Event()
+
+ async def execute(self, *, wire_name, arguments):
+ self.calls.append((wire_name, arguments))
+ self.started.set()
+ await self.release.wait()
+ return "youtube_music", {
+ "success": True,
+ "output": "playing",
+ "error": None,
+ }
+
+ user_text = (
+ "Kannst du bitte für mich ein richtig geiles Lied abspielen?" # i18n-allow: live 18:17
+ )
+ jsons: list[dict] = []
+ bridge = _SlowBridge()
+ # Same native-call release shape as the BUG-154 in-flight guard: the
+ # empty-turn re-ask is what delivers the tool_call on this fake
+ # transport. The stall watchdog is what 18:17 actually tripped.
+ provider = ScriptedTextTurnsProvider(
+ [
+ RealtimeEvent(type="input_transcript", text=user_text, is_final=True),
+ RealtimeEvent(type="turn_complete"),
+ ],
+ [
+ RealtimeEvent(
+ type="tool_call",
+ call_id="call-yt-stall",
+ tool_name="youtube_music",
+ tool_args={"action": "play", "query": "aktuelle Hits 2026"},
+ ),
+ ],
+ )
+ sess = _session(
+ provider,
+ brain=FakeBrain(replies=("never spoken",)),
+ tool_bridge=bridge,
+ tool_mode="hybrid",
+ jsons=jsons,
+ )
+
+ await sess.handle_control({"type": "audio_start", "sample_rate": 16_000})
+ await asyncio.wait_for(bridge.started.wait(), timeout=8)
+ # Shrink the stall window only after execute is live, so session
+ # startup (first-import planning) cannot close the turn first.
+ monkeypatch.setattr(session_module, "_TURN_STALL_TIMEOUT_S", 0.15)
+ monkeypatch.setattr(session_module, "_TURN_STALL_POLL_S", 0.02)
+ await asyncio.sleep(0.5)
+ spoken = [m for m in jsons if m.get("type") == "error_spoken"]
+ assert spoken == [], "in-flight youtube_music must not trip the stall watchdog"
+ assert sess._native_tools_in_flight == 1
+ assert sess._turn_id, "the play turn must stay open while the tool runs"
+ bridge.release.set()
+ await sess.end(reason="test")