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): keep the call alive when a handoff has no executor

rubenluetke10-beepaa17fe872d62
diff --git a/jarvis/realtime/session.py b/jarvis/realtime/session.py
index 510e0804e2..47576a2990 100644
--- a/jarvis/realtime/session.py
+++ b/jarvis/realtime/session.py
@@ -1093,6 +1093,22 @@ class RealtimeVoiceSession:
"so actions remain functional",
session_id,
)
+ if not direct_tools_supported and not self._delegate_enabled:
+ # The one combination in which a capability-limited transport has
+ # NO action path at all: it cannot receive tool declarations, and
+ # the deterministic delegate that would stand in for them is not
+ # available either. The conversation still works; every handoff
+ # will be declined out loud. Say so once, here, rather than
+ # letting each declined action look like an isolated glitch.
+ log.warning(
+ "realtime[%s] a configured provider cannot declare tools "
+ "natively AND no deterministic delegate is available "
+ "(callable brain: %s) — actions will be declined for the "
+ "whole call. A tool bridge cannot stand in: this transport "
+ "has no way to receive the declarations.",
+ session_id,
+ bool(callable(brain)),
+ )
if self._delegate_enabled:
log.info(
"realtime[%s] tool mode: delegate — one action function "
@@ -2478,11 +2494,16 @@ class RealtimeVoiceSession:
)
await self._ensure_turn_started()
if not self._delegate_enabled or not self._last_user_text:
- await self._fail_terminally(
- "Realtime provider requested a supervised handoff, "
- "but no deterministic Jarvis delegate is available."
+ # A transport that cannot declare tools natively reaches
+ # EVERY action through this one event, so this gap used
+ # to hang up on the user mid-sentence. Losing an action
+ # degrades a turn; it must not cost the conversation.
+ await self._decline_provider_handoff(
+ "no deterministic Jarvis delegate is available"
+ if not self._delegate_enabled
+ else "the handoff carried no recognizable user request"
)
- break
+ continue
self._delegate_required_for_turn = True
self._response_requested_for_turn = True
self._drop_provider_output_until_new_response = True
@@ -4998,6 +5019,50 @@ class RealtimeVoiceSession:
name=f"rt-delegate-bridge-{self.session_id}",
)
+ async def _decline_provider_handoff(self, reason: str) -> None:
+ """Speak an honest refusal for a handoff this session cannot execute.
+
+ A provider whose ``supports_direct_tools`` capability is False reaches
+ actions ONLY through the handoff control event, so an unavailable
+ executor used to end the whole call. Say what is missing and keep
+ talking instead (AP-30): the user still has a working conversation,
+ and the surface leaves PROCESSING either way.
+ """
+ from jarvis.voice.action_phrases import action_phrase # noqa: PLC0415
+
+ log.warning(
+ "realtime[%s] provider handoff declined: %s",
+ self.session_id,
+ reason,
+ )
+ spoken = action_phrase("actions_unavailable", self._language)
+ send_speech = getattr(self._session, "send_speech", None)
+ if callable(send_speech):
+ try:
+ # Provider-voiced text must NOT estimate its playback horizon —
+ # its real audio advances the echo guard on the way out.
+ self._register_spoken_reference(spoken)
+ await send_speech(spoken)
+ if getattr(self._session, "direct_speech_is_authoritative", False):
+ # Trusted verbatim speech carries no model transcript for
+ # the scrub gate to vet; without this the refusal is
+ # dropped at the turn boundary and the user hears silence.
+ self._gate.trust_direct_speech()
+ for chunk in self._gate.release_available():
+ await self._emit_audio(chunk)
+ return
+ except Exception: # noqa: BLE001 — the surface still speaks it
+ log.warning(
+ "realtime[%s] handoff refusal could not be voiced by the "
+ "provider; falling back to the surface",
+ self.session_id,
+ exc_info=True,
+ )
+ self._register_spoken_reference(spoken, estimate_playback=True)
+ await self._send_json(self._surface_speech_message(spoken))
+ await self._send_json({"type": "turn_complete"})
+ await self._publish_turn_completed()
+
async def _await_provider_response_boundary(
self, turn_state: _DelegateTurnState
) -> None:
diff --git a/jarvis/voice/action_phrases.py b/jarvis/voice/action_phrases.py
index ccd479ecac..dad71e1ab3 100644
--- a/jarvis/voice/action_phrases.py
+++ b/jarvis/voice/action_phrases.py
@@ -247,6 +247,17 @@ _PHRASES: dict[str, dict[str, str]] = {
"en": "That didn't work: {reason}",
"es": "Eso no funcionó: {reason}",
},
+ # The realtime provider yielded control for an action, but this session has
+ # no executor to hand it to (no callable supervisor brain, or the request
+ # carried no recognizable user text). Transports that cannot declare tools
+ # natively — the ChatGPT-subscription voice among them — reach actions ONLY
+ # through that handoff, so the gap used to end the whole call. A dropped
+ # action is a degraded turn; it is not a reason to hang up on the user.
+ "actions_unavailable": {
+ "de": "Aktionen gehen gerade nicht, aber wir können weiter reden.", # i18n-allow
+ "en": "I can't run actions right now, but we can keep talking.",
+ "es": "Ahora mismo no puedo ejecutar acciones, pero podemos seguir hablando.",
+ },
# A local action that ran past its short deadline. Replaces the old
# tool-name-prefixed "X timeout after 3s" machine string (which leaked the
# internal tool name) with a plain, honest sentence.
diff --git a/tests/unit/realtime/test_session.py b/tests/unit/realtime/test_session.py
index 3609295773..3eba838ce3 100644
--- a/tests/unit/realtime/test_session.py
+++ b/tests/unit/realtime/test_session.py
@@ -2049,6 +2049,53 @@ async def test_capability_forced_delegate_executes_provider_handoff():
await sess.end(reason="test")
+async def test_handoff_without_a_delegate_declines_instead_of_ending_the_call():
+ """A missing executor must cost the ACTION, never the conversation.
+
+ A transport that cannot declare tools natively (the ChatGPT-subscription
+ voice) reaches every action through ``handoff_requested``. When no
+ deterministic delegate is available the session used to fail terminally —
+ it hung up mid-sentence because one action could not be routed. The honest
+ behaviour is to say so out loud and keep the call.
+ """
+
+ class NoDirectToolsProvider(FakeProvider):
+ supports_direct_tools = False
+
+ provider = NoDirectToolsProvider(
+ [
+ RealtimeEvent(
+ type="input_transcript",
+ text="Open the settings view.",
+ is_final=True,
+ ),
+ RealtimeEvent(
+ type="handoff_requested",
+ text="Open the settings view.",
+ handoff_id="handoff-no-delegate",
+ ),
+ RealtimeEvent(type="output_transcript_delta", text="Still here."),
+ RealtimeEvent(type="turn_complete"),
+ ]
+ )
+ jsons: list[dict] = []
+ # No brain => no deterministic delegate, and this transport cannot receive
+ # tool declarations either, so the handoff has nowhere to go.
+ sess = _session(provider, brain=None, tool_mode="delegate", jsons=jsons)
+
+ await sess.handle_control({"type": "audio_start", "sample_rate": 16_000})
+ await sess.wait_finished()
+
+ assert not [item for item in jsons if item.get("type") == "provider_error"]
+ spoken = [item for item in jsons if item.get("type") == "error_spoken"]
+ assert spoken, "the declined handoff must be voiced, not swallowed"
+ assert "action" in spoken[0]["text"].lower()
+ # The stream kept being consumed after the refusal.
+ assert any(item.get("type") == "turn_complete" for item in jsons)
+ await sess.end(reason="test")
+
+
@pytest.mark.asyncio
async def test_provider_eof_waits_for_supervised_delegate_delivery():
"""A finite provider stream must not abandon its accepted handoff."""