The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(updater): keep recovered retries native-safe
fangliquanflq97051703ae7b
diff --git a/hermes_cli/_early_recovery.py b/hermes_cli/_early_recovery.pyindex 11f0f0ce64e..15fcd980205 100644--- a/hermes_cli/_early_recovery.py+++ b/hermes_cli/_early_recovery.py@@ -56,6 +56,19 @@ LAZY_REFRESH_REPAIR_PACKAGES: dict[str, str] = {"jwt": "PyJWT",}+# Set only when this process successfully finishes a deferred core install for+# an ``update`` invocation. The normal CLI import that follows must not resolve+# external secret sources: a configured source can map cryptography._rust and+# immediately recreate the self-lock marker this fresh process just consumed.+# Process-local state is intentional so child processes do not inherit the+# bootstrap exception.+_UPDATE_RETRY_RECOVERED = False+++def _should_skip_external_secret_sources() -> bool:+ """Whether this updater already completed its deferred native install."""+ return _UPDATE_RETRY_RECOVERED+def _project_root() -> Path:return Path(__file__).resolve().parent.parent@@ -352,6 +365,8 @@ def recover_if_needed(Never raises: on any failure the import of main.py proceeds and surfacesthe real error."""+ global _UPDATE_RETRY_RECOVERED+try:args = sys.argv[1:] if argv is None else argvroot = _project_root() if project_root is None else project_root@@ -384,7 +399,9 @@ def recover_if_needed(if core_marker.exists():if _marker_owner_is_live(core_marker):return- _complete_pending_core_install(root, core_marker)+ completed = _complete_pending_core_install(root, core_marker)+ if completed and "update" in args:+ _UPDATE_RETRY_RECOVERED = Truereturn# Keep the historical update-argv exclusion for the lazy-refresh@@ -482,7 +499,7 @@ def _release_recovery_lock(root: Path) -> None:pass-def _complete_pending_core_install(root: Path, core_marker: Path) -> None:+def _complete_pending_core_install(root: Path, core_marker: Path) -> bool:"""Run the pending core install BEFORE main.py can import native modules.``recover_if_needed`` invokes this when ``.update-incomplete`` exists —@@ -498,7 +515,8 @@ def _complete_pending_core_install(root: Path, core_marker: Path) -> None:attempts ceiling caps automatic retries so a persistent installerfailure does not block every launch (``hermes acp`` included).- Never raises: any failure leaves the marker for the post-import path.+ Never raises: any failure leaves the marker for the post-import path and+ returns ``False``. Returns ``True`` only after the install succeeds."""try:from hermes_cli import _install_repair as ir@@ -526,10 +544,10 @@ def _complete_pending_core_install(root: Path, core_marker: Path) -> None:"post-import recovery path.",file=sys.stderr,)- return+ return Falseif not _claim_recovery_lock(root):- return+ return Falsetry:print(@@ -551,7 +569,7 @@ def _complete_pending_core_install(root: Path, core_marker: Path) -> None:"the current venv in the meantime.",file=sys.stderr,)- return+ return Falsefinally:_release_recovery_lock(root)@@ -563,6 +581,7 @@ def _complete_pending_core_install(root: Path, core_marker: Path) -> None:" ✓ Dependency installation completed in the early pass.",file=sys.stderr,)+ return Trueexcept Exception:# Never block launch — the marker stays for the post-import path.- pass+ return Falsediff --git a/hermes_cli/env_loader.py b/hermes_cli/env_loader.pyindex b3a79654a75..05d6de052ec 100644--- a/hermes_cli/env_loader.py+++ b/hermes_cli/env_loader.py@@ -517,7 +517,15 @@ def load_hermes_dotenv(_load_dotenv_with_fallback(project_env_path, override=not loaded)loaded.append(project_env_path)- _apply_external_secret_sources(home_path)+ # A fresh ``hermes update`` retry may have completed a deferred dependency+ # install before importing this module. Do not remap native secret-source+ # dependencies in that same updater process or the self-lock preflight will+ # recreate the marker and exit 2 again. Dotenv and managed env still load;+ # only external source resolution is unnecessary for the updater.+ from hermes_cli import _early_recovery++ if not _early_recovery._should_skip_external_secret_sources():+ _apply_external_secret_sources(home_path)_apply_managed_env()# config.yaml is the documented source of truth for terminal.* settings,diff --git a/tests/hermes_cli/test_early_recovery.py b/tests/hermes_cli/test_early_recovery.pyindex 09de7cad1e6..d8bac329beb 100644--- a/tests/hermes_cli/test_early_recovery.py+++ b/tests/hermes_cli/test_early_recovery.py@@ -488,12 +488,14 @@ def test_core_marker_from_dead_updater_is_recovered_on_update_retry(calls = []monkeypatch.setattr(ir, "run_core_install", lambda project_root: calls.append(project_root))monkeypatch.setattr(er, "_marker_owner_is_live", lambda _marker: False, raising=False)+ monkeypatch.setattr(er, "_UPDATE_RETRY_RECOVERED", False)import hermes_cli._install_repair # noqa: F401er.recover_if_needed(project_root=root, argv=["update"])assert calls == [root]assert not core_marker.exists()+ assert er._should_skip_external_secret_sources() is Truedef test_core_marker_owned_by_live_updater_is_not_recovered(diff --git a/tests/hermes_cli/test_env_loader.py b/tests/hermes_cli/test_env_loader.pyindex d870e11f6bf..1eb34a41c06 100644--- a/tests/hermes_cli/test_env_loader.py+++ b/tests/hermes_cli/test_env_loader.py@@ -6,6 +6,31 @@ import sysfrom hermes_cli.env_loader import load_hermes_dotenv+def test_recovered_update_retry_skips_external_secret_sources(tmp_path, monkeypatch):+ """The post-recovery updater must not remap native vault dependencies."""+ import hermes_cli.env_loader as env_loader+ from hermes_cli import _early_recovery++ home = tmp_path / "hermes"+ home.mkdir()+ env_file = home / ".env"+ env_file.write_text("UPDATE_RETRY_DOTENV=loaded\n", encoding="utf-8")+ monkeypatch.delenv("UPDATE_RETRY_DOTENV", raising=False)+ monkeypatch.setattr(_early_recovery, "_UPDATE_RETRY_RECOVERED", True)+ external_calls = []+ monkeypatch.setattr(+ env_loader,+ "_apply_external_secret_sources",+ lambda path: external_calls.append(path),+ )++ loaded = load_hermes_dotenv(hermes_home=home)++ assert loaded == [env_file]+ assert os.environ["UPDATE_RETRY_DOTENV"] == "loaded"+ assert external_calls == []++def test_utf8_bom_does_not_mangle_first_key(tmp_path, monkeypatch):"""A leading UTF-8 BOM must not prefix the first key name in os.environ.