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(voice): store a live call's words while it runs

rubenluetke10-beepe82c2c4c3708
diff --git a/jarvis/live/config.py b/jarvis/live/config.py
index a65186a2da..e657662888 100644
--- a/jarvis/live/config.py
+++ b/jarvis/live/config.py
@@ -31,6 +31,9 @@ class LiveConfig(BaseModel):
"not completion. Use discover_tools and call_tool for additional capabilities. "
"A superseded result describes earlier work, not the latest request; reconcile "
"the actual outcome with the latest correction without blindly repeating actions. "
+ "The current request is in this conversation. Stored transcripts and session "
+ "history from another session are earlier calls: never resume their tasks "
+ "unless the user asks for that. "
"Discover only the tools needed for the current task using a few English "
"keywords; reuse their schemas and still-current results from this conversation. "
"Read tool schemas before calling. Do not bypass denied actions. "
diff --git a/jarvis/sessions/recorder.py b/jarvis/sessions/recorder.py
index 4d40ff53b2..f5144bfabc 100644
--- a/jarvis/sessions/recorder.py
+++ b/jarvis/sessions/recorder.py
@@ -61,6 +61,7 @@ from jarvis.core.events import (
TranscriptPolished,
VoiceSessionEnded,
VoiceSessionStarted,
+ VoiceTranscriptUpdated,
VoiceTurnCompleted,
VoiceTurnStarted,
WakeWordDetected,
@@ -203,6 +204,12 @@ class _TurnState:
# Supervisor state changes may happen between those two events and must not
# close the row early under a recorder-generated boundary.
uses_explicit_lifecycle: bool = False
+ # Continuous-voice caption snapshots: segment_id -> (start_ms, revision,
+ # role, text), plus the texts last projected from them. A projection only
+ # replaces a text it wrote itself, never one an authoritative event set.
+ captions: dict[str, tuple[int, int, str, str]] = field(default_factory=dict)
+ caption_user_text: str = ""
+ caption_jarvis_text: str = ""
finalized: bool = False
@@ -347,6 +354,8 @@ class SessionRecorder:
self._on_transcription_update(event)
elif isinstance(event, TranscriptPolished):
self._on_transcript_polished(event)
+ elif isinstance(event, VoiceTranscriptUpdated):
+ self._on_voice_transcript(event)
elif isinstance(event, BrainTurnStarted):
self._on_brain_started(event)
elif isinstance(event, BrainTurnCompleted):
@@ -793,6 +802,44 @@ class SessionRecorder:
recovered.turn_id,
)
+ def _on_voice_transcript(self, event: VoiceTranscriptUpdated) -> None:
+ """Keep a continuous call's words on its open turn while it runs.
+
+ GPT-Live publishes only caption snapshots during the call; its words
+ reached this recorder once, in the archive ``VoiceTurnCompleted`` the
+ live session sends on close. Two failures followed (live 2026-10-01,
+ session 0071cf3a): while the call ran its turn row held no
+ ``user_text``, so ``session-latest-turn`` answered with the PREVIOUS
+ call and the backend model resumed that call's task; and when the
+ pipeline sealed the session first (client_stop), the archive arrived
+ too late and the call was stored without a single word.
+ """
+ assert self._state is not None
+ if event.session_id != self._state.session_id or not event.segment_id:
+ return
+ t = self._state.current_turn
+ if t is None or t.finalized:
+ return
+ known = t.captions.get(event.segment_id)
+ if known is not None and known[1] > event.revision:
+ return
+ t.captions[event.segment_id] = (event.start_ms, event.revision, event.role, event.text)
+ user_text = _caption_text(t.captions, "user")
+ jarvis_text = _caption_text(t.captions, "assistant")
+ changed = False
+ if user_text != t.caption_user_text and t.user_text in ("", t.caption_user_text):
+ t.user_text = user_text
+ changed = True
+ if jarvis_text != t.caption_jarvis_text and t.jarvis_text in ("", t.caption_jarvis_text):
+ t.jarvis_text = jarvis_text
+ changed = True
+ t.caption_user_text = user_text
+ t.caption_jarvis_text = jarvis_text
+ if changed:
+ self._store.record_turn_progress(
+ turn_id=t.turn_id, user_text=t.user_text, jarvis_text=t.jarvis_text
+ )
+
def _on_transcript_polished(self, event: TranscriptPolished) -> None:
"""Attach a polished reading to the turn whose words it re-reads.
@@ -1098,6 +1145,16 @@ def _normalize_intent_level_to_tier(intent_level: str) -> str:
return "router"
+def _caption_text(captions: dict[str, tuple[int, int, str, str]], role: str) -> str:
+ """One speaker's caption segments in spoken order, as one text."""
+ parts = sorted(
+ (start_ms, text.strip())
+ for start_ms, _revision, speaker, text in captions.values()
+ if speaker == role and text.strip()
+ )
+ return " ".join(text for _start, text in parts)
+
+
def _now_ms() -> int:
return int(time.time() * 1000)
diff --git a/jarvis/sessions/store.py b/jarvis/sessions/store.py
index 54dcada315..748a00ea85 100644
--- a/jarvis/sessions/store.py
+++ b/jarvis/sessions/store.py
@@ -375,6 +375,22 @@ class SessionStore:
),
)
+ def record_turn_progress(self, *, turn_id: str, user_text: str, jarvis_text: str) -> None:
+ """Store an OPEN turn's words so far; a finalized turn is never touched.
+
+ A continuous call is one turn that stays open until hang-up. Without
+ this, every reader of the store saw the running call as empty for its
+ whole length and fell back to the previous call.
+ """
+ with self._lock:
+ self._c.execute(
+ """
+ UPDATE voice_turns SET user_text = ?, jarvis_text = ?
+ WHERE id = ? AND ended_ms IS NULL
+ """,
+ (user_text, jarvis_text, turn_id),
+ )
+
def set_turn_polished(self, *, turn_id: str, text: str) -> None:
"""Attach the polished reading of a turn's user text.
diff --git a/tests/unit/sessions/test_recorder_live_captions.py b/tests/unit/sessions/test_recorder_live_captions.py
new file mode 100644
index 0000000000..1242f45293
--- /dev/null
+++ b/tests/unit/sessions/test_recorder_live_captions.py
@@ -0,0 +1,146 @@
+"""A continuous call's words reach the store while it runs, not only at close.
+
+Live 2026-10-01 (session 0071cf3a): the running GPT-Live call had no
+``user_text`` in its turn row, so ``session-latest-turn`` returned the previous
+call and the backend model resumed that call's task. The pipeline then sealed
+the session before the live archive arrived, and the call was stored empty.
+"""
+
+from __future__ import annotations
+
+import pytest
+
+from jarvis.core.bus import EventBus
+from jarvis.core.events import (
+ VoiceSessionEnded,
+ VoiceSessionStarted,
+ VoiceTranscriptUpdated,
+ VoiceTurnCompleted,
+ VoiceTurnStarted,
+)
+from jarvis.sessions.recorder import SessionRecorder
+from jarvis.sessions.store import SessionStore
+
+
+async def _start_call(bus: EventBus, session_id: str, turn_id: str) -> None:
+ await bus.publish(
+ VoiceSessionStarted(
+ source_layer="speech.pipeline", session_id=session_id, language="de"
+ )
+ )
+ await bus.publish(
+ VoiceTurnStarted(
+ source_layer="live.session", session_id=session_id, turn_id=turn_id
+ )
+ )
+
+
+def _caption(
+ session_id: str, segment: str, role: str, text: str, start_ms: int, revision: int = 1
+) -> VoiceTranscriptUpdated:
+ return VoiceTranscriptUpdated(
+ source_layer="live.transcript",
+ session_id=session_id,
+ segment_id=segment,
+ role=role, # type: ignore[arg-type]
+ text=text,
+ start_ms=start_ms,
+ end_ms=start_ms + 500,
+ revision=revision,
+ )
+
+
+async def test_running_call_is_the_latest_turn_not_the_previous_call(tmp_path) -> None:
+ store = SessionStore(tmp_path / "sessions.db")
+ store.open()
+ try:
+ bus = EventBus()
+ SessionRecorder(store).attach(bus)
+
+ await _start_call(bus, "old-call", "old-turn")
+ await bus.publish(
+ VoiceTurnCompleted(
+ source_layer="live.session",
+ session_id="old-call",
+ turn_id="old-turn",
+ user_text="Send the macOS task.",
+ jarvis_text="Sent.",
+ )
+ )
+ await bus.publish(VoiceSessionEnded(source_layer="test", session_id="old-call"))
+
+ await _start_call(bus, "new-call", "new-turn")
+ await bus.publish(_caption("new-call", "u1", "user", " Create a", 100))
+ await bus.publish(
+ _caption("new-call", "u1", "user", " Create a Trendfinder agent", 100, 2)
+ )
+ await bus.publish(_caption("new-call", "a1", "assistant", " On it.", 900))
+
+ latest = store.get_latest_user_turn()
+ assert latest is not None
+ assert latest.session_id == "new-call"
+ assert latest.user_text == "Create a Trendfinder agent"
+ assert latest.ended_ms is None
+ scoped = store.get_latest_user_turn(session_id="new-call")
+ assert scoped is not None and scoped.jarvis_text == "On it."
+ finally:
+ store.close()
+
+
+async def test_call_sealed_before_its_archive_keeps_its_words(tmp_path) -> None:
+ store = SessionStore(tmp_path / "sessions.db")
+ store.open()
+ try:
+ bus = EventBus()
+ SessionRecorder(store).attach(bus)
+ await _start_call(bus, "call", "turn")
+ await bus.publish(_caption("call", "u1", "user", " Hello", 100))
+ await bus.publish(_caption("call", "u2", "user", " and more", 4000))
+ await bus.publish(_caption("call", "a1", "assistant", " Hi.", 1000))
+ # The pipeline seals the session first; the live archive comes later
+ # and finds no open session.
+ await bus.publish(VoiceSessionEnded(source_layer="test", session_id="call"))
+ await bus.publish(
+ VoiceTurnCompleted(
+ source_layer="live.session",
+ session_id="call",
+ turn_id="turn",
+ user_text=" Hello and more",
+ )
+ )
+
+ (turn,) = store.get_turns("call")
+ assert turn.user_text == "Hello and more"
+ assert turn.jarvis_text == "Hi."
+ assert turn.ended_ms is not None
+ finally:
+ store.close()
+
+
+async def test_captions_never_replace_an_authoritative_text(tmp_path) -> None:
+ store = SessionStore(tmp_path / "sessions.db")
+ store.open()
+ try:
+ bus = EventBus()
+ SessionRecorder(store).attach(bus)
+ await _start_call(bus, "call", "turn")
+ await bus.publish(_caption("call", "u1", "user", " draft", 100))
+ await bus.publish(
+ VoiceTurnCompleted(
+ source_layer="live.session",
+ session_id="call",
+ turn_id="turn",
+ user_text="The archived words.",
+ )
+ )
+ # Another session's caption is not this call's words.
+ await bus.publish(_caption("other", "x1", "user", " stray", 200))
+ await bus.publish(VoiceSessionEnded(source_layer="test", session_id="call"))
+
+ (turn,) = store.get_turns("call")
+ assert turn.user_text == "The archived words."
+ finally:
+ store.close()