Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 30 additions & 13 deletions hermes_cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6089,17 +6089,34 @@ def _find_stale_dashboard_pids(

Returns an empty list on any scan error (missing ps/wmic, timeout, etc.).
"""
patterns = [
"hermes dashboard",
"hermes_cli.main dashboard",
"hermes_cli/main.py dashboard",
# The headless backend (`hermes serve`) is the same long-lived server
# under a different command name — the desktop app spawns it. Reap it
# on update for the same frontend/backend-mismatch reason.
"hermes serve",
"hermes_cli.main serve",
"hermes_cli/main.py serve",
]
# A Hermes web server is a long-lived process whose argv contains the
# subcommand ``dashboard`` or ``serve`` as a *whitespace-delimited token*
# (not embedded in a path like ``dashboard.py``) AND that is clearly a
# Hermes process. We match on tokens, NOT a contiguous substring, because
# real launch cmdlines interpose flags between the module name and the
# subcommand — e.g. launchd spawns
# ``python -m hermes_cli.main --profile orchestrator dashboard ...``. A
# naive substring ``"hermes_cli.main dashboard"`` never matches that, so
# the scanner returned 0 stale processes and ``hermes update`` left the
# old backend (still serving the previous version's /api/status) running
# forever — the "dashboard never shows the new version" bug (#30271-class
# frontend/backend mismatch). Token matching also ignores unrelated
# cmdlines that merely *contain* the word "dashboard" (a chat session, a
# log grep), which the greedy-regex discussion at the call sites warned
# about.
web_server_subcommands = frozenset({"dashboard", "serve"})

def _is_hermes_web_server_cmd(command: str) -> bool:
toks = command.split()
if not any(tok in web_server_subcommands for tok in toks):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This accepts dashboard or serve anywhere in argv, including a non-server Hermes prompt/argument. Because lines 6113-6117 only establish that it is a Hermes process, the update cleanup can kill that unrelated process. Parse from the Hermes entrypoint and require the first positional subcommand after recognized global flags instead.

return False
lowered = command.lower()
return (
"hermes_cli.main" in lowered
or "hermes_cli/main.py" in lowered
or (toks and toks[0].rstrip("/").endswith("hermes"))
)

self_pid = os.getpid()
dashboard_pids: list[int] = []

Expand Down Expand Up @@ -6136,7 +6153,7 @@ def _find_stale_dashboard_pids(
elif line.startswith("ProcessId="):
pid_str = line[len("ProcessId=") :]
if (
any(p in current_cmd for p in patterns)
_is_hermes_web_server_cmd(current_cmd)
and int(pid_str) != self_pid
):
try:
Expand Down Expand Up @@ -6169,7 +6186,7 @@ def _find_stale_dashboard_pids(
except ValueError:
continue
command = parts[1]
if any(p in command for p in patterns) and pid != self_pid:
if _is_hermes_web_server_cmd(command) and pid != self_pid:
dashboard_pids.append(pid)
except (FileNotFoundError, subprocess.TimeoutExpired, OSError):
return []
Expand Down