The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(update): the commit point refuses without a fleet obligation and hands back only its own records (review F26, F21, F27, F22, F28)
Tekniumfcd2768c050a
diff --git a/hermes_cli/update_cmd_commit.py b/hermes_cli/update_cmd_commit.pyindex 27564757e7b..27932fcc50c 100644--- a/hermes_cli/update_cmd_commit.py+++ b/hermes_cli/update_cmd_commit.py@@ -37,6 +37,8 @@ from hermes_cli.update_custody import run_git# What this run found before it armed anything: {path: bytes or None}. None = nothing armed yet._armed_snapshot: Optional[dict[Path, Optional[bytes]]] = None+# What this run's latest arm left at each path: disarm hands back only records still exactly these.+_armed_bytes: dict[Path, Optional[bytes]] = {}# (git_cmd, (HEAD, branch)) when this run reached its checkout phase, and the checkout it names._run_start: Optional[tuple[list, tuple[str, str]]] = None_obligation_root: Optional[Path] = None@@ -53,19 +55,24 @@ def _obligation_paths(root: Path) -> list[Path]:from hermes_cli.update_host_obligation import host_obligation_pathfrom hermes_cli.venv_sync import completion_pending_path- paths = [completion_pending_path(root), _fleet_restart_pending_marker_path()]- host = host_obligation_path()- if host is not None:- paths.append(host)- return paths+ return [completion_pending_path(root), _fleet_restart_pending_marker_path(), host_obligation_path()]+++def _read_or_none(path: Path) -> Optional[bytes]:+ """The record's bytes, None when absent. Any other read error raises: custody is never guessed."""+ try:+ return path.read_bytes()+ except FileNotFoundError:+ return Nonedef arm_commit_obligations(root: Path, expected_sha: str) -> None:"""Owe the completion tail and the fleet restart for ``expected_sha`` BEFORE the tree moves.Idempotent within a run (the first call snapshots what to restore on a no-op failure). An- unwritable install state raises: nothing has moved yet, and moving without the obligation is- exactly the tail-never-runs state this exists to prevent.+ unwritable install state, an unreadable record or a fleet restart neither store accepted+ raises: nothing has moved yet, and moving without the obligation is exactly the+ tail-never-runs state this exists to prevent."""global _armed_snapshotfrom hermes_cli.update_cmd_fleet import _write_fleet_restart_pending_marker@@ -75,15 +82,14 @@ def arm_commit_obligations(root: Path, expected_sha: str) -> None:if _owns_live_checkout(root):returnif _armed_snapshot is None:- snapshot: dict[Path, Optional[bytes]] = {}- for path in _obligation_paths(root):- try:- snapshot[path] = path.read_bytes()- except OSError:- snapshot[path] = None- _armed_snapshot = snapshot- arm_completion(root)- _write_fleet_restart_pending_marker(expected_sha=expected_sha or "")+ _armed_snapshot = {path: _read_or_none(path) for path in _obligation_paths(root)}+ try:+ arm_completion(root)+ owed = _write_fleet_restart_pending_marker(expected_sha=expected_sha or "")+ finally: # even a half-done arm: disarm must still recognise what this run wrote+ _armed_bytes.update({path: _read_or_none(path) for path in _armed_snapshot})+ if not owed:+ raise OSError("could not record the pending gateway-restart obligation")def disarm_commit_obligations() -> None:@@ -100,8 +106,12 @@ def disarm_commit_obligations() -> None:if root is None or not start_head or head_and_branch(git_cmd, root)[0] != start_head:returnsnapshot, _armed_snapshot = _armed_snapshot, None+ armed = dict(_armed_bytes)+ _armed_bytes.clear()for path, data in (snapshot or {}).items():try:+ if path not in armed or _read_or_none(path) != armed[path]:+ continue # rewritten since this run armed it (another install's update): theirs nowif data is None:path.unlink(missing_ok=True)else:@@ -378,5 +388,6 @@ def preflight_refusal(git_cmd, root: Path, target_ref: str, critical_files) -> sdef reset_for_tests() -> None:global _armed_snapshot, _run_start, _obligation_root_armed_snapshot = None+ _armed_bytes.clear()_run_start = None_obligation_root = Nonediff --git a/hermes_cli/update_cmd_fleet.py b/hermes_cli/update_cmd_fleet.pyindex f37e91eb67a..d7eff376bfa 100644--- a/hermes_cli/update_cmd_fleet.py+++ b/hermes_cli/update_cmd_fleet.py@@ -82,8 +82,8 @@ def _write_legacy_fleet_restart_pending_marker(return False-def _write_fleet_restart_pending_marker(*, expected_sha: str = "", runtimes: list[dict] | None = None) -> None:- """Arm the HOST pull→restart obligation. Never raises.+def _write_fleet_restart_pending_marker(*, expected_sha: str = "", runtimes: list[dict] | None = None) -> bool:+ """Arm the HOST pull→restart obligation. Never raises; False when neither store took it.An unwritable host state dir (``HERMES_GATEWAY_LOCK_DIR`` on a read-only mount, a containerUID that does not own ``$HOME``) must never disarm the obligation: an update interrupted@@ -95,20 +95,20 @@ def _write_fleet_restart_pending_marker(*, expected_sha: str = "", runtimes: lis# An explicit empty inventory owes no restart (e.g. Desktop-hosted `serve` with no# gateway services). Arming the marker here leaves a breadcrumb nothing can discharge:# a no-gateway host would then fail every later ``hermes update`` (#115311).- return+ return Truefrom hermes_cli.update_cmd import _mfrom hermes_cli.update_host_obligation import host_obligation_path, write_host_obligationif _m()._pytest_owns_live_checkout(_fleet_restart_pending_marker_path().parent):logger.debug("Skipping fleet-restart-pending obligation under pytest (live checkout)")- return+ return Trueif write_host_obligation(expected_sha=expected_sha, runtimes=runtimes, profile=_current_profile_name()):- return+ return Trueif _write_legacy_fleet_restart_pending_marker(expected_sha=expected_sha, runtimes=runtimes):logger.warning("Host update-restart obligation (%s) is unwritable; armed the per-home marker %s instead.",host_obligation_path(), _fleet_restart_pending_marker_path())- return+ return Truelogger.error("Could not arm the update-restart obligation in %s or %s; an interrupted update will not warn.",host_obligation_path(), _fleet_restart_pending_marker_path())@@ -117,6 +117,7 @@ def _write_fleet_restart_pending_marker(*, expected_sha: str = "", runtimes: lis"restart gateways with `hermes gateway restart` if this update is interrupted.",file=sys.stderr,)+ return Falsedef _current_profile_name() -> str:diff --git a/tests/hermes_cli/test_update_commit_obligations.py b/tests/hermes_cli/test_update_commit_obligations.pynew file mode 100644index 00000000000..e4add6ae3dc--- /dev/null+++ b/tests/hermes_cli/test_update_commit_obligations.py@@ -0,0 +1,90 @@+"""The commit point's obligations: armed before the tree moves, handed back only when still ours.++``arm_commit_obligations`` owes the completion tail and the host fleet restart before git (or the+ZIP swap) writes a file; ``disarm_commit_obligations`` puts them back after a failure that left the+tree at its start commit. The host record is shared by every install of the OS user.+"""++from __future__ import annotations++import os+from pathlib import Path++import pytest++from hermes_cli import update_cmd_commit as commit+from hermes_cli.update_host_obligation import host_obligation_path++[email protected](autouse=True)+def _fresh_commit_point(tmp_path, monkeypatch):+ monkeypatch.setenv("HERMES_HOME", str(tmp_path / "home"))+ (tmp_path / "home").mkdir()+ commit.reset_for_tests()+ yield+ commit.reset_for_tests()+++def root(tmp_path) -> Path:+ install = tmp_path / "install"+ install.mkdir()+ return install+++def test_arm_refuses_when_no_store_accepts_the_fleet_restart(root):+ """Both the host record and the per-home breadcrumb unwritable: the move must not start (F26)."""+ from hermes_cli.update_cmd_fleet import _fleet_restart_pending_marker_path++ host_obligation_path().mkdir(parents=True) # a directory where the record goes+ _fleet_restart_pending_marker_path().mkdir(parents=True)++ with pytest.raises(OSError):+ commit.arm_commit_obligations(root, "b" * 40)+++def test_disarm_leaves_another_installs_newer_host_record(root):+ """A failed run hands back only what it armed: another install's record written since stays (F27)."""+ host = host_obligation_path()+ host.parent.mkdir(parents=True, exist_ok=True)+ host.write_text("OLD", encoding="utf-8")+ commit.arm_commit_obligations(root, "a" * 40)+ host.write_text("OTHER-INSTALL", encoding="utf-8")++ commit.disarm_commit_obligations()++ assert host.read_text(encoding="utf-8") == "OTHER-INSTALL"+++def test_plain_arm_and_disarm_restores_what_the_run_found(root):+ host = host_obligation_path()+ host.parent.mkdir(parents=True, exist_ok=True)+ host.write_text("OLD", encoding="utf-8")+ commit.arm_commit_obligations(root, "a" * 40)+ assert host.read_text(encoding="utf-8") != "OLD"++ commit.disarm_commit_obligations()++ assert host.read_text(encoding="utf-8") == "OLD"+++def test_an_unreadable_record_refuses_the_arm_and_survives(root, monkeypatch):+ """A read error is not absence: guessing 'none' would delete the record on disarm (F28)."""+ host = host_obligation_path()+ host.parent.mkdir(parents=True, exist_ok=True)+ host.write_text("OLD", encoding="utf-8")+ real = Path.read_bytes++ def flaky(self):+ if self == host:+ raise PermissionError(13, "sharing violation", str(self))+ return real(self)++ monkeypatch.setattr(Path, "read_bytes", flaky)+ with pytest.raises(OSError):+ commit.arm_commit_obligations(root, "a" * 40)+ monkeypatch.setattr(Path, "read_bytes", real)+ commit.disarm_commit_obligations()++ assert host.read_text(encoding="utf-8") == "OLD"+