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): a window reloads itself again after a rebuild — the holding-page test matched the real index
rubenluetke10-beepb5a9604bfd8e
diff --git a/jarvis/ui/web/frontend/index.html b/jarvis/ui/web/frontend/index.htmlindex e675edcdb2..d51e7603e0 100644--- a/jarvis/ui/web/frontend/index.html+++ b/jarvis/ui/web/frontend/index.html@@ -186,8 +186,13 @@var RETRY_MS = 700;var SLOW_RETRY_MS = 3000;var FAST_TRIES = 20;- // Mirrors HOLDING_MARKER in jarvis/ui/web/spa_build.py.+ // Mirrors HOLDING_MARKER in jarvis/ui/web/spa_build.py. Tested for in+ // its attribute form only, composed here so this very script never+ // contains it: this document IS what a reload fetches, and a test for+ // the bare word found it in these lines and never reloaded anything+ // (2026-08-22/23). Mirrors HOLDING_ATTRIBUTE in src/lib/safeReload.ts.var HOLDING = "jarvis-build-holding";+ var HOLDING_ATTR = 'data-state="' + HOLDING + '"';var KEY = "jarvis:blank-reloaded";var started = Date.now();var lastError = "";@@ -234,7 +239,7 @@return r.ok ? r.text() : "";}).then(function (html) {- if (!html || html.indexOf(HOLDING) !== -1) {+ if (!html || html.indexOf(HOLDING_ATTR) !== -1) {again();return;}diff --git a/jarvis/ui/web/frontend/src/lib/bootWatchdog.test.ts b/jarvis/ui/web/frontend/src/lib/bootWatchdog.test.tsindex c43136619f..bff122f335 100644--- a/jarvis/ui/web/frontend/src/lib/bootWatchdog.test.ts+++ b/jarvis/ui/web/frontend/src/lib/bootWatchdog.test.ts@@ -20,7 +20,8 @@ function indexHtmlPath(): string {const candidate = resolve(dir, "index.html");if (existsSync(candidate)) return candidate;const up = dirname(dir);- if (up === dir) throw new Error("index.html not found above " + process.cwd());+ if (up === dir)+ throw new Error("index.html not found above " + process.cwd());dir = up;}}@@ -31,7 +32,8 @@ const HTML = readFileSync(indexHtmlPath(), "utf8");function watchdogSource(): string {const scripts = HTML.match(/<script>([\s\S]*?)<\/script>/g) ?? [];const found = scripts.find((s) => s.includes("jarvis:blank-reloaded"));- if (!found) throw new Error("index.html no longer carries the blank-window watchdog");+ if (!found)+ throw new Error("index.html no longer carries the blank-window watchdog");return found.replace(/^<script>/, "").replace(/<\/script>$/, "");}@@ -122,6 +124,22 @@ describe("the blank-window watchdog in index.html", () => {expect(run.reloads()).toBe(1);});+ test("it reloads into the REAL index.html, whose own script names the holding marker", async () => {+ // The regression of 2026-08-22/23: this very document spells out the+ // holding marker in the watchdog's source, so a test for the bare word+ // took every genuine build for the holding page and no window ever+ // reloaded again. The served document here is index.html itself, shaped+ // as the build ships it (a hashed entry asset in its head).+ const built = HTML.replace(+ "</head>",+ '<script type="module" crossorigin src="/assets/index-abc.js"></script></head>',+ );+ setRoot("");+ const run = runWatchdog({ served: built });+ await vi.advanceTimersByTimeAsync(3_000);+ expect(run.reloads()).toBe(1);+ });+test("an emptied root is a crash, and does not wait twenty seconds for it", async () => {setRoot("");const run = runWatchdog();@@ -174,7 +192,9 @@ describe("the blank-window watchdog in index.html", () => {const run = runWatchdog();run.store.set("jarvis:blank-reloaded", "1");window.dispatchEvent(- new ErrorEvent("error", { message: "Failed to fetch dynamically imported module" }),+ new ErrorEvent("error", {+ message: "Failed to fetch dynamically imported module",+ }),);vi.advanceTimersByTime(3_000);expect(run.reloads()).toBe(0);diff --git a/jarvis/ui/web/frontend/src/lib/bundleWatch.test.ts b/jarvis/ui/web/frontend/src/lib/bundleWatch.test.tsindex fdc58f1687..e56d571c96 100644--- a/jarvis/ui/web/frontend/src/lib/bundleWatch.test.ts+++ b/jarvis/ui/web/frontend/src/lib/bundleWatch.test.ts@@ -8,6 +8,8 @@*/import { describe, expect, it, vi } from "vitest";import {+ HIDDEN_EVERY_N_TICKS,+ STALE_INFLIGHT_TICKS,bundleFingerprint,installBundleWatch,shouldReload,@@ -89,7 +91,9 @@ describe("bundleFingerprint", () => {);const reordered ='<link href="/assets/index-AAA.css"><script src="/assets/index-AAA.js">';- expect(bundleFingerprint(reordered)).toBe(bundleFingerprint(indexHtml("AAA")));+ expect(bundleFingerprint(reordered)).toBe(+ bundleFingerprint(indexHtml("AAA")),+ );});it("has no fingerprint for a document with no bundle behind it", () => {@@ -128,13 +132,23 @@ describe("shouldReload", () => {it("never reloads for an unchanged or unreadable answer", () => {expect(- shouldReload({ baseline, seen: baseline, confirmed: baseline, idleMs: null }),+ shouldReload({+ baseline,+ seen: baseline,+ confirmed: baseline,+ idleMs: null,+ }),).toBe(false);expect(shouldReload({ baseline, seen: "", confirmed: "", idleMs: null }),).toBe(false);expect(- shouldReload({ baseline: "", seen: "new", confirmed: "new", idleMs: null }),+ shouldReload({+ baseline: "",+ seen: "new",+ confirmed: "new",+ idleMs: null,+ }),).toBe(false);});});@@ -196,6 +210,52 @@ describe("installBundleWatch", () => {expect(app.reload).toHaveBeenCalledOnce();});+ it("still picks up a rebuild in a window that claims to be hidden forever", async () => {+ // The desktop shell's engine was measured reporting an on-screen window as+ // hidden for minutes (2026-08-23). A watch that trusts it never polls again+ // and the window runs a stale build through every later rebuild.+ const app = harness(indexHtml("AAA"));+ installBundleWatch(app.deps);+ await app.tick();++ app.hide(true);+ app.serve(indexHtml("BBB"));+ for (let i = 0; i < HIDDEN_EVERY_N_TICKS * 2; i += 1) {+ await app.tick();+ }++ expect(app.reload).toHaveBeenCalledOnce();+ });++ it("does not let one check that never answers hold the watch forever", async () => {+ const app = harness(indexHtml("AAA"));+ let first = true;+ const stalling: BundleWatchDeps = {+ ...app.deps,+ fetchIndex: () => {+ if (first) {+ first = false;+ return new Promise<string>(() => {+ /* never settles */+ });+ }+ return app.deps.fetchIndex();+ },+ };+ installBundleWatch(stalling);+ // The opening check is the one that hangs.+ for (let i = 0; i < STALE_INFLIGHT_TICKS; i += 1) {+ await app.tick();+ }+ // By now a fresh check has established the baseline; a rebuild gets seen.+ await app.tick();+ app.serve(indexHtml("BBB"));+ await app.tick();+ await app.tick();++ expect(app.reload).toHaveBeenCalledOnce();+ });+it("treats a failed check as no information at all", async () => {const app = harness(indexHtml("AAA"));const failing: BundleWatchDeps = {diff --git a/jarvis/ui/web/frontend/src/lib/bundleWatch.ts b/jarvis/ui/web/frontend/src/lib/bundleWatch.tsindex 647eeb6f89..b709f36cde 100644--- a/jarvis/ui/web/frontend/src/lib/bundleWatch.ts+++ b/jarvis/ui/web/frontend/src/lib/bundleWatch.ts@@ -22,6 +22,23 @@* reloading into that is the flicker loop preloadRecovery was written for;* * the user must be idle for a moment, because a reload in the middle of a* sentence loses the sentence.+ *+ * And two rules keep it from quietly dying, which is the failure that was+ * actually reported (2026-08-23: the desktop window ran a morning-old build+ * through two rebuilds and showed every section it had not visited yet as a+ * crash):+ *+ * * a window that says it is hidden is still checked, only slower. The+ * desktop shell's engine (WebView2 under pywebview) was measured reporting+ * an on-screen, on-top window as `visibilityState === "hidden"` for minutes+ * at a time; a watch that trusts that verdict never polls again. One request+ * every half minute is nothing, and a reload of a window nobody is looking at+ * costs nothing either;+ * * a check that never answers does not hold the watch. The single in-flight+ * guard protected against stacking, but a request the engine never settles —+ * a server mid-restart, a socket the machine slept through — turned it into+ * a permanent lock. An answer that is late past a few ticks is treated as+ * lost and a fresh check goes out.*//** How often the served bundle is checked, while the window is visible. */@@ -30,6 +47,12 @@ export const POLL_MS = 5_000;/** Quiet time required before a reload is allowed to interrupt. */export const IDLE_MS = 2_000;+/** A window that reports itself hidden still checks, every this many ticks. */+export const HIDDEN_EVERY_N_TICKS = 6;++/** A check still unanswered after this many ticks no longer blocks the next. */+export const STALE_INFLIGHT_TICKS = 3;+/*** What the running document would have to load to be current.*@@ -50,7 +73,7 @@ export interface BundleWatchDeps {reload: () => void;/** Milliseconds since the last keystroke or pointer press, or null if none. */idleFor: () => number | null;- /** Is this window on screen? A hidden window polls nothing. */+ /** Is this window on screen? A hidden window polls {@link HIDDEN_EVERY_N_TICKS}× slower. */visible: () => boolean;/** Schedule the repeating check. Returns a handle for {@link stop}. */every: (fn: () => void, ms: number) => number;@@ -93,21 +116,43 @@ export function shouldReload({export function installBundleWatch(deps: BundleWatchDeps): () => void {let baseline = "";let confirmed: string | null = null;- let busy = false;+ // Ticks the current check has been waiting for its answer; 0 = none open.+ let inflightTicks = 0;+ // Which check is current. An answer from a check that was given up on must+ // not be mistaken for fresh information.+ let generation = 0;+ let hiddenTicks = 0;const check = () => {- if (busy || !deps.visible()) return;- busy = true;+ if (inflightTicks > 0 && inflightTicks < STALE_INFLIGHT_TICKS) {+ // One check at a time — a slow answer is not a reason to stack another.+ inflightTicks += 1;+ return;+ }+ if (!deps.visible()) {+ // Hidden is a hint to go easy, never a reason to stop: the verdict is+ // wrong in at least one engine this app ships in (see the module note).+ hiddenTicks += 1;+ if (hiddenTicks % HIDDEN_EVERY_N_TICKS !== 0) return;+ } else {+ hiddenTicks = 0;+ }+ inflightTicks = 1;+ generation += 1;+ const mine = generation;void deps.fetchIndex().then((html) => {+ if (mine !== generation) return;const seen = bundleFingerprint(html);if (!seen) return;if (!baseline) {baseline = seen;return;}- if (shouldReload({ baseline, seen, confirmed, idleMs: deps.idleFor() })) {+ if (+ shouldReload({ baseline, seen, confirmed, idleMs: deps.idleFor() })+ ) {deps.reload();return;}@@ -118,7 +163,7 @@ export function installBundleWatch(deps: BundleWatchDeps): () => void {// poll asks again. A window must never reload because a request failed.}).finally(() => {- busy = false;+ if (mine === generation) inflightTicks = 0;});};diff --git a/jarvis/ui/web/frontend/src/lib/safeReload.test.ts b/jarvis/ui/web/frontend/src/lib/safeReload.test.tsindex 2648e8397d..9e83710289 100644--- a/jarvis/ui/web/frontend/src/lib/safeReload.test.ts+++ b/jarvis/ui/web/frontend/src/lib/safeReload.test.ts@@ -1,12 +1,28 @@+import { existsSync, readFileSync } from "node:fs";+import { dirname, resolve } from "node:path";import { describe, expect, test } from "vitest";import {entryAssets,+ HOLDING_ATTRIBUTE,HOLDING_MARKER,looksBootable,reloadWhenServable,type SafeReloadDeps,} from "./safeReload";+/** The real entry document this app ships — the one every reload fetches. */+function realIndexHtml(): string {+ let dir = process.cwd();+ for (;;) {+ const candidate = resolve(dir, "index.html");+ if (existsSync(candidate)) return readFileSync(candidate, "utf8");+ const up = dirname(dir);+ if (up === dir)+ throw new Error("index.html not found above " + process.cwd());+ dir = up;+ }+}+const INDEX = `<!doctype html><html><head><script type="module" crossorigin src="/assets/index-abc123.js"></script><link rel="stylesheet" href="/assets/index-def456.css">@@ -22,7 +38,8 @@ function harness(pages: string[], assets: (url: string) => boolean) {let waits = 0;const asked: string[] = [];const deps: SafeReloadDeps = {- fetchIndex: () => Promise.resolve(pages.length > 1 ? pages.shift()! : pages[0]),+ fetchIndex: () =>+ Promise.resolve(pages.length > 1 ? pages.shift()! : pages[0]),assetOk: (url) => {asked.push(url);return Promise.resolve(assets(url));@@ -70,9 +87,27 @@ describe("looksBootable", () => {});test("the server's holding page is not — it says a build is in flight", () => {- expect(looksBootable(`<html><div data-state="${HOLDING_MARKER}"></div></html>`)).toBe(- false,+ expect(+ looksBootable(`<html><div data-state="${HOLDING_MARKER}"></div></html>`),+ ).toBe(false);+ });++ test("the REAL index.html is, although its inline watchdog names the marker", () => {+ // The regression of 2026-08-22/23: index.html carries a watchdog script+ // that spells out the holding marker, a check for the bare word took every+ // genuine build for the holding page, and no window ever reloaded again.+ // Only the attribute form on the holding page's element counts — and the+ // real document must never contain that form.+ const source = realIndexHtml();+ expect(source).toContain(HOLDING_MARKER);+ expect(source).not.toContain(HOLDING_ATTRIBUTE);+ // What Vite makes of it: the same document with hashed entry assets.+ const built = source.replace(+ "</head>",+ '<script type="module" crossorigin src="/assets/index-abc123.js"></script></head>',);+ expect(entryAssets(built).length).toBeGreaterThan(0);+ expect(looksBootable(built)).toBe(true);});});@@ -82,7 +117,10 @@ describe("reloadWhenServable", () => {reloadWhenServable(h.deps);await settle();expect(h.reloads()).toBe(1);- expect(h.asked()).toEqual(["/assets/index-abc123.js", "/assets/index-def456.css"]);+ expect(h.asked()).toEqual([+ "/assets/index-abc123.js",+ "/assets/index-def456.css",+ ]);});test("an index whose entry bundle 404s is NOT reloaded into", async () => {@@ -96,7 +134,10 @@ describe("reloadWhenServable", () => {});test("the holding page is waited out, never reloaded into", async () => {- const h = harness([`<html><div data-state="${HOLDING_MARKER}"></div></html>`], () => true);+ const h = harness(+ [`<html><div data-state="${HOLDING_MARKER}"></div></html>`],+ () => true,+ );reloadWhenServable(h.deps);await settle();expect(h.reloads()).toBe(0);diff --git a/jarvis/ui/web/frontend/src/lib/safeReload.ts b/jarvis/ui/web/frontend/src/lib/safeReload.tsindex 7420637461..810d975260 100644--- a/jarvis/ui/web/frontend/src/lib/safeReload.ts+++ b/jarvis/ui/web/frontend/src/lib/safeReload.ts@@ -35,6 +35,21 @@/** Marks the server's holding page. Mirrors `HOLDING_MARKER` in spa_build.py. */export const HOLDING_MARKER = "jarvis-build-holding";+/**+ * How the holding page carries its marker — and the ONLY form a document is+ * tested against.+ *+ * The bare word is not enough: the real `index.html` ships an inline watchdog+ * that names the marker in its own source, so a test for the word alone takes+ * every genuine build for the holding page and never reloads into it. That is+ * what kept every open window on a stale build from 2026-08-22 to 2026-08-23+ * (bundle watch, preload recovery and the stale-chunk card all funnel through+ * here). The attribute form appears on the holding page's own element and+ * nowhere else; `index.html` composes it at runtime for the same reason. See+ * the pinning test in safeReload.test.ts and bootWatchdog.test.ts.+ */+export const HOLDING_ATTRIBUTE = `data-state="${HOLDING_MARKER}"`;+/** Delay between checks while a build is in flight. */export const RETRY_MS = 700;@@ -74,7 +89,7 @@ export function entryAssets(html: string): string[] {* exactly the failure this module exists for.*/export function looksBootable(html: string): boolean {- if (!html || html.includes(HOLDING_MARKER)) return false;+ if (!html || html.includes(HOLDING_ATTRIBUTE)) return false;return entryAssets(html).length > 0;}diff --git a/jarvis/ui/web/frontend/src/main.tsx b/jarvis/ui/web/frontend/src/main.tsxindex 3ad7c0242a..f9b6601e50 100644--- a/jarvis/ui/web/frontend/src/main.tsx+++ b/jarvis/ui/web/frontend/src/main.tsx@@ -6,7 +6,7 @@ import { ThemeProvider } from "./hooks/useTheme";import { ViewErrorBoundary } from "./components/ViewErrorBoundary";import { AuthGate } from "./components/AuthGate";import { installPreloadRecovery } from "./lib/preloadRecovery";-import { installBundleWatch } from "./lib/bundleWatch";+import { POLL_MS, installBundleWatch } from "./lib/bundleWatch";import { browserSafeReloadDeps, reloadWhenServable } from "./lib/safeReload";import "./index.css";@@ -45,9 +45,16 @@ installPreloadRecovery({}installBundleWatch({fetchIndex: () =>- fetch("/", { cache: "no-store", headers: { Accept: "text/html" } }).then(- (response) => (response.ok ? response.text() : ""),- ),+ fetch("/", {+ cache: "no-store",+ headers: { Accept: "text/html" },+ // A request the engine never settles must not outlive the next tick;+ // the watch treats a late answer as lost, this makes sure it IS lost.+ signal:+ typeof AbortSignal.timeout === "function"+ ? AbortSignal.timeout(POLL_MS - 500)+ : undefined,+ }).then((response) => (response.ok ? response.text() : "")),reload: () => reloadWhenServable(browserSafeReloadDeps()),idleFor: () => (lastInput === null ? null : Date.now() - lastInput),visible: () => document.visibilityState !== "hidden",diff --git a/jarvis/ui/web/spa_build.py b/jarvis/ui/web/spa_build.pyindex 9a24f1ce51..e5a6145917 100644--- a/jarvis/ui/web/spa_build.py+++ b/jarvis/ui/web/spa_build.py@@ -35,7 +35,13 @@ from __future__ import annotationsimport refrom pathlib import Path-__all__ = ["referenced_assets", "build_is_complete", "holding_page_html", "HOLDING_MARKER"]+__all__ = [+ "referenced_assets",+ "build_is_complete",+ "holding_page_html",+ "HOLDING_ATTRIBUTE",+ "HOLDING_MARKER",+]# Present in the holding page and in nothing else, so a page that is waiting# for a build can tell — from the document alone — whether the server is ready@@ -43,6 +49,15 @@ __all__ = ["referenced_assets", "build_is_complete", "holding_page_html", "HOLDI# reloads test for it.HOLDING_MARKER = "jarvis-build-holding"+# The ONLY form a document is ever tested against. The bare word is not safe:+# the real index.html ships an inline watchdog that names the marker in its own+# source, so a test for the word alone took every genuine build for the+# holding page — this page then never reloaded into the app, and the+# frontend's own reloads (src/lib/safeReload.ts) never fired (2026-08-22/23).+# The attribute form lives on the holding page's element and nowhere else;+# index.html composes it at runtime so it can never contain it literally.+HOLDING_ATTRIBUTE = f'data-state="{HOLDING_MARKER}"'+# Every hashed build output index.html points at. Mirrors the frontend's own# `bundleFingerprint` (src/lib/bundleWatch.ts) — keep the two patterns in# lockstep, they are answering the same question from opposite ends.@@ -144,7 +159,7 @@ def holding_page_html() -> str:"tries++;""fetch('/',{cache:'no-store',headers:{Accept:'text/html'}})"f".then(function(r){{return r.ok?r.text():'{HOLDING_MARKER}';}})"- f".then(function(t){{if(t.indexOf('{HOLDING_MARKER}')===-1){{"+ f".then(function(t){{if(t.indexOf('{HOLDING_ATTRIBUTE}')===-1){{""location.reload();return;}""setTimeout(look, tries<20?700:3000);})""['catch'](function(){setTimeout(look, tries<20?700:3000);});"diff --git a/tests/unit/ui/web/test_spa_build_completeness.py b/tests/unit/ui/web/test_spa_build_completeness.pyindex fa457608db..908c83dde6 100644--- a/tests/unit/ui/web/test_spa_build_completeness.py+++ b/tests/unit/ui/web/test_spa_build_completeness.py@@ -26,6 +26,7 @@ import pytestfrom jarvis.ui.web.fast_bootstrap import FastBootstrapfrom jarvis.ui.web.spa_build import (+ HOLDING_ATTRIBUTE,HOLDING_MARKER,build_is_complete,holding_page_html,@@ -36,7 +37,7 @@ _INDEX = ("<!doctype html><html><head>"'<script type="module" crossorigin src="/assets/index-abc123.js"></script>''<link rel="stylesheet" href="/assets/index-def456.css">'- "</head><body><div id=\"root\"></div></body></html>"+ '</head><body><div id="root"></div></body></html>')@@ -77,9 +78,7 @@ class TestBuildIsComplete:dist = _dist(tmp_path, index=False)assert build_is_complete(dist / "index.html", dist) is False- def test_it_is_never_cached_because_the_files_move_under_it(- self, tmp_path: Path- ) -> None:+ def test_it_is_never_cached_because_the_files_move_under_it(self, tmp_path: Path) -> None:# index.html stays byte-identical while dist/assets is emptied — a# result keyed on its mtime would be exactly wrong here.dist = _dist(tmp_path)@@ -97,6 +96,22 @@ class TestBuildIsComplete:class TestHoldingPage:def test_it_carries_the_marker_a_waiting_window_looks_for(self) -> None:assert HOLDING_MARKER in holding_page_html()+ assert HOLDING_ATTRIBUTE in holding_page_html()++ def test_it_tells_itself_apart_from_the_real_index_by_the_attribute_form(self) -> None:+ # The real index.html names the bare marker in its inline watchdog, so+ # a page polling for the bare word would take every genuine build for+ # itself and spin on "Updating…" forever (2026-08-22/23). The poll+ # tests for the attribute form, which the real document never carries.+ page = holding_page_html()+ assert f"indexOf('{HOLDING_ATTRIBUTE}')" in page+ assert f"indexOf('{HOLDING_MARKER}')" not in page+ root = Path(__file__).resolve().parents[4]+ source = (root / "jarvis" / "ui" / "web" / "frontend" / "index.html").read_text(+ encoding="utf-8"+ )+ assert HOLDING_MARKER in source+ assert HOLDING_ATTRIBUTE not in sourcedef test_it_never_reloads_on_a_blind_timer(self) -> None:# A meta refresh reloads into the same half-written build over and over.@@ -149,9 +164,7 @@ class TestFastBootstrapServesTheHoldingPage:assert b"index-abc123.js" in body@pytest.mark.asyncio- async def test_a_half_written_build_gets_the_holding_page(- self, tmp_path: Path- ) -> None:+ async def test_a_half_written_build_gets_the_holding_page(self, tmp_path: Path) -> None:dist = _dist(tmp_path)(dist / "assets" / "index-abc123.js").unlink()bs = FastBootstrap(dist_dir=dist)