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(ui): assistant-name seed survives the autostart race (stuck 'Assistant' brand)
Ruben Lütke26bf4002a6f4
diff --git a/jarvis/ui/web/frontend/src/hooks/useAssistantNameSeed.test.tsx b/jarvis/ui/web/frontend/src/hooks/useAssistantNameSeed.test.tsxindex e594de635d..3aed4990fc 100644--- a/jarvis/ui/web/frontend/src/hooks/useAssistantNameSeed.test.tsx+++ b/jarvis/ui/web/frontend/src/hooks/useAssistantNameSeed.test.tsx@@ -80,6 +80,87 @@ describe("useAssistantNameSeed mount seed", () => {expect(useEventStore.getState().assistantName).toBe("Assistant");});+ it("retries after a failed boot fetch and seeds once the backend is up", async () => {+ // The autostart race: the app mounts while the backend is still binding,+ // the first fetch throws, a later retry succeeds. The neutral fallback+ // must not stick until a manual reload.+ vi.useFakeTimers();+ try {+ let calls = 0;+ vi.stubGlobal(+ "fetch",+ vi.fn(async () => {+ calls += 1;+ if (calls === 1) throw new Error("backend not up yet");+ return {+ ok: true,+ json: async () => ({ resolved: "Nova", default: "Assistant" }),+ };+ }) as unknown as typeof fetch,+ );++ render(<Harness />);+ // Let the first (failing) fetch settle and schedule its retry.+ await vi.advanceTimersByTimeAsync(0);+ expect(useEventStore.getState().assistantName).toBe("Assistant");++ // First backoff step is 1s — advancing past it fires the retry.+ await vi.advanceTimersByTimeAsync(1_100);+ expect(useEventStore.getState().assistantName).toBe("Nova");+ } finally {+ vi.useRealTimers();+ }+ });++ it("retries after a non-OK warmup response (503) instead of giving up", async () => {+ vi.useFakeTimers();+ try {+ let calls = 0;+ vi.stubGlobal(+ "fetch",+ vi.fn(async () => {+ calls += 1;+ if (calls === 1) return { ok: false, status: 503 };+ return {+ ok: true,+ json: async () => ({ resolved: "Nova", default: "Assistant" }),+ };+ }) as unknown as typeof fetch,+ );++ render(<Harness />);+ await vi.advanceTimersByTimeAsync(0);+ expect(useEventStore.getState().assistantName).toBe("Assistant");++ await vi.advanceTimersByTimeAsync(1_100);+ expect(useEventStore.getState().assistantName).toBe("Nova");+ } finally {+ vi.useRealTimers();+ }+ });++ it("never caches the neutral fallback name in localStorage", async () => {+ // A resolved "Assistant" (no wake word configured, or a warmup artifact)+ // must not be persisted: an empty cache already yields the fallback, and+ // persisting it would poison later boots that DO have a real name.+ vi.stubGlobal(+ "fetch",+ vi.fn(async () => ({+ ok: true,+ json: async () => ({ resolved: "Assistant", default: "Assistant" }),+ })) as unknown as typeof fetch,+ );++ render(<Harness />);+ await waitFor(() =>+ expect((fetch as unknown as ReturnType<typeof vi.fn>).mock.calls.length).toBeGreaterThan(0),+ );+ await Promise.resolve();+ await Promise.resolve();++ expect(localStorage.getItem("jarvis.assistantName")).toBeNull();+ });+it("ignores an empty resolved value (does not blank the wordmark)", async () => {vi.stubGlobal("fetch",diff --git a/jarvis/ui/web/frontend/src/hooks/useAssistantNameSeed.ts b/jarvis/ui/web/frontend/src/hooks/useAssistantNameSeed.tsindex 655304fd10..5c7530949e 100644--- a/jarvis/ui/web/frontend/src/hooks/useAssistantNameSeed.ts+++ b/jarvis/ui/web/frontend/src/hooks/useAssistantNameSeed.ts@@ -1,6 +1,19 @@import { useEffect } from "react";import { useEventStore } from "@/store/events";-import { writeCachedAssistantName } from "@/lib/assistantNameCache";+import {+ NEUTRAL_ASSISTANT_NAME,+ writeCachedAssistantName,+} from "@/lib/assistantNameCache";++/**+ * Retry schedule for the boot window. The seed fetch races backend startup+ * under autostart (the AuthGate deliberately lets the app mount even when the+ * backend is still unreachable), so a single fetch can fail and the neutral+ * "Assistant" fallback would stick on every surface until a full page reload.+ * Backoff caps at 15s and keeps going until the first success — the request+ * is a tiny local GET, so a quiet steady retry is cheaper than a stuck brand.+ */+const RETRY_DELAYS_MS = [1_000, 2_000, 4_000, 8_000, 15_000];/*** Seed the resolved assistant name into the global store on mount.@@ -8,47 +21,79 @@ import { writeCachedAssistantName } from "@/lib/assistantNameCache";* The assistant's display name (header wordmark + every assistant byline) is* derived solely from the wake phrase configured in `[trigger.wake_word].phrase`* (via `deriveAssistantName` on the backend). This hook reads the current value- * once on mount via GET /api/settings/assistant-name (mirroring useVoiceStatus /+ * on mount via GET /api/settings/assistant-name (mirroring useVoiceStatus /* useBrainStatus) and writes `resolved` into the store.*- * `useWakeWord.saveWakeWord` dispatches `jarvis:assistant-name-changed` after a- * successful wake-word save, so we re-fetch on that event to keep every byline- * live without a reload. A fetch failure (offline / headless host) is a no-op:- * the store keeps its default and the next event/mount re-seeds it.+ * Robustness — the fetch retries with capped backoff until it succeeds once:+ * under autostart the backend may still be binding/warming when the app mounts+ * (it can even answer 503 while `app.state.config` is unset), and a one-shot+ * fetch left the neutral fallback stuck until a reload (the "assistant+ * everywhere after PC reboot" bug). `useWakeWord.saveWakeWord` dispatches+ * `jarvis:assistant-name-changed` after a successful wake-word save, and+ * `useWebSocket` dispatches it on every WS welcome, so we re-fetch on that+ * event to keep every byline live without a reload.*/export function useAssistantNameSeed(): void {const setAssistantName = useEventStore((s) => s.setAssistantName);useEffect(() => {let cancelled = false;+ let attempt = 0;+ let retryTimer: number | undefined;const ctrl = new AbortController();+ const scheduleRetry = () => {+ if (cancelled) return;+ const delay =+ RETRY_DELAYS_MS[Math.min(attempt, RETRY_DELAYS_MS.length - 1)];+ attempt += 1;+ window.clearTimeout(retryTimer);+ retryTimer = window.setTimeout(seed, delay);+ };+const seed = () => {void fetch("/api/settings/assistant-name", { signal: ctrl.signal }).then((r) => (r.ok ? r.json() : null)).then((data) => {- if (cancelled || !data) return;+ if (cancelled) return;+ if (!data) {+ // Non-OK response (503 while the backend warms, auth hiccup) —+ // try again shortly instead of freezing the neutral fallback.+ scheduleRetry();+ return;+ }const resolved =typeof data.resolved === "string" ? data.resolved.trim() : "";if (resolved) {+ attempt = 0;setAssistantName(resolved);// Mirror into localStorage so the next boot can paint this name// instantly (store seed + index.html splash) with no fetch wait.- writeCachedAssistantName(resolved);+ // The neutral fallback is never cached: an empty cache already+ // yields it, and persisting it would poison the next boots with+ // "Assistant" if this response was a warmup artifact.+ if (resolved !== NEUTRAL_ASSISTANT_NAME) {+ writeCachedAssistantName(resolved);+ }}}).catch(() => {- // Network/timeout/headless — keep the store value; a later rename- // event (or remount) re-seeds it.+ // Network/timeout — backend not up yet (autostart race) or headless.+ // Keep the store value and retry; a later rename event also re-seeds.+ if (!ctrl.signal.aborted) scheduleRetry();});};seed();- const onChanged = () => seed();+ const onChanged = () => {+ attempt = 0;+ seed();+ };window.addEventListener("jarvis:assistant-name-changed", onChanged);return () => {cancelled = true;+ window.clearTimeout(retryTimer);ctrl.abort();window.removeEventListener("jarvis:assistant-name-changed", onChanged);};diff --git a/jarvis/ui/web/frontend/src/hooks/useWebSocket.ts b/jarvis/ui/web/frontend/src/hooks/useWebSocket.tsindex c1b5a13a85..fec80785df 100644--- a/jarvis/ui/web/frontend/src/hooks/useWebSocket.ts+++ b/jarvis/ui/web/frontend/src/hooks/useWebSocket.ts@@ -84,6 +84,13 @@ export function useWebSocket(): void {// Offline / headless: keep the current value; the live// VoiceBootStatus event still updates it if/when it arrives.});+ // Re-seed the assistant name on EVERY (re)connect for the same+ // reason: under autostart the mount-seed fetch can race a backend+ // that is not serving yet, leaving the neutral "Assistant" brand+ // stuck on every surface until a reload. The welcome frame is the+ // authoritative "backend is up" signal — useAssistantNameSeed+ // listens for this event and re-fetches the resolved name.+ window.dispatchEvent(new CustomEvent("jarvis:assistant-name-changed"));return;}diff --git a/jarvis/ui/web/settings_routes.py b/jarvis/ui/web/settings_routes.pyindex 8e8e2b3b1b..750a3e11ae 100644--- a/jarvis/ui/web/settings_routes.py+++ b/jarvis/ui/web/settings_routes.py@@ -1262,6 +1262,14 @@ async def get_assistant_name(request: Request) -> dict[str, object]:from jarvis.brain.assistant_name import DEFAULT_ASSISTANT_NAME, resolve_assistant_namecfg = _config(request)+ if cfg is None:+ # No config on app.state means the server is still warming up (or a+ # degraded boot). Answering the neutral fallback here would be a lie+ # the frontend persists into its localStorage name cache — every+ # surface would then show "Assistant" until a successful re-fetch.+ # 503 tells the seed hook to retry instead (mirrors the sessions/runs+ # routes' warmup behavior).+ raise HTTPException(status_code=503, detail="Configuration not loaded yet")return {"resolved": resolve_assistant_name(cfg),"default": DEFAULT_ASSISTANT_NAME,diff --git a/tests/unit/ui/web/test_assistant_name_route.py b/tests/unit/ui/web/test_assistant_name_route.pynew file mode 100644index 0000000000..3764ac8749--- /dev/null+++ b/tests/unit/ui/web/test_assistant_name_route.py@@ -0,0 +1,36 @@+"""GET /api/settings/assistant-name must never invent a name while warming up.++Under autostart the frontend can reach this route before ``app.state.config``+is populated. Resolving the name from a missing config would answer the+neutral "Assistant" fallback, which the frontend persists into its+localStorage name cache — freezing the wrong brand on every surface until a+successful re-fetch. The route answers 503 instead, so the seed hook retries.+"""+from __future__ import annotations++from types import SimpleNamespace++import pytest+from fastapi import HTTPException++from jarvis.ui.web.settings_routes import get_assistant_name+++def _request_with_config(cfg: object) -> SimpleNamespace:+ return SimpleNamespace(app=SimpleNamespace(state=SimpleNamespace(config=cfg, cfg=None)))+++async def test_warmup_without_config_answers_503_not_a_fake_name() -> None:+ with pytest.raises(HTTPException) as excinfo:+ await get_assistant_name(_request_with_config(None)) # type: ignore[arg-type]+ assert excinfo.value.status_code == 503+++async def test_resolves_name_from_wake_phrase_when_config_present() -> None:+ # Arbitrary pinned brand (never the host's live wake-word config).+ cfg = SimpleNamespace(+ trigger=SimpleNamespace(wake_word=SimpleNamespace(phrase="Hey Nova"))+ )+ payload = await get_assistant_name(_request_with_config(cfg)) # type: ignore[arg-type]+ assert payload["resolved"] == "Nova"+ assert payload["default"] == "Assistant"