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.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
fix(agentic-ide): never resurrect a pane that was stopped on purpose
Ruben Lütke25287fdd986c
diff --git a/jarvis/agentic_ide/session.py b/jarvis/agentic_ide/session.pyindex 27dc184f9f..f8ba2ec14b 100644--- a/jarvis/agentic_ide/session.py+++ b/jarvis/agentic_ide/session.py@@ -282,6 +282,12 @@ class Terminal:slot: int = 0status: Status = "pending"pty_id: str | None = None+ # Set just before this pane's agent is killed on purpose (viewer gone, pane+ # closed, workspace closed). A killed process reports a failure exit exactly+ # like a crashed one, so without this the resume self-healing in `attach`+ # would helpfully restart an agent somebody had just stopped — and it would+ # then run on unwatched, which is the whole thing the kill prevents.+ stopping: bool = Falseexit_code: int | None = Noneerror: str = ""started_at: float | None = None@@ -670,6 +676,8 @@ class Registry:if forget:await self._forget()manager = self._pty+ for term in session.terminals:+ term.stopping = True # deliberate kills, not crashed resumesif manager is not None:for term in session.terminals:if term.pty_id:@@ -757,6 +765,8 @@ class Registry:term.resume = mintedterm.transcript.resize(cols, rows)+ # This pane is wanted again, so the last deliberate kill is history.+ term.stopping = False# Monotonic: a wall clock can jump (NTP, a laptop waking up) and would# then mis-measure how long the agent survived.spawned_at = time.monotonic()@@ -772,9 +782,16 @@ class Registry:term.pty_id = Nonedied_young = time.monotonic() - spawned_at < RESUME_FAILED_WINDOW_S# Only a FAILED early exit is blamed on the resume. Quitting an- # agent normally exits 0, and restarting a pane the user just closed- # would be its own bug.- if term.resumed and not recovered and died_young and code != 0:+ # agent normally exits 0, and a pane we killed ourselves reports a+ # failure exit that looks identical to a crash — restarting either+ # of those would be its own bug.+ if (+ term.resumed+ and not term.stopping+ and not recovered+ and died_young+ and code != 0+ ):recovered = Truelogger.warning("Agentic IDE: {} could not continue its previous "@@ -898,6 +915,10 @@ class Registry:term = session.find(key)if term is None or not term.pty_id:return+ # Announce the kill before making it, or the exit it causes reads as a+ # crashed resume and the pane gets helpfully restarted behind the back+ # of the person who just closed it.+ term.stopping = Trueself._manager().close(term.pty_id)term.pty_id = Noneif term.status == "live":@@ -1052,6 +1073,7 @@ class Registry:known = ", ".join(t.name for t in session.terminals) or "none"raise SessionError(f"No terminal called {wanted!r}. Running: {known}.")+ term.stopping = True # a deliberate kill, not a crashed resumeif term.pty_id and self._pty is not None:try:self._pty.close(term.pty_id)diff --git a/tests/unit/agentic_ide/test_resume_session.py b/tests/unit/agentic_ide/test_resume_session.pyindex 782fec3bc9..0eb5f9fa8f 100644--- a/tests/unit/agentic_ide/test_resume_session.py+++ b/tests/unit/agentic_ide/test_resume_session.py@@ -151,6 +151,33 @@ async def test_a_clean_exit_after_a_resume_is_not_second_guessed(assert registry.session.find("Mika").status == "exited"+async def test_closing_a_resumed_pane_does_not_resurrect_it(+ registry: ide.Registry, fake_pty: FakePtyManager, tmp_path: Path+) -> None:+ """The trap the self-healing walks into if it is not told about the kill.++ Stopping a pane kills its agent, and a killed process reports a failure exit+ that looks exactly like a crashed resume. Without knowing the kill was+ deliberate, the recovery would restart an agent the user had just closed —+ and it would then run on with nobody watching, which is precisely what+ stopping it prevents.+ """+ await registry.start(str(tmp_path), [{"agent": "claude", "name": "Mika"}])+ registry.session.find("Mika").resume = ResumeHandle(+ kind="claude_session", id="fine", captured_at=1.0+ )+ await registry.attach("Mika", 80, 24, _noop, _noop_exit)+ assert registry.session.find("Mika").resumed is True+ spawns_before = len(fake_pty.spawns)++ # The browser tab closed a second after the pane came back.+ registry.detach("Mika")+ await fake_pty.spawns[-1]["on_closed"]("fake-pty-1", 1)++ assert len(fake_pty.spawns) == spawns_before, "the agent must stay stopped"+ assert registry.session.find("Mika").status == "exited"++async def test_a_late_crash_is_reported_as_a_crash(registry: ide.Registry,fake_pty: FakePtyManager,