The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): spare the updating Desktop's helper processes on POSIX
ethernetd7973cdc7db1
diff --git a/hermes_cli/main_desktop.py b/hermes_cli/main_desktop.pyindex d74b4eca2f4..9547f5aabbe 100644--- a/hermes_cli/main_desktop.py+++ b/hermes_cli/main_desktop.py@@ -435,12 +435,31 @@ def _stop_desktop_processes_locking_build(desktop_dir: Path, *, also_posix: bool# leaves nobody to relaunch. It also outlives the swap safely because it# relaunches itself afterwards. Windows keeps stopping it: there, the exe# lock would make the rename fail anyway.+ #+ # Spare that Desktop's whole process tree, not just its main process. Its+ # zygote, renderer, GPU and network-service helpers run the same release+ # exe but are siblings of us, not ancestors. Stopping them leaves a main+ # process with no renderer. It cannot draw its update overlay, relaunch, or+ # quit, so it outlives the update forever. (That is the v2026.7.1 Linux+ # in-app update E2E: the receipt succeeds and then the app hangs.)spared: set[int] = set()if sys.platform != "win32":try:- spared = {parent.pid for parent in psutil.Process(me).parents()}+ ancestors = list(psutil.Process(me).parents())except Exception:- spared = set()+ ancestors = []+ for parent in ancestors:+ spared.add(parent.pid)+ try:+ parent_exe = Path(parent.exe()).resolve()+ except Exception:+ continue+ # Only a Desktop ancestor's descendants. Every process descends from+ # init, so sparing all ancestors' trees would spare everything.+ if release_dir not in parent_exe.parents:+ continue+ with contextlib.suppress(Exception):+ spared.update(child.pid for child in parent.children(recursive=True))victims = []try:proc_iter = psutil.process_iter(["pid", "exe"])diff --git a/tests/hermes_cli/test_gui_command.py b/tests/hermes_cli/test_gui_command.pyindex 88b3758911e..776f23c4a97 100644--- a/tests/hermes_cli/test_gui_command.py+++ b/tests/hermes_cli/test_gui_command.py@@ -1096,7 +1096,9 @@ def test_stop_desktop_processes_locking_build_posix_swap_bypasses_early_return(t@pytest.mark.platforms("posix") # Windows must stop the exe-locking ancestor toodef test_posix_swap_spares_the_desktop_driving_this_update(tmp_path, monkeypatch):"""A historical Desktop runs `hermes update` as a piped child and relaunches- itself afterwards; stopping it breaks the update's stdout (EPIPE). Only an+ itself afterwards; stopping it breaks the update's stdout (EPIPE). Its+ renderer/GPU/zygote helpers run the same exe but are not our ancestors;+ stopping them leaves a main process that can neither draw nor quit. Only anunrelated Desktop from the same release tree is stopped."""root = _make_desktop_tree(tmp_path)desktop_dir = root / "apps" / "desktop"@@ -1105,25 +1107,37 @@ def test_posix_swap_spares_the_desktop_driving_this_update(tmp_path, monkeypatchlive_exe.write_text("old", encoding="utf-8")class _FakeProc:- def __init__(self, pid, exe):+ def __init__(self, pid, exe, children=()):self.info = {"pid": pid, "exe": exe}self.pid = pid+ self._children = list(children)++ def exe(self):+ return self.info["exe"]++ def children(self, recursive=False):+ assert recursive+ return self._childrendef terminate(self):return None- driver = _FakeProc(100, str(live_exe))- other = _FakeProc(300, str(live_exe))+ renderer = _FakeProc(101, str(live_exe))+ gpu = _FakeProc(102, str(live_exe))+ driver = _FakeProc(100, str(live_exe), children=[renderer, gpu])+ # A non-Desktop ancestor's tree (think init) must not spare everything.+ shell = _FakeProc(1, "/usr/bin/bash", children=[driver, renderer, gpu, _FakeProc(300, str(live_exe))])+ other = shell._children[-1]class _FakePsutil:@staticmethoddef Process(pid):assert pid == os.getpid()- return types.SimpleNamespace(parents=lambda: [driver])+ return types.SimpleNamespace(parents=lambda: [driver, shell])@staticmethoddef process_iter(attrs):- return [driver, other]+ return [driver, renderer, gpu, other]@staticmethoddef wait_procs(victims, timeout=5):