Skip to content

The agent that grows with you

fix(update): trim SHA-less obligation salvage to the checkout fallback (#125952, salvage #125964)

teknium1f46c7159e42b
diff --git a/hermes_cli/update_cmd.py b/hermes_cli/update_cmd.py
index 47b40154ac1..5c60cc906dd 100644
--- a/hermes_cli/update_cmd.py
+++ b/hermes_cli/update_cmd.py
@@ -724,10 +724,9 @@ def _complete_source_update(request: dict | None) -> None:
current = _completion_receipt._current.get()
if current is not None:
request["receipt"] = deepcopy(current.data)
- _write_fleet_restart_pending_marker(
- expected_sha=request.get("expected_sha")
- or _completion_receipt._receipt_post_update_sha(request["receipt"])
- )
+ # A head capture that came back empty must not arm an SHA-less record: it names no code the
+ # fleet can be proven current on, so the warning could never clear (#125952).
+ _write_fleet_restart_pending_marker(expected_sha=request.get("expected_sha") or _current_checkout_sha() or "")
result = run_completion(request)
_accept_completion_pm_receipt(result.get("pm_receipt"), request["receipt"]["update_id"])
token = request["windows_resume"]
diff --git a/hermes_cli/update_cmd_fleet.py b/hermes_cli/update_cmd_fleet.py
index 080efe89b9a..765fae19a61 100644
--- a/hermes_cli/update_cmd_fleet.py
+++ b/hermes_cli/update_cmd_fleet.py
@@ -387,10 +387,9 @@ def _marker_only_restart_obsolete() -> bool:
that died before its inventory was recorded, #115638) clears once every live gateway is
current on the checkout — there is no recorded owed set, so the fleet running the code on disk
is the whole of the evidence the marker's warning can be about, even after HEAD moved past
- ``expected_sha`` by an out-of-band pull. An inventory-less record armed with no SHA at all
- (a no-op update whose head capture failed, #125952) settles by the same live-fleet evidence
- once the process that armed it is gone: a status call must not discharge a restart phase
- that is still running. With no live gateway at all, the inventory-less marker
+ ``expected_sha`` by an out-of-band pull — and so does an inventory-less record armed with no
+ SHA at all (a no-op update whose head capture failed, #125952): with no owed set and no SHA,
+ the checkout is the only code it can be held to. With no live gateway at all, the inventory-less marker
asks the host instead (``update_cmd_fleet_gatewayless``): it clears when no profile left a
gateway that should be running and every live runtime is supervisor-owned or handed off, so a
Desktop-only install stops failing every later update (#118742).
@@ -421,23 +420,10 @@ def _marker_only_restart_obsolete() -> bool:
_clear_fleet_restart_pending_marker()
logger.debug("Fleet-restart-pending marker discharged: no gateway obligation recorded")
return True
- if not expected_sha:
- if owed is not None:
- return False # an inventoried obligation without its SHA can never be proven
- # An inventory-less record armed with no SHA (a no-op update whose head capture
- # failed, #125952) has no equality gate to hold it to; the fleet running the
- # checkout code is the whole of the evidence, but never discharge an update
- # whose arming process may still be mid-restart-phase.
- from hermes_cli._subprocess_compat import pid_exists_stdlib
-
- try:
- armer_pid = int(fields.get("pid", "") or 0)
- except ValueError:
- return False
- if armer_pid > 0 and pid_exists_stdlib(armer_pid):
- return False
+ if owed is not None and not expected_sha:
+ return False # an inventoried obligation without its SHA can never be proven
checkout_sha = _current_checkout_sha()
- if expected_sha and owed is not None and checkout_sha != expected_sha and not checkout_contains(expected_sha):
+ if owed is not None and checkout_sha != expected_sha and not checkout_contains(expected_sha):
return False # a newer pull moved HEAD; it owns a fresh obligation
# HEAD may sit past ``expected_sha`` by a carried local commit (a cherry-picked hotfix) that no
# pull made and no fresh obligation covers; the fleet is held to the code it actually runs, which
@@ -452,8 +438,8 @@ def _marker_only_restart_obsolete() -> bool:
logger.debug("Fleet probe failed; keeping fleet-restart-pending marker: %s", exc)
return False
if not fleet:
- if owed is not None:
- return False # Absence cannot prove recovery of the recorded inventory.
+ if owed is not None or not expected_sha:
+ return False # Absence cannot prove recovery of the recorded inventory / unnamed code.
return _discharge_gatewayless_marker(checkout_sha, expected_sha)
covered = _fleet_covered_gateways(fleet)
if covered is None:
diff --git a/hermes_cli/update_host_obligation.py b/hermes_cli/update_host_obligation.py
index cc9ec15658d..23a6ae62c3d 100644
--- a/hermes_cli/update_host_obligation.py
+++ b/hermes_cli/update_host_obligation.py
@@ -154,10 +154,6 @@ def obligation_fields() -> Optional[dict[str, str]]:
if record is None:
return None
fields = {"expected_sha": str(record.get("expected_sha") or "")}
- pid = record.get("pid")
- if pid is not None:
- # The arming process, for readers that must not discharge a still-running update.
- fields["pid"] = str(pid)
inventory = record.get("inventory")
if inventory is not None:
fields["inventory"] = json.dumps(inventory)
diff --git a/hermes_cli/update_receipt.py b/hermes_cli/update_receipt.py
index aad20505512..c1d6ddf4664 100644
--- a/hermes_cli/update_receipt.py
+++ b/hermes_cli/update_receipt.py
@@ -172,24 +172,6 @@ class UpdateReceipt:
self.data["post_update"] = _code_identity(refresh=True)
-def _receipt_post_update_sha(receipt: Any) -> str:
- """The SHA the completed receipt says the checkout ended on, else ``""``.
-
- Arming the host restart obligation with an empty SHA leaves a record the reader can
- never prove discharged (#125952); the receipt carried in the same completion request
- already names the code a no-op update stood on.
- """
- if not isinstance(receipt, dict):
- return ""
- post_update = receipt.get("post_update")
- if isinstance(post_update, dict) and post_update.get("sha"):
- return str(post_update["sha"])
- pre_update = receipt.get("pre_update")
- if isinstance(pre_update, dict) and pre_update.get("sha"):
- return str(pre_update["sha"])
- return ""
-
-
def _receipt_dir() -> Path:
# ``hermes_constants`` (stdlib-only), never ``hermes_cli.config``: the receipt must be
# writable from the refused/failed paths where config loading itself may be what broke
diff --git a/tests/hermes_cli/test_update_fleet_restart_pending.py b/tests/hermes_cli/test_update_fleet_restart_pending.py
index 68bd9c675ec..0168e7f7f5a 100644
--- a/tests/hermes_cli/test_update_fleet_restart_pending.py
+++ b/tests/hermes_cli/test_update_fleet_restart_pending.py
@@ -1077,27 +1077,13 @@ def test_second_profile_attaches_to_completed_host_restart(monkeypatch):
# the warning could never clear even with every live gateway current on the checkout.
-def _write_sha_less_obligation(pid: int = 424242) -> None:
- """Arm the poisoned shape verbatim: no SHA, no inventory, a known arming pid."""
+def test_startup_warn_discharged_when_sha_less_marker_fleet_current(monkeypatch, capsys):
+ checkout = "e" * 40
path = host_obligation.host_obligation_path()
- assert path is not None
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(json.dumps({
- "version": 1, "started": 0.0, "pid": pid, "armed_by_profile": "default",
- "expected_sha": "",
+ "version": 1, "started": 0.0, "pid": 424242, "armed_by_profile": "default", "expected_sha": "",
}), encoding="utf-8")
-
-
-def _patch_armer_liveness(monkeypatch, alive_pids: set[int]) -> None:
- monkeypatch.setattr(
- "hermes_cli._subprocess_compat.pid_exists_stdlib", lambda pid: int(pid) in alive_pids
- )
-
-
-def test_startup_warn_discharged_when_sha_less_marker_fleet_current(monkeypatch, capsys):
- checkout = "e" * 40
- _write_sha_less_obligation()
- _patch_armer_liveness(monkeypatch, set()) # the update that armed it is gone
_patch_marker_sha(monkeypatch, checkout)
monkeypatch.setattr(
"hermes_cli.update_receipt.collect_fleet_versions",
@@ -1112,57 +1098,18 @@ def test_startup_warn_discharged_when_sha_less_marker_fleet_current(monkeypatch,
assert not update_cmd_fleet._fleet_restart_obligation_armed()
-def test_startup_warn_kept_when_sha_less_marker_armer_still_alive(monkeypatch, capsys):
- """A status call must not discharge an update that is still mid-restart-phase."""
+def test_completion_arms_obligation_with_checkout_sha_when_head_capture_empty(monkeypatch):
+ """The armer must never record the poisoned shape: an empty head capture falls back to the
+ checkout identity the reader compares the fleet against."""
checkout = "e" * 40
- _write_sha_less_obligation()
- _patch_armer_liveness(monkeypatch, {424242}) # the arming update is still running
_patch_marker_sha(monkeypatch, checkout)
- monkeypatch.setattr(
- "hermes_cli.update_receipt.collect_fleet_versions",
- lambda **kwargs: [
- {"profile": "default", "pid": 42, "code_sha": checkout, "code_version": "0.21.5", "state": "current"}
- ],
- )
-
- update_cmd._warn_pending_fleet_restart_on_startup()
-
- assert "did not restart running gateways" in capsys.readouterr().err
- assert update_cmd_fleet._fleet_restart_obligation_armed()
+ armed = []
+ monkeypatch.setattr(update_cmd, "_write_fleet_restart_pending_marker", lambda **kw: armed.append(kw["expected_sha"]))
+ monkeypatch.setattr(update_cmd, "run_completion", lambda request: {"exit_code": 0})
+ monkeypatch.setattr(update_cmd, "_accept_completion_pm_receipt", lambda *a: None)
+ monkeypatch.setattr(update_cmd, "adopt_retired_channel", lambda request: False)
+ update_cmd._complete_source_update(
+ {"expected_sha": "", "receipt": {"update_id": "u1"}, "windows_resume": None})
-def test_startup_warn_kept_when_sha_less_marker_fleet_stale(monkeypatch, capsys):
- checkout = "e" * 40
- _write_sha_less_obligation()
- _patch_armer_liveness(monkeypatch, set())
- _patch_marker_sha(monkeypatch, checkout)
- monkeypatch.setattr(
- "hermes_cli.update_receipt.collect_fleet_versions",
- lambda **kwargs: [
- {"profile": "default", "pid": 42, "code_sha": "7" * 40, "code_version": "0.20.0", "state": "stale"}
- ],
- )
-
- update_cmd._warn_pending_fleet_restart_on_startup()
-
- assert "did not restart running gateways" in capsys.readouterr().err
- assert update_cmd_fleet._fleet_restart_obligation_armed()
-
-
-def test_startup_warn_kept_when_inventory_present_but_sha_less(monkeypatch, capsys):
- """An inventoried obligation without its SHA can never be proven: fail closed."""
- checkout = "e" * 40
- _write_sha_less_obligation()
- host_obligation.amend_host_obligation(inventory={"version": 1, "runtimes": [{"kind": "gateway", "profile": "default"}]})
- _patch_marker_sha(monkeypatch, checkout)
- monkeypatch.setattr(
- "hermes_cli.update_receipt.collect_fleet_versions",
- lambda **kwargs: [
- {"profile": "default", "pid": 42, "code_sha": checkout, "code_version": "0.21.5", "state": "current"}
- ],
- )
-
- update_cmd._warn_pending_fleet_restart_on_startup()
-
- assert "did not restart running gateways" in capsys.readouterr().err
- assert update_cmd_fleet._fleet_restart_obligation_armed()
+ assert armed == [checkout]