Skip to content

The agent that grows with you

fix: an unwritable host restart record refuses the move on a multi-profile install

Teknium56c17174b297
diff --git a/hermes_cli/update_cmd_fleet.py b/hermes_cli/update_cmd_fleet.py
index fecaee647e7..61a9329cb4b 100644
--- a/hermes_cli/update_cmd_fleet.py
+++ b/hermes_cli/update_cmd_fleet.py
@@ -83,13 +83,16 @@ def _write_legacy_fleet_restart_pending_marker(
def _write_fleet_restart_pending_marker(*, expected_sha: str = "", runtimes: list[dict] | None = None, owner: str = "") -> bool:
- """Arm the HOST pull→restart obligation. Never raises; False when neither store took it.
+ """Arm the HOST pull→restart obligation. Never raises; False when no store every profile reads took it.
An unwritable host state dir (``HERMES_GATEWAY_LOCK_DIR`` on a read-only mount, a container
UID that does not own ``$HOME``) must never disarm the obligation: an update interrupted
after this point would then leave stale code running with no warning and no catch-up restart
(#117275). The legacy per-home marker — which every reader here still honours — carries it
- instead, and a host that can write neither says so out loud.
+ instead, and a host that can write neither says so out loud. That marker is visible to the
+ invoking profile only, so it settles the debt only on an install with no other profile: with
+ one, the other profiles would read "nothing owed", so the marker is still left for this
+ profile but the arm returns False and the commit point refuses to move (review S2).
"""
if runtimes == []:
# An explicit empty inventory owes no restart (e.g. Desktop-hosted `serve` with no
@@ -104,14 +107,18 @@ def _write_fleet_restart_pending_marker(*, expected_sha: str = "", runtimes: lis
if write_host_obligation(
expected_sha=expected_sha, runtimes=runtimes, profile=_current_profile_name(), owner=owner):
return True
- if _write_legacy_fleet_restart_pending_marker(expected_sha=expected_sha, runtimes=runtimes):
+ from hermes_cli.profiles import list_profile_names
+ others = len(list_profile_names()) > 1
+ if _write_legacy_fleet_restart_pending_marker(expected_sha=expected_sha, runtimes=runtimes) and not others:
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 True
logger.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())
+ "Could not arm the update-restart obligation in %s%s; an interrupted update will not warn.",
+ host_obligation_path(),
+ " (this profile's marker hides it from the other profiles)" if others
+ else f" or {_fleet_restart_pending_marker_path()}")
print(
" ⚠ Could not record the pending gateway-restart obligation (state dir not writable) — "
"restart gateways with `hermes gateway restart` if this update is interrupted.",
diff --git a/tests/hermes_cli/test_update_host_obligation.py b/tests/hermes_cli/test_update_host_obligation.py
index bffe0ac8e90..a005cb15b0d 100644
--- a/tests/hermes_cli/test_update_host_obligation.py
+++ b/tests/hermes_cli/test_update_host_obligation.py
@@ -198,6 +198,27 @@ def test_unwritable_host_state_dir_still_arms_the_obligation(two_profiles, no_li
lock_dir.chmod(0o700)
[email protected](getattr(os, "geteuid", lambda: 1)() == 0, reason="root ignores directory permissions")
+def test_unwritable_host_state_dir_never_hides_the_debt_from_another_profile(two_profiles, no_live_fleet, monkeypatch, tmp_path):
+ """With a second profile on the install, the arming profile's per-home marker is a debt the
+ other profile cannot see: it would read "no restart owed" for a tree about to move. Every
+ profile observes the debt, or the arm refuses and the commit point does not move (review S2).
+ """
+ for home in two_profiles.values():
+ (home / "config.yaml").write_text("{}\n", encoding="utf-8") # real, listed profiles
+ _enter(monkeypatch, two_profiles["coder"])
+ lock_dir = tmp_path / "gateway-locks"
+ lock_dir.mkdir(parents=True, exist_ok=True)
+ lock_dir.chmod(0o500)
+ try:
+ armed = fleet._write_fleet_restart_pending_marker(
+ expected_sha=SHA, runtimes=[{"kind": "gateway", "profile": "coder"}])
+ _enter(monkeypatch, two_profiles["writer"])
+ assert armed is False or fleet._fleet_restart_obligation_armed(), "writer cannot see the armed debt"
+ finally:
+ lock_dir.chmod(0o700)
+
+
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.