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(desktop): reopen main window on repeated launch (#451)

Ruben Lütke9eb5c479c21c
diff --git a/docs/os-parity.md b/docs/os-parity.md
index 8d789b6bad..a31c1f56bc 100644
--- a/docs/os-parity.md
+++ b/docs/os-parity.md
@@ -77,6 +77,20 @@ red close, yellow minimize/Dock restore, green fullscreen/exit and Option-green
zoom in light and dark appearance, including a detached view and a reopened
main window. This Windows development host cannot qualify those native clicks.
+## Reopening the desktop with detached windows (2026-10-07, T2)
+
+A second launch reopens the main window when a detached view keeps the desktop
+process alive. It uses the same serialized creation path as the tray's Open
+action, preserving the running backend and detached views. A quitting process
+or a host without a desktop window loop still reports that no window can open.
+The recovery decision is shared across Windows, macOS and Linux; native window
+creation and each platform's frame controls are unchanged. Regression tests cover
+the focus HTTP route through launcher recovery, repeated opens, background mode,
+and native creation failure. Native macOS and Linux execution remains unverified.
+An isolated Windows WebView2 smoke closed main with a detached window alive,
+reopened it through the real focus handler and launcher recovery twice, and
+confirmed that exactly one main and the original detached window remained.
+
## Current cryptography and SSH channel validation (2026-10-01, T3)
Every architecture now requires cryptography >=50.0.2 and AsyncSSH >=2.24.0.
diff --git a/jarvis/ui/desktop_app.py b/jarvis/ui/desktop_app.py
index 7890ef6fa6..adf99cca73 100644
--- a/jarvis/ui/desktop_app.py
+++ b/jarvis/ui/desktop_app.py
@@ -5249,7 +5249,12 @@ class DesktopApp:
# being destroyed and then exit as if it had succeeded (2026-09-30).
return {"ok": False, "focused": False, "reason": "quitting"}
if self._window is None:
- if getattr(getattr(self, "_background", None), "keeper", None) is not None:
+ # A detached view also keeps the GUI loop alive after main closes.
+ # A second launch must reopen main just like the tray's Open action,
+ # instead of reporting this healthy process as a windowless hang.
+ if getattr(self, "_detached_windows", None) or getattr(
+ getattr(self, "_background", None), "keeper", None
+ ) is not None:
self._ensure_main_window()
if self._window is None:
return {"ok": False, "reason": "no_window"}
diff --git a/tests/unit/ui/test_desktop_detached_windows.py b/tests/unit/ui/test_desktop_detached_windows.py
index bf4b19ce2b..402fb04ab6 100644
--- a/tests/unit/ui/test_desktop_detached_windows.py
+++ b/tests/unit/ui/test_desktop_detached_windows.py
@@ -37,9 +37,13 @@ class _FakeWindow:
self.title = title
self.url = url
self.destroyed = False
+ self.shown = 0
self.evaluated: list[str] = []
self.events = SimpleNamespace(loaded=_List(), closed=_List(), closing=_List())
+ def show(self) -> None:
+ self.shown += 1
+
def destroy(self) -> None:
self.destroyed = True
@@ -317,6 +321,58 @@ def test_snapshot_lists_detached_views(monkeypatch) -> None:
# --- _ensure_main_window -----------------------------------------------------
[email protected]("view", ["agentic-ide", "chats", "appshot-editor"])
+def test_second_launch_reopens_main_while_a_detached_window_keeps_running(
+ monkeypatch, view,
+) -> None:
+ """The real focus route must recover a closed main without replacing its process."""
+ import sys
+
+ from jarvis.ui import desktop_app
+ from jarvis.ui.web import launcher
+
+ app = _app(monkeypatch)
+ secondary = _FakeWindow(app._detached_title(view))
+ app._detached_windows[view] = secondary
+ assert app._on_window_closing() is True
+ app._on_main_window_closed()
+ assert not app._user_requested_quit
+ created: list[_FakeWindow] = []
+ monkeypatch.setitem(sys.modules, "webview", _fake_webview(created))
+ monkeypatch.setattr(desktop_app, "window_needs_restore", lambda _title: False)
+ monkeypatch.setattr(desktop_app, "window_restores_maximized", lambda _title: False)
+ app._restore_overlay_for_visible_window = lambda: None
+ api = FastAPI()
+ api.state.desktop_app = app
+ app._install_focus_route(SimpleNamespace(app=api))
+
+ def unexpected_recovery(*_args, **_kwargs):
+ pytest.fail("A live detached window must not trigger stuck-process recovery")
+
+ with TestClient(api) as client:
+ def focus():
+ response = client.post("/api/window/focus")
+ assert response.json() == {"ok": True, "focused": True}
+ return desktop_app._focus_response_means_window_raised(response)
+
+ for _ in range(2):
+ assert launcher._recover_from_already_running(
+ desktop_app.SingleInstanceError("already running (pid=4242)"),
+ focus=focus,
+ read_meta=lambda: {"pid": 4242, "port": 47821},
+ health=lambda _port: True,
+ ask=unexpected_recovery,
+ terminate=unexpected_recovery,
+ acquire=unexpected_recovery,
+ ) is None
+
+ assert len(created) == 1
+ assert app._window is created[0]
+ assert created[0].shown == 2
+ assert app._detached_windows == {view: secondary}
+ assert not secondary.destroyed
+
+
@pytest.mark.parametrize("platform", ["darwin", "win32", "linux"])
def test_ensure_main_window_recreates_and_rehooks(monkeypatch, platform) -> None:
import sys