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(realtime): avoid idle subscription loading state
rubenluetke10-beep0c7dd587b9e4
diff --git a/jarvis/ui/web/frontend/src/hooks/useVoiceMode.test.tsx b/jarvis/ui/web/frontend/src/hooks/useVoiceMode.test.tsxindex 7fcd9fc7d2..642745534d 100644--- a/jarvis/ui/web/frontend/src/hooks/useVoiceMode.test.tsx+++ b/jarvis/ui/web/frontend/src/hooks/useVoiceMode.test.tsx@@ -1,11 +1,14 @@-import { cleanup, renderHook, waitFor } from "@testing-library/react";+import { act, cleanup, renderHook, waitFor } from "@testing-library/react";import { QueryClient, QueryClientProvider } from "@tanstack/react-query";import type { ReactNode } from "react";import { afterEach, describe, expect, it, vi } from "vitest";import { useVoiceMode } from "./useVoiceMode";-function response(available: boolean): Response {+function response(+ available: boolean,+ overrides: Record<string, unknown> = {},+): Response {return {ok: true,json: async () => ({@@ -23,6 +26,7 @@ function response(available: boolean): Response {active_session_provider: "",active_session_model: "",transitioning: false,+ ...overrides,}),} as Response;}@@ -61,4 +65,59 @@ describe("useVoiceMode realtime discovery", () => {"ChatGPT-Live (model chosen by OpenAI)",);});++ it("does not show a handshake when an idle realtime provider changes", async () => {+ const fetchMock = vi+ .fn()+ .mockResolvedValue(response(true, { handshake_budget_s: 135 }));+ vi.stubGlobal("fetch", fetchMock);+ const client = new QueryClient({+ defaultOptions: { queries: { retry: false } },+ });+ const wrapper = ({ children }: { children: ReactNode }) => (+ <QueryClientProvider client={client}>{children}</QueryClientProvider>+ );++ const { result } = renderHook(() => useVoiceMode(), { wrapper });+ await waitFor(() => expect(result.current.statusKnown).toBe(true));++ act(() => {+ window.dispatchEvent(new CustomEvent("jarvis:realtime-switched"));+ });++ await waitFor(() => expect(fetchMock).toHaveBeenCalledTimes(2));+ expect(result.current.connecting).toBe(false);+ });++ it("does not show a handshake when realtime is selected while idle", async () => {+ let getCount = 0;+ const fetchMock = vi.fn().mockImplementation((_url, init?: RequestInit) => {+ if (init?.method === "PUT") {+ return Promise.resolve(response(true, { mode: "realtime" }));+ }+ getCount += 1;+ return Promise.resolve(+ response(true, {+ mode: getCount === 1 ? "pipeline" : "realtime",+ handshake_budget_s: 135,+ }),+ );+ });+ vi.stubGlobal("fetch", fetchMock);+ const client = new QueryClient({+ defaultOptions: { queries: { retry: false } },+ });+ const wrapper = ({ children }: { children: ReactNode }) => (+ <QueryClientProvider client={client}>{children}</QueryClientProvider>+ );++ const { result } = renderHook(() => useVoiceMode(), { wrapper });+ await waitFor(() => expect(result.current.mode).toBe("pipeline"));++ act(() => result.current.setMode("realtime"));++ await waitFor(() => expect(result.current.mode).toBe("realtime"));+ await waitFor(() => expect(result.current.isSaving).toBe(false));+ expect(result.current.connecting).toBe(false);+ });});diff --git a/jarvis/ui/web/frontend/src/hooks/useVoiceMode.ts b/jarvis/ui/web/frontend/src/hooks/useVoiceMode.tsindex 551470720a..c5fd8b7ffa 100644--- a/jarvis/ui/web/frontend/src/hooks/useVoiceMode.ts+++ b/jarvis/ui/web/frontend/src/hooks/useVoiceMode.ts@@ -191,12 +191,18 @@ export function useVoiceMode() {await qc.cancelQueries({ queryKey: ["voice-mode"] });const prev = qc.getQueryData<VoiceModeResp>(["voice-mode"]);if (prev) qc.setQueryData<VoiceModeResp>(["voice-mode"], { ...prev, mode });- // Selecting realtime restarts an open call through the full provider- // handshake — arm the connecting poll so the status rows follow it, and- // ask the offer broker to publish BEFORE the reconnect lands.+ // Selecting realtime restarts an OPEN call through the full provider+ // handshake. When idle, this only changes the engine preference: arming+ // the provider budget there would fabricate a 20-140 s "connecting"+ // state for a call that does not exist.if (mode === "realtime") {requestRealtimeTransportOffer();- markRealtimeStartPending();+ const callIsOpen =+ prev?.session_active === true ||+ prev?.transitioning === true ||+ voiceState !== "idle";+ if (callIsOpen) markRealtimeStartPending();+ else setStartPendingUntil(0);}return { prev };},@@ -210,18 +216,31 @@ export function useVoiceMode() {// A realtime provider card changes the provider, never `[voice].mode`.// Refresh because this response also carries the selected provider/model// shown in the runtime status; the engine mode itself remains user-controlled.- // A switch also reconnects an open call, so the connecting poll is armed too.+ // A switch also reconnects an OPEN call, so the connecting poll is armed only+ // when runtime state proves there is one. The event is also emitted for idle+ // provider selection and subscription login/logout; those actions refresh+ // availability but must never impersonate a voice-session handshake.// The same event is dispatched when a subscription login connects or// disconnects, which is what makes `realtime_available` flip without waiting// out the discovery backoff.useEffect(() => {function onRealtimeSwitched() {- markRealtimeStartPending();+ const cached = qc.getQueryData<VoiceModeResp>(["voice-mode"]);+ const callIsOpen =+ cached?.session_active === true ||+ cached?.transitioning === true ||+ voiceState !== "idle";+ if (callIsOpen) {+ markRealtimeStartPending();+ return;+ }+ setStartPendingUntil(0);+ void qc.invalidateQueries({ queryKey: ["voice-mode"] });}window.addEventListener("jarvis:realtime-switched", onRealtimeSwitched);return () =>window.removeEventListener("jarvis:realtime-switched", onRealtimeSwitched);- }, [markRealtimeStartPending]);+ }, [markRealtimeStartPending, qc, voiceState]);useEffect(() => {function onTransportIssue(event: Event) {