Skip to content

The agent that grows with you

fix(update): skip source-update completion when the stamp names HEAD

finn7636770bc9578e6
diff --git a/hermes_cli/venv_sync.py b/hermes_cli/venv_sync.py
index a483b1356d1..4b5b7317b75 100644
--- a/hermes_cli/venv_sync.py
+++ b/hermes_cli/venv_sync.py
@@ -309,6 +309,28 @@ def _supervised_child() -> bool:
)
+def _tree_matches_completed_stamp(root: Path) -> bool:
+ """True when the checkout is the exact tree the last install/update completed.
+
+ Every finished tail records its tree in install-stamp.json (write_source_stamp);
+ when that commit is HEAD, the products in the tree were built for this commit, so
+ a stale venv only needs re-provisioning and a pending marker is a leftover from a
+ previous home/install, never a rebuild of the same SHA (fresh Windows installs and
+ pristine HERMES_HOMEs hit exactly this: #123314). Unreadable state fails closed to
+ running the tail.
+ """
+ try:
+ from hermes_cli.steward import read_install_stamp
+ from hermes_cli.version_info import _run_git
+
+ commit = read_install_stamp(root).get("commit")
+ if not commit or not isinstance(commit, str):
+ return False
+ return _run_git(root, "rev-parse", "HEAD") == commit
+ except Exception: # noqa: BLE001 — never strand a launch on a provenance read
+ return False
+
+
def prepare_launch(project_root: Path, argv: list[str]) -> Path | None:
"""Finish a self-managed source update before importing app dependencies.
@@ -423,7 +445,19 @@ def _finish_source_update(root: Path, *, current: bool, pending: Path) -> None:
if any(_marker_owner_is_live(marker) for marker in legacy_markers):
raise RuntimeError("an update is still running; wait for it to exit, then relaunch Hermes")
print("hermes: completing source-update dependencies...", file=sys.stderr, flush=True)
- _sync_source_dependencies(root, arm=True)
+ completed = _tree_matches_completed_stamp(root)
+ # ponytail: commit-only match; a product dir deleted by hand is rebuilt on demand
+ # by its own entry point (the TUI/web freshness gates), not here.
+ _sync_source_dependencies(root, arm=not completed)
+ if completed:
+ clear_completion(root)
+ return
+ elif _tree_matches_completed_stamp(root):
+ # The stamp names HEAD, so the last install/update already built this tree:
+ # a pending marker is a leftover from a previous home/install, not an
+ # interrupted update, and owing nothing is quieter than announcing one.
+ clear_completion(root)
+ return
else:
print("hermes: finishing an interrupted source update...", file=sys.stderr, flush=True)
# Sync commits the dependency generation, but a source update also owes
diff --git a/tests/hermes_cli/test_update_launch_completion.py b/tests/hermes_cli/test_update_launch_completion.py
index 6ef21c78a6c..d5048fe4ee3 100644
--- a/tests/hermes_cli/test_update_launch_completion.py
+++ b/tests/hermes_cli/test_update_launch_completion.py
@@ -56,6 +56,65 @@ def _self_checkout(tmp_path, monkeypatch):
return root
+def _committed_checkout(tmp_path, monkeypatch):
+ """A scratch source checkout whose completed stamp names its live HEAD.
+
+ Mirrors a fresh official install: the installer ran the full tail and
+ recorded the tree, so launching at the same commit owes no rebuild.
+ """
+ from hermes_cli import _launchers
+
+ root = tmp_path / "checkout"
+ root.mkdir()
+ (root / "pyproject.toml").write_text("[project]\nname='example'\n")
+ for args in (["init"], ["config", "user.email", "[email protected]"],
+ ["config", "user.name", "test"], ["add", "-A"],
+ ["commit", "-m", "init"]):
+ subprocess.run(["git", *args], cwd=root, check=True,
+ capture_output=True, timeout=30)
+ head = subprocess.run(["git", "rev-parse", "HEAD"], cwd=root, check=True,
+ capture_output=True, text=True, timeout=30).stdout.strip()
+ assert head
+ (root / "install-stamp.json").write_text(
+ json.dumps({"updateMechanism": "self", "commit": head}))
+ monkeypatch.setenv("HERMES_HOME", str(tmp_path / "home"))
+ monkeypatch.setattr(Path, "home", lambda: tmp_path)
+ monkeypatch.delenv("HERMES_DISABLE_LAZY_INSTALLS", raising=False)
+ monkeypatch.setattr(_launchers, "resolve_store_python", lambda _: Path(sys.executable))
+ return root
+
+
+def test_completed_tree_with_stale_pending_marker_skips_tail(tmp_path, monkeypatch, completion_tail):
+ """Fresh install under a preserved home (#123314): the stamp names HEAD, so a
+ leftover source-completion-pending marker owes no rebuild against the same SHA."""
+ import pm
+
+ root = _committed_checkout(tmp_path, monkeypatch)
+ monkeypatch.setattr(pm, "venv_is_current", lambda **kw: True)
+ pending = venv_sync.completion_pending_path(root)
+ pending.parent.mkdir(parents=True, exist_ok=True)
+ pending.write_text("owed\n")
+ assert venv_sync.prepare_launch(root, []) is None
+ assert completion_tail == []
+ assert not pending.exists()
+
+
+def test_pristine_home_provisions_dependencies_without_rebuild(tmp_path, monkeypatch, completion_tail):
+ """Pristine HERMES_HOME on a freshly installed tree (#123314): with no facts the venv
+ needs provisioning, but the stamp names HEAD so no product rebuild or update is owed."""
+ import pm
+
+ root = _committed_checkout(tmp_path, monkeypatch)
+ assert not venv_sync.completion_pending_path(root).exists()
+ monkeypatch.setattr(pm, "venv_is_current", lambda **kw: False)
+ syncs = []
+ monkeypatch.setattr(pm, "sync_venv", lambda *args, **kwargs: syncs.append((args, kwargs)))
+ assert venv_sync.prepare_launch(root, []) == Path(sys.executable)
+ assert len(syncs) == 1
+ assert completion_tail == []
+ assert not venv_sync.completion_pending_path(root).exists()
+
+
@pytest.mark.parametrize("argv", [["--version"], ["-V"], ["--help"], ["-p", "work", "-h"]])
def test_metadata_query_never_waits_on_source_completion(tmp_path, monkeypatch, argv):
"""`hermes --version` offline must answer from the tree, not run a network-bound sync."""