The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(update): a gone target retires its recovery marker only over a clean tree at pre (review G2)
Tekniumdc9415b2d1fd
diff --git a/hermes_cli/_early_recovery.py b/hermes_cli/_early_recovery.pyindex 88b6a423c16..9fc84975b36 100644--- a/hermes_cli/_early_recovery.py+++ b/hermes_cli/_early_recovery.py@@ -1144,9 +1144,12 @@ def _restore_holding_claim(root: Path, marker: Path, *, after_failure: bool = Fareturn Falsewritten = _paths_git_wrote(git, root, pre, target)if written is None: # after a gc or re-clone: nothing left to compare against- if rollback and not _rollback_verified(git, git_dir, pre):- print(f"⚠ An interrupted `hermes update` rollback to {pre[:10]} is not verified and commit "- f"{target[:10]} is gone; the marker was kept. Inspect `git -C {root} status`.", file=sys.stderr)+ # Unattributable bytes are not proof of a whole tree: only a clean tracked tree at ``pre``+ # retires the record, rollback or not (review G2).+ if not _rollback_verified(git, git_dir, pre):+ print(f"⚠ An interrupted `hermes update` left tracked files that differ from {pre[:10]} and commit "+ f"{target[:10]} is gone; the marker was kept. Inspect `git -C {root} status`, then "+ f"`git -C {root} checkout {pre[:10]} -- <file>` for each file the update wrote.", file=sys.stderr)return Falsemarker.unlink()print(f"⚠ Ignoring a stale interrupted-update marker: commit {target[:10]} is gone.", file=sys.stderr)diff --git a/tests/hermes_cli/test_update_interrupted_pull.py b/tests/hermes_cli/test_update_interrupted_pull.pyindex 7fbd8137e34..2f716ef71d6 100644--- a/tests/hermes_cli/test_update_interrupted_pull.py+++ b/tests/hermes_cli/test_update_interrupted_pull.py@@ -228,9 +228,16 @@ def test_restore_never_touches_user_work_when_git_wrote_nothing(checkout, capsysassert er.restore_interrupted_pull(root) is Falseassert (root / "utils.py").read_text(encoding="utf-8") == "OLD = 1 # my stash, re-applied\n"assert not marker.exists(), "git wrote nothing: the marker is spent"- # A target git no longer knows (gc, re-clone) can never be compared against: drop the marker.+ # A target git no longer knows (gc, re-clone) can never be compared against: the marker goes+ # only over a clean tracked tree, since the dirty bytes may be the update's (review G2).marker.write_text(stale.replace(b, "0" * 40), encoding="utf-8", newline="")+ capsys.readouterr()+ assert er.restore_interrupted_pull(root) is False and marker.exists()+ assert "the marker was kept" in capsys.readouterr().err+ assert (root / "utils.py").read_text(encoding="utf-8") == "OLD = 1 # my stash, re-applied\n"+ _git(root, "stash", "-q")assert er.restore_interrupted_pull(root) is False and not marker.exists()+ _git(root, "stash", "pop", "-q")# Killed inside the custom-branch `git merge`: its files are the merge of both sides, not origin's# blob, and still git's (torn ones too), while the user's own edit survives.@@ -898,3 +905,23 @@ def test_a_lock_that_predates_the_move_stays_foreign_after_our_git_exited(tmp_paassert er.restore_interrupted_pull(root) is Falseassert lock.exists() and marker.exists(), "a lock that predates the move was deleted"assert _git(root, "rev-parse", "HEAD") == target++[email protected]("torn", [True, False])+def test_a_gone_target_retires_its_marker_only_over_a_clean_pre_tree(tmp_path, torn):+ """A killed move left HEAD on ``pre`` with the target's bytes in a tracked file, then git pruned+ the target commit: recovery cannot attribute those bytes, and it dropped the only record over+ the dirty tree (review G2). The marker now goes only when the tracked tree is clean at pre."""+ root, pre, target = _broken_release(tmp_path, 2)+ _git(root, "reset", "-q", "--hard", pre)+ _git(root, "reflog", "expire", "--expire=now", "--all")+ _git(root, "gc", "-q", "--prune=now")+ assert subprocess.run(["git", "-C", str(root), "cat-file", "-e", target]).returncode != 0 # gone+ if torn:+ (root / "module.py").write_text("def broken(:\n", encoding="utf-8", newline="")+ marker = er.interrupted_pull_marker(root)+ marker.write_text(f"pid=0\npre={pre}\ntarget={target}\nstash=\n", encoding="utf-8", newline="")+ assert er.restore_interrupted_pull(root) is False+ assert marker.exists() is torn+ if torn:+ assert (root / "module.py").read_text(encoding="utf-8") == "def broken(:\n" # never guessed back