Skip to content

The agent that grows with you

fix(pm): solve plugin workspaces only for the interpreter that installs them

Tekniumdb5b65607e30
diff --git a/pm/workspace.py b/pm/workspace.py
index ac31449ba22..da375d07ed6 100644
--- a/pm/workspace.py
+++ b/pm/workspace.py
@@ -10,7 +10,6 @@ import hashlib
import json
import os
import shutil
-import sys
from collections.abc import Mapping
from pathlib import Path
from typing import TYPE_CHECKING, Optional
@@ -135,8 +134,9 @@ def _copy_core_inputs(source: Path, destination: Path) -> None:
shutil.copy2(entry, target)
-def _generate_pyproject(plugin_dirs: list[Path] | Mapping[Path, Path], root: Path, *, source: Path) -> None:
- """Snapshot core and plugin build inputs into a fresh generation."""
+def _generate_pyproject(plugin_dirs: list[Path] | Mapping[Path, Path], root: Path, *, source: Path,
+ python: Path) -> None:
+ """Snapshot core and plugin build inputs into a fresh generation for the *python* that installs it."""
source = source.resolve()
if root.resolve() == source or source.is_relative_to(root.resolve()):
raise InstallError("venv", "workspace must not replace the core source")
@@ -160,9 +160,7 @@ def _generate_pyproject(plugin_dirs: list[Path] | Mapping[Path, Path], root: Pat
uv_policy.pop("exclude-newer", None)
uv_policy.pop("exclude-newer-package", None)
uv_policy["workspace"] = {"members": sorted(members)}
- # Termux is a real install target: only rewrite the solve off-Android.
- if sys.platform != "android":
- _exclude_android_from_solve(uv_policy)
+ _solve_only_for(uv_policy, python)
text = tomli_w.dumps(document)
else:
# A member-less generation syncs frozen against core's own lock.
@@ -186,22 +184,26 @@ def _without_release_age(text: str) -> str:
return re.sub(r"(?m)^exclude-newer\s*=.*\n", "", text)
-def _exclude_android_from_solve(uv_policy: dict) -> None:
- """Drop Android from ``tool.uv.environments`` in a generated workspace.
+def _solve_only_for(uv_policy: dict, python: Path) -> None:
+ """Narrow ``tool.uv.environments`` to the platform of the interpreter that installs the generation.
- uv solves every platform its environment markers can name, Android included;
- a plugin's native transitives (torch behind an optional extra) can have no
- Python 3.14 wheels there, and one unsolvable platform fails the whole lock —
- the update then evicts the plugin. A generated workspace installs on one
- host, so its solve only has to cover that host's platform set. The core's
- own lock never passes through here and keeps its full platform coverage.
+ uv solves every platform the environments admit, and since uv 0.12.14 it fails the whole
+ lock when one fork has no wheels for a dependency: onnxruntime and torch ship none for
+ Android, so a Linux or macOS update evicted the plugin over a platform it never runs on.
+ A generation installs into one interpreter on one machine; only core's committed lock
+ has to cover every platform, and it never passes through here. The interpreter is asked
+ rather than this process, because PM can run under a bootstrap Python (an older Termux
+ interpreter reports ``linux``) while uv evaluates markers against *python*.
"""
- environments = uv_policy.get("environments")
- uv_policy["environments"] = (
- [f"{entry} and sys_platform != 'android'" for entry in environments]
- if environments
- else ["sys_platform != 'android'"]
- )
+ import subprocess
+
+ from pm.filesystem import native
+
+ probe = subprocess.run([native(python), "-I", "-c", "import platform, sys; print(sys.platform); print(platform.machine())"],
+ capture_output=True, text=True, encoding="utf-8", check=True, timeout=60)
+ sys_platform, machine = probe.stdout.split()
+ host = f"sys_platform == {sys_platform!r} and platform_machine == {machine!r}"
+ uv_policy["environments"] = [f"({entry}) and {host}" for entry in uv_policy.get("environments") or []] or [host]
def _is_member_candidate(plugin_dir: Path) -> bool:
@@ -412,7 +414,7 @@ def lock_and_sync(
if root.exists() or root.is_symlink():
raise InstallError("venv", f"workspace must be fresh: {root}")
if replay is None:
- _generate_pyproject(plugin_dirs, root, source=source)
+ _generate_pyproject(plugin_dirs, root, source=source, python=environment.python)
if seed_lock is not None:
(root / "uv.lock").write_bytes(seed_lock.read_bytes())
else:
diff --git a/tests/pm/test_workspace.py b/tests/pm/test_workspace.py
index a3e1499b4c6..f856e170890 100644
--- a/tests/pm/test_workspace.py
+++ b/tests/pm/test_workspace.py
@@ -91,6 +91,34 @@ def test_plugin_workspace_trusts_core_lock_instead_of_rechecking_release_age(lay
assert "member-dep" in locked
+def test_plugin_workspace_solves_only_for_the_installing_interpreter(layout):
+ """A platform the install never runs on must not fail its solve.
+
+ uv fails the whole lock when one fork lacks wheels (onnxruntime and torch ship none for
+ Android), so a desktop update evicted mnemosyne over Android (#143254, #143305, #144003).
+ Core's own environment bounds still apply on top.
+ """
+ import tomllib
+
+ from packaging.markers import Marker, default_environment
+
+ tmp, core, plug_a, _ = layout
+ manifest = core / "pyproject.toml"
+ manifest.write_text(manifest.read_text().replace("[tool.uv]\n", "[tool.uv]\nenvironments=[\"python_version >= '3.11'\"]\n", 1))
+ root = tmp / "workspace"
+ ws.lock_and_sync([plug_a], [], root=root, source=core, seed_lock=None,
+ environment=managed_environment(tmp / "env"))
+
+ [solved] = tomllib.loads((root / "pyproject.toml").read_text())["tool"]["uv"]["environments"]
+ host = default_environment()
+ other = "win32" if host["sys_platform"] != "win32" else "linux"
+ for environment, expected in ((host, True), ({**host, "sys_platform": "android"}, False),
+ ({**host, "sys_platform": other}, False),
+ ({**host, "platform_machine": "riscv64"}, False),
+ ({**host, "python_version": "3.10"}, False)):
+ assert Marker(solved).evaluate(environment) is expected, environment
+
+
@@ -112,7 +140,7 @@ def test_core_only_generation_carries_no_release_age_cutoff(layout):
manifest = core / "pyproject.toml"
manifest.write_text(manifest.read_text().replace("[tool.uv]\n", '[tool.uv]\nexclude-newer = "3 days"\n', 1))
root = tmp / "workspace"
- ws._generate_pyproject([], root, source=core)
+ ws._generate_pyproject([], root, source=core, python=Path(sys.executable))
generated = (root / "pyproject.toml").read_text(encoding="utf-8")
assert "exclude-newer" not in generated and "[tool.uv]" in generated
diff --git a/tests/pm/test_workspace_android_exclusion.py b/tests/pm/test_workspace_android_exclusion.py
deleted file mode 100644
index 689e73d0953..00000000000
--- a/tests/pm/test_workspace_android_exclusion.py
+++ /dev/null
@@ -1,40 +0,0 @@
-"""Generated workspaces must not solve for Android.
-
-Regression guard for the update-time plugin eviction (2026-10-23): uv's universal
-resolution solves every platform named by ``tool.uv.environments``, Android
-included, and a plugin-carried native transitive (torch behind the nerve plugin's
-optional ``laya`` extra) has no Python 3.14 Android wheels — one unsolvable
-platform fails the whole workspace lock, and ``hermes update`` then evicts the
-plugin. The generated workspace installs on one host, so its solve is narrowed to
-non-Android platforms on a non-Android host (``pm.workspace._generate_pyproject``).
-"""
-
-from pm.workspace import _exclude_android_from_solve
-
-
-def test_existing_environments_lose_android_only():
- uv_policy = {"environments": ["python_version >= '3.14'"]}
- _exclude_android_from_solve(uv_policy)
- assert uv_policy["environments"] == [
- "python_version >= '3.14' and sys_platform != 'android'"
- ]
-
-
-def test_multiple_environment_entries_all_narrowed():
- uv_policy = {"environments": ["python_version >= '3.14'", "python_version < '3.14'"]}
- _exclude_android_from_solve(uv_policy)
- assert all(entry.endswith(" and sys_platform != 'android'")
- for entry in uv_policy["environments"])
- assert len(uv_policy["environments"]) == 2
-
-
-def test_missing_environments_gets_platform_only_entry():
- uv_policy: dict = {}
- _exclude_android_from_solve(uv_policy)
- assert uv_policy["environments"] == ["sys_platform != 'android'"]
-
-
-def test_unrelated_uv_policy_keys_untouched():
- uv_policy = {"default-groups": [], "environments": ["python_version >= '3.14'"]}
- _exclude_android_from_solve(uv_policy)
- assert uv_policy["default-groups"] == []
\ No newline at end of file