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): keep asking for the profile name while the backend boots (#1118)
Ruben Lütkecebdb804bdef
diff --git a/dodaios/ui/web/frontend/src/hooks/useUserName.test.tsx b/dodaios/ui/web/frontend/src/hooks/useUserName.test.tsxnew file mode 100644index 0000000000..cf85327f2f--- /dev/null+++ b/dodaios/ui/web/frontend/src/hooks/useUserName.test.tsx@@ -0,0 +1,39 @@+import { afterEach, describe, expect, it, vi } from "vitest";+import { renderHook, waitFor } from "@testing-library/react";+import { QueryClient, QueryClientProvider } from "@tanstack/react-query";+import type { ReactNode } from "react";+import { useUserName } from "./useUserName";++function wrapper({ children }: { children: ReactNode }) {+ const client = new QueryClient();+ return <QueryClientProvider client={client}>{children}</QueryClientProvider>;+}++describe("useUserName", () => {+ afterEach(() => vi.unstubAllGlobals());++ it("asks again when the backend is still booting, so the name still arrives", async () => {+ const fetchMock = vi+ .fn()+ .mockResolvedValueOnce(new Response("", { status: 503 }))+ .mockResolvedValue(new Response(JSON.stringify({ user: { name: "Ruben" } }), { status: 200 }));+ vi.stubGlobal("fetch", fetchMock);++ const { result } = renderHook(() => useUserName(), { wrapper });++ await waitFor(() => expect(result.current).toBe("Ruben"), { timeout: 4_000 });+ expect(fetchMock).toHaveBeenCalledTimes(2);+ });++ it("does not keep asking a host that has no profile route", async () => {+ const fetchMock = vi.fn().mockResolvedValue(new Response("", { status: 404 }));+ vi.stubGlobal("fetch", fetchMock);++ const { result } = renderHook(() => useUserName(), { wrapper });++ await waitFor(() => expect(fetchMock).toHaveBeenCalledTimes(1));+ await new Promise((r) => setTimeout(r, 1_500));+ expect(fetchMock).toHaveBeenCalledTimes(1);+ expect(result.current).toBeNull();+ });+});diff --git a/dodaios/ui/web/frontend/src/hooks/useUserName.ts b/dodaios/ui/web/frontend/src/hooks/useUserName.tsindex 1de39e4cbb..4c5ddcb53b 100644--- a/dodaios/ui/web/frontend/src/hooks/useUserName.ts+++ b/dodaios/ui/web/frontend/src/hooks/useUserName.ts@@ -16,11 +16,17 @@ export function useUserName(): string | null {queryKey: ["profile"],queryFn: async (): Promise<ProfileUser> => {const res = await fetch("/api/profile");- if (!res.ok) throw new Error(`HTTP ${res.status}`);+ if (!res.ok) throw Object.assign(new Error(`HTTP ${res.status}`), { status: res.status });return (await res.json()) as ProfileUser;},staleTime: 60_000,- retry: false,+ // The window often loads before the backend has finished booting. With no+ // retry that first failed fetch stuck, and the sidebar footer said+ // "Profile" instead of the person's name until the next restart. Keep+ // asking for about a minute; a host without the route (404) stays quiet.+ retry: (failures, error) =>+ failures < 6 && (error as { status?: number }).status !== 404,+ retryDelay: (attempt) => Math.min(1_000 * 2 ** attempt, 15_000),});// The name set in the Profile, else the one the memory has learned// (`display_name`, from the user's wiki entity page — profile_routes.py).