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(onboarding): retry state fetch during backend warmup instead of failing open
Ruben Lütke67f1b5cefb23
diff --git a/jarvis/ui/web/frontend/src/hooks/useOnboarding.test.ts b/jarvis/ui/web/frontend/src/hooks/useOnboarding.test.tsindex 12bdbe8ef3..5cdc119070 100644--- a/jarvis/ui/web/frontend/src/hooks/useOnboarding.test.ts+++ b/jarvis/ui/web/frontend/src/hooks/useOnboarding.test.ts@@ -35,6 +35,32 @@ it("loads state and posts a step", async () => {expect(JSON.parse(put![1]!.body as string).step).toBe("terms");});+it("retries a warming 503 until the backend answers, then resolves state", async () => {+ const fetchMock = vi+ .fn()+ .mockResolvedValueOnce({ ok: false, status: 503, json: () => Promise.resolve({}) })+ .mockResolvedValueOnce({ ok: false, status: 503, json: () => Promise.resolve({}) })+ .mockResolvedValue({ ok: true, json: () => Promise.resolve(STATE) });+ vi.stubGlobal("fetch", fetchMock);++ const { result } = renderHook(() => useOnboarding());+ await waitFor(() => expect(result.current.state?.completed).toBe(false), {+ timeout: 15000,+ });+ expect(result.current.error).toBeNull();+ expect(fetchMock.mock.calls.length).toBeGreaterThanOrEqual(3);+}, 20000);++it("gives up after the bounded retry window (fail-open preserved)", async () => {+ vi.stubGlobal(+ "fetch",+ vi.fn().mockRejectedValue(new Error("net down")),+ );+ const { result } = renderHook(() => useOnboarding({ retryDelaysMs: [10, 20] }));+ await waitFor(() => expect(result.current.error).not.toBeNull(), { timeout: 5000 });+ expect(result.current.loading).toBe(false);+});+it("complete() surfaces a failed completion (throws, no event)", async () => {vi.stubGlobal("fetch",diff --git a/jarvis/ui/web/frontend/src/hooks/useOnboarding.ts b/jarvis/ui/web/frontend/src/hooks/useOnboarding.tsindex fcd0b30318..510127110a 100644--- a/jarvis/ui/web/frontend/src/hooks/useOnboarding.ts+++ b/jarvis/ui/web/frontend/src/hooks/useOnboarding.ts@@ -24,29 +24,47 @@ async function post(url: string, body?: unknown): Promise<void> {if (!res.ok) throw new Error(`HTTP ${res.status}`);}+// Bounded warmup retry: on a fresh machine the serve-first backend answers+// /api/onboarding/state from the fast-boot path immediately, but a slow disk+// or a dev server without it can still 503/refuse briefly. Retrying keeps the+// first-run gate from failing open (= never showing) on the one boot where it+// matters most. ~30 s total, then fail-open as before (never trap the user).+const RETRY_DELAYS_MS = [500, 1000, 1500, 2000, 3000, 3000, 4000, 5000, 5000, 5000];+/*** Loads /api/onboarding/state and exposes the onboarding mutation actions.* `saveStep` is best-effort (progress persistence — never blocks navigation);* `acceptTerms`/`acknowledgeWakeWord`/`complete` propagate failures so the* calling step can surface an error. `complete` dispatches* `jarvis:onboarding-changed` only after a successful POST.+ * `opts.retryDelaysMs` is a test seam for the warmup retry schedule.*/-export function useOnboarding() {+export function useOnboarding(opts?: { retryDelaysMs?: number[] }) {const [state, setState] = useState<OnboardingState | null>(null);const [loading, setLoading] = useState(true);const [error, setError] = useState<string | null>(null);+ const retryDelays = opts?.retryDelaysMs ?? RETRY_DELAYS_MS;const refetch = useCallback(async () => {setError(null);- try {- const res = await fetch("/api/onboarding/state");- if (!res.ok) throw new Error(`HTTP ${res.status}`);- setState((await res.json()) as OnboardingState);- } catch (e) {- setError((e as Error).message);- } finally {- setLoading(false);+ for (let attempt = 0; ; attempt++) {+ try {+ const res = await fetch("/api/onboarding/state");+ if (!res.ok) throw new Error(`HTTP ${res.status}`);+ setState((await res.json()) as OnboardingState);+ setLoading(false);+ return;+ } catch (e) {+ const delay = retryDelays[attempt];+ if (delay === undefined) {+ setError((e as Error).message);+ setLoading(false);+ return;+ }+ await new Promise((r) => setTimeout(r, delay));+ }}+ // eslint-disable-next-line react-hooks/exhaustive-deps -- retryDelays is a stable test seam}, []);useEffect(() => {