diff --git a/hermes_cli/gateway.py b/hermes_cli/gateway.py index 7c56431fef8..d5b76574a12 100644 --- a/hermes_cli/gateway.py +++ b/hermes_cli/gateway.py @@ -3865,22 +3865,24 @@ def _guard_existing_gateway_process_conflict(replace: bool = False) -> None: is expensive: it pulls in model_tools/plugin discovery first. On small instances, a supervisor or dashboard loop repeatedly running bare ``hermes gateway run`` can burn memory/CPU just to fail with "already - running" after plugin discovery. This cheap CLI-side preflight preserves the - same user-facing contract while avoiding that startup work. + running" after plugin discovery. This cheap PID-file preflight preserves the + same user-facing contract while avoiding that startup work without scanning + unrelated gateway processes from other HERMES_HOME roots. """ if replace or _running_under_gateway_supervisor(): return try: - snapshot = get_gateway_runtime_snapshot() + from gateway.status import get_running_pid + + pid = get_running_pid() except Exception: logger.debug("Existing-gateway process probe failed", exc_info=True) return - if not snapshot.gateway_pids: + if pid is None: return - pid_text = _format_gateway_pids(snapshot.gateway_pids, limit=1) print_error( - f"Another gateway instance is already running (PID {pid_text})." + f"Another gateway instance is already running (PID {pid})." ) print(" Use 'hermes gateway restart' to replace it,") print(" or 'hermes gateway stop' first.") diff --git a/tests/hermes_cli/test_gateway.py b/tests/hermes_cli/test_gateway.py index 4fe01da7b8d..38a65101279 100644 --- a/tests/hermes_cli/test_gateway.py +++ b/tests/hermes_cli/test_gateway.py @@ -129,13 +129,6 @@ def _running_snapshot(manager="systemd (user)"): ) -def _process_snapshot(*pids: int, manager="manual process"): - return gateway.GatewayRuntimeSnapshot( - manager=manager, - gateway_pids=tuple(pids), - ) - - def test_run_gateway_refuses_when_service_supervising(monkeypatch, capsys): """A shell `gateway run --replace` must not become a second writer.""" calls = [] @@ -230,11 +223,7 @@ def test_run_gateway_refuses_existing_process_before_importing_gateway_run(monke _install_fake_gateway_run(monkeypatch, fake_start_gateway) _clear_supervisor_markers(monkeypatch) - monkeypatch.setattr( - gateway, - "get_gateway_runtime_snapshot", - lambda: _process_snapshot(17907), - ) + monkeypatch.setattr("gateway.status.get_running_pid", lambda: 17907) with pytest.raises(SystemExit) as exc_info: gateway.run_gateway() @@ -255,11 +244,7 @@ def test_run_gateway_replace_skips_existing_process_preflight(monkeypatch): _install_fake_gateway_run(monkeypatch, fake_start_gateway) _clear_supervisor_markers(monkeypatch) - monkeypatch.setattr( - gateway, - "get_gateway_runtime_snapshot", - lambda: _process_snapshot(17907), - ) + monkeypatch.setattr("gateway.status.get_running_pid", lambda: 17907) monkeypatch.setattr(gateway.asyncio, "run", lambda coro: True) gateway.run_gateway(replace=True)