The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(update): record Desktop's correlation_id in the update receipt
Austin Pickett90b0b215377d
diff --git a/hermes_cli/update_receipt.py b/hermes_cli/update_receipt.pyindex c6ce017d39e..b1a6c72c7dc 100644--- a/hermes_cli/update_receipt.py+++ b/hermes_cli/update_receipt.py@@ -103,6 +103,15 @@ def _str_records(entries: Any, keys: tuple[str, ...], *, pid: bool = False) -> lreturn records+def _launcher_correlation_id() -> Optional[str]:+ """Correlation id handed in by an external launcher, or None.++ Desktop's managed SSH update exports ``HERMES_UPDATE_CORRELATION_ID`` and+ only accepts a receipt whose ``correlation_id`` equals it. This is separate+ from ``update_id``, which stays the CLI's own id for pm sync receipts."""+ return os.environ.get("HERMES_UPDATE_CORRELATION_ID", "").strip() or None++class UpdateReceipt:"""Collects the observable facts of one ``hermes update`` run."""@@ -118,6 +127,7 @@ class UpdateReceipt:# (pm.receipt captures it via the _correlation ContextVar).self.correlation_id = uuid.uuid4().hexself.data["update_id"] = self.correlation_id+ self.data["correlation_id"] = _launcher_correlation_id()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()})@@ -201,6 +211,8 @@ def begin_update_receipt(*, previous: dict | None = None, correlation_id: str |receipt.data.update(copy.deepcopy(previous))receipt.correlation_id = correlation_id or receipt.correlation_idreceipt.data.update(update_id=receipt.correlation_id, outcome="running", finished_at=None)+ # A handoff receipt from an older interpreter may predate the field.+ receipt.data["correlation_id"] = receipt.data.get("correlation_id") or _launcher_correlation_id()except Exception as exc: # pragma: no cover - defensivelogger.debug("Could not start update receipt: %s", exc)returndiff --git a/tests/hermes_cli/test_update_receipt.py b/tests/hermes_cli/test_update_receipt.pyindex 7a6f2fb53b5..52ca9177653 100644--- a/tests/hermes_cli/test_update_receipt.py+++ b/tests/hermes_cli/test_update_receipt.py@@ -244,6 +244,61 @@ class TestCommandBoundaryFinalization:assert len(list(directory.glob("update_*.json"))) == 1+def _desktop_correlated_receipt(home, correlation):+ """Desktop's managed SSH receipt lookup (managed-ssh-update.ts ``receipt()``)."""+ directory = home / "logs" / "update_receipts"+ for path in sorted(directory.glob("update_*.json"), key=lambda p: p.stat().st_mtime_ns, reverse=True):+ payload = json.loads(path.read_text(encoding="utf-8"))+ if payload.get("correlation_id") != correlation:+ continue+ if payload.get("outcome") == "running" or not payload.get("finished_at"):+ continue+ return payload+ return None+++class TestLauncherCorrelation:+ """Desktop matches the remote receipt by HERMES_UPDATE_CORRELATION_ID (#101516)."""++ CORRELATION = "1e7cb007-a6f8-4f6c-badb-d80e204942bf"++ def test_receipt_carries_launcher_correlation(self, receipt_home, monkeypatch):+ monkeypatch.setenv("HERMES_UPDATE_CORRELATION_ID", self.CORRELATION)+ ur.begin_update_receipt()+ update_id = ur.current_correlation_id()+ _finalize("success")++ payload = _desktop_correlated_receipt(receipt_home, self.CORRELATION)+ assert payload is not None+ assert payload["outcome"] == "success"+ # update_id stays the CLI's own id (pm sync receipts bind to it).+ assert payload["update_id"] == update_id != self.CORRELATION++ def test_handoff_receipt_keeps_correlation(self, receipt_home, monkeypatch):+ monkeypatch.setenv("HERMES_UPDATE_CORRELATION_ID", self.CORRELATION)+ ur.begin_update_receipt()+ pre_swap = dict(ur._current.get().data)+ with ur.update_receipt_scope():+ # The post-swap interpreter need not inherit the env var.+ monkeypatch.delenv("HERMES_UPDATE_CORRELATION_ID")+ ur.begin_update_receipt(previous=pre_swap, correlation_id=pre_swap["update_id"])+ _finalize("success")+ assert _desktop_correlated_receipt(receipt_home, self.CORRELATION) is not None++ def test_legacy_handoff_receipt_gains_correlation(self, receipt_home, monkeypatch):+ # A pre-swap receipt from an older updater has no correlation_id field.+ monkeypatch.setenv("HERMES_UPDATE_CORRELATION_ID", self.CORRELATION)+ ur.begin_update_receipt(previous={"update_id": "abc123", "steps": []}, correlation_id="abc123")+ _finalize("success")+ assert _desktop_correlated_receipt(receipt_home, self.CORRELATION)["update_id"] == "abc123"++ def test_no_launcher_correlation_is_null(self, receipt_home, monkeypatch):+ monkeypatch.delenv("HERMES_UPDATE_CORRELATION_ID", raising=False)+ ur.begin_update_receipt()+ _finalize("success")+ assert ur.read_latest_receipt()["correlation_id"] is None++class TestFleetClassification:def _fleet_with(self, monkeypatch, tmp_path, record, expected_sha="a" * 40):"""Run collect_fleet_versions against one fake default profile."""