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.

refactor(realtime): grow the session protocol to match its widest adapter

rubenluetke10-beep605d6bda2fe6
diff --git a/jarvis/plugins/realtime/gemini_live.py b/jarvis/plugins/realtime/gemini_live.py
index c8f1b594ac..6f565e7d5e 100644
--- a/jarvis/plugins/realtime/gemini_live.py
+++ b/jarvis/plugins/realtime/gemini_live.py
@@ -336,10 +336,14 @@ class _GeminiLiveSession:
instructions: str | None = None,
language: str | None = None,
tools: tuple[dict[str, Any], ...] | None = None,
+ turn_directive: str | None = None,
) -> None:
# Gemini fixes system instructions at connect time. The orchestrator
# reconnects on a substantive language change in a later session.
- del instructions, language, tools
+ # Accepting turn_directive keeps the per-turn update off the
+ # session's TypeError-retry path; the directive is already embedded
+ # in the (fixed) instructions.
+ del instructions, language, tools, turn_directive
async def request_response(self, *, required_tool: str | None = None) -> None:
# Gemini Live creates a response automatically at the VAD turn boundary.
diff --git a/jarvis/plugins/realtime/openai_realtime.py b/jarvis/plugins/realtime/openai_realtime.py
index f86587823f..4bcfda04f0 100644
--- a/jarvis/plugins/realtime/openai_realtime.py
+++ b/jarvis/plugins/realtime/openai_realtime.py
@@ -583,8 +583,13 @@ class _OpenAIRealtimeSession:
instructions: str | None = None,
language: str | None = None,
tools: tuple[dict[str, Any], ...] | None = None,
+ turn_directive: str | None = None,
) -> None:
del language # Input transcription stays provider-inferred and multilingual.
+ # This transport REPLACES its instructions wholesale, and the turn
+ # directive is already embedded in them. Accepting the keyword keeps
+ # the per-turn update off the session's TypeError-retry path.
+ del turn_directive
update: dict[str, Any] = {"type": "realtime"}
if instructions is not None:
update["instructions"] = instructions
diff --git a/jarvis/realtime/protocol.py b/jarvis/realtime/protocol.py
index c0030e64f5..d235a066d8 100644
--- a/jarvis/realtime/protocol.py
+++ b/jarvis/realtime/protocol.py
@@ -157,12 +157,28 @@ class RealtimeSession(Protocol):
instructions: str | None = None,
language: str | None = None,
tools: tuple[dict[str, Any], ...] | None = None,
+ # Turn-scoped directive, delivered separately so an APPEND-only
+ # transport can supersede the previous one whole instead of leaving
+ # contradictory "this current turn" texts standing. Adapters that
+ # replace their instructions wholesale may simply ``del`` it — the
+ # same text is already embedded in ``instructions``. The session
+ # retries without it on TypeError for third-party adapters.
+ turn_directive: str | None = None,
) -> None: ...
async def request_response(self, *, required_tool: str | None = None) -> None: ...
async def send_text(self, text: str) -> None: ...
async def truncate(self, audio_end_ms: int) -> None: ...
- async def interrupt(self) -> None: ...
+ async def interrupt(
+ self,
+ *,
+ # True ONLY on the delegation/handoff paths: the interrupted
+ # utterance's one automatic-response entitlement is withdrawn with
+ # the cut. A plain barge-in must never set it — at that moment the
+ # input generation already belongs to the user's NEW utterance, and
+ # retiring it silences the answer to the question just asked.
+ retire_input_entitlement: bool = False,
+ ) -> None: ...
async def send_tool_result(
self, call_id: str, name: str, result: dict[str, Any]
) -> None: ...
diff --git a/jarvis/realtime/scrub_gate.py b/jarvis/realtime/scrub_gate.py
index 283296ebfe..345055cc41 100644
--- a/jarvis/realtime/scrub_gate.py
+++ b/jarvis/realtime/scrub_gate.py
@@ -73,13 +73,14 @@ _COVERAGE_MS_PER_CHAR = 55.0
# by the deliberate underestimation alone; log it as a transcription stall.
_FINALIZE_EXCESS_LOG_MS = 5_000.0
# Release budget for ONE injected direct-speech utterance — an OVERestimate
-# of its rendering time (the opposite direction of _COVERAGE_MS_PER_CHAR's
-# deliberate underestimate: 2x that rate, so a real voice can never outrun
-# it). Clamping the trusted answer itself would recreate "the action ran and
-# the user heard nothing", so the bound must stay generous — but not so
-# generous it misses the incident class it exists for: the live 2026-08-04
-# case was 8.2 s of foreign audio riding a stall-phrase-length clearance,
-# which a 10 s floor would have waved through entirely.
+# of its rendering time. 110 ms/char is ~1.5x the SLOWEST real voice this
+# module has measured (Gemini Live German, ~14 chars/s = ~71 ms/char), so a
+# legitimate readback keeps headroom at every length while the floor covers
+# leading pauses on short phrases. Clamping the trusted answer itself would
+# recreate "the action ran and the user heard nothing", so the bound must
+# stay generous — but not so generous it misses the incident class it exists
+# for: the live 2026-08-04 case was 8.2 s of foreign audio riding a
+# stall-phrase-length clearance, which a 10 s floor waved through entirely.
_DIRECT_SPEECH_MS_PER_CHAR = 110.0
_DIRECT_SPEECH_BUDGET_FLOOR_MS = 3_000.0