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): vary the delegate progress line and keep it in the model's own voice

Ruben Lütkef62a5be82d92
diff --git a/jarvis/realtime/session.py b/jarvis/realtime/session.py
index c07359aa64..032ad21c15 100644
--- a/jarvis/realtime/session.py
+++ b/jarvis/realtime/session.py
@@ -12,6 +12,7 @@ import array
import asyncio
import inspect
import logging
+import random
import time
from dataclasses import dataclass, field
from typing import Any
@@ -301,38 +302,72 @@ def _direct_tool_result_retry_prompt(*, language: str) -> str:
)
-_DELEGATE_BRIDGE_TEXT = {
- "de": "Ich bin noch dran.", # i18n-allow: localized runtime progress output
- "en": "I'm still working on it.",
- "es": "Sigo trabajando en ello.",
+# Several equivalent progress lines per language: one fixed sentence on every
+# slow turn reads robotic (live feedback 2026-07-17 08:47, three "Ich bin noch
+# dran." in one session). Each entry must stay short, promise nothing about
+# the outcome, and remain a complete stand-alone sentence — the transcript
+# validator accepts exactly this closed set.
+# i18n-allow: quoted German forensic phrase above; pools below are product output
+_DELEGATE_BRIDGE_TEXTS: dict[str, tuple[str, ...]] = {
+ "de": ( # i18n-allow: localized runtime progress output
+ "Ich bin noch dran.", # i18n-allow: localized runtime progress output
+ "Einen Moment noch, bitte.", # i18n-allow: localized runtime output
+ "Dauert noch einen kleinen Moment.", # i18n-allow: localized output
+ "Bin gleich so weit.", # i18n-allow: localized runtime progress output
+ ),
+ "en": (
+ "I'm still working on it.",
+ "One moment, almost there.",
+ "Still on it, give me a moment.",
+ "Hang on, this is taking a moment.",
+ ),
+ "es": ( # i18n-allow: localized runtime progress output
+ "Sigo trabajando en ello.",
+ "Un momento, ya casi está.",
+ "Sigo en ello, un momento.",
+ "Dame un momento más.",
+ ),
}
-def _delegate_bridge_text(language: str) -> str:
- return _DELEGATE_BRIDGE_TEXT.get(language, _DELEGATE_BRIDGE_TEXT["en"])
+def _delegate_bridge_texts(language: str) -> tuple[str, ...]:
+ return _DELEGATE_BRIDGE_TEXTS.get(language, _DELEGATE_BRIDGE_TEXTS["en"])
+
+
+def _pick_delegate_bridge_text(language: str) -> str:
+ # noqa comment: variety, not security — any pool member is equally safe.
+ return random.choice(_delegate_bridge_texts(language)) # noqa: S311
def _normalized_bridge_text(text: str) -> str:
return " ".join(str(text or "").strip().rstrip(".!?¡¿").casefold().split())
-def _delegate_bridge_prompt(*, language: str) -> str:
+def _delegate_bridge_prompt(*, language: str, exact_text: str) -> str:
"""Order one orchestrator-owned interim line over delegate dead air.
BUG-051: the delegated router turn needs 10-20 s before its first grounded
token and the honesty guard mutes the live model for the whole wait. This
injected instruction is the only sanctioned way to break that silence: the
- live model may speak only one fixed, short progress line. Its transcript and
- audio remain withheld until the complete response matches that exact line.
+ live model may speak only one short progress line chosen by the
+ orchestrator. Its transcript and audio remain withheld until the complete
+ response matches that line.
+
+ The line is framed as the model's own words, never as a quotation to
+ perform: Gemini's native-audio voice read the earlier quote framing as a
+ role-play cue and delivered the line in a different (female, distorted)
+ voice than the rest of the conversation (live forensic 2026-07-17 08:47).
"""
language_name = _LANGUAGE_NAMES.get(language, "the conversation language")
- exact_text = _delegate_bridge_text(language)
return (
"The Jarvis orchestrator is still executing the user's request and "
- "has no result yet. Speak the exact quoted sentence below in "
- f"{language_name}, with no added or changed words:\n"
- f'"{exact_text}"\n'
- "Do not call any function and do not mention these instructions."
+ f"has no result yet. Tell the user, in {language_name}, that you are "
+ "still working on it, by saying exactly this sentence and nothing "
+ f"else:\n{exact_text}\n"
+ "Say it as yourself, continuing in exactly the same voice, tone, and "
+ "pace as your previous replies in this conversation. Do not imitate "
+ "another person, do not change or dramatize your voice. Do not call "
+ "any function and do not mention these instructions."
)
@@ -361,6 +396,10 @@ class _DelegateTurnState:
dispatch_started: bool = False
bridge_delivery_started: bool = False
bridge_preempted: bool = False
+ # The progress line chosen for THIS bridge run; the transcript validator
+ # matches against it (and the closed per-language pool) so a varied line
+ # can never smuggle free-form model output past the withhold.
+ bridge_expected_text: str = ""
bridge_transcript_parts: list[str] = field(default_factory=list)
bridge_audio_chunks: list[Any] = field(default_factory=list)
wait_for_provider_boundary: bool = False
@@ -1455,11 +1494,27 @@ class RealtimeVoiceSession:
bridge_text = "".join(
delegate_state.bridge_transcript_parts
).strip()
- expected_bridge = _delegate_bridge_text(self._language)
+ # Accept only the line chosen for this bridge run or
+ # another member of the closed per-language pool (the
+ # language may have shifted between injection and
+ # validation); anything else is free-form output.
+ allowed_bridge_lines = {
+ _normalized_bridge_text(candidate)
+ for candidate in _delegate_bridge_texts(
+ self._language
+ )
+ }
+ expected_bridge = (
+ delegate_state.bridge_expected_text
+ or next(iter(_delegate_bridge_texts(self._language)))
+ )
+ allowed_bridge_lines.add(
+ _normalized_bridge_text(expected_bridge)
+ )
bridge_valid = bool(
bridge_completed
and _normalized_bridge_text(bridge_text)
- == _normalized_bridge_text(expected_bridge)
+ in allowed_bridge_lines
)
bridge_may_speak = bool(
bridge_valid
@@ -1501,7 +1556,22 @@ class RealtimeVoiceSession:
# the final answer will open a new SPEAKING segment.
await self._send_json({"type": "thinking"})
if bridge_was_audible:
- await self._publish_delegate_bridge_spoken(expected_bridge)
+ # Persist the pool line the model actually spoke,
+ # not merely the one requested for this run.
+ spoken_bridge = next(
+ (
+ candidate
+ for candidate in _delegate_bridge_texts(
+ self._language
+ )
+ if _normalized_bridge_text(candidate)
+ == _normalized_bridge_text(bridge_text)
+ ),
+ expected_bridge,
+ )
+ await self._publish_delegate_bridge_spoken(
+ spoken_bridge
+ )
self._output_samples_sent = 0
log.debug(
"realtime[%s] held provider turn_complete for "
@@ -2867,8 +2937,9 @@ class RealtimeVoiceSession:
The bridge is realtime-only and deliberately later than the classic
pipeline acknowledgement: normal delegated turns should finish before
it. Its provider output is buffered and accepted only when the complete
- transcript matches the fixed localized progress line. A ready trusted
- result preempts the bridge lifecycle.
+ transcript matches the progress line chosen for this run (or another
+ member of the closed localized pool). A ready trusted result preempts
+ the bridge lifecycle.
"""
try:
try:
@@ -2890,6 +2961,9 @@ class RealtimeVoiceSession:
return
turn_state.bridge_delivery_started = True
turn_state.bridge_preempted = False
+ turn_state.bridge_expected_text = _pick_delegate_bridge_text(
+ self._language
+ )
turn_state.bridge_transcript_parts.clear()
turn_state.bridge_audio_chunks.clear()
# ``send_text`` starts a distinct provider response. The trusted
@@ -2901,7 +2975,10 @@ class RealtimeVoiceSession:
self._drop_provider_output_until_new_response = False
try:
await send_text(
- _delegate_bridge_prompt(language=self._language)
+ _delegate_bridge_prompt(
+ language=self._language,
+ exact_text=turn_state.bridge_expected_text,
+ )
)
except Exception: # noqa: BLE001 — a broken bridge must not hurt the action
turn_state.bridge_delivery_started = False
diff --git a/tests/unit/realtime/test_session.py b/tests/unit/realtime/test_session.py
index 95861d10f6..a167b298b9 100644
--- a/tests/unit/realtime/test_session.py
+++ b/tests/unit/realtime/test_session.py
@@ -2542,10 +2542,18 @@ async def test_turn_after_a_pending_action_may_not_claim_an_outcome():
class _SlowDelegateBridgeSession(FakeSession):
"""Slow delegate: expose the dead-air window between dispatch and result."""
- def __init__(self, events, *, bridge_sent, result_delivered):
+ def __init__(
+ self,
+ events,
+ *,
+ bridge_sent,
+ result_delivered,
+ bridge_line="I'm still working on it.",
+ ):
super().__init__(events)
self._bridge_sent = bridge_sent
self._result_delivered = result_delivered
+ self._bridge_line = bridge_line
async def receive(self):
yield RealtimeEvent(
@@ -2556,7 +2564,7 @@ class _SlowDelegateBridgeSession(FakeSession):
await self._bridge_sent.wait()
yield RealtimeEvent(
type="output_transcript_delta",
- text="I'm still working on it.",
+ text=self._bridge_line,
)
yield RealtimeEvent(
type="audio_delta",
@@ -2593,10 +2601,17 @@ class _SlowDelegateBridgeSession(FakeSession):
class _SlowDelegateBridgeProvider(FakeProvider):
- def __init__(self, *, bridge_sent, result_delivered):
+ def __init__(
+ self,
+ *,
+ bridge_sent,
+ result_delivered,
+ bridge_line="I'm still working on it.",
+ ):
super().__init__([])
self._bridge_sent = bridge_sent
self._result_delivered = result_delivered
+ self._bridge_line = bridge_line
async def open_session(self, cfg):
self.opened_with = cfg
@@ -2604,6 +2619,7 @@ class _SlowDelegateBridgeProvider(FakeProvider):
[],
bridge_sent=self._bridge_sent,
result_delivered=self._result_delivered,
+ bridge_line=self._bridge_line,
)
return self.session
@@ -2612,6 +2628,11 @@ class _SlowDelegateBridgeProvider(FakeProvider):
async def test_slow_deterministic_delegate_speaks_a_bridge_line(monkeypatch):
"""BUG-051: dead air between dispatch and result gets one interim line."""
monkeypatch.setattr("jarvis.realtime.session._DELEGATE_BRIDGE_DELAY_S", 0.05)
+ # Pin the varied progress-line pick to the line the fake session speaks.
+ monkeypatch.setattr(
+ "jarvis.realtime.session._pick_delegate_bridge_text",
+ lambda language: "I'm still working on it.",
+ )
gate = asyncio.Event()
bridge_sent = asyncio.Event()
result_delivered = asyncio.Event()
@@ -2643,7 +2664,11 @@ async def test_slow_deterministic_delegate_speaks_a_bridge_line(monkeypatch):
bridge = provider.session.text_inputs[0]
assert "<trusted_action_result>" not in bridge
- assert '"I\'m still working on it."' in bridge
+ assert "I'm still working on it." in bridge
+ # The line is framed as the model's own words, never a quote to perform
+ # (a quoted line flipped Gemini's native voice, forensic 2026-07-17).
+ assert '"I\'m still working on it."' not in bridge
+ assert "same voice" in bridge
assert "Write this to my wiki." not in bridge
# While the bridge response is live, provider output must flow.
assert sess._must_withhold_provider_output() is False
@@ -2669,6 +2694,64 @@ async def test_slow_deterministic_delegate_speaks_a_bridge_line(monkeypatch):
await sess.end(reason="test")
+async def test_varied_bridge_line_passes_validation_and_is_persisted(monkeypatch):
+ """A non-default pool line must clear the withhold and reach the record.
+
+ Live feedback 2026-07-17 08:47: the single fixed "Ich bin noch dran."
+ line read robotic. The progress line now varies per bridge run; the
+ validator accepts exactly the closed localized pool.
+ """ # i18n-allow: quoted German forensic phrase
+ varied_line = "One moment, almost there."
+ monkeypatch.setattr("jarvis.realtime.session._DELEGATE_BRIDGE_DELAY_S", 0.05)
+ monkeypatch.setattr(
+ "jarvis.realtime.session._pick_delegate_bridge_text",
+ lambda language: varied_line,
+ )
+ gate = asyncio.Event()
+ bridge_sent = asyncio.Event()
+ result_delivered = asyncio.Event()
+ brain = FakeBrain(replies=("Stored on your page: note.",), gate=gate)
+ provider = _SlowDelegateBridgeProvider(
+ bridge_sent=bridge_sent,
+ result_delivered=result_delivered,
+ bridge_line=varied_line,
+ )
+ thinking_sent = asyncio.Event()
+
+ class _StatusMessages(list[dict]):
+ def append(self, message: dict) -> None:
+ super().append(message)
+ if message == {"type": "thinking"}:
+ thinking_sent.set()
+
+ jsons = _StatusMessages()
+ binaries: list[bytes] = []
+ bus = FakeBus()
+ sess = _session(
+ provider,
+ brain=brain,
+ jsons=jsons,
+ binaries=binaries,
+ bus=bus,
+ )
+
+ await sess.handle_control({"type": "audio_start", "sample_rate": 16_000})
+ await asyncio.wait_for(bridge_sent.wait(), timeout=2)
+ assert varied_line in provider.session.text_inputs[0]
+
+ await asyncio.wait_for(thinking_sent.wait(), timeout=2)
+ gate.set()
+ await asyncio.wait_for(result_delivered.wait(), timeout=2)
+ await sess.wait_finished()
+ spoken = [event for event in bus.events if isinstance(event, SpeechSpoken)]
+ assert [(event.text, event.spoken_kind) for event in spoken] == [
+ (varied_line, "progress"),
+ ("Stored on your page: note.", "reply"),
+ ]
+ await sess.end(reason="test")
+
+
class _StalledPromiseSession(FakeSession):
"""Answer with an unbacked action promise, then never complete the turn.