fix(cli): tighten stale-dashboard match to explicit patterns

Replace the Linux/macOS pgrep regex ("hermes.*dashboard") with a ps
scan + the same explicit patterns list already used on the Windows
branch and in hermes_cli.gateway._scan_gateway_pids:

    hermes dashboard
    hermes_cli.main dashboard
    hermes_cli/main.py dashboard

The old greedy regex would match any cmdline containing both words —
e.g. a chat session whose argv mentions "dashboard" or an unrelated
grafana/dashboard-server process. Added regression tests for both.

Follow-up tightening on #16881.
This commit is contained in:
Teknium
2026-04-28 01:13:13 -07:00
committed by Teknium
parent 66b1142384
commit 9048fd020f
2 changed files with 109 additions and 25 deletions

View File

@@ -5257,19 +5257,32 @@ def _warn_stale_dashboard_processes() -> None:
except ValueError:
pass
else:
# Linux / macOS: scan /proc or fall back to ps.
# Linux / macOS: scan the process table via ps and match against
# the same explicit patterns list used on Windows. Using ps
# (rather than `pgrep -f "hermes.*dashboard"`) keeps us consistent
# with `hermes_cli.gateway._scan_gateway_pids` and avoids the
# greedy regex matching unrelated cmdlines that merely contain
# both words (e.g. a chat session discussing "dashboard").
result = subprocess.run(
["pgrep", "-f", "hermes.*dashboard"],
capture_output=True, text=True, timeout=5,
["ps", "-A", "-o", "pid=,command="],
capture_output=True, text=True, timeout=10,
)
if result.returncode == 0:
for line in result.stdout.strip().splitlines():
for line in result.stdout.split("\n"):
stripped = line.strip()
if not stripped or "grep" in stripped:
continue
parts = stripped.split(None, 1)
if len(parts) != 2:
continue
try:
pid = int(line.strip())
if pid != self_pid:
dashboard_pids.append(pid)
pid = int(parts[0])
except ValueError:
pass
continue
command = parts[1]
if (any(p in command for p in patterns)
and pid != self_pid):
dashboard_pids.append(pid)
except (FileNotFoundError, subprocess.TimeoutExpired, OSError):
return