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(chat): restore voice history and hide phantom text threads
Ruben Lütkea8295de811d0
diff --git a/jarvis/state/chat_store.py b/jarvis/state/chat_store.pyindex f54a52d1d3..37e42f9ce4 100644--- a/jarvis/state/chat_store.py+++ b/jarvis/state/chat_store.py@@ -140,12 +140,17 @@ class ChatStore:self._conn = None# ------- Queries (sync, reads are idempotent) ---------------------- def list_threads(self) -> list[dict[str, Any]]:+ def list_threads(self, *, include_empty: bool = True) -> list[dict[str, Any]]:"""All threads, most-recently-active first.Recency uses the largest message ``rowid`` per thread (monotonic withinsertion across all threads), so it is deterministic regardless ofclock granularity. Empty threads sort last by creation order.++ Conversation-history surfaces pass ``include_empty=False``. For text+ chats, a conversation starts with a user turn: rows with no persisted+ user message are either unsent drafts or legacy assistant-only residue+ and must not masquerade as real text conversations."""conn = self._ensure_conn()with self._lock:@@ -159,14 +164,26 @@ class ChatStore:t.updated_at_ns AS updated_at_ns,(SELECT COUNT(*) FROM chat_messages mWHERE m.thread_id = t.thread_id) AS message_count,+ (SELECT COUNT(*) FROM chat_messages m+ WHERE m.thread_id = t.thread_id+ AND m.role = 'user'+ AND TRIM(m.text) != ''+ ) AS user_message_count,(SELECT m.text FROM chat_messages mWHERE m.thread_id = t.thread_id AND m.role = 'user'ORDER BY m.rowid LIMIT 1) AS preview,(SELECT MAX(m.rowid) FROM chat_messages mWHERE m.thread_id = t.thread_id) AS last_seqFROM chat_threads t+ WHERE ? = 1 OR EXISTS (+ SELECT 1 FROM chat_messages visible+ WHERE visible.thread_id = t.thread_id+ AND visible.role = 'user'+ AND TRIM(visible.text) != ''+ )ORDER BY (last_seq IS NULL), last_seq DESC, t.rowid DESC- """+ """,+ (1 if include_empty else 0,),).fetchall()return [{@@ -176,6 +193,7 @@ class ChatStore:"created_at_ns": r["created_at_ns"],"updated_at_ns": r["updated_at_ns"],"message_count": r["message_count"],+ "user_message_count": r["user_message_count"],"preview": r["preview"] or "",}for r in rows@@ -261,7 +279,12 @@ class ChatStore:await self.create_thread(title=title, thread_id=thread_id, kind=kind)async def add_message(- self, *, thread_id: str, role: str, text: str+ self,+ *,+ thread_id: str,+ role: str,+ text: str,+ publish_event: bool = True,) -> ChatMessage:await self.ensure_thread(thread_id)msg = ChatMessage(@@ -294,14 +317,15 @@ class ChatStore:"UPDATE chat_threads SET title = ? WHERE thread_id = ?",(_derive_title(text), thread_id),)- await self._bus.publish(- MessageSent(- source_layer="chat",- thread_id=thread_id,- role=role,- text=text,+ if publish_event:+ await self._bus.publish(+ MessageSent(+ source_layer="chat",+ thread_id=thread_id,+ role=role,+ text=text,+ ))- )return msgasync def delete_thread(self, thread_id: str) -> bool:diff --git a/jarvis/ui/desktop_app.py b/jarvis/ui/desktop_app.pyindex 9b8505f69c..19fe04c7da 100644--- a/jarvis/ui/desktop_app.py+++ b/jarvis/ui/desktop_app.py@@ -1470,6 +1470,15 @@ class DesktopApp:returnthread_id = evt.thread_id or "default"+ # Persist the initiating turn before the reply. Older builds stored+ # only the assistant half, producing anonymous "New Thread" rows+ # that looked like text messages the user never sent.+ await chat_store.add_message(+ thread_id=thread_id,+ role="user",+ text=evt.text,+ publish_event=False,+ )from loguru import loggerbrain = await _await_brain_ready()diff --git a/jarvis/ui/web/chats_routes.py b/jarvis/ui/web/chats_routes.pyindex 7f43114c2e..d724d0c944 100644--- a/jarvis/ui/web/chats_routes.py+++ b/jarvis/ui/web/chats_routes.py@@ -244,7 +244,7 @@ async def list_conversations(session_store = _optional_session_store(request)items: list[ConversationSummary] = [- _text_thread_to_summary(t) for t in chat_store.list_threads()+ _text_thread_to_summary(t) for t in chat_store.list_threads(include_empty=False)]if session_store is not None:try:diff --git a/jarvis/ui/web/launcher.py b/jarvis/ui/web/launcher.pyindex 804d4c1fa4..ef2059cf9f 100644--- a/jarvis/ui/web/launcher.py+++ b/jarvis/ui/web/launcher.py@@ -561,6 +561,15 @@ async def _run_headless(args) -> int:if evt.source_layer in ("chat", "brain:mock"):returnthread_id = evt.thread_id or "default"+ # Persist the initiating turn before the reply. Older builds stored only+ # the assistant half, producing anonymous "New Thread" rows that looked+ # like text messages the user never sent.+ await chat_store.add_message(+ thread_id=thread_id,+ role="user",+ text=evt.text,+ publish_event=False,+ )# The brain is built in the background (off the boot critical path); a# first turn that arrives before it finishes waits (bounded) for it# rather than erroring — the honest deferral contract.diff --git a/tests/unit/state/test_chat_store_persistence.py b/tests/unit/state/test_chat_store_persistence.pyindex 2292e85f97..8da5d4e817 100644--- a/tests/unit/state/test_chat_store_persistence.py+++ b/tests/unit/state/test_chat_store_persistence.py@@ -8,8 +8,6 @@ in-process without touching disk."""from __future__ import annotations-import pytest-from jarvis.core.bus import EventBusfrom jarvis.core.events import MessageSentfrom jarvis.state.chat_store import ChatStore@@ -58,6 +56,22 @@ async def test_list_threads_newest_first_with_preview(tmp_path) -> None:assert old["updated_at_ns"] >= old["created_at_ns"]+async def test_history_filter_hides_drafts_and_assistant_only_residue(tmp_path) -> None:+ s = ChatStore(bus=EventBus(), db_path=_db(tmp_path))+ await s.create_thread(title="New Chat", thread_id="draft")+ await s.add_message(thread_id="orphan", role="assistant", text="internal reply")+ await s.add_message(thread_id="blank", role="user", text=" ")+ await s.add_message(thread_id="real", role="user", text="visible conversation")++ assert {r["thread_id"] for r in s.list_threads()} == {+ "blank",+ "draft",+ "orphan",+ "real",+ }+ assert [r["thread_id"] for r in s.list_threads(include_empty=False)] == ["real"]++async def test_title_derived_from_first_user_message(tmp_path) -> None:s = ChatStore(bus=EventBus(), db_path=_db(tmp_path))await s.add_message(@@ -88,6 +102,26 @@ async def test_add_message_publishes_message_sent(tmp_path) -> None:assert any(e.text == "ping" and e.thread_id == "t" for e in seen)+async def test_add_message_can_persist_an_already_published_event(tmp_path) -> None:+ bus = EventBus()+ seen: list[MessageSent] = []++ async def _collect(e: MessageSent) -> None:+ seen.append(e)++ bus.subscribe(MessageSent, _collect)+ s = ChatStore(bus=bus, db_path=_db(tmp_path))+ await s.add_message(+ thread_id="t",+ role="user",+ text="persist once",+ publish_event=False,+ )++ assert s.get_thread("t")["messages"][0]["text"] == "persist once"+ assert seen == []++async def test_delete_thread(tmp_path) -> None:s = ChatStore(bus=EventBus(), db_path=_db(tmp_path))await s.add_message(thread_id="t", role="user", text="bye")diff --git a/tests/unit/state/test_chats_routes.py b/tests/unit/state/test_chats_routes.pyindex 98f360469f..f097698efe 100644--- a/tests/unit/state/test_chats_routes.py+++ b/tests/unit/state/test_chats_routes.py@@ -100,6 +100,20 @@ async def test_list_text_only_without_session_store() -> None:assert [row["kind"] for row in rows] == ["text"]+async def test_list_hides_unsent_and_assistant_only_text_threads() -> None:+ app, store = await _make_app(with_session=False)+ await store.create_thread(title="New Chat", thread_id="draft")+ await store.add_message(thread_id="orphan", role="assistant", text="internal reply")+ await store.add_message(thread_id="blank", role="user", text=" ")+ await store.add_message(thread_id="real", role="user", text="actual text chat")++ async with _client(app) as c:+ r = await c.get("/api/chats")++ assert r.status_code == 200+ assert [row["id"] for row in r.json()] == ["real"]++async def test_get_text_conversation_detail() -> None:app, store = await _make_app()await store.add_message(thread_id="t1", role="user", text="q")