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): remove mid-reply scrub-gate holds entirely (BUG-080 amendment)
Ruben Lütke90afbfef56bc
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex fb800befb2..15643ae8f6 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -11,13 +11,15 @@ versioning per [SemVer](https://semver.org/lang/de/).### Fixed-- **Realtime voice no longer freezes mid-word for seconds.** When the live+- **Realtime voice no longer pauses or stutters mid-reply.** When the liveprovider's output transcription lagged its audio (Gemini Live: routinely- 3-22 s), the voice-scrub gate held the audio for the whole lag — an- audible dead stop mid-sentence. The mid-reply hold is now bounded at- 400 ms once the reply's transcript has been vetted clean once; the strict- fail-closed turn opening and the hard-leak kill switch are unchanged- (BUG-080).+ 3-22 s), the voice-scrub gate held the audio back — first as+ multi-second dead stops mid-word, then (after an interim 400 ms bounded+ hold) as rhythmic block-wise stutter. Mid-reply holds are now removed+ entirely: once the reply's opening transcript has been vetted clean,+ audio flows unconditionally and the scrubber acts as a trailing kill+ switch that still cancels the response on a detected leak. The strict+ fail-closed turn opening is unchanged (BUG-080).- **macOS 15 no longer kills the app when hotkeys arm or Computer-Use types("Personal Jarvis quit unexpectedly", SIGILL).** pynput resolved thediff --git a/docs/BUGS.md b/docs/BUGS.mdindex 7c51656efa..35060f1fb3 100644--- a/docs/BUGS.md+++ b/docs/BUGS.md@@ -5624,6 +5624,24 @@ reach the user anyway (here: the finalize() flush), and let the killswitch — not the hold — be the actual safety mechanism. An unbounded holdconverts a provider lag into a user-facing outage.+**Amendment (2026-07-18, maintainer mandate).** The 400 ms bounded grace+was still audible: while the transcription lagged, the gate metered audio+out in ~400 ms blocks, which the maintainer heard as rhythmic mid-reply+stutter and rejected. Mid-reply release rationing is now removed entirely+(third scheme to fail against provider transcription lag, after the+per-delta credit and the coverage budget — the class rule generalizes:+ANY mid-reply rationing of a live stream converts provider lag into+audible artifacts). Final model: the turn opening stays fail-closed until+the aggregate transcript has been vetted clean once (nothing is audible+yet, so that hold interrupts nothing); from then on audio flows+unconditionally and the scrubber acts purely as a trailing kill switch —+a hard leak in a later delta drops all unplayed audio and cancels the+response. Accepted trade-off: mid-reply audio can be audible before its+own transcript is vetted. Guards updated:+`test_audio_flows_unconditionally_once_the_opening_is_vetted`,+`test_later_segment_leak_still_cancels_after_a_clean_first_segment`,+`tests/unit/realtime/test_session.py::test_audio_after_a_leak_transcript_is_never_emitted`.+---## BUG-081: Hanging up a realtime call can hang forever — end() loses its one pump cancel to an asyncio race after a transport rebuild (HIGH, FIXED 2026-07-18)diff --git a/jarvis/realtime/scrub_gate.py b/jarvis/realtime/scrub_gate.pyindex 59e0118dc3..1ae3c084d5 100644--- a/jarvis/realtime/scrub_gate.py+++ b/jarvis/realtime/scrub_gate.py@@ -7,31 +7,22 @@ decoded audio delta and release it only once its transcript region has passedthe buffered audio and signals the session to cancel + speak the fallback.Regex-only, no LLM (AP-11).-Release accounting is a COVERAGE BUDGET, not a per-delta credit. Providers do-not pace their output transcription against their audio: a Gemini Live probe-(2026-07-17) delivered the ENTIRE reply transcript as one delta alongside the-first audio chunk, and live sessions have shown the opposite — transcription-falling 5-7 s behind the audio. The previous design released exactly one-audio push per transcript delta, so an up-front en-bloc transcript starved-every later chunk until turn end: the audible word-splitting stutter and-multi-second mid-reply holes of BUG-069. Now each clean transcript char funds-``_COVERAGE_MS_PER_CHAR`` of audio, cumulatively per response. The rate is-deliberately FASTER than any real speaking voice (~18 chars/s vs a real-12-17), so the budget systematically underestimates the true spoken duration-of the vetted text — released audio therefore always stays inside the span-the scrubber has already cleared. Audio beyond that span still buffers,-fail-closed, exactly as before.--The hold is additionally TIME-BOUNDED once a turn's aggregate transcript has-been vetted clean at least once (BUG-080): Gemini Live's output transcription-routinely falls 3-22 s behind its audio, and an unbounded mid-reply hold-turned every such lag into an audible mid-word freeze. After-``_LAGGING_TRANSCRIPT_GRACE_MS`` the backlog flows even though its own-transcript has not arrived yet — a deliberate, narrow fail-open: the same-never-covered audio would have been flushed by ``finalize()`` at the turn-boundary anyway, and a hard leak in a later transcript delta still cancels-the remaining output. Before the first clean transcript the gate stays-strictly fail-closed with no grace.+The hold applies ONLY to the turn opening. Providers do not pace their+output transcription against their audio: Gemini Live has delivered the+entire reply transcript en bloc with the first audio chunk, and live+sessions have shown the opposite — transcription falling 3-22 s behind the+audio. Every mid-reply release-accounting scheme tried against that reality+turned provider lag into audible dead air: the per-delta credit starved+audio into word-splitting stutter (BUG-069), the coverage budget froze the+voice mid-word for the whole lag (BUG-080), and the 400 ms bounded grace+still chopped the reply into rhythmic blocks while transcription lagged+(maintainer test 2026-07-18). The maintainer mandate is zero gate-caused+interruptions: once the turn's AGGREGATE transcript has been vetted clean+at least once, audio flows unconditionally and the scrubber becomes a+trailing kill switch — a hard leak in a later transcript delta still drops+everything not yet played and cancels the response. Before that first clean+transcript the gate stays strictly fail-closed (nothing is audible yet, so+the hold cannot interrupt anything)."""from __future__ import annotations@@ -72,21 +63,14 @@ _KNOWN_SCRUB_ACTIONS = (_HARD_LEAK_ACTIONS | _NON_BLOCKING_SCRUB_ACTIONS | {_RESIDUE_ACTION})_TRANSCRIPT_TAIL_MAX_CHARS = 4_096-# How much audio one vetted transcript char funds. 55 ms/char is ~18 chars/s-# — faster than any real TTS voice speaks (measured Gemini Live German:-# ~14 chars/s, i.e. ~70 ms/char) — so the budget UNDERESTIMATES the spoken-# duration of already-scrubbed text and released audio cannot outrun it.+# Diagnosis only (no release decision hangs on it): estimated audio one+# vetted transcript char accounts for. 55 ms/char is ~18 chars/s — faster+# than any real TTS voice speaks (measured Gemini Live German: ~14 chars/s)+# — so released audio far beyond this estimate proves transcription lagged._COVERAGE_MS_PER_CHAR = 55.0# A finalize() tail this far beyond the coverage estimate cannot be explained# by the deliberate underestimation alone; log it as a transcription stall._FINALIZE_EXCESS_LOG_MS = 5_000.0-# Longest a mid-reply hold may last once the aggregate transcript has been-# clean at least once (BUG-080). Short enough that a lagging transcription-# never freezes the voice perceptibly (live 2026-07-17 20:04: a 4.9 s-# mid-word hole; observed lags run 3-22 s), long enough that a co-timed-# transcript (typically <300 ms behind its audio) still wins the race — in-# the healthy case the scrubber keeps vetting text BEFORE its audio plays.-_LAGGING_TRANSCRIPT_GRACE_MS = 400.0class ScrubHoldGate:@@ -209,73 +193,34 @@ class ScrubHoldGate:async def push_audio(self, chunk: AudioChunk) -> list[AudioChunk]:"""Buffer or release an audio delta. Returns chunks safe to play now.- Release order of precedence:- 1. A clean transcript delta clears everything buffered before it plus- this chunk (audio received before the delta belongs to text up to- that delta on a co-timed stream) — the pre-budget behavior,- unchanged.- 2. The coverage budget: this chunk flows immediately while cumulative- released audio stays inside the estimated spoken duration of all- vetted transcript chars. This is what keeps playback continuous- when a provider sends its transcript up-front en bloc (BUG-069).- 3. The lagging-transcript grace (BUG-080): once the aggregate- transcript has been clean at least once, a backlog held longer- than ``_LAGGING_TRANSCRIPT_GRACE_MS`` flows anyway — the provider- transcription is lagging its audio, and an unbounded hold freezes- the voice mid-word for the whole lag. A hard leak in a later- transcript delta still cancels the remaining output.- Anything else buffers, fail-closed.+ Two states only (maintainer mandate 2026-07-18, BUG-080 follow-up —+ zero gate-caused mid-reply interruptions):+ 1. Turn opening (aggregate transcript never clean yet): buffer,+ fail-closed. Nothing is audible yet, so this hold cannot+ interrupt speech — it only delays the reply start by the co-timed+ transcript's few-ms head start. A clean transcript delta clears+ the backlog (via ``_cleared``/``release_available``).+ 2. After the first clean aggregate transcript: everything flows+ unconditionally, however far the provider transcription lags its+ audio. The scrubber keeps running as a trailing kill switch — a+ hard leak in a later delta drops all unplayed audio and cancels+ the response."""if self._hard_leak:return []- if self._cleared:- out = self._pending + [chunk]- self._pending = []- self._pending_audio_ms = 0.0- self._cleared = False- self._released_ms += _duration_ms(out)- self._consume_hold_clock()- return out- chunk_ms = _duration_ms((chunk,))- if self._coverage_active:- # Evaluate the WHOLE backlog plus this chunk so a budget that- # grew since the backlog formed can un-stick it (FIFO preserved:- # either everything flows or everything keeps buffering).- total_ms = self._pending_audio_ms + chunk_ms- if (- self._released_ms + total_ms- <= self._covered_chars * _COVERAGE_MS_PER_CHAR- ):- out = self._pending + [chunk]- self._pending = []- self._pending_audio_ms = 0.0- self._released_ms += total_ms- self._consume_hold_clock()- return out- if (- self._pending_since is not None- and (time.monotonic() - self._pending_since) * 1_000.0- >= _LAGGING_TRANSCRIPT_GRACE_MS- ):- out = self._pending + [chunk]- self._pending = []- self._pending_audio_ms = 0.0- self._released_ms += total_ms- self._consume_hold_clock()- log.info(- "scrub gate released %d ms of audio after a %d ms hold "- "— the provider output transcription is lagging behind "- "its audio; a leak in a later transcript delta still "- "cancels the remaining output",- int(total_ms),- int(self.last_hold_ms),- )- return out- if not self._pending and self._pending_since is None:- self._pending_since = time.monotonic()- self._pending.append(chunk)- self._pending_audio_ms += chunk_ms- return []+ if not self._cleared and not self._coverage_active:+ if not self._pending and self._pending_since is None:+ self._pending_since = time.monotonic()+ self._pending.append(chunk)+ self._pending_audio_ms += _duration_ms((chunk,))+ return []+ out = self._pending + [chunk]+ self._pending = []+ self._pending_audio_ms = 0.0+ self._cleared = False+ self._released_ms += _duration_ms(out)+ self._consume_hold_clock()+ return outdef release_available(self) -> list[AudioChunk]:"""Release buffered audio only after a transcript cleared the gate."""diff --git a/tests/unit/realtime/test_scrub_gate.py b/tests/unit/realtime/test_scrub_gate.pyindex 3d2baddd31..88ed5751ab 100644--- a/tests/unit/realtime/test_scrub_gate.py+++ b/tests/unit/realtime/test_scrub_gate.py@@ -69,23 +69,23 @@ async def test_leading_streaming_dash_waits_for_meaningful_transcript():async def test_split_filler_opener_can_complete_a_substantive_reply():"""A temporary ``Let me think`` prefix must not abort streamed output.- The 2000 ms chunk exceeds what the few prefix chars fund, so it must- buffer until the substantive continuation arrives — never abort.+ The first delta ("Let me") scrubs clean, which opens the gate; the+ aggregate then dipping into benign residue (" think" completes a filler+ opener) must neither abort the response nor close the flow again."""gate = ScrubHoldGate(language="en")- buffered = _chunk(48_000)+ chunk = _chunk(48_000)display = [await gate.feed_transcript("Let me")]display.append(await gate.feed_transcript(" think"))assert gate.hard_leak_pending() is False- assert await gate.push_audio(buffered) == []+ assert await gate.push_audio(chunk) == [chunk]continuation = ", the benefits include stronger bones."display.append(await gate.feed_transcript(continuation))assert gate.hard_leak_pending() is Falseassert "".join(display) == f"Let me think{continuation}"- assert gate.release_available() == [buffered]@pytest.mark.asyncio@@ -250,29 +250,24 @@ async def test_scrub_is_regex_only_no_llm(monkeypatch):@pytest.mark.asyncio-async def test_later_segment_leak_is_caught_after_a_clean_first_segment():- """Audio beyond the vetted coverage budget still gets held.-- Regression for the sticky-_cleared defect, updated for the BUG-069- coverage budget: a short clean first segment funds only its own- estimated spoken duration, so a later segment's audio that outruns that- budget (and whose own transcript may be a hard leak) must buffer until- its transcript is scrubbed — and must be dropped when that transcript- turns out to be a stacktrace.+async def test_later_segment_leak_still_cancels_after_a_clean_first_segment():+ """The trailing kill switch survives the unconditional-flow redesign.++ Once the opening is vetted clean, later audio flows before ITS+ transcript arrives (maintainer mandate 2026-07-18: no mid-reply holds).+ When that transcript turns out to be a stacktrace, the gate must still+ flag the hard leak so the session cancels, and must drop everything not+ yet played."""gate = ScrubHoldGate(language="en")- # Segment 1: buffer while no transcript yet, then a clean transcript- # clears the gate and the next push_audio() releases.await gate.push_audio(_chunk(4))await gate.feed_transcript("A normal clean sentence.")- out1 = await gate.push_audio(_chunk(4))- assert out1 # segment 1 audio released+ assert await gate.push_audio(_chunk(4)) # segment 1 audio released- # Segment 2: 2000 ms of audio arrives before ITS transcript — far more- # than the 24-char first segment can fund. It must buffer, not release.- out2 = await gate.push_audio(_chunk(48_000))- assert out2 == [] # must be buffered, not released+ # Segment 2: 2000 ms of audio arrives before ITS transcript. It flows+ # immediately — smoothness over mid-reply vet-ahead.+ assert await gate.push_audio(_chunk(48_000))# Segment 2's transcript turns out to be a hard leak (a real stacktrace).await gate.feed_transcript(@@ -280,9 +275,9 @@ async def test_later_segment_leak_is_caught_after_a_clean_first_segment():)assert gate.hard_leak_pending() is True- # Segment 2's audio must never be released.- out3 = await gate.push_audio(_chunk(4))- assert out3 == []+ # From the leak on, nothing may be released.+ assert await gate.push_audio(_chunk(4)) == []+ assert gate.finalize() == []@pytest.mark.asyncio@@ -312,18 +307,18 @@ async def test_missing_transcript_fails_closed_instead_of_releasing_audio():@pytest.mark.asyncio-async def test_clean_transcript_covers_buffered_tail_at_response_boundary():+async def test_audio_beyond_the_vetted_estimate_flows_without_boundary_wait():gate = ScrubHoldGate(language="en")first = _chunk(4)- # 2000 ms — beyond what the 25-char transcript's coverage budget funds,- # so it must wait for the response boundary.+ # 2000 ms — far beyond the 25-char transcript's spoken-duration+ # estimate; it must flow anyway instead of waiting for the boundary.tail = _chunk(48_000)await gate.feed_transcript("A complete safe response.")assert await gate.push_audio(first) == [first]- assert await gate.push_audio(tail) == []+ assert await gate.push_audio(tail) == [tail]- assert gate.finalize() == [tail]+ assert gate.finalize() == []assert gate.hard_leak_pending() is False@@ -365,43 +360,27 @@ async def test_en_bloc_upfront_transcript_keeps_audio_flowing():@pytest.mark.asyncio-async def test_budget_exhaustion_buffers_audio_beyond_vetted_text():- """Fail-closed core: audio outrunning the vetted text still buffers."""- gate = ScrubHoldGate(language="en")-- await gate.feed_transcript("Okay.") # funds ~275 ms- first = _chunk(9_600) # 400 ms- assert await gate.push_audio(first) == [first] # clean-delta release-- second = _chunk(9_600)- assert await gate.push_audio(second) == [] # budget spent: buffer-- await gate.feed_transcript(" The rest of the sentence arrives late.")- assert gate.release_available() == [second]---async def test_clean_delta_credit_still_releases_one_chunk_beyond_budget():- """The budget redesign must never be stricter than the old gate.+async def test_audio_flows_unconditionally_once_the_opening_is_vetted():+ """Maintainer mandate 2026-07-18: no mid-reply holds of any kind.- When a clean delta arrives with nothing buffered, the pre-budget gate- preserved its credit and released exactly one later chunk regardless of- size. That parity must survive: the first chunk after such a delta flows- even though the tiny transcript cannot fund its duration — and only one.+ Every release-rationing scheme tried here (per-delta credit, coverage+ budget, 400 ms bounded grace) turned provider transcription lag into+ audible stutter or dead air (BUG-069/BUG-080). Once the opening is+ clean, every chunk flows the moment it arrives."""gate = ScrubHoldGate(language="en")- await gate.feed_transcript("Hi.") # funds only ~165 ms- assert gate.release_available() == [] # nothing buffered: credit survives-- first = _chunk(9_600) # 400 ms — larger than the funded estimate- assert await gate.push_audio(first) == [first] # legacy credit release- assert await gate.push_audio(_chunk(9_600)) == [] # credit is one-shot+ await gate.feed_transcript("Okay.") # a clean opening — however short+ for _ in range(10):+ chunk = _chunk(9_600) # 400 ms at 24 kHz — a realistic Gemini chunk+ assert await gate.push_audio(chunk) == [chunk]+ assert gate.pending_audio_ms == 0.0+ assert gate.hard_leak_pending() is False@pytest.mark.asyncio-async def test_residue_only_transcript_never_activates_the_budget():- """A turn whose aggregate transcript is still residue funds nothing."""+async def test_residue_only_transcript_keeps_the_opening_closed():+ """A turn whose aggregate transcript is still residue releases nothing."""gate = ScrubHoldGate(language="en")await gate.feed_transcript("Great question.") # residue: filler opener@@ -438,84 +417,12 @@ async def test_fail_closed_reports_missing_transcript_action():assert gate.hard_leak_actions() == ("no_transcript",)-class _FakeClock:- """Deterministic stand-in for the gate's ``time`` module."""-- def __init__(self) -> None:- self.now = 1_000.0-- def monotonic(self) -> float:- return self.now---def clock(monkeypatch) -> _FakeClock:- fake = _FakeClock()- monkeypatch.setattr(scrub_gate_module, "time", fake)- return fake---async def test_lagging_transcript_backlog_flows_after_grace(clock):- """BUG-080: a mid-reply transcription stall must not freeze the voice.-- Gemini Live's output transcription can fall 3-22 s behind its audio- (live 2026-07-17 20:04: a 4.9 s mid-word hole). Once the aggregate- transcript has been clean, a backlog held past the grace window flows- even though its own transcript has not arrived yet.- """- gate = ScrubHoldGate(language="en")-- await gate.feed_transcript("Okay.") # clean: activates coverage- first = _chunk(9_600) # 400 ms at 24 kHz- assert await gate.push_audio(first) == [first]-- second = _chunk(9_600)- assert await gate.push_audio(second) == [] # budget spent: buffers-- clock.now += 0.5 # past the 400 ms grace, transcript still absent- third = _chunk(9_600)- assert await gate.push_audio(third) == [second, third]- assert gate.pending_audio_ms == 0.0- assert gate.hard_leak_pending() is False--@pytest.mark.asyncio-async def test_no_grace_release_before_first_clean_transcript(clock):- """The turn opening stays strictly fail-closed — grace never applies."""+async def test_repeated_pushes_before_any_transcript_stay_closed():+ """The turn opening stays strictly fail-closed no matter how much audio+ arrives — only a clean transcript (or finalize/fail paths) moves it."""gate = ScrubHoldGate(language="en")assert await gate.push_audio(_chunk(9_600)) == []- clock.now += 10.0assert await gate.push_audio(_chunk(9_600)) == []assert gate.fail_closed() is True---async def test_residue_only_transcript_gets_no_grace_release(clock):- """A turn whose aggregate transcript is still residue funds no grace."""- gate = ScrubHoldGate(language="en")-- await gate.feed_transcript("Great question.") # residue: filler opener- assert await gate.push_audio(_chunk(9_600)) == []- clock.now += 10.0- assert await gate.push_audio(_chunk(9_600)) == []---async def test_hard_leak_after_grace_release_still_blocks_further_audio(clock):- """The grace release must not weaken the hard-leak kill switch."""- gate = ScrubHoldGate(language="en")-- await gate.feed_transcript("Okay.")- assert await gate.push_audio(_chunk(9_600))- assert await gate.push_audio(_chunk(9_600)) == []- clock.now += 0.5- assert await gate.push_audio(_chunk(9_600)) # grace release happened-- await gate.feed_transcript(- "Traceback (most recent call last):\n File x\nValueError: y\n\n"- )- assert gate.hard_leak_pending() is True- assert await gate.push_audio(_chunk(9_600)) == []- assert gate.finalize() == []diff --git a/tests/unit/realtime/test_session.py b/tests/unit/realtime/test_session.pyindex 44f3240806..3468f4fbde 100644--- a/tests/unit/realtime/test_session.py+++ b/tests/unit/realtime/test_session.py@@ -950,18 +950,17 @@ async def test_split_filler_opener_keeps_realtime_answer_playing():@pytest.mark.asyncio-async def test_later_segment_leak_audio_not_emitted():- # Regression test for the T4 ScrubHoldGate one-chunk-boundary residual:- # push_audio's "cleared" branch bundles the release-triggering chunk with- # the previously-buffered one, so a LATER segment's first audio chunk- # could ride along before its own transcript is scrubbed. The session- # must flush release_available() right after sending a clean transcript- # so the gate's _cleared flag never spans into the next segment's audio.- # The leak segment carries 1500 ms of PCM — beyond what the 23-char clean- # first sentence funds under the BUG-069 coverage budget, so it must stay- # buffered until its own (leaking) transcript arrives and drops it.+async def test_audio_after_a_leak_transcript_is_never_emitted():+ # The gate flows audio unconditionally once the turn opening is vetted+ # clean (maintainer mandate 2026-07-18, BUG-080 follow-up: zero+ # gate-caused mid-reply interruptions). A later segment's audio (a2) is+ # therefore audible BEFORE its own transcript is scrubbed — accepted+ # trade-off. The trailing kill switch is the remaining guarantee: from+ # the moment the leaking transcript is detected, the response cancels+ # and no further provider audio (a3) may reach the user.a1 = b"\x11\x22" * 8a2 = b"\x33\x44" * 36_000+ a3 = b"\x55\x66" * 8events = [RealtimeEvent(type="audio_delta", audio=AudioChunk(pcm=a1, sample_rate=24000, timestamp_ns=0)@@ -974,6 +973,9 @@ async def test_later_segment_leak_audio_not_emitted():type="output_transcript_delta",text="Traceback (most recent call last):\n File x\nValueError: y\n\n",),+ RealtimeEvent(+ type="audio_delta", audio=AudioChunk(pcm=a3, sample_rate=24000, timestamp_ns=0)+ ),RealtimeEvent(type="turn_complete"),]binaries, jsons = [], []@@ -989,7 +991,8 @@ async def test_later_segment_leak_audio_not_emitted():await sess.wait_finished()await sess.end(reason="test")assert a1 in binaries- assert a2 not in binaries+ assert a2 in binaries # flowed before its transcript — mandated trade-off+ assert a3 not in binaries # after the leak: kill switch, nothing plays@pytest.mark.asyncio