The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: a lost completion closes the run from the child's record, not the parent's stale snapshot
Teknium85bfcbd13969
diff --git a/hermes_cli/update_completion.py b/hermes_cli/update_completion.pyindex 44af0eb469c..d51d4896fb6 100644--- a/hermes_cli/update_completion.py+++ b/hermes_cli/update_completion.py@@ -231,6 +231,7 @@ def settle_lost_completion(request: dict, reason: str) -> dict:except Exception as exc: # health: allow BLE001 -- post-commit boundary: stale dependencies still make the next launch syncprint(f" ⚠ Could not record the owed source-update tail: {exc}")_report_desktop_build_owed(request, _running_record(request), "the update completion did not finish")+ update_receipt.resume_run_record() # the child's persisted stages, never this stale snapshotupdate_receipt.record_followup("completion", reason, retry="the next launch or `hermes update` finishes it")parked = not _record_owed_user_action(request)if parked:diff --git a/hermes_cli/update_receipt.py b/hermes_cli/update_receipt.pyindex 0a70ea23d71..4682bff304c 100644--- a/hermes_cli/update_receipt.py+++ b/hermes_cli/update_receipt.py@@ -710,6 +710,32 @@ def finalize_pending_update_receipt(exit_code: Optional[int] = None, stop_reasonreturn finalize_update_receipt(outcome, stop_reason=stop_reason)+def resume_run_record() -> Optional[Path]:+ """Carry the open run forward from its own archive when another process took it further.++ The completion child resumes this process's snapshot and persists stages (or closes the run)+ the snapshot never saw; closing the run from that stale snapshot would erase them. Returns the+ archive when the run is already closed there (the open receipt is dropped: nothing is left to+ finalize), else None. Never raises.+ """+ current = _current.get()+ found = read_run_record(str(current.data.get("update_id"))) if current is not None else None+ if found is None:+ return None+ path, record = found+ if record.get("finished_at"):+ try:+ _current.reset(current.current_token)+ except ValueError: # token from another context: pop THIS context only+ _current.set(None)+ return path+ record.pop("writer_pid", None)+ clone = copy.copy(current)+ clone.data = record+ _current.set(clone)+ return None++def finalize_interrupted_update_receipt(stop_reason: str, *, exit_code: int = 130) -> Optional[Path]:"""Close a run the operator interrupted AFTER the commit point as ``interrupted``. Never raises.@@ -719,20 +745,14 @@ def finalize_interrupted_update_receipt(stop_reason: str, *, exit_code: int = 13"""print("⚠ Interrupted after the code was updated: the new code is in place; its remaining steps are owed ""and the next launch or `hermes update` finishes them.", flush=True)- current = _current.get()- if current is None:+ if _current.get() is None:return None+ closed = resume_run_record()+ if closed is not None: # the completion child already closed the run+ return closedwith suppress(Exception):- clone = copy.copy(current)- clone.data = copy.deepcopy(current.data)- found = read_run_record(str(current.data.get("update_id")))- if found is not None:- path, on_disk = found- if on_disk.get("finished_at"): # the completion child already closed the run- _current.reset(current.current_token)- return path- on_disk.pop("writer_pid", None)- clone.data = on_disk+ clone = copy.copy(_current.get())+ clone.data = copy.deepcopy(clone.data)clone.data["exit_code"] = int(exit_code)_current.set(clone)return finalize_update_receipt("interrupted", stop_reason=stop_reason)diff --git a/tests/hermes_cli/test_update_receipt_run_record.py b/tests/hermes_cli/test_update_receipt_run_record.pyindex 0db8d58532a..c60121d1274 100644--- a/tests/hermes_cli/test_update_receipt_run_record.py+++ b/tests/hermes_cli/test_update_receipt_run_record.py@@ -26,3 +26,17 @@ def test_lost_completion_over_a_malformed_run_archive_still_closes_the_run(_isolassert result["receipt"]["update_id"] == run["update_id"]assert result["receipt"]["outcome"] == "success"assert [row["step"] for row in result["receipt"]["followups"]] == ["completion"]+++def test_lost_completion_keeps_the_stages_the_completion_child_persisted(_isolate_hermes_home, tmp_path):+ # The child resumed the parent's snapshot, persisted its own progress, then died (OOM, SIGKILL).+ # The parent's pre-child snapshot is stale: closing the run from it would erase what ran.+ run, archive, request = _lost_run(tmp_path)+ progress = [{"name": "deps", "outcome": "success", "at": "t1"}, {"name": "build", "outcome": "failed", "at": "t2"}]+ update_receipt._persist_running({**run, "stages": progress})++ result = update_completion.settle_lost_completion(request, "the completion process exited -9")++ assert result["receipt"]["stages"][:2] == progress+ assert [row["step"] for row in result["receipt"]["followups"]] == ["completion"]+ assert update_receipt._current.get() is None # the parent's own receipt closed, nothing left open