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): drop the reply Gemini abandons for its own retry
rubenluetke10-beepe57b5a91e74b
diff --git a/docs/BUGS.md b/docs/BUGS.mdindex 052d77cdd4..7e629299fc 100644--- a/docs/BUGS.md+++ b/docs/BUGS.md@@ -11713,6 +11713,9 @@ later — the "Guten Abend … und ich bin / bei mir läuft alles" restart aboveplays both halves. That race is a product decision (keep the turn-scoped modeline on Gemini and accept a restart, or drop the partial, or send the lineonly while the user is still audibly speaking) and is left documented.+**Settled in BUG-171 (2026-08-23), second option:** the restart stands, the+partial is dropped. The race itself is still there — only its audible half is+gone.**Fix.** `jarvis/plugins/realtime/gemini_live.py`: an `interrupted` edge thatarrives for a generation that handed out a function call is the first half of@@ -12003,3 +12006,89 @@ on what a generation once did, rather than on what it has done since, turnsthe first counter-example into a stuck turn — and a stuck SPEAKING turn isthe worst failure the voice path has, because nothing the user does withtheir voice can end it.++## BUG-171: one question, two spoken answers — the per-turn directive interrupts the reply the server has already started, and both halves are played (HIGH, FIXED 2026-08-23)++**Symptom (maintainer, 2026-08-23 10:06).** A reply ended mid-sentence and a+different one followed it a beat later, sounding like a second speaker cutting+the first off: "Alles klar. Wenn du nachher noch was brauchst, sag" — then <!-- i18n-allow: quoted live German output under forensic analysis -->+"Dann wünsche ich dir einen entspannten Start in die neue Woche!". Every turn <!-- i18n-allow: quoted live German output under forensic analysis -->+of that call had the shape; the transcript recorded each half as its own turn,+the second with an empty `user_text`.++**Timeline (`data/sessions.db` + `data/jarvis_desktop.log`, one turn).**++```+10:05:58.588 delivered a per-turn steering delta (turn; 642 chars)+10:05:58.597 generation started 0.01s after the last steering text input+10:05:58.614 interrupted — audio=2.4s transcript=50 chars generation=0.02s;+ 0.03s after the last steering text input+10:05:58.614 deferred an unconfirmed provider interruption; waiting for the+ user's own words before cutting the reply+10:05:58.652 turn complete — audio=0.0s transcript=0 chars+10:06:00.588 generation started 2.00s after the last steering text input+10:06:02.534 turn complete — audio=3.0s transcript=63 chars+```++Both generations answer the same utterance ("Nee, nicht wirklich."), and the <!-- i18n-allow: quoted live German output under forensic analysis -->+first is 50 characters of a sentence the model never got to finish.++**Root cause.** On Gemini Live a text input IS a user turn — there is no+configuration channel. `update_session` therefore delivers the per-turn mode+line as a realtime text at the FINAL input transcript, which on this transport+arrives in the same millisecond the server starts generating. `_flush_steering`+guards on `_model_generating`, but that flag is set by the first output the+adapter READS; the server had already decided. When the text loses the race it+lands on an answer in flight, the server abandons that answer (`interrupted`),+closes it with an empty `turn_complete`, and regenerates two seconds later.+3 of the 9 directives delivered that day did this (09:24, 10:05, 10:06).++The session then made it audible. RT-09 defers an `interrupted` edge that no+user words confirm — correct for a cough, wrong here: nobody was ever going to+confirm an edge caused by our own text, so the dead half played out in full,+was recorded as a turn, and the replacement was spoken after it. The gap is+that the edge was *knowable*: the adapter logs the attribution ("0.03s after+the last steering text input") and then threw it away.++**Fix (2026-08-23).** The adapter names the edge instead of logging it:+`_interrupt_is_our_own_text_input` marks an `interrupted` that follows one of+our own text inputs within 1.5 s as `superseded` on the provider event (a real+barge-in cannot land there — the user's final transcript arrived milliseconds+earlier), and withholds the empty `turn_complete` that closes the abandoned+generation, exactly as the BUG-165 tool boundary is withheld. Spoken output+from the replacement releases the withhold; the user's next words release it+too; a second empty boundary passes through, so a turn can never latch open.+`_drop_superseded_generation` in the session drops what the far end abandoned+— buffered PCM, partial transcript, surface queue — and keeps the turn open+for the replacement. It deliberately does NOT arm+`_drop_provider_output_until_new_response`: that guard is released by the next+locally grounded final transcript, and a regeneration comes with no new user+input at all, so arming it would swallow the very answer being cleared for+(the 2026-08-10 shape — three complete replies discarded, 23.3 s to first+audio). Straggling frames of the dead generation are kept out by retiring its+response id instead.++Nothing is audibly lost: the edge lands 30–90 ms after the first audio chunk,+against a device output latency of 0.41 s, so on both live incidents the cut+half had not reached the speaker yet.++**Guards.** `tests/unit/realtime/test_gemini_live.py::test_our_own_steering_text_interrupting_a_reply_supersedes_it`+(the live message sequence, edge for edge),+`::test_a_barge_in_long_after_our_own_text_still_interrupts` (the+counterweight), `::test_a_second_empty_boundary_after_a_supersede_is_not_withheld`+(the anti-latch), and+`tests/unit/realtime/test_session_noise_interrupt.py::test_a_superseded_generation_is_dropped_and_its_replacement_speaks`,+which pins the sharper half: the replacement must still arrive.++**Not fixed here.** The race itself stands. The mode line depends on the turn+plan, which depends on what the user just said, so it cannot be sent earlier+than the final transcript; sending it later would provoke an unprompted reply.+Removing the race for good means owning the turn boundary — manual activity+detection, where the client sends the directive and only then declares the+user finished — which is a turn-taking change with its own latency and+barge-in risk, not a bug fix.++**Lesson.** RT-09's "wait for the user's words" is the right default for an+edge whose cause is unknown. It is the wrong one for an edge whose cause is+US, and the adapter knew the cause well enough to write it into the log. An+attribution that is good enough to diagnose from is good enough to act on.diff --git a/jarvis/plugins/realtime/gemini_live.py b/jarvis/plugins/realtime/gemini_live.pyindex 1742591f40..83c83d78c7 100644--- a/jarvis/plugins/realtime/gemini_live.py+++ b/jarvis/plugins/realtime/gemini_live.py@@ -84,6 +84,21 @@ _STEERING_HEADER = ()+# Inputs this adapter sends ITSELF, as named by ``_note_input_sent``. A text+# on this transport is a user-side realtime input, so any one of them can+# interrupt an answer the server had already started.+_SELF_TEXT_INPUT_KINDS = frozenset({"steering text", "text"})++# How long after one of our own text inputs an ``interrupted`` edge is that+# input rather than a barge-in. Measured on the wire: 0.03 s, 0.09 s and+# 0.17 s in the three cut replies of 2026-08-23 (09:24, 10:05, 10:06). A real+# barge-in cannot land in this window — the user's final transcript arrived+# only milliseconds before the text went out, so nobody had started speaking+# again. Generous enough to cover a slow round trip, far below the ~2 s a new+# utterance needs to reach the server VAD.+_SELF_TEXT_INTERRUPT_WINDOW_S = 1.5++def _end_of_speech_sensitivity(types: Any, preference: str | None) -> Any | None:"""Resolve the requested end-of-speech patience, or None on an old SDK.@@ -180,6 +195,12 @@ class _ProviderEvent:# The Live channel was previously the only brain path whose spend was# invisible to the recorder — 100% of Live-API tokens went unmetered.usage: dict[str, int] | None = None+ # This ``interrupted`` closes a generation the SERVER abandoned in favour+ # of its own retry, not one the user talked over. Mirrors the field of the+ # same name on ``jarvis.realtime.protocol.ProviderEvent``, which this+ # adapter may not import (plugins carry no ``jarvis.*`` dependency); the+ # session reads it by attribute, so the two only have to agree by name.+ superseded: bool = Falseclass _GeminiLiveSession:@@ -289,11 +310,42 @@ class _GeminiLiveSession:# shouted barge-in). A boundary is a tool boundary only while this# counter is zero.self._gen_output_since_tool = 0+ # An ``interrupted`` edge this adapter attributed to its OWN text input+ # (see ``_interrupt_is_our_own_text_input``). The server closes such a+ # generation the way it closes a tool hand-off: the edge, then an empty+ # ``turn_complete``, then — seconds later — the regenerated answer.+ # That middle boundary ends nothing, and forwarding it made the session+ # treat a turn that was still coming as finished: on the 2026-08-23+ # 10:05 call the abandoned half was recorded as a turn of its own and+ # spoken before the real reply ("Alles klar. Wenn du nachher noch was # i18n-allow+ # brauchst, sag" / "Dann wünsche ich dir einen entspannten Start in # i18n-allow+ # die neue Woche!"). Carried across exactly like+ # ``_tool_boundary_pending`` and released by the same evidence: spoken+ # output from the generation that replaced it.+ self._superseded_pending = Falsedef _note_input_sent(self, kind: str) -> None:self._last_input_kind = kindself._last_input_at = time.monotonic()+ def _interrupt_is_our_own_text_input(self) -> bool:+ """Whether this ``interrupted`` edge is our own text, not a barge-in.++ A text input on this transport is a user turn, so one that reaches the+ server while a reply is already streaming makes the server abandon+ that reply and answer again. There is no flag for it on the wire: the+ edge is byte-identical to a barge-in. What tells them apart is that a+ barge-in needs the user to speak, and the user's words reach this+ adapter as an input transcript — which is precisely what has NOT+ arrived when the last thing on the wire was our own text, milliseconds+ ago.+ """+ if self._last_input_kind not in _SELF_TEXT_INPUT_KINDS:+ return False+ return (+ time.monotonic() - self._last_input_at+ ) <= _SELF_TEXT_INTERRUPT_WINDOW_S+def _note_generation_output(self, *, audio_bytes: int = 0, transcript_chars: int = 0, calls: int = 0) -> None:@@ -311,6 +363,9 @@ class _GeminiLiveSession:# to a server that skipped the ``turn_complete`` half of the# pair; never let it withhold the real end of the answer.self._tool_boundary_pending = False+ # Same reasoning for the superseded half: this IS the+ # regenerated answer, so its own boundary is the turn's end.+ self._superseded_pending = Falseself._gen_audio_bytes += audio_bytesself._gen_transcript_chars += transcript_charsself._gen_function_calls += calls@@ -498,8 +553,30 @@ class _GeminiLiveSession:kind="interrupted (function call, edge withheld)")else:- self._log_generation_boundary(kind="interrupted")- yield _ProviderEvent(type="interrupted")+ # Not a tool boundary — but possibly not a barge-in+ # either. Our own per-turn directive travels as a+ # realtime text input at the final-transcript+ # boundary, which is the same millisecond the+ # server starts answering; when it loses that race+ # the server abandons the reply it had already+ # streamed and generates a fresh one. Both halves+ # used to be spoken, the first cut mid-sentence.+ # Naming the edge is the whole fix on this side:+ # the session drops what the far end abandoned.+ superseded = self._interrupt_is_our_own_text_input()+ self._log_generation_boundary(+ kind=(+ f"interrupted (our own {self._last_input_kind} "+ "input; the generation is superseded)"+ if superseded+ else "interrupted"+ )+ )+ if superseded:+ self._superseded_pending = True+ yield _ProviderEvent(+ type="interrupted", superseded=superseded+ )input_transcription = getattr(content, "input_transcription", None@@ -514,6 +591,12 @@ class _GeminiLiveSession:# orchestrator reacts to the transcript, so the delta# is in context for the reply this turn produces.self._user_turn_open = True+ # The user's words end every withhold that keys on+ # "the far end is about to speak again": whatever the+ # server was regenerating, this turn supersedes it,+ # and a boundary held for the old one must not close+ # the new one instead.+ self._superseded_pending = Falseawait self._flush_steering()yield _ProviderEvent(type="input_transcript", text=input_text, is_final=True@@ -590,21 +673,42 @@ class _GeminiLiveSession:function_calls)self._tool_boundary_pending = False+ # The other half of the superseded pair. A generation+ # the server abandoned in favour of its own retry is+ # closed by an EMPTY boundary — the regenerated answer+ # arrives seconds later under its own. Forwarding this+ # one ends a turn whose reply has not been spoken yet;+ # the session then reads the silence as a mute+ # provider and sends a re-ask text, which is one more+ # input racing the very generation everyone is waiting+ # for. Spoken output releases the flag above, so a+ # boundary that follows the retry is never the one+ # withheld here, and a second empty boundary passes+ # unchanged rather than latching the turn open.+ superseded_boundary = (+ self._superseded_pending and not tool_generation+ )+ self._superseded_pending = Falseself._log_generation_boundary(kind=("turn complete (function call, boundary ""withheld)"if tool_generationelse (- "turn complete (function call answered "- "in place)"- if answered_in_place- else "turn complete"+ "turn complete (superseded generation, "+ "boundary withheld)"+ if superseded_boundary+ else (+ "turn complete (function call "+ "answered in place)"+ if answered_in_place+ else "turn complete"+ ))),reason=reason_name,)- if not tool_generation:+ if not tool_generation and not superseded_boundary:yield _ProviderEvent(type="turn_complete")go_away = getattr(message, "go_away", None)diff --git a/jarvis/realtime/protocol.py b/jarvis/realtime/protocol.pyindex 5cf9ed72a4..9325bbd26d 100644--- a/jarvis/realtime/protocol.py+++ b/jarvis/realtime/protocol.py@@ -75,6 +75,15 @@ class RealtimeEvent:# orchestrator reads its own cancellation as a barge-in and arms the# user-speech state against a user who never said anything.self_initiated: bool = False+ # True when the PROVIDER abandoned the generation this ``interrupted``+ # closes and is regenerating the same answer. Distinct from+ # ``self_initiated``: nobody cancelled locally, so nothing has been drained+ # and the orchestrator still owns the cleanup — but the partial reply is+ # dead text the far end will never finish, so playing it out is wrong. A+ # transport whose text inputs double as user turns (Gemini Live) does this+ # to itself whenever a per-turn directive lands on an answer already in+ # flight; without the flag the session heard both halves as two replies.+ superseded: bool = False@dataclass(frozen=True, slots=True)diff --git a/jarvis/realtime/session.py b/jarvis/realtime/session.pyindex 17b5563bd1..042acc7e50 100644--- a/jarvis/realtime/session.py+++ b/jarvis/realtime/session.py@@ -2568,6 +2568,11 @@ class RealtimeVoiceSession:self._interruption_deferred_at = 0.0self._interruption_settle_task: asyncio.Task[None] | None = Noneself._unconfirmed_interruptions = 0+ # Generations the PROVIDER abandoned and replaced on its own (RT-10).+ # Its counterpart above counts edges we could not attribute; this one+ # counts edges the adapter attributed to our own text input, where the+ # partial reply is dead and dropping it is the correct answer.+ self._superseded_generations = 0self._external_update: _ExternalUpdateState | None = None# from_brain returns None when no public supervisor gateway is ready.# Say so, or a tool-less session is indistinguishable from a healthy one.@@ -5777,6 +5782,41 @@ class RealtimeVoiceSession:# decides when it is over. A silence timer would abandon# exactly the turn this branch exists to protect.self._deferred_provider_speech_start = True+ elif event.type == "interrupted" and getattr(+ event, "superseded", False+ ):+ # NOT ambiguous: the adapter attributed this edge to an+ # input JARVIS itself sent, so no user spoke and there is+ # nothing to wait for words about. The far end abandoned+ # the reply it was streaming and is generating another one.+ # Deferring here — the branch below — is what let both+ # halves be spoken: the dead partial played out in full,+ # was recorded as a turn of its own, and the regenerated+ # answer followed it two seconds later, so one question got+ # two spoken replies with the first cut mid-sentence (live+ # 2026-08-23 10:05 and 10:06, "…brauchst, sag" / "Dann # i18n-allow+ # wünsche ich dir…"; 3 of 9 per-turn directives that day). # i18n-allow+ # The provider already made the decision; follow it.+ if not self._reply_is_in_flight():+ # The race went the other way and the edge arrived+ # before anything was produced. Nothing to drop, and+ # no deferral either: a backstop armed here would+ # later cut the very reply that is still coming+ # (BUG-152).+ log.info(+ "realtime[%s] provider superseded a generation "+ "that had produced nothing yet",+ self.session_id,+ )+ self._clear_deferred_interruption()+ else:+ log.info(+ "realtime[%s] dropping a reply the provider "+ "abandoned for its own retry; the regenerated "+ "answer owns this turn",+ self.session_id,+ )+ await self._drop_superseded_generation()elif event.type == "interrupted":# The SAME ambiguity, now while a reply is actually being# spoken. Acting on the edge alone cancelled the answer and@@ -12854,6 +12894,50 @@ class RealtimeVoiceSession:except Exception: # noqa: BLE001, S110pass+ async def _drop_superseded_generation(self) -> None:+ """Discard a reply the PROVIDER abandoned in favour of its own retry.++ Neither a barge-in nor our own cancel. Nobody spoke, nothing was+ cancelled locally — the far end decided the answer it had already+ streamed is void and started producing a different one. Everything+ received so far belongs to a generation that will never be finished,+ so all of it goes: the buffered PCM, the partial transcript, and+ whatever the surface has queued. The TURN stays open; the replacement+ arrives under it.++ Deliberately WITHOUT ``_drop_provider_output_until_new_response``.+ That guard is released by the next locally grounded final transcript,+ and a regeneration arrives with no new user input at all, so arming it+ here would swallow precisely the answer this method clears the way for+ — the 2026-08-10 shape, three complete replies discarded and 23.3 s to+ the first audible frame. Straggling frames of the dead generation are+ kept out by retiring its response id, which its successor does not+ share.+ """+ self._superseded_generations += 1+ self._gate.drain()+ self._retire_active_provider_response()+ # The abandoned half must reach neither the recorder nor the next+ # turn's context. Nobody heard it, and a half sentence left standing+ # is believed by everything downstream — the same reason+ # _cancel_unsafe_output clears this (live forensic 2026-07-17 10:04).+ self._output_transcript.clear()+ self._output_samples_sent = 0+ self._output_active = False+ self._reset_echo_horizon()+ # No edge is pending any more: this one was answered, not deferred.+ self._clear_deferred_interruption()+ self._mark_latency_named(+ "REALTIME_SUPERSEDED_GENERATION",+ detail="provider abandoned its own generation",+ )+ try:+ # Terminal local playback boundary: every surface consumes+ # tts_cancel to flush its audio and leave SPEAKING.+ await self._send_json({"type": "tts_cancel"})+ except Exception: # noqa: BLE001, S110 — surface may already be gone+ pass+def _harvest_adapter_diagnostics(self, session: Any) -> None:"""Accumulate a provider session's postmortem counters.diff --git a/tests/unit/realtime/test_gemini_live.py b/tests/unit/realtime/test_gemini_live.pyindex 0a804a5690..522777f2dc 100644--- a/tests/unit/realtime/test_gemini_live.py+++ b/tests/unit/realtime/test_gemini_live.py@@ -1673,3 +1673,167 @@ def test_real_router_tool_schemas_survive_sanitizing(assert result.get("type") == schema.get("type")if "properties" in schema:assert set(result["properties"]) == set(schema["properties"])+++def _session_over_with_text_channel(+ sdk_turns: list[list[SimpleNamespace]],+) -> tuple[_GeminiLiveSession, list[str]]:+ """A wire the adapter can also SEND text on, recording what went out."""+ sent: list[str] = []+ receive_calls = 0++ async def fake_receive():+ nonlocal receive_calls+ receive_calls += 1+ turn_index = receive_calls - 1+ if turn_index < len(sdk_turns):+ for message in sdk_turns[turn_index]:+ yield message++ async def fake_send_realtime_input(*, text: str = "", **_: object) -> None:+ sent.append(text)++ session = _GeminiLiveSession(+ session=SimpleNamespace(+ receive=fake_receive,+ send_realtime_input=fake_send_realtime_input,+ ),+ connection_cm=SimpleNamespace(),+ client=SimpleNamespace(),+ session_id="steering-race",+ )+ return session, sent+++def _input_transcript_content(text: str) -> SimpleNamespace:+ return SimpleNamespace(+ output_transcription=None,+ input_transcription=SimpleNamespace(text=text),+ interrupted=False,+ turn_complete=False,+ )+++async def test_our_own_steering_text_interrupting_a_reply_supersedes_it() -> None:+ """The live shape of 2026-08-23 10:05 and 10:06, message for message.++ The per-turn directive travels at the final-transcript boundary, which on+ this transport is the same millisecond the server starts answering. When+ it loses that race the text lands as a user turn on an answer already+ streaming: the server abandons that answer (``interrupted``), closes it+ with an EMPTY ``turn_complete``, and generates a replacement seconds+ later. Both halves used to be spoken and recorded as two turns — the+ first cut mid-sentence ("Alles klar. Wenn du nachher noch was brauchst,+ sag" / "Dann wünsche ich dir einen entspannten Start in die neue+ Woche!"). The edge must name itself superseded and the empty boundary+ must not close a turn whose reply has not been spoken yet.+ """+ session, sent = _session_over_with_text_channel(+ [+ [+ # The user's words open the one window steering may travel in.+ _fake_message(server_content=_input_transcript_content("Nee.")),+ # The server had already started answering; its audio and+ # transcript arrive before it reads our text.+ _fake_message(data=b"\x00\x01"),+ _fake_message(+ server_content=_server_content(output_text="Alles klar.")+ ),+ # Our text lands: the server drops its own answer …+ _fake_message(server_content=_server_content(interrupted=True)),+ # … and closes the abandoned generation with an empty boundary.+ _fake_message(server_content=_server_content(turn_complete=True)),+ # Seconds later, the answer it really means.+ _fake_message(data=b"\x02\x03"),+ _fake_message(+ server_content=_server_content(output_text="Dann wünsche ich …")+ ),+ _fake_message(server_content=_server_content(turn_complete=True)),+ ]+ ]+ )+ await session.update_session(language="de", turn_directive="Mode: chat.")++ events = [event async for event in session.receive()]++ assert sent, "the queued steering delta must travel on the user's turn"+ assert [event.type for event in events] == [+ "input_transcript",+ "audio_delta",+ "output_transcript_delta",+ "interrupted",+ # No turn_complete here: the abandoned generation ends nothing.+ "audio_delta",+ "output_transcript_delta",+ "turn_complete",+ ]+ interrupted = next(event for event in events if event.type == "interrupted")+ assert interrupted.superseded is True+++async def test_a_barge_in_long_after_our_own_text_still_interrupts() -> None:+ """The counterweight: our text explains only the edges that follow it closely.++ Same wire, but the user talks over a reply seconds after the directive+ went out. That is a real barge-in — it must keep cutting the answer, and+ its boundary must keep closing the turn.+ """+ session, _sent = _session_over_with_text_channel(+ [+ [+ _fake_message(server_content=_input_transcript_content("Ja.")),+ _fake_message(data=b"\x00\x01"),+ _fake_message(server_content=_server_content(interrupted=True)),+ _fake_message(server_content=_server_content(turn_complete=True)),+ ]+ ]+ )+ await session.send_text("a delegate readback")+ # Age our own input past the attribution window without touching the clock+ # every other assertion here depends on.+ session._last_input_at -= 60.0++ events = [event async for event in session.receive()]++ assert [event.type for event in events] == [+ "input_transcript",+ "audio_delta",+ "interrupted",+ "turn_complete",+ ]+ interrupted = next(event for event in events if event.type == "interrupted")+ assert interrupted.superseded is False+++async def test_a_second_empty_boundary_after_a_supersede_is_not_withheld() -> None:+ """The withhold is spent by the boundary it was armed for, never latched.++ A server that closes the abandoned generation twice — or that never+ produces the replacement — must not leave the turn open forever: that is+ the shape that froze the desktop pipeline in JARVIS_SPEAKING with the+ microphone shut (2026-08-23 09:25, the tool-boundary sibling).+ """+ session, _sent = _session_over_with_text_channel(+ [+ [+ _fake_message(server_content=_input_transcript_content("Nee.")),+ _fake_message(data=b"\x00\x01"),+ _fake_message(server_content=_server_content(interrupted=True)),+ _fake_message(server_content=_server_content(turn_complete=True)),+ _fake_message(server_content=_server_content(turn_complete=True)),+ ]+ ]+ )+ await session.update_session(language="de", turn_directive="Mode: chat.")++ events = [event async for event in session.receive()]++ assert [event.type for event in events] == [+ "input_transcript",+ "audio_delta",+ "interrupted",+ "turn_complete",+ ]diff --git a/tests/unit/realtime/test_session_noise_interrupt.py b/tests/unit/realtime/test_session_noise_interrupt.pyindex cc11efee24..2684a66c3e 100644--- a/tests/unit/realtime/test_session_noise_interrupt.py+++ b/tests/unit/realtime/test_session_noise_interrupt.py@@ -269,3 +269,52 @@ async def test_stale_interrupt_cannot_cancel_speaker_drain():assert "and warm." in _assistant_text(jsons)assert not any(item.get("type") == "tts_cancel" for item in jsons)assert sess._unconfirmed_interruptions == 1+++async def test_a_superseded_generation_is_dropped_and_its_replacement_speaks():+ """An edge the ADAPTER attributed to our own text is not deferred (RT-10).++ On a transport whose text inputs are user turns, a per-turn directive that+ reaches the server while it is already answering makes it abandon that+ answer and generate another. Deferring here — correct for an ambiguous+ edge — played the dead half out in full, recorded it as a turn of its own,+ and then played the replacement too: one question, two spoken replies,+ the first cut mid-sentence (live 2026-08-23 10:05 and 10:06).++ Both halves of the fix are pinned: what the far end abandoned is cancelled+ on the surface, and what it sent instead still arrives. The second is the+ sharper edge — clearing the way with the post-barge-in withhold would have+ swallowed the replacement, which no new user transcript ever comes to+ release.+ """++ async def script():+ yield RealtimeEvent(type="input_transcript", text=OPENING, is_final=True)+ yield RealtimeEvent(type="output_transcript_delta", text="Sure thing, if")+ yield RealtimeEvent(+ type="audio_delta",+ audio=AudioChunk(pcm=HEAD, sample_rate=24_000, timestamp_ns=0),+ )+ # Our own steering text landed on the answer in flight.+ yield RealtimeEvent(type="interrupted", superseded=True)+ # The server's replacement, under the same turn and with no new user+ # input in between.+ yield RealtimeEvent(type="output_transcript_delta", text="Have a good week.")+ yield RealtimeEvent(+ type="audio_delta",+ audio=AudioChunk(pcm=TAIL, sample_rate=24_000, timestamp_ns=0),+ )+ yield RealtimeEvent(type="turn_complete")++ binaries, jsons = [], []+ provider = _scripted(script)+ sess = await _run(provider, binaries=binaries, jsons=jsons)++ assert TAIL in binaries, "the regenerated answer must not be withheld"+ assert any(item.get("type") == "tts_cancel" for item in jsons)+ assert sess._superseded_generations == 1+ # The edge was answered, not parked: nothing is left waiting for words+ # that are never coming.+ assert sess._unconfirmed_interruptions == 0+ assert sess._deferred_provider_speech_start is False