The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(update): the import-health probe sees the venv's editable finder, not the checkout cwd
teknium18680a8d1ed7c
diff --git a/hermes_cli/update_cmd_deps.py b/hermes_cli/update_cmd_deps.pyindex c0c47261dd3..ff5c8c7273e 100644--- a/hermes_cli/update_cmd_deps.py+++ b/hermes_cli/update_cmd_deps.py@@ -172,19 +172,28 @@ def _critical_module_import_failures(report_runtime_errors, marker))try:interpreter = sys.executable+ argv = [interpreter, "-c", probe]with suppress(Exception):venv_dir = project_venv_dir(root) or Path(root) / "venv"venv_python = venv_python_path(venv_dir, windows=_m()._is_windows())if venv_python.exists():interpreter = str(venv_python)+ argv = [interpreter, "-c", probe]+ # ``-c`` puts the cwd (the checkout) at sys.path[0], which masks the installed+ # editable finder — the exact thing a gateway started from ``/`` imports through.+ # A stale finder MAPPING (new top-level package since the install) then reports+ # green here and crash-loops the gateway (#119466). ``-P`` makes the probe see what+ # the venv sees; only when an editable install exists, so a bare dev checkout that+ # is importable through its cwd alone keeps its advisory verdict.+ if _editable_finder_files(venv_dir):+ argv = [interpreter, "-P", "-c", probe]# The candidate stays importable through the probe's cwd and its editable install;# the scrub only removes paths the guard never meant to vouch for.probe_env = dict(os.environ)for denied_key in _PROBE_ENV_DENYLIST:probe_env.pop(denied_key, None)result = bounded_probe_run(- [interpreter, "-c", probe], timeout=120, cwd=str(root), raise_on_spawn_failure=True,- env=probe_env,+ argv, timeout=120, cwd=str(root), raise_on_spawn_failure=True, env=probe_env,)except (OSError, subprocess.SubprocessError):# Keep this guard advisory: a probe we could not even spawn (unreadable venvdiff --git a/tests/hermes_cli/test_update_import_guard.py b/tests/hermes_cli/test_update_import_guard.pyindex 400a314e0c2..a90fd96298f 100644--- a/tests/hermes_cli/test_update_import_guard.py+++ b/tests/hermes_cli/test_update_import_guard.py@@ -399,3 +399,30 @@ def test_hint_fires_for_each_first_party_root(modname):assert partial_update_hint(exc), f"expected guidance for {modname}"+def test_import_probe_sees_a_stale_editable_finder_instead_of_the_checkout_cwd(monkeypatch, tmp_path):+ """``-c`` puts the checkout cwd on sys.path[0], so a venv whose editable finder cannot resolve a+ new top-level package still probed green — the exact state that crash-loops a gateway started+ from ``/`` (#119466). With an editable install present the probe runs under ``-P`` and reports+ the first-party ModuleNotFoundError; a venv WITHOUT an editable install keeps the cwd path."""+ (tmp_path / "hermes_probe_pkg").mkdir()+ (tmp_path / "hermes_probe_pkg" / "__init__.py").write_text("")+ venv = tmp_path / "venv"+ python = venv / "bin" / "python"+ python.parent.mkdir(parents=True)+ python.symlink_to(sys.executable)+ monkeypatch.setattr(update_cmd, "_UPDATE_CRITICAL_MODULES", ("hermes_probe_pkg",))+ monkeypatch.setattr(update_cmd_deps, "_UPDATE_CRITICAL_MODULES", ("hermes_probe_pkg",))+ monkeypatch.setattr(update_cmd_deps, "project_venv_dir", lambda root: venv)+ monkeypatch.setattr(update_cmd_deps, "_editable_finder_files", lambda v: [])++ assert update_cmd_deps._critical_module_import_failures(tmp_path) == {} # dev checkout: cwd vouches++ site = venv / "lib" / f"python{sys.version_info.major}.{sys.version_info.minor}" / "site-packages"+ site.mkdir(parents=True)+ finder = site / "__editable___hermes_agent_0_21_0_finder.py"+ finder.write_text("MAPPING = {}\n", encoding="utf-8") # stale: no hermes_probe_pkg+ monkeypatch.setattr(update_cmd_deps, "_editable_finder_files", lambda v: [finder])++ failures = update_cmd_deps._critical_module_import_failures(tmp_path)+ assert set(failures) == {"hermes_probe_pkg"}+ assert failures["hermes_probe_pkg"][0] == "ModuleNotFoundError"