The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(bot-screen): profile delete/rename stop the profile's Bot Desktop, not only its gateway
teknium1ce24f855f65b
diff --git a/hermes_cli/profiles.py b/hermes_cli/profiles.pyindex 12c98d10486..2043f294a2d 100644--- a/hermes_cli/profiles.py+++ b/hermes_cli/profiles.py@@ -1075,6 +1075,25 @@ def _stop_profile_backends(canon: str, profile_dir: Path) -> None:print(f"✓ Stopped {len(pids)} profile backend process(es)")+def _stop_bot_desktop(profile_dir: Path) -> None:+ """Stop the profile's Bot Desktop (Xvnc + Xfce launcher) before its directory is removed or renamed;+ gateway shutdown does not reach it (its own session, its own pid file). Scoped through the hermes-home+ override so the runtime reads THIS profile's bot-desktop/ state, whichever profile invoked the op.+ A failure here is logged, never fatal: the profile op is what the user asked for."""+ from hermes_constants import reset_hermes_home_override, set_hermes_home_override+ from tools.bot_desktop import runtime+ if not runtime.is_supported_host():+ return+ token = set_hermes_home_override(profile_dir)+ try:+ if runtime.stop():+ print("✓ Bot Desktop stopped")+ except Exception as e:+ logger.warning("Could not stop the Bot Desktop of %s: %s", profile_dir, e)+ finally:+ reset_hermes_home_override(token)++def _rmtree_make_writable(func, path, exc):"""onexc/onerror handler: add +w on PermissionError so rmtree can proceed. Covers NixOS-style read-only copies where the path itself (0444) or its parent (0555) isn't writable."""@@ -1168,6 +1187,7 @@ def delete_profile(name: str, yes: bool = False) -> Path:if gw_running:_stop_gateway_process(profile_dir)_stop_profile_backends(canon, profile_dir)+ _stop_bot_desktop(profile_dir)# Tombstone before rmtree so a stale serve/logging mkdir cannot relist this name live.mark_named_profile_deleted(profile_dir)@@ -1662,10 +1682,11 @@ def rename_profile(old_name: str, new_name: str) -> Path:if new_dir.exists():raise FileExistsError(f"Profile '{new_canon}' already exists.")- # 1. Stop gateway if running+ # 1. Stop gateway if running, and the screen whose launcher holds paths under the old nameif _check_gateway_running(old_dir):_cleanup_gateway_service(old_canon, old_dir)_stop_gateway_process(old_dir)+ _stop_bot_desktop(old_dir)# 2. Rename directoryold_dir.rename(new_dir)diff --git a/tests/hermes_cli/test_profiles.py b/tests/hermes_cli/test_profiles.pyindex b7c7bf61a4f..91d6c034348 100644--- a/tests/hermes_cli/test_profiles.py+++ b/tests/hermes_cli/test_profiles.py@@ -1161,3 +1161,37 @@ class TestResolveProfileEnvSpelling:assert Path(resolve_profile_env("default")) == _get_default_hermes_home()+++def _live_bot_desktop_launcher(profile_dir: Path):+ """A synthetic Bot Desktop launcher for ``profile_dir``: its own session (like launcher.sh) with the+ identity file + env runtime.status() reads, so the profile op sees a running screen."""+ import subprocess+ from tools.bot_desktop import runtime++ proc = subprocess.Popen(["sleep", "60"], start_new_session=True)+ sd = profile_dir / "bot-desktop"+ sd.mkdir()+ (sd / "launcher.pid").write_text(f"{proc.pid} {runtime._create_time(proc.pid)}", encoding="utf-8")+ (sd / "env").write_text("DISPLAY=:42\n", encoding="utf-8")+ return proc++[email protected]_only[email protected]("op", ["delete", "rename"])+def test_profile_delete_and_rename_stop_the_profiles_bot_desktop(profile_env, op):+ """Deleting or renaming a profile stops its gateway, and must stop its Bot Desktop launcher too: the+ Xvnc/Xfce session otherwise keeps running against a directory that no longer exists (or now belongs to+ another name), holding its display number and an rfb.sock nobody can reach through status()."""+ profile_dir = create_profile("coder", no_alias=True)+ proc = _live_bot_desktop_launcher(profile_dir)+ try:+ with patch("hermes_cli.profiles._cleanup_gateway_service"), \+ patch("hermes_cli.profiles.check_alias_collision", return_value="skip"):+ if op == "delete":+ delete_profile("coder", yes=True)+ else:+ rename_profile("coder", "hacker")+ assert proc.wait(timeout=10) != 0, "the launcher was signalled by the profile op"+ finally:+ proc.kill()