Skip to content

The agent that grows with you

fix(update): ignore unrelated transitional SCM services

fangliquanflqd5632392c73f
diff --git a/hermes_cli/gateway.py b/hermes_cli/gateway.py
index 4c18203e100..fb19ad7ce48 100644
--- a/hermes_cli/gateway.py
+++ b/hermes_cli/gateway.py
@@ -1061,6 +1061,7 @@ def find_windows_gateway_services(
if profile_processes is None:
profile_processes = find_profile_gateway_processes(strict=True)
service_names_by_pid: dict[int, set[str]] = {}
+ indeterminate_services_by_pid: dict[int, list[tuple[str, object]]] = {}
for service in psutil_module.win_service_iter():
try:
if all(
@@ -1086,9 +1087,11 @@ def find_windows_gateway_services(
if service_status == "stopped":
continue
if service_status != "running":
- raise RuntimeError(
- f"SCM service {service_name} has indeterminate status: {service_status}"
- )
+ if service_pid > 0:
+ indeterminate_services_by_pid.setdefault(service_pid, []).append(
+ (service_name, service_status)
+ )
+ continue
if service_pid <= 0:
raise RuntimeError(
f"Running SCM service {service_name} has no valid process ID"
@@ -1107,6 +1110,14 @@ def find_windows_gateway_services(
) > 0.001:
raise RuntimeError("Gateway process identity changed during SCM discovery")
ancestor_pids = [int(parent.pid) for parent in gateway_process.parents()]
+ for pid in ancestor_pids:
+ indeterminate_services = indeterminate_services_by_pid.get(pid, [])
+ if indeterminate_services:
+ service_name, service_status = indeterminate_services[0]
+ raise RuntimeError(
+ f"SCM service {service_name} has indeterminate status: "
+ f"{service_status}"
+ )
shared_service_pids = [
pid
for pid in ancestor_pids
diff --git a/tests/hermes_cli/test_gateway.py b/tests/hermes_cli/test_gateway.py
index 02ff059cccb..53c014b641c 100644
--- a/tests/hermes_cli/test_gateway.py
+++ b/tests/hermes_cli/test_gateway.py
@@ -1015,15 +1015,16 @@ def test_find_windows_gateway_services_maps_verified_pid_tree(monkeypatch):
profile = SimpleNamespace(profile="default", pid=300, create_time=300.0)
class FakeService:
- def __init__(self, name, pid):
+ def __init__(self, name, pid, status="running"):
self.name = name
self.pid = pid
+ self.status = status
def as_dict(self):
return {
"name": self.name,
"pid": self.pid,
- "status": "running",
+ "status": self.status,
}
class FakeProcess:
@@ -1044,7 +1045,7 @@ def test_find_windows_gateway_services_maps_verified_pid_tree(monkeypatch):
fake_psutil = SimpleNamespace(
win_service_iter=lambda: [
FakeService("HermesGateway", 100),
- FakeService("UnrelatedService", 900),
+ FakeService("UnrelatedService", 900, "stop_pending"),
],
Process=FakeProcess,
)
@@ -1068,6 +1069,37 @@ def test_find_windows_gateway_services_maps_verified_pid_tree(monkeypatch):
]
+def test_find_windows_gateway_services_rejects_transitional_ancestor(monkeypatch):
+ """A transitional service in the gateway ancestry remains fail-closed."""
+ monkeypatch.setattr(gateway.sys, "platform", "win32")
+ profile = SimpleNamespace(profile="default", pid=300, create_time=300.0)
+
+ class FakeService:
+ def as_dict(self):
+ return {"name": "HermesGateway", "pid": 100, "status": "stop_pending"}
+
+ class FakeProcess:
+ def __init__(self, pid):
+ self.pid = pid
+
+ def parents(self):
+ return [FakeProcess(100)]
+
+ def create_time(self):
+ return float(self.pid)
+
+ fake_psutil = SimpleNamespace(
+ win_service_iter=lambda: [FakeService()],
+ Process=FakeProcess,
+ )
+
+ with pytest.raises(RuntimeError, match="indeterminate status: stop_pending"):
+ 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")