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): preserve transcript spacing and wrapping

Ruben Lütke9985fa4c09a2
diff --git a/jarvis/realtime/scrub_gate.py b/jarvis/realtime/scrub_gate.py
index f3621e76b3..f7a02f8221 100644
--- a/jarvis/realtime/scrub_gate.py
+++ b/jarvis/realtime/scrub_gate.py
@@ -52,7 +52,15 @@ class ScrubHoldGate:
self._pending.clear()
return result.cleaned # the canned fallback phrase
self._cleared = True
- return result.cleaned
+ if not result.actions:
+ # Realtime providers stream transcript deltas with meaningful edge
+ # whitespace (for example ``"All"``, ``" right"``). The voice
+ # scrubber normalizes each call with ``strip()``, so returning its
+ # clean result here would glue every streamed word together. No
+ # scrub action means the original delta was safe; preserve it byte
+ # for byte, including punctuation-only and whitespace-only deltas.
+ return text
+ return _restore_edge_whitespace(text, result.cleaned)
async def push_audio(self, chunk: AudioChunk) -> list[AudioChunk]:
"""Buffer or release an audio delta. Returns chunks safe to play now."""
@@ -80,3 +88,14 @@ class ScrubHoldGate:
self._pending.clear()
self._cleared = False
self._hard_leak = False
+
+
+def _restore_edge_whitespace(original: str, cleaned: str) -> str:
+ """Keep provider delta separators around content changed by the scrubber."""
+ if not cleaned:
+ return cleaned
+ leading_count = len(original) - len(original.lstrip())
+ trailing_count = len(original) - len(original.rstrip())
+ leading = original[:leading_count]
+ trailing = original[-trailing_count:] if trailing_count else ""
+ return f"{leading}{cleaned}{trailing}"
diff --git a/jarvis/ui/web/frontend/src/components/sessions/TurnCard.test.tsx b/jarvis/ui/web/frontend/src/components/sessions/TurnCard.test.tsx
index 0524c3ca06..fa1a64c760 100644
--- a/jarvis/ui/web/frontend/src/components/sessions/TurnCard.test.tsx
+++ b/jarvis/ui/web/frontend/src/components/sessions/TurnCard.test.tsx
@@ -72,6 +72,23 @@ describe("TurnCard spoken track", () => {
expect(screen.queryByText("Spoken output")).toBeNull();
});
+ it("wraps very long transcript content without widening the turn card", () => {
+ const longUserText = `user-${"x".repeat(400)}`;
+ const longJarvisText = `assistant-${"y".repeat(400)}`;
+ const { container } = render(
+ <TurnCard
+ turn={turn({ user_text: longUserText, jarvis_text: longJarvisText })}
+ />,
+ );
+
+ expect(container.firstElementChild?.className).toContain("min-w-0");
+ for (const text of [longUserText, longJarvisText]) {
+ const block = screen.getByText(text);
+ expect(block.className).toContain("whitespace-pre-wrap");
+ expect(block.className).toContain("[overflow-wrap:anywhere]");
+ }
+ });
+
it("does NOT surface the technical detail in the transcript", () => {
// The technical diagnostic (exit code + raw harness reason) is still recorded
// on the SpeechSpoken event so the Run Inspector can show it, but it must NOT
diff --git a/jarvis/ui/web/frontend/src/components/sessions/TurnCard.tsx b/jarvis/ui/web/frontend/src/components/sessions/TurnCard.tsx
index 0684885e99..c99ff42c19 100644
--- a/jarvis/ui/web/frontend/src/components/sessions/TurnCard.tsx
+++ b/jarvis/ui/web/frontend/src/components/sessions/TurnCard.tsx
@@ -104,8 +104,8 @@ export function TurnCard({ turn, spoken = [] }: Props) {
});
return (
- <Card className="bg-background/40">
- <CardContent className="space-y-3 p-4">
+ <Card className="min-w-0 max-w-full bg-background/40">
+ <CardContent className="min-w-0 space-y-3 p-4">
{/* Header */}
<div className="flex items-center justify-between gap-2">
<div className="flex items-center gap-2 text-xs text-muted-foreground">
@@ -157,7 +157,7 @@ export function TurnCard({ turn, spoken = [] }: Props) {
{turn.user_lang}
</Badge>
</div>
- <div className="rounded-md border border-emerald-400/20 bg-emerald-400/5 p-2 text-sm">
+ <div className="min-w-0 whitespace-pre-wrap break-words rounded-md border border-emerald-400/20 bg-emerald-400/5 p-2 text-sm [overflow-wrap:anywhere]">
{turn.user_text}
</div>
</div>
@@ -233,7 +233,7 @@ export function TurnCard({ turn, spoken = [] }: Props) {
</Badge>
)}
</div>
- <div className="rounded-md border border-primary/20 bg-primary/5 p-2 text-sm">
+ <div className="min-w-0 whitespace-pre-wrap break-words rounded-md border border-primary/20 bg-primary/5 p-2 text-sm [overflow-wrap:anywhere]">
{turn.jarvis_text}
</div>
</div>
@@ -281,7 +281,9 @@ export function TurnCard({ turn, spoken = [] }: Props) {
stays on the recorded SpeechSpoken event and is shown
in the Run Inspector — never here (user request
2026-06-22, reversing the 2026-06-16 ask). */}
- <span className="break-words">{s.text}</span>
+ <span className="whitespace-pre-wrap break-words [overflow-wrap:anywhere]">
+ {s.text}
+ </span>
</div>
</div>
);
diff --git a/tests/unit/realtime/test_scrub_gate.py b/tests/unit/realtime/test_scrub_gate.py
index 3a0da28256..21c128b690 100644
--- a/tests/unit/realtime/test_scrub_gate.py
+++ b/tests/unit/realtime/test_scrub_gate.py
@@ -20,6 +20,25 @@ async def test_clean_transcript_releases_buffered_audio():
assert out # buffered + new audio flows once transcript cleared
+async def test_clean_transcript_preserves_provider_delta_boundaries():
+ gate = ScrubHoldGate(language="en")
+ raw_deltas = ["All", " right", ", ", "I", " can", " help", "."]
+
+ display_deltas = [await gate.feed_transcript(delta) for delta in raw_deltas]
+
+ assert "".join(display_deltas) == "All right, I can help."
+
+
+async def test_scrubbed_delta_keeps_its_original_leading_separator():
+ gate = ScrubHoldGate(language="en")
+
+ display = await gate.feed_transcript(" **ready**")
+
+ assert display == " ready"
+
+
@pytest.mark.asyncio
async def test_hard_leak_transcript_marks_leak_and_drops_audio():
gate = ScrubHoldGate(language="en")
diff --git a/tests/unit/realtime/test_transcript_persistence.py b/tests/unit/realtime/test_transcript_persistence.py
index 09da719a0d..67b1e01fb1 100644
--- a/tests/unit/realtime/test_transcript_persistence.py
+++ b/tests/unit/realtime/test_transcript_persistence.py
@@ -275,6 +275,47 @@ async def test_session_end_flushes_pending_turn_without_provider_completion(
store.close()
+async def test_streamed_output_deltas_keep_spaces_in_persisted_transcript(
+ tmp_path,
+) -> None:
+ provider = FakeRealtimeProvider(
+ "openai-realtime",
+ [
+ RealtimeEvent(
+ type="input_transcript", text="Can you help?", is_final=True
+ ),
+ RealtimeEvent(type="output_transcript_delta", text="All"),
+ RealtimeEvent(type="output_transcript_delta", text=" right"),
+ RealtimeEvent(type="output_transcript_delta", text=", "),
+ RealtimeEvent(type="output_transcript_delta", text="I"),
+ RealtimeEvent(type="output_transcript_delta", text=" can help"),
+ RealtimeEvent(type="output_transcript_delta", text="."),
+ RealtimeEvent(type="turn_complete"),
+ ],
+ )
+ store = SessionStore(tmp_path / "sessions.db")
+ store.open()
+ try:
+ bus = EventBus()
+ SessionRecorder(store).attach(bus)
+ session = await _start_session(
+ bus=bus,
+ provider=provider,
+ surface="browser",
+ tool_mode="direct",
+ session_id="streamed-spacing-session",
+ )
+ await session.wait_finished()
+ await _end_session(session, bus=bus, surface="browser", reason="ws_closed")
+
+ turns = store.get_turns("streamed-spacing-session")
+ assert len(turns) == 1
+ assert turns[0].jarvis_text == "All right, I can help."
+ finally:
+ store.close()
+
+
@pytest.mark.asyncio
async def test_assistant_output_without_input_transcript_still_persists_turn(
tmp_path,