The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(update): a same-commit update that failed still owes its tail on launch
teknium100302e636c15
diff --git a/hermes_cli/venv_sync.py b/hermes_cli/venv_sync.pyindex 26fa60a2f99..cf442ea94bc 100644--- a/hermes_cli/venv_sync.py+++ b/hermes_cli/venv_sync.py@@ -310,23 +310,29 @@ 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.+ """True when the checkout is the exact clean 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). Boot-time adoption also stamps- HEAD but builds nothing, so its stamp (``adoptedAt``) is not evidence.+ when that commit is a clean HEAD, the products in the tree were built for it, so a+ stale venv only needs re-provisioning and a marker armed BEFORE that stamp 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). A marker+ armed after the stamp is newer debt (a same-commit ``hermes update`` that failed+ or was killed) and is still owed. Boot-time adoption also stamps HEAD but builds+ nothing, so its stamp (``adoptedAt``) is not evidence; neither is a dirty tree."""from hermes_cli.steward import read_install_stamp- from hermes_cli.version_info import _run_git+ from hermes_cli.version_info import _git_version_infostamp = read_install_stamp(root)commit = stamp.get("commit")- if not isinstance(commit, str) or not commit or "adoptedAt" in stamp:+ if not isinstance(commit, str) or not commit or "adoptedAt" in stamp or stamp.get("dirty") is not False:return False- return _run_git(root, "rev-parse", "HEAD") == commit+ pending = completion_pending_path(root)+ if pending.is_file() and pending.stat().st_mtime >= (root / "install-stamp.json").stat().st_mtime:+ return False+ info = _git_version_info(root, include_untracked=True)+ return info.commit == commit and not info.dirtydef prepare_launch(project_root: Path, argv: list[str]) -> Path | None:diff --git a/tests/hermes_cli/test_update_launch_completion.py b/tests/hermes_cli/test_update_launch_completion.pyindex ce1d85d3f20..a96e6283dcb 100644--- a/tests/hermes_cli/test_update_launch_completion.py+++ b/tests/hermes_cli/test_update_launch_completion.py@@ -64,19 +64,18 @@ def _committed_checkout(tmp_path, monkeypatch):"""from hermes_cli import _launchers+ from hermes_cli.source_stamp import write_source_stamp+root = tmp_path / "checkout"root.mkdir()(root / "pyproject.toml").write_text("[project]\nname='example'\n")+ (root / ".gitignore").write_text("install-stamp.json\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}))+ assert write_source_stamp(root)["dirty"] is Falsemonkeypatch.setenv("HERMES_HOME", str(tmp_path / "home"))monkeypatch.setattr(Path, "home", lambda: tmp_path)monkeypatch.delenv("HERMES_DISABLE_LAZY_INSTALLS", raising=False)@@ -84,34 +83,41 @@ def _committed_checkout(tmp_path, monkeypatch):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."""[email protected]("marker_age, owed", [(-60, False), (60, True)])+def test_completed_tree_discharges_only_a_marker_older_than_its_stamp(+ tmp_path, monkeypatch, completion_tail, marker_age, owed):+ """Fresh install under a preserved home (#123314): a marker armed before the stamp+ owes no rebuild of the same SHA. One armed after it (a same-commit `hermes update`+ that failed or was killed) is newer debt and the launch still finishes it."""import pmroot = _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")+ pending = venv_sync.arm_completion(root)+ stamped = (root / "install-stamp.json").stat().st_mtime+ os.utime(pending, (stamped + marker_age, stamped + marker_age))assert venv_sync.prepare_launch(root, []) is None- assert completion_tail == []+ assert len(completion_tail) == (1 if owed else 0)assert not pending.exists()-def test_pristine_home_provisions_dependencies_without_rebuild(tmp_path, monkeypatch, completion_tail):[email protected]("edited", [False, True])+def test_pristine_home_provisions_dependencies_without_rebuild(tmp_path, monkeypatch, completion_tail, edited):"""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."""+ needs provisioning, but the stamp names a clean HEAD so no product rebuild is owed.+ Local edits since the stamp void that proof: the tail runs as before."""import pmroot = _committed_checkout(tmp_path, monkeypatch)+ if edited:+ (root / "pyproject.toml").write_text("[project]\nname='edited'\n")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 len(completion_tail) == (1 if edited else 0)assert not venv_sync.completion_pending_path(root).exists()