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): never let a wedged server's own emissions reset the deaf-wedge defenses (BUG-064 recurrence #4)

Ruben Lütke67b2e427b2df
diff --git a/docs/BUGS.md b/docs/BUGS.md
index 7a85e11cd3..128c0bd112 100644
--- a/docs/BUGS.md
+++ b/docs/BUGS.md
@@ -4653,6 +4653,35 @@ watchdog, otherwise one swallowed terminal event freezes every dependent
defense simultaneously — and the freeze is invisible because each defense
individually looks correctly disarmed.
+**Recurrence #4, 2026-07-16 11:23 — the wedge feeds the watchdogs (session
+`a69d2318`, first live run WITH the recurrence-#3 stall watchdog).** Turn 1
+("Wie viel Geld hat", VAD-truncated mid-sentence) was cancelled by the local <!-- i18n-allow: quoted German user utterance under forensic analysis -->
+barge-in; the requested response's lifecycle hung again (idle clear). This
+time BOTH remaining defenses were disarmed by the wedge's own emissions:
+(1) the deaf server emitted transcription FAILED events, which
+`_note_input_transcript()` counted as "re-arm heeded" — so the
+stray-after-unheeded-re-arm escalation saw a healed session and re-armed
+forever; (2) the server auto-created stray responses every ~7.8 s — just
+under `_RESPONSE_STALL_S` (8 s) — and every stray stamped
+`_last_response_activity`, keeping the dead lifecycle looking alive. The
+session sat mute 16 s until manual hang-up.
+
+**Fixes (same adapter).** (1) A failed transcript settles the per-turn
+contract debt (deadline cleared) but no longer marks a re-arm as heeded —
+only a COMPLETED transcript proves the transcription side works
+(`_note_input_transcript(restored_hearing=False)` on failed). (2) Only an
+ACCEPTED response's events stamp the stall clock; unsolicited strays are
+wedge symptoms, not liveness. Accept/adopt paths stamp explicitly. Guards:
+`test_failed_transcription_does_not_mark_rearm_as_heeded`,
+`test_unsolicited_stray_does_not_feed_the_stall_watchdog`.
+
+**Class rule (final form).** When a server is misbehaving, its OWN emissions
+must never count as evidence of health for any watchdog that exists to catch
+that misbehavior — classify every inbound signal as symptom or proof-of-cure
+FIRST, and let only proof-of-cure reset a defense. A wedge that emits
+symptoms on a timer will otherwise starve every timeout-based defense
+forever.
+
## BUG-065: macOS/Linux desktop shows a permanent OFFLINE — WebKit drops the HttpOnly session cookie from WebSocket handshakes (HIGH, FIXED 2026-07-16)
**Symptom (real Mac hardware, 2026-07-15).** During and after boot the macOS
diff --git a/jarvis/plugins/realtime/openai_realtime.py b/jarvis/plugins/realtime/openai_realtime.py
index 86c5915d19..29eaccb3bd 100644
--- a/jarvis/plugins/realtime/openai_realtime.py
+++ b/jarvis/plugins/realtime/openai_realtime.py
@@ -365,16 +365,18 @@ class _OpenAIRealtimeSession:
async def _dispatch_event(self, event: Any) -> AsyncIterator[_ProviderEvent]:
event_type = str(getattr(event, "type", "") or "")
- if event_type.startswith("response."):
- # Any response event — accepted or not — is proof the response
- # pipeline is alive; only its total absence marks a stalled
- # lifecycle (BUG-064 recurrence #3).
- self._last_response_activity = time.monotonic()
if event_type == "response.created":
await self._handle_response_created(event)
return
- if event_type.startswith("response.") and not self._response_is_accepted(event):
- return
+ if event_type.startswith("response."):
+ if not self._response_is_accepted(event):
+ return
+ # Only an ACCEPTED response's events are liveness for the
+ # lifecycle we are waiting on. Unsolicited strays must not feed
+ # this clock: the wedged Grok server auto-created strays every
+ # ~7.8 s (2026-07-16 11:23), keeping a dead lifecycle looking
+ # alive just under the 8 s stall threshold forever.
+ self._last_response_activity = time.monotonic()
if event_type == "response.output_audio.delta":
self._last_item_id = str(getattr(event, "item_id", "") or "")
yield _ProviderEvent(
@@ -401,7 +403,12 @@ class _OpenAIRealtimeSession:
# The model still has the committed audio in conversation
# context. Let the orchestrator fail open to a spoken response,
# while withholding tools because no auditable text exists.
- self._note_input_transcript()
+ # A FAILED transcript settles the per-turn contract debt but is
+ # NOT proof the transcription side works again — treating it as
+ # restored hearing kept re-arming a deaf Grok session forever
+ # (2026-07-16 11:23: the wedge emitted failed events, so the
+ # stray-after-unheeded-re-arm escalation never fired).
+ self._note_input_transcript(restored_hearing=False)
yield _ProviderEvent(
type="input_transcript",
text="",
@@ -663,6 +670,7 @@ class _OpenAIRealtimeSession:
)
self._response_idle.clear()
self._accepted_response_ids.add(response_id)
+ self._last_response_activity = time.monotonic()
self._server_heard_user_since_response = False
self._auto_adopted_unanswered_input = True
await self._rearm_session_contract()
@@ -721,6 +729,7 @@ class _OpenAIRealtimeSession:
)
return
self._accepted_response_ids.add(response_id)
+ self._last_response_activity = time.monotonic()
# This lifecycle now answers the pending user turn; only NEW speech
# evidence may qualify a later unsolicited response for adoption.
self._server_heard_user_since_response = False
@@ -753,11 +762,17 @@ class _OpenAIRealtimeSession:
exc_info=True,
)
- def _note_input_transcript(self) -> None:
- """Any input transcript proves the server can still hear."""
+ def _note_input_transcript(self, *, restored_hearing: bool = True) -> None:
+ """An input transcript settles the per-turn contract debt.
+
+ Only a COMPLETED transcript additionally proves the transcription
+ side works (``restored_hearing``); a failed one merely shows the
+ event pipeline is alive while the session may still be deaf.
+ """
self._last_transcript_at = time.monotonic()
self._transcript_deadline = None
- self._transcript_heard_since_rearm = True
+ if restored_hearing:
+ self._transcript_heard_since_rearm = True
# The manual flow answers transcribed turns itself; a crossing
# auto-response is now a duplicate, not a salvageable answer.
self._server_heard_user_since_response = False
diff --git a/tests/unit/realtime/test_openai_realtime.py b/tests/unit/realtime/test_openai_realtime.py
index 414fb891ab..ff973f8928 100644
--- a/tests/unit/realtime/test_openai_realtime.py
+++ b/tests/unit/realtime/test_openai_realtime.py
@@ -1366,3 +1366,125 @@ async def test_accepted_response_without_done_stalls_and_rebuilds(
assert [event.type for event in events] == ["input_transcript"]
assert events[0].text == "Heard again"
await session.close()
+
+
+async def test_failed_transcription_does_not_mark_rearm_as_heeded(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ """BUG-064 recurrence #4 (grok-realtime 2026-07-16 11:23, session
+ a69d2318): the deaf server emitted transcription FAILED events, which
+ counted as "the re-arm restored hearing" — so the
+ stray-after-unheeded-re-arm escalation never fired and the session
+ re-armed forever until manual hang-up. A failed transcript settles the
+ per-turn contract debt but proves nothing about the transcription side:
+ only a COMPLETED transcript may mark a re-arm as heeded."""
+ holder = _patch_openai_client(monkeypatch)
+ monkeypatch.setattr(openai_realtime, "_CONTRACT_REARM_COOLDOWN_S", 0.0)
+ session = await OpenAIRealtimeProvider(api_key="test-key").open_session(
+ RealtimeSessionConfig(model="gpt-realtime")
+ )
+ api = holder["client"].realtime
+ conn1 = api.last_conn
+ conn2 = _FakeConn()
+ conn2._events = iter(
+ [
+ SimpleNamespace(type="session.updated"),
+ SimpleNamespace(
+ type="conversation.item.input_audio_transcription.completed",
+ item_id="post-rebuild-1",
+ transcript="Heard again",
+ ),
+ ]
+ )
+ api.extra_conns.append(conn2)
+ conn1._events = iter(
+ [
+ SimpleNamespace(
+ type="conversation.item.input_audio_transcription.completed",
+ item_id="item-1",
+ transcript="How much money does",
+ ),
+ SimpleNamespace(
+ type="response.created",
+ response=SimpleNamespace(id="resp-stray-1", metadata=None),
+ ),
+ SimpleNamespace(
+ type="conversation.item.input_audio_transcription.failed",
+ item_id="item-2",
+ error=SimpleNamespace(code="", message="transcription failed"),
+ ),
+ SimpleNamespace(
+ type="response.created",
+ response=SimpleNamespace(id="resp-stray-2", metadata=None),
+ ),
+ ]
+ )
+ session._events = conn1.__aiter__()
+
+ events = [event async for event in session.receive()]
+
+ assert [event.type for event in events] == [
+ "input_transcript",
+ "input_transcript",
+ "error",
+ "input_transcript",
+ ]
+ assert "rebuilt" in str(events[2].error)
+ assert events[3].text == "Heard again"
+ assert conn1.response_cancels == ["resp-stray-1", "resp-stray-2"]
+ assert api.connect_calls == ["gpt-realtime", "gpt-realtime"]
+ assert session._conn is conn2
+ await session.close()
+
+
+async def test_unsolicited_stray_does_not_feed_the_stall_watchdog(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ """BUG-064 recurrence #4 (grok-realtime 2026-07-16 11:23): the wedged
+ server auto-created stray responses every ~7.8 s — just under the 8 s
+ stall threshold — and every stray stamped the response-liveness clock,
+ keeping a dead in-flight lifecycle looking alive forever. Only events of
+ an ACCEPTED response may feed the stall watchdog."""
+ holder = _patch_openai_client(monkeypatch)
+ monkeypatch.setattr(openai_realtime, "_RESPONSE_STALL_S", float("inf"))
+ session = await OpenAIRealtimeProvider(api_key="test-key").open_session(RealtimeSessionConfig())
+ conn = holder["client"].realtime.last_conn
+
+ await session.request_response()
+ conn._events = iter(
+ [
+ SimpleNamespace(
+ type="response.created",
+ response=SimpleNamespace(id="resp-live", metadata=None),
+ ),
+ ]
+ )
+ session._events = conn.__aiter__()
+ assert [event async for event in session.receive()] == []
+ assert not session._response_idle.is_set()
+
+ sentinel = 123.0
+ session._last_response_activity = sentinel
+ conn._events = iter(
+ [
+ SimpleNamespace(
+ type="response.created",
+ response=SimpleNamespace(id="resp-stray", metadata=None),
+ ),
+ SimpleNamespace(
+ type="response.output_audio.delta",
+ response_id="resp-stray",
+ item_id="item-stray",
+ delta="AAA=",
+ ),
+ ]
+ )
+ session._events = conn.__aiter__()
+ assert [event async for event in session.receive()] == []
+
+ assert session._last_response_activity == sentinel
+ assert session._rebuild_task is None
+ assert conn.response_cancels == ["resp-stray"]
+ await session.close()