The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(update): venv-holder labels parse the real subcommand; gateway ancestors stay visible to the scan
Tekniumc02cac00ce4e
diff --git a/hermes_cli/update_cmd.py b/hermes_cli/update_cmd.pyindex 021b7656feb..4ad10d8d58e 100644--- a/hermes_cli/update_cmd.py+++ b/hermes_cli/update_cmd.py@@ -3683,8 +3683,28 @@ def _detect_venv_python_processes(skip: set[int] = set(exclude_pids or set())skip.add(os.getpid())+ try:+ from gateway.status import looks_like_gateway_command_line as _is_gw+ except Exception:+ _is_gw = Nonetry:for anc in psutil.Process().parents():+ # #87594: do NOT blanket-exclude ancestors. When `/update` runs+ # from a messaging platform the updater is a CHILD of the gateway+ # — excluding all ancestors hides the gateway from the scan, so+ # the pause machinery downstream never sees the one process it+ # exists to stop, and the update dead-ends on `venv-blocked`.+ # A GATEWAY ancestor stays visible (the pause path stops it+ # gracefully; a detached child updater survives its parent's+ # stop on Windows). Every other ancestor (shells, terminals,+ # this CLI's own venv python chain) stays excluded — an updater+ # must never nominate its own interactive ancestry as blockers.+ try:+ anc_cmdline = " ".join(anc.cmdline() or [])+ except Exception:+ anc_cmdline = ""+ if _is_gw is not None and anc_cmdline and _is_gw(anc_cmdline):+ continueskip.add(int(anc.pid))except Exception:pass@@ -3915,18 +3935,71 @@ def _defer_update_for_self_lock(loaded: list[str]) -> None:_m()._write_update_incomplete_marker()+def _hermes_holder_subcommand(cmdline: str) -> str | None:+ """The actual Hermes SUBCOMMAND a venv-holder argv runs, or None.++ Token-based, never substring (#90778: ``kanban --preserve-cache``+ contained \"serve\" and got labeled as the Desktop backend). Finds the+ ``hermes_cli.main`` / ``hermes(.exe)`` entry token, then returns the+ first following token that is not a flag or a flag's value. Profile+ selectors (``--profile X``, ``-p X``) are skipped like the canonical+ gateway matcher does. Returns None when no subcommand can be+ determined — callers must NOT guess a label in that case.+ """+ try:+ import shlex++ tokens = shlex.split(cmdline, posix=False)+ except Exception:+ tokens = cmdline.split()++ entry_idx: int | None = None+ for i, token in enumerate(tokens):+ low = token.lower().strip('"')+ if low.endswith("hermes_cli.main") and i > 0 and tokens[i - 1] == "-m":+ entry_idx = i+ break+ base = low.rsplit("\\", 1)[-1].rsplit("/", 1)[-1]+ if base in ("hermes", "hermes.exe"):+ entry_idx = i+ break+ if entry_idx is None:+ return None++ value_flags = {"--profile", "-p", "--config", "--model", "--provider"}+ i = entry_idx + 1+ while i < len(tokens):+ token = tokens[i]+ if token in value_flags:+ i += 2+ continue+ if token.startswith("-"):+ i += 1+ continue+ return token.lower()+ return None++def _format_venv_python_holders_message(matches: list[tuple[int, str, str]]) -> str:- """Explain which venv processes block the update and how to clear them."""+ """Explain which venv processes block the update and how to clear them.++ Holder labels come from the parsed SUBCOMMAND, never substring matching+ (#90778): a standalone ``hermes dashboard`` must not be labeled as the+ Desktop backend (advice to close an app that isn't running), and flags+ like ``--preserve-cache`` must not match \"serve\". Unknown argv gets no+ hint rather than a wrong one.+ """lines = ["✗ Other Hermes processes are running from this install's venv:",]+ hint_by_subcommand = {+ "serve": " ← Hermes backend (if the Desktop app is open, close it)",+ "dashboard": " ← hermes dashboard (stop it: hermes dashboard stop, or close that terminal)",+ "gateway": " ← gateway",+ }for pid, name, cmdline in matches[:6]:- hint = ""- low = cmdline.lower()- if "serve" in low or "dashboard" in low:- hint = " ← Hermes Desktop backend (close the desktop app)"- elif "gateway" in low:- hint = " ← gateway"+ sub = _hermes_holder_subcommand(cmdline)+ hint = hint_by_subcommand.get(sub or "", "")lines.append(f" PID {pid} {name} {cmdline[:120]}{hint}")if len(matches) > 6:lines.append(f" ... and {len(matches) - 6} more")@@ -3983,9 +4056,23 @@ def _venv_launcher_ancestors(pids: list[int]) -> list[int]:# Never return ourselves or our own ancestry: a CLI ``hermes update``# runs from the venv python and would otherwise nominate itself.+ # Same #87594 carve-out as _detect_venv_python_processes: a GATEWAY+ # ancestor is not "our own ancestry" in the interactive sense — it is+ # the process the pause machinery must see (the /update-from-gateway+ # topology makes the updater the gateway's child).+ try:+ from gateway.status import looks_like_gateway_command_line as _is_gw+ except Exception:+ _is_gw = Noneskip: set[int] = {os.getpid()}try:for anc in psutil.Process().parents():+ try:+ anc_cmdline = " ".join(anc.cmdline() or [])+ except Exception:+ anc_cmdline = ""+ if _is_gw is not None and anc_cmdline and _is_gw(anc_cmdline):+ continueskip.add(int(anc.pid))except Exception:passdiff --git a/tests/hermes_cli/test_venv_holder_classifier.py b/tests/hermes_cli/test_venv_holder_classifier.pynew file mode 100644index 00000000000..2b17573d529--- /dev/null+++ b/tests/hermes_cli/test_venv_holder_classifier.py@@ -0,0 +1,61 @@+"""Cross-platform unit tests for the venv-holder message classifier (#90778)."""++import pytest++from hermes_cli.update_cmd import (+ _format_venv_python_holders_message,+ _hermes_holder_subcommand,+)+++class TestHolderSubcommand:+ @pytest.mark.parametrize(+ ("cmdline", "expected"),+ [+ (r"C:\x\venv\Scripts\python.exe -m hermes_cli.main serve --host 127.0.0.1", "serve"),+ (r"C:\x\venv\Scripts\python.exe -m hermes_cli.main dashboard", "dashboard"),+ (r"python.exe -m hermes_cli.main gateway run", "gateway"),+ # profile selector skipped; its VALUE must not become the subcommand+ (r"python -m hermes_cli.main --profile serve gateway run", "gateway"),+ (r"python -m hermes_cli.main -p work serve", "serve"),+ # 90778: flags containing subcommand words are not subcommands+ (r"python -m hermes_cli.main kanban --preserve-cache", "kanban"),+ (r"C:\bin\hermes.exe dashboard", "dashboard"),+ (r"/usr/local/bin/hermes serve", "serve"),+ # no hermes entry at all+ (r"python -c import time; time.sleep(3)", None),+ # entry but no subcommand+ (r"python -m hermes_cli.main", None),+ ],+ )+ def test_parses_subcommand(self, cmdline, expected):+ assert _hermes_holder_subcommand(cmdline) == expected+++class TestHolderMessage:+ def _msg(self, cmdline):+ return _format_venv_python_holders_message([(4242, "python.exe", cmdline)])++ def test_dashboard_not_labeled_desktop_backend(self):+ message = self._msg(r"C:\v\Scripts\python.exe -m hermes_cli.main dashboard")+ assert "close the desktop app" not in message.lower()+ assert "hermes dashboard" in message++ def test_preserve_cache_not_labeled_serve(self):+ message = self._msg(r"python -m hermes_cli.main kanban --preserve-cache")+ holder_line = next(l for l in message.splitlines() if "PID 4242" in l)+ # the holder LINE gets no serve/desktop hint (generic footer text+ # legitimately mentions the desktop app)+ assert "←" not in holder_line++ def test_serve_gets_backend_hint(self):+ message = self._msg(r"python -m hermes_cli.main serve --host 127.0.0.1 --port 0")+ assert "Hermes backend" in message++ def test_gateway_hint(self):+ message = self._msg(r"python -m hermes_cli.main gateway run")+ assert "← gateway" in message++ def test_unknown_argv_gets_no_hint(self):+ message = self._msg(r"python -c import this")+ assert "←" not in message