Skip to content

The agent that grows with you

fix(update): adopting an orphaned pause keeps its pre-update tree evidence (review F2-adoption-restamps-baseline)

Teknium0f3fedd9a6ec
diff --git a/hermes_cli/update_pause_record.py b/hermes_cli/update_pause_record.py
index fc08695cbb8..03c6edf250d 100644
--- a/hermes_cli/update_pause_record.py
+++ b/hermes_cli/update_pause_record.py
@@ -604,6 +604,11 @@ def merge_into(token: dict | None, adopted: dict) -> dict:
obligation id (and every id it absorbed) is recorded so a leftover copy is never resumed twice."""
token = token if token is not None else {"resume_needed": True, "profiles": {}, "unmapped_pids": [], "unmapped": []}
token["resume_needed"] = True
+ # The oldest tree evidence wins: stamping the current tree instead would certify whatever a
+ # killed update left half-written as "dirty before the pause".
+ for key in ("pre_sha", "dirty_at_pause"):
+ if key in adopted:
+ token.setdefault(key, adopted[key])
absorbed = token.setdefault("absorbed", [])
absorbed.extend(i for i in [adopted.get("pause_id"), *(adopted.get("absorbed") or [])] if i and i not in absorbed)
profiles = token.setdefault("profiles", {})
diff --git a/tests/hermes_cli/test_update_pause_record.py b/tests/hermes_cli/test_update_pause_record.py
index 937fd39bde9..05f2fd3b25e 100644
--- a/tests/hermes_cli/test_update_pause_record.py
+++ b/tests/hermes_cli/test_update_pause_record.py
@@ -114,6 +114,26 @@ def test_resume_waits_for_a_whole_tree(tmp_path):
assert not whole and "dependencies" in why, why
+def test_an_update_adopting_an_orphan_never_certifies_the_tree_it_left_torn(tmp_path, monkeypatch):
+ root = tmp_path / "checkout"
+ root.mkdir()
+ _git(root, "init", "-q")
+ (root / "a.py").write_text("v1\n", encoding="utf-8")
+ _git(root, "add", ".")
+ _git(root, "commit", "-qm", "v1")
+ monkeypatch.setenv("HERMES_HOME", str(tmp_path / "home"))
+ monkeypatch.setattr(pause_record, "install_root", lambda: root)
+ pause_record.write(pause_record.stamp_tree({"resume_needed": True, "profiles": {"default": 4242}}),
+ owner=pause_record.UNOWNED)
+ (root / "a.py").write_text("half-written\n", encoding="utf-8") # the killed update's git died mid-checkout
+ assert not pause_record.tree_is_whole(pause_record.read()["token"], root)[0], "premise: the orphan's gate refuses"
+
+ adopted, claims = pause_record.adopt_orphans()
+ token = pause_record.record_pause({"resume_needed": True, "profiles": {"beta": 99}}, adopted, claims)
+ whole, why = pause_record.tree_is_whole(token, root)
+ assert not whole and "a.py" in why, "adoption certified the torn tree as the pre-update baseline"
+
+
def _orphan(tmp_path: Path, profiles: dict) -> None:
"""A record whose owner — a real ``hermes update`` stand-in — was SIGKILLed after writing it."""
owner = _child("""