Skip to content

The agent that grows with you

fix(pm): heal agent-browser entries staged without the exec bit

teknium192ce6f47601e
diff --git a/pm/install.py b/pm/install.py
index 8baef8d5ab3..3b6cfd8433e 100644
--- a/pm/install.py
+++ b/pm/install.py
@@ -5,6 +5,7 @@ from __future__ import annotations
import json
import logging
+import os
import shutil
import threading
from contextlib import ExitStack, contextmanager, nullcontext
@@ -66,6 +67,19 @@ def _store() -> Store:
return Store(paths.store_root())
+def _heal_exec_bit(binary: Path) -> bool:
+ """agent-browser entries staged before stage() set the exec bit sit at 0644 and fail every
+ launch with PermissionError. Modes are not part of the pinned digest, so restore it in place;
+ an entry we cannot chmod (sealed store) is treated as not installed."""
+ if os.name == "nt" or os.access(binary, os.X_OK):
+ return True
+ try:
+ binary.chmod(binary.stat().st_mode | 0o111)
+ except OSError:
+ return False
+ return os.access(binary, os.X_OK)
+
+
def _installed_location(package: Package, lockfile: Lockfile, target: str, *,
verify: bool = False, allow_outdated: bool = False,
roots: tuple[Path, ...] | None = None):
@@ -81,6 +95,8 @@ def _installed_location(package: Package, lockfile: Lockfile, target: str, *,
binary = package.binary(store.entry(fact["entry"]), target)
if binary is not None and not binary.is_file():
continue
+ if binary is not None and target == current_target() and not _heal_exec_bit(binary):
+ continue
if verify and not _entry_verified(package, fact, store, target):
continue
if facts.installed(package.name, lockfile.version(package.name), root,
diff --git a/tests/pm/test_installed_package.py b/tests/pm/test_installed_package.py
index 90a4cf5f295..cd301ff1a03 100644
--- a/tests/pm/test_installed_package.py
+++ b/tests/pm/test_installed_package.py
@@ -2,6 +2,10 @@
from __future__ import annotations
+import os
+
+import pytest
+
import pm
from pm import paths
from pm.install import ensure
@@ -47,3 +51,13 @@ def test_state_fact_in_shared_facts_file_is_not_a_store_install(pm_env):
assert not facts.installed("venv", None, paths.store_root())
composed = env_for("venv", "faketool", *all_packages())
assert composed == env_for("faketool")
+
+
[email protected](os.name == "nt", reason="POSIX exec bit")
+def test_entry_staged_without_exec_bit_is_usable_again(pm_env):
+ """agent-browser entries staged before stage() set the exec bit raised PermissionError on every launch."""
+ ensure("faketool", explicit=True)
+ binary = pm.installed_package("faketool").binary
+ binary.chmod(0o644)
+ healed = pm.installed_package("faketool")
+ assert healed is not None and healed.binary == binary and os.access(binary, os.X_OK)