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(update): take over from older native builds and relaunch Windows installs updating from v2.4.x

rubenluetke10-beepeef420064adb
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 43f907fbcd..b7a8a81e76 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -585,6 +585,7 @@ jobs:
tests/unit/ui/test_relauncher_frozen.py \
tests/unit/ui/test_relauncher_fresh_env.py \
tests/unit/ui/test_relauncher_update_transaction.py \
+ tests/unit/ui/web/test_launcher_update_handoff.py \
tests/unit/ui/web/test_update_routes.py \
tests/unit/ui/web/test_update_routes_frozen.py \
tests/unit/web/test_update_progress.py \
diff --git a/jarvis/ui/web/launcher.py b/jarvis/ui/web/launcher.py
index 1c238e3ca1..b957ce8674 100644
--- a/jarvis/ui/web/launcher.py
+++ b/jarvis/ui/web/launcher.py
@@ -1136,6 +1136,113 @@ def _health_answers(port: int, *, timeout: float = 2.0) -> bool:
return response.status_code == 200
+# How long a freshly installed native build waits for the OLDER build it is
+# replacing to exit. Long enough for an old app to finish quitting after its
+# installer handover; short enough that a genuinely stuck old instance still
+# reaches the normal "already running" recovery.
+UPDATE_HANDOFF_WAIT_S = 90.0
+
+
+def _holder_version(port: int, *, timeout: float = 1.5) -> str | None:
+ """The version the running instance reports on ``/api/health``, if any."""
+ try:
+ import httpx
+ except Exception: # noqa: BLE001 — no probe possible means no hand-off claim
+ return None
+ try:
+ response = httpx.get(f"http://127.0.0.1:{int(port)}/api/health", timeout=timeout)
+ version = response.json().get("version")
+ except Exception: # noqa: BLE001 — silent/old holder: treat as "unknown version"
+ return None
+ return version if isinstance(version, str) and version.strip() else None
+
+
+def _is_older(holder: str, ours: str) -> bool:
+ """True only when ``holder`` is provably an older release than ``ours``."""
+ try:
+ from packaging.version import InvalidVersion, Version
+ except Exception: # noqa: BLE001 — cannot compare means "not older"
+ return False
+ try:
+ return Version(holder) < Version(ours)
+ except InvalidVersion:
+ return False
+
+
+def _wait_out_an_older_holder(
+ *,
+ frozen: bool | None = None,
+ read_meta=None,
+ version_of=None,
+ acquire=None,
+ running_version: str | None = None,
+ sleep=None,
+ now=None,
+ wait_s: float = UPDATE_HANDOFF_WAIT_S,
+):
+ """Take over from an OLDER native build that is quitting for an update.
+
+ Native builds up to v2.4.x start the new version while they themselves are
+ still running: macOS ``open -n`` and the Linux AppImage respawn fire right
+ after the swap, before the old app has quit. The new version then found the
+ lock held, focused the old window and exited — and the old app quit a
+ moment later, leaving nothing running. When the lock holder reports an
+ older version than this build, this is that hand-off: wait for it to let
+ go instead of bowing out. Returns the lock, or ``None`` to fall through to
+ the normal "already running" handling (same version, a dev tree, a holder
+ that does not answer, or one that never exits).
+ """
+ from loguru import logger
+
+ from jarvis.ui import desktop_app as _desktop_app
+
+ if frozen is None:
+ from jarvis.core.frozen import is_frozen
+
+ frozen = is_frozen()
+ if not frozen:
+ return None
+ read_meta = read_meta or _desktop_app._read_meta
+ version_of = version_of or _holder_version
+ if acquire is None:
+
+ def acquire():
+ return _desktop_app.acquire_single_instance_lock(
+ timeout=0.5, terminate=lambda _pid: False
+ )
+
+ if running_version is None:
+ from jarvis import __version__ as running_version
+ sleep = sleep or time.sleep
+ now = now or time.monotonic
+
+ meta = None
+ with contextlib.suppress(Exception):
+ meta = read_meta()
+ port = meta.get("port") if isinstance(meta, dict) else None
+ if port is None:
+ return None
+ holder = version_of(int(port))
+ if holder is None or not _is_older(holder, running_version):
+ return None
+
+ logger.info(
+ "launcher: v{} is still running while v{} starts — an update hand-over; "
+ "waiting up to {:.0f}s for it to quit",
+ holder,
+ running_version,
+ wait_s,
+ )
+ deadline = now() + wait_s
+ while now() < deadline:
+ try:
+ return acquire()
+ except _desktop_app.SingleInstanceError:
+ sleep(0.5)
+ logger.warning("launcher: the older v{} never quit — normal recovery takes over", holder)
+ return None
+
+
def _holder_alive(pid: int) -> bool:
"""False only when ``pid`` has certainly exited; an unknown answer is True.
@@ -1475,12 +1582,16 @@ def _run_desktop(cfg, use_lock: bool) -> int:
try:
lock = acquire_single_instance_lock()
except SingleInstanceError as exc:
- print(f"{APP_DISPLAY_NAME} is already running.", file=sys.stderr)
- lock = _recover_from_already_running(
- exc,
- focus=focus_existing_instance_robust,
- health=_health_answers,
- )
+ # An older native build quitting for an update is not "already
+ # running" — this build is its replacement and takes over.
+ lock = _wait_out_an_older_holder()
+ if lock is None:
+ print(f"{APP_DISPLAY_NAME} is already running.", file=sys.stderr)
+ lock = _recover_from_already_running(
+ exc,
+ focus=focus_existing_instance_robust,
+ health=_health_answers,
+ )
if lock is None:
return 3
diff --git a/packaging/windows/PersonalJarvis.iss b/packaging/windows/PersonalJarvis.iss
index 58c9b3b198..7850214c49 100644
--- a/packaging/windows/PersonalJarvis.iss
+++ b/packaging/windows/PersonalJarvis.iss
@@ -255,8 +255,21 @@ begin
RemoveDirFromUserPath(ExpandConstant('{app}'));
end;
-{ True when the in-app updater passed /RELAUNCH=1 (see the [Run] section). }
+{ True when the in-app updater asked for the app to come back (see the [Run]
+ section). Updaters up to v2.4.x passed /RESTARTAPPLICATIONS instead of
+ /RELAUNCH=1 and nothing relaunched the app; honouring that flag too means
+ an install updating FROM one of those versions also comes back. }
function RelaunchRequested: Boolean;
+var
+ I: Integer;
begin
Result := ExpandConstant('{param:RELAUNCH|0}') = '1';
+ if Result then
+ Exit;
+ for I := 1 to ParamCount do
+ if CompareText(ParamStr(I), '/RESTARTAPPLICATIONS') = 0 then
+ begin
+ Result := True;
+ Exit;
+ end;
end;
diff --git a/scripts/ci/classify_changes.py b/scripts/ci/classify_changes.py
index d01bcbb73b..58f9253b47 100644
--- a/scripts/ci/classify_changes.py
+++ b/scripts/ci/classify_changes.py
@@ -156,12 +156,14 @@ _UPDATER_PREFIXES = (
"tests/unit/core/test_installer_update",
"tests/unit/install/test_installer_update",
"tests/unit/ui/test_relauncher",
+ "tests/unit/ui/web/test_launcher_update_handoff",
"tests/unit/ui/web/test_update_routes",
"tests/unit/web/test_update_",
)
_UPDATER_FILES = {
"jarvis/__main__.py",
"jarvis/ui/desktop_app.py",
+ "jarvis/ui/web/launcher.py",
"jarvis/ui/web/settings_routes.py",
".github/workflows/desktop-installers.yml",
} | _DEPS_FILES
diff --git a/tests/unit/core/test_installer_update.py b/tests/unit/core/test_installer_update.py
index 104918dc3d..a62a9562a4 100644
--- a/tests/unit/core/test_installer_update.py
+++ b/tests/unit/core/test_installer_update.py
@@ -265,6 +265,11 @@ def test_windows_installer_script_honours_the_relaunch_param() -> None:
assert "skipifsilent" not in relaunch_lines[0]
assert "runasoriginaluser" in relaunch_lines[0]
+ # Apps up to v2.4.x hand the NEW installer their old flags; it must still
+ # bring them back, or the first update onto this fix leaves the app closed.
+ function = text.split("function RelaunchRequested", 1)[1].split("\nend;", 1)[0]
+ assert "/RESTARTAPPLICATIONS" in function
+
def test_handover_refuses_a_missing_file(tmp_path: Path) -> None:
with pytest.raises(InstallerUpdateError, match="does not exist"):
diff --git a/tests/unit/ui/web/test_launcher_update_handoff.py b/tests/unit/ui/web/test_launcher_update_handoff.py
new file mode 100644
index 0000000000..6c59568f28
--- /dev/null
+++ b/tests/unit/ui/web/test_launcher_update_handoff.py
@@ -0,0 +1,108 @@
+"""A freshly installed native build takes over from the OLDER build it replaces.
+
+Native builds up to v2.4.x start the new version while they are still running
+(macOS ``open -n`` and the Linux AppImage respawn fire right after the swap).
+The new version used to find the lock held, focus the old window and exit —
+then the old app quit too, and nothing was left running. These tests pin the
+hand-off: an older holder is waited out, everything else falls through to the
+normal "already running" handling untouched.
+"""
+
+from __future__ import annotations
+
+from jarvis.ui import desktop_app
+from jarvis.ui.web import launcher
+
+
+class _Clock:
+ def __init__(self) -> None:
+ self.t = 0.0
+
+ def now(self) -> float:
+ return self.t
+
+ def sleep(self, seconds: float) -> None:
+ self.t += seconds
+
+
+def _acquire_after(attempts: int):
+ calls = {"n": 0}
+
+ def acquire():
+ calls["n"] += 1
+ if calls["n"] <= attempts:
+ raise desktop_app.SingleInstanceError("held")
+ return "LOCK"
+
+ return acquire, calls
+
+
+def _wait(**overrides):
+ clock = _Clock()
+ kwargs = {
+ "frozen": True,
+ "read_meta": lambda: {"port": 47821, "pid": 1},
+ "version_of": lambda _port: "2.4.4",
+ "running_version": "2.5.0",
+ "sleep": clock.sleep,
+ "now": clock.now,
+ "wait_s": 90.0,
+ }
+ kwargs.update(overrides)
+ return launcher._wait_out_an_older_holder(**kwargs), clock
+
+
+def test_an_older_holder_is_waited_out_and_the_lock_taken() -> None:
+ acquire, calls = _acquire_after(3)
+ lock, clock = _wait(acquire=acquire)
+ assert lock == "LOCK"
+ assert calls["n"] == 4
+ assert clock.t == 1.5
+
+
+def test_the_same_version_is_a_normal_second_launch() -> None:
+ acquire, calls = _acquire_after(0)
+ lock, _ = _wait(acquire=acquire, version_of=lambda _port: "2.5.0")
+ assert lock is None
+ assert calls["n"] == 0
+
+
+def test_a_newer_holder_is_never_replaced() -> None:
+ acquire, calls = _acquire_after(0)
+ lock, _ = _wait(acquire=acquire, version_of=lambda _port: "2.6.0")
+ assert lock is None
+ assert calls["n"] == 0
+
+
+def test_a_source_install_never_waits() -> None:
+ acquire, calls = _acquire_after(0)
+ lock, _ = _wait(acquire=acquire, frozen=False)
+ assert lock is None
+ assert calls["n"] == 0
+
+
+def test_a_silent_holder_falls_through_to_recovery() -> None:
+ acquire, calls = _acquire_after(0)
+ lock, _ = _wait(acquire=acquire, version_of=lambda _port: None)
+ assert lock is None
+ assert calls["n"] == 0
+
+
+def test_no_sidecar_means_no_hand_off() -> None:
+ acquire, calls = _acquire_after(0)
+ lock, _ = _wait(acquire=acquire, read_meta=lambda: None)
+ assert lock is None
+ assert calls["n"] == 0
+
+
+def test_an_older_holder_that_never_quits_gives_up_at_the_deadline() -> None:
+ acquire, _ = _acquire_after(10_000)
+ lock, clock = _wait(acquire=acquire, wait_s=5.0)
+ assert lock is None
+ assert clock.t >= 5.0
+
+
+def test_garbage_versions_are_not_older() -> None:
+ assert launcher._is_older("not-a-version", "2.5.0") is False
+ assert launcher._is_older("2.4.4", "2.5.0") is True
+ assert launcher._is_older("2.5.0", "2.5.0") is False