Skip to content

The agent that grows with you

fix(pm): refuse a registry gap in the caller, never through a PM worker

Tekniuma1cc85f3e2c3
diff --git a/pm/client.py b/pm/client.py
index bce938e8676..8d06f12b230 100644
--- a/pm/client.py
+++ b/pm/client.py
@@ -17,10 +17,19 @@ from pm.worker_operations import OPERATIONS
def _missing_or_refuse(name):
- from pm.install import _refuse_lazy, is_installed, lazy_installs_allowed
- from pm.registry import walk
+ from pm.install import _refuse_lazy, current_target, is_installed, lazy_installs_allowed
+ from pm.registry import get_package, walk
missing = [package.name for package in walk([name]) if not is_installed(package.name)]
+ target = current_target() if missing else None
+ for gap in missing:
+ # A registry gap (git on POSIX: "uses system git by choice") is static: no worker can
+ # install it, so answer with the worker's own refusal here. Asking one anyway cost a PM
+ # worker round trip (about a second) on every ``selected_git_env()``, which each
+ # checkpoint git child calls, so one gateway /rollback or /diff paid it several times.
+ reason = get_package(gap).missing_reason(target)
+ if reason is not None:
+ raise InstallError(gap, f"unavailable on {target}: {reason}", "none")
if missing and not lazy_installs_allowed():
raise _refuse_lazy(name, ", ".join(missing))
return missing
diff --git a/tests/gateway/test_hosted_rooms.py b/tests/gateway/test_hosted_rooms.py
index 50b88511235..83c843f65d6 100644
--- a/tests/gateway/test_hosted_rooms.py
+++ b/tests/gateway/test_hosted_rooms.py
@@ -730,6 +730,9 @@ def test_room_log_pages_are_bounded_by_serialized_event_bytes(tmp_path, monkeypa
kind="message.user",
actor=USER,
payload={"text": "x" * 180, "index": index},
+ # A fixed clock: the budget below is one event's serialized size, and a wall-clock
+ # created_at's float repr varies by a few bytes from event to event.
+ now=1_700_000_000.5,
)
one_event = rooms.read_events(db, room_id="room-1", limit=1)
diff --git a/tests/pm/test_registry_gap_refusal.py b/tests/pm/test_registry_gap_refusal.py
new file mode 100644
index 00000000000..14dc2fc62aa
--- /dev/null
+++ b/tests/pm/test_registry_gap_refusal.py
@@ -0,0 +1,37 @@
+"""A registry gap is refused in the caller, never by a PM worker round trip.
+
+Git on POSIX is a declared gap ("uses system git by choice"). ``selected_git_env()`` asks PM for it
+before every checkpoint git child, so a worker spawn per ask made each gateway /rollback or /diff
+pay seconds and timed those RPCs out on a loaded CI runner.
+"""
+import pytest
+
+from hermes_cli._subprocess_compat import selected_git_env
+import pm
+from pm import client, install
+from pm.package import InstallError
+
+
+def no_worker(monkeypatch):
+ monkeypatch.setattr(client, "is_runtime", lambda: False)
+ monkeypatch.setattr(install, "is_installed", lambda name: False)
+ monkeypatch.setattr(install, "current_target", lambda: "linux-x64")
+ # The product default; the harness disables lazy installs, which refuses before any worker.
+ monkeypatch.setattr(install, "lazy_installs_allowed", lambda: True)
+
+ def worker(operation, arguments, **kwargs):
+ pytest.fail(f"a PM worker was asked to {operation} {arguments}")
+
+ monkeypatch.setattr(client, "_request", worker)
+
+
+def test_a_registry_gap_is_refused_without_a_worker(no_worker):
+ with pytest.raises(InstallError) as refused:
+ pm.ensure("git", base_env={})
+ assert refused.value.remedy == "none"
+ assert "POSIX uses system git by choice" in refused.value.cause
+
+
+def test_selected_git_env_keeps_the_system_git_without_a_worker(no_worker):
+ assert selected_git_env({"PATH": "/usr/bin"}) == {"PATH": "/usr/bin"}