The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): don't report pausable gateways as venv-update blockers
iso2kx0bec37aefc45
diff --git a/hermes_cli/_scan_venv_blockers.py b/hermes_cli/_scan_venv_blockers.pyindex 0842577ba61..74940fae9a3 100644--- a/hermes_cli/_scan_venv_blockers.py+++ b/hermes_cli/_scan_venv_blockers.py@@ -92,6 +92,35 @@ def _redact_sensitive_cmdline(cmdline: str) -> str:return cmdline+def _is_pausable_gateway(cmdline: str) -> bool:+ """Return True when *cmdline* is a gateway process the updater can pause.++ A running gateway shows up in the venv-holder scan as one or both halves+ of its launcher/worker chain (``venv\\Scripts\\python.exe -m+ hermes_cli.main gateway run`` and the uv-side interpreter re-running the+ same argv). Reporting those as blockers dead-ends the Desktop update:+ the preflight aborts with ``venv-blocked`` *before* spawning+ ``hermes-setup``, so the CLI updater's own+ ``_pause_windows_gateways_for_update()`` — which exists precisely to+ stop these processes (and is always active: ``hermes-setup`` invokes+ ``hermes update --yes --gateway``) — never gets the chance to run.++ Only gateway invocations are exempted. Anything else running from the+ venv (an operator's REPL, a stray script, a ``serve`` backend that+ survived the desktop's own teardown) has no pause machinery downstream+ and must keep blocking the handoff.+ """+ lowered = cmdline.lower()+ if "hermes_cli.main" not in lowered:+ return False+ try:+ tokens = [t for t in lowered.split() if t]+ idx = tokens.index("gateway")+ except ValueError:+ return False+ return len(tokens) > idx + 1 and tokens[idx + 1] == "run"++def main() -> None:"""Entry point. Prints one JSON doc to stdout. Exits 0 for valid scan."""try:@@ -113,8 +142,17 @@ def main() -> None:"cmdline": _redact_sensitive_cmdline(cmdline),}for pid, name, cmdline in matches+ if not _is_pausable_gateway(cmdline)]- data = {"ok": True, "blocked": bool(processes), "processes": processes}+ exempted = sum(1 for _pid, _name, cmdline in matches if _is_pausable_gateway(cmdline))+ data = {+ "ok": True,+ "blocked": bool(processes),+ "processes": processes,+ # Diagnostic only: gateway processes present but not counted as+ # blockers because the downstream updater pauses them itself.+ "pausable_gateways": exempted,+ }print(json.dumps(data))sys.exit(0)diff --git a/tests/hermes_cli/test_scan_venv_blockers.py b/tests/hermes_cli/test_scan_venv_blockers.pyindex bcd62ddf16f..72f109c58d5 100644--- a/tests/hermes_cli/test_scan_venv_blockers.py+++ b/tests/hermes_cli/test_scan_venv_blockers.py@@ -17,6 +17,7 @@ import pytestimport agent.redact as redact_modulefrom hermes_cli._scan_venv_blockers import (+ _is_pausable_gateway,_redact_sensitive_cmdline,main,)@@ -92,4 +93,118 @@ def test_redact_short_flags_not_redacted() -> None:"""Short flags -t (toolset), -p (profile), -k are NOT redacted."""raw = "python.exe -m hermes_cli.main serve -t web -p default -k somearg"result = _redact_sensitive_cmdline(raw)- assert result == raw # short flags pass through unchanged\ No newline at end of file+ assert result == raw # short flags pass through unchanged+++# ---------------------------------------------------------------------------+# _is_pausable_gateway — the gateway exemption+#+# `hermes-setup` always invokes `hermes update --yes --gateway`, whose+# `_pause_windows_gateways_for_update()` stops running gateways itself. The+# Desktop preflight must therefore not report gateway launcher/worker chains+# as blockers — doing so aborts the handoff before the component that can+# handle them ever runs.+# ---------------------------------------------------------------------------+++ "cmdline",+ [+ # venv-side launcher, exactly as the scheduled task spawns it+ r"C:\Users\u\AppData\Local\hermes\hermes-agent\venv\Scripts\python.exe"+ " -m hermes_cli.main gateway run --replace",+ # uv-side worker re-running the same argv (quoted exe, double space)+ r'"C:\Users\u\AppData\Roaming\uv\python\cpython-3.11-windows-x86_64-none\python.exe"'+ " -m hermes_cli.main gateway run --replace",+ # profile-scoped gateway+ "python.exe -m hermes_cli.main --profile work gateway run",+ # case variations survive+ "PYTHON.EXE -m hermes_cli.main GATEWAY RUN",+ ],+)+def test_is_pausable_gateway_accepts_gateway_run_chains(cmdline: str) -> None:+ assert _is_pausable_gateway(cmdline) is True+++ "cmdline",+ [+ # desktop backend: no pause machinery downstream, must keep blocking+ "python.exe -m hermes_cli.main serve --host 127.0.0.1 --port 8756",+ # other gateway subcommands are not running gateways+ "python.exe -m hermes_cli.main gateway stop",+ "python.exe -m hermes_cli.main gateway status",+ "python.exe -m hermes_cli.main gateway install",+ # operator REPL / stray script+ "python.exe",+ "python.exe myscript.py gateway run", # not a hermes_cli.main invocation+ # 'gateway' as a trailing word with nothing after it+ "python.exe -m hermes_cli.main gateway",+ "",+ ],+)+def test_is_pausable_gateway_rejects_everything_else(cmdline: str) -> None:+ assert _is_pausable_gateway(cmdline) is False+++def _run_main_with_detector(monkeypatch, capsys, matches):+ """Run main() with the process detector patched to return *matches*."""+ for name, mod in _psutil_fake().items():+ monkeypatch.setitem(sys.modules, name, mod)+ import hermes_cli.main as cli_main++ monkeypatch.setattr(cli_main, "_detect_venv_python_processes", lambda: matches)+ with pytest.raises(SystemExit) as excinfo:+ main()+ out = capsys.readouterr().out+ return excinfo.value.code, json.loads(out)+++def test_main_exempts_gateway_chain_but_keeps_other_holders(monkeypatch, capsys):+ """A gateway launcher/worker pair alone must scan clear; a non-gateway+ holder alongside it must still block (and be the only reported PID)."""+ gateway_launcher = (+ 12,+ "python.exe",+ r"C:\x\venv\Scripts\python.exe -m hermes_cli.main gateway run --replace",+ )+ gateway_worker = (+ 34,+ "python.exe",+ r'"C:\u\uv\python\python.exe" -m hermes_cli.main gateway run --replace',+ )+ stray_repl = (56, "python.exe", r"C:\x\venv\Scripts\python.exe")++ # Gateway chain only → clear+ code, data = _run_main_with_detector(+ monkeypatch, capsys, [gateway_launcher, gateway_worker]+ )+ assert code == 0+ assert data["ok"] is True+ assert data["blocked"] is False+ assert data["processes"] == []+ assert data["pausable_gateways"] == 2++ # Gateway chain + stray REPL → blocked, reporting only the REPL+ code, data = _run_main_with_detector(+ monkeypatch, capsys, [gateway_launcher, gateway_worker, stray_repl]+ )+ assert code == 0+ assert data["blocked"] is True+ assert [p["pid"] for p in data["processes"]] == [56]+ assert data["pausable_gateways"] == 2+++def test_main_desktop_serve_backend_still_blocks(monkeypatch, capsys):+ """The desktop's own `serve` backend has no downstream pause — it must+ keep blocking exactly as before the exemption."""+ serve = (+ 78,+ "python.exe",+ r"C:\x\venv\Scripts\python.exe -m hermes_cli.main serve --host 127.0.0.1",+ )+ code, data = _run_main_with_detector(monkeypatch, capsys, [serve])+ assert code == 0+ assert data["blocked"] is True+ assert [p["pid"] for p in data["processes"]] == [78]+ assert data["pausable_gateways"] == 0\ No newline at end of file