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(browser): reuse the host Python only for the exact requested minor (#813)

Ruben Lütkeb795de414bfc
diff --git a/dodaios/society/browser/install.py b/dodaios/society/browser/install.py
index 215225def0..d094c8f4d1 100644
--- a/dodaios/society/browser/install.py
+++ b/dodaios/society/browser/install.py
@@ -64,6 +64,22 @@ def managed_python_request(system: str, machine: str) -> str:
return "3.12"
+def host_matches_managed_python(request: str, version: tuple[int, int], *, frozen: bool) -> bool:
+ """True when this very interpreter can seed the browser runtime.
+
+ The browser dependency lock is hashed for one CPython minor version, so a
+ host 3.11 or 3.13 would build a runtime whose wheels do not match it. Only
+ a plain ``"X.Y"`` request equal to the host's own minor version reuses the
+ host; a frozen app or a pinned build string (Windows on ARM) goes to uv.
+ """
+ if frozen:
+ return False
+ major, dot, minor = request.partition(".")
+ if not (dot and major.isdigit() and minor.isdigit()):
+ return False
+ return (int(major), int(minor)) == tuple(version[:2])
+
+
def _manifest(data_dir: Path | None = None) -> dict[str, Any]:
try:
row = json.loads((install_root(data_dir) / "installed.json").read_text("utf-8"))
@@ -286,10 +302,8 @@ def ensure_installed(
_set(data_dir, phase="installing", percent=5, error="", detail="Preparing browser runtime")
try:
request = managed_python_request(sys.platform, platform.machine())
- if (
- not getattr(sys, "frozen", False)
- and (3, 11) <= sys.version_info[:2] < (3, 14)
- and request == "3.12"
+ if host_matches_managed_python(
+ request, sys.version_info[:2], frozen=bool(getattr(sys, "frozen", False))
):
_run([sys.executable, "-m", "venv", str(runtime)], env=env)
else:
diff --git a/tests/unit/society/test_browser_install.py b/tests/unit/society/test_browser_install.py
index 5c57f6691c..1a5fdbbb44 100644
--- a/tests/unit/society/test_browser_install.py
+++ b/tests/unit/society/test_browser_install.py
@@ -2,10 +2,12 @@
import json
import os
+import sys
from concurrent.futures import ThreadPoolExecutor
from pathlib import Path
import pytest
+
from dodaios.society.browser import install
@@ -39,13 +41,60 @@ def installer(monkeypatch, tmp_path):
)
return ""
+ from dodaios.society.browser import bootstrap
+
monkeypatch.setattr(install, "_run", run)
+ # A host that is not 3.12 builds the runtime through uv; never download it.
+ monkeypatch.setattr(bootstrap, "ensure_uv", lambda _root: "uv")
monkeypatch.setattr(install, "managed_python_request", lambda *_: "3.12")
monkeypatch.setattr(install.sys, "frozen", False, raising=False)
yield tmp_path, root, launches, failure
install._reset_for_tests()
+ ("request_", "version", "frozen", "reuse"),
+ [
+ ("3.12", (3, 12), False, True),
+ ("3.12", (3, 11), False, False),
+ ("3.12", (3, 13), False, False),
+ ("3.12", (3, 12), True, False),
+ ("3.13", (3, 13), False, True),
+ ("cpython-3.12-windows-x86_64-none", (3, 12), False, False),
+ ("", (3, 12), False, False),
+ ],
+)
+def test_host_python_is_reused_only_for_the_exact_requested_minor(request_, version, frozen, reuse):
+ assert install.host_matches_managed_python(request_, version, frozen=frozen) is reuse
+
+
+def _host_minor(offset: int = 0) -> str:
+ return f"{sys.version_info[0]}.{sys.version_info[1] + offset}"
+
+
[email protected](("offset", "via_uv"), [(0, False), (1, True), (-1, True)])
+def test_installer_builds_from_host_only_when_its_minor_matches(
+ installer, monkeypatch, offset, via_uv
+):
+ data, _, _, _ = installer
+ request = _host_minor(offset)
+ monkeypatch.setattr(install, "managed_python_request", lambda *_: request)
+ seen = []
+ original = install._run
+
+ def run(cmd, **kwargs):
+ seen.append(cmd)
+ return original(cmd, **kwargs)
+
+ monkeypatch.setattr(install, "_run", run)
+ install.ensure_installed(data)
+ venv = next(cmd for cmd in seen if "venv" in cmd)
+ if via_uv:
+ assert venv[:4] == ["uv", "venv", "--python", request]
+ else:
+ assert venv[:3] == [sys.executable, "-m", "venv"]
+
+
@pytest.mark.parametrize("stage", ["ensurepip", "pip", "playwright", "--probe"])
def test_failed_repair_keeps_the_verified_environment(installer, stage):
data, root, launches, failure = installer