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): publish the session-end event from every surface, not only browser

Ruben Lütke2e91e87cafd6
diff --git a/jarvis/realtime/session.py b/jarvis/realtime/session.py
index c74d33e60e..2f98dd5e03 100644
--- a/jarvis/realtime/session.py
+++ b/jarvis/realtime/session.py
@@ -4060,10 +4060,16 @@ class RealtimeVoiceSession:
await self._tool_bridge.close()
except Exception: # noqa: BLE001, S110 — teardown is best-effort
pass
- if (
- self._surface == "browser"
- and self._browser_session_started
- and self._bus is not None
+ # Every surface publishes the logical session end. The browser
+ # surface has no other publisher (it bypasses the speech pipeline),
+ # so it keeps its started-gate; the desktop surface ALSO gets one
+ # from the pipeline's teardown — subscribers that consume per-session
+ # state (the wiki VoiceFactBridge sweep pops its turn buffer) treat
+ # the second event with the same session_id as a natural no-op, and
+ # the redundancy keeps the wiki completeness sweep alive even when
+ # one layer misses its teardown.
+ if self._bus is not None and (
+ self._surface != "browser" or self._browser_session_started
):
try:
from jarvis.core.events import VoiceSessionEnded
diff --git a/tests/unit/memory/wiki/test_voice_bridge_realtime.py b/tests/unit/memory/wiki/test_voice_bridge_realtime.py
index a6df4f8738..d3b969a663 100644
--- a/tests/unit/memory/wiki/test_voice_bridge_realtime.py
+++ b/tests/unit/memory/wiki/test_voice_bridge_realtime.py
@@ -387,3 +387,34 @@ async def test_session_end_runs_one_full_realtime_sweep(tmp_path: Path) -> None:
assert brain.call_count == 2
assert journal.capture_summary()["sessions_swept"] == 1
+
+
+async def test_duplicate_session_end_sweeps_only_once(tmp_path: Path) -> None:
+ """On desktop BOTH the realtime session and the speech pipeline publish
+ VoiceSessionEnded with the same session_id. The first event pops the
+ per-session turn buffer, so the duplicate must be a natural no-op."""
+ bus, journal, _curator, bridge, brain = _stack(tmp_path)
+ try:
+ await bus.publish(_realtime_turn(FACT_SENTENCE, "Okay.", turn_id="turn-a"))
+ await _wait_for_calls(brain, 1)
+ await bus.publish(
+ VoiceSessionEnded(session_id="rt-session", hangup_reason="hotkey")
+ )
+ await bus.publish(
+ VoiceSessionEnded(session_id="rt-session", hangup_reason="client_stop")
+ )
+ await _wait_for_calls(brain, 2)
+ deadline = time.monotonic() + 2.0
+ while ( # noqa: ASYNC110 - polls a persisted counter with a hard deadline
+ journal.capture_summary()["sessions_swept"] < 1
+ and time.monotonic() < deadline
+ ):
+ await asyncio.sleep(0.02)
+ # Give a hypothetical second sweep a moment to (wrongly) start.
+ await asyncio.sleep(0.1)
+ finally:
+ bridge.stop()
+
+ assert brain.call_count == 2 # one turn extraction + ONE sweep
+ assert journal.capture_summary()["sessions_swept"] == 1
diff --git a/tests/unit/realtime/test_session.py b/tests/unit/realtime/test_session.py
index a79d0f3ea6..bf0863ae71 100644
--- a/tests/unit/realtime/test_session.py
+++ b/tests/unit/realtime/test_session.py
@@ -1040,8 +1040,14 @@ async def test_desktop_session_publishes_effective_provider_and_completed_turn()
assert completed.model == "live-model"
assert completed.user_text == "Hello"
assert completed.jarvis_text == "Hi there."
+ # VoiceSessionStarted stays pipeline-owned on desktop; the session END is
+ # published from every surface so the wiki completeness sweep never
+ # depends on the outer layer alone. The desktop pipeline publishes a
+ # second end event with the same session_id; sweep consumers treat the
+ # duplicate as a no-op (their per-session buffer is popped by the first).
assert "VoiceSessionStarted" not in by_name
- assert "VoiceSessionEnded" not in by_name
+ ended = by_name["VoiceSessionEnded"]
+ assert ended.session_id == "desktop-telemetry"
@pytest.mark.asyncio