The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(entrypoints): tolerate only an absent bootstrap, not a broken one
ethernet44f99caacd1b
diff --git a/acp_adapter/entry.py b/acp_adapter/entry.pyindex e201f0f05e2..734ff92ba82 100644--- a/acp_adapter/entry.py+++ b/acp_adapter/entry.py@@ -12,10 +12,10 @@ Usage::# on Windows. No-op on POSIX. See hermes_bootstrap.py for full rationale.try:import hermes_bootstrap # noqa: F401-except ModuleNotFoundError:- # Partial ``hermes update`` (git-reset landed, ``uv pip install -e .`` did not):- # UTF-8 stdio setup is skipped on Windows; POSIX is unaffected.- pass+except ModuleNotFoundError as exc:+ # Partial ``hermes update`` (git-reset landed, ``uv pip install -e .`` did not).+ if exc.name != "hermes_bootstrap":+ raise # the bootstrap exists but cannot load: skipping it would skip PM activationelse:# Stop a ``utils/``/``proxy/``/``ui/`` package in the launch cwd from shadowing Hermes modules.hermes_bootstrap.harden_import_path()diff --git a/batch_runner.py b/batch_runner.pyindex 4c947831dcd..ade717fa710 100644--- a/batch_runner.py+++ b/batch_runner.py@@ -9,10 +9,10 @@ statistics aggregated across all batches. See ``main`` (fire CLI) for usage.# hermes_bootstrap must be the very first import — UTF-8 stdio on Windows, no-op on POSIX.try:import hermes_bootstrap # noqa: F401-except ModuleNotFoundError:- # Partial ``hermes update`` (git reset landed, ``uv pip install -e .`` did not):- # only Windows UTF-8 stdio setup is skipped.- pass+except ModuleNotFoundError as exc:+ # Partial ``hermes update`` (git reset landed, ``uv pip install -e .`` did not).+ if exc.name != "hermes_bootstrap":+ raise # the bootstrap exists but cannot load: skipping it would skip PM activationimport jsonimport loggingdiff --git a/cli.py b/cli.pyindex 1bd1312a7f0..3a85e725824 100644--- a/cli.py+++ b/cli.py@@ -4,8 +4,9 @@# Must be the very first import (UTF-8 stdio on Windows). Missing only mid-``hermes update``.try:import hermes_bootstrap # noqa: F401-except ModuleNotFoundError:- pass+except ModuleNotFoundError as exc:+ if exc.name != "hermes_bootstrap":+ raise # the bootstrap exists but cannot load: skipping it would skip PM activationimport loggingimport osdiff --git a/gateway/run.py b/gateway/run.pyindex 26f9ef6f724..7ddd02f945e 100644--- a/gateway/run.py+++ b/gateway/run.py@@ -6,8 +6,9 @@ Run via ``python -m gateway.run`` or ``python cli.py --gateway``."""# hermes_bootstrap must be the very first import (UTF-8 stdio on Windows; no-op on POSIX).try:import hermes_bootstrap # noqa: F401-except ModuleNotFoundError:- pass # a partial ``hermes update`` can leave the bootstrap unregistered; only Windows UTF-8 stdio suffers+except ModuleNotFoundError as exc: # a partial ``hermes update`` can leave the bootstrap unregistered+ if exc.name != "hermes_bootstrap":+ raise # the bootstrap exists but cannot load: skipping it would skip PM activationimport asyncioimport concurrent.futuresdiff --git a/hermes_cli/main.py b/hermes_cli/main.pyindex 85d26e5b7ec..c1d1bd18d3d 100644--- a/hermes_cli/main.py+++ b/hermes_cli/main.py@@ -14,8 +14,9 @@ Usage:# here would block ``hermes update``.try:import hermes_bootstrap # noqa: F401-except ModuleNotFoundError:- pass+except ModuleNotFoundError as exc:+ if exc.name != "hermes_bootstrap":+ raise # the bootstrap exists but cannot load: skipping it would skip PM activation# Windows: neutralize CPython's ``platform._syscmd_ver`` before anything else# imports — it shells out ``cmd /c ver`` and flashes a console when thisdiff --git a/run_agent.py b/run_agent.pyindex a6483565a02..085a9bad18e 100644--- a/run_agent.py+++ b/run_agent.py@@ -9,8 +9,9 @@# hermes_bootstrap must be the very first import (UTF-8 stdio on Windows; no-op on POSIX).try:import hermes_bootstrap # noqa: F401-except ModuleNotFoundError:- pass # partial `hermes update` — only skips the Windows UTF-8 stdio setup+except ModuleNotFoundError as exc: # partial `hermes update` left the bootstrap unregistered+ if exc.name != "hermes_bootstrap":+ raise # the bootstrap exists but cannot load: skipping it would skip PM activationimport jsonimport loggingdiff --git a/tests/test_hermes_bootstrap.py b/tests/test_hermes_bootstrap.pyindex d2debacf9d1..f846f284480 100644--- a/tests/test_hermes_bootstrap.py+++ b/tests/test_hermes_bootstrap.py@@ -265,6 +265,51 @@ print('reached-pm')assert result.stdout.strip() == "reached-pm"[email protected]("path", [+ "hermes_cli/main.py", "run_agent.py", "acp_adapter/entry.py",+ "gateway/run.py", "batch_runner.py", "cli.py",+])[email protected]("bootstrap,expected", [+ (None, "proceeded"),+ ("import hermes_missing_dependency_probe\n", "raised hermes_missing_dependency_probe"),+])+def test_entrypoint_tolerates_only_an_absent_bootstrap(tmp_path, path, bootstrap, expected):+ """The entry-point guard covers a bootstrap a partial update left unregistered.++ A bootstrap that exists but cannot import its own dependencies must surface:+ swallowing that skipped PM activation silently and the tree ran on stale deps.+ """+ root = Path(__file__).resolve().parents[1]+ entry = tmp_path / "startup.py"+ entry.write_bytes((root / path).read_bytes())+ fake_root = tmp_path / "root"+ fake_root.mkdir()+ if bootstrap is not None:+ (fake_root / "hermes_bootstrap.py").write_text(bootstrap)+ program = r"""+import builtins, runpy, sys+fake_root, entry = sys.argv[1:]+sys.path.insert(0, fake_root)+real_import = builtins.__import__+class Boundary(BaseException): pass+def guarded(name, globals=None, locals=None, fromlist=(), level=0):+ if globals and globals.get('__file__') == entry and name not in ('__future__', 'hermes_bootstrap'):+ raise Boundary()+ return real_import(name, globals, locals, fromlist, level)+builtins.__import__ = guarded+try:+ runpy.run_path(entry, run_name='__main__')+except Boundary:+ print('proceeded')+except ModuleNotFoundError as exc:+ print('raised', exc.name)+"""+ result = subprocess.run([sys.executable, "-I", "-S", "-c", program, str(fake_root), str(entry)],+ cwd=tmp_path, capture_output=True, text=True, timeout=30)+ assert result.returncode == 0, result.stderr+ assert result.stdout.strip() == expected++class TestHardenImportPath:"""harden_import_path() must keep a same-named package in the launchdirectory from shadowing Hermes's own top-level modules — covering both