Skip to content

The agent that grows with you

fix(update): preserve SSH ownership only during updates

fangliquan858916acc484
diff --git a/hermes_cli/dashboard_procs.py b/hermes_cli/dashboard_procs.py
index 3434b152db2..2e8f2b16e89 100644
--- a/hermes_cli/dashboard_procs.py
+++ b/hermes_cli/dashboard_procs.py
@@ -374,11 +374,12 @@ def _kill_stale_dashboard_processes(
except (ValueError, TypeError):
pass
- # An SSH-owned backend belongs to an attached Desktop client even when the
- # updater runs from an unrelated remote shell with no Desktop child PID.
- # Honor the same validated ownership records as the orphan reaper; killing
- # one permanently strands that client's fixed SSH port-forward.
- exclude |= _lock_owned_serve_pids()
+ if restart_managed:
+ # An SSH-owned backend belongs to an attached Desktop client even when
+ # the updater runs from an unrelated remote shell with no Desktop child
+ # PID. Honor the same validated ownership records as the orphan reaper;
+ # killing one permanently strands that client's fixed SSH port-forward.
+ exclude |= _lock_owned_serve_pids()
pids = _m()._find_stale_dashboard_pids(exclude_pids=exclude or None)
if not pids:
diff --git a/tests/hermes_cli/test_update_stale_dashboard.py b/tests/hermes_cli/test_update_stale_dashboard.py
index 85d8dff574b..0e9aca8e224 100644
--- a/tests/hermes_cli/test_update_stale_dashboard.py
+++ b/tests/hermes_cli/test_update_stale_dashboard.py
@@ -88,7 +88,7 @@ def _ps_runner(stdout: str):
return _side_effect
-def test_update_cleanup_spares_backend_owned_by_valid_ssh_lock(tmp_path, monkeypatch):
+def _write_valid_ssh_backend_lock(tmp_path, monkeypatch) -> int:
pid = 4242
ownership_id = "a" * 32
spawn_nonce = "b" * 16
@@ -110,6 +110,11 @@ def test_update_cleanup_spares_backend_owned_by_valid_ssh_lock(tmp_path, monkeyp
}))
monkeypatch.setenv("HERMES_HOME", str(tmp_path))
monkeypatch.delenv("HERMES_DESKTOP_CHILD_PID", raising=False)
+ return pid
+
+
+def test_update_cleanup_spares_backend_owned_by_valid_ssh_lock(tmp_path, monkeypatch):
+ pid = _write_valid_ssh_backend_lock(tmp_path, monkeypatch)
def assert_owned_pid_is_excluded(*, exclude_pids=None):
assert exclude_pids is not None
@@ -125,6 +130,25 @@ def test_update_cleanup_spares_backend_owned_by_valid_ssh_lock(tmp_path, monkeyp
assert result == {"matched": [], "killed": [], "failed": []}
+def test_explicit_stop_does_not_spare_backend_owned_by_valid_ssh_lock(
+ tmp_path,
+ monkeypatch,
+):
+ pid = _write_valid_ssh_backend_lock(tmp_path, monkeypatch)
+
+ def assert_owned_pid_is_not_excluded(*, exclude_pids=None):
+ assert exclude_pids is None or pid not in exclude_pids
+ return []
+
+ with patch(
+ "hermes_cli.main._find_stale_dashboard_pids",
+ side_effect=assert_owned_pid_is_not_excluded,
+ ):
+ result = _kill_stale_dashboard_processes(restart_managed=False)
+
+ assert result == {"matched": [], "killed": [], "failed": []}
+
+
class TestFindStaleDashboardPids:
"""Unit tests for the ps/wmic-based detection step."""