The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(update): an adoption stamp never discharges an owed completion tail
teknium138254027bf0d
diff --git a/hermes_cli/post_update.py b/hermes_cli/post_update.pyindex 2bd1c71d6d5..869249f8c1f 100644--- a/hermes_cli/post_update.py+++ b/hermes_cli/post_update.py@@ -226,7 +226,7 @@ def step_adopt_blessed_checkout(project_root: Path | None = None) -> dict:try:# Full checkout identity when git can answer; the birth-certificate# minimum below only when it cannot (or the tree is read-only).- identified = write_source_stamp(root)+ identified = write_source_stamp(root, adopted=True)except OSError as exc:# A read-only tree (nix-like layouts without their own stamp)# must not crash the boot — it just stays unadopted.diff --git a/hermes_cli/source_stamp.py b/hermes_cli/source_stamp.pyindex a62a12f3270..7416bf7bda1 100644--- a/hermes_cli/source_stamp.py+++ b/hermes_cli/source_stamp.py@@ -12,9 +12,12 @@ import tempfilefrom hermes_cli.version_info import _git_version_info, _reset_version_info_cache-def write_source_stamp(root: Path) -> dict | None:+def write_source_stamp(root: Path, *, adopted: bool = False) -> dict | None:"""Replace ``install-stamp.json`` with identity read from ``root`` itself.+ *adopted* marks a boot-time adoption (``adoptedAt``): identity only, nothing+ built, so it must never read as a completed install/update of this commit.+A root git cannot identify -- the ZIP update fallback runs precisely becausegit is unusable -- publishes no identity: the old stamp is removed ratherthan left naming the commit that was just replaced. Returns None then.@@ -42,6 +45,8 @@ def write_source_stamp(root: Path) -> dict | None:"payload": "bootstrap","tag": None,}+ if adopted:+ stamp["adoptedAt"] = stamp["builtAt"]stamp_path = root / "install-stamp.json"fd, tmp_name = tempfile.mkstemp(dir=root, prefix=".install-stamp.", suffix=".tmp")try:diff --git a/hermes_cli/venv_sync.py b/hermes_cli/venv_sync.pyindex 4b5b7317b75..26fa60a2f99 100644--- a/hermes_cli/venv_sync.py+++ b/hermes_cli/venv_sync.py@@ -316,19 +316,17 @@ def _tree_matches_completed_stamp(root: Path) -> bool:when that commit is HEAD, the products in the tree were built for this commit, soa stale venv only needs re-provisioning and a pending marker is a leftover from aprevious 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.+ pristine HERMES_HOMEs hit exactly this: #123314). Boot-time adoption also stamps+ HEAD but builds nothing, so its stamp (``adoptedAt``) is not evidence."""- 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+ from hermes_cli.steward import read_install_stamp+ from hermes_cli.version_info import _run_git++ stamp = read_install_stamp(root)+ commit = stamp.get("commit")+ if not isinstance(commit, str) or not commit or "adoptedAt" in stamp:return False+ return _run_git(root, "rev-parse", "HEAD") == commitdef 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 d5048fe4ee3..ce1d85d3f20 100644--- a/tests/hermes_cli/test_update_launch_completion.py+++ b/tests/hermes_cli/test_update_launch_completion.py@@ -115,6 +115,27 @@ def test_pristine_home_provisions_dependencies_without_rebuild(tmp_path, monkeypassert not venv_sync.completion_pending_path(root).exists()+def test_adoption_stamp_never_discharges_an_owed_tail(tmp_path, monkeypatch, completion_tail):+ """Boot-time adoption stamps HEAD but builds nothing: an unstamped blessed root with a+ pending marker still owes its tail, on this launch and on every later one."""+ import pm++ root = _committed_checkout(tmp_path, monkeypatch)+ blessed = tmp_path / "home/hermes-agent"+ blessed.parent.mkdir(parents=True)+ root.rename(blessed)+ (blessed / "install-stamp.json").unlink()+ monkeypatch.setattr(pm, "venv_is_current", lambda **kw: True)+ pending = venv_sync.arm_completion(blessed)+ completion_tail.exit_code = 1+ for _ in range(2):+ with pytest.raises(RuntimeError, match="completion failed"):+ venv_sync.prepare_launch(blessed, [])+ assert "adoptedAt" in json.loads((blessed / "install-stamp.json").read_text())+ assert len(completion_tail) == 2+ assert pending.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."""