The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(update): a launch that cannot get the repair claim never continues from the torn tree (review F20)
Teknium3c47d77bae59
diff --git a/hermes_cli/_early_recovery.py b/hermes_cli/_early_recovery.pyindex aff2136cede..c7270bca60e 100644--- a/hermes_cli/_early_recovery.py+++ b/hermes_cli/_early_recovery.py@@ -862,9 +862,12 @@ def restore_interrupted_pull(project_root: Path | None = None, *, after_failure:return Falsewith _restore_claim(marker.parent) as claimed:if not claimed:- print("⚠ Another Hermes launch is still repairing the checkout after an interrupted "- "`hermes update`; if this one fails, launch again in a moment.", file=sys.stderr)- return False+ if after_failure:+ return False # the marker stays: the updater reports the move as not settled+ # The tree is still torn (the marker is there): importing checkout code now would run+ # the half-written files. Fail closed like unprovable custody does.+ raise RuntimeError("another Hermes launch is still repairing the checkout after an "+ "interrupted `hermes update`; launch again in a moment")if not marker.is_file():return True # another launch finished while this one started: rerun from its tree# The claim orders launches; the checkout lock keeps out an update tree. Claim first, so adiff --git a/tests/hermes_cli/test_update_interrupted_pull.py b/tests/hermes_cli/test_update_interrupted_pull.pyindex a7c2fbe3ce1..878bf20d08a 100644--- a/tests/hermes_cli/test_update_interrupted_pull.py+++ b/tests/hermes_cli/test_update_interrupted_pull.py@@ -410,6 +410,25 @@ def test_a_rollback_marker_outlives_a_lock_that_may_still_be_live(tmp_path):assert _git(root, "status", "--porcelain", "--untracked-files=no") == ""+def test_a_launch_that_cannot_get_the_repair_claim_never_continues_from_the_torn_tree(tmp_path, monkeypatch):+ """Another launch holds the restore claim past the wait while the marker says the tree is torn:+ this launch must stop (fail closed) instead of reporting 'nothing to repair' and importing it."""+ root, pre, target = _broken_release(tmp_path, 5)+ marker = _rollback_marker(root, pre, target)+ monkeypatch.setattr(er, "_RESTORE_CLAIM_WAIT_SECONDS", 0.2)+ fd = os.open(marker.parent / er._RESTORE_CLAIM, os.O_RDWR | os.O_CREAT, 0o644)+ try:+ assert er._lock_fd(fd, True)+ with pytest.raises(RuntimeError, match="launch again"):+ er.restore_interrupted_pull(root)+ finally:+ er._lock_fd(fd, False)+ os.close(fd)+ assert marker.exists() and _git(root, "rev-parse", "HEAD") == target+ assert er.restore_interrupted_pull(root) is True # once the claim is free the repair runs+ assert _git(root, "rev-parse", "HEAD") == pre and not marker.exists()++# --- R2: the launch-time repair holds the checkout kernel lock -------------------------------_HOLD_CHECKOUT = """