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(ide): keep a reloaded pane hidden until its promised repaint lands

rubenluetke10-beepb2d8b758b0bb
diff --git a/jarvis/agentic_ide/session.py b/jarvis/agentic_ide/session.py
index 1d7cc0f213..5a9cc4d977 100644
--- a/jarvis/agentic_ide/session.py
+++ b/jarvis/agentic_ide/session.py
@@ -3795,6 +3795,11 @@ class Registry:
them. Omitting ``on_replay`` keeps the old single-channel behaviour, for
internal callers that consume bytes rather than paint them.
+ ``on_replay`` is called with ``repaint=True`` when the replay cannot
+ stand on its own and a full-screen agent has been asked to repaint: the
+ viewer then waits for that repaint's whole-screen erase before showing
+ the pane.
+
**This is also where a conversation is continued rather than restarted.**
A pane holding a resume handle launches its CLI with the arguments that
reopen that conversation; a pane without one starts fresh and keeps
@@ -3910,7 +3915,15 @@ class Registry:
# On the replay channel when the viewer offered one — see the
# docstring for what appending it to a screen that already had
# a copy of it looked like.
- await (on_replay or on_output)(replay)
+ if on_replay is not None and needs_repaint and term.replay.holds_screen:
+ # This replay alone cannot rebuild the screen, and the
+ # nudge below will be answered by a whole-screen erase —
+ # so the viewer is told to keep its curtain down until that
+ # erase arrives, instead of revealing the broken tail
+ # while a busy agent takes its time to repaint.
+ await on_replay(replay, repaint=True)
+ else:
+ await (on_replay or on_output)(replay)
if needs_repaint:
# Either the tail lost its opening frame, or its cursor moves
# belong to another geometry. Neither can rebuild this viewer.
diff --git a/jarvis/ui/web/agentic_ide_routes.py b/jarvis/ui/web/agentic_ide_routes.py
index 610beae69d..505941b45e 100644
--- a/jarvis/ui/web/agentic_ide_routes.py
+++ b/jarvis/ui/web/agentic_ide_routes.py
@@ -4366,7 +4366,7 @@ async def agentic_pty(ws: WebSocket, name: str) -> None:
except Exception: # noqa: BLE001, S110 - viewer gone; transcript keeps filling
pass
- async def on_replay(text: str) -> None:
+ async def on_replay(text: str, repaint: bool = False) -> None:
"""The screen this pane is re-joining, as the bytes that drew it.
Its own frame type rather than a large ``o``, because the viewer has to
@@ -4379,10 +4379,17 @@ async def agentic_pty(ws: WebSocket, name: str) -> None:
A viewer that does not know this frame simply ignores it and comes back
blank rather than scrambled, which is the better of the two failures and
only reachable by a client older than this server.
+
+ ``repaint`` says a whole-screen repaint has been requested and will
+ follow on the ordinary output channel; the viewer keeps the pane hidden
+ until it lands (older viewers ignore the extra field).
"""
+ frame: dict[str, object] = {"t": "replay", "d": text}
+ if repaint:
+ frame["repaint"] = True
async with send_lock:
try:
- await ws.send_json({"t": "replay", "d": text})
+ await ws.send_json(frame)
except Exception: # noqa: BLE001, S110 - viewer gone; transcript keeps filling
pass
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 a5800df8d3..ed3441bcf3 100644
--- a/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.test.tsx
+++ b/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.test.tsx
@@ -192,6 +192,8 @@ import {
CURTAIN_MAX_MS,
DRAG_REFIT_MS,
REBUILD_QUIET_MS,
+ REBUILD_SETTLE_MAX_MS,
+ REPAINT_WAIT_MAX_MS,
RESIZE_PARSE_WAIT_MS,
UNMEASURED_SIZE,
} from "./AgenticTerminal";
@@ -653,6 +655,71 @@ describe("AgenticTerminal layout", () => {
expect(region?.className).not.toContain("invisible");
});
+ it("waits for a promised repaint rather than showing the broken tail", () => {
+ // A replay the server marks as needing a repaint cannot rebuild the screen
+ // by itself. A busy agent may answer the repaint request late (the server
+ // repeats it after half a second), and revealing on quiet in between showed
+ // the cut-off tail — terminals badly formatted for a second after a reload.
+ vi.useFakeTimers();
+ render(
+ <AgenticTerminal
+ name="Dana"
+ displayName="Claude"
+ appearance="dark"
+ fontSize={13}
+ active
+ />,
+ );
+ const region = screen.getByTestId("agentic-terminal-host-Dana").parentElement;
+ act(() => vi.advanceTimersByTime(PAST_REBUILD));
+
+ terminalHarness.deferWrite = true;
+ act(() => {
+ // An older erase inside the replay itself is not the answer.
+ terminalHarness.handlers.current?.onReplay?.(
+ "\x1b[2Jcut-off tail" as never,
+ true as never,
+ );
+ terminalHarness.writeCallbacks.shift()?.();
+ });
+ act(() => vi.advanceTimersByTime(REBUILD_SETTLE_MAX_MS + 100));
+ expect(region?.className).toContain("invisible");
+
+ // The erase arrives split across two chunks; the quiet window follows it.
+ act(() => {
+ terminalHarness.handlers.current?.onOutput?.("\x1b[2" as never);
+ terminalHarness.handlers.current?.onOutput?.("Jthe repainted screen" as never);
+ });
+ expect(region?.className).toContain("invisible");
+ act(() => vi.advanceTimersByTime(PAST_REBUILD));
+ expect(region?.className).not.toContain("invisible");
+ });
+
+ it("shows the pane anyway when a promised repaint never comes", () => {
+ vi.useFakeTimers();
+ render(
+ <AgenticTerminal
+ name="Dana"
+ displayName="Claude"
+ 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?.("cut-off tail" as never, true as never);
+ terminalHarness.writeCallbacks.shift()?.();
+ });
+ act(() => vi.advanceTimersByTime(REPAINT_WAIT_MAX_MS - 50));
+ expect(region?.className).toContain("invisible");
+ act(() => vi.advanceTimersByTime(100));
+ 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
diff --git a/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.tsx b/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.tsx
index 5288d449a2..3495215f13 100644
--- a/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.tsx
+++ b/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.tsx
@@ -217,6 +217,24 @@ export const REBUILD_QUIET_MS = 140;
*/
export const REBUILD_SETTLE_MAX_MS = 450;
+/**
+ * How long a rebuild may wait for a repaint the server has promised.
+ *
+ * A replay whose front was cut (or that belongs to another geometry) cannot
+ * rebuild a full-screen agent's interface; the server says so on the replay
+ * frame and asks the agent to repaint, and that repaint opens with a
+ * whole-screen erase. Revealing on quiet alone showed the broken tail
+ * whenever the agent answered late — a busy Claude Code lets a repaint request
+ * pass and the server repeats it half a second later — which after a bundle
+ * reload, with every pane rebuilding at once, read as terminals badly
+ * formatted for about a second (reported 2026-09-29). So such a rebuild waits
+ * for the erase, bounded by this, and still under {@link CURTAIN_MAX_MS}.
+ */
+export const REPAINT_WAIT_MAX_MS = 1_400;
+
+/** The whole-screen erase a full-screen agent's repaint starts with. */
+const FULL_SCREEN_ERASE = "\x1b[2J";
+
/**
* The longest an active pane's surface may stay behind a curtain, full stop.
*
@@ -1275,6 +1293,26 @@ export function AgenticTerminal({
let settleReveal: (() => void) | null = null;
/** The rebuild being waited out, so a superseded one cannot reveal. */
let settlingFor = 0;
+ /**
+ * Is the current rebuild still waiting for the repaint's whole-screen
+ * erase (see {@link REPAINT_WAIT_MAX_MS})? Set by a replay that announced
+ * one, cleared by the erase arriving — which may happen before the replay
+ * has even finished parsing.
+ */
+ let repaintPending = false;
+ /** The last bytes of the preceding chunk, in case it split the erase. */
+ let eraseScanTail = "";
+
+ const noteRepaintOutput = (text: string) => {
+ if (!repaintPending) return;
+ const scanned = eraseScanTail + text;
+ if (scanned.includes(FULL_SCREEN_ERASE)) {
+ repaintPending = false;
+ eraseScanTail = "";
+ return;
+ }
+ eraseScanTail = scanned.slice(-(FULL_SCREEN_ERASE.length - 1));
+ };
const clearSettleTimers = () => {
if (quietTimer !== undefined) window.clearTimeout(quietTimer);
@@ -1289,6 +1327,8 @@ export function AgenticTerminal({
clearSettleTimers();
settlingFor = 0;
settleReveal = null;
+ repaintPending = false;
+ eraseScanTail = "";
// 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.
@@ -1307,6 +1347,10 @@ export function AgenticTerminal({
const noteRebuildOutput = () => {
if (settlingFor === 0) return;
if (quietTimer !== undefined) window.clearTimeout(quietTimer);
+ quietTimer = undefined;
+ // Quiet proves nothing while the promised repaint has not started: the
+ // agent may simply not have answered yet. Only the deadline runs then.
+ if (repaintPending) return;
quietTimer = window.setTimeout(finishSettle, REBUILD_QUIET_MS);
};
@@ -1315,7 +1359,10 @@ export function AgenticTerminal({
clearSettleTimers();
settlingFor = generation;
settleReveal = reveal;
- deadlineTimer = window.setTimeout(finishSettle, REBUILD_SETTLE_MAX_MS);
+ deadlineTimer = window.setTimeout(
+ finishSettle,
+ repaintPending ? REPAINT_WAIT_MAX_MS : REBUILD_SETTLE_MAX_MS,
+ );
noteRebuildOutput();
};
settleRebuildRef.current = settleRebuild;
@@ -1328,6 +1375,7 @@ export function AgenticTerminal({
// 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.
+ noteRepaintOutput(text);
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
@@ -1381,8 +1429,11 @@ export function AgenticTerminal({
* the agent negotiated (alternate screen, mouse tracking), and those have
* to start from a known state or the pane inherits half of the old one.
*/
- const replayToPane = (text: string) => {
+ const replayToPane = (text: string, awaitRepaint = false) => {
if (!text) return;
+ // A newer replay replaces whatever an older one was waiting for.
+ repaintPending = false;
+ eraseScanTail = "";
const replayViewport =
preservedViewportRef.current ?? captureTerminalViewport(term);
if (replayViewport) preservedViewportRef.current = replayViewport;
@@ -1461,6 +1512,12 @@ export function AgenticTerminal({
});
});
});
+ // Armed only AFTER the replay went in: its own bytes may well contain
+ // an older erase, and that must not count as the repaint's answer.
+ // Output from here on is live, so the erase it waits for can arrive
+ // before the replay has finished parsing — the settle then starts on
+ // an ordinary quiet window.
+ if (curtain && awaitRepaint) repaintPending = true;
};
/*
@@ -1756,7 +1813,7 @@ export function AgenticTerminal({
requestAnimationFrame(() => sendResize());
},
onOutput: (text) => writeToPane(text),
- onReplay: (text) => replayToPane(text),
+ onReplay: (text, awaitRepaint) => replayToPane(text, awaitRepaint),
/**
* The agent is in a different size than this pane asked for — follow it.
*
diff --git a/jarvis/ui/web/frontend/src/components/agentic/paneSocket.test.ts b/jarvis/ui/web/frontend/src/components/agentic/paneSocket.test.ts
index cd69af3302..ac75e12b00 100644
--- a/jarvis/ui/web/frontend/src/components/agentic/paneSocket.test.ts
+++ b/jarvis/ui/web/frontend/src/components/agentic/paneSocket.test.ts
@@ -156,7 +156,7 @@ describe("openPaneSocket", () => {
// interleave into unreadable text (2026-07-29).
MockWebSocket.last!.deliver({ t: "replay", d: "\x1b[?1049h# the screen" });
- expect(cb.onReplay).toHaveBeenCalledWith("\x1b[?1049h# the screen");
+ expect(cb.onReplay).toHaveBeenCalledWith("\x1b[?1049h# the screen", false);
expect(cb.onOutput).not.toHaveBeenCalled();
MockWebSocket.last!.deliver({ t: "o", d: "live" });
@@ -165,6 +165,17 @@ describe("openPaneSocket", () => {
socket.close();
});
+ it("passes on that a replay is waiting for a repaint", () => {
+ const cb = handlers();
+ const socket = openPaneSocket({ name: "Mika", cols: 80, rows: 24 }, cb);
+ MockWebSocket.last!.fire("open");
+
+ MockWebSocket.last!.deliver({ t: "replay", d: "tail", repaint: true });
+
+ expect(cb.onReplay).toHaveBeenCalledWith("tail", true);
+ socket.close();
+ });
+
it("gives up when the pane is no longer part of the open workspace", async () => {
const cb = handlers();
const socket = openPaneSocket({ name: "Ghost", 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.ts
index 11c086ce43..2dd795a4a1 100644
--- a/jarvis/ui/web/frontend/src/components/agentic/paneSocket.ts
+++ b/jarvis/ui/web/frontend/src/components/agentic/paneSocket.ts
@@ -205,8 +205,14 @@ export interface PaneSocketHandlers {
* The implementation therefore has exactly one obligation — reset the
* terminal before writing this — and it is required rather than optional so
* that a new pane cannot quietly forget it.
+ *
+ * `awaitRepaint` means the replay cannot rebuild the screen by itself (its
+ * front was cut, or it belongs to another geometry) and the server has asked
+ * the full-screen agent to repaint: that repaint starts with a whole-screen
+ * erase on the ordinary output channel, and the pane should stay hidden
+ * until it arrives.
*/
- onReplay: (text: string) => void;
+ onReplay: (text: string, awaitRepaint?: boolean) => void;
/**
* The agent is attached — freshly started, resumed, or re-joined.
*
@@ -497,6 +503,7 @@ export function openPaneSocket(
last_prompt_preview?: string;
cols?: number;
rows?: number;
+ repaint?: boolean;
};
try {
msg = JSON.parse((ev as MessageEvent).data as string);
@@ -506,7 +513,7 @@ export function openPaneSocket(
if (msg.t === "o") {
handlers.onOutput(msg.d ?? "");
} else if (msg.t === "replay") {
- handlers.onReplay(msg.d ?? "");
+ handlers.onReplay(msg.d ?? "", msg.repaint === true);
} else if (msg.t === "ready") {
// A live handshake also clears the auth streak: whatever credential
// this attempt used, it worked.
diff --git a/tests/unit/agentic_ide/test_replay_channel.py b/tests/unit/agentic_ide/test_replay_channel.py
index b6e8493665..dce17cef36 100644
--- a/tests/unit/agentic_ide/test_replay_channel.py
+++ b/tests/unit/agentic_ide/test_replay_channel.py
@@ -48,12 +48,14 @@ class Viewer:
def __init__(self) -> None:
self.output: list[str] = []
self.replay: list[str] = []
+ self.repaint_flags: list[bool] = []
async def on_output(self, text: str) -> None:
self.output.append(text)
- async def on_replay(self, text: str) -> None:
+ async def on_replay(self, text: str, repaint: bool = False) -> None:
self.replay.append(text)
+ self.repaint_flags.append(repaint)
async def _running_pane(pool: FakePtyManager, folder: Path): # noqa: ANN202 - internal fixture
@@ -101,6 +103,51 @@ async def test_a_rejoined_screen_arrives_as_a_replay(
)
+async def test_a_self_sufficient_replay_promises_no_repaint(
+ pool: FakePtyManager, tmp_path: Path
+) -> None:
+ """A whole, same-size replay rebuilds the screen alone; nothing is awaited."""
+ registry, session, term = await _running_pane(pool, tmp_path)
+ back = Viewer()
+
+ await registry.attach(
+ term.key,
+ 80,
+ 24,
+ back.on_output,
+ _gone,
+ workspace_id=session.id,
+ on_replay=back.on_replay,
+ )
+
+ assert back.repaint_flags == [False]
+
+
+async def test_a_replay_at_another_size_promises_a_repaint(
+ pool: FakePtyManager, tmp_path: Path
+) -> None:
+ """The viewer is told to wait for the repaint a stale geometry needs.
+
+ Without the promise the viewer revealed on quiet, and a busy agent that
+ answered the repaint request late left the pane showing a broken screen
+ for about a second after every bundle reload (2026-09-29).
+ """
+ registry, session, term = await _running_pane(pool, tmp_path)
+ back = Viewer()
+
+ await registry.attach(
+ term.key,
+ 100,
+ 30,
+ back.on_output,
+ _gone,
+ workspace_id=session.id,
+ on_replay=back.on_replay,
+ )
+
+ assert back.repaint_flags == [True]
+
+
async def test_live_output_after_a_rejoin_is_still_output(
pool: FakePtyManager, tmp_path: Path
) -> None:
diff --git a/tests/unit/agentic_ide/test_session.py b/tests/unit/agentic_ide/test_session.py
index fe07316bc6..e746ba989e 100644
--- a/tests/unit/agentic_ide/test_session.py
+++ b/tests/unit/agentic_ide/test_session.py
@@ -335,7 +335,7 @@ async def test_a_geometry_change_rebases_an_intact_replay_and_repaints(
replayed: list[str] = []
- async def _capture_replay(text: str) -> None:
+ async def _capture_replay(text: str, repaint: bool = False) -> None:
replayed.append(text)
fake_pty.resizes.clear()