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): re-arm the session contract when a server sends an unsolicited response (BUG-064)

Ruben Lütke2d2900eba045
diff --git a/docs/BUGS.md b/docs/BUGS.md
index 99c0d598ca..d995c37b19 100644
--- a/docs/BUGS.md
+++ b/docs/BUGS.md
@@ -4491,3 +4491,72 @@ carry the conversation: any harness goal built from a single utterance is
wrong for every follow-up, correction, and instrument-naming turn. And a
recovery path that already holds the complete user text must never refuse to
act because a provider wire event failed to arrive.
+
+## BUG-064: Grok realtime session goes permanently deaf after a barge-in cancel — server drops the session contract (HIGH, FIXED 2026-07-16)
+
+**Symptom.** Desktop realtime session on `grok-realtime`, 2026-07-16 08:07
+(session `3cefaede`, exported as `voice-session-2026-07-16_08-07-constable.md`).
+Turn 1 ("Constable.") completed normally. Turn 2 was cut short by server VAD
+("Can you please" — the user paused mid-sentence), Jarvis requested a
+response, and 362 ms later the user resumed speaking, so the barge-in path
+cancelled the in-flight response (`realtime_cancel … reason=barge_in`). From
+that moment the user kept talking for over 80 seconds: the taskbar/JarvisBar
+audio indicators kept reacting (local mic level + server VAD both alive), but
+**no transcription ever appeared again, no turn started, and Jarvis never
+answered** until the user hung up via hotkey at 08:09:02. The exported
+transcript therefore ends after two turns although substantially more was
+said.
+
+**Evidence.** `data/jarvis_desktop.log` + `data/flight_recorder/2026-07-16.jsonl`:
+
+- 08:07:36.878 `LatencySpan realtime_cancel duration_ms=362 reason=barge_in`
+ — the only wire `response.cancel` of the session that hit an ACTIVE
+ response lifecycle.
+- Afterwards, five `OpenAI Realtime suppressed unsolicited response <id>`
+ warnings (08:07:57.918, 08:08:19.499, 08:08:26.469, 08:08:29.878,
+ 08:08:44.740) — the server auto-created a response at each detected end of
+ speech, which `create_response: false` forbids.
+- Zero `conversation.item.input_audio_transcription.completed` **and** zero
+ `.failed` events after turn 2 — the deafness is server-side; the client
+ pump was demonstrably alive (it processed and suppressed the five
+ responses).
+- Contrast: the same suppression on `openai-realtime` (2026-07-15 11:03:03)
+ occurred once, was followed by the benign `response_cancel_not_active`
+ error, and the session continued normally — the wedge is Grok-specific.
+
+**Root cause.** The barge-in `response.cancel` of an active response left the
+xAI server without the session contract Jarvis configured at open: input
+transcription (`grok-transcribe`) stopped producing events and manual
+response mode (`turn_detection.create_response: false`) reverted to automatic
+— both live in the same `audio.input` session block, consistent with the
+server dropping/reverting session state. The client correctly cancelled each
+unsolicited response (the exactly-one-response invariant held; no stray audio
+reached the speaker) but had no path that ever RESTORED the contract, so the
+session stayed connected, listening, and deaf until manual hang-up.
+
+**Fix.** In the shared OpenAI-compatible adapter
+(`jarvis/plugins/realtime/openai_realtime.py`, inherited by `grok_realtime`):
+the session now retains the full session payload sent at open, kept current
+by `update_session()` (live instructions/tool changes are folded in, so a
+re-arm never reverts newer state). Suppressing an unsolicited response —
+impossible in a healthy manual-response session, hence a reliable wedge
+signal — now re-sends that full payload (`_rearm_session_contract()`),
+restoring input transcription and `create_response: false` in place. The
+re-arm is throttled (5 s cooldown per burst) and fail-safe (a rejected
+session.update never kills the receive pump). On a healthy server the re-arm
+is an idempotent no-op, so the defense is provider-family-wide and free.
+
+Guards: `tests/unit/realtime/test_openai_realtime.py`
+(`test_unsolicited_response_rearms_the_full_session_contract`,
+`test_contract_rearm_is_throttled_within_a_burst`,
+`test_contract_rearm_carries_live_instruction_and_tool_updates`) and
+`tests/unit/realtime/test_grok_realtime.py`
+(`test_unsolicited_response_rearms_grok_transcription_contract`).
+
+**Class rule.** A duplex provider's session configuration is a CONTRACT, not
+an initialization detail: any event that is impossible under the configured
+contract (here: an unsolicited response under manual-response mode) is proof
+the server no longer holds it, and the client must re-assert the full
+contract instead of only suppressing the symptom. Suppression without
+restoration turns one server-side hiccup into an unbounded silent outage that
+the user experiences as "it hears me (indicators fire) but nothing happens."
diff --git a/jarvis/plugins/realtime/grok_realtime.py b/jarvis/plugins/realtime/grok_realtime.py
index 9e3d1d4535..3aef8bc500 100644
--- a/jarvis/plugins/realtime/grok_realtime.py
+++ b/jarvis/plugins/realtime/grok_realtime.py
@@ -82,14 +82,16 @@ class GrokRealtimeProvider:
)
raise
+ payload = _grok_session_payload(cfg)
session = _OpenAIRealtimeSession(
connection=connection,
connection_cm=connection_cm,
client=client,
session_id=str(uuid4()),
+ session_payload=payload,
)
try:
- await connection.session.update(session=_grok_session_payload(cfg))
+ await connection.session.update(session=payload)
await session.wait_until_ready()
except BaseException:
await session.close()
diff --git a/jarvis/plugins/realtime/openai_realtime.py b/jarvis/plugins/realtime/openai_realtime.py
index 4bbb01c1a0..f70053cff0 100644
--- a/jarvis/plugins/realtime/openai_realtime.py
+++ b/jarvis/plugins/realtime/openai_realtime.py
@@ -12,6 +12,7 @@ import asyncio
import base64
import json
import logging
+import time
from collections.abc import AsyncIterator
from dataclasses import dataclass
from typing import Any
@@ -24,6 +25,14 @@ _INPUT_RATE = 24_000
_OUTPUT_RATE = 24_000
_HANDSHAKE_TIMEOUT_S = 12.0
_RESPONSE_REQUEST_METADATA_KEY = "jarvis_request_id"
+# BUG-064: an unsolicited response is proof the server no longer honors the
+# manual-response contract (``create_response: false``). One xAI Grok live
+# session additionally stopped emitting input transcription events after a
+# legitimate barge-in ``response.cancel`` — the session stayed connected but
+# went permanently deaf. Re-sending the full session payload restores both
+# halves of the contract; the cooldown keeps a burst of unsolicited responses
+# from turning into a session.update storm.
+_CONTRACT_REARM_COOLDOWN_S = 5.0
# Benign response-lifecycle races (BUG-053/BUG-056): both sides of the same
# boundary. ``conversation_already_has_active_response`` = our response.create
# arrived while one was still running; ``response_cancel_not_active`` = our
@@ -177,12 +186,18 @@ class _OpenAIRealtimeSession:
connection_cm: Any,
client: Any,
session_id: str,
+ session_payload: dict[str, Any] | None = None,
) -> None:
self._conn = connection
self._connection_cm = connection_cm
self._client = client
self._events = connection.__aiter__()
self.session_id = session_id
+ # The full session contract as sent at open. Kept current by
+ # update_session() so a BUG-064 re-arm never reverts live
+ # instructions or tool declarations to their session-start values.
+ self._session_contract = session_payload
+ self._last_contract_rearm = float("-inf")
self._last_item_id = ""
self._response_had_tool_calls = False
self._tool_response_done_seen = False
@@ -346,6 +361,10 @@ class _OpenAIRealtimeSession:
]
update["tool_choice"] = "auto" if update["tools"] else "none"
if len(update) > 1:
+ if self._session_contract is not None:
+ for key in ("instructions", "tools", "tool_choice"):
+ if key in update:
+ self._session_contract[key] = update[key]
await self._conn.session.update(session=update)
async def request_response(self, *, required_tool: str | None = None) -> None:
@@ -486,6 +505,15 @@ class _OpenAIRealtimeSession:
"OpenAI Realtime unsolicited response cancel failed",
exc_info=True,
)
+ # BUG-064: under the manual-response contract an unsolicited
+ # response should be impossible — its arrival means the server
+ # dropped the session configuration (observed live on grok-realtime
+ # 2026-07-16 08:07: after a barge-in cancel, input transcription
+ # stopped and server VAD auto-created responses; the session sat
+ # deaf until manual hang-up). Re-assert the full contract so the
+ # session hears again; on a healthy server this is an idempotent
+ # no-op.
+ await self._rearm_session_contract()
return
if not response_id:
@@ -496,6 +524,33 @@ class _OpenAIRealtimeSession:
return
self._accepted_response_ids.add(response_id)
+ async def _rearm_session_contract(self) -> None:
+ """Re-send the full session payload after an unsolicited response.
+
+ Restores input transcription and ``create_response: false`` when the
+ server silently dropped them (BUG-064). Throttled so a burst of
+ unsolicited responses re-arms once, and fail-safe so a rejected
+ session.update can never take down the receive pump.
+ """
+ if self._session_contract is None or self._closed:
+ return
+ now = time.monotonic()
+ if now - self._last_contract_rearm < _CONTRACT_REARM_COOLDOWN_S:
+ return
+ self._last_contract_rearm = now
+ log.warning(
+ "OpenAI Realtime re-arming the session contract (input "
+ "transcription + manual-response mode) after an unsolicited "
+ "response — the server may have dropped session state"
+ )
+ try:
+ await self._conn.session.update(session=self._session_contract)
+ except Exception: # noqa: BLE001 -- the pump must survive a failed re-arm
+ log.debug(
+ "OpenAI Realtime session contract re-arm failed",
+ exc_info=True,
+ )
+
def _response_is_accepted(self, event: Any) -> bool:
response_id = self._event_response_id(event)
if response_id:
@@ -575,14 +630,16 @@ class OpenAIRealtimeProvider:
exc_info=True,
)
raise
+ payload = _session_payload(cfg)
session = _OpenAIRealtimeSession(
connection=connection,
connection_cm=connection_cm,
client=client,
session_id=str(uuid4()),
+ session_payload=payload,
)
try:
- await connection.session.update(session=_session_payload(cfg))
+ await connection.session.update(session=payload)
await session.wait_until_ready()
except BaseException:
await session.close()
diff --git a/tests/unit/realtime/test_grok_realtime.py b/tests/unit/realtime/test_grok_realtime.py
index 7ac3a2d2ef..196252e5e3 100644
--- a/tests/unit/realtime/test_grok_realtime.py
+++ b/tests/unit/realtime/test_grok_realtime.py
@@ -210,6 +210,45 @@ async def test_default_model_audio_and_xai_events_are_mapped(
await session.close()
+async def test_unsolicited_response_rearms_grok_transcription_contract(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ """BUG-064 (live incident 2026-07-16 08:07): after a barge-in cancel the
+ Grok server stopped emitting input transcription events and auto-created
+ responses — the session stayed connected but permanently deaf. Suppressing
+ such an unsolicited response must re-send the full Grok session payload,
+ including the grok-transcribe input transcription."""
+ _patch_client(monkeypatch)
+ session = await GrokRealtimeProvider(api_key="xai-test").open_session(
+ RealtimeSessionConfig()
+ )
+ client = _FakeAsyncOpenAI.last
+ assert client is not None
+ conn = client.realtime.conn
+ conn._events = iter(
+ [
+ SimpleNamespace(
+ type="response.created",
+ response=SimpleNamespace(id="resp-auto", metadata=None),
+ ),
+ ]
+ )
+ session._events = conn.__aiter__()
+
+ events = [event async for event in session.receive()]
+
+ assert events == []
+ assert conn.response_cancels == ["resp-auto"]
+ assert len(conn.session_updates) == 2
+ rearmed = conn.session_updates[-1]
+ assert rearmed["audio"]["input"]["transcription"] == {
+ "model": "grok-transcribe"
+ }
+ assert rearmed["audio"]["input"]["turn_detection"]["create_response"] is False
+ await session.close()
+
+
@pytest.mark.asyncio
async def test_keyless_provider_is_unavailable() -> None:
assert await GrokRealtimeProvider().can_open_duplex_session() is False
diff --git a/tests/unit/realtime/test_openai_realtime.py b/tests/unit/realtime/test_openai_realtime.py
index 5b6a958f3d..107a52c396 100644
--- a/tests/unit/realtime/test_openai_realtime.py
+++ b/tests/unit/realtime/test_openai_realtime.py
@@ -823,6 +823,119 @@ async def test_response_cancel_not_active_error_is_recoverable(
await session.close()
+async def test_unsolicited_response_rearms_the_full_session_contract(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ """BUG-064: an unsolicited response means the server dropped the
+ manual-response contract (live grok-realtime 2026-07-16 08:07: after a
+ barge-in cancel the session went permanently deaf — no input transcription
+ events, server VAD auto-created responses). Suppression must re-send the
+ FULL session payload so transcription and ``create_response: false`` are
+ restored."""
+ holder = _patch_openai_client(monkeypatch)
+ session = await OpenAIRealtimeProvider(api_key="test-key").open_session(
+ RealtimeSessionConfig()
+ )
+ conn = holder["client"].realtime.last_conn
+ conn._events = iter(
+ [
+ SimpleNamespace(
+ type="response.created",
+ response=SimpleNamespace(id="resp-auto", metadata=None),
+ ),
+ SimpleNamespace(
+ type="response.done",
+ response=SimpleNamespace(id="resp-auto"),
+ ),
+ ]
+ )
+ session._events = conn.__aiter__()
+
+ events = [event async for event in session.receive()]
+
+ assert events == []
+ assert conn.response_cancels == ["resp-auto"]
+ assert len(conn.session_updates) == 2
+ rearmed = conn.session_updates[-1]
+ assert rearmed == conn.session_updates[0]
+ assert rearmed["audio"]["input"]["transcription"]["model"]
+ assert rearmed["audio"]["input"]["turn_detection"]["create_response"] is False
+ await session.close()
+
+
+async def test_contract_rearm_is_throttled_within_a_burst(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ """BUG-064: a burst of unsolicited responses re-arms the contract once per
+ cooldown window; every response in the burst is still cancelled."""
+ holder = _patch_openai_client(monkeypatch)
+ session = await OpenAIRealtimeProvider(api_key="test-key").open_session(
+ RealtimeSessionConfig()
+ )
+ conn = holder["client"].realtime.last_conn
+ conn._events = iter(
+ [
+ SimpleNamespace(
+ type="response.created",
+ response=SimpleNamespace(id="resp-auto-1", metadata=None),
+ ),
+ SimpleNamespace(
+ type="response.created",
+ response=SimpleNamespace(id="resp-auto-2", metadata=None),
+ ),
+ ]
+ )
+ session._events = conn.__aiter__()
+
+ events = [event async for event in session.receive()]
+
+ assert events == []
+ assert conn.response_cancels == ["resp-auto-1", "resp-auto-2"]
+ assert len(conn.session_updates) == 2
+ await session.close()
+
+
+async def test_contract_rearm_carries_live_instruction_and_tool_updates(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ """BUG-064: the re-armed payload must reflect the LATEST live session
+ state — re-asserting the contract must never revert instructions or tool
+ declarations to their session-start values."""
+ holder = _patch_openai_client(monkeypatch)
+ session = await OpenAIRealtimeProvider(api_key="test-key").open_session(
+ RealtimeSessionConfig(instructions="Session-start instructions.")
+ )
+ conn = holder["client"].realtime.last_conn
+ declaration = {
+ "name": "late_tool",
+ "description": "A tool connected mid-session.",
+ "parameters": {"type": "object", "properties": {}},
+ }
+ await session.update_session(
+ instructions="Turn-updated instructions.", tools=(declaration,)
+ )
+ conn._events = iter(
+ [
+ SimpleNamespace(
+ type="response.created",
+ response=SimpleNamespace(id="resp-auto", metadata=None),
+ ),
+ ]
+ )
+ session._events = conn.__aiter__()
+
+ _ = [event async for event in session.receive()]
+
+ rearmed = conn.session_updates[-1]
+ assert rearmed["instructions"] == "Turn-updated instructions."
+ assert rearmed["tools"] == [{"type": "function", **declaration}]
+ assert rearmed["audio"]["input"]["turn_detection"]["create_response"] is False
+ await session.close()
+
+
@pytest.mark.asyncio
async def test_interrupt_skips_wire_cancel_when_no_response_active(
monkeypatch: pytest.MonkeyPatch,