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(ide): close workspaces when their final terminal leaves (#292)
Ruben Lütke8db7ae7ac7cc
diff --git a/jarvis/agentic_ide/session.py b/jarvis/agentic_ide/session.pyindex fd2e0693bc..1d149b4503 100644--- a/jarvis/agentic_ide/session.py+++ b/jarvis/agentic_ide/session.py@@ -6614,6 +6614,11 @@ class Registry:self._renumber(session)if resolved:await self._persist()+ if not session.terminals:+ # Save the empty pane list before closing so the previous+ # terminals cannot return through the workspace restore offer.+ await self._close_locked(session.id)+ await self._persist()logger.info("Agentic IDE: closed terminals {}",", ".join(term.name for term in resolved),diff --git a/tests/unit/agentic_ide/test_close_empty_workspace.py b/tests/unit/agentic_ide/test_close_empty_workspace.pynew file mode 100644index 0000000000..0a5499b1a6--- /dev/null+++ b/tests/unit/agentic_ide/test_close_empty_workspace.py@@ -0,0 +1,89 @@+"""Closing the final pane retires its workspace across registry entry points."""++from pathlib import Path++import pytest++from jarvis.agentic_ide import resume_store+from jarvis.agentic_ide import session as ide+from tests.fakes.fake_pty_manager import FakePtyManager+++def registry(monkeypatch: pytest.MonkeyPatch) -> ide.Registry:+ monkeypatch.setattr(ide, "agent_argv", lambda name: (f"/usr/bin/{name}",))+ return ide.Registry(pty_manager=FakePtyManager())+++async def test_final_close_selects_the_most_recent_survivor(+ registry: ide.Registry, tmp_path: Path+) -> None:+ first = await registry.start(str(tmp_path), [{"agent": "claude"}], name="First")+ second = await registry.start(str(tmp_path), [{"agent": "claude"}], name="Second")+ target = await registry.start(str(tmp_path), [{"agent": "claude"}], name="Target")+ await registry.activate(first.id)+ await registry.activate(target.id)++ await registry.close_terminal("T1", workspace_id=target.id)++ assert registry.get(target.id) is None+ assert registry.session is first+ assert registry.get(second.id) is second+ stored = resume_store.load()+ assert stored is not None+ assert stored.active_session_id == first.id+ assert {space.session_id for space in stored.workspaces} == {first.id, second.id}+++async def test_final_background_close_preserves_the_active_workspace(+ registry: ide.Registry, tmp_path: Path+) -> None:+ background = await registry.start(str(tmp_path), [{"agent": "claude"}], name="Background")+ front = await registry.start(str(tmp_path), [{"agent": "claude"}], name="Front")++ await registry.close_terminal("T1", workspace_id=background.id)++ assert registry.get(background.id) is None+ assert registry.session is front+ assert len(front.terminals) == 1++[email protected]("invalid_names", [[], ["missing", "T1"]])+async def test_batch_closing_every_pane_retires_the_workspace(+ registry: ide.Registry, tmp_path: Path, invalid_names: list[str]+) -> None:+ workspace = await registry.start(str(tmp_path), [{"agent": "claude"}] * 2)++ closed, failed = await registry.close_terminals(["T1", "T2", *invalid_names])++ assert len(closed) == 2+ assert len(failed) == len(invalid_names)+ assert registry.get(workspace.id) is None+ assert registry.session is None+ assert resume_store.load() is None+++async def test_empty_close_selection_does_not_close_a_workspace(+ registry: ide.Registry, tmp_path: Path+) -> None:+ workspace = await registry.start(str(tmp_path), [{"agent": "claude"}])++ assert await registry.close_terminals([]) == ([], [])++ assert registry.session is workspace+ assert len(workspace.terminals) == 1+++async def test_auto_close_preserves_other_closed_workspace_restore_points(+ registry: ide.Registry, tmp_path: Path+) -> None:+ remembered = await registry.start(str(tmp_path), [{"agent": "claude"}], name="Remembered")+ await registry.end(remembered.id)+ target = await registry.start(str(tmp_path), [{"agent": "claude"}], name="Target")++ await registry.close_terminal("T1", workspace_id=target.id)++ stored = resume_store.load()+ assert stored is not None+ assert [space.session_id for space in stored.workspaces] == [remembered.id]+ assert registry.session is Nonediff --git a/tests/unit/agentic_ide/test_pane_notifications.py b/tests/unit/agentic_ide/test_pane_notifications.pyindex d3398ca1b3..9edfb3fc63 100644--- a/tests/unit/agentic_ide/test_pane_notifications.py+++ b/tests/unit/agentic_ide/test_pane_notifications.py@@ -1025,7 +1025,9 @@ async def test_a_new_pane_never_inherits_the_closed_ones_entries(itself instead of leaving it to the next sweep."""watcher = notifications.watcher()- await registry.start(str(tmp_path), [{"agent": "claude", "name": "T1"}])+ await registry.start(+ str(tmp_path), [{"agent": "claude", "name": "T1"}, {"agent": "claude", "name": "T2"}]+ )first = await registry.attach("T1", 100, 30, _noop, _noop_exit)await _file_one(watcher, registry, first, start=100.0)diff --git a/tests/unit/agentic_ide/test_panes.py b/tests/unit/agentic_ide/test_panes.pyindex 411c5db9d8..52e7ba06a8 100644--- a/tests/unit/agentic_ide/test_panes.py+++ b/tests/unit/agentic_ide/test_panes.py@@ -245,14 +245,15 @@ async def test_closing_a_whole_column_repacks_the_columns(assert _layout(registry) == [("T1", 0, 0), ("T3", 1, 0)]-async def test_closing_the_last_pane_leaves_an_empty_workspace(+async def test_closing_the_last_pane_closes_the_workspace(registry: Registry, tmp_path: Path) -> None:- """Allowed on purpose: the grid then offers to open a fresh terminal."""- await _open(registry, tmp_path, 1)+ """Closing the final pane must not leave a blank workspace on screen."""+ session = await _open(registry, tmp_path, 1)await registry.close_terminal("T1")- assert registry.session is not None- assert registry.session.terminals == []+ assert registry.session is None+ assert registry.get(session.id) is None+ assert registry.active_id is Noneasync def test_closing_an_unknown_pane_names_the_real_ones(@@ -306,7 +307,7 @@ async def test_a_closed_pane_refuses_further_prompts(registry: Registry, tmp_patasync def test_a_reopened_call_sign_is_a_fresh_pane(registry: Registry, tmp_path: Path) -> None:"""Closing T1 and splitting again must not resurrect the old transcript."""- await _open(registry, tmp_path, 1)+ await _open(registry, tmp_path, 2)await registry.attach("T1", 80, 24, _noop, _noop_exit)registry.session.terminals[0].transcript.feed("old work\r\n")await registry.close_terminal("T1")diff --git a/tests/unit/agentic_ide/test_resume_session.py b/tests/unit/agentic_ide/test_resume_session.pyindex c132ac5bd8..9db05b597e 100644--- a/tests/unit/agentic_ide/test_resume_session.py+++ b/tests/unit/agentic_ide/test_resume_session.py@@ -274,7 +274,7 @@ async def test_closing_a_resumed_pane_does_not_resurrect_it(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("T1") is None, "and its pane must be gone"+ assert registry.session is None, "and its empty workspace must be gone"async def test_closing_the_workspace_does_not_resurrect_a_resumed_pane(