The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: a completed restart never deletes the unkeyed restart debt another install armed
Teknium2163e536db56
diff --git a/hermes_cli/update_host_obligation.py b/hermes_cli/update_host_obligation.pyindex b992f0581d8..442f47e758b 100644--- a/hermes_cli/update_host_obligation.py+++ b/hermes_cli/update_host_obligation.py@@ -35,8 +35,8 @@ from typing import Any, Callable, Iterable, Optionallogger = logging.getLogger("hermes_cli.update_cmd")#: The record before it carried an install key, beside ``host-gateway.json`` / ``host-serve.json``.-#: Still read, and cleared on discharge, so a debt an older release armed survives the upgrade; it-#: names no install, so it keeps its old meaning: owed by whichever install reads it.+#: Still read, and cleared by a discharge that judged it, so a debt an older release armed survives+#: the upgrade; it names no install, so it keeps its old meaning: owed by whichever install reads it.HOST_OBLIGATION_NAME = "host-update-restart.json"_RECORD_VERSION = 1@@ -305,13 +305,18 @@ def replace_bytes(path: Path, data: bytes) -> None:def clear_host_obligation() -> None:- """Discharge this install's obligation (and an older release's unkeyed one). Never raises."""- path = host_obligation_path()- for owed in (path, path.with_name(HOST_OBLIGATION_NAME)):- try:- owed.unlink(missing_ok=True)- except OSError as exc:- logger.debug("Could not clear host update-restart obligation: %s", exc)+ """Discharge the record this install's readers judged (``_owed_path``). Never raises.++ That is this install's own record whenever it has one. An older release's unkeyed record names+ no install: while this install has its own record, the unkeyed one may be another+ installation's standing debt that nothing here judged, so it stays (review S3 residual). It goes+ only when it was the record judged (this install armed none): it keeps its old meaning, owed by+ whichever install reads it, and an upgrade's own interrupted debt must stay dischargeable.+ """+ try:+ _owed_path().unlink(missing_ok=True)+ except OSError as exc:+ logger.debug("Could not clear host update-restart obligation: %s", exc)def obligation_fields() -> Optional[dict[str, str]]:diff --git a/tests/hermes_cli/test_update_host_obligation.py b/tests/hermes_cli/test_update_host_obligation.pyindex 118bbf86968..d749546e548 100644--- a/tests/hermes_cli/test_update_host_obligation.py+++ b/tests/hermes_cli/test_update_host_obligation.py@@ -255,6 +255,32 @@ def test_one_installs_completed_restart_never_erases_another_installs_debt(tmp_passert run("install-b", "print(host_obligation_present())") == "False"[email protected]("a_sha", ["a" * 40, "b" * 40])+def test_a_completion_never_erases_the_unkeyed_debt_an_older_install_armed(tmp_path, monkeypatch, a_sha):+ """Install A still runs a release that writes the unkeyed record; install B (this release) armed+ its own keyed record. B's completed restart judged only B's record, so A's debt must survive it,+ whether the SHAs differ or match. With no record of its own, B honours the unkeyed one and its+ discharge clears it: an upgrade's own interrupted debt never sticks (review S3 residual)."""+ lock_dir = tmp_path / "gateway-locks"+ monkeypatch.setenv("HERMES_GATEWAY_LOCK_DIR", str(lock_dir))+ legacy = lock_dir / host_obligation.HOST_OBLIGATION_NAME++ def a_arms() -> None: # the older release's writer: unkeyed name, no owners, no mutex+ lock_dir.mkdir(parents=True, exist_ok=True)+ legacy.write_text(json.dumps({"version": 1, "pid": 1, "expected_sha": a_sha}), encoding="utf-8")++ assert host_obligation.write_host_obligation(expected_sha="b" * 40, owner="run-b")+ a_arms()+ host_obligation.mark_host_restart_completed("b" * 40)+ host_obligation.clear_host_obligation()++ assert json.loads(legacy.read_text(encoding="utf-8"))["expected_sha"] == a_sha+ assert (host_obligation.read_host_obligation() or {}).get("expected_sha") == a_sha++ host_obligation.clear_host_obligation() # B now owns no record: the unkeyed one is what it judged+ assert not host_obligation.host_obligation_present()++def test_unreadable_host_record_is_never_discharged_by_the_legacy_marker(two_profiles, no_live_fleet, monkeypatch, tmp_path):"""A record whose terms are UNKNOWN cannot be settled by another record's terms.diff --git a/website/docs/getting-started/updating.md b/website/docs/getting-started/updating.mdindex 3247731f60d..85ac6ab9478 100644--- a/website/docs/getting-started/updating.md+++ b/website/docs/getting-started/updating.md@@ -288,7 +288,7 @@ The same inventory is embedded in every real update's receipt (`~/.hermes/logs/uEvery `hermes update` run writes a machine-readable receipt to `~/.hermes/logs/update_receipts/` (last 20 kept, `latest.json` always points at the most recent): the pre-update fleet plan, each step taken, anything skipped and why, the gateway restart outcome, and the final fleet version matrix. The SQLite runtime repair is one of those steps (`sqlite_runtime_repair`): a failed repair records the actual reason (for example the `uv sync` error) and the SQLite version pair, a deferred or not-applicable repair lands in the skips with its reason. After the restart phase the updater compares each live gateway's running code against the freshly updated checkout and prints a per-profile matrix — a gateway still serving pre-update code is reported loudly with the exact restart command and recorded as a `gateway_restart` follow-up in the receipt; the code is already in place, so the update still exits 0, and every later command warns until the fleet serves the new code, so a mixed-version fleet is never silently healthy. Both `--plan` and the fleet check ask each running gateway directly over its local control socket (`gateway.sock` in the profile's data directory, a named pipe on Windows) when available, so version and supervisor information comes from the gateway itself; gateways from older versions are still discovered through their state files as before.-A multiplexed default gateway is one process serving several profiles, so it appears once in the matrix and vouches for every profile in its `served_profiles` record. The same coverage clears the "A previous `hermes update` pulled new code but did not restart running gateways" hint: once that gateway (or, after a manual `git pull`, every gateway an update restarted) runs the current code, `hermes gateway restart` is enough — the hint no longer waits for the next `hermes update` to write a fresh receipt. The same is true of the restart obligation left by an update that died before recording which gateways it owed (or by an older updater that never recorded them): once every live gateway runs the current checkout, the obligation is retired and the hint stops. On a host that runs no gateway at all (the Desktop app alone), it is retired once no profile has a gateway that went away without a clean stop and every running backend is restarted by its own supervisor or has its own reminder. That obligation is recorded once per HOST, in the cross-profile rendezvous directory (`$HERMES_GATEWAY_LOCK_DIR`, else `$XDG_STATE_HOME/hermes/gateway-locks`) as `host-update-restart-<install key>.json` (one per installation, so a second Hermes checkout for the same user keeps its own), so every profile's CLI sees the same one: `hermes -p coder update` and `hermes -p writer update` restart the shared multiplexed gateway once between them, not once each. An obligation left behind by an older per-profile updater (`fleet_restart_pending` in one profile's Hermes home) is still read and cleared. An update whose pre-update plan found no gateway at all owes nothing and leaves no breadcrumb. A backend supervised by Desktop, systemd or launchd is restarted by its supervisor and never blocks this settlement; only a manual backend whose reminder could not be saved keeps the obligation open.+A multiplexed default gateway is one process serving several profiles, so it appears once in the matrix and vouches for every profile in its `served_profiles` record. The same coverage clears the "A previous `hermes update` pulled new code but did not restart running gateways" hint: once that gateway (or, after a manual `git pull`, every gateway an update restarted) runs the current code, `hermes gateway restart` is enough — the hint no longer waits for the next `hermes update` to write a fresh receipt. The same is true of the restart obligation left by an update that died before recording which gateways it owed (or by an older updater that never recorded them): once every live gateway runs the current checkout, the obligation is retired and the hint stops. On a host that runs no gateway at all (the Desktop app alone), it is retired once no profile has a gateway that went away without a clean stop and every running backend is restarted by its own supervisor or has its own reminder. That obligation is recorded once per HOST, in the cross-profile rendezvous directory (`$HERMES_GATEWAY_LOCK_DIR`, else `$XDG_STATE_HOME/hermes/gateway-locks`) as `host-update-restart-<install key>.json` (one per installation, so a second Hermes checkout for the same user keeps its own; an older release's unkeyed `host-update-restart.json` is honoured and cleared only by an installation that has no record of its own, so another checkout still on that release keeps its debt), so every profile's CLI sees the same one: `hermes -p coder update` and `hermes -p writer update` restart the shared multiplexed gateway once between them, not once each. An obligation left behind by an older per-profile updater (`fleet_restart_pending` in one profile's Hermes home) is still read and cleared. An update whose pre-update plan found no gateway at all owes nothing and leaves no breadcrumb. A backend supervised by Desktop, systemd or launchd is restarted by its supervisor and never blocks this settlement; only a manual backend whose reminder could not be saved keeps the obligation open.### Manual backend restart reminders