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): repeat the repaint nudge until a full-screen agent redraws

rubenluetke10-beep04f4b42e6852
diff --git a/jarvis/agentic_ide/session.py b/jarvis/agentic_ide/session.py
index 44908908d8..e1972556f8 100644
--- a/jarvis/agentic_ide/session.py
+++ b/jarvis/agentic_ide/session.py
@@ -430,6 +430,19 @@ COLD_START_HOLD_MAX_S = 15.0
# short enough that nobody sees a pane one row short.
REPAINT_NUDGE_S = 0.08
+# A nudge is a request, and a busy agent may ignore it: measured against Claude
+# Code 2.1.283 on Windows (2026-09-28), 10 of 20 nudges sent while it worked
+# drew nothing, and a longer hold (0.3 s) or a width nudge did no better. A
+# viewer that re-joined on a cut replay then keeps empty rectangles wherever
+# the agent's screen does not change. So a full-screen agent's answer — the
+# whole-screen erase its repaint opens with — is waited for, and the nudge
+# repeated when none comes. Re-sending right away answered within two tries in
+# every one of 12 measured runs; five bound the cost for an agent that never
+# repaints this way.
+REPAINT_CONFIRM_S = 0.5
+REPAINT_NUDGE_ATTEMPTS = 5
+REPAINT_POLL_S = 0.05
+
# Bracketed paste. A TUI that has enabled it receives everything between these
# markers as ONE pasted block rather than as keystrokes, which is the only way
# a structured prompt survives the trip: a bare "\n" written to a PTY IS the
@@ -1898,6 +1911,9 @@ class Registry:
# references to tasks; without this set a hold could be collected
# mid-wait and its slot never given back.
self._cold_start_holds: set[asyncio.Task[None]] = set()
+ # The follow-ups checking that a repaint nudge was answered (see
+ # ``_confirm_repaint``), held for the same weak-reference reason.
+ self._repaint_checks: set[asyncio.Task[None]] = set()
# Whether panes may live in the PTY host (``jarvis.terminal.pty_host``)
# instead of this process. Off until the app turns it on through
# ``boot_restore``: a registry built by a test, a script or the CLI
@@ -4404,10 +4420,63 @@ class Registry:
Never fatal: a pane whose PTY refuses to resize is one whose screen
could not have been repaired anyway, and that must not cost the user
the reconnect itself.
+
+ A full-screen agent may let a nudge pass without redrawing (see
+ ``REPAINT_CONFIRM_S``), so for one the answer is checked in the
+ background and the nudge repeated — off the caller's path, because
+ the caller holds the registry lock every other pane's attach waits on.
+ """
+ clears_before = term.replay.clears
+ if not await self._resize_there_and_back(term, cols, rows):
+ return
+ if not term.replay.holds_screen:
+ # A line-mode CLI or a shell answers with no whole-screen erase at
+ # all; waiting for one would only nudge it four more times.
+ return
+ task = asyncio.get_running_loop().create_task(self._confirm_repaint(term, clears_before))
+ self._repaint_checks.add(task)
+ task.add_done_callback(self._repaint_checks.discard)
+
+ async def _confirm_repaint(self, term: Terminal, clears_before: int) -> None:
+ """Repeat the nudge until the agent's screen has really been redrawn.
+
+ Each retry uses the size the pane has NOW: a viewer may have resized it
+ meanwhile, and nudging back to the size captured earlier would undo
+ that. A new process in the pane ends the check — its first paint is
+ whole anyway.
"""
pty_id = term.pty_id
+ generation = term.process_generation
+ loop = asyncio.get_running_loop()
+ for attempt in range(1, REPAINT_NUDGE_ATTEMPTS + 1):
+ deadline = loop.time() + REPAINT_CONFIRM_S
+ while loop.time() < deadline:
+ if term.replay.clears != clears_before:
+ return
+ await asyncio.sleep(REPAINT_POLL_S)
+ if term.replay.clears != clears_before:
+ return
+ if term.pty_id != pty_id or term.process_generation != generation:
+ return
+ if not term.pty_cols or not term.pty_rows:
+ return
+ if attempt == REPAINT_NUDGE_ATTEMPTS:
+ break
+ clears_before = term.replay.clears
+ if not await self._resize_there_and_back(term, term.pty_cols, term.pty_rows):
+ return
+ logger.info(
+ "Agentic IDE: {} did not redraw after {} nudges; its pane may show gaps "
+ "until the agent next repaints",
+ term.name,
+ REPAINT_NUDGE_ATTEMPTS,
+ )
+
+ async def _resize_there_and_back(self, term: Terminal, cols: int, rows: int) -> bool:
+ """One nudge: the height one row short, then back. False if it failed."""
+ pty_id = term.pty_id
if not pty_id:
- return
+ return False
manager = self._manager()
try:
# The whole point of the nudge is a full repaint — which must read
@@ -4424,6 +4493,8 @@ class Registry:
term.last_resize_at = time.time()
except Exception as exc: # noqa: BLE001 - a stale screen beats a failed reconnect
logger.debug("Agentic IDE: could not nudge {} into a repaint: {}", term.name, exc)
+ return False
+ return True
def claim_viewer(
self,
diff --git a/jarvis/agentic_ide/transcript.py b/jarvis/agentic_ide/transcript.py
index c9029b9212..f0e14d8786 100644
--- a/jarvis/agentic_ide/transcript.py
+++ b/jarvis/agentic_ide/transcript.py
@@ -56,6 +56,8 @@ _PRIVATE_MODE_RE = re.compile(r"\x1b\[\?([0-9;]+)([hl])")
# after any byte, including between ``ESC[?10`` and ``00h``.
_PRIVATE_MODE_PARTIAL_RE = re.compile(r"\x1b(?:\[(?:\?(?:[0-9;]*))?)?$")
_PRIVATE_MODE_PARTIAL_MAX = 128
+#: ``ESC [ 2 J`` — erase the whole screen, the first thing a full repaint sends.
+_FULL_CLEAR = "\x1b[2J"
_DECORATION_CHARS = set("─│┌┐└┘├┤┬┴┼━┃╭╮╯╰═║╔╗╚╝╠╣╦╩╬▀▄█▌▐░▒▓▔▁·.-_=*#~ ")
_SPINNER_CHARS = set("|/\\-◐◓◑◒✻✽✢·✳✶⣿")
@@ -193,7 +195,9 @@ class ReplayBuffer:
Whoever replays a truncated buffer therefore has to ask the agent for a
fresh paint afterwards; :meth:`SessionRegistry.attach` does it with a
- window-size change, the one request every TUI answers with a full redraw.
+ window-size change, the one request every TUI answers with a full redraw —
+ usually. Claude Code 2.1.283 let half of them pass unanswered while busy
+ (measured 2026-09-28), so the answer is checked for, via :attr:`clears`.
**The modes are kept even when the bytes that set them are gone.** A CLI
negotiates what kind of terminal it is talking to exactly ONCE, in its first
@@ -230,11 +234,22 @@ class ReplayBuffer:
_modes: dict[str, bool] = field(default_factory=dict, init=False)
#: Incomplete private-mode prefix from the preceding PTY read.
_mode_scan_tail: str = field(default="", init=False)
+ #: How many whole-screen erases have gone past — a counter, never reset by
+ #: a rebase. A full repaint of a full-screen TUI starts with one, so this
+ #: rising is how the repaint nudge knows it was answered (see
+ #: ``SessionRegistry._confirm_repaint``).
+ clears: int = field(default=0, init=False)
+ #: The last bytes of the preceding read, in case it split an erase.
+ _clear_scan_tail: str = field(default="", init=False)
def feed(self, chunk: str) -> None:
if not chunk:
return
self._note_modes(chunk)
+ scanned = self._clear_scan_tail + chunk
+ # The tail is shorter than the sequence, so no erase is counted twice.
+ self.clears += scanned.count(_FULL_CLEAR)
+ self._clear_scan_tail = scanned[-(len(_FULL_CLEAR) - 1) :]
self._chunks.append(chunk)
self._size += len(chunk)
while self._size > self.limit and len(self._chunks) > 1:
@@ -264,6 +279,11 @@ class ReplayBuffer:
candidate if len(candidate) <= _PRIVATE_MODE_PARTIAL_MAX else ""
)
+ @property
+ def holds_screen(self) -> bool:
+ """Is the agent drawing on the alternate screen, i.e. a full-screen TUI?"""
+ return self._modes.get("1049", False)
+
def _mode_prologue(self) -> str:
"""The negotiation a truncated replay lost, re-stated in order."""
return "".join(f"\x1b[?{mode}{'h' if on else 'l'}" for mode, on in self._modes.items())
@@ -331,6 +351,7 @@ class ReplayBuffer:
self._open_escape = False
self._modes.clear()
self._mode_scan_tail = ""
+ self._clear_scan_tail = ""
__all__ = [
diff --git a/tests/unit/agentic_ide/test_session.py b/tests/unit/agentic_ide/test_session.py
index 263dcca107..9729c210d1 100644
--- a/tests/unit/agentic_ide/test_session.py
+++ b/tests/unit/agentic_ide/test_session.py
@@ -8,6 +8,7 @@ could interrupt, kill, or drive the keyboard shortcuts of a coding agent.
from __future__ import annotations
+import asyncio
import os
import sys
from pathlib import Path
@@ -347,6 +348,10 @@ async def test_a_geometry_change_rebases_an_intact_replay_and_repaints(
on_replay=_capture_replay,
)
+ # The agent answers the nudge with its full repaint.
+ await fake_pty.emit(pty, "\x1b[2J\x1b[HNEW FRAME")
+ await asyncio.gather(*registry._repaint_checks)
+
sizes = [(cols, rows) for tid, cols, rows in fake_pty.resizes if tid == pty]
restored = "".join(replayed)
assert "OLD STATUS ROW" not in restored
@@ -354,6 +359,94 @@ async def test_a_geometry_change_rebases_an_intact_replay_and_repaints(
assert sizes == [(100, 30), (100, 29), (100, 30)]
+async def _rejoin_cut_fullscreen_pane(
+ registry: Registry, fake_pty: FakePtyManager, tmp_path: Path
+) -> tuple[object, str]:
+ """A full-screen agent whose replay lost its start, re-joined at 80x24."""
+ session = await _open(registry, tmp_path, [{"agent": "claude"}])
+ term = session.terminals[0]
+ await registry.attach(term.name, 80, 24, _noop_output, _noop_exit)
+ pty = term.pty_id
+ term.replay.limit = 64
+ await fake_pty.emit(pty, "\x1b[?1049h\x1b[2J\x1b[Hthe frame with the prompt box")
+ await fake_pty.emit(pty, "\x1b[Kspinner" * 10)
+ assert term.replay.truncated
+ registry.detach(term.key, session.id)
+ fake_pty.resizes.clear()
+ await registry.attach(term.name, 80, 24, _noop_output, _noop_exit)
+ return term, pty
+
+
+async def test_an_ignored_repaint_nudge_is_sent_again(
+ registry: Registry,
+ fake_pty: FakePtyManager,
+ tmp_path: Path,
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ """A busy agent may let a nudge pass; the pane must not keep the gaps.
+
+ Claude Code 2.1.283 ignored half of the nudges sent while it worked
+ (2026-09-28). The re-joined viewer then showed empty rectangles wherever
+ the agent's screen did not change, next to panes that looked fine.
+ """
+ monkeypatch.setattr(session_mod, "REPAINT_CONFIRM_S", 0.05)
+ monkeypatch.setattr(session_mod, "REPAINT_POLL_S", 0.01)
+ plain_resize = FakePtyManager.resize
+
+ def answer_second_nudge(self: FakePtyManager, tid: str, cols: int, rows: int) -> bool:
+ # The first nudge goes unanswered; the second one gets the repaint.
+ done = plain_resize(self, tid, cols, rows)
+ if len(self.resizes) == 4:
+ asyncio.get_running_loop().create_task(
+ self.emit(tid, "\x1b[2J\x1b[Hthe whole frame again")
+ )
+ return done
+
+ monkeypatch.setattr(FakePtyManager, "resize", answer_second_nudge)
+ _term, pty = await _rejoin_cut_fullscreen_pane(registry, fake_pty, tmp_path)
+ await asyncio.gather(*registry._repaint_checks)
+
+ sizes = [(cols, rows) for tid, cols, rows in fake_pty.resizes if tid == pty]
+ assert sizes == [(80, 23), (80, 24), (80, 23), (80, 24)]
+
+
+async def test_repaint_nudges_stop_at_the_bound_and_leave_the_real_size(
+ registry: Registry,
+ fake_pty: FakePtyManager,
+ tmp_path: Path,
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ monkeypatch.setattr(session_mod, "REPAINT_CONFIRM_S", 0.02)
+ monkeypatch.setattr(session_mod, "REPAINT_POLL_S", 0.005)
+ _term, pty = await _rejoin_cut_fullscreen_pane(registry, fake_pty, tmp_path)
+
+ await asyncio.gather(*registry._repaint_checks)
+
+ sizes = [(cols, rows) for tid, cols, rows in fake_pty.resizes if tid == pty]
+ assert len(sizes) == 2 * session_mod.REPAINT_NUDGE_ATTEMPTS
+ assert sizes[-1] == (80, 24), "the pane must be left at the size it really is"
+
+
+async def test_a_line_mode_agent_is_nudged_once(
+ registry: Registry, fake_pty: FakePtyManager, tmp_path: Path
+) -> None:
+ """Without the alternate screen there is no whole-screen erase to wait for."""
+ session = await _open(registry, tmp_path, [{"agent": "claude"}])
+ term = session.terminals[0]
+ await registry.attach(term.name, 80, 24, _noop_output, _noop_exit)
+ pty = term.pty_id
+ term.replay.limit = 64
+ await fake_pty.emit(pty, "the first lines of a line-mode CLI")
+ await fake_pty.emit(pty, "line mode output " * 10)
+ assert term.replay.truncated
+ registry.detach(term.key, session.id)
+ fake_pty.resizes.clear()
+ await registry.attach(term.name, 80, 24, _noop_output, _noop_exit)
+
+ assert not registry._repaint_checks
+ assert [(c, r) for tid, c, r in fake_pty.resizes if tid == pty] == [(80, 23), (80, 24)]
+
+
async def test_a_crowded_grid_never_squeezes_the_agent_out_of_drawing(
registry: Registry, fake_pty: FakePtyManager, tmp_path: Path
) -> None:
diff --git a/tests/unit/agentic_ide/test_transcript.py b/tests/unit/agentic_ide/test_transcript.py
index f4f8d670ec..858cc2979a 100644
--- a/tests/unit/agentic_ide/test_transcript.py
+++ b/tests/unit/agentic_ide/test_transcript.py
@@ -328,3 +328,25 @@ def test_a_replay_forgets_the_modes_when_it_is_cleared() -> None:
buffer.feed("fresh")
assert buffer.text() == "fresh"
+
+
+def test_whole_screen_erases_are_counted_even_split_across_reads() -> None:
+ """The repaint nudge reads this counter to know its request was answered."""
+ buffer = ReplayBuffer()
+ buffer.feed("\x1b[?1049h\x1b[2J\x1b[Hframe")
+ assert buffer.clears == 1
+ buffer.feed("spinner\x1b[")
+ buffer.feed("2J\x1b[Hframe again")
+ assert buffer.clears == 2, "a PTY read may cut the erase after any byte"
+ buffer.rebase_for_resize()
+ assert buffer.clears == 2, "a rebase changes what is replayed, not what went past"
+
+
+def test_only_an_alternate_screen_agent_holds_the_screen() -> None:
+ buffer = ReplayBuffer()
+ buffer.feed("plain shell output")
+ assert buffer.holds_screen is False
+ buffer.feed("\x1b[?1049h")
+ assert buffer.holds_screen is True
+ buffer.feed("\x1b[?1049l")
+ assert buffer.holds_screen is False