The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(update): drop the dead Windows venv-holder gate
etherneta792e96388ad
diff --git a/hermes_cli/update_cmd_windows.py b/hermes_cli/update_cmd_windows.pyindex a10607091a8..d9481a4dfea 100644--- a/hermes_cli/update_cmd_windows.py+++ b/hermes_cli/update_cmd_windows.py@@ -262,34 +262,6 @@ def _hermes_holder_subcommand(cmdline: str) -> str | None: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.-- Labels come from the parsed SUBCOMMAND, never substring: a standalone ``hermes dashboard`` must not be- called the Desktop backend, ``--preserve-cache`` must not match "serve". Unknown argv gets no hint.-- See #90778.- """- 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",- }- lines = ["✗ Other Hermes processes are running from this install's venv:"]- for pid, name, cmdline in matches[:6]:- hint = hint_by_subcommand.get(_hermes_holder_subcommand(cmdline) or "", "")- lines.append(f" PID {pid} {name} {cmdline[:120]}{hint}")- if len(matches) > 6:- lines.append(f" ... and {len(matches) - 6} more")- lines.append(- "\n On Windows these keep native extension files (.pyd) locked, so the\n"- " dependency update would fail partway and leave a broken install.\n"- " Close the Hermes desktop app / other Hermes terminals, then re-run:\n hermes update\n"- " (or use `hermes update --force-venv` to proceed anyway at your own risk)"- )- return "\n".join(lines)--def _venv_launcher_ancestors(pids: list[int]) -> list[int]:"""Venv-interpreter parents of *pids* that hold the install open; never raises.@@ -1332,92 +1304,3 @@ def _resume_windows_gateways_and_merge_outcome(outcome, _windows_gateway_resume,failed_units=outcome.failed_or_stale_units, incomplete=outcome.incomplete or bool(outcome.failed_or_stale_units),phase_error="; ".join(outcome.phase_errors) or None,)---def _reap_and_rescan(message: str, pids, stop=None) -> list[tuple[int, str, str]]:- """Announce *message*, stop *pids* (tree-kill unless *stop* given), settle 1s, re-scan venv holders."""- from hermes_cli.update_cmd import _m- print(message)- (stop or _m()._stop_process_trees)(pids)- _time.sleep(1.0)- return _detect_venv_python_processes()---def _terminate_leftover_gateways(pids) -> None:- """Force-stop leftover gateways one by one; a failure is logged, never raised."""- from gateway.status import get_process_start_time, terminate_pid- for _pid in pids:- _try_call(lambda p=int(_pid): terminate_pid(p, force=True, expected_start_time=get_process_start_time(p)),- "Could not stop leftover gateway %s: %s", _pid)---def _in_handoff_without_live_shim(args) -> bool:- """GUI hand-off gate: ``--gateway`` + update-incomplete marker AND no live ``hermes.exe`` shim.-- Fail closed: unverifiable marker or shim state reads as "not a hand-off" / "live shim"."""- from hermes_cli.update_cmd import _m- try:- if not (bool(getattr(args, "gateway", False)) and _m()._update_marker_path().exists()):- return False- scripts_dir = _m()._venv_scripts_dir()- return scripts_dir is not None and not _m()._detect_concurrent_hermes_instances(scripts_dir)- except Exception:- return False---def _clear_windows_venv_holders_or_exit(args, gateway_mode: bool, _windows_gateway_resume):- """Windows: stop every venv-python holder we can positively identify, else resume paused gateways and exit 2.-- Rungs in order: leftover pausable gateways -> ledger orphaned backends -> orphaned Desktop backends ->- ledger manual serve (relaunched at exit on the same bind) -> GUI hand-off leaks. Remaining holders are- refused (the sync would corrupt against a locked .pyd)."""- from hermes_cli.update_cmd import _m, _record_update_step, _refuse_gateway_ancestor_tree_kill-- def _resume_and_exit():- _m()._resume_windows_gateways_after_update(_windows_gateway_resume)- sys.exit(2)-- holders = _detect_venv_python_processes()- # Gateways the pause machinery owns (respawned in the pause->guard window or unmapped- # spawn path): stop and re-check; post-update resume brings them back.- if holders and (gateway_holders := _m()._leftover_pausable_gateway_pids(holders)) is not None:- if _refuse_gateway_ancestor_tree_kill(gateway_holders, gateway_mode=gateway_mode):- _resume_and_exit()- holders = _reap_and_rescan(- f" ⚠ {len(gateway_holders)} gateway process(es) still hold the venv after the pause; stopping them",- gateway_holders, stop=_terminate_leftover_gateways,- )- # Tree-reap rungs. Ledger rung = positive identity in any context (self-registered backend, spawner- # provably dead; no PPID archaeology). Orphan rung = Desktop `serve` whose app is GONE (nothing- # respawns an orphan); live-Desktop backends return None and keep the refusal.- for classifier, message in (- (_m()._ledger_reapable_backend_pids, "ledger-identified orphaned Hermes backend process(es) hold the venv"),- (_m()._orphaned_desktop_backend_pids, "orphaned Desktop backend process(es) still hold the venv"),- ):- if holders and (backends := classifier(holders)):- holders = _reap_and_rescan(f" ⚠ {len(backends)} {message}; stopping their trees", backends)- # Manual serve/dashboard rung (e.g. `hermes serve --host <ip>` for a REMOTE Desktop): ledger identity- # only (spawner dead; Desktop-owned keep the refusal). Stop and register an idempotent atexit relaunch- # on the SAME host/port/profile — success or failure.- if holders and (serve_entries := _m()._ledger_manual_serve_holders(holders)):- def _stop_and_park(pids):- _m()._stop_process_trees(pids)- _record_update_step("serve_pause", True, f"stopped={len(serve_entries)}")- import atexit as _serve_atexit- _serve_atexit.register(_m()._relaunch_stopped_serves, {"pending": True, "entries": serve_entries})-- holders = _reap_and_rescan(- f" ⚠ {len(serve_entries)} manual serve/dashboard backend(s) hold the venv; stopping them for "- "the update (they will be relaunched on their recorded endpoints)",- [int(e["pid"]) for e in serve_entries], stop=_stop_and_park,- )- # Final rung: in a GUI hand-off the Desktop is contractually gone; surviving `serve` backends are leaks- # even with a live parent (which made the orphan-only rung bail and hang) — reap by cmdline.- if holders and _in_handoff_without_live_shim(args) and (handoff_backends := _m()._handoff_reapable_backend_pids(holders)):- holders = _reap_and_rescan(- f" ⚠ {len(handoff_backends)} Hermes backend process(es) "- "still hold the venv after the Desktop hand-off; stopping their trees", handoff_backends,- )- if holders:- print(_format_venv_python_holders_message(holders))- _resume_and_exit()diff --git a/tests/hermes_cli/test_update_venv_holder_retirement.py b/tests/hermes_cli/test_update_venv_holder_retirement.pyindex 08851f58d12..431fc1461c1 100644--- a/tests/hermes_cli/test_update_venv_holder_retirement.py+++ b/tests/hermes_cli/test_update_venv_holder_retirement.py@@ -95,7 +95,6 @@ def test_command_reaches_checkout_preparation_without_holder_gates(monkeypatch,# Recreate the former call-site names as tripwires, not host-OS fakes.# The scan remains live for lifecycle ownership, but must not gate updates.monkeypatch.setattr(main, "_detect_concurrent_hermes_instances", forbidden, raising=False)- monkeypatch.setattr(update_cmd, "_clear_windows_venv_holders_or_exit", forbidden, raising=False)monkeypatch.setattr(update_cmd_windows, "_detect_venv_python_processes", forbidden)monkeypatch.setattr(update_cmd, "_refuse_gateway_ancestor_tree_kill", forbidden)monkeypatch.setattr(main, "_is_windows", forbidden)