The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(updater): require Hermes-owned Windows services
fangliquanflq94d0789cc590
diff --git a/hermes_cli/gateway.py b/hermes_cli/gateway.pyindex dcdec3f6b9b..6ca3c2e66a5 100644--- a/hermes_cli/gateway.py+++ b/hermes_cli/gateway.py@@ -788,6 +788,12 @@ def find_profile_gateway_processes(exclude_pids: set | None = None, *, strict: breturn processes+def _is_hermes_windows_gateway_service(name: str) -> bool:+ """Return whether an SCM service name declares Hermes ownership."""+ normalized = "".join(char for char in name.casefold() if char.isalnum())+ return normalized == "hermes" or normalized.startswith("hermesgateway")++def find_windows_gateway_services(*, psutil_module=None, profile_processes: list[ProfileGatewayProcess] | None = None) -> list[WindowsGatewayService]:@@ -830,6 +836,8 @@ def find_windows_gateway_services(continueif service_pid <= 0:raise RuntimeError(f"Running SCM service {service_name} has no valid process ID")+ if not _is_hermes_windows_gateway_service(service_name):+ continueservice_names_by_pid.setdefault(service_pid, set()).add(service_name)except Exception as exc:raise RuntimeError("SCM service enumeration failed") from excdiff --git a/tests/hermes_cli/test_gateway.py b/tests/hermes_cli/test_gateway.pyindex 50aa0fa2e39..8fd83f50cd4 100644--- a/tests/hermes_cli/test_gateway.py+++ b/tests/hermes_cli/test_gateway.py@@ -1322,6 +1322,41 @@ def test_find_windows_gateway_services_rejects_transitional_ancestor(monkeypatch)+def test_find_windows_gateway_services_ignores_task_scheduler_ancestor(monkeypatch):+ """A task-launched gateway is not owned by the Schedule SCM service."""+ monkeypatch.setattr(gateway.sys, "platform", "win32")+ profile = SimpleNamespace(profile="default", pid=300, create_time=300.0)++ class FakeService:+ def as_dict(self):+ return {"name": "Schedule", "pid": 100, "status": "running"}++ class FakeProcess:+ def __init__(self, pid):+ self.pid = pid++ def parents(self):+ return [FakeProcess(200), FakeProcess(100)]++ def children(self, recursive=False):+ assert self.pid == 100+ assert recursive is True+ return [FakeProcess(200), FakeProcess(300)]++ def create_time(self):+ return float(self.pid)++ fake_psutil = SimpleNamespace(+ win_service_iter=lambda: [FakeService()],+ Process=FakeProcess,+ )++ assert gateway.find_windows_gateway_services(+ psutil_module=fake_psutil,+ profile_processes=[profile],+ ) == []++def test_find_windows_gateway_services_rejects_shared_service_host_pid(monkeypatch):"""A shared host PID cannot prove which service owns the gateway subtree."""monkeypatch.setattr(gateway.sys, "platform", "win32")@@ -1348,7 +1383,10 @@ def test_find_windows_gateway_services_rejects_shared_service_host_pid(monkeypatreturn float(self.pid)fake_psutil = SimpleNamespace(- win_service_iter=lambda: [FakeService("ServiceA"), FakeService("ServiceB")],+ win_service_iter=lambda: [+ FakeService("HermesGatewayA"),+ FakeService("HermesGatewayB"),+ ],Process=FakeProcess,)