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): make scrub-gate _cleared flag one-shot so later-segment leaks are caught

Ruben Lütkeca248ee5a938
diff --git a/jarvis/realtime/scrub_gate.py b/jarvis/realtime/scrub_gate.py
index 6bdd441ab4..f3621e76b3 100644
--- a/jarvis/realtime/scrub_gate.py
+++ b/jarvis/realtime/scrub_gate.py
@@ -61,6 +61,7 @@ class ScrubHoldGate:
if self._cleared:
out = self._pending + [chunk]
self._pending = []
+ self._cleared = False
return out
self._pending.append(chunk)
return []
@@ -71,7 +72,7 @@ class ScrubHoldGate:
return []
out = self._pending
self._pending = []
- self._cleared = True
+ self._cleared = False
return out
def drain(self) -> None:
diff --git a/tests/unit/realtime/test_scrub_gate.py b/tests/unit/realtime/test_scrub_gate.py
index 943ef5b661..3a0da28256 100644
--- a/tests/unit/realtime/test_scrub_gate.py
+++ b/tests/unit/realtime/test_scrub_gate.py
@@ -3,8 +3,6 @@ import pytest
from jarvis.core.protocols import AudioChunk
from jarvis.realtime.scrub_gate import ScrubHoldGate
-_HARD_LEAK_ACTIONS = {"replaced_stacktrace", "replaced_raw_repr", "replaced_shell_command"}
-
def _chunk(n: int) -> AudioChunk:
return AudioChunk(pcm=b"\x00\x01" * n, sample_rate=24000, timestamp_ns=0)
@@ -15,8 +13,8 @@ async def test_clean_transcript_releases_buffered_audio():
gate = ScrubHoldGate(language="en")
await gate.push_audio(_chunk(4))
released = await gate.feed_transcript("Hello there, how can I help?")
- # display text returned; audio releasable after the clean boundary
- assert released == "Hello there, how can I help?" or released # scrubbed display
+ # scrub_for_voice leaves this clean sentence unchanged
+ assert released == "Hello there, how can I help?"
out = await gate.push_audio(_chunk(4))
assert gate.hard_leak_pending() is False
assert out # buffered + new audio flows once transcript cleared
@@ -51,3 +49,38 @@ async def test_scrub_is_regex_only_no_llm(monkeypatch):
gate = ScrubHoldGate(language="en")
await gate.feed_transcript("A normal sentence.")
assert calls["n"] >= 1
+
+
+async def test_later_segment_leak_is_caught_after_a_clean_first_segment():
+ """_cleared must be one-shot: a later segment's audio still gets held.
+
+ Regression for the sticky-_cleared defect: after the first clean
+ transcript in a turn released `_cleared = True` and never reset it, so
+ every later push_audio() released immediately without buffering — audio
+ for a later segment (which may contain a hard leak) could reach the
+ speaker before its own transcript was scrubbed.
+ """
+ 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
+
+ # Segment 2: audio arrives before ITS transcript. If _cleared were still
+ # sticky from segment 1, this would release immediately (the bug).
+ out2 = await gate.push_audio(_chunk(4))
+ assert out2 == [] # must be buffered, not released
+
+ # Segment 2's transcript turns out to be a hard leak (a real stacktrace).
+ await gate.feed_transcript(
+ "Traceback (most recent call last):\n File x\nValueError: y\n\n"
+ )
+ assert gate.hard_leak_pending() is True
+
+ # Segment 2's audio must never be released.
+ out3 = await gate.push_audio(_chunk(4))
+ assert out3 == []