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): hold a rebuilt pane until its repaint has landed

rubenluetke10-beep6decdb7a73d0
diff --git a/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.test.tsx b/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.test.tsx
index f75dd3680d..42e05b33ba 100644
--- a/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.test.tsx
+++ b/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.test.tsx
@@ -174,7 +174,14 @@ vi.mock("./paneFileDrag", () => ({
vi.mock("@/lib/editActions", () => ({ attachTerminalBridge: () => undefined }));
vi.mock("@/lib/agenticIdeApi", () => ({ attachToTerminal: vi.fn() }));
-import { AgenticTerminal } from "./AgenticTerminal";
+import { AgenticTerminal, REBUILD_QUIET_MS } from "./AgenticTerminal";
+
+/**
+ * Past the quiet window a rebuilt pane waits out, plus the reveal frame behind
+ * it. Bound to the real constant so tuning the window cannot silently turn
+ * these assertions into "revealed eventually".
+ */
+const PAST_REBUILD = REBUILD_QUIET_MS + 40;
class ResizeObserverHarness implements ResizeObserver {
constructor(_callback: ResizeObserverCallback) {}
@@ -444,7 +451,7 @@ describe("AgenticTerminal layout", () => {
act(() => {
terminalHarness.writeCallbacks.shift()?.();
- vi.advanceTimersByTime(20);
+ vi.advanceTimersByTime(PAST_REBUILD);
});
expect(terminalHarness.scrollToBottom).toHaveBeenCalled();
@@ -490,7 +497,7 @@ describe("AgenticTerminal layout", () => {
act(() => {
terminalHarness.writeCallbacks.shift()?.();
- vi.advanceTimersByTime(20);
+ vi.advanceTimersByTime(PAST_REBUILD);
});
expect(terminalHarness.scrollToBottom).toHaveBeenCalled();
@@ -498,6 +505,82 @@ describe("AgenticTerminal layout", () => {
expect(region?.className).not.toContain("invisible");
});
+ it("stays hidden while the post-replay repaint is still arriving", () => {
+ // The replay is only half the rebuild: the server answers a truncated or
+ // re-based one by nudging the agent into painting its whole screen again
+ // (`SessionRegistry._nudge_repaint`), and that second screen lands AFTER
+ // the replay parsed. Revealing in between is what still put the repaint in
+ // front of the reader — a Codex pane opening on the top of its history and
+ // racing down — even with the replay curtain working exactly as designed.
+ vi.useFakeTimers();
+ render(
+ <AgenticTerminal
+ name="Dana"
+ displayName="Codex"
+ appearance="dark"
+ fontSize={13}
+ active
+ />,
+ );
+ const region = screen.getByTestId("agentic-terminal-host-Dana").parentElement;
+ act(() => vi.advanceTimersByTime(PAST_REBUILD));
+
+ terminalHarness.deferWrite = true;
+ act(() => {
+ terminalHarness.handlers.current?.onReplay?.("recorded session" as never);
+ terminalHarness.writeCallbacks.shift()?.();
+ });
+ expect(region?.className).toContain("invisible");
+
+ // The repaint arrives mid-window and restarts it — the pane keeps waiting
+ // rather than revealing on the schedule the replay alone would have set.
+ act(() => {
+ vi.advanceTimersByTime(REBUILD_QUIET_MS - 20);
+ terminalHarness.handlers.current?.onOutput?.("the repainted screen" as never);
+ vi.advanceTimersByTime(REBUILD_QUIET_MS - 20);
+ });
+ expect(region?.className).toContain("invisible");
+
+ act(() => vi.advanceTimersByTime(PAST_REBUILD));
+ expect(region?.className).not.toContain("invisible");
+ });
+
+ it("reveals a pane whose agent never stops talking", () => {
+ // The quiet window assumes the redraw ends. An agent streaming an answer
+ // never goes quiet, and waiting on it would trade a visible scroll for a
+ // pane that simply does not come back.
+ vi.useFakeTimers();
+ render(
+ <AgenticTerminal
+ name="Dana"
+ displayName="Codex"
+ appearance="dark"
+ fontSize={13}
+ active
+ />,
+ );
+ const region = screen.getByTestId("agentic-terminal-host-Dana").parentElement;
+ act(() => vi.advanceTimersByTime(PAST_REBUILD));
+
+ terminalHarness.deferWrite = true;
+ act(() => {
+ terminalHarness.handlers.current?.onReplay?.("recorded session" as never);
+ terminalHarness.writeCallbacks.shift()?.();
+ });
+ expect(region?.className).toContain("invisible");
+
+ act(() => {
+ // Chatty enough that the quiet window never once elapses.
+ for (let tick = 0; tick < 12; tick += 1) {
+ vi.advanceTimersByTime(REBUILD_QUIET_MS - 40);
+ terminalHarness.handlers.current?.onOutput?.("still working…" as never);
+ }
+ vi.advanceTimersByTime(40);
+ });
+
+ expect(region?.className).not.toContain("invisible");
+ });
+
it("restores a scrolled-back viewport after replaying a Codex terminal", () => {
vi.useFakeTimers();
terminalHarness.deferWrite = true;
@@ -555,13 +638,13 @@ describe("AgenticTerminal layout", () => {
act(() => {
terminalHarness.writeCallbacks.shift()?.();
- vi.advanceTimersByTime(20);
+ vi.advanceTimersByTime(PAST_REBUILD);
});
expect(region?.className).toContain("invisible");
act(() => {
terminalHarness.writeCallbacks.shift()?.();
- vi.advanceTimersByTime(20);
+ vi.advanceTimersByTime(PAST_REBUILD);
});
expect(region?.className).not.toContain("invisible");
});
@@ -607,12 +690,12 @@ describe("AgenticTerminal layout", () => {
);
expect(terminalHarness.writeCallbacks).toHaveLength(1);
- act(() => vi.advanceTimersByTime(20));
+ act(() => vi.advanceTimersByTime(PAST_REBUILD));
expect(region?.className).toContain("invisible");
act(() => {
terminalHarness.writeCallbacks.shift()?.();
- vi.advanceTimersByTime(20);
+ vi.advanceTimersByTime(PAST_REBUILD);
});
expect(region?.className).not.toContain("invisible");
});
diff --git a/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.tsx b/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.tsx
index 4cf590fabd..3cc3f82c7d 100644
--- a/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.tsx
+++ b/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.tsx
@@ -170,6 +170,39 @@ function restoreTerminalViewport(
term.scrollToLine(Math.min(viewport.line, buffer.baseY));
}
+/**
+ * How long a rebuilding pane must see NO further output before it is revealed.
+ *
+ * A replay is only HALF of a rebuild. Handing the recorded bytes over cannot
+ * repair a tail that lost its opening frame, nor one whose cursor moves belong
+ * to another geometry — so the server follows it by asking the agent to paint
+ * its interface again, with a one-row window-size change held for 80 ms and put
+ * back (`SessionRegistry._nudge_repaint`). That answer is a SECOND full screen
+ * and it lands AFTER the replay has parsed, which is where the pane used to be
+ * revealed: the repaint then played out in front of the reader (reported
+ * 2026-08-09 — every switch onto a Codex pane opened on the top of its history
+ * and raced down, with the replay curtain already in place and working).
+ *
+ * Only a normal-buffer CLI shows it. An alternate-screen agent (Claude Code)
+ * repaints over itself, so nothing travels and nothing is there to hide.
+ *
+ * So the reveal waits for the pane's output to go QUIET rather than for one
+ * write to finish. Comfortably past the nudge's own 80 ms plus a loopback round
+ * trip, and short enough that nobody can time it.
+ */
+export const REBUILD_QUIET_MS = 140;
+
+/**
+ * The longest a pane may stay hidden while it rebuilds, however talkative.
+ *
+ * The quiet window assumes the redraw ENDS. An agent midway through streaming
+ * an answer never goes quiet at all, and waiting on it would trade a visible
+ * scroll for a pane that simply does not come back. Past this the pane is shown
+ * mid-stream — which is what every other terminal in the app looks like while
+ * an agent is talking.
+ */
+export const REBUILD_SETTLE_MAX_MS = 450;
+
/**
* How long a call-sign may be — the same cap the backend enforces
* (`MAX_TERMINAL_NAME`), so the field stops where the save would have failed
@@ -463,6 +496,20 @@ export function AgenticTerminal({
// "B is still rebuilding", so an old callback could otherwise reveal B.
const replayGenerationRef = useRef(0);
const replayRevealFrameRef = useRef<number | undefined>(undefined);
+ /**
+ * Hold a finished rebuild back until the pane has stopped being redrawn.
+ *
+ * Owned by the connect effect, because only that scope sees every byte this
+ * pane draws. Reached from the stage-switch effect below as well: taking the
+ * stage also announces a new size, and an agent answers a size the same way
+ * it answers the server's nudge — by painting its whole screen again.
+ *
+ * Null before the terminal exists; the caller then reveals straight away,
+ * which is right for a pane that has nothing to rebuild yet.
+ */
+ const settleRebuildRef = useRef<
+ ((generation: number, reveal: () => void) => void) | null
+ >(null);
/**
* The delivery this pane is currently showing a receipt for, if any.
*
@@ -822,11 +869,75 @@ export function AgenticTerminal({
revealIfOnScreen();
};
+ /*
+ * Reveal a rebuilt pane on QUIET, not on one write having finished.
+ *
+ * Two timers, and the difference between them is the whole contract. The
+ * quiet timer is restarted by every chunk that arrives while the curtain is
+ * down, so the repaint the server asks for after a replay plays out behind
+ * it. The deadline is armed once and NEVER restarted by output — it is the
+ * promise that the pane comes back even if the agent never stops talking.
+ */
+ let quietTimer: number | undefined;
+ let deadlineTimer: number | undefined;
+ /** What to run once the rebuild has settled; null while none is pending. */
+ let settleReveal: (() => void) | null = null;
+ /** The rebuild being waited out, so a superseded one cannot reveal. */
+ let settlingFor = 0;
+
+ const clearSettleTimers = () => {
+ if (quietTimer !== undefined) window.clearTimeout(quietTimer);
+ if (deadlineTimer !== undefined) window.clearTimeout(deadlineTimer);
+ quietTimer = undefined;
+ deadlineTimer = undefined;
+ };
+
+ const finishSettle = () => {
+ const reveal = settleReveal;
+ const generation = settlingFor;
+ clearSettleTimers();
+ settlingFor = 0;
+ settleReveal = null;
+ // Before the guards, deliberately: a settle abandoned because the pane
+ // went away must not leave the curtain flag raised, or the next stage
+ // switch would refuse to lift a curtain nobody owns any more.
+ replayCurtainRef.current = false;
+ if (
+ disposed ||
+ !activeRef.current ||
+ generation !== replayGenerationRef.current
+ ) {
+ return;
+ }
+ reveal?.();
+ };
+
+ /** Something is still being drawn — push the reveal back one quiet window. */
+ const noteRebuildOutput = () => {
+ if (settlingFor === 0) return;
+ if (quietTimer !== undefined) window.clearTimeout(quietTimer);
+ quietTimer = window.setTimeout(finishSettle, REBUILD_QUIET_MS);
+ };
+
+ const settleRebuild = (generation: number, reveal: () => void) => {
+ if (disposed || generation !== replayGenerationRef.current) return;
+ clearSettleTimers();
+ settlingFor = generation;
+ settleReveal = reveal;
+ deadlineTimer = window.setTimeout(finishSettle, REBUILD_SETTLE_MAX_MS);
+ noteRebuildOutput();
+ };
+ settleRebuildRef.current = settleRebuild;
+
// 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.
const writeToPane = (text: string, afterWrite?: () => void) => {
if (!text) return;
+ // Anything drawn while a rebuild settles belongs to that rebuild. The
+ // viewport is deliberately NOT touched here — where the pane opens is
+ // the reveal's decision, and it restores what the reader was looking at.
+ noteRebuildOutput();
// The first byte is what retires the "starting" overlay — and it is taken
// HERE rather than at the socket, so a pane whose output is parked
// offscreen still counts as painted. It has a screen; nobody is looking
@@ -923,33 +1034,39 @@ export function AgenticTerminal({
// counts as the pane having painted.
writeToPane(text, () => {
if (generation !== replayGenerationRef.current) return;
- // Cleared unconditionally: a callback that fired while the pane was
- // away must not leave the stage-switch settle step refusing to lift
- // the curtain forever.
- replayCurtainRef.current = false;
- if (disposed || !activeRef.current) return;
+ if (disposed || !activeRef.current) {
+ // A callback that fired while the pane was away must not leave the
+ // stage-switch settle step refusing to lift the curtain forever.
+ replayCurtainRef.current = false;
+ return;
+ }
restoreTerminalViewport(term, replayViewport);
if (!curtain) {
+ replayCurtainRef.current = false;
if (preservedViewportRef.current === replayViewport) {
preservedViewportRef.current = null;
}
return;
}
- replayRevealFrameRef.current = requestAnimationFrame(() => {
- replayRevealFrameRef.current = undefined;
- if (
- disposed ||
- !activeRef.current ||
- generation !== replayGenerationRef.current
- ) {
- return;
- }
- restoreTerminalViewport(term, replayViewport);
- setTailReady(true);
- container.style.removeProperty("visibility");
- if (preservedViewportRef.current === replayViewport) {
- preservedViewportRef.current = null;
- }
+ // The bytes have parsed; the REPAINT they provoke has not arrived yet.
+ // Stay hidden until this pane stops being drawn — see REBUILD_QUIET_MS.
+ settleRebuild(generation, () => {
+ replayRevealFrameRef.current = requestAnimationFrame(() => {
+ replayRevealFrameRef.current = undefined;
+ if (
+ disposed ||
+ !activeRef.current ||
+ generation !== replayGenerationRef.current
+ ) {
+ return;
+ }
+ restoreTerminalViewport(term, replayViewport);
+ setTailReady(true);
+ container.style.removeProperty("visibility");
+ if (preservedViewportRef.current === replayViewport) {
+ preservedViewportRef.current = null;
+ }
+ });
});
});
};
@@ -1257,6 +1374,14 @@ export function AgenticTerminal({
replayRevealFrameRef.current = undefined;
}
container.style.removeProperty("visibility");
+ // A pending reveal would fire into a disposed terminal, and its timers
+ // would outlive the pane that armed them.
+ clearSettleTimers();
+ settleReveal = null;
+ settlingFor = 0;
+ if (settleRebuildRef.current === settleRebuild) {
+ settleRebuildRef.current = null;
+ }
// Before the terminal is disposed below: a deadline flush one tick later
// would write into it after it is gone.
cancelHoldTimer();
@@ -1347,13 +1472,21 @@ export function AgenticTerminal({
// A replay mid-rebuild keeps the curtain: lifting it here would show
// the rest of its history printing. Its own completion reveals the
// pane (see `replayToPane`).
- if (!replayCurtainRef.current) {
+ if (replayCurtainRef.current) return;
+ const reveal = () => {
+ restoreViewport();
setTailReady(true);
containerRef.current?.style.removeProperty("visibility");
if (preservedViewportRef.current === returningViewport) {
preservedViewportRef.current = null;
}
- }
+ };
+ // Taking the stage announces a new size, and an agent answers a size
+ // by painting its whole screen again — the same redraw the replay path
+ // waits out, arriving just as late. Reveal once this pane is quiet.
+ const settleFn = settleRebuildRef.current;
+ if (settleFn) settleFn(replayGenerationRef.current, reveal);
+ else reveal();
});
};
const afterFlush = () => {