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.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
fix(realtime): keep the stale-generation watch armed after a dropped phantom
Harald269a51ab80f9
diff --git a/docs/BUGS.md b/docs/BUGS.mdindex a86514e183..a3a18b55a1 100644--- a/docs/BUGS.md+++ b/docs/BUGS.md@@ -10392,3 +10392,42 @@ still discarded; `test_voice_during_the_speaker_drain_keeps_the_next_answer`(`test_vertex_live_builds_vertex_tts_with_session_voice`,`test_vertex_live_builds_on_the_project_path_without_a_key`,`test_vertex_live_without_any_credential_yields_no_surface_tts`).++## BUG-149: after a Vertex Live delegate readback the same confirmation is spoken twice — the stale-generation guard dropped the first phantom and then stood down (HIGH, FIXED 2026-08-19)++**Symptom.** Realtime voice session `e1ba9504` (2026-08-19 11:10, Vertex Live,+delegate tool mode, desktop). User: "Nova, kannst bitteschön eine Musik+abspielen vor dem Morgen?" YouTube Music played. The provider rendered+"Läuft für dich." — and ~500 ms later a second turn with EMPTY user text+spoke the truncated echo "Läuft für". Heard twice, logged twice. Reported+by the maintainer from the Mission-deck SAY lines.++**Reconstruction (flight recorder).** Turn 0: orchestrator → `youtube_music`+(21 s) → Vertex `gemini-3.7-flash` (42.7 k / 268, text_len=15) → Vertex Live+readback "Läuft für dich." Postmortem: `stale_generations_dropped=1`,+`delegate_delivery_duplicates_suppressed=0`, `turns_completed=2`. The+BUG-143/148 guard WAS live and DID drop one extra generation. Then+`_finish_stale_generation_drop` disarmed the watch on that phantom's+`turn_complete`. Vertex Live started another unprompted generation the+moment the withhold lifted (338 ms to first audio, 11.2 k / 60, no tools,+`user_text=""`). That one played.++**Fix (`jarvis/realtime/session.py::_finish_stale_generation_drop`).** The+withhold for one discarded generation still ends on its own boundary. The+watch stays armed for the rest of the 2.5 s window. Fresh evidence (user+speech, an open turn, a deliberate injection, the window) still disarms via+`_stale_generation_guard_reason`. Capability-gated the same way as+BUG-143: only `creates_responses_automatically` transports. Covers every+server-VAD family (gemini-live, vertex-live, and any later automatic+transport), not just the box that reproduced it.++**Class rule.** "Stand down when the thing you were waiting for arrives" is+wrong when the producer can emit another of the same thing. A fail-open+window is the bound; a single discarded event is not.++**Guards.** `tests/unit/realtime/test_stale_generation_after_readback.py`+(`test_second_unprompted_generation_after_a_dropped_one_is_also_discarded`+— two extras after the readback, one spoken reply, two drops;+`test_finishing_a_drop_keeps_the_watch_armed`; the original+`test_second_generation_after_readback_is_discarded_whole` now asserts the+watch stays armed).diff --git a/jarvis/realtime/session.py b/jarvis/realtime/session.pyindex d8e24c80ad..cbe7b9498a 100644--- a/jarvis/realtime/session.py+++ b/jarvis/realtime/session.py@@ -279,11 +279,16 @@ _DELEGATE_READBACK_POLL_S = 0.1# reply's remaining playback — 7.6 s and 4.6 s readbacks both slipped past a# 2.5 s window and were spoken twice (live 2026-08-18 18:40, BUG-148)._STALE_GENERATION_WINDOW_S = 2.5-# A discarded generation is released by its own boundary. Every awaited state-# in this file carries a bound (the turn stall watchdog, the late-result-# flush), and this one is no exception: a transport that loses that single-# terminal frame while the socket stays open must not leave the session deaf-# for the rest of the call. Same order as _TURN_STALL_TIMEOUT_S.+# The withhold for ONE discarded generation is released by that generation's+# own boundary. The WATCH stays armed for the rest of the window: Gemini Live+# / Vertex Live can emit a second unprompted generation the moment the first+# phantom ends (live 2026-08-19 11:10, session e1ba9504 — BUG-149: the first+# extra was dropped, then "Läuft für" played as a user-less turn). Every+# awaited state in this file carries a bound (the turn stall watchdog, the+# late-result flush), and the withhold is no exception: a transport that+# loses that single terminal frame while the socket stays open must not+# leave the session deaf for the rest of the call. Same order as+# _TURN_STALL_TIMEOUT_S._STALE_GENERATION_DROP_MAX_S = 20.0_STALE_GENERATION_TRANSCRIPT_MAX_CHARS = 400# Mid-reply audio-flow diagnostics: an audible hole inside one spoken answer@@ -2196,13 +2201,15 @@ class RealtimeVoiceSession:# plain turn re-rendering one of them is a stale ghost repeat, not a# fresh answer (live forensic 2026-07-21 11:32).self._stale_readback_refs: list[str] = []- # Stale-generation guard (BUG-143, see _STALE_GENERATION_WINDOW_S).- # ``armed_at`` is the monotonic moment a provider-rendered delegate- # readback turn closed; a generation that begins while it is armed —- # no open turn, no new user input — is discarded WHOLE (``dropping``- # stays set until that generation's own boundary), never played and- # never opened as a turn. ``transcript`` keeps what was discarded for- # the log line, bounded, so a live call can be checked afterwards.+ # Stale-generation guard (BUG-143 / BUG-149, see+ # _STALE_GENERATION_WINDOW_S). ``armed_at`` is the monotonic moment a+ # provider-rendered delegate readback turn closed; every generation+ # that begins while it is armed — no open turn, no new user input —+ # is discarded WHOLE (``dropping`` stays set until THAT generation's+ # own boundary). The watch itself stays armed until the window, a+ # fresh user turn, or a deliberate injection — one phantom's+ # boundary must not let the next one through. ``transcript`` keeps+ # what was discarded for the log line, bounded.self._stale_generation_guard_armed_at = 0.0self._stale_generation_guard_reply = ""self._stale_generation_dropping = False@@ -8009,7 +8016,8 @@ class RealtimeVoiceSession:deliberate injection opened it), the microphone carried the user'svoice after the readback ended, a server speech edge was confirmed,or the bounded window simply ran out. Each of them disarms the guard- for good — it never survives into a later turn.+ for good. A discarded generation's own boundary does NOT — that+ would let the next unprompted generation through (BUG-149)."""armed_at = self._stale_generation_guard_armed_atif not armed_at:@@ -8097,7 +8105,14 @@ class RealtimeVoiceSession:)def _finish_stale_generation_drop(self) -> None:- """The discarded generation reached its boundary: log and stand down."""+ """The discarded generation reached its boundary: release the withhold.++ The watch stays armed. Standing it down here was BUG-149: Vertex Live+ started a second unprompted generation the moment the first phantom+ closed, and that one played as a user-less turn. Fresh evidence+ (user speech, an open turn, a deliberate injection, the window)+ still disarms via ``_stale_generation_guard_reason``.+ """discarded = "".join(self._stale_generation_transcript).strip()heard = _normalize_for_repeat_match(discarded)delivered = _normalize_for_repeat_match(self._stale_generation_guard_reply)@@ -8116,7 +8131,6 @@ class RealtimeVoiceSession:self._stale_generation_dropping = Falseself._stale_generation_dropping_since = 0.0self._stale_generation_transcript.clear()- self._disarm_stale_generation_guard()async def _reject_stale_generation_tool_call(self, event: Any) -> None:"""Answer a stale generation's function call without executing it.diff --git a/tests/unit/realtime/test_stale_generation_after_readback.py b/tests/unit/realtime/test_stale_generation_after_readback.pyindex 3e1d2547bc..84d323f8a9 100644--- a/tests/unit/realtime/test_stale_generation_after_readback.py+++ b/tests/unit/realtime/test_stale_generation_after_readback.py@@ -1,4 +1,4 @@-"""Stale-generation guard after a delivered readback (BUG-143).+"""Stale-generation guard after a delivered readback (BUG-143 / BUG-149).Live forensic 2026-08-18 14:25 (session 7b20e182, turns 4/5 and 6/7): on aserver-VAD transport one Jarvis turn carried TWO turn-ending inputs on the@@ -8,6 +8,10 @@ the injected result re-rendered that same result, so the user heard "Ichhabe work geöffnet: T eins." and then "Ich habe work geöffnet: T1.", andthe recorder wrote a phantom turn with no user text for the repeat.+BUG-149 (2026-08-19, session e1ba9504): the first extra generation WAS+dropped, then ``_finish_stale_generation_drop`` disarmed the watch and+Vertex Live spoke a truncated echo on the next unprompted generation.+The session cannot cancel that second generation (Gemini has no responsecancel). It refuses to play it instead: a generation that begins right aftera provider-rendered readback with NO new user input is discarded whole,@@ -82,6 +86,9 @@ class _ServerVadWire:* ``second-generation`` — a second generation of the same reply startsimmediately after the readback boundary, with no user input at all(the live failure).+ * ``second-generation-twice`` — TWO unprompted generations after the+ readback (BUG-149: Vertex Live started another the moment the first+ phantom closed; the first was dropped, the second played).* ``after-user-input`` — the user asks a follow-up first; the provider'sanswer to it must play.* ``after-local-voice`` — no transcript yet, but the microphone carried@@ -135,9 +142,16 @@ class _ServerVadWire:await asyncio.sleep(0.02)if self.before_second_generation is not None:await self.before_second_generation()- if self._script == "second-generation":+ if self._script in {"second-generation", "second-generation-twice"}:async for event in self._readback(REPLY):yield event+ if self._script == "second-generation-twice":+ # A second phantom, starting the moment the first one's+ # boundary released the withhold. Live Vertex Live did this+ # with a truncated echo of the same confirmation.+ await asyncio.sleep(0.02)+ async for event in self._readback(REPLY.split()[0] + " " + REPLY.split()[1]):+ yield eventelif self._script == "after-user-input":yield RealtimeEvent(type="input_transcript",@@ -310,9 +324,38 @@ async def test_second_generation_after_readback_is_discarded_whole(assert sum(1 for m in messages if m.get("type") == "turn_complete") == 1assert _turn_starts(bus) == 1assert session._stale_generations_dropped == 1- # The guard stood down with the discarded generation's own boundary.+ # The withhold ended with the discarded generation's boundary. The+ # watch stays armed so a second phantom cannot play (BUG-149).assert session._stale_generation_dropping is False- assert session._stale_generation_guard_armed_at == 0.0+ assert session._stale_generation_guard_armed_at > 0.0+++async def test_second_unprompted_generation_after_a_dropped_one_is_also_discarded(+ monkeypatch: pytest.MonkeyPatch,+) -> None:+ """Live 2026-08-19 11:10 (BUG-149, session e1ba9504, Vertex Live).++ The first extra generation was dropped (``stale_generations_dropped=1``)+ and the guard stood down on its boundary. Vertex Live then started a+ second unprompted generation — empty user text, 338 ms to first audio —+ that spoke a truncated echo of the same confirmation. Both extras must+ stay inaudible; only the original readback reaches the speaker.+ """+ _shorten_delegate_waits(monkeypatch)+ provider = _ServerVadProvider(script="second-generation-twice")++ session, messages, binaries, bus = await _run(provider, settle_s=0.5)++ assert provider.session.text_inputs, "the trusted result was never injected"+ assert REPLY in provider.session.text_inputs[0]+ assert len(binaries) == 1+ assert _assistant_texts(messages) == [REPLY]+ assert sum(1 for m in messages if m.get("type") == "turn_complete") == 1+ assert _turn_starts(bus) == 1+ assert session._stale_generations_dropped == 2+ assert session._stale_generation_dropping is False+ assert session._stale_generation_guard_armed_at > 0.0# ---------------------------------------------------------------------------@@ -710,3 +753,28 @@ def test_drop_without_a_boundary_is_released_at_the_ceiling() -> None:assert session._stale_generation_drop_active() is Falseassert session._stale_generation_dropping is Falseassert session._must_withhold_provider_output() is False+++def test_finishing_a_drop_keeps_the_watch_armed() -> None:+ """BUG-149: the first phantom's boundary must not stand the watch down."""+ session = RealtimeVoiceSession(+ session_id="watch-stays",+ send_binary=lambda _data: asyncio.sleep(0),+ send_json=lambda _message: asyncio.sleep(0),+ provider=_ServerVadProvider(script="second-generation"),+ config=_config(),+ bus=None,+ browser_sample_rate=16_000,+ surface="desktop",+ brain=_DelegatingBrain(),+ )+ session._session = SimpleNamespace(creates_responses_automatically=True)+ session._arm_stale_generation_guard(REPLY)+ armed_at = session._stale_generation_guard_armed_at+ session._stale_generation_dropping = True+ session._stale_generation_transcript.append(REPLY)+ session._finish_stale_generation_drop()+ assert session._stale_generation_dropping is False+ assert session._stale_generation_guard_armed_at == armed_at+ assert session._stale_generation_guard_reply == REPLY+ assert session._stale_generation_guard_reason()