The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): profile backends stop reaping the Desktop's live SSH backends
teknium15b651e075ed9
diff --git a/hermes_cli/dashboard_procs.py b/hermes_cli/dashboard_procs.pyindex b8a7eed7115..0a0b3169267 100644--- a/hermes_cli/dashboard_procs.py+++ b/hermes_cli/dashboard_procs.py@@ -638,16 +638,35 @@ def _valid_lockfile_payload(parsed: object, ownership_id: str) -> bool:return parsed["logPath"].endswith(f"/{ownership_id}/{parsed['spawnNonce']}.log")+def _remote_lock_roots(base_dir: Path | None) -> list[Path]:+ """Every dir the Desktop may have written ``desktop-ssh/<ownershipId>/backend.lock.json`` under.++ The Desktop writes SSH locks beneath the ROOT home (``~/.hermes/desktop-ssh``), but a profile+ backend (``hermes --profile X serve``) runs with ``HERMES_HOME=<root>/profiles/X`` — scanning only+ the process home found no lock there and its reaper killed the sibling profile's live SSH+ backend on every profile switch (#89811)."""+ if base_dir is not None:+ return [base_dir]+ from hermes_constants import get_default_hermes_root+ roots: list[Path] = []+ for home in (_hermes_home_dir(), get_default_hermes_root()):+ root = home / _REMOTE_LOCK_SUBDIR+ if root not in roots:+ roots.append(root)+ return roots++def _lock_owned_serve_pids(base_dir: Path | None = None) -> set[int]:"""PIDs claimed by valid ``{hermes_home}/desktop-ssh/<ownershipId>/backend.lock.json`` records(best-effort: a bad record contributes no PID; never raises)."""import json- root = base_dir if base_dir is not None else _hermes_home_dir() / _REMOTE_LOCK_SUBDIRowned: set[int] = set()- try:- entries = list(root.iterdir()) if root.is_dir() else []- except OSError:- return owned+ entries: list[Path] = []+ for root in _remote_lock_roots(base_dir):+ try:+ entries.extend(root.iterdir() if root.is_dir() else [])+ except OSError:+ continuefor entry in entries:ownership_id = entry.namelock_path = entry / "backend.lock.json"diff --git a/tests/hermes_cli/test_orphan_desktop_serve_reap.py b/tests/hermes_cli/test_orphan_desktop_serve_reap.pyindex 46d58d9f18e..48b48ce40c2 100644--- a/tests/hermes_cli/test_orphan_desktop_serve_reap.py+++ b/tests/hermes_cli/test_orphan_desktop_serve_reap.py@@ -162,6 +162,28 @@ def test_lock_owned_serve_pids_reads_valid_backend_lock(tmp_path):assert _lock_owned_serve_pids(base_dir=lock_root) == {7777}+def test_lock_owned_serve_pids_sees_root_home_locks_from_a_profile_home(tmp_path, monkeypatch):+ """A profile backend (``HERMES_HOME=<root>/profiles/<name>``) must still see the Desktop's SSH+ locks, which live under ``<root>/desktop-ssh`` — otherwise its reaper kills the sibling+ profile's live SSH backend on every profile switch (#89811)."""+ import hermes_constants++ root = tmp_path / ".hermes"+ profile_home = root / "profiles" / "flocki"+ profile_home.mkdir(parents=True)+ oid = "f" * 32+ nonce = "d" * 16+ (root / "desktop-ssh" / oid).mkdir(parents=True)+ (root / "desktop-ssh" / oid / "backend.lock.json").write_text(+ json.dumps(_valid_lock_payload(7777, oid, nonce))+ )+ monkeypatch.setenv("HERMES_HOME", str(profile_home))+ monkeypatch.setattr(hermes_constants, "_get_platform_default_hermes_home", lambda: root)+ monkeypatch.setattr(hermes_constants, "_default_hermes_root_memo", None, raising=False)++ assert _lock_owned_serve_pids() == {7777}++def test_valid_lockfile_payload_rejects_wrong_owner_and_shape():oid = "f" * 32nonce = "d" * 16