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(voice): preserve active calls when reopening their chat
rubenluetke10-beep4f76cb694aec
diff --git a/jarvis/ui/web/frontend/src/components/home/RecentChats.test.tsx b/jarvis/ui/web/frontend/src/components/home/RecentChats.test.tsxindex 9726781e05..be6eff5eaf 100644--- a/jarvis/ui/web/frontend/src/components/home/RecentChats.test.tsx+++ b/jarvis/ui/web/frontend/src/components/home/RecentChats.test.tsx@@ -1,4 +1,4 @@-import { act, cleanup, fireEvent, render, screen } from "@testing-library/react";+import { act, cleanup, fireEvent, render, screen, waitFor } from "@testing-library/react";import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";import { RecentChats, compactChatTitle } from "@/components/home/RecentChats";@@ -48,8 +48,11 @@ describe("RecentChats", () => {activeThreadId: null,messages: [],activeSection: "board",+ activeKind: "text",+ voiceState: "idle",});- useHomeStore.setState({ surface: "voice", transcript: [] });+ useHomeStore.setState({ surface: "voice", transcript: [], liveReply: "", liveSessionId: null,+ continuedVoiceId: null, voiceSelectionPending: false, voiceSwitchStopping: false });useAgentChatStore.setState({sessions: [{@@ -106,6 +109,81 @@ describe("RecentChats", () => {]);});+ it.each(["listening", "thinking", "speaking", "paused", "connecting"] as const)(+ "returns to the current %s call without ending it or replacing its live transcript", async (voiceState) => {+ const transcript = [{ id: "live-line", who: "user" as const, text: "Current question", ts: 3_000 }];+ useEventStore.setState({ voiceState, activeSection: "board" });+ useHomeStore.setState({ liveSessionId: "v1", transcript, liveReply: "Reply in progress", surface: "chat" });+ render(<RecentChats />);+ fireEvent.click(screen.getByTitle("Spoken thread"));+ await flush();+ expect(vi.mocked(fetch).mock.calls.some(([url]) => String(url).includes("/hangup") || String(url).endsWith("/resume"))).toBe(false);+ expect(useEventStore.getState().voiceState).toBe(voiceState);+ expect(useEventStore.getState().activeSection).toBe("chats");+ expect(useEventStore.getState().activeThreadId).toBe("v1");+ expect(useHomeStore.getState().surface).toBe("voice");+ expect(useHomeStore.getState().transcript).toBe(transcript);+ expect(useHomeStore.getState().liveReply).toBe("Reply in progress");+ expect(useHomeStore.getState().voiceSelectionPending).toBe(false);+ expect(useAgentChatStore.getState().newChat).not.toHaveBeenCalled();+ },+ );++ it("recognizes a running call recorded into a continued voice chat", async () => {+ useEventStore.setState({ voiceState: "speaking" });+ useHomeStore.setState({ liveSessionId: "current-call", continuedVoiceId: "v1", liveReply: "Still speaking" });+ render(<RecentChats />);+ fireEvent.click(screen.getByTitle("Spoken thread"));+ await flush();+ expect(vi.mocked(fetch).mock.calls.some(([url]) => String(url).includes("/hangup") || String(url).endsWith("/resume"))).toBe(false);+ expect(useHomeStore.getState().liveSessionId).toBe("current-call");+ expect(useHomeStore.getState().continuedVoiceId).toBe("v1");+ expect(useHomeStore.getState().liveReply).toBe("Still speaking");+ });++ it("still loads an ended call when its last session id remains in the store", async () => {+ useHomeStore.setState({ liveSessionId: "v1", continuedVoiceId: "v1" });+ render(<RecentChats />);+ fireEvent.click(screen.getByTitle("Spoken thread"));+ await flush();+ expect(fetch).toHaveBeenCalledWith("/api/chats/voice/v1/resume", { method: "POST" });+ expect(useHomeStore.getState().transcript.map((line) => line.text)).toEqual(["hello", "Hi there."]);+ });++ it("does not mistake another archive for the running call when selecting its row", async () => {+ useEventStore.setState({ voiceState: "listening" });+ useHomeStore.setState({ liveSessionId: "other-call", continuedVoiceId: "other-archive" });+ render(<RecentChats />);+ fireEvent.click(screen.getByTitle("Spoken thread"));+ await waitFor(() => expect(fetch).toHaveBeenCalledWith("/api/voice/hangup", { method: "POST", cache: "no-store" }));+ expect(vi.mocked(fetch).mock.calls.some(([url]) => String(url).endsWith("/resume"))).toBe(false);+ await act(async () => {+ useHomeStore.getState().ingest("VoiceSessionEnded", { session_id: "other-call", hangup_reason: "client_stop" }, 3);+ useEventStore.getState().setVoice("idle");+ });+ await waitFor(() => expect(useHomeStore.getState().transcript.map((line) => line.text)).toEqual(["hello", "Hi there."]));+ });++ it("keeps the live transcript when an older archive read finishes after returning to the call", async () => {+ let finish!: (response: Response) => void;+ vi.mocked(fetch).mockImplementation(async (url) => String(url).endsWith("/resume")+ ? new Promise<Response>((resolve) => { finish = resolve; })+ : new Response(JSON.stringify(CONVERSATIONS), { status: 200 }));+ render(<RecentChats />);+ fireEvent.click(screen.getByTitle("Spoken thread"));+ await waitFor(() => expect(finish).toBeTypeOf("function"));+ const transcript = [{ id: "live", who: "user" as const, text: "New live words", ts: 3 }];+ act(() => {+ useHomeStore.setState({ liveSessionId: "v1", transcript });+ useEventStore.setState({ voiceState: "listening", activeSection: "board" });+ });+ fireEvent.click(screen.getByTitle("Spoken thread"));+ await act(async () => { finish(new Response(JSON.stringify(DETAIL), { status: 200 })); });+ expect(useHomeStore.getState().transcript).toBe(transcript);+ expect(useEventStore.getState().activeThreadId).toBe("v1");+ expect(useHomeStore.getState().voiceSelectionPending).toBe(false);+ });+it("marks voice and typed chats apart and names a topicless voice chat by its kind", async () => {useEventStore.setState({conversations: [...CONVERSATIONS, { ...row("voice", "v2", ""), preview: "Hallo" }],diff --git a/jarvis/ui/web/frontend/src/components/home/chatRows.ts b/jarvis/ui/web/frontend/src/components/home/chatRows.tsindex c6cac4b09d..9daa7557f1 100644--- a/jarvis/ui/web/frontend/src/components/home/chatRows.ts+++ b/jarvis/ui/web/frontend/src/components/home/chatRows.ts@@ -51,7 +51,7 @@ export interface ChatRowsApi {}export function useChatRows({ poll = false }: { poll?: boolean } = {}): ChatRowsApi {- const { conversations, openConversation } = useConversations({ poll });+ const { conversations, openConversation, reopenLiveConversation } = useConversations({ poll });const sessions = useAgentChatStore((s) => s.sessions);const activeSessionId = useAgentChatStore((s) => s.activeSessionId);const activeVoiceId = useEventStore((s) => (s.activeKind === "voice" ? s.activeThreadId : null));@@ -101,6 +101,11 @@ export function useChatRows({ poll = false }: { poll?: boolean } = {}): ChatRows// an agent's chat opened from the sidebar.useHomeStore.getState().openAgentChat(null);if (row.kind === "voice") {+ if (reopenLiveConversation(row.id)) {+ setSurface("voice");+ setActiveSection("chats");+ return;+ }// End the agent session on stage first: the chat stage renders the// voice archive only while no agent chat is open, and its socket has// no business staying connected to a conversation nobody is looking at.@@ -111,7 +116,9 @@ export function useChatRows({ poll = false }: { poll?: boolean } = {}): ChatRowsconst stayOnVoice = useHomeStore.getState().surface === "voice";const opened = openConversation("voice", row.id);if (stayOnVoice) {- void opened.then((messages) => seedTranscript(transcriptFromMessages(messages)));+ void opened.then((messages) => {+ if (messages !== null) seedTranscript(transcriptFromMessages(messages));+ });} else {void opened;setSurface("chat");@@ -126,7 +133,7 @@ export function useChatRows({ poll = false }: { poll?: boolean } = {}): ChatRows}setActiveSection("chats");},- [openConversation, seedTranscript, setActiveConversation, setActiveSection, setMessages, setSurface],+ [openConversation, reopenLiveConversation, seedTranscript, setActiveConversation, setActiveSection, setMessages, setSurface],);const remove = useCallback((row: ChatRow) => {diff --git a/jarvis/ui/web/frontend/src/components/society/chat/JarvisHistoryRail.test.tsx b/jarvis/ui/web/frontend/src/components/society/chat/JarvisHistoryRail.test.tsxindex c35e3d6da9..4bbd14344b 100644--- a/jarvis/ui/web/frontend/src/components/society/chat/JarvisHistoryRail.test.tsx+++ b/jarvis/ui/web/frontend/src/components/society/chat/JarvisHistoryRail.test.tsx@@ -67,7 +67,7 @@ function json(body: unknown, status = 200) {describe("JarvisHistoryRail", () => {beforeEach(() => {vi.clearAllMocks();- useHomeStore.setState({ voiceSelectionPending: false, voiceSwitchStopping: false });+ useHomeStore.setState({ voiceSelectionPending: false, voiceSwitchStopping: false, continuedVoiceId: null });useHomeStore.getState().resetTranscript();Element.prototype.scrollIntoView = vi.fn();vi.stubGlobal("WebSocket", FakeSocket);@@ -141,6 +141,21 @@ describe("JarvisHistoryRail", () => {expect(setJarvisCardMode).toHaveBeenCalledWith("voice");});+ test("returning to the running call preserves its captions and never resumes or ends it", async () => {+ const transcript = [{ id: "live", who: "assistant" as const, text: "Current answer", ts: 3 }];+ useEventStore.setState({ voiceState: "speaking" });+ useHomeStore.setState({ liveSessionId: "voice-1", transcript, liveReply: "Still answering" });+ render(<JarvisHistoryRail />);+ fireEvent.click(await screen.findByTestId("jarvis-history-voice-row"));+ expect(useHomeStore.getState().transcript).toBe(transcript);+ expect(useHomeStore.getState().liveReply).toBe("Still answering");+ expect(useEventStore.getState().activeThreadId).toBe("voice-1");+ expect(useEventStore.getState().voiceState).toBe("speaking");+ expect(setJarvisCardMode).toHaveBeenCalledWith("voice");+ expect(vi.mocked(fetch).mock.calls.some(([url]) => String(url).includes("/hangup") || String(url).endsWith("/resume"))).toBe(false);+ expect(vi.mocked(fetch).mock.calls.some(([url, init]) => String(url).endsWith("/voice-chat") && init?.method === "PUT")).toBe(false);+ });+test("a late archive response cannot restore the previous call after hangup", async () => {let finish!: (response: Response) => void;render(<JarvisHistoryRail />);@@ -159,6 +174,7 @@ describe("JarvisHistoryRail", () => {test("switching archives ends the active call before resuming and keeps the selected context", async () => {useEventStore.setState({ voiceState: "listening" });+ useHomeStore.setState({ liveSessionId: "other-call", continuedVoiceId: "other-archive" });render(<JarvisHistoryRail />);fireEvent.click(await screen.findByTestId("jarvis-history-voice-row"));await waitFor(() => expect(fetch).toHaveBeenCalledWith("/api/voice/hangup", { method: "POST", cache: "no-store" }));diff --git a/jarvis/ui/web/frontend/src/components/society/chat/JarvisHistoryRail.tsx b/jarvis/ui/web/frontend/src/components/society/chat/JarvisHistoryRail.tsxindex 09a2557d1f..cab40530e9 100644--- a/jarvis/ui/web/frontend/src/components/society/chat/JarvisHistoryRail.tsx+++ b/jarvis/ui/web/frontend/src/components/society/chat/JarvisHistoryRail.tsx@@ -31,7 +31,7 @@ export function JarvisHistoryRail() {const sessions = useAgentChatStore((s) => s.sessions);const activeSessionId = useAgentChatStore((s) => s.activeSessionId);const loadSessions = useAgentChatStore((s) => s.loadSessions);- const { conversations, openConversation, refresh } = useConversations({ poll: true });+ const { conversations, openConversation, reopenLiveConversation, refresh } = useConversations({ poll: true });const setActiveConversation = useEventStore((s) => s.setActiveConversation);const setMessages = useEventStore((s) => s.setMessages);const voiceThreadId = useEventStore((s) => (s.activeKind === "voice" ? s.activeThreadId : null));@@ -49,10 +49,15 @@ export function JarvisHistoryRail() {};const openVoice = async (voiceId: string) => {+ if (reopenLiveConversation(voiceId)) {+ setJarvisCardMode("voice");+ return;+ }useAgentChatStore.getState().newChat();useHomeStore.getState().seedTranscript([]);setJarvisCardMode("voice");const messages = await openConversation("voice", voiceId);+ if (messages === null) return;const active = useEventStore.getState();if (active.activeKind !== "voice" || active.activeThreadId !== voiceId) return;useHomeStore.getState().seedTranscript(transcriptFromMessages(messages));diff --git a/jarvis/ui/web/frontend/src/hooks/useConversations.ts b/jarvis/ui/web/frontend/src/hooks/useConversations.tsindex 8c0a177c54..e67083679c 100644--- a/jarvis/ui/web/frontend/src/hooks/useConversations.ts+++ b/jarvis/ui/web/frontend/src/hooks/useConversations.ts@@ -78,14 +78,32 @@ export function useConversations({ poll = false }: { poll?: boolean } = {}) {}, [poll, voiceEvent]);useHistoryPolling(refresh, poll);+ /** Return to the running call without resuming an archive over its live state. */+ const reopenLiveConversation = useCallback((id: string): boolean => {+ const home = useHomeStore.getState();+ const voiceState = useEventStore.getState().voiceState;+ if (+ !home.liveSessionId+ || !["listening", "thinking", "speaking", "paused", "connecting"].includes(voiceState)+ || (id !== home.liveSessionId && id !== home.continuedVoiceId)+ ) return false;+ // Check before callers replace continuedVoiceId with the selected row.+ // A previous archive read must not overwrite the call after this click.+ ++selectionGeneration;+ setActiveConversation("voice", id);+ useHomeStore.setState({ voiceSelectionPending: false, freshVoicePending: false });+ return true;+ }, [setActiveConversation]);+/*** Make a conversation the active one and resume it on the backend (the* brain is seeded with it, so the next typed OR spoken turn continues it).* Resolves to the stored messages — empty when the backend had none or- * could not be reached — so a caller can show them elsewhere too.+ * could not be reached — so a caller can show them elsewhere too. A superseded+ * selection returns null so callers leave the newer transcript alone.*/const openConversation = useCallback(- async (kind: ConversationKind, id: string): Promise<ChatMessage[]> => {+ async (kind: ConversationKind, id: string): Promise<ChatMessage[] | null> => {const generation = ++selectionGeneration;useHomeStore.setState({ voiceSelectionPending: kind === "voice", freshVoicePending: false });setActiveConversation(kind, id);@@ -102,7 +120,7 @@ export function useConversations({ poll = false }: { poll?: boolean } = {}) {}}const selected = useEventStore.getState();- if (generation !== selectionGeneration || selected.activeKind !== kind || selected.activeThreadId !== id) return [];+ if (generation !== selectionGeneration || selected.activeKind !== kind || selected.activeThreadId !== id) return null;const detail = await resumeConversation(kind, id);messages = detailToMessages(detail);traces = detailToTraces(detail);@@ -116,7 +134,7 @@ export function useConversations({ poll = false }: { poll?: boolean } = {}) {// The stored traces replace the previous conversation's, so a reply// in the new thread never wears the steps of an old one.const active = useEventStore.getState();- if (generation !== selectionGeneration || active.activeKind !== kind || active.activeThreadId !== id) return [];+ if (generation !== selectionGeneration || active.activeKind !== kind || active.activeThreadId !== id) return null;seedThinkingTraces(traces);setMessages(messages);return messages;@@ -165,6 +183,7 @@ export function useConversations({ poll = false }: { poll?: boolean } = {}) {activeThreadId,activeKind,refresh,+ reopenLiveConversation,openConversation,newChat,newVoiceRun,