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.

fix(agentic-ide): stop a pane parking its agent's screen behind a hidden window

Ruben Lütke88708716c33f
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.tsx
index 721b34d291..81d093ac27 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
@@ -199,6 +199,45 @@ describe("AgenticTerminal off-screen output", () => {
);
});
+ it("does not park while the whole document is hidden", () => {
+ // The window behind an editor, minimized, or a background tab: every
+ // element reports intersecting nothing, and showing the window again moves
+ // no geometry, so no further callback ever arrives to undo it. Parking on
+ // that verdict is what left freshly spawned panes black — for minutes on a
+ // chatty CLI, and indefinitely on one that printed its prompt and went
+ // quiet (2026-07-27).
+ const hidden = vi.spyOn(document, "hidden", "get").mockReturnValue(true);
+ mount();
+ act(() => harness.fire?.(false));
+
+ act(() => harness.handlers?.onOutput("the agent's opening screen"));
+ expect(harness.writes).toContain("the agent's opening screen");
+ hidden.mockRestore();
+ });
+
+ it("replays a parked pane when the window comes back", () => {
+ // Parked while the document was still visible (a pane genuinely scrolled
+ // out of the grid), then the app went behind another window and returned.
+ // No geometry changed across that, so the observer says nothing and the
+ // pane has to answer for itself.
+ mount();
+ act(() => harness.fire?.(false));
+ act(() => harness.handlers?.onOutput("held while away"));
+ expect(harness.writes).toEqual([]);
+
+ // On screen by measurement — jsdom reports a zero box otherwise, which
+ // would (correctly) read as "no area, still off screen".
+ vi.spyOn(Element.prototype, "getBoundingClientRect").mockReturnValue({
+ top: 10, bottom: 400, left: 10, right: 400, width: 390, height: 390,
+ x: 10, y: 10, toJSON: () => ({}),
+ } as DOMRect);
+
+ act(() => {
+ document.dispatchEvent(new Event("visibilitychange"));
+ });
+ expect(harness.writes).toEqual(["held while away"]);
+ });
+
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.tsx
index 5a397e7f39..d8fda36b09 100644
--- a/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.tsx
+++ b/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.tsx
@@ -79,13 +79,29 @@ import { robustPaste } from "@/lib/clipboard";
import { installPasteBridge } from "./terminalPaste";
import { createKeyEventChain } from "./terminalKeyChain";
import { installNewlineBridge } from "./terminalNewline";
-import { OffscreenBuffer } from "./offscreenBuffer";
+import {
+ boxOnScreen,
+ OffscreenBuffer,
+ OFFSCREEN_MARGIN_PX,
+} from "./offscreenBuffer";
import { installQuerySuppression } from "./terminalQueries";
import { PaneScrollbar } from "./PaneScrollbar";
import { openPaneSocket, type PaneSocket } from "./paneSocket";
export type PaneStatus = "connecting" | "live" | "exited" | "error";
+/**
+ * Is the whole document out of sight — window behind another, minimized, or in
+ * a background tab?
+ *
+ * Read through a function rather than inlined so a pane behaves the same in a
+ * test environment that ships no `document`, and so the two places that must
+ * agree about it cannot drift apart.
+ */
+function documentHidden(): boolean {
+ return typeof document !== "undefined" && document.hidden === true;
+}
+
/** A coding CLI a split may start, as offered by the pane's split menu. */
export interface SplitAgentChoice {
/** Backend id — "claude", "codex", "shell". */
@@ -439,6 +455,24 @@ export function AgenticTerminal({
if (held) term.write(held);
};
+ /**
+ * Un-park this pane if it is genuinely on screen — measured, not remembered.
+ *
+ * The observer below reports CHANGES, and a pane can be left parked in a
+ * state no change ever leads out of (see `boxOnScreen`). This is the way
+ * back, and it is called from the two moments that produce exactly that
+ * state: the document becoming visible again, and the pane being resized.
+ */
+ const revealIfOnScreen = () => {
+ if (paneVisible) return;
+ const box = container.getBoundingClientRect();
+ const viewport = {
+ width: window.innerWidth || 0,
+ height: window.innerHeight || 0,
+ };
+ if (boxOnScreen(box, viewport)) showPane();
+ };
+
// Everything this pane draws goes through here, not just the agent's
// stream: an exit banner written straight to xterm while output is parked
// would appear ABOVE the output it is supposed to follow.
@@ -492,6 +526,13 @@ export function AgenticTerminal({
return;
}
if (socket?.send({ t: "r", ...size })) sentSize = size;
+ // Resizing a pane is the other half of the un-park story. Maximizing one,
+ // dragging a seam, changing the font — all of them are a user opening up
+ // a pane to READ it, and the pane it opens must not be a parked one still
+ // holding its agent's screen. The measurement above already proved the
+ // container has area, so this only ever un-parks a pane that is really
+ // there; a pane genuinely off screen stays parked.
+ revealIfOnScreen();
};
resizeRef.current = sendResize;
@@ -620,18 +661,55 @@ export function AgenticTerminal({
io = new IntersectionObserver(
(entries) => {
const onScreen = entries[entries.length - 1]?.isIntersecting ?? true;
- if (onScreen) showPane();
- else paneVisible = false;
+ if (onScreen) {
+ showPane();
+ return;
+ }
+ // A hidden DOCUMENT is not an off-screen pane, and treating the two
+ // as one is what left panes black for minutes at a time. While the
+ // window is behind another one, minimized, or its tab in the
+ // background, EVERY element here reports intersecting nothing — and
+ // bringing the window back changes no geometry, so no further
+ // callback ever arrives to undo it. Parking on that verdict meant a
+ // pane opened while the user was looking elsewhere never drew again
+ // (measured 2026-07-27: a workspace spawned by voice came back with
+ // its new panes empty, and a chatty CLI took ~3 minutes to appear —
+ // exactly how long 256 KB of output takes to force the buffer out).
+ //
+ // Parking is also pointless in that state: a hidden document paints
+ // nothing, so there is no frame budget being defended. The whole
+ // reason this exists is panes competing for the main thread WHILE the
+ // user watches another one.
+ if (!documentHidden()) paneVisible = false;
},
- { rootMargin: "300px" },
+ { rootMargin: `${OFFSCREEN_MARGIN_PX}px` },
);
io.observe(container);
}
+ /*
+ * The window came back — check whether this pane is on screen now.
+ *
+ * The observer cannot answer this on its own: showing a window again moves
+ * neither geometry nor scroll position, which are the only things that make
+ * it recompute. Without this a pane parked while the app sat behind an
+ * editor stayed parked after the user switched back to it.
+ */
+ const onDocumentVisible = () => {
+ if (documentHidden()) return;
+ revealIfOnScreen();
+ };
+ if (typeof document !== "undefined") {
+ document.addEventListener("visibilitychange", onDocumentVisible);
+ }
+
return () => {
disposed = true;
if (resizeTimer !== undefined) window.clearTimeout(resizeTimer);
window.removeEventListener("resize", scheduleResize);
+ if (typeof document !== "undefined") {
+ document.removeEventListener("visibilitychange", onDocumentVisible);
+ }
ro.disconnect();
io?.disconnect();
disposePasteBridge();
diff --git a/jarvis/ui/web/frontend/src/components/agentic/offscreenBuffer.ts b/jarvis/ui/web/frontend/src/components/agentic/offscreenBuffer.ts
index a0caf67e24..a455b25437 100644
--- a/jarvis/ui/web/frontend/src/components/agentic/offscreenBuffer.ts
+++ b/jarvis/ui/web/frontend/src/components/agentic/offscreenBuffer.ts
@@ -41,6 +41,51 @@
*/
export const OFFSCREEN_LIMIT_CHARS = 256 * 1024;
+/**
+ * How far outside the window a pane still counts as worth drawing.
+ *
+ * Generous on purpose: a pane one flick of the wheel away catches up before it
+ * is looked at, so scrolling never shows a pane mid-write. Shared by the
+ * `IntersectionObserver` that watches a pane and by {@link boxOnScreen}, which
+ * answers the same question directly — the two must agree, or a pane parks by
+ * one rule and un-parks by another.
+ */
+export const OFFSCREEN_MARGIN_PX = 300;
+
+/**
+ * Is this box on screen right now, by the same rule the observer applies?
+ *
+ * An `IntersectionObserver` is the right tool for *changes* and the wrong one
+ * for *questions*: it only recomputes when geometry or scrolling moves, so
+ * there are states it will never report its way out of. The one that put empty
+ * rectangles in a live workspace (2026-07-27): while the document is HIDDEN —
+ * the app window behind another, minimized, or its tab in the background —
+ * every element reads as intersecting nothing, and the callback that says so
+ * is the last one delivered. Showing the window again changes no geometry, so
+ * nothing fires, and a pane that parked its agent's output in that moment
+ * keeps parking it forever. It comes back only once 256 KB have piled up
+ * ({@link OffscreenBuffer.full}), which for a chatty CLI is minutes and for a
+ * freshly started one that printed its prompt and went quiet is never.
+ *
+ * So the pane asks this instead at the two moments the observer cannot cover:
+ * when the document becomes visible again, and when the pane is resized.
+ */
+export function boxOnScreen(
+ box: { top: number; bottom: number; left: number; right: number; width: number; height: number },
+ viewport: { width: number; height: number },
+ margin: number = OFFSCREEN_MARGIN_PX,
+): boolean {
+ // A pane with no area intersects nothing — that is what an element being laid
+ // out, or hidden behind a maximized sibling, looks like.
+ if (box.width < 1 || box.height < 1) return false;
+ return (
+ box.bottom >= -margin &&
+ box.right >= -margin &&
+ box.top <= viewport.height + margin &&
+ box.left <= viewport.width + margin
+ );
+}
+
export class OffscreenBuffer {
private chunks: string[] = [];
private size = 0;