The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(update): a failed repair counts its attempt on a marker that is not valid UTF-8
Teknium34b80709f88b
diff --git a/hermes_cli/_early_recovery.py b/hermes_cli/_early_recovery.pyindex 0acfbb4554c..86d623cfb2b 100644--- a/hermes_cli/_early_recovery.py+++ b/hermes_cli/_early_recovery.py@@ -1238,7 +1238,8 @@ def _count_failed_attempt(marker: Path) -> None:# Best-effort: an unwritable marker only means the limit trips later.with contextlib.suppress(OSError):attempts = _read_marker_attempts(marker) + 1- body = marker.read_text(encoding="utf-8-sig")+ # Our own record: undecodable bytes must not raise UnicodeDecodeError on every launch.+ body = marker.read_text(encoding="utf-8-sig", errors="replace")if any(line.startswith("pid=") for line in body.splitlines()):lines = [line for line in body.splitlines() if not line.startswith("attempts=")]body = "\n".join([*lines, f"attempts={attempts}"]) + "\n"diff --git a/tests/hermes_cli/test_early_recovery.py b/tests/hermes_cli/test_early_recovery.pyindex 1ce7f2953f0..cadc7fdfc6c 100644--- a/tests/hermes_cli/test_early_recovery.py+++ b/tests/hermes_cli/test_early_recovery.py@@ -262,3 +262,14 @@ def test_marker_attempts_from_a_hand_edited_body_are_a_nonnegative_int(tmp_path,marker.write_text(body, encoding="utf-8")attempts = er._read_marker_attempts(marker)assert type(attempts) is int and attempts >= 0+++def test_a_failed_repair_counts_its_attempt_even_on_an_undecodable_marker(tmp_path):+ """The attempt bump read the marker strictly, inside only suppress(OSError): a non-UTF-8 marker+ raised UnicodeDecodeError out of every launch's failed repair (review C6)."""+ marker = tmp_path / ".update-incomplete"+ marker.write_bytes(b"pid=1\nstash=\xff\xfe\n")++ er._count_failed_attempt(marker)++ assert er._read_marker_attempts(marker) == 1