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(desktop): stop reloading a healthy window every time it is shown
rubenluetke10-beep1f66346e8b86
diff --git a/jarvis/ui/desktop_app.py b/jarvis/ui/desktop_app.pyindex 78e2e0a638..78cbbcfbec 100644--- a/jarvis/ui/desktop_app.py+++ b/jarvis/ui/desktop_app.py@@ -43,6 +43,10 @@ if TYPE_CHECKING:# is "Personal Jarvis Dev", so neither instance ever raises the other's window.WINDOW_TITLE = current_instance().display_name+# True while the WebView shows the app's own document — booted or still+# booting. A stale error body has no ``#root``. See ``_reload_window_if_stale``.+_SPA_DOCUMENT_PROBE = "document.getElementById('root') !== null"+# Direct ``python -m jarvis.ui.desktop_app`` entry points bypass the launcher,# so they need the same pythonw/PyInstaller stream repair here as well.ensure_standard_streams()@@ -6205,25 +6209,31 @@ class DesktopApp:rendered last. When the user hides the window for a while andthe FastAPI server later recovers, ``show()`` only un-hides thecached frame — including stale 4xx/5xx pages such as the bare- ``Internal Server Error`` body. Probing ``document.title`` lets- us recognise that the React app never booted and forces a fresh- navigation to the SPA root.+ ``Internal Server Error`` body. The SPA document always carries+ ``#root`` (from ``index.html``, before React even mounts); an error+ body never does, so its absence is what forces a fresh navigation.++ The probe used to look for "Jarvis" in ``document.title``, but the+ title has been the neutral "Assistant" since 2026-07-01, so EVERY+ show — a tray click, the orb, a click on the appshot card — reloaded+ a perfectly healthy window: the editor the card had just opened was+ wiped and a running voice call hung up."""if self._window is None:returnfrom loguru import loggertry:- title = self._window.evaluate_js("document.title")+ booted = self._window.evaluate_js(_SPA_DOCUMENT_PROBE)except Exception as exc: # noqa: BLE001- # A probe that ALWAYS fails looks identical to "the SPA never- # booted", so every show() reloads the window — the reload loop- # that reads as a flickering window at startup. Distinguishing a- # broken probe from a genuinely stale frame needs this line.- logger.debug("Staleness probe failed, assuming a stale frame: {}", exc)- title = None- if title and isinstance(title, str) and "Jarvis" in title:+ # A probe that fails says nothing about the page; reloading on it+ # would reload a healthy window on every show (the old loop that+ # read as a flickering window at startup), so keep what is there.+ logger.debug("Staleness probe failed; leaving the window as it is: {}", exc)+ return+ if booted is True:return+ logger.info("The window shows no app (stale error page); reloading it.")try:self._window.load_url(self._url())except Exception as exc: # noqa: BLE001diff --git a/tests/unit/ui/test_desktop_show_window.py b/tests/unit/ui/test_desktop_show_window.pyindex 1964be4d01..de1d4defee 100644--- a/tests/unit/ui/test_desktop_show_window.py+++ b/tests/unit/ui/test_desktop_show_window.py@@ -189,3 +189,70 @@ def test_launcher_focus_does_not_fall_back_to_a_quitting_window(assert desktop_app.focus_existing_instance_robust() is Falseassert raised == []+++class _ProbedWindow:+ """pywebview stand-in whose staleness probe answers with ``probe``."""++ def __init__(self, probe: object) -> None:+ self.probe = probe+ self.scripts: list[str] = []+ self.loaded: list[str] = []++ def evaluate_js(self, script: str) -> object:+ self.scripts.append(script)+ if isinstance(self.probe, Exception):+ raise self.probe+ return self.probe++ def load_url(self, url: str) -> None:+ self.loaded.append(url)+++def _probed_app(window: _ProbedWindow) -> DesktopApp:+ app = DesktopApp.__new__(DesktopApp)+ app._window = window # noqa: SLF001+ app._url = lambda: "http://127.0.0.1:47821/" # type: ignore[method-assign] # noqa: SLF001+ return app+++def test_showing_a_healthy_window_never_reloads_it() -> None:+ """Regression 2026-10-03: a click on the appshot card reloaded the app.++ The probe used to require "Jarvis" in ``document.title``; the title has+ been "Assistant" since July, so every show — tray, orb, appshot card —+ reloaded the window, wiping the editor the card had just opened and+ hanging up a running voice call.+ """+ window = _ProbedWindow(probe=True)+ _probed_app(window)._reload_window_if_stale() # noqa: SLF001++ assert window.loaded == []+ assert "title" not in window.scripts[0], "the title is not the app's identity"+++def test_a_stale_error_page_is_still_reloaded() -> None:+ window = _ProbedWindow(probe=False)+ _probed_app(window)._reload_window_if_stale() # noqa: SLF001++ assert window.loaded == ["http://127.0.0.1:47821/"]+++def test_a_failing_probe_leaves_the_window_alone() -> None:+ """A probe that throws knows nothing about the page; reloading on it+ reloaded a healthy window on every show."""+ window = _ProbedWindow(probe=RuntimeError("bridge not ready"))+ _probed_app(window)._reload_window_if_stale() # noqa: SLF001++ assert window.loaded == []+++def test_the_shipped_index_satisfies_the_probe() -> None:+ """The probe's marker must exist in the document the app actually serves."""+ from pathlib import Path++ from jarvis.ui import desktop_app++ index = Path(desktop_app.__file__).parent / "web" / "frontend" / "index.html"+ assert "root" in desktop_app._SPA_DOCUMENT_PROBE # noqa: SLF001+ assert 'id="root"' in index.read_text(encoding="utf-8")