Agent Zero AI framework
Repair the pinned Xpra runtime stack
Alessandrob22a144bf59f
diff --git a/docker/run/AGENTS.md b/docker/run/AGENTS.mdindex 65b4c5ce9..a6c08997f 100644--- a/docker/run/AGENTS.md+++ b/docker/run/AGENTS.md@@ -19,7 +19,7 @@- `BRANCH` is required for branch-based Docker builds.- Preserve exposed ports for SSH, HTTP, and tunneled services unless docs and workflows are updated together.- Keep the two-runtime Python model aligned with the root contract.-- Keep runtime desktop packages on `kali-last-snapshot`; pin the verified Python 3.13-compatible LibreOffice and Xpra versions in `fs/ins/install_additional.sh` for both published architectures.+- Keep runtime desktop packages on `kali-last-snapshot`; carry the rolling base's matching ATK introspection package into that transaction, then pin the verified Python 3.13-compatible LibreOffice and complete Xpra runtime versions in `fs/ins/install_additional.sh` for both published architectures.- Do not bake secrets, local `.env` values, or user data into the image.- Runtime startup must ensure `/a0/usr/uploads` exists before supervised services start.- Runtime startup raises the soft open-file limit toward `A0_NOFILE_LIMIT` (default `65535`) before supervisord starts, bounded by the container hard limit.diff --git a/docker/run/fs/ins/install_additional.sh b/docker/run/fs/ins/install_additional.shindex 36c99c909..efdb0d084 100644--- a/docker/run/fs/ins/install_additional.sh+++ b/docker/run/fs/ins/install_additional.sh@@ -33,10 +33,17 @@ LIBREOFFICE_PACKAGES=(XPRA_PACKAGES=("xpra-common=$XPRA_VERSION""xpra-server=$XPRA_VERSION"+ "xpra-client=$XPRA_VERSION"+ "xpra-client-gtk3=$XPRA_VERSION""xpra-x11=$XPRA_VERSION""xpra-html5=$XPRA_HTML5_VERSION")+apt-get update+ATK_VERSION="$(dpkg-query -W -f='${Version}' libatk1.0-0t64)"+ATK_GIR_PACKAGE="/tmp/gir1.2-atk-1.0_${ATK_VERSION}_${arch}.deb"+(cd /tmp && apt-get download "gir1.2-atk-1.0=$ATK_VERSION")+for source in /etc/apt/sources.list /etc/apt/sources.list.d/kali.sources; do[ ! -f "$source" ] || sed -i "s/kali-rolling/$KALI_SUITE/g" "$source"done@@ -54,6 +61,8 @@ Architectures: $archEOFapt-get updateDEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \+ "$ATK_GIR_PACKAGE" \+ gir1.2-gtk-3.0 \"${LIBREOFFICE_PACKAGES[@]}" \"${XPRA_PACKAGES[@]}" \xfce4-session \@@ -66,7 +75,10 @@ DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \libglib2.0-bin \xfce4-terminal \x11-xserver-utils \+ x11-utils \+ x11-apps \xdotool \+ xclip \xauth \xvfb \dbus-x11 \@@ -78,4 +90,5 @@ DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \fonts-noto-cjk \fonts-noto-color-emoji+rm -f "$ATK_GIR_PACKAGE"rm -rf /var/lib/apt/lists/*diff --git a/plugins/_desktop/AGENTS.md b/plugins/_desktop/AGENTS.mdindex f3dc67d12..98a48833f 100644--- a/plugins/_desktop/AGENTS.md+++ b/plugins/_desktop/AGENTS.md@@ -14,6 +14,7 @@## Local Contracts- Preserve session startup, cleanup, and route protection for desktop access.+- Keep the Xpra server, client modules, and GTK introspection runtime present as one compatible stack; Xpra shadow sessions import all three even when users connect only through HTML5.- Keep desktop state injected into prompts accurate and bounded.- Do not expose desktop routes without the expected auth protections.- Keep Desktop host visibility tied to an attached modal or canvas host; modal cleanup may preserve the iframe in keepalive, but must not leave stale modal mode behind.diff --git a/plugins/_desktop/hooks.py b/plugins/_desktop/hooks.pyindex d122508e0..89a6390df 100644--- a/plugins/_desktop/hooks.py+++ b/plugins/_desktop/hooks.py@@ -3,6 +3,7 @@ from __future__ import annotationsimport osimport shutilimport subprocess+import tempfileimport threadingimport timeimport urllib.request@@ -22,8 +23,22 @@ LIBREOFFICE_RUNTIME_PACKAGES = (XPRA_SOURCE_FILE = Path("/etc/apt/sources.list.d/xpra.sources")XPRA_KEYRING_FILE = Path("/usr/share/keyrings/xpra.asc")XPRA_KEY_URL = "https://xpra.org/xpra.asc"+XPRA_VERSION = "6.5.2-r0-1"+GTK_RUNTIME_PACKAGE = "gir1.2-gtk-3.0"+KALI_ROLLING_SOURCE = "deb http://http.kali.org/kali kali-rolling main contrib non-free non-free-firmware\n"+XPRA_VERSIONED_RUNTIME_PACKAGES = frozenset(+ {+ "xpra-common",+ "xpra-server",+ "xpra-client",+ "xpra-client-gtk3",+ "xpra-x11",+ }+)RUNTIME_PACKAGES = (*LIBREOFFICE_RUNTIME_PACKAGES,+ GTK_RUNTIME_PACKAGE,+ "xpra-common","xpra-server","xpra-client","xpra-client-gtk3",@@ -54,10 +69,6 @@ RUNTIME_PACKAGES = ("fonts-noto-cjk","fonts-noto-color-emoji",)-OPTIONAL_RUNTIME_PACKAGES = (- "xpra-client",- "xpra-client-gtk3",-)RETIRED_RUNTIME_PACKAGES = ("firefox-esr",)@@ -202,6 +213,17 @@ def _package_installed(package: str) -> bool:return result.returncode == 0 and "install ok installed" in result.stdout+def _package_version(package: str) -> str:+ result = subprocess.run(+ ["dpkg-query", "-W", "-f=${Version}", package],+ check=False,+ text=True,+ capture_output=True,+ timeout=8,+ )+ return result.stdout.strip() if result.returncode == 0 else ""++def _purge_packages(removed: list[str],errors: list[str],@@ -223,6 +245,8 @@ def _purge_packages(def _ensure_runtime_dependencies(installed: list[str], errors: list[str]) -> None:if os.geteuid() != 0 or not shutil.which("apt-get") or not shutil.which("dpkg-query"):return+ if not _ensure_kali_gtk_runtime(installed, errors):+ returnmissing = [package for package in RUNTIME_PACKAGES if not _package_installed(package)]if not missing:return@@ -230,8 +254,7 @@ def _ensure_runtime_dependencies(installed: list[str], errors: list[str]) -> Nonif not _apt_update(errors):return- required_missing, optional_missing = _split_runtime_packages(missing)- required_xpra_missing = [package for package in required_missing if package.startswith("xpra")]+ required_xpra_missing = [package for package in missing if package.startswith("xpra")]if required_xpra_missing and not _package_candidates_available(required_xpra_missing):previous_error_count = len(errors)_ensure_xpra_repository(installed, errors)@@ -240,47 +263,72 @@ def _ensure_runtime_dependencies(installed: list[str], errors: list[str]) -> Nonmissing = [package for package in RUNTIME_PACKAGES if not _package_installed(package)]if not missing:return- required_missing, optional_missing = _split_runtime_packages(missing)- if required_missing and not _install_runtime_packages(required_missing, installed, errors):- return+ if missing:+ _install_runtime_packages(missing, installed, errors)- if optional_missing:- optional_xpra_missing = [package for package in optional_missing if package.startswith("xpra")]- if optional_xpra_missing and not _package_candidates_available(optional_xpra_missing):- return- _install_runtime_packages(optional_missing, installed, errors, optional=True)+def _ensure_kali_gtk_runtime(installed: list[str], errors: list[str]) -> bool:+ if (+ GTK_RUNTIME_PACKAGE not in RUNTIME_PACKAGES+ or _package_installed(GTK_RUNTIME_PACKAGE)+ or _read_os_release().get("ID") != "kali"+ ):+ return True-def _split_runtime_packages(packages: list[str]) -> tuple[list[str], list[str]]:- optional = [package for package in packages if package in OPTIONAL_RUNTIME_PACKAGES]- required = [package for package in packages if package not in OPTIONAL_RUNTIME_PACKAGES]- return required, optional+ with tempfile.TemporaryDirectory(prefix="a0-desktop-apt-") as directory:+ source = Path(directory) / "kali-rolling.list"+ source.write_text(KALI_ROLLING_SOURCE, encoding="utf-8")+ options = [+ "-o",+ f"Dir::Etc::sourcelist={source}",+ "-o",+ "Dir::Etc::sourceparts=-",+ ]+ result = _run_apt_command(["apt-get", *options, "update"], timeout=300)+ if result.returncode == 0:+ result = _run_apt_command(+ [+ "apt-get",+ *options,+ "install",+ "-y",+ "--no-install-recommends",+ GTK_RUNTIME_PACKAGE,+ ],+ timeout=900,+ )+ if result.returncode == 0:+ installed.append(GTK_RUNTIME_PACKAGE)+ return True+ errors.append((result.stderr or result.stdout or "GTK runtime install failed").strip())+ return Falsedef _install_runtime_packages(packages: list[str],installed: list[str],errors: list[str],- *,- optional: bool = False,) -> bool:- result = _run_apt_command(["apt-get", "install", "-y", "--no-install-recommends", *packages], timeout=900)+ xpra_version = ""+ if any(package in XPRA_VERSIONED_RUNTIME_PACKAGES for package in packages):+ xpra_version = _package_version("xpra-common") or XPRA_VERSION+ package_specs = [+ f"{package}={xpra_version}" if package in XPRA_VERSIONED_RUNTIME_PACKAGES else package+ for package in packages+ ]+ result = _run_apt_command(+ ["apt-get", "install", "-y", "--no-install-recommends", *package_specs],+ timeout=900,+ )if result.returncode == 0:installed.extend(packages)return Trueoutput = (result.stderr or result.stdout or "apt-get install failed").strip()- if optional and _is_xpra_codec_dependency_gap(output):- return Falseerrors.append(output)return False-def _is_xpra_codec_dependency_gap(output: str) -> bool:- normalized = output.lower()- return "xpra-codecs" in normalized and "libvpx9" in normalized--def _apt_update(errors: list[str]) -> bool:result = _run_apt_command(["apt-get", "update"], timeout=300)if result.returncode == 0:@@ -359,21 +407,8 @@ def _xpra_repository_source() -> str:codename = os_release.get("VERSION_CODENAME", "")arch = _dpkg_architecture()- if os_id == "kali" and arch == "amd64":- uri = "https://xpra.org/beta"- suite = "sid"- elif os_id == "kali":- uri = "https://xpra.org"- suite = "trixie"- elif codename in {"sid", "forky"} and arch == "amd64":- uri = "https://xpra.org/beta"- suite = codename- elif codename in {"sid", "forky"}:- uri = "https://xpra.org"- suite = "trixie"- else:- uri = "https://xpra.org"- suite = codename or "trixie"+ uri = "https://xpra.org"+ suite = "trixie" if os_id == "kali" or codename in {"sid", "forky"} else codename or "trixie"return (f"Types: deb\n"diff --git a/tests/test_browser_agent_regressions.py b/tests/test_browser_agent_regressions.pyindex fa1687861..7fba2ba48 100644--- a/tests/test_browser_agent_regressions.py+++ b/tests/test_browser_agent_regressions.py@@ -2357,6 +2357,7 @@ def test_browser_docker_installs_full_chromium_to_tmp_cache():assert "self.interactive_view.ensure_display()" in runtimeassert " xvfb \\" in install_additionalassert " xdotool \\" in install_additional+ assert " xclip \\" in install_additionaldef test_browser_docker_pins_python_313_compatible_desktop_packages():@@ -2370,8 +2371,14 @@ def test_browser_docker_pins_python_313_compatible_desktop_packages():assert 'XPRA_HTML5_VERSION="19-r1-1"' in install_additionalassert 'XPRA_HTML5_VERSION="21-r1-1"' in install_additionalassert '"python3-uno=$LIBREOFFICE_VERSION"' in install_additional+ assert 'apt-get download "gir1.2-atk-1.0=$ATK_VERSION"' in install_additional+ assert ' "$ATK_GIR_PACKAGE" \\' in install_additional+ assert " gir1.2-gtk-3.0 \\" in install_additional+ assert '"xpra-client=$XPRA_VERSION"' in install_additional+ assert '"xpra-client-gtk3=$XPRA_VERSION"' in install_additionalassert '"xpra-server=$XPRA_VERSION"' in install_additionalassert '"xpra-html5=$XPRA_HTML5_VERSION"' in install_additional+ assert install_additional.index("apt-get download") < install_additional.index('s/kali-rolling/$KALI_SUITE')assert "https://xpra.org/beta" not in install_additionaldiff --git a/tests/test_office_document_store.py b/tests/test_office_document_store.pyindex 7c4e8850c..cdc421560 100644--- a/tests/test_office_document_store.py+++ b/tests/test_office_document_store.py@@ -1659,10 +1659,18 @@ def test_office_runtime_dependency_install_waits_out_apt_locks(monkeypatch):def test_desktop_runtime_packages_include_libreoffice_for_desktop_status():+ install_additional = (+ PROJECT_ROOT / "docker" / "run" / "fs" / "ins" / "install_additional.sh"+ ).read_text(encoding="utf-8")+assert set(desktop_hooks.LIBREOFFICE_RUNTIME_PACKAGES).issubset(desktop_hooks.RUNTIME_PACKAGES)assert "libreoffice-writer" in desktop_hooks.RUNTIME_PACKAGESassert "libreoffice-calc" in desktop_hooks.RUNTIME_PACKAGESassert "libreoffice-impress" in desktop_hooks.RUNTIME_PACKAGES+ assert desktop_hooks.GTK_RUNTIME_PACKAGE in desktop_hooks.RUNTIME_PACKAGES+ assert "xpra-client" in desktop_hooks.RUNTIME_PACKAGES+ assert "xpra-client-gtk3" in desktop_hooks.RUNTIME_PACKAGES+ assert f'XPRA_VERSION="{desktop_hooks.XPRA_VERSION}"' in install_additionaldef test_desktop_cleanup_moves_retired_state_to_plugin_state(tmp_path, monkeypatch):@@ -1756,8 +1764,8 @@ def test_cleanup_hook_enables_official_xpra_repo_when_kali_lacks_candidate(tmp_passert errors == []assert installed == ["xpra"]assert keyring.read_bytes() == b"xpra-key"- assert "URIs: https://xpra.org/beta" in source.read_text(encoding="utf-8")- assert "Suites: sid" in source.read_text(encoding="utf-8")+ assert "URIs: https://xpra.org\n" in source.read_text(encoding="utf-8")+ assert "Suites: trixie" in source.read_text(encoding="utf-8")assert calls.count(["apt-get", "update"]) == 2assert calls[-1][:4] == ["apt-get", "install", "-y", "--no-install-recommends"]@@ -1803,24 +1811,19 @@ def test_cleanup_hook_uses_trixie_xpra_components_for_kali_arm64(tmp_path, monkeassert "URIs: https://xpra.org\n" in source_textassert "Suites: trixie" in source_textassert "xpra" not in calls[-1]- assert calls[-1][-3:] == ["xpra-server", "xpra-x11", "xpra-html5"]+ assert calls[-1][-3:] == [+ f"xpra-server={desktop_hooks.XPRA_VERSION}",+ f"xpra-x11={desktop_hooks.XPRA_VERSION}",+ "xpra-html5",+ ]-def test_cleanup_hook_skips_optional_xpra_client_codec_conflict(monkeypatch):+def test_cleanup_hook_installs_matching_xpra_client_stack(monkeypatch):calls = []installed_state = {- "xpra-server": True,"xpra-client": False,"xpra-client-gtk3": False,- "xpra-x11": True,- "xpra-html5": True,}- codec_error = (- "E: Unable to satisfy dependencies. Reached two conflicting assignments:\n"- " 1. xpra-codecs:arm64=6.4.3-r0-1 is selected for install\n"- " 2. xpra-codecs:arm64 Depends libvpx9 (>= 1.12.0)\n"- " but none of the choices are installable: [no choices]"- )monkeypatch.setattr(desktop_hooks.os, "geteuid", lambda: 0)monkeypatch.setattr(@@ -1831,16 +1834,18 @@ def test_cleanup_hook_skips_optional_xpra_client_codec_conflict(monkeypatch):monkeypatch.setattr(desktop_hooks,"RUNTIME_PACKAGES",- ("xpra-server", "xpra-client", "xpra-client-gtk3", "xpra-x11", "xpra-html5"),+ ("xpra-client", "xpra-client-gtk3"),)monkeypatch.setattr(desktop_hooks, "_package_installed", lambda package: installed_state.get(package, False))+ monkeypatch.setattr(desktop_hooks, "_package_version", lambda package: "6.5.2-r0-1")def fake_run(command, **kwargs):calls.append(command)if command[:2] == ["apt-cache", "policy"]:- return types.SimpleNamespace(returncode=0, stdout="Candidate: 6.4.3-r0-1\n", stderr="")+ return types.SimpleNamespace(returncode=0, stdout="Candidate: 6.5.3-r0-1\n", stderr="")if command[:2] == ["apt-get", "install"]:- return types.SimpleNamespace(returncode=100, stdout="", stderr=codec_error)+ installed_state["xpra-client"] = True+ installed_state["xpra-client-gtk3"] = Truereturn types.SimpleNamespace(returncode=0, stdout="", stderr="")monkeypatch.setattr(desktop_hooks.subprocess, "run", fake_run)@@ -1849,9 +1854,49 @@ def test_cleanup_hook_skips_optional_xpra_client_codec_conflict(monkeypatch):desktop_hooks._ensure_runtime_dependencies(installed, errors)- assert installed == []+ assert installed == ["xpra-client", "xpra-client-gtk3"]+ assert errors == []+ assert calls[-1][-2:] == ["xpra-client=6.5.2-r0-1", "xpra-client-gtk3=6.5.2-r0-1"]+++def test_cleanup_hook_repairs_kali_gtk_from_rolling_source(monkeypatch):+ calls = []+ source_text = []+ installed_state = {desktop_hooks.GTK_RUNTIME_PACKAGE: False}++ monkeypatch.setattr(desktop_hooks.os, "geteuid", lambda: 0)+ monkeypatch.setattr(+ desktop_hooks.shutil,+ "which",+ lambda name: f"/usr/bin/{name}" if name in {"apt-get", "dpkg-query"} else "",+ )+ monkeypatch.setattr(desktop_hooks, "RUNTIME_PACKAGES", (desktop_hooks.GTK_RUNTIME_PACKAGE,))+ monkeypatch.setattr(desktop_hooks, "_read_os_release", lambda: {"ID": "kali"})+ monkeypatch.setattr(desktop_hooks, "_package_installed", lambda package: installed_state.get(package, False))++ def fake_run(command, **kwargs):+ calls.append(command)+ source_option = next(+ (item for item in command if item.startswith("Dir::Etc::sourcelist=")),+ "",+ )+ if source_option:+ source_text.append(Path(source_option.split("=", 1)[1]).read_text(encoding="utf-8"))+ if "install" in command:+ installed_state[desktop_hooks.GTK_RUNTIME_PACKAGE] = True+ return types.SimpleNamespace(returncode=0, stdout="", stderr="")++ monkeypatch.setattr(desktop_hooks.subprocess, "run", fake_run)+ installed = []+ errors = []++ desktop_hooks._ensure_runtime_dependencies(installed, errors)++ assert installed == [desktop_hooks.GTK_RUNTIME_PACKAGE]assert errors == []- assert calls[-1][-2:] == ["xpra-client", "xpra-client-gtk3"]+ assert source_text == [desktop_hooks.KALI_ROLLING_SOURCE, desktop_hooks.KALI_ROLLING_SOURCE]+ assert calls[0][-1] == "update"+ assert calls[1][-2:] == ["--no-install-recommends", desktop_hooks.GTK_RUNTIME_PACKAGE]def test_cleanup_hook_reports_required_xpra_codec_conflict(monkeypatch):