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(agentic-ide): let a pane reconnect the moment it is looked at
Ruben Lütkebe904e7867a9
diff --git a/jarvis/ui/web/frontend/src/components/agentic/paneSocket.test.ts b/jarvis/ui/web/frontend/src/components/agentic/paneSocket.test.tsindex 396bb96374..7bb2142c37 100644--- a/jarvis/ui/web/frontend/src/components/agentic/paneSocket.test.ts+++ b/jarvis/ui/web/frontend/src/components/agentic/paneSocket.test.ts@@ -44,6 +44,14 @@ class MockWebSocket {}}+/** Put the document in or out of view, the way a window switch does. */+function hidden(value: boolean) {+ Object.defineProperty(document, "hidden", {+ configurable: true,+ get: () => value,+ });+}+function handlers() {return {onOpen: vi.fn(),@@ -212,6 +220,67 @@ describe("openPaneSocket", () => {socket.close();});+ it("retries at once when the window comes back, without waiting out the clamp", async () => {+ /*+ * The live 2026-07-27 20:11 failure. A hidden document has its timers+ * clamped to about once a second, and to once a minute after a few minutes+ * of that — so five panes whose backoff asked for 0.5/1/2/4 s knocked on a+ * flat one-second grid, ran their streak down while the workspace was+ * opening, and surfaced their agents around two minutes later. The prompts+ * had gone out on time; only the screen was late.+ *+ * Being looked at ends the wait. No timer is advanced in this test on+ * purpose: that is the whole point — the retry must not depend on one.+ */+ const cb = handlers();+ const socket = openPaneSocket({ name: "Mika", cols: 80, rows: 24 }, cb);++ for (let i = 0; i < 10; i += 1) {+ MockWebSocket.last!.dropped(4503);+ await vi.advanceTimersByTimeAsync(30_000);+ }+ const spent = MockWebSocket.opened.length;++ hidden(true);+ MockWebSocket.last!.dropped(4503);+ hidden(false);+ document.dispatchEvent(new Event("visibilitychange"));++ expect(MockWebSocket.opened.length).toBe(spent + 1);++ MockWebSocket.last!.fire("open");+ MockWebSocket.last!.deliver({ t: "ready", resumed: true, reattached: false });+ expect(cb.onReady).toHaveBeenCalledTimes(1);+ socket.close();+ });++ it("does not open a second socket for a pane that is already connected", async () => {+ /* Coming back into view may only ever pull a PENDING retry forward. */+ const cb = handlers();+ const socket = openPaneSocket({ name: "Mika", cols: 80, rows: 24 }, cb);+ MockWebSocket.last!.fire("open");+ MockWebSocket.last!.deliver({ t: "ready", resumed: false, reattached: false });+ const spent = MockWebSocket.opened.length;++ hidden(false);+ document.dispatchEvent(new Event("visibilitychange"));++ expect(MockWebSocket.opened.length).toBe(spent);+ socket.close();+ });++ it("stops listening for visibility once the pane is closed", async () => {+ const cb = handlers();+ const socket = openPaneSocket({ name: "Mika", cols: 80, rows: 24 }, cb);+ MockWebSocket.last!.dropped(4503);+ socket.close();+ const spent = MockWebSocket.opened.length;++ document.dispatchEvent(new Event("visibilitychange"));++ expect(MockWebSocket.opened.length).toBe(spent);+ });+it("treats an agent exit as final, not as a dropped connection", async () => {const cb = handlers();const socket = openPaneSocket({ name: "Mika", cols: 80, rows: 24 }, cb);diff --git a/jarvis/ui/web/frontend/src/components/agentic/paneSocket.ts b/jarvis/ui/web/frontend/src/components/agentic/paneSocket.tsindex 913e24f0ba..1701b2c23a 100644--- a/jarvis/ui/web/frontend/src/components/agentic/paneSocket.ts+++ b/jarvis/ui/web/frontend/src/components/agentic/paneSocket.ts@@ -29,6 +29,22 @@* All three are bounded: a pane never hammers a backend that is genuinely* gone — it falls back to knocking every half minute — and whatever it ends up* believing, it says out loud.+ *+ * **Every one of those waits is measured by a timer, and a timer is the one+ * thing a hidden window does not honour.** Chromium clamps `setTimeout` in a+ * document that is not visible to roughly once per second, and to once per+ * minute after a few minutes of that — so a 500 ms retry becomes a second, and+ * the half-minute knock becomes a minute or more. Measured live 2026-07-27+ * 20:11: five panes reconnecting into a workspace that was still opening+ * knocked at 10.174, 11.174, 12.162, 13.170 — a flat one-second grid where the+ * backoff asked for 0.5 s, 1 s, 2 s, 4 s. The workspace opened at 20:11:24 and+ * the panes, by then deep in the slow schedule, surfaced their agents around+ * two minutes later with the work long since running. The agents were fine and+ * the prompts had gone out on time; only the screen was late.+ *+ * So the reconnect does not rely on the timer alone: coming back into view+ * retries immediately (see `onDocumentVisible`). The user looking at the pane+ * is the most reliable signal there is that the wait should end now.*/import { mintWsTicket } from "@/lib/ws";@@ -166,6 +182,32 @@ export function openPaneSocket(}, delay);};+ /**+ * The window came back — stop waiting and try now.+ *+ * A hidden document's timers are clamped, so whatever delay was scheduled has+ * been stretched by an unknown amount and may still be minutes out. Worse,+ * the streak counters kept growing while the clamp made every attempt look+ * slow, so a pane can arrive here believing the backend is gone when it was+ * merely unwatched. Being looked at is fresh evidence: the counters go back to+ * zero and the pending attempt happens immediately.+ *+ * Only ever pulls a retry FORWARD. A pane with no attempt scheduled is either+ * connected or finished, and neither wants a socket opened underneath it.+ */+ const onDocumentVisible = () => {+ if (stopped || typeof document === "undefined" || document.hidden) return;+ if (timer === null) return;+ clearTimeout(timer);+ timer = null;+ attempts = 0;+ waits = 0;+ open();+ };+ if (typeof document !== "undefined") {+ document.addEventListener("visibilitychange", onDocumentVisible);+ }+const giveUp = (message: string) => {stopped = true;handlers.onTrouble(message, false);@@ -320,6 +362,9 @@ export function openPaneSocket(},close(): void {stopped = true;+ if (typeof document !== "undefined") {+ document.removeEventListener("visibilitychange", onDocumentVisible);+ }if (timer !== null) {clearTimeout(timer);timer = null;