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(sessions): hide empty voice attempts from history

Ruben Lütke05478887623b
diff --git a/jarvis/sessions/store.py b/jarvis/sessions/store.py
index 67d265ec99..6c373c4f76 100644
--- a/jarvis/sessions/store.py
+++ b/jarvis/sessions/store.py
@@ -372,11 +372,16 @@ class SessionStore:
*,
limit: int = 100,
offset: int = 0,
+ include_empty: bool = True,
) -> list[SessionListItem]:
"""Sessions by started_ms desc — newest first.
``preview`` is the first user utterance (the first turn row with
- a non-empty ``user_text``).
+ a non-empty ``user_text``). Set ``include_empty=False`` for
+ conversation-history surfaces: finished attempts without any persisted
+ user or assistant transcript stay available to diagnostics, but do not
+ crowd out real conversations. Open sessions remain visible while they
+ wait for their first turn.
"""
with self._lock:
cur = self._c.execute(
@@ -389,10 +394,21 @@ class SessionStore:
ORDER BY t.idx ASC
LIMIT 1) AS preview
FROM voice_sessions s
+ WHERE ? = 1
+ OR s.ended_ms IS NULL
+ OR EXISTS (
+ SELECT 1
+ FROM voice_turns meaningful
+ WHERE meaningful.session_id = s.id
+ AND (
+ TRIM(COALESCE(meaningful.user_text, '')) != ''
+ OR TRIM(COALESCE(meaningful.jarvis_text, '')) != ''
+ )
+ )
ORDER BY s.started_ms DESC
LIMIT ? OFFSET ?
""",
- (limit, max(0, int(offset))),
+ (1 if include_empty else 0, limit, max(0, int(offset))),
)
rows = cur.fetchall()
# Per-row validation in a try/except: a single invalid row (e.g.
diff --git a/jarvis/ui/web/chats_routes.py b/jarvis/ui/web/chats_routes.py
index ac7cba407b..7f43114c2e 100644
--- a/jarvis/ui/web/chats_routes.py
+++ b/jarvis/ui/web/chats_routes.py
@@ -248,7 +248,7 @@ async def list_conversations(
]
if session_store is not None:
try:
- for s in session_store.list_sessions(limit=limit):
+ for s in session_store.list_sessions(limit=limit, include_empty=False):
items.append(_voice_session_to_summary(s))
except Exception as exc: # noqa: BLE001 — voice list must never 500 the page
log.warning("voice session list failed, showing text-only: %s", exc)
diff --git a/jarvis/ui/web/frontend/src/components/sessions/sessionSelection.test.ts b/jarvis/ui/web/frontend/src/components/sessions/sessionSelection.test.ts
new file mode 100644
index 0000000000..c53574bec4
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/components/sessions/sessionSelection.test.ts
@@ -0,0 +1,47 @@
+import { describe, expect, it } from "vitest";
+
+import type { SessionListItem } from "./types";
+import { resolveSelectedSessionId } from "./sessionSelection";
+
+function session(id: string, ended: boolean): SessionListItem {
+ return {
+ id,
+ started_ms: 1_000,
+ ended_ms: ended ? 2_000 : null,
+ hangup_reason: ended ? "hotkey" : "",
+ turn_count: ended ? 1 : 0,
+ total_cost_usd: 0,
+ total_tokens_in: 0,
+ total_tokens_out: 0,
+ providers_used: [],
+ language: "en",
+ wake_keyword: "hotkey",
+ voice_mode: "realtime",
+ duration_s: ended ? 1 : null,
+ preview: ended ? "Hello" : "",
+ };
+}
+
+describe("resolveSelectedSessionId", () => {
+ it("keeps a selection that remains visible", () => {
+ const sessions = [session("running", false), session("finished", true)];
+
+ expect(resolveSelectedSessionId(sessions, "running")).toBe("running");
+ });
+
+ it("moves from a filtered empty attempt to the newest finished transcript", () => {
+ const sessions = [session("running", false), session("finished", true)];
+
+ expect(resolveSelectedSessionId(sessions, "filtered-empty")).toBe("finished");
+ });
+
+ it("falls back to a running session only when no finished transcript exists", () => {
+ const sessions = [session("running", false)];
+
+ expect(resolveSelectedSessionId(sessions, null)).toBe("running");
+ });
+
+ it("clears selection when no transcripts remain", () => {
+ expect(resolveSelectedSessionId([], "filtered-empty")).toBeNull();
+ });
+});
diff --git a/jarvis/ui/web/frontend/src/components/sessions/sessionSelection.ts b/jarvis/ui/web/frontend/src/components/sessions/sessionSelection.ts
new file mode 100644
index 0000000000..3cc2262e3b
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/components/sessions/sessionSelection.ts
@@ -0,0 +1,13 @@
+import type { SessionListItem } from "./types";
+
+/** Keep transcript selection valid as running or empty rows enter and leave. */
+export function resolveSelectedSessionId(
+ sessions: SessionListItem[],
+ currentId: string | null,
+): string | null {
+ if (currentId !== null && sessions.some((session) => session.id === currentId)) {
+ return currentId;
+ }
+ const newestFinished = sessions.find((session) => session.ended_ms !== null);
+ return (newestFinished ?? sessions[0])?.id ?? null;
+}
diff --git a/jarvis/ui/web/frontend/src/views/SessionsView.tsx b/jarvis/ui/web/frontend/src/views/SessionsView.tsx
index 8eff2f1723..e03c63640d 100644
--- a/jarvis/ui/web/frontend/src/views/SessionsView.tsx
+++ b/jarvis/ui/web/frontend/src/views/SessionsView.tsx
@@ -12,6 +12,7 @@ import { useEventStore } from "@/store/events";
import { ViewHeader } from "@/views/ChatsView";
import { SessionDetail } from "@/components/sessions/SessionDetail";
import { SessionList } from "@/components/sessions/SessionList";
+import { resolveSelectedSessionId } from "@/components/sessions/sessionSelection";
import { useSessionDetail, useSessions } from "@/hooks/useSessions";
import { useT } from "@/i18n";
@@ -21,23 +22,16 @@ export function SessionsView() {
const sessionsQuery = useSessions();
const [selectedId, setSelectedId] = useState<string | null>(null);
- // On the first successful load, auto-select the newest **finished**
- // session. Rationale: ``list_sessions`` (store.py) also lists sessions
- // still in progress (``ended_ms === null``) — those show up at the very
- // top because they have the most recent ``started_ms``. If we
- // auto-selected one of those, the user would see an *empty* detail pane
- // when switching tabs during an ongoing voice session and think "my last
- // transcript is gone". We prefer the newest session with
- // ``ended_ms !== null`` (= fully finished, with aggregates);
- // only when there is no finished session do we fall back to the first
- // list item.
+ // Keep selection aligned with the visible list. A running attempt can be
+ // selected and then disappear after hangup when the API confirms that it
+ // contains no transcript. In that case, move to the newest finished
+ // transcript instead of leaving an invisible row selected in the detail
+ // pane. Initial selection follows the same rule.
useEffect(() => {
- if (selectedId !== null) return;
const list = sessionsQuery.data;
- if (!list || list.length === 0) return;
- const lastFinished = list.find((s) => s.ended_ms !== null);
- setSelectedId((lastFinished ?? list[0]).id);
- }, [sessionsQuery.data, selectedId]);
+ if (!list) return;
+ setSelectedId((currentId) => resolveSelectedSessionId(list, currentId));
+ }, [sessionsQuery.data]);
const detailQuery = useSessionDetail(selectedId);
diff --git a/jarvis/ui/web/sessions_routes.py b/jarvis/ui/web/sessions_routes.py
index 62c2362455..3fdf1ce9e7 100644
--- a/jarvis/ui/web/sessions_routes.py
+++ b/jarvis/ui/web/sessions_routes.py
@@ -70,14 +70,20 @@ def _require_store(request: Request) -> SessionStore:
async def list_sessions(
request: Request,
limit: int = Query(default=100, ge=1, le=500),
+ include_empty: bool = Query(
+ default=False,
+ description="Include finished voice attempts without transcript content.",
+ ),
) -> list[SessionListItem]:
- """List of all voice sessions, newest first.
+ """List transcript-bearing and currently running voice sessions, newest first.
The frontend calls this on tab switch to "Transcription" as well as
- after a ``VoiceSessionEnded`` WS event (refetch).
+ after a ``VoiceSessionEnded`` WS event (refetch). Empty completed attempts
+ remain queryable for diagnostics through ``include_empty=true`` and their
+ direct detail URL.
"""
store = _require_store(request)
- return store.list_sessions(limit=limit)
+ return store.list_sessions(limit=limit, include_empty=include_empty)
@router.get("/latest-turn", response_model=VoiceTurnRow)
diff --git a/tests/unit/sessions/test_empty_session_visibility.py b/tests/unit/sessions/test_empty_session_visibility.py
new file mode 100644
index 0000000000..52b0885eb8
--- /dev/null
+++ b/tests/unit/sessions/test_empty_session_visibility.py
@@ -0,0 +1,164 @@
+"""Visibility rules for empty voice-session attempts."""
+from __future__ import annotations
+
+from fastapi import FastAPI
+from fastapi.testclient import TestClient
+
+from jarvis.sessions.store import SessionStore
+from jarvis.ui.web import sessions_routes
+
+
+def _finalize_session(
+ store: SessionStore,
+ *,
+ session_id: str,
+ started_ms: int,
+ user_text: str = "",
+ assistant_text: str = "",
+) -> None:
+ store.upsert_session(
+ session_id=session_id,
+ started_ms=started_ms,
+ language="en",
+ voice_mode="realtime",
+ )
+ turn_count = 0
+ if user_text or assistant_text:
+ turn_id = f"{session_id}-turn"
+ store.upsert_turn(
+ turn_id=turn_id,
+ session_id=session_id,
+ idx=0,
+ started_ms=started_ms,
+ )
+ store.finalize_turn(
+ turn_id=turn_id,
+ ended_ms=started_ms + 500,
+ user_text=user_text,
+ user_lang="en" if user_text else "",
+ jarvis_text=assistant_text,
+ jarvis_lang="en" if assistant_text else "",
+ tier="realtime",
+ provider="test-live",
+ model="test-model",
+ tokens_in=0,
+ tokens_out=0,
+ cost_usd=0.0,
+ latency_total_ms=500,
+ tool_calls=[],
+ )
+ turn_count = 1
+ store.finalize_session(
+ session_id=session_id,
+ ended_ms=started_ms + 1_000,
+ hangup_reason="hotkey",
+ turn_count=turn_count,
+ total_cost_usd=0.0,
+ total_tokens_in=0,
+ total_tokens_out=0,
+ providers_used=[],
+ )
+
+
+def test_transcript_filter_keeps_content_and_open_sessions(tmp_path) -> None:
+ store = SessionStore(tmp_path / "sessions.db")
+ store.open()
+ try:
+ _finalize_session(
+ store,
+ session_id="meaningful",
+ started_ms=1_000,
+ user_text="Hello",
+ )
+ _finalize_session(
+ store,
+ session_id="assistant-only",
+ started_ms=2_000,
+ assistant_text="Microphone access is unavailable.",
+ )
+ _finalize_session(store, session_id="empty", started_ms=4_000)
+ store.upsert_session(
+ session_id="running",
+ started_ms=3_000,
+ language="en",
+ voice_mode="unknown",
+ )
+
+ visible = store.list_sessions(limit=10, include_empty=False)
+ all_attempts = store.list_sessions(limit=10, include_empty=True)
+
+ assert [session.id for session in visible] == [
+ "running",
+ "assistant-only",
+ "meaningful",
+ ]
+ assert [session.id for session in all_attempts] == [
+ "empty",
+ "running",
+ "assistant-only",
+ "meaningful",
+ ]
+ finally:
+ store.close()
+
+
+def test_empty_attempts_do_not_consume_the_visible_limit(tmp_path) -> None:
+ store = SessionStore(tmp_path / "sessions.db")
+ store.open()
+ try:
+ _finalize_session(
+ store,
+ session_id="meaningful",
+ started_ms=1_000,
+ user_text="Hello",
+ )
+ for index in range(2, 8):
+ _finalize_session(
+ store,
+ session_id=f"empty-{index}",
+ started_ms=index * 1_000,
+ )
+
+ visible = store.list_sessions(limit=1, include_empty=False)
+
+ assert [session.id for session in visible] == ["meaningful"]
+ finally:
+ store.close()
+
+
+def test_sessions_api_hides_empty_attempts_but_keeps_diagnostics_access(
+ tmp_path,
+) -> None:
+ store = SessionStore(tmp_path / "sessions.db")
+ store.open()
+ try:
+ _finalize_session(
+ store,
+ session_id="meaningful",
+ started_ms=1_000,
+ user_text="Hello",
+ )
+ _finalize_session(store, session_id="empty", started_ms=2_000)
+ app = FastAPI()
+ app.include_router(sessions_routes.router)
+ app.state.session_store = store
+
+ with TestClient(app) as client:
+ visible = client.get("/api/sessions")
+ all_attempts = client.get(
+ "/api/sessions",
+ params={"include_empty": True},
+ )
+ empty_detail = client.get("/api/sessions/empty")
+
+ assert visible.status_code == 200
+ assert [session["id"] for session in visible.json()] == ["meaningful"]
+ assert all_attempts.status_code == 200
+ assert [session["id"] for session in all_attempts.json()] == [
+ "empty",
+ "meaningful",
+ ]
+ assert empty_detail.status_code == 200
+ assert empty_detail.json()["turns"] == []
+ finally:
+ store.close()
diff --git a/tests/unit/state/test_chats_routes.py b/tests/unit/state/test_chats_routes.py
index 1a923bd55c..98f360469f 100644
--- a/tests/unit/state/test_chats_routes.py
+++ b/tests/unit/state/test_chats_routes.py
@@ -8,7 +8,6 @@ from __future__ import annotations
from types import SimpleNamespace
import httpx
-import pytest
from fastapi import FastAPI
from jarvis.core.bus import EventBus
@@ -55,7 +54,7 @@ def _fake_session_store():
]
return SimpleNamespace(
- list_sessions=lambda *, limit=100: list(sessions),
+ list_sessions=lambda *, limit=100, include_empty=True: list(sessions),
get_session=lambda cid: sessions[0] if cid == "v1" else None,
get_turns=lambda cid: list(turns) if cid == "v1" else [],
)