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(boot): stop the cold-boot self-amplifiers in the start sequence
rubenluetke10-beep42891d4d1a21
diff --git a/jarvis/plugins/stt/fwhisper.py b/jarvis/plugins/stt/fwhisper.pyindex 95e6adc4e9..6f302ad1f4 100644--- a/jarvis/plugins/stt/fwhisper.py+++ b/jarvis/plugins/stt/fwhisper.py@@ -477,6 +477,22 @@ def _new_whisper_model(if cpu_threads and cpu_threads > 0:kwargs["cpu_threads"] = int(cpu_threads)kwargs["num_workers"] = 1+ # Cache-first: without local_files_only, faster_whisper asks huggingface.co+ # for the model revision on EVERY build — a network round-trip on the boot+ # path (observed in the 2026-09-01 cold-boot log), and a hang/timeout when+ # the machine boots faster than its network comes up. Only a genuine cache+ # miss goes online.+ try:+ return WhisperModel(model_name, local_files_only=True, **kwargs)+ except OSError as exc:+ # huggingface_hub raises LocalEntryNotFoundError (a FileNotFoundError)+ # on a cache miss; engine/CUDA build failures are RuntimeError and+ # propagate unchanged so they are never retried as a download.+ log.info(+ "Whisper model %s not in the local cache (%s) — fetching online.",+ model_name,+ exc.__class__.__name__,+ )return WhisperModel(model_name, **kwargs)diff --git a/jarvis/ui/desktop_app.py b/jarvis/ui/desktop_app.pyindex ada371632d..4f2210c873 100644--- a/jarvis/ui/desktop_app.py+++ b/jarvis/ui/desktop_app.py@@ -4778,7 +4778,7 @@ class DesktopApp:return f"{WINDOW_TITLE} cannot start: {type(exc).__name__}: {exc}\n\nPython: {python}"return f"{WINDOW_TITLE} cannot start: the backend did not become ready.\n\nPython: {python}"- def _wait_for_backend(self, timeout_s: float = 45.0) -> bool:+ def _wait_for_backend(self, timeout_s: float = 45.0, hard_timeout_s: float = 180.0) -> bool:"""Polls ``/api/health`` until it returns 200 or the timeout expires.45s default — Whisper/VAD models are loaded on first initialization@@ -4787,17 +4787,37 @@ class DesktopApp:If the backend thread has already died (missing import, bind error),return immediately — waiting out the timeout just hides the reasonunder pythonw for 45 seconds.++ A LIVE backend thread that merely has not bound yet is a different+ case: on a cold boot the whole tree competes with every other+ autostart for a paging disk, and quitting with a failure dialog at+ 45 s turned a slow boot into a dead one. As long as the thread is+ alive the wait continues past ``timeout_s`` (with one log line) up to+ ``hard_timeout_s``; only a dead thread or the hard cap gives up."""import httpxurl = f"http://127.0.0.1:{self.cfg.ui.admin_api_port}/api/health"start = time.monotonic()+ slow_boot_logged = False# 100 ms startup buffer so the thread can set up the loop.time.sleep(0.05)- while time.monotonic() - start < timeout_s:+ while time.monotonic() - start < hard_timeout_s:thread = self._backend_threadif thread is not None and not thread.is_alive():return False+ elapsed = time.monotonic() - start+ if elapsed >= timeout_s and not slow_boot_logged:+ slow_boot_logged = True+ from loguru import logger++ logger.warning(+ "Backend still binding after {:.0f} s — the thread is alive, "+ "so this looks like a starved cold boot; waiting up to "+ "{:.0f} s instead of failing.",+ elapsed,+ hard_timeout_s,+ )try:r = httpx.get(url, timeout=0.5)if r.status_code == 200:@@ -4858,10 +4878,27 @@ class DesktopApp:r = client.get(f"http://127.0.0.1:{self.cfg.ui.admin_api_port}/api/health",)+ warming = False+ if r.status_code == 200:+ try:+ warming = bool(r.json().get("warming"))+ except Exception: # noqa: BLE001 — a non-JSON health body means the real app+ warming = False+ self._backend_warming_flag = warmingreturn bool(r.status_code == 200)except Exception: # noqa: BLE001 — an unreachable server is the answer+ self._backend_warming_flag = Falsereturn False+ def _backend_warming(self) -> bool:+ """Was the last health answer the bootstrap's ``warming: true``?++ Piggybacks on ``_backend_healthy``'s response instead of probing again —+ the blank-window watchdog calls both within one tick, and a second HTTP+ request per tick would double the probe cost for the same byte.+ """+ return bool(getattr(self, "_backend_warming_flag", False))+def _backend_thread_alive(self) -> bool:"""Is the thread that serves this window still running?@@ -4890,6 +4927,7 @@ class DesktopApp:url=self._url(),health_probe=self._backend_healthy,backend_alive=self._backend_thread_alive,+ warming_probe=self._backend_warming,failure_detail=self._blank_window_detail,theme=self._resolved_theme,)diff --git a/jarvis/ui/web/frontend/src/components/AuthGate.tsx b/jarvis/ui/web/frontend/src/components/AuthGate.tsxindex d36c81b8ec..55b9d490cc 100644--- a/jarvis/ui/web/frontend/src/components/AuthGate.tsx+++ b/jarvis/ui/web/frontend/src/components/AuthGate.tsx@@ -90,20 +90,34 @@ export function AuthGate({ children }: AuthGateProps) {started.current = true;void (async () => {- let response: Response;- try {- response = await fetch("/api/config", {- cache: "no-store",- credentials: "same-origin",- });- } catch {- // Authentication is required only when the backend explicitly returns- // 401. Let the existing application surfaces handle warmup/offline- // failures instead of trapping the user behind an unrelated gate.- setState("authorized");- return;+ // During a cold boot the serve-first bootstrap holds this request for up+ // to 120 s. One untimed fetch pinned a connection for that whole window;+ // short timed attempts hold at most one connection at a time and pick up+ // the real answer within seconds of the app becoming ready.+ const ATTEMPT_TIMEOUT_MS = 10_000;+ const MAX_ATTEMPTS = 15;+ let response: Response | null = null;+ for (let attempt = 0; attempt < MAX_ATTEMPTS; attempt++) {+ try {+ response = await fetch("/api/config", {+ cache: "no-store",+ credentials: "same-origin",+ signal: AbortSignal.timeout(ATTEMPT_TIMEOUT_MS),+ });+ break;+ } catch (exc) {+ if (exc instanceof DOMException && exc.name === "TimeoutError") {+ continue; // still warming — ask again with a fresh connection+ }+ // Authentication is required only when the backend explicitly+ // returns 401. Let the existing application surfaces handle+ // warmup/offline failures instead of trapping the user behind an+ // unrelated gate.+ setState("authorized");+ return;+ }}- if (response.status !== 401) {+ if (response === null || response.status !== 401) {setState("authorized");return;}diff --git a/jarvis/ui/web/frontend/src/hooks/useCapabilities.ts b/jarvis/ui/web/frontend/src/hooks/useCapabilities.tsindex 5894befabd..9f45e7b9b8 100644--- a/jarvis/ui/web/frontend/src/hooks/useCapabilities.ts+++ b/jarvis/ui/web/frontend/src/hooks/useCapabilities.ts@@ -15,6 +15,8 @@*/import { useEffect, useState } from "react";+import { bootSettled } from "@/lib/bootStagger";+export interface Capabilities {native_file_actions: boolean;platform: "win32" | "darwin" | "linux";@@ -28,7 +30,9 @@ function loadCapabilities(): Promise<Capabilities> {if (_inflight) return _inflight;// Promise.resolve().then(...) so a missing/relative-URL fetch (e.g. in a unit// test with no server) becomes a rejected promise, never a synchronous throw.- _inflight = Promise.resolve()+ // Non-critical: awaits the boot stagger so the first-mount burst keeps+ // Chromium's small per-origin connection pool for the essential requests.+ _inflight = bootSettled().then(() => fetch("/api/downloads/capabilities")).then((r) => {if (!r.ok) throw new Error(`HTTP ${r.status}`);diff --git a/jarvis/ui/web/frontend/src/hooks/usePermissions.ts b/jarvis/ui/web/frontend/src/hooks/usePermissions.tsindex 83bc0333ac..6676849f6b 100644--- a/jarvis/ui/web/frontend/src/hooks/usePermissions.ts+++ b/jarvis/ui/web/frontend/src/hooks/usePermissions.ts@@ -1,5 +1,7 @@import { useCallback, useEffect, useMemo, useState } from "react";+import { bootSettled } from "@/lib/bootStagger";+export type PermissionId =| "microphone"| "screen_recording"@@ -146,7 +148,9 @@ export function usePermissions() {);useEffect(() => {- void refetch();+ // Non-critical: the banner can appear a few seconds late; the first-mount+ // burst must not spend a connection on it (see bootStagger).+ void bootSettled().then(refetch);}, [refetch]);useEffect(() => {diff --git a/jarvis/ui/web/frontend/src/hooks/usePluginAttention.ts b/jarvis/ui/web/frontend/src/hooks/usePluginAttention.tsindex e7fb8e13c9..3ab49fe293 100644--- a/jarvis/ui/web/frontend/src/hooks/usePluginAttention.ts+++ b/jarvis/ui/web/frontend/src/hooks/usePluginAttention.ts@@ -1,5 +1,7 @@import { useEffect, useState } from "react";+import { bootSettled } from "@/lib/bootStagger";+/** What the sidebar needs to surface a plugin problem: how many connected* plugins need attention and their display names (for a concrete tooltip). */export interface PluginAttention {@@ -48,7 +50,8 @@ export function usePluginAttention(): PluginAttention {}};- void check();+ // Non-critical: the first check waits out the boot burst (see bootStagger).+ void bootSettled().then(check);const id = setInterval(check, 60_000);return () => {alive = false;diff --git a/jarvis/ui/web/frontend/src/hooks/useUpdate.ts b/jarvis/ui/web/frontend/src/hooks/useUpdate.tsindex 472cd5f138..ef7013a2ff 100644--- a/jarvis/ui/web/frontend/src/hooks/useUpdate.ts+++ b/jarvis/ui/web/frontend/src/hooks/useUpdate.ts@@ -1,5 +1,7 @@import { useCallback, useEffect, useState } from "react";+import { bootSettled } from "@/lib/bootStagger";+/*** Result of GET /api/update/status. ``managed`` is false on any checkout that is* not an installer-managed install (a dev tree, a manual clone) — the update@@ -111,7 +113,8 @@ export function useUpdate() {}, []);useEffect(() => {- void refresh();+ // Non-critical: the first status check waits out the boot burst.+ void bootSettled().then(() => refresh());const id = window.setInterval(() => void refresh(), POLL_INTERVAL_MS);const onFocus = () => void refresh();window.addEventListener("focus", onFocus);diff --git a/jarvis/ui/web/frontend/src/lib/bootStagger.ts b/jarvis/ui/web/frontend/src/lib/bootStagger.tsnew file mode 100644index 0000000000..a28a80b733--- /dev/null+++ b/jarvis/ui/web/frontend/src/lib/bootStagger.ts@@ -0,0 +1,29 @@+/**+ * First-mount request staggering.+ *+ * Chromium allows ~6 concurrent HTTP/1.1 connections per origin. The shell+ * fires ~15 `/api/*` requests in its first frames, and during a cold boot the+ * serve-first bootstrap HOLDS each of them until the real app registers — so+ * the pool is exhausted, and even the 1 s health poll and lazy-chunk asset+ * fetches queue behind held requests. The window then reads as frozen while it+ * is only waiting (2026-09-01 cold-boot forensics).+ *+ * Non-critical lookups (update badge, marketplace attention, permissions+ * banner, download capabilities) await `bootSettled()` before their first+ * request: the essential burst (config, providers, chats, brain, voice) gets+ * the whole pool, and the long-tail lookups arrive once the app has painted+ * real data. The timer starts on first call — effectively at app mount.+ */++const BOOT_SETTLE_MS = 4_000;++let settled: Promise<void> | null = null;++export function bootSettled(): Promise<void> {+ if (!settled) {+ settled = new Promise((resolve) => {+ window.setTimeout(resolve, BOOT_SETTLE_MS);+ });+ }+ return settled;+}diff --git a/jarvis/ui/window_watchdog.py b/jarvis/ui/window_watchdog.pyindex e4f7b458ae..0d881f8335 100644--- a/jarvis/ui/window_watchdog.py+++ b/jarvis/ui/window_watchdog.py@@ -124,6 +124,11 @@ class Observation:backend_alive: boolserver_healthy: boolnow: float+ #: The serve-first bootstrap answers ``/api/health`` 200 with+ #: ``warming: true`` while the real app is still initializing. A blank+ #: window is the EXPECTED picture then — the page is deliberately not+ #: served yet — so it must not be judged, and above all not reloaded.+ server_warming: bool = False@dataclass(frozen=True, slots=True)@@ -188,6 +193,15 @@ class BlankWindowPolicy:if not obs.backend_alive:return self._explain_once(BlankReason.BACKEND_DEAD)+ # A warming backend is not a silent one: health answers, and the blank+ # window is expected until warm-up ends. Judging it now turned a slow+ # cold boot into a reload loop — each reload restarted a cold WebView+ # (BelowNormal + paging, 2026-08-30) and made the boot slower still. The+ # grace starts counting once warming ends.+ if obs.server_warming:+ self._deadline = max(self._deadline, obs.now + self._grace_s)+ return Verdict(Action.WAIT)+# An outage that just ended is a new event, not a repeat of the one the# budget was spent on — so it always buys one more attempt. Without# this, a window whose reloads were used up during a long freeze would@@ -223,7 +237,12 @@ class BlankWindowPolicy:# ---- internals ---------------------------------------------------------def _arm_after_reload(self, now: float) -> None:- self._deadline = now + self._settle_s+ # Escalating settle: 1x, 2x, 4x the base. A window that did not come+ # back after one reload is loading slowly, not broken — burning the+ # remaining budget at the same fixed cadence just piled cold WebView+ # starts onto the machine that was already too busy to paint.+ used = max(0, self._budget - self._reloads_left - 1)+ self._deadline = now + self._settle_s * (2**used)self._blank_since = nowself._explained = None@@ -494,6 +513,7 @@ class BlankWindowWatchdog:url: str,health_probe: Callable[[], bool],backend_alive: Callable[[], bool],+ warming_probe: Callable[[], bool] | None = None,failure_detail: Callable[[], str] | None = None,theme: Callable[[], str] | None = None,policy: BlankWindowPolicy | None = None,@@ -505,6 +525,7 @@ class BlankWindowWatchdog:self._url = urlself._health_probe = health_probeself._backend_alive = backend_alive+ self._warming_probe = warming_probe or (lambda: False)self._failure_detail = failure_detail or (lambda: "")self._theme = theme or (lambda: "dark")self._policy = policy or BlankWindowPolicy()@@ -563,6 +584,7 @@ class BlankWindowWatchdog:backend_alive=self._safe(self._backend_alive, default=True),server_healthy=self._safe(self._health_probe, default=False),now=time.monotonic(),+ server_warming=self._safe(self._warming_probe, default=False),))self._apply(window, verdict)diff --git a/tests/unit/ui/test_blank_window_watchdog.py b/tests/unit/ui/test_blank_window_watchdog.pyindex 828bb503b7..e6b8e9a913 100644--- a/tests/unit/ui/test_blank_window_watchdog.py+++ b/tests/unit/ui/test_blank_window_watchdog.py@@ -56,12 +56,14 @@ def _obs(page: str = "blank",alive: bool = True,healthy: bool = True,+ warming: bool = False,) -> Observation:return Observation(page=page, # type: ignore[arg-type]backend_alive=alive,server_healthy=healthy,now=now,+ server_warming=warming,)@@ -198,7 +200,9 @@ def test_reloads_are_budgeted_then_the_window_explains_itself() -> None:p.decide(_obs(t))actions = []for _ in range(3):- t += GRACE + 1+ # The settle escalates per used reload (1x, 2x, ...), so the clock+ # jumps far enough to clear every deadline on the way.+ t += GRACE + SETTLE * 4v = p.decide(_obs(t))actions.append(v)t += 0.1@@ -216,6 +220,45 @@ def test_a_reload_is_given_time_to_settle_before_the_next_one() -> None:assert p.decide(_obs(GRACE + SETTLE + 2)).action is Action.RELOAD+def test_each_further_reload_waits_twice_as_long() -> None:+ """A window that did not come back after one reload is loading slowly, not+ broken — hammering it at a fixed cadence piled cold WebView starts onto a+ machine already too busy to paint (the 2026-08-30 cold-boot thrash)."""+ p = _policy()+ p.decide(_obs(0.0))+ t1 = GRACE + 1+ assert p.decide(_obs(t1)).action is Action.RELOAD # settle 1x from here+ assert p.decide(_obs(t1 + SETTLE + 1)).action is Action.RELOAD # settle 2x+ assert p.decide(_obs(t1 + SETTLE + 1 + SETTLE + 2)).action is Action.WAIT+ assert p.decide(_obs(t1 + SETTLE + 1 + SETTLE * 2 + 2)).action is Action.RELOAD+++# --- the warming boot --------------------------------------------------------+++def test_a_warming_backend_is_never_reloaded_no_matter_how_long() -> None:+ """The bootstrap answers health with warming: a blank window is the+ EXPECTED picture then, and every reload only restarts a cold WebView."""+ p = _policy()+ for t in (0.0, GRACE + 1, GRACE * 10, GRACE * 100):+ assert p.decide(_obs(t, warming=True)).action is Action.WAIT+++def test_grace_starts_fresh_when_warming_ends() -> None:+ p = _policy()+ p.decide(_obs(0.0, warming=True))+ p.decide(_obs(60.0, warming=True))+ # Warming ended at t=60; the window still gets its full grace from there.+ assert p.decide(_obs(60.0 + GRACE - 1)).action is Action.WAIT+ assert p.decide(_obs(60.0 + GRACE + 2)).action is Action.RELOAD+++def test_a_dead_backend_wins_over_a_stale_warming_flag() -> None:+ v = _policy().decide(_obs(GRACE + 1, alive=False, warming=True))+ assert v.action is Action.EXPLAIN+ assert v.reason is BlankReason.BACKEND_DEAD++# --- the explanation page ---------------------------------------------------