Skip to content

The agent that grows with you

fix(update): a carried local commit no longer strands the fleet-restart obligation

teknium130056d612b04
diff --git a/hermes_cli/update_cmd_fleet.py b/hermes_cli/update_cmd_fleet.py
index 0151384a755..578114efaf4 100644
--- a/hermes_cli/update_cmd_fleet.py
+++ b/hermes_cli/update_cmd_fleet.py
@@ -346,6 +346,7 @@ def _marker_only_restart_obsolete() -> bool:
``update_inventory.report_unaccounted_runtimes``, which prints it and exits 1 when the restart
phase never touched it — this marker only stops re-warning about it on every later startup.
"""
+ from hermes_cli.update_cmd_fleet_checkout import checkout_contains
from hermes_cli.update_serve_obligations import defer_manual_serve
try:
@@ -387,9 +388,12 @@ def _marker_only_restart_obsolete() -> bool:
if not expected_sha:
return False
checkout_sha = _current_checkout_sha()
- if owed is not None and checkout_sha != 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
- target_sha = expected_sha if owed is not None else checkout_sha
+ # 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
+ # is what an equality gate on ``expected_sha`` could never discharge (#119367).
+ target_sha = checkout_sha
if not target_sha:
return False
try:
diff --git a/hermes_cli/update_cmd_fleet_checkout.py b/hermes_cli/update_cmd_fleet_checkout.py
new file mode 100644
index 00000000000..2d7dfffc1b2
--- /dev/null
+++ b/hermes_cli/update_cmd_fleet_checkout.py
@@ -0,0 +1,30 @@
+"""Checkout ancestry for the update-restart obligation (``update_cmd_fleet`` sibling).
+
+The obligation records the SHA a pull landed on; the checkout may later sit past it by a carried
+local commit (a cherry-picked hotfix). Whether that recorded SHA is still *contained* in HEAD is
+the question these readers ask, so the live fleet can be held to the code on disk (#119367).
+"""
+
+from __future__ import annotations
+
+import logging
+import subprocess
+
+logger = logging.getLogger(__name__)
+
+
+def checkout_contains(sha: str) -> bool:
+ """True when ``sha`` is an ancestor of (or equal to) the checkout HEAD; False on any probe failure.
+
+ Fail-closed on purpose: an unknown ancestry is not evidence that the fleet serves the update.
+ """
+ from hermes_cli.update_cmd import _m
+ try:
+ result = subprocess.run(
+ ["git", "merge-base", "--is-ancestor", sha, "HEAD"],
+ cwd=_m().PROJECT_ROOT, capture_output=True, text=True, timeout=10,
+ )
+ return result.returncode == 0
+ except Exception as exc:
+ logger.debug("Checkout ancestry probe for %s failed: %s", sha[:10], exc)
+ return False
diff --git a/tests/hermes_cli/test_update_fleet_restart_pending.py b/tests/hermes_cli/test_update_fleet_restart_pending.py
index b2c45a630d2..49b96664a3c 100644
--- a/tests/hermes_cli/test_update_fleet_restart_pending.py
+++ b/tests/hermes_cli/test_update_fleet_restart_pending.py
@@ -866,7 +866,7 @@ def test_startup_warn_kept_when_inventory_holds_unclassified_serve(monkeypatch,
("e" * 40, []), # probe answered empty: no proof either way
("e" * 40, [{"profile": "default", "pid": 42, "code_sha": None, "code_version": None, "state": "unknown"}]),
(None, [{"profile": "default", "code_sha": "e" * 40, "state": "current"}]),
- # checkout advanced past the marker: a newer pull owns a fresh obligation
+ # checkout moved to a commit unrelated to the marker's SHA: a newer pull owns a fresh obligation
("f" * 40, [{"profile": "default", "pid": 42, "code_sha": "e" * 40, "code_version": None, "state": "current"}]),
],
ids=["stale-row", "empty-probe", "unknown-identity", "unknown-checkout", "checkout-moved"],
@@ -882,6 +882,69 @@ def test_startup_warn_kept_without_positive_evidence(monkeypatch, capsys, disk_s
assert update_cmd_fleet._fleet_restart_obligation_armed()
+# ── Carried local commits: HEAD past ``expected_sha`` with no pull behind it (#119367) ──
+#
+# A cherry-picked hotfix on top of the pulled SHA moves HEAD without arming a fresh obligation,
+# so an equality gate on ``expected_sha`` could never discharge the old one: every CLI start
+# warned and every no-op ``hermes update`` exited 1 while the gateway verifiably served HEAD.
+
+
+def _checkout_with_carried_commit(monkeypatch, tmp_path):
+ """A real checkout: the update's SHA plus one local commit on top; returns (expected, head)."""
+ import subprocess
+
+ repo = tmp_path / "checkout"
+ repo.mkdir()
+
+ def git(*args):
+ return subprocess.run(["git", *args], cwd=repo, capture_output=True, text=True, check=True).stdout.strip()
+
+ git("init", "-q", "-b", "main")
+ git("config", "user.email", "t@t")
+ git("config", "user.name", "t")
+ (repo / "a").write_text("1")
+ git("add", "a")
+ git("commit", "-qm", "pulled")
+ expected = git("rev-parse", "HEAD")
+ (repo / "b").write_text("2")
+ git("add", "b")
+ git("commit", "-qm", "carried hotfix")
+ head = git("rev-parse", "HEAD")
+ monkeypatch.setattr(hermes_main, "PROJECT_ROOT", repo)
+ _patch_marker_sha(monkeypatch, head)
+ return expected, head
+
+
+def test_obligation_discharges_when_gateway_serves_descendant_of_expected_sha(monkeypatch, tmp_path, capsys):
+ expected, head = _checkout_with_carried_commit(monkeypatch, tmp_path)
+ update_cmd._write_fleet_restart_pending_marker(expected_sha=expected, runtimes=[{"kind": "gateway", "profile": "default"}])
+ monkeypatch.setattr(
+ "hermes_cli.update_receipt.collect_fleet_versions",
+ lambda **kwargs: [{"profile": "default", "pid": 42, "code_sha": head, "code_version": "0.21.4", "state": "current"}],
+ )
+ monkeypatch.setattr(update_cmd, "_run_pending_fleet_restart", lambda: pytest.fail("nothing to restart"))
+
+ update_cmd._apply_pending_fleet_restart_catchup() # must not sys.exit(1)
+ update_cmd._warn_pending_fleet_restart_on_startup()
+
+ assert capsys.readouterr().err == ""
+ assert not update_cmd_fleet._fleet_restart_obligation_armed()
+
+
+def test_obligation_kept_when_gateway_serves_stale_code_on_carried_checkout(monkeypatch, tmp_path, capsys):
+ expected, _head = _checkout_with_carried_commit(monkeypatch, tmp_path)
+ update_cmd._write_fleet_restart_pending_marker(expected_sha=expected, runtimes=[{"kind": "gateway", "profile": "default"}])
+ monkeypatch.setattr(
+ "hermes_cli.update_receipt.collect_fleet_versions",
+ lambda **kwargs: [{"profile": "default", "pid": 42, "code_sha": "0" * 40, "code_version": "0.21.3", "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_receipt_owed_gateway_is_down(monkeypatch, capsys):
"""A sibling the restart phase killed yields no startup row; the marker still owns it."""
disk_sha = "e" * 40