The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(update): pin handoff module before checkout swap
fangliquan26e85cfea2be
diff --git a/hermes_cli/update_cmd.py b/hermes_cli/update_cmd.pyindex 70930d542e0..0da8f27006d 100644--- a/hermes_cli/update_cmd.py+++ b/hermes_cli/update_cmd.py@@ -17,6 +17,7 @@ from dataclasses import dataclassfrom pathlib import Pathfrom hermes_cli.config import get_hermes_home # noqa: F401 (re-exported; patched via update_cmd)+from hermes_cli import update_handoff as _update_handofffrom hermes_cli.update_cmd_common import _best_effortfrom hermes_constants import get_default_hermes_root, project_venv_dir, venv_python_path@@ -1381,11 +1382,11 @@ def _hand_off_post_swap(args, **payload_kwargs) -> None:The parent detaches from the receipt and its Windows resume hook — the child owns both —and only relays the exit code (``hermes_cli/update_handoff.py``)."""- from hermes_cli.update_handoff import continue_update_in_fresh_interpreterfrom hermes_cli.update_receipt import resume_update_receiptpayload = _post_swap_payload(**payload_kwargs)- code = continue_update_in_fresh_interpreter(payload, argv_tail=_post_swap_argv_tail(args))+ code = _update_handoff.continue_update_in_fresh_interpreter(+ payload, argv_tail=_post_swap_argv_tail(args))token = payload_kwargs.get("_windows_gateway_resume")if token and code is not None:# The child got its own copy (serialized before this flip) and owns the resume; every@@ -1408,10 +1409,9 @@ def _hand_off_post_swap(args, **payload_kwargs) -> None:def _run_post_swap_phase(args, gateway_mode: bool) -> None:"""Child half of the update (``--post-swap``): resume the receipt and finish the run on thepulled code."""- from hermes_cli.update_handoff import read_handofffrom hermes_cli.update_receipt import resume_update_receipt- payload = read_handoff(args.post_swap)+ payload = _update_handoff.read_handoff(args.post_swap)with suppress(OSError):Path(args.post_swap).unlink()if payload.get("receipt"):diff --git a/tests/hermes_cli/test_update_post_swap_handoff.py b/tests/hermes_cli/test_update_post_swap_handoff.pyindex 98358e08ef6..c32ed1a0155 100644--- a/tests/hermes_cli/test_update_post_swap_handoff.py+++ b/tests/hermes_cli/test_update_post_swap_handoff.py@@ -10,7 +10,7 @@ receipt and owns the tail.import jsonimport osimport sys-from types import SimpleNamespace+from types import ModuleType, SimpleNamespaceimport pytest@@ -24,6 +24,31 @@ def _opts():pre_update_version="0.21.3", active_lazy_features=["voice"], active_tool_dependencies={"x": 1})[email protected]_post_swap_handoff+def test_parent_uses_handoff_module_loaded_before_checkout_changes(monkeypatch):+ """The pre-swap updater must not import a newly pulled module into its stale module graph."""+ called = {}++ def pre_pull_handoff(payload, *, argv_tail):+ called["argv_tail"] = argv_tail+ return 0++ pulled_handoff = ModuleType("hermes_cli.update_handoff")+ pulled_handoff.continue_update_in_fresh_interpreter = lambda *a, **k: (_ for _ in ()).throw(+ AssertionError("post-pull handoff module was imported into the pre-pull interpreter"))+ monkeypatch.setattr(update_handoff, "continue_update_in_fresh_interpreter", pre_pull_handoff)+ monkeypatch.setitem(sys.modules, "hermes_cli.update_handoff", pulled_handoff)++ with pytest.raises(SystemExit) as exit_info:+ update_cmd._hand_off_post_swap(+ SimpleNamespace(yes=True, no_gateway_restart=False, branch=None, gateway=False),+ swap="git", branch="main", opts=_opts(), gateway_mode=False,+ had_desktop_app_before_update=False)++ assert exit_info.value.code == 0+ assert called["argv_tail"] == ["--yes"]++@pytest.mark.real_post_swap_handoffdef test_parent_reexecs_tail_on_pulled_tree_and_relays_exit_code(monkeypatch, tmp_path):"""The pre-swap interpreter runs NOTHING after the swap: it spawns ``python -m hermes_cli.main