Skip to content

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.

feat(diagnostics): report a frozen UI thread from the window that froze

Ruben Lütkee19ba6f2a9ed
diff --git a/jarvis/ui/web/diagnostics_routes.py b/jarvis/ui/web/diagnostics_routes.py
index ae8ff84ba5..4d8d1d673d 100644
--- a/jarvis/ui/web/diagnostics_routes.py
+++ b/jarvis/ui/web/diagnostics_routes.py
@@ -19,6 +19,8 @@ import contextlib
from typing import Any
from fastapi import APIRouter
+from loguru import logger as log
+from pydantic import BaseModel, Field
router = APIRouter(prefix="/api/diagnostics", tags=["diagnostics"])
@@ -174,6 +176,56 @@ async def cancel_scopes() -> dict[str, Any]:
}
+class UiStallReport(BaseModel):
+ """One stretch during which the UI thread could not answer the user."""
+
+ blocked_ms: float = Field(
+ description="How long the browser's main thread was busy in one task."
+ )
+ at: str = Field(
+ default="",
+ description="Which view was on screen, as the UI names it.",
+ )
+ panes: int = Field(
+ default=0, description="Terminal panes mounted when it happened."
+ )
+ detail: str = Field(
+ default="",
+ description=(
+ "What the browser attributed the task to. Never free text from a "
+ "user and never page content — the reporter sends fixed labels."
+ ),
+ )
+
+
[email protected]("/ui-stall", summary="Report a frozen UI thread")
+async def report_ui_stall(report: UiStallReport) -> dict[str, Any]:
+ """Record that the window stopped answering, and for how long.
+
+ The desktop app is a WebView with no console and no dev tools, so a browser
+ main thread that blocks is invisible: the user sees "Not responding" in the
+ title bar and there is nothing anywhere to say what it was doing. The
+ backend already reports its own stalls from off the loop
+ (``jarvis.core.loop_watchdog``); this is the same idea for the half that
+ draws the window, and it is the half that survived every backend hypothesis
+ on 2026-07-28 — loop lag, CPU contention, GIL pressure, terminal frame
+ rate, xterm write and reflow cost were all measured and all clean, while
+ the window kept freezing for the user.
+
+ Deliberately a log line rather than stored state: it is read while chasing
+ a live complaint, next to the backend's own stall reports on the same clock.
+ """
+ log.warning(
+ "UI thread STALLED for {:.0f} ms (view={}, panes={}) — the window could "
+ "not answer clicks or keystrokes during this. Attributed to: {}",
+ report.blocked_ms,
+ report.at or "unknown",
+ report.panes,
+ report.detail or "unattributed",
+ )
+ return {"ok": True}
+
+
@router.get("/event-loop-lag")
async def event_loop_lag() -> dict[str, Any]:
"""Measure scheduling lag of the serving loop.
diff --git a/jarvis/ui/web/frontend/src/lib/uiStallWatch.test.ts b/jarvis/ui/web/frontend/src/lib/uiStallWatch.test.ts
new file mode 100644
index 0000000000..15c626eebe
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/lib/uiStallWatch.test.ts
@@ -0,0 +1,135 @@
+/**
+ * The UI-stall reporter.
+ *
+ * It exists because a blocked browser main thread is invisible inside a WebView
+ * — the user gets "Not responding" in the title bar and nothing else. So the
+ * two properties that matter are pinned here: it must stay silent through
+ * ordinary slow moments, and it must never become a source of load itself.
+ */
+import { afterEach, describe, expect, it, vi } from "vitest";
+import { watchUiStalls } from "./uiStallWatch";
+
+type ObserverCallback = (list: { getEntries: () => PerformanceEntry[] }) => void;
+
+/** Stand-in for the browser's observer, driven by the test. */
+function installObserver() {
+ const state: { cb: ObserverCallback | null; observed: unknown[]; disconnected: number } = {
+ cb: null,
+ observed: [],
+ disconnected: 0,
+ };
+ class FakeObserver {
+ constructor(cb: ObserverCallback) {
+ state.cb = cb;
+ }
+ observe(options: unknown) {
+ state.observed.push(options);
+ }
+ disconnect() {
+ state.disconnected += 1;
+ }
+ }
+ vi.stubGlobal("PerformanceObserver", FakeObserver);
+ return state;
+}
+
+function entry(duration: number, attribution?: unknown[]): PerformanceEntry {
+ return { duration, name: "self", entryType: "longtask", startTime: 0, attribution } as never;
+}
+
+afterEach(() => {
+ vi.unstubAllGlobals();
+ vi.useRealTimers();
+});
+
+describe("watchUiStalls", () => {
+ it("stays silent for tasks below the reporting bar", () => {
+ const state = installObserver();
+ const report = vi.fn();
+ watchUiStalls(report);
+
+ // A GC pause, a large terminal write, a pane reflow — all survivable.
+ state.cb?.({ getEntries: () => [entry(60), entry(240), entry(950)] });
+
+ expect(report).not.toHaveBeenCalled();
+ });
+
+ it("reports a multi-second block", () => {
+ const state = installObserver();
+ const report = vi.fn();
+ watchUiStalls(report);
+
+ state.cb?.({ getEntries: () => [entry(4200)] });
+
+ expect(report).toHaveBeenCalledTimes(1);
+ expect(report.mock.calls[0][0].blocked_ms).toBe(4200);
+ });
+
+ it("rate-limits a thread that keeps blocking", () => {
+ const state = installObserver();
+ const report = vi.fn();
+ watchUiStalls(report);
+
+ // Each report is itself a request the same thread must make; a stall storm
+ // must not turn into a request storm.
+ for (let i = 0; i < 20; i++) state.cb?.({ getEntries: () => [entry(3000)] });
+
+ expect(report).toHaveBeenCalledTimes(1);
+ });
+
+ it("sends fixed labels only, never page content", () => {
+ const state = installObserver();
+ const report = vi.fn();
+ watchUiStalls(report);
+
+ state.cb?.({
+ getEntries: () => [
+ entry(2000, [{ name: "script", containerType: "iframe", containerName: "x" }]),
+ ],
+ });
+
+ const payload = report.mock.calls[0][0];
+ expect(payload.detail).toBe("script/iframe/x");
+ expect(typeof payload.panes).toBe("number");
+ expect(payload.detail.length).toBeLessThanOrEqual(120);
+ });
+
+ it("survives an entry with no attribution", () => {
+ const state = installObserver();
+ const report = vi.fn();
+ watchUiStalls(report);
+
+ state.cb?.({ getEntries: () => [entry(2000)] });
+
+ expect(report.mock.calls[0][0].detail).toBe("");
+ });
+
+ it("is a no-op where the API does not exist", () => {
+ vi.stubGlobal("PerformanceObserver", undefined);
+ const report = vi.fn();
+ const stop = watchUiStalls(report);
+ expect(() => stop()).not.toThrow();
+ expect(report).not.toHaveBeenCalled();
+ });
+
+ it("is a no-op when the entry type is unsupported", () => {
+ class Refusing {
+ constructor(_cb: ObserverCallback) {}
+ observe() {
+ throw new TypeError("longtask is not a valid entry type");
+ }
+ disconnect() {}
+ }
+ vi.stubGlobal("PerformanceObserver", Refusing);
+ const report = vi.fn();
+ expect(() => watchUiStalls(report)()).not.toThrow();
+ expect(report).not.toHaveBeenCalled();
+ });
+
+ it("stops observing when told to", () => {
+ const state = installObserver();
+ const stop = watchUiStalls(vi.fn());
+ stop();
+ expect(state.disconnected).toBe(1);
+ });
+});
diff --git a/jarvis/ui/web/frontend/src/lib/uiStallWatch.ts b/jarvis/ui/web/frontend/src/lib/uiStallWatch.ts
new file mode 100644
index 0000000000..8cb4ef6381
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/lib/uiStallWatch.ts
@@ -0,0 +1,113 @@
+/**
+ * Notice when the browser's main thread stops answering — and say so out loud.
+ *
+ * The desktop app is a WebView with no address bar, no dev tools and no
+ * console, so a blocked main thread is completely invisible from the inside.
+ * What the user sees is the window title turning into "Not responding", clicks
+ * landing late, and characters appearing in a terminal pane seconds after they
+ * were typed — all three being the same event: one JavaScript task ran long
+ * enough that nothing else, input included, could be serviced.
+ *
+ * The backend already reports its own stalls from a thread the loop cannot
+ * block (`jarvis/core/loop_watchdog.py`). This is the same instrument for the
+ * half that draws the window, and it exists because that half is the one that
+ * survived every measurement on 2026-07-28: backend loop lag, CPU contention
+ * from other processes, GIL pressure inside the app, terminal frame rate,
+ * xterm write cost and reflow cost were each measured and each came back
+ * clean, while the window kept freezing during real use.
+ *
+ * Cost when nothing is wrong: one registered observer that is never called.
+ * `longtask` entries are only emitted for tasks already over ~50 ms, so this
+ * cannot itself become the thing that slows the page down.
+ */
+
+/**
+ * Report tasks longer than this, in milliseconds.
+ *
+ * Well above the ~50 ms the browser already considers "long": a garbage
+ * collection pause, a big terminal write and a pane reflow all land in the low
+ * hundreds and are survivable. What is being hunted is the multi-second block
+ * that makes Windows draw the ghost window, so the bar sits high enough that a
+ * quiet session reports nothing at all.
+ */
+const REPORT_OVER_MS = 1000;
+
+/**
+ * Never send more than one report per this window.
+ *
+ * A thread that is blocking repeatedly would otherwise report on every block,
+ * and each report is itself a request the same thread has to make. One line a
+ * minute is enough to establish what is happening.
+ */
+const MIN_GAP_MS = 60_000;
+
+/** Fixed labels only — no page content, no user text, ever leaves here. */
+function describe(entry: PerformanceEntry): string {
+ const attribution = (entry as PerformanceEntry & {
+ attribution?: Array<{ name?: string; containerType?: string; containerName?: string }>;
+ }).attribution;
+ if (!attribution?.length) return "";
+ const first = attribution[0];
+ return [first.name, first.containerType, first.containerName]
+ .filter(Boolean)
+ .join("/")
+ .slice(0, 120);
+}
+
+/** How many terminal panes are mounted right now, as the DOM knows it. */
+function paneCount(): number {
+ try {
+ return document.querySelectorAll("[data-testid^='agentic-terminal-host-']").length;
+ } catch {
+ return 0;
+ }
+}
+
+/**
+ * Start watching. Returns a stop function; safe to call in any environment —
+ * an engine without `PerformanceObserver` or without the `longtask` entry type
+ * simply gets a no-op rather than a crash.
+ */
+export function watchUiStalls(
+ report: (payload: {
+ blocked_ms: number;
+ at: string;
+ panes: number;
+ detail: string;
+ }) => void,
+): () => void {
+ if (typeof PerformanceObserver === "undefined") return () => {};
+
+ let lastReportAt = 0;
+ let observer: PerformanceObserver;
+ try {
+ observer = new PerformanceObserver((list) => {
+ for (const entry of list.getEntries()) {
+ if (entry.duration < REPORT_OVER_MS) continue;
+ const now = Date.now();
+ if (now - lastReportAt < MIN_GAP_MS) continue;
+ lastReportAt = now;
+ report({
+ blocked_ms: Math.round(entry.duration),
+ // The route the app is on, not its contents — enough to tell a stall
+ // in the Agentic IDE apart from one anywhere else.
+ at: (location.hash || location.pathname || "").slice(0, 60),
+ panes: paneCount(),
+ detail: describe(entry),
+ });
+ }
+ });
+ observer.observe({ type: "longtask", buffered: true });
+ } catch {
+ // Entry type unsupported in this engine — nothing to watch, nothing broken.
+ return () => {};
+ }
+
+ return () => {
+ try {
+ observer.disconnect();
+ } catch {
+ /* already gone */
+ }
+ };
+}
diff --git a/jarvis/ui/web/frontend/src/main.tsx b/jarvis/ui/web/frontend/src/main.tsx
index 45cd5e38d3..f44bbd7c56 100644
--- a/jarvis/ui/web/frontend/src/main.tsx
+++ b/jarvis/ui/web/frontend/src/main.tsx
@@ -25,6 +25,25 @@ window.addEventListener("load", () => {
sessionStorage.removeItem("jarvis:preload-reloaded");
});
+// Say it out loud when the main thread stops answering the user. In a WebView
+// there is no console to notice it in, so a multi-second block shows up only as
+// "Not responding" in the window title and as keystrokes arriving late in a
+// terminal pane — with nothing anywhere to say what ran. The backend reports
+// its own stalls the same way (jarvis/core/loop_watchdog.py); this covers the
+// half that draws the window. Silent unless something actually blocks.
+void import("./lib/uiStallWatch").then(({ watchUiStalls }) => {
+ watchUiStalls((payload) => {
+ void fetch("/api/diagnostics/ui-stall", {
+ method: "POST",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify(payload),
+ // The thread that just unblocked may be on its way to blocking again, and
+ // this report must survive that rather than be cancelled with the page.
+ keepalive: true,
+ }).catch(() => undefined);
+ });
+});
+
const queryClient = new QueryClient({
defaultOptions: {
queries: { staleTime: 5_000, retry: 1 },