The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway-windows): a start attestation past the horizon is no authority for a cold-start
kshitijk4poor8c13452b4c73
diff --git a/hermes_cli/gateway_windows.py b/hermes_cli/gateway_windows.pyindex 109d09b6605..3d4758d1929 100644--- a/hermes_cli/gateway_windows.py+++ b/hermes_cli/gateway_windows.py@@ -897,6 +897,26 @@ def _clear_start_attestation() -> None:pass+# A start attestation older than this is no authority (#110020 review (d)): the marker is a one-shot+# meant to bridge the seconds between a ✓ and the next ``hermes gateway status``/``update``; a+# historical marker must never later override Desktop ownership into a duplicate gateway (#76129).+START_ATTESTATION_MAX_AGE_S = 24 * 3600+++def _attestation_within_horizon(data: object, now: float | None = None) -> bool:+ """False for a marker whose ``ts`` is missing, unparsable or older than the horizon (fail closed)."""+ try:+ ts = datetime.fromisoformat(str(data["ts"])) if isinstance(data, dict) else None+ if ts is None:+ return False+ if ts.tzinfo is None:+ ts = ts.replace(tzinfo=timezone.utc)+ age = (time.time() if now is None else now) - ts.timestamp()+ return 0 <= age <= START_ATTESTATION_MAX_AGE_S+ except Exception:+ return False++def _attestation_generation(data: object) -> str | None:"""The marker instance identity, or ``None`` for a marker that carries none."""return str(data["generation"]) if isinstance(data, dict) and data.get("generation") else None@@ -960,7 +980,7 @@ def attested_death_generation(current_pids: list[int]) -> str | None:exit): "unknown" must never read as "dead"."""data = _read_start_attestation()attested = _attested_pids_from(data)- if not attested or not _attested_dead(attested, current_pids):+ if not attested or not _attestation_within_horizon(data) or not _attested_dead(attested, current_pids):return Nonereturn _attestation_generation(data)diff --git a/tests/hermes_cli/test_gateway_start_attestation.py b/tests/hermes_cli/test_gateway_start_attestation.pyindex d82db4c069a..cf6e9a2558d 100644--- a/tests/hermes_cli/test_gateway_start_attestation.py+++ b/tests/hermes_cli/test_gateway_start_attestation.py@@ -228,3 +228,18 @@ def test_attested_probe_fails_closed_without_a_well_formed_dead_attestation(atte)gateway_windows._write_start_attestation([556], "cold-start after update")assert gateway_windows.attested_death_generation(current_pids=[]) is None # planned stop+++def test_attested_probe_treats_a_marker_past_the_horizon_as_no_authority(attest_home):+ """#110020 review (d): a historical marker must not later override Desktop ownership into a+ duplicate gateway (#76129). Missing/unparsable/old ``ts`` all fail closed."""+ marker = attest_home / "state" / "gateway.start-attestation.json"+ marker.parent.mkdir(exist_ok=True)+ gateway_windows._write_start_attestation([555], "direct spawn (PID 555)")+ assert gateway_windows.attested_death_generation(current_pids=[]) is not None # fresh+ data = json.loads(marker.read_text(encoding="utf-8"))+ for ts in (None, "not-a-date", "2020-01-01T00:00:00+00:00"):+ stale = {k: v for k, v in data.items() if k != "ts"} if ts is None else {**data, "ts": ts}+ marker.write_text(json.dumps(stale), encoding="utf-8")+ assert gateway_windows.attested_death_generation(current_pids=[]) is None, ts+ assert marker.exists() # not consumed either