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): stop a pane freezing while its agent works on
Ruben Lütke025c7eb074bb
diff --git a/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.offscreen.test.tsx b/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.offscreen.test.tsxindex a5e81b3b68..12e2f3efe0 100644--- a/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.offscreen.test.tsx+++ b/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.offscreen.test.tsx@@ -94,6 +94,7 @@ vi.mock("@/lib/editActions", () => ({ attachTerminalBridge: () => undefined }));vi.mock("@/lib/agenticIdeApi", () => ({ attachToTerminal: vi.fn() }));import { AgenticTerminal } from "./AgenticTerminal";+import { OFFSCREEN_MAX_HOLD_MS } from "./offscreenBuffer";class ResizeObserverHarness implements ResizeObserver {constructor(_callback: ResizeObserverCallback) {}@@ -325,6 +326,82 @@ describe("AgenticTerminal off-screen output", () => {expect(harness.writes).toEqual([]);});+ it("writes what it holds once the deadline passes, still believing it is hidden", () => {+ // The backstop for every visibility question this pane can get wrong. The+ // three known ways to be wrongly parked were each found one live incident+ // at a time, so the pane must not depend on having learnt the last of them:+ // being mistaken has to cost a coalesced write, never a screen that stopped+ // (reported 2026-07-31 — two live panes, one frozen at a time).+ //+ // Nothing here tells the pane it is visible: no observer callback, no+ // `visibilitychange`, and jsdom measures a zero box, which `boxOnScreen`+ // reads as off screen. It writes anyway, which is the whole point.+ vi.useFakeTimers();+ try {+ mount();+ act(() => harness.fire?.(false));+ act(() => harness.handlers?.onOutput("the agent is still working"));+ expect(harness.writes).toEqual([]);++ act(() => {+ vi.advanceTimersByTime(OFFSCREEN_MAX_HOLD_MS + 50);+ });++ expect(harness.writes.join("")).toContain("the agent is still working");+ } finally {+ vi.useRealTimers();+ }+ });++ it("still coalesces a burst inside the hold window into ONE write", () => {+ // The performance contract that parking exists for, unchanged: a pane+ // nobody is looking at merges a burst into a single parse rather than+ // taking a frame per chunk from the pane being typed into. The deadline+ // bounds how far behind that can leave a screen; it does not turn parking+ // back into one write per chunk.+ vi.useFakeTimers();+ try {+ mount();+ act(() => harness.fire?.(false));+ act(() => {+ harness.handlers?.onOutput("frame one ");+ harness.handlers?.onOutput("frame two ");+ harness.handlers?.onOutput("frame three");+ });+ expect(harness.writes).toEqual([]);++ act(() => {+ vi.advanceTimersByTime(OFFSCREEN_MAX_HOLD_MS + 50);+ });++ expect(harness.writes).toEqual(["frame one frame two frame three"]);+ } finally {+ vi.useRealTimers();+ }+ });++ it("does not leave a quiet agent's last word parked", () => {+ // The case a deadline checked only when the NEXT chunk arrives cannot+ // reach: an agent that says something and then waits. That pane receives+ // nothing further, so a check on write would never run again and the last+ // thing it said would stay parked for as long as it stays quiet — which is+ // precisely the screen a user reads as frozen.+ vi.useFakeTimers();+ try {+ mount();+ act(() => harness.fire?.(false));+ act(() => harness.handlers?.onOutput("waiting for your answer"));++ act(() => {+ vi.advanceTimersByTime(OFFSCREEN_MAX_HOLD_MS + 50);+ });++ expect(harness.writes.join("")).toContain("waiting for your answer");+ } finally {+ vi.useRealTimers();+ }+ });+it("stays visible where IntersectionObserver does not exist", () => {// Old engines and bare test environments: the pane must keep drawing// rather than go permanently silent.diff --git a/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.tsx b/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.tsxindex b3d58171a1..cd7a76f512 100644--- a/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.tsx+++ b/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.tsx@@ -543,12 +543,43 @@ export function AgenticTerminal({const offscreen = new OffscreenBuffer();/** When this pane last measured itself while parked (see `recheckParked`). */let parkedCheckedAt = 0;+ /** The pending deadline flush, if this pane is holding anything. */+ let holdTimer: number | undefined;++ const cancelHoldTimer = () => {+ if (holdTimer === undefined) return;+ window.clearTimeout(holdTimer);+ holdTimer = undefined;+ };++ /**+ * Write what is held, whether or not this pane believes it is watched.+ *+ * The deadline half of parking (see ./offscreenBuffer): being wrong about+ * visibility must cost a coalesced write, never a screen that stopped.+ */+ const flushHeld = () => {+ cancelHoldTimer();+ const held = offscreen.drain();+ if (held) term.write(held);+ };++ /** Make sure the held output has a flush coming, without moving one nearer. */+ const armHoldTimer = () => {+ if (holdTimer !== undefined) return;+ const due = offscreen.dueIn();+ if (due === null) return;+ holdTimer = window.setTimeout(() => {+ holdTimer = undefined;+ if (disposed) return;+ flushHeld();+ }, due);+ };const showPane = () => {if (paneVisible) return;paneVisible = true;- const held = offscreen.drain();- if (held) term.write(held);+ flushHeld();};const parkPane = () => {@@ -624,7 +655,18 @@ export function AgenticTerminal({// the spinner row it rewrote last and blank rows where its prompt box// belongs. Parsing into a surface nobody is painting is the cheap half// of what parking avoids; a permanently broken screen is not.- if (offscreen.full) term.write(offscreen.drain());+ //+ // The same answer, for the same reason, once it has held long enough:+ // this pane's belief that nobody is watching may simply be wrong, and+ // that must cost a coalesced write rather than a frozen terminal. The+ // timer covers the case this branch cannot — an agent that goes quiet+ // right after saying something would otherwise hold that last word for+ // as long as it stays quiet.+ if (offscreen.full || offscreen.stale()) {+ flushHeld();+ return;+ }+ armHoldTimer();};/**@@ -653,6 +695,9 @@ export function AgenticTerminal({// Parked output belongs to the screen this replay REPLACES, and it was// captured before it. Written afterwards it would paint the older screen// over the newer one; written before, it would be reset away regardless.+ // The deadline goes with it — a flush firing after this would draw the+ // screen this replay just replaced.+ cancelHoldTimer();offscreen.drain();term.reset();// Through the ordinary path, so a replay arriving while nobody is looking@@ -931,6 +976,9 @@ export function AgenticTerminal({return () => {disposed = true;+ // Before the terminal is disposed below: a deadline flush one tick later+ // would write into it after it is gone.+ cancelHoldTimer();if (resizeTimer !== undefined) window.clearTimeout(resizeTimer);// A queued reflow outlives the pane by up to a frame, and would then fit// a disposed terminal inside a detached element.diff --git a/jarvis/ui/web/frontend/src/components/agentic/offscreenBuffer.test.ts b/jarvis/ui/web/frontend/src/components/agentic/offscreenBuffer.test.tsindex 477a7be36e..43ddb242b8 100644--- a/jarvis/ui/web/frontend/src/components/agentic/offscreenBuffer.test.ts+++ b/jarvis/ui/web/frontend/src/components/agentic/offscreenBuffer.test.ts@@ -1,6 +1,6 @@import { describe, expect, it } from "vitest";-import { OffscreenBuffer } from "./offscreenBuffer";+import { OFFSCREEN_LIMIT_CHARS, OffscreenBuffer } from "./offscreenBuffer";describe("OffscreenBuffer", () => {it("hands back exactly what it was given, in order, once", () => {@@ -50,6 +50,44 @@ describe("OffscreenBuffer", () => {expect(buffer.full).toBe(false);});+ it("comes due once it has held its oldest chunk long enough", () => {+ // The backstop for a pane that is wrong about being watched. Size alone+ // could not provide it: a CLI that prints one line and waits never reaches+ // the limit, so its pane held that line for as long as the agent stayed+ // quiet — a terminal that had visibly stopped while the work ran on.+ const buffer = new OffscreenBuffer(OFFSCREEN_LIMIT_CHARS, 1500);+ const start = 10_000;++ expect(buffer.stale(start)).toBe(false);+ expect(buffer.dueIn(start)).toBeNull();++ buffer.push("the agent said something", start);+ expect(buffer.stale(start + 1499)).toBe(false);+ expect(buffer.dueIn(start + 500)).toBe(1000);+ expect(buffer.stale(start + 1500)).toBe(true);++ // Draining answers it, exactly like `full` — otherwise a pane past its+ // deadline would write on every chunk from then on rather than coalescing.+ buffer.drain();+ expect(buffer.stale(start + 5000)).toBe(false);+ expect(buffer.dueIn(start + 5000)).toBeNull();+ });++ it("measures the deadline from the OLDEST chunk, not the newest", () => {+ // A pane fed a steady trickle would otherwise push its own deadline back+ // with every chunk and never come due — which is the busiest pane, and so+ // exactly the one whose freeze a user notices.+ const buffer = new OffscreenBuffer(OFFSCREEN_LIMIT_CHARS, 1500);+ const start = 10_000;++ buffer.push("first", start);+ for (let at = start + 200; at <= start + 1400; at += 200) {+ buffer.push("more", at);+ }++ expect(buffer.stale(start + 1500)).toBe(true);+ });+it("stays bounded when its user drains on full", () => {// How the pane actually uses it: park, and write out whenever it is full.// Memory stays capped WITHOUT anything being discarded.diff --git a/jarvis/ui/web/frontend/src/components/agentic/offscreenBuffer.ts b/jarvis/ui/web/frontend/src/components/agentic/offscreenBuffer.tsindex 558dccecea..7b6c931567 100644--- a/jarvis/ui/web/frontend/src/components/agentic/offscreenBuffer.ts+++ b/jarvis/ui/web/frontend/src/components/agentic/offscreenBuffer.ts@@ -30,6 +30,35 @@* holds to xterm even though nobody is watching. That costs one parse on a* surface the browser is not painting — which is the cheap half of the work* this class exists to avoid, and far cheaper than a screen that never recovers.+ *+ * ## Why holding is also bounded by TIME, not only by size+ *+ * Everything above assumes the pane finds out when it is looked at again. That+ * assumption has now failed three times, each in a state the browser reports no+ * way out of — a hidden document, a pane that came back at exactly the size it+ * left, a measurement taken while the window could not be measured at all — and+ * each was answered by teaching the pane one more question to ask+ * ({@link boxOnScreen}, `visibilitychange`, the resize path, the re-check on+ * output). Every one of those is a patch on the same shape of bug, and the list+ * is not provably complete: the failure is always "the pane believes nobody is+ * watching while somebody is", and from inside it is indistinguishable from+ * being right.+ *+ * The cost of being wrong used to be unbounded. A pane could hold its agent's+ * screen until 256 KB had piled up — minutes for a chatty CLI, forever for one+ * that printed a line and went quiet — and the user watched a terminal that had+ * simply stopped moving while the work behind it ran on (reported 2026-07-31:+ * two live panes, one frozen at a time, and clicking the frozen one handed the+ * freeze to its neighbour).+ *+ * So parking is capped at {@link OFFSCREEN_MAX_HOLD_MS}. That turns this class+ * from "withhold until somebody proves you are visible" into "COALESCE": a pane+ * still merges a burst of output into one write instead of sixty, which is the+ * entire performance win, but it can never be more than a moment behind — no+ * matter which visibility question it got wrong. A pane that really is hidden+ * pays one parse per interval onto a surface the browser does not paint, which+ * is the cheap half of the work; a pane that is wrongly hidden stops being a+ * frozen screen.*//**@@ -60,6 +89,23 @@ export const OFFSCREEN_LIMIT_CHARS = 256 * 1024;*/export const PARKED_RECHECK_MS = 1000;+/**+ * The longest a parked pane may hold its agent's output before writing it.+ *+ * This is the backstop for every visibility question this module gets wrong —+ * see the module docstring for why a complete list of those cannot be assumed.+ * Past it the pane writes what it holds without asking anything: it may still+ * be off screen, and writing costs one parse onto a surface nobody paints,+ * which is far cheaper than a terminal that has visibly stopped.+ *+ * Chosen so a burst of output still coalesces into one write — the whole point+ * of parking — while the worst case a user can observe is a screen that is one+ * and a half seconds behind rather than one that never moves again. Raising it+ * trades the same performance win for a longer freeze when a pane is wrong+ * about being watched.+ */+export const OFFSCREEN_MAX_HOLD_MS = 1500;+/*** How far outside the window a pane still counts as worth drawing.*@@ -108,14 +154,55 @@ export function boxOnScreen(export class OffscreenBuffer {private chunks: string[] = [];private size = 0;+ /**+ * When the oldest chunk still held here arrived, or null while empty.+ *+ * Measured from the FIRST chunk rather than the newest, because the age that+ * matters is the age of the oldest thing the user cannot see — a pane fed a+ * steady trickle would otherwise reset its own deadline forever and never+ * come due.+ */+ private heldSince: number | null = null;- constructor(private readonly limit: number = OFFSCREEN_LIMIT_CHARS) {}+ constructor(+ private readonly limit: number = OFFSCREEN_LIMIT_CHARS,+ private readonly maxHoldMs: number = OFFSCREEN_MAX_HOLD_MS,+ ) {}- /** Park one chunk of agent output. */- push(text: string): void {+ /**+ * Park one chunk of agent output.+ *+ * ``now`` is injectable so the pane and its tests can drive the deadline from+ * one clock; it defaults to the real one.+ */+ push(text: string, now: number = Date.now()): void {if (!text) return;this.chunks.push(text);this.size += text.length;+ if (this.heldSince === null) this.heldSince = now;+ }++ /**+ * Has this pane held what it has for long enough to write it regardless?+ *+ * The backstop for a pane that is wrong about being watched — see the module+ * docstring. Like {@link full} this means "write now", never "discard".+ */+ stale(now: number = Date.now()): boolean {+ return this.heldSince !== null && now - this.heldSince >= this.maxHoldMs;+ }++ /**+ * Milliseconds until {@link stale} turns true, or null while nothing is held.+ *+ * The pane schedules its own flush on this, so output that stops arriving is+ * still written: a deadline only checked when the next chunk lands would keep+ * the LAST thing an agent said parked for as long as it stays quiet, which is+ * exactly the screen a user reads as frozen.+ */+ dueIn(now: number = Date.now()): number | null {+ if (this.heldSince === null) return null;+ return Math.max(0, this.maxHoldMs - (now - this.heldSince));}/**@@ -130,6 +217,7 @@ export class OffscreenBuffer {/** Everything kept, oldest first, ready for a single `term.write`. */drain(): string {+ this.heldSince = null;if (this.chunks.length === 0) return "";const text = this.chunks.join("");this.chunks = [];