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(wiki): VoiceFactBridge.stop() never actually left the bus
rubenluetke10-beepe663a7c976dc
diff --git a/jarvis/memory/wiki/voice_bridge.py b/jarvis/memory/wiki/voice_bridge.pyindex e54f96bf33..71f6edb979 100644--- a/jarvis/memory/wiki/voice_bridge.py+++ b/jarvis/memory/wiki/voice_bridge.py@@ -164,7 +164,12 @@ class VoiceFactBridge:# (WikiIntegrationConfig.fallback_to_direct_ingest posture).self._extractor = extractorself._pending = _PendingTurn()- self._unsubs: list[Any] = []+ # (event type, handler) pairs, because EventBus.subscribe returns None:+ # detaching needs both halves handed back to unsubscribe(). This used to+ # hold the return value of subscribe() and therefore a list of None,+ # whose call raised into a bare except — stop() cleared the list and+ # left every handler attached to the bus.+ self._subscriptions: list[tuple[type[Any], Any]] = []self._inflight: set[asyncio.Task[Any]] = set()self._session_inflight: dict[str, set[asyncio.Task[Any]]] = {}# In-call extraction jobs held back until the session ends (AP-9).@@ -192,21 +197,19 @@ class VoiceFactBridge:"""Subscribe to the turn events of both voice engines."""if self._started:return- self._unsubs.append(- self._bus.subscribe(TranscriptFinal, self._on_transcript_final)- )- self._unsubs.append(- self._bus.subscribe(MessageSent, self._on_user_message)- )- self._unsubs.append(- self._bus.subscribe(ResponseGenerated, self._on_response_generated)- )- self._unsubs.append(- self._bus.subscribe(VoiceTurnCompleted, self._on_voice_turn_completed)- )- self._unsubs.append(- self._bus.subscribe(VoiceSessionEnded, self._on_voice_session_ended)+ # Annotated: the five handlers have five different event parameters, and+ # an unannotated literal makes the checker join them into a union that+ # no longer matches subscribe()'s Callable[[Event], ...].+ wiring: tuple[tuple[type[Any], Any], ...] = (+ (TranscriptFinal, self._on_transcript_final),+ (MessageSent, self._on_user_message),+ (ResponseGenerated, self._on_response_generated),+ (VoiceTurnCompleted, self._on_voice_turn_completed),+ (VoiceSessionEnded, self._on_voice_session_ended),)+ for event_type, handler in wiring:+ self._bus.subscribe(event_type, handler)+ self._subscriptions.append((event_type, handler))self._started = Truelog.info("VoiceFactBridge started "@@ -241,12 +244,14 @@ class VoiceFactBridge:def _cancel_and_unsubscribe(self) -> tuple[asyncio.Task[Any], ...]:"""Stop accepting work and return tasks whose cancellation must drain."""- for unsub in self._unsubs:+ for event_type, handler in self._subscriptions:try:- unsub()- except Exception: # noqa: BLE001, S110- pass- self._unsubs.clear()+ self._bus.unsubscribe(event_type, handler)+ except Exception: # noqa: BLE001 — teardown reports, never raises+ log.debug(+ "VoiceFactBridge: could not detach %s", event_type.__name__, exc_info=True+ )+ self._subscriptions.clear()tasks = tuple(self._inflight)for task in tasks:task.cancel()diff --git a/tests/unit/memory/wiki/test_voice_bridge_detach.py b/tests/unit/memory/wiki/test_voice_bridge_detach.pynew file mode 100644index 0000000000..a1ace75b5d--- /dev/null+++ b/tests/unit/memory/wiki/test_voice_bridge_detach.py@@ -0,0 +1,97 @@+"""``VoiceFactBridge.stop()`` must actually detach from the bus.++Regression guard for a silent leak: ``start()`` used to store the RETURN VALUE+of ``EventBus.subscribe``, which is ``None`` — so ``stop()`` iterated a list of+``None``, ``None()`` raised, a bare ``except Exception: pass`` swallowed it, and+the list was cleared with every handler still attached. Nothing failed loudly;+the bridge simply kept ingesting after it had been stopped, and a restart+stacked a second live set of handlers on top of the first.++The contract these tests pin is the observable one — what the bus holds, and+whether a handler still runs — not how the bridge stores its bookkeeping.+"""+from __future__ import annotations++import asyncio++from jarvis.core.bus import EventBus+from jarvis.core.config import VoiceBridgeConfig+from jarvis.core.events import (+ MessageSent,+ ResponseGenerated,+ TranscriptFinal,+ VoiceSessionEnded,+ VoiceTurnCompleted,+)+from jarvis.memory.wiki.voice_bridge import VoiceFactBridge++SUBSCRIBED_EVENTS = (+ TranscriptFinal,+ MessageSent,+ ResponseGenerated,+ VoiceTurnCompleted,+ VoiceSessionEnded,+)+++def _bridge(bus: EventBus) -> VoiceFactBridge:+ return VoiceFactBridge(+ bus=bus, curator=None, config=VoiceBridgeConfig(), extractor=None+ )+++def _attached(bus: EventBus) -> int:+ return sum(len(bus._subscribers.get(event, [])) for event in SUBSCRIBED_EVENTS) # noqa: SLF001+++def test_start_attaches_and_stop_detaches() -> None:+ bus = EventBus()+ bridge = _bridge(bus)++ bridge.start()+ assert _attached(bus) == len(SUBSCRIBED_EVENTS)++ bridge.stop()+ assert _attached(bus) == 0+++def test_a_stopped_bridge_ignores_a_later_turn() -> None:+ """The leak's real symptom: work continued after the bridge was stopped."""+ bus = EventBus()+ bridge = _bridge(bus)+ bridge.start()+ bridge.stop()++ seen: list[str] = []++ async def _witness(event: VoiceTurnCompleted) -> None:+ seen.append(event.user_text)++ bus.subscribe(VoiceTurnCompleted, _witness)++ async def _drive() -> None:+ await bus.publish(+ VoiceTurnCompleted(user_text="after stop", jarvis_text="ok", tier="realtime")+ )++ asyncio.run(_drive())++ # The witness proves the event was really delivered, so an empty bridge+ # state cannot be mistaken for an event that never fired.+ assert seen == ["after stop"]+ assert _attached(bus) == 1 # only the witness+++def test_stop_is_idempotent_and_restart_does_not_stack_handlers() -> None:+ bus = EventBus()+ bridge = _bridge(bus)++ bridge.start()+ bridge.stop()+ bridge.stop()+ assert _attached(bus) == 0++ bridge.start()+ assert _attached(bus) == len(SUBSCRIBED_EVENTS)+ bridge.stop()+ assert _attached(bus) == 0