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): draw a replayed screen at the agent's size

rubenluetke10-beep4b3c687aa8db
diff --git a/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.geometry.test.tsx b/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.geometry.test.tsx
index c020b203f1..bd55ebc295 100644
--- a/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.geometry.test.tsx
+++ b/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.geometry.test.tsx
@@ -6,6 +6,7 @@ const harness = vi.hoisted(() => ({
terminal: null as Terminal | null,
handlers: null as null | {
onOutput(text: string): void;
+ onReplay(text: string, awaitRepaint?: boolean): void;
onGeometry(size: { cols: number; rows: number }): void;
},
size: { cols: 80, rows: 24 },
@@ -48,7 +49,9 @@ vi.mock("@/lib/terminalFont", async (importOriginal) => ({
syncTerminalFont: () => () => undefined,
}));
vi.mock("./paneSocket", () => ({
- openPaneSocket: (_options: unknown, handlers: typeof harness.handlers) => {
+ openPaneSocket: (options: { cols: number; rows: number }, handlers: typeof harness.handlers) => {
+ // The real socket reads the handshake size into its URL on connect.
+ void [options.cols, options.rows];
harness.handlers = handlers;
return { send: () => true, close() {} };
},
@@ -144,6 +147,72 @@ describe("pane geometry in the PTY output stream", () => {
expect(screenRows(term)[2]).toBe("Working");
});
+ /*
+ * Reported 2026-10-06: the window reloaded while the IDE was on the thread
+ * layout, so every pane of the grid behind it mounted in a display:none box
+ * and kept xterm's constructed 80x24. The server replays the agent's screen
+ * before it reports the size that screen was drawn at, and the replay was
+ * parsed into those 24 rows: every row below them landed on the last one,
+ * the status line over the prompt box. The size report then grew the grid to
+ * the agent's 40 rows with blank rows underneath, and nothing asked the
+ * agent to paint again, because the PTY already had that size.
+ */
+ const tallFrame = "\x1b[?1049h\x1b[2J\x1b[H" +
+ Array.from({ length: 36 }, (_, i) => `\x1b[${i + 1};1Hline ${i + 1}`).join("") +
+ "\x1b[38;1H" + "-".repeat(68) + "\x1b[39;1H> prompt\x1b[40;1H footer";
+
+ it.each([
+ ["mounted off the stage", false],
+ ["in a window too small to measure", true],
+ ] as const)("draws a replay at the agent's size when the pane mounted unmeasured (%s)", async (_label, active) => {
+ const { Terminal: RealTerminal } = await vi.importActual<typeof import("@xterm/xterm")>("@xterm/xterm");
+ const reference = new RealTerminal({ cols: 68, rows: 40, allowProposedApi: true });
+ const width = vi.spyOn(HTMLElement.prototype, "clientWidth", "get").mockReturnValue(0);
+ const height = vi.spyOn(HTMLElement.prototype, "clientHeight", "get").mockReturnValue(0);
+ try {
+ await flush(reference, tallFrame);
+ const view = render(pane(active));
+ const term = harness.terminal!;
+ term.options.windowsPty = { backend: "conpty" };
+ expect([term.cols, term.rows]).toEqual([80, 24]);
+ await act(async () => {
+ // The order the server sends them in: the screen, then its size.
+ harness.handlers!.onReplay(tallFrame);
+ harness.handlers!.onGeometry({ cols: 68, rows: 40 });
+ await flush(term);
+ });
+ expect([term.cols, term.rows]).toEqual([68, 40]);
+ expect(screenRows(term)).toEqual(screenRows(reference));
+
+ // Taking the stage at the same size keeps the screen as it is.
+ width.mockReturnValue(800);
+ height.mockReturnValue(500);
+ harness.size = { cols: 68, rows: 40 };
+ view.rerender(pane(true));
+ await act(async () => { await flush(term); });
+ expect(screenRows(term)).toEqual(screenRows(reference));
+ } finally {
+ reference.dispose();
+ }
+ });
+
+ it("keeps a measured hidden pane's old output at the size it already holds", async () => {
+ // Only a grid that never had a real size waits for the agent's: a pane
+ // that was measured drains what it holds first, then follows.
+ const view = render(pane(false));
+ const term = harness.terminal!;
+ await act(async () => {
+ harness.handlers!.onReplay(oldFrame);
+ harness.handlers!.onGeometry({ cols: 40, rows: 48 });
+ await flush(term);
+ });
+ expect([term.cols, term.rows]).toEqual([40, 48]);
+ expect(screenRows(term)[2]).toBe("Working");
+ view.rerender(pane(true));
+ await act(async () => { await flush(term); });
+ expect(screenRows(term)[2]).toBe("Working");
+ });
+
it.each([undefined, { backend: "conpty" as const }])(
"does not introduce a large gap when an old narrow frame is followed by a wider pane (%j)",
async (windowsPty) => {
diff --git a/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.tsx b/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.tsx
index f8eea93c15..a535e25f27 100644
--- a/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.tsx
+++ b/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.tsx
@@ -1212,6 +1212,22 @@ export function AgenticTerminal({
} catch {
/* not measured yet — the ResizeObserver below will fit */
}
+ /*
+ * Did this socket's handshake go out without a size (`UNMEASURED_SIZE`),
+ * with the server's report of the agent's real size still to come?
+ *
+ * The server replays the agent's screen BEFORE it sends that report, and
+ * the screen is addressed by row at the agent's size. Parsed into this
+ * grid first — xterm's constructed 80x24 when the pane mounted hidden or
+ * in a minimized window — every row below the 24th landed on the last one
+ * (the status line written over the prompt box), and the report then grew
+ * the grid with blank rows underneath. Nothing repaired it: the PTY
+ * already had the size the pane went on to ask for, so the agent was never
+ * asked to paint again (reported 2026-10-06, the window reloading while
+ * the IDE showed the thread layout). So output is held until the report
+ * arrives and drawn after the grid has taken it (see `onGeometry`).
+ */
+ let awaitingSizeReport = false;
const report = (status: PaneStatus, detail?: string) => {
statusRef.current = status;
@@ -1338,7 +1354,10 @@ export function AgenticTerminal({
return;
}
paneVisible = true;
- flushHeld(afterFlush);
+ // Held output waits for the size report (see `awaitingSizeReport`); its
+ // deadline flush is still armed, so waiting cannot freeze the pane.
+ if (awaitingSizeReport) afterFlush?.();
+ else flushHeld(afterFlush);
};
const parkPane = () => {
@@ -1500,7 +1519,7 @@ export function AgenticTerminal({
// at it. Cheap to call per chunk: React bails out on an unchanged value.
setPainted(true);
if (!paneVisible) recheckParked();
- if (paneVisible) {
+ if (paneVisible && !awaitingSizeReport) {
writeToTerminal(text, afterWrite);
return;
}
@@ -1571,7 +1590,10 @@ export function AgenticTerminal({
// callback, `setTailReady(false)` may not reach the DOM before xterm's
// write queue starts parsing. Hide the canvas host imperatively BEFORE
// reset/write; React still mirrors the curtain below for later renders.
- const curtain = paneVisible && activeRef.current;
+ // A replay waiting for the size report is held (see
+ // `awaitingSizeReport`), and the callback that would lift a curtain
+ // goes with it.
+ const curtain = paneVisible && !awaitingSizeReport && activeRef.current;
if (curtain) {
container.style.visibility = "hidden";
replayCurtainRef.current = true;
@@ -2052,6 +2074,9 @@ export function AgenticTerminal({
*/
let openedWithClaim = viewerMayOwn();
const connectSize = () => {
+ // Without a size the server answers with the agent's (see
+ // `awaitingSizeReport`), and output waits for that answer.
+ awaitingSizeReport = true;
if (!mountMeasured || !measurable()) return UNMEASURED_SIZE;
let proposed: { cols: number; rows: number } | undefined;
try {
@@ -2062,6 +2087,7 @@ export function AgenticTerminal({
const cols = proposed?.cols ?? term.cols;
const rows = proposed?.rows ?? term.rows;
if (!Number.isFinite(cols) || !Number.isFinite(rows)) return UNMEASURED_SIZE;
+ awaitingSizeReport = false;
// The same floors `applyResize` puts on the grid.
return {
cols: Math.max(cols, MIN_REAL_COLS),
@@ -2142,6 +2168,19 @@ export function AgenticTerminal({
/* the terminal is being torn down — nothing left to reconcile */
}
};
+ // The report a handshake without a size was waiting for. What this
+ // pane holds — the replayed screen and anything after it — was
+ // drawn at THIS size, so the grid takes it first (see
+ // `awaitingSizeReport`). Something already parsing was flushed
+ // early by the hold's deadline; it keeps the ordinary order below.
+ if (awaitingSizeReport) {
+ awaitingSizeReport = false;
+ if (parsing === 0) {
+ applyGeometry();
+ flushHeld();
+ return;
+ }
+ }
// A size frame belongs BETWEEN the output before and after it.
// xterm parses writes asynchronously, and a hidden workspace can
// still hold older output outside xterm. Resizing immediately made