The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): ignore other Unix users' gateway processes in the process scan
Teknium99b57a42c708
diff --git a/hermes_cli/gateway.py b/hermes_cli/gateway.pyindex 40c59694128..5267c950401 100644--- a/hermes_cli/gateway.py+++ b/hermes_cli/gateway.py@@ -566,8 +566,7 @@ def _scan_gateway_pids(exclude_pids: set[int], all_profiles: bool = False, include_restart_managers: bool = False) -> list[int]:"""Best-effort process-table scan for gateway PIDs (backs up a stale/missing PID file; ``--all`` sweeps)."""- # Exclude the entire ancestor chain so the CLI process that invoked this scan (e.g. ``hermes gateway- # status``) is never mistaken for a running gateway. See #13242.+ # Exclude the whole ancestor chain: the invoking CLI (``hermes gateway status``) is not a gateway (#13242).exclude_pids = exclude_pids | _get_ancestor_pids()pids: list[int] = []# Strict matcher shared with gateway.status: requires a real ``gateway run`` argv, so@@ -580,6 +579,7 @@ def _scan_gateway_pids(command_line_names_hermes_home,)from hermes_cli.dashboard_procs import _hermes_home_for_pid, _normalized_home_for_compare+ from hermes_cli.gateway_migrate_guards import pid_is_other_userscurrent_home_path = get_hermes_home().resolve()current_home = str(current_home_path)# Forward slashes on both sides of the HERMES_HOME= match (mirrors gateway.status), and no@@ -623,7 +623,7 @@ def _scan_gateway_pids(matches_runtime = looks_like_gateway_command_line(command) or (include_restart_managers and looks_like_gateway_runtime_command_line(command))- if matches_runtime and (all_profiles or _matches_current_profile(pid, command)):+ if matches_runtime and not pid_is_other_users(pid) and (all_profiles or _matches_current_profile(pid, command)):_append_unique_pid(pids, pid, exclude_pids)try:diff --git a/hermes_cli/gateway_migrate_guards.py b/hermes_cli/gateway_migrate_guards.pyindex 4912c3a9501..d952466b20f 100644--- a/hermes_cli/gateway_migrate_guards.py+++ b/hermes_cli/gateway_migrate_guards.py@@ -37,6 +37,19 @@ def _pid_uid(pid: int) -> Optional[int]:return None+def pid_is_other_users(pid: int) -> bool:+ """True when *pid* is owned by another Unix user than this non-root caller.++ Gateway process scans match argv host-wide, so without this a second account's gateway (users+ isolate credentials by UID) became a ``restart --all`` SIGTERM target and "unfolded profile"+ advice. Root keeps the host-wide view (``sudo … --system`` over a ``User=`` unit), as does+ Windows (no ``geteuid``); an unknown owner is not called foreign.+ """+ my_uid = os.geteuid() if hasattr(os, "geteuid") else 0+ owner = _pid_uid(pid) if my_uid else None+ return owner is not None and owner != my_uid++def _system_unit_uid(unit_path: Path) -> Optional[int]:"""uid a system unit runs as: its ``User=`` (root when absent); None when the name is unknown."""from hermes_cli.gateway import _read_systemd_user_from_unit