Skip to content

The agent that grows with you

fix: the dashboard update status certifies an outcome only from its own action's receipt

Teknium692ed13e59e8
diff --git a/hermes_cli/update_receipt.py b/hermes_cli/update_receipt.py
index 9aadd1117e2..8e7596500a6 100644
--- a/hermes_cli/update_receipt.py
+++ b/hermes_cli/update_receipt.py
@@ -156,6 +156,9 @@ class UpdateReceipt:
self.correlation_id = uuid.uuid4().hex
self.data["update_id"] = self.correlation_id
self.data["correlation_id"] = _launcher_correlation_id()
+ # The dashboard action that spawned this run: the receipt store is root-wide, so the
+ # action-status route certifies an outcome only from a receipt naming ITS action.
+ self.data["action_id"] = os.environ.get("HERMES_ACTION_ID", "").strip() or None
def step(self, name: str, ok: bool, detail: str = "") -> None:
self.data["steps"].append({"name": name, "ok": bool(ok), "detail": detail, "at": _utc_now_iso()})
@@ -746,6 +749,21 @@ def read_latest_receipt() -> Optional[dict[str, Any]]:
return None
+def read_receipt_for_action(action_id: str) -> Optional[dict[str, Any]]:
+ """Newest receipt written by the dashboard action ``action_id`` (``latest.json`` first, then
+ the retained archive), or None. Never raises."""
+ latest = read_latest_receipt()
+ if latest and latest.get("action_id") == action_id:
+ return latest
+ with suppress(Exception):
+ for path in sorted(_receipt_dir().glob("update_*.json"), key=lambda p: p.stat().st_mtime, reverse=True):
+ with suppress(Exception):
+ payload = json.loads(path.read_text(encoding="utf-8-sig"))
+ if isinstance(payload, dict) and payload.get("action_id") == action_id:
+ return payload
+ return None
+
+
def _profile_homes() -> list[tuple[str, Path]]:
"""``(profile, home)`` for the default home plus every valid named profile dir, sorted."""
from hermes_cli.profiles import _get_default_hermes_home, _get_profiles_root, _PROFILE_ID_RE
diff --git a/hermes_cli/web_routers/actions.py b/hermes_cli/web_routers/actions.py
index 30dea8f558b..f6c0845f2ea 100644
--- a/hermes_cli/web_routers/actions.py
+++ b/hermes_cli/web_routers/actions.py
@@ -346,9 +346,9 @@ def _completed_exit_code(
if durable_action_id:
return 0
if receipt is not None and receipt.get("outcome") in ("success", "partial"):
- # No in-memory result and no log marker (e.g. log rotated), but the
- # receipt proves a completed run: report its outcome rather than a
- # null clients time out on. ``partial`` maps to exit 1 like the CLI.
+ # No in-memory result and no log marker (e.g. log rotated), but THIS
+ # action's receipt proves a completed run: report its outcome rather than
+ # a null clients time out on. ``partial`` maps to exit 1 like the CLI.
return 0 if receipt["outcome"] == "success" else 1
return None
@@ -365,7 +365,7 @@ async def get_action_status(name: str, lines: int = 200):
tail = _tail_lines(log_dir / log_file_name, requested_lines)
durable_update_action_id = None
- update_receipt_summary = None
+ update_receipt_summary = action_receipt_summary = None
if name == "hermes-update":
# ``hermes update`` mirrors to the ROOT home's update.log (main_dashboard), never this
# dashboard's profile home: read it where it is written.
@@ -373,7 +373,9 @@ async def get_action_status(name: str, lines: int = 200):
durable_update_action_id = _durable_completed_update_action_id(
_tail_lines(get_default_hermes_root() / "logs" / "update.log", 2000))
- if durable_update_action_id != _latest_spawned_update_action_id(_tail_lines(log_dir / log_file_name, 2000)):
+ spawned_action_id = (_latest_spawned_update_action_id(_tail_lines(log_dir / log_file_name, 2000))
+ or _ACTION_IDS.get(name))
+ if durable_update_action_id != spawned_action_id:
# The root log is shared by every profile: another profile's (or an older) run's
# completion never certifies the action this dashboard started.
durable_update_action_id = None
@@ -386,14 +388,17 @@ async def get_action_status(name: str, lines: int = 200):
# dashboard restarting itself mid-action). Surface it so clients READ
# the outcome instead of inferring it from liveness probes.
# See #81193, #87359, #91277.
- update_receipt_summary = _latest_update_receipt_summary()
+ # The store is root-wide (every profile's runs): show THIS action's receipt when one exists.
+ update_receipt_summary = _latest_update_receipt_summary(spawned_action_id)
+ if spawned_action_id and (update_receipt_summary or {}).get("action_id") == spawned_action_id:
+ action_receipt_summary = update_receipt_summary
proc = _ACTION_PROCS.get(name)
if proc is None:
result = _ACTION_RESULTS.get(name)
running = False
pid = result.get("pid") if result else None
- exit_code = _completed_exit_code(result, durable_update_action_id, update_receipt_summary)
+ exit_code = _completed_exit_code(result, durable_update_action_id, action_receipt_summary)
else:
exit_code = proc.poll()
running = exit_code is None
@@ -420,22 +425,28 @@ def _read_latest_receipt() -> Optional[Dict[str, Any]]:
return None
-def _latest_update_receipt_summary() -> Optional[Dict[str, Any]]:
- """Compact summary of the latest receipt (written by EVERY ``hermes update`` run,
- incl. refused/failed), or None; never raises. Steps/skips stay in the full endpoint.
+def _latest_update_receipt_summary(action_id: Optional[str] = None) -> Optional[Dict[str, Any]]:
+ """Compact summary of dashboard action ``action_id``'s receipt when one exists, else of the
+ latest receipt (written by EVERY ``hermes update`` run, incl. refused/failed), or None; never
+ raises. Steps/skips stay in the full endpoint. ``action_id`` names the writer so a client
+ never credits another action's run.
Phase-1 bullet 3 (#91277): the receipt (written by EVERY ``hermes update`` run since #91283, including
refused and failed ones, with a ``latest.json`` pointer) is the durable success signal the Desktop and
dashboard should read instead of inferring outcomes from liveness probes across the update's stop/start
gap (#81193, #87359).
"""
- receipt = _read_latest_receipt()
+ receipt = None
+ if action_id:
+ from hermes_cli.update_receipt import read_receipt_for_action
+ receipt = read_receipt_for_action(action_id)
+ receipt = receipt or _read_latest_receipt()
if not receipt:
return None
try:
post = receipt.get("post_update") or {}
return {
- **{k: receipt.get(k) for k in ("outcome", "started_at", "finished_at")},
+ **{k: receipt.get(k) for k in ("outcome", "started_at", "finished_at", "action_id")},
"pre_sha": (receipt.get("pre_update") or {}).get("sha"),
"post_sha": post.get("sha"), "post_version": post.get("version"),
"fleet_states": sorted({str(e.get("state")) for e in receipt.get("fleet") or [] if isinstance(e, dict)}),
diff --git a/tests/hermes_cli/test_update_receipt_endpoint.py b/tests/hermes_cli/test_update_receipt_endpoint.py
index bcdc34fd144..e9d4d5daed4 100644
--- a/tests/hermes_cli/test_update_receipt_endpoint.py
+++ b/tests/hermes_cli/test_update_receipt_endpoint.py
@@ -32,6 +32,9 @@ def client():
return c
+_ACTION_ID = "d" * 32
+
+
def _write_receipt(tmp_path: Path, monkeypatch, *, outcome="success") -> dict:
receipt = {
"schema": 1,
@@ -40,6 +43,7 @@ def _write_receipt(tmp_path: Path, monkeypatch, *, outcome="success") -> dict:
"argv": ["hermes", "update"],
"pid": 12345,
"outcome": outcome,
+ "action_id": _ACTION_ID,
"pre_update": {"sha": "a" * 40, "version": "0.20.4"},
"post_update": {"sha": "b" * 40, "version": "0.20.5"},
"steps": [{"name": "pre_update_backup", "ok": True, "detail": "", "at": ""}],
@@ -91,6 +95,9 @@ class TestUpdateStatusReadsReceipt:
def _clear_registries(self, monkeypatch, tmp_path):
monkeypatch.setattr(_web_server_gateway, "_ACTION_LOG_DIR", tmp_path / "actions")
(tmp_path / "actions").mkdir(exist_ok=True)
+ # The dashboard's own log names the action it spawned; the receipt must name the same one.
+ (tmp_path / "actions" / "hermes-update.log").write_text(
+ f"=== hermes-update started 2026-08-23 07:00:00 {_ACTION_ID} ===\n", encoding="utf-8")
monkeypatch.setattr(_web_server_gateway, "_ACTION_PROCS", {})
monkeypatch.setattr(_web_server_gateway, "_ACTION_RESULTS", {})
monkeypatch.setattr(_web_server_gateway, "_ACTION_COMMANDS", {})
diff --git a/tests/hermes_cli/test_web_server_update_status.py b/tests/hermes_cli/test_web_server_update_status.py
index 7656849f5cb..132e486291b 100644
--- a/tests/hermes_cli/test_web_server_update_status.py
+++ b/tests/hermes_cli/test_web_server_update_status.py
@@ -86,3 +86,36 @@ class TestUpdateStatusRootLog:
own = status_after_root_completion(b_id)
assert own["exit_code"] == 0
assert own["action_id"] == b_id
+
+ @pytest.mark.parametrize("b_outcome", [None, "failed", "success"])
+ def test_root_latest_receipt_of_another_profile_never_certifies_this_action(self, monkeypatch, tmp_path, b_outcome):
+ # The receipt store is root-wide too: A's later success in latest.json must not become B's
+ # exit 0. Only a receipt naming B's action (found in the archive when A is latest) counts.
+ from hermes_cli import update_receipt
+
+ root = tmp_path / "root"
+ (root / "logs").mkdir(parents=True)
+ b_id, a_id = "b" * 32, "a" * 32
+ for profile, action_id, outcome in (("b", b_id, b_outcome), ("a", a_id, "success")):
+ if outcome:
+ monkeypatch.setenv("HERMES_HOME", str(root / "profiles" / profile))
+ monkeypatch.setenv("HERMES_ACTION_ID", action_id)
+ update_receipt.begin_update_receipt()
+ update_receipt.finalize_update_receipt(outcome)
+ monkeypatch.delenv("HERMES_ACTION_ID")
+ monkeypatch.setenv("HERMES_HOME", str(root / "profiles" / "b"))
+ assert update_receipt.read_latest_receipt()["action_id"] == a_id
+ (tmp_path / "hermes-update.log").write_text(
+ f"=== hermes-update started 2026-08-17 11:19:34 {b_id} ===\n", encoding="utf-8")
+ (root / "logs" / "update.log").write_text(f"=== hermes-update completed {a_id} ===\n", encoding="utf-8")
+ monkeypatch.setattr(_web_server_gateway, "_ACTION_LOG_DIR", tmp_path)
+ for registry in ("_ACTION_PROCS", "_ACTION_RESULTS", "_ACTION_COMMANDS", "_ACTION_IDS"):
+ monkeypatch.setattr(_web_server_gateway, registry, {})
+
+ data = self.client.get("/api/actions/hermes-update/status?lines=2000").json()
+
+ assert data["exit_code"] == (0 if b_outcome == "success" else None)
+ assert "action_id" not in data # A's root completion marker is not B's
+ # The attached receipt names its writer: B's own when it exists, else A's (never B's).
+ assert data["receipt"]["action_id"] == (b_id if b_outcome else a_id)
+ assert data["receipt"]["outcome"] == (b_outcome or "success")