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(windows): stop letting any interpreter claim the Start-Menu shortcut
Harald4dd6d28d8abe
diff --git a/jarvis/ui/desktop_app.py b/jarvis/ui/desktop_app.pyindex ef34036557..6ac309d0ef 100644--- a/jarvis/ui/desktop_app.py+++ b/jarvis/ui/desktop_app.py@@ -44,7 +44,13 @@ if sys.platform == "win32":try:from jarvis.ui.icon_utils import ensure_windows_app_identity- ensure_windows_app_identity()+ # No shortcut write on the import path: a headless boot, `jarvis <group>`+ # and the test suite all import this module, and an import is no promise+ # of a window. Rewriting the Start-Menu entry from here pointed it at+ # whichever interpreter imported the module last — silently killing the+ # Windows Search launch when that interpreter had no pywebview. The+ # entry is claimed where a window is actually created (launcher.py).+ ensure_windows_app_identity(write_shortcut=False)except Exception: # noqa: S110# Taskbar-icon grouping is cosmetic and Windows-only; failing here must# not stop the app from starting on any other OS.diff --git a/jarvis/ui/icon_utils.py b/jarvis/ui/icon_utils.pyindex 4fd6b73667..a9bdc479a2 100644--- a/jarvis/ui/icon_utils.py+++ b/jarvis/ui/icon_utils.py@@ -142,6 +142,31 @@ def _pythonw_executable() -> Path | None:return exe if exe.exists() else None+def _interpreter_can_open_a_window() -> bool:+ """Does the RUNNING interpreter have the toolkit the desktop window needs?++ The Start-Menu shortcut is written against ``sys.executable``, so it is only+ a valid launch target if that interpreter can actually open the window.+ Guarding on pywebview is what keeps a foreign interpreter out of the+ shortcut: the identity call sits on an import path that headless runs, CLI+ commands and stray virtualenvs all reach, and whichever one ran last used to+ win. Repoint the shortcut at a python without pywebview and the Start-Menu+ entry dies silently — ``pythonw`` has no console, so the ImportError goes+ nowhere and the app simply never appears (live forensic 2026-08-16: a+ ``--headless`` run from an unrelated venv rewrote the entry, after which+ Windows Search launched a window-less interpreter and nothing happened).++ ``find_spec`` only resolves the module, it never imports pywebview — this+ runs on the boot critical path (AP-26).+ """+ import importlib.util++ try:+ return importlib.util.find_spec("webview") is not None+ except (ImportError, ValueError): # broken/partial install+ return False++def _replace_exe_icon(exe_path: Path, ico_path: Path) -> bool:"""Overwrite ``exe_path``'s embedded application icon with ``ico_path``.@@ -602,6 +627,17 @@ def ensure_start_menu_shortcut(lnk = programs / START_MENU_SHORTCUT_NAMEiid = pywintypes.IID(_IID_IPROPERTYSTORE)+ if not _interpreter_can_open_a_window():+ # This interpreter cannot start the desktop app, so it must not become+ # the shortcut's target. Leave whatever is there — a working entry from+ # the installer or from a real desktop run — strictly alone.+ logger.debug(+ "Start-Menu shortcut left untouched: {} has no pywebview and would "+ "be a dead launch target",+ pythonw,+ )+ return lnk.is_file()+# Idempotent BUT self-healing: leave an existing shortcut alone ONLY if it# still carries this AUMID *and* its icon + target resolve to real files.#@@ -661,7 +697,9 @@ def ensure_start_menu_shortcut(return False-def ensure_windows_app_identity(app_id: str = APP_USER_MODEL_ID) -> bool:+def ensure_windows_app_identity(+ app_id: str = APP_USER_MODEL_ID, *, write_shortcut: bool = True+) -> bool:"""Pin a stable Windows app identity for taskbar grouping AND name.Three layers, each a different shell surface:@@ -679,6 +717,12 @@ def ensure_windows_app_identity(app_id: str = APP_USER_MODEL_ID) -> bool:Must run before the first window is created (idempotent across the desktop,orb and overlay processes, which all call this early). The return valuereflects only step 1; steps 2 and 3 are best-effort side effects.++ ``write_shortcut=False`` keeps layers 1 and 3 and skips layer 2. Callers on+ an import path use it: importing ``jarvis.ui.desktop_app`` (which a headless+ boot, a CLI command and the test suite all do) must not rewrite the user's+ Start-Menu entry, because at import time nothing yet says this process will+ ever show a window. Only a run that really opens one may claim the entry."""if sys.platform != "win32":return False@@ -687,7 +731,8 @@ def ensure_windows_app_identity(app_id: str = APP_USER_MODEL_ID) -> bool:# Name the taskbar button (shortcut) + the toast identity (registry). Both# best-effort and must be in place before the AUMID is set + the window# appears, so Explorer resolves them on first button creation.- ensure_start_menu_shortcut(aumid=app_id, icon_path=ico_arg)+ if write_shortcut:+ ensure_start_menu_shortcut(aumid=app_id, icon_path=ico_arg)register_windows_app_user_model_id(app_id, icon_path=ico_arg)try:import ctypesdiff --git a/tests/unit/ui/test_start_menu_shortcut_target.py b/tests/unit/ui/test_start_menu_shortcut_target.pynew file mode 100644index 0000000000..c0dc9017d7--- /dev/null+++ b/tests/unit/ui/test_start_menu_shortcut_target.py@@ -0,0 +1,168 @@+"""The Start-Menu shortcut must never be aimed at an interpreter without a window.++Forensic 2026-08-16 — "the app doesn't start any more, neither from the CLI nor+from Windows Search":++``jarvis/ui/desktop_app.py`` called ``ensure_windows_app_identity()`` as an+*import* side effect, and that call rewrites the Start-Menu shortcut to point at+``sys.executable``. But importing ``desktop_app`` is not the same as opening a+window — a ``--headless`` boot, a ``jarvis <group>`` control command and the test+suite all import it too. So whichever interpreter imported the module last won+the shortcut. Once that was a virtualenv without pywebview, Windows Search+launched a ``pythonw`` that died on ``import webview`` — and ``pythonw`` has no+console, so the error went nowhere and the app simply never appeared.++Two independent guards, one test class each:+ * the shortcut writer refuses an interpreter that cannot open a window, and+ * the import path no longer writes the shortcut at all.++Both are checked without touching the live Start Menu: a throwaway+``programs_dir`` everywhere a shortcut may be written.+"""+from __future__ import annotations++import sys+from pathlib import Path++import pytest++from jarvis.ui import icon_utils++_TEST_AUMID = "PersonalJarvis.Test.ShortcutTarget"++windows_only = pytest.mark.skipif(+ sys.platform != "win32", reason="Start-Menu shortcuts are Windows-only"+)+++class TestWindowCapabilityProbe:+ """``_interpreter_can_open_a_window`` decides whether we may claim the entry."""++ def test_matches_the_actual_import_state(self) -> None:+ import importlib.util++ expected = importlib.util.find_spec("webview") is not None+ assert icon_utils._interpreter_can_open_a_window() is expected++ def test_never_imports_pywebview(self, monkeypatch: pytest.MonkeyPatch) -> None:+ """It runs on the boot critical path, so resolving must stay stat-only."""+ import importlib++ real_import = importlib.import_module++ def _boom(name: str, *a: object, **k: object) -> object:+ if name == "webview" or name.startswith("webview."):+ raise AssertionError("probe imported pywebview; find_spec only")+ return real_import(name, *a, **k)++ monkeypatch.setattr(importlib, "import_module", _boom)+ icon_utils._interpreter_can_open_a_window()++ def test_broken_install_reads_as_no_window(+ self, monkeypatch: pytest.MonkeyPatch+ ) -> None:+ """A half-removed package raises from find_spec; treat that as unusable."""+ import importlib.util++ def _raise(name: str) -> object:+ raise ValueError("half-removed distribution")++ monkeypatch.setattr(importlib.util, "find_spec", _raise)+ assert icon_utils._interpreter_can_open_a_window() is False+++@windows_only+class TestShortcutWriterRefusesADeadTarget:+ def test_leaves_an_existing_shortcut_untouched(+ self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch+ ) -> None:+ """The regression itself: a window-less run must not steal the entry."""+ programs = tmp_path / "Programs"+ programs.mkdir()+ lnk = programs / icon_utils.START_MENU_SHORTCUT_NAME+ lnk.write_bytes(b"pretend this is the installer's working shortcut")+ before = lnk.read_bytes()++ monkeypatch.setattr(icon_utils, "_interpreter_can_open_a_window", lambda: False)+ result = icon_utils.ensure_start_menu_shortcut(+ aumid=_TEST_AUMID, programs_dir=programs+ )++ assert lnk.read_bytes() == before, "a window-less run rewrote the shortcut"+ assert result is True, "an existing entry is still present, so report it"++ def test_writes_no_shortcut_where_none_exists(+ self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch+ ) -> None:+ """Better no Start-Menu entry than one that opens nothing."""+ programs = tmp_path / "Programs"+ programs.mkdir()+ monkeypatch.setattr(icon_utils, "_interpreter_can_open_a_window", lambda: False)++ result = icon_utils.ensure_start_menu_shortcut(+ aumid=_TEST_AUMID, programs_dir=programs+ )++ assert not (programs / icon_utils.START_MENU_SHORTCUT_NAME).exists()+ assert result is False++ def test_writes_the_shortcut_when_the_interpreter_can_open_a_window(+ self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch+ ) -> None:+ """The guard must not break the case it is meant to protect."""+ programs = tmp_path / "Programs"+ programs.mkdir()+ monkeypatch.setattr(icon_utils, "_interpreter_can_open_a_window", lambda: True)++ result = icon_utils.ensure_start_menu_shortcut(+ aumid=_TEST_AUMID, programs_dir=programs+ )++ lnk = programs / icon_utils.START_MENU_SHORTCUT_NAME+ assert result is True and lnk.is_file()++ from win32com.client import Dispatch++ sc = Dispatch("WScript.Shell").CreateShortcut(str(lnk))+ assert Path(sc.TargetPath).is_file(), "shortcut points at a missing exe"+ assert sc.Arguments.strip() == f"-m {icon_utils._LAUNCHER_MODULE}"+++@windows_only+class TestIdentityCallCanSkipTheShortcut:+ def test_write_shortcut_false_writes_nothing(+ self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch+ ) -> None:+ calls: list[object] = []+ monkeypatch.setattr(+ icon_utils,+ "ensure_start_menu_shortcut",+ lambda **kw: calls.append(kw) or True,+ )+ icon_utils.ensure_windows_app_identity(_TEST_AUMID, write_shortcut=False)+ assert not calls, "import-path identity call must not write the shortcut"++ def test_default_still_writes_it(self, monkeypatch: pytest.MonkeyPatch) -> None:+ """A real window run keeps claiming the entry — the taskbar name needs it."""+ calls: list[object] = []+ monkeypatch.setattr(+ icon_utils,+ "ensure_start_menu_shortcut",+ lambda **kw: calls.append(kw) or True,+ )+ icon_utils.ensure_windows_app_identity(_TEST_AUMID)+ assert calls, "a window run must still name its taskbar button"+++class TestImportPathHasNoShortcutSideEffect:+ """Source-level guard — the import side effect is what caused the outage."""++ def test_desktop_app_import_passes_write_shortcut_false(self) -> None:+ src = (+ Path(icon_utils.__file__).resolve().parent / "desktop_app.py"+ ).read_text(encoding="utf-8-sig")+ head = src.split("# Constants", 1)[0]+ assert "ensure_windows_app_identity(write_shortcut=False)" in head, (+ "importing jarvis.ui.desktop_app must not rewrite the Start-Menu "+ "shortcut — an import is no promise of a window"+ )