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): preserve interrupted pane recovery

Ruben Lütke5c769915743d
diff --git a/jarvis/agentic_ide/notifications.py b/jarvis/agentic_ide/notifications.py
index 786f26261b..594822143b 100644
--- a/jarvis/agentic_ide/notifications.py
+++ b/jarvis/agentic_ide/notifications.py
@@ -333,6 +333,10 @@ class _PaneWatch:
#: is the watcher's own bookkeeping — nothing else has any use for it.
digest: str = ""
changed_at: float = 0.0
+ #: Process identity whose screen the fingerprint describes. A pane can
+ #: survive several PTYs; reusing the previous one's digest fabricates a
+ #: still observation for the replacement process.
+ process_generation: int = 0
def _detail(term: Any) -> str:
@@ -440,8 +444,9 @@ class ActivityWatcher:
# movement can only be seen by comparing against the previous sweep —
# so the fingerprint is taken first and the answer is derived from it.
watch = self._panes.get(ident)
+ process_generation = int(getattr(term, "process_generation", 0))
digest = screen_digest(term)
- if watch is None:
+ if watch is None or watch.process_generation != process_generation:
# First sight. Nothing is filed: the pane may have been sitting
# finished for an hour before this watcher existed, and announcing
# that on startup would fill the bell with history.
@@ -464,6 +469,7 @@ class ActivityWatcher:
resume_needed=bool(getattr(term, "resume_continuation_needed", False)),
digest=digest,
changed_at=settled_at,
+ process_generation=process_generation,
)
self._panes[ident] = watch
self._checkpoint_resume_state(term, activity, watch, now)
@@ -539,14 +545,18 @@ class ActivityWatcher:
preserved while it waits at its prompt.
"""
if activity == "working":
- if getattr(term, "idle_seen", False):
- # It stood still and then moved again, so somebody put this pane
- # back to work and the offer to continue it is spent.
- term.continuation_pending = False
- # Otherwise this is the pane's CLI painting itself back onto the
- # screen after a restart — the exact seconds in which the offer is
- # needed, and where retracting it made the button report zero for
- # every restored pane, for ever (see `Terminal.idle_seen`).
+ instructed_here = getattr(term, "submit_generation", -1) == getattr(
+ term, "process_generation", 0
+ )
+ if not getattr(term, "idle_seen", False) and not instructed_here:
+ # This is the pane's CLI painting itself back onto the screen
+ # after a restart. Preserve both resume flags until this
+ # process has genuinely stood still once or receives a real
+ # instruction of its own.
+ return
+ # It stood still and then moved again, so somebody put this pane
+ # back to work and the offer to continue it is spent.
+ term.continuation_pending = False
self._set_resume_needed(term, watch, True)
return
if activity in {"asking", "failed"}:
diff --git a/jarvis/agentic_ide/session.py b/jarvis/agentic_ide/session.py
index 89f7aa5c36..14110dafb4 100644
--- a/jarvis/agentic_ide/session.py
+++ b/jarvis/agentic_ide/session.py
@@ -935,6 +935,14 @@ class Terminal:
# looks, never a single one), cleared on every spawn. Never persisted — it
# describes the process now running in the pane.
idle_seen: bool = False
+ # Monotonic identity for the process currently occupying this pane. The
+ # notification watcher outlives PTYs, so it uses this to discard the old
+ # process's screen fingerprint before interpreting a replacement process.
+ process_generation: int = 0
+ # The process generation that most recently received a real instruction.
+ # A startup repaint has no such stamp, even if the pane resumes an old
+ # conversation whose historical prompt count is non-zero.
+ submit_generation: int = -1
transcript: Transcript = field(default_factory=Transcript)
# The RAW output stream, kept so the next viewer can be handed the screen
# this pane is actually showing. Cleared on a fresh spawn, so what a viewer
@@ -2458,6 +2466,11 @@ class Registry:
if not term.resumed:
term.resume_continuation_needed = False
+ # Everything below belongs to a new process attempt. Reset this before
+ # spawning so neither early output nor a concurrent notification sweep
+ # can inherit the previous PTY's settled-screen evidence.
+ term.process_generation += 1
+ term.idle_seen = False
term.transcript.resize(cols, rows)
# A fresh process draws a fresh screen: anything the previous one left
# in the replay buffer belongs to a terminal that no longer exists, and
@@ -2577,7 +2590,6 @@ class Registry:
# And this process has not stood still yet, whatever the previous one
# did. Everything it is about to draw is a CLI painting itself, not an
# agent working — see the field.
- term.idle_seen = False
if term.resume is None and can_resume(term.agent):
# A CLI that cannot be told its session id (Codex): find out which
# one it just created, shortly from now.
@@ -2818,6 +2830,7 @@ class Registry:
# never goes through `send_prompt`, so without this hook the bell
# would stay silent for everybody who types their own prompts.
term.last_submit_at = term.last_input_at
+ term.submit_generation = term.process_generation
# And the pane's conversation may have just begun, which for most
# coding CLIs is the first moment its id exists on disk at all. A
# pane driven only by hand never goes through `send_prompt`, so
@@ -3467,6 +3480,7 @@ class Registry:
# way. Set even for a hard False: the text is in the pane's input box,
# and whatever it does next was still asked of it.
term.last_submit_at = term.last_prompt_at
+ term.submit_generation = term.process_generation
term.submitted = submitted
term.sent_multiline = multiline and submitted is True
history_entry = prompt_history.PromptHistoryEntry(
diff --git a/tests/unit/agentic_ide/test_pane_notifications.py b/tests/unit/agentic_ide/test_pane_notifications.py
index 6f4dfa16ee..7d18f76b33 100644
--- a/tests/unit/agentic_ide/test_pane_notifications.py
+++ b/tests/unit/agentic_ide/test_pane_notifications.py
@@ -150,7 +150,15 @@ def _quiet_since(term: Any, at: float) -> None:
term.last_input_at = None
-def _busy(watcher: Any, registry: Registry, term: Any, *, start: float, sweeps: int = 3) -> float:
+def _busy(
+ watcher: Any,
+ registry: Registry,
+ term: Any,
+ *,
+ start: float,
+ sweeps: int = 3,
+ tasked: bool = True,
+) -> float:
"""Drive a pane through ``sweeps`` sweeps of a MOVING screen.
A pane is busy because its picture keeps changing, so making one busy in a
@@ -163,7 +171,9 @@ def _busy(watcher: Any, registry: Registry, term: Any, *, start: float, sweeps:
while it is starting up, which is the case
`test_a_starting_cli_painting_itself_is_not_a_finished_job` covers.
"""
- term.last_submit_at = start - 0.1
+ if tasked:
+ term.last_submit_at = start - 0.1
+ term.submit_generation = term.process_generation
at = start
for step in range(sweeps):
at = start + step * notifications.SWEEP_INTERVAL_S
@@ -433,11 +443,39 @@ async def test_a_restored_pane_painting_itself_keeps_its_continue_offer(
term.continuation_pending = True
assert term.idle_seen is False, "a freshly spawned process has settled nothing"
- _busy(watcher, registry, term, start=100.0)
+ _busy(watcher, registry, term, start=100.0, tasked=False)
assert term.continuation_pending is True, "a CLI drawing itself is not the agent working"
+async def test_a_new_process_for_the_same_pane_discards_the_old_screen_observation(
+ registry: Registry, tmp_path: Path
+) -> None:
+ """A replacement PTY must not inherit the previous process's still screen."""
+ watcher = notifications.watcher()
+ _session, term = await _pane(registry, tmp_path)
+
+ _rest(watcher, registry, term, IDLE_SCREEN, at=100.0, emit=False)
+ assert term.idle_seen is True
+
+ term.continuation_pending = True
+ term.resume_continuation_needed = False
+ term.process_generation += 1
+ term.idle_seen = False
+
+ # A replacement CLI initially redraws the same prompt as its predecessor.
+ watcher.poll(registry, now=200.0, emit=False)
+ assert term.idle_seen is False
+ assert term.continuation_pending is True
+ assert term.resume_continuation_needed is False
+
+ term.transcript.clear()
+ _draw(term, BUSY_SCREEN)
+ watcher.poll(registry, now=200.0 + notifications.SWEEP_INTERVAL_S, emit=False)
+ assert term.continuation_pending is True
+ assert term.resume_continuation_needed is False
+
+
async def test_movement_after_the_pane_settled_does_retract_the_offer(
registry: Registry, tmp_path: Path
) -> None: