Skip to content

The agent that grows with you

fix(host-topology): only a PROVEN-live host record names the host gateway

teknium1f66089174c68
diff --git a/gateway/host_topology.py b/gateway/host_topology.py
index c2750c732b9..2a2a58d22cc 100644
--- a/gateway/host_topology.py
+++ b/gateway/host_topology.py
@@ -62,6 +62,11 @@ def _from_host_record() -> Optional[HostGatewayTopology]:
record = hr.read_record(hr.ROLE_GATEWAY) # already drops stale/PID-reused records
if record is None or not record.pid:
return None
+ # A record whose (pid, createTime) cannot be POSITIVELY matched is a candidate, never an owner
+ # (``host_rendezvous`` contract): reporting an unprovable record as the live host gateway would
+ # turn a leftover record into a permanent "running" lie on every surface.
+ if not hr.liveness_is_proven(record):
+ return None
return HostGatewayTopology(pid=int(record.pid), profiles=tuple(record.profiles), source="host_record")
diff --git a/tests/gateway/test_host_topology.py b/tests/gateway/test_host_topology.py
index 988d7b46039..4a393005fb8 100644
--- a/tests/gateway/test_host_topology.py
+++ b/tests/gateway/test_host_topology.py
@@ -40,3 +40,13 @@ def test_unserved_profile_is_not_claimed_by_the_host_gateway(host_gateway, monke
monkeypatch.setattr("hermes_cli.gateway.named_profile_served_by_running_multiplexer", lambda *a: False)
(host_gateway / "profiles" / "other").mkdir()
assert status.multiplexer_liveness_for_profile(host_gateway / "profiles" / "other") is None
+
+
+def test_unprovable_record_is_a_candidate_not_the_host_gateway(host_gateway, monkeypatch):
+ """A leftover record whose (pid, createTime) cannot be POSITIVELY matched must never be
+ reported as the live host gateway — otherwise it is a permanent "running" lie."""
+ from gateway import host_topology
+
+ monkeypatch.setattr("gateway.host_rendezvous.liveness_is_proven", lambda record: False)
+ monkeypatch.setattr("hermes_cli.gateway_multiplex_served.live_default_gateway_pid", lambda: None)
+ assert host_topology.host_gateway_topology() is None
diff --git a/tests/gateway/test_status.py b/tests/gateway/test_status.py
index ef94bb6c824..ef51b6016f3 100644
--- a/tests/gateway/test_status.py
+++ b/tests/gateway/test_status.py
@@ -1607,12 +1607,15 @@ class TestResolveGatewayLiveness:
assert calls == {"health": 0, "runtime_pid": 0}
- def test_probe_exception_degrades_instead_of_raising(self):
+ def test_probe_exception_degrades_instead_of_raising(self, tmp_path, monkeypatch):
"""A raising rung must fall through, never propagate.
Status endpoints poll this constantly; an exotic /proc or a
permissions error must not turn into a 500.
"""
+ # Empty rendezvous dir: no host gateway owns the role, so the multiplexer rung stays quiet.
+ monkeypatch.setenv("HERMES_GATEWAY_LOCK_DIR", str(tmp_path))
+
def _boom(*a, **k):
raise RuntimeError("probe exploded")
diff --git a/tests/hermes_cli/test_cron.py b/tests/hermes_cli/test_cron.py
index 615f1094093..a1873ce397f 100644
--- a/tests/hermes_cli/test_cron.py
+++ b/tests/hermes_cli/test_cron.py
@@ -1,6 +1,7 @@
"""Tests for hermes_cli.cron command handling."""
import argparse
+import tempfile
import time
from argparse import Namespace
from datetime import datetime, timedelta, timezone
@@ -610,6 +611,9 @@ class TestStatusSurfacesDeadScheduler:
flag it as overdue and say when the scheduler last ticked."""
def _dead_gateway(self, monkeypatch):
+ # No gateway owns the HOST role either: point the rendezvous dir at an empty scratch dir
+ # so an unrelated host record can never make this profile look served.
+ monkeypatch.setenv("HERMES_GATEWAY_LOCK_DIR", tempfile.mkdtemp(prefix="hermes-locks-"))
monkeypatch.setattr("hermes_cli.gateway.find_gateway_pids", lambda: [])
monkeypatch.setattr(
"hermes_cli.gateway.named_profile_served_by_running_multiplexer", lambda: None