The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
chore(update): Windows-safe subprocess and signal calls in the POSIX pause
Teknium82d3d3b00037
diff --git a/hermes_cli/update_cmd_posix_pause.py b/hermes_cli/update_cmd_posix_pause.pyindex 43c2dfc04cf..2426059ab2a 100644--- a/hermes_cli/update_cmd_posix_pause.py+++ b/hermes_cli/update_cmd_posix_pause.py@@ -253,7 +253,8 @@ def _escape_cgroup(unit: dict) -> bool:f"hermes-update-{os.getpid()}.scope", "fail", "2", "PIDs", "au", str(len(pids)), *map(str, pids),"Description", "s", f"hermes update (outside {unit['unit']} while it is paused)", "0"]with suppress(OSError, subprocess.SubprocessError):- subprocess.run(cmd, capture_output=True, text=True, timeout=15, check=False)+ subprocess.run(cmd, capture_output=True, text=True, encoding="utf-8", errors="replace",+ stdin=subprocess.DEVNULL, timeout=15, check=False)deadline = time.monotonic() + 5.0while time.monotonic() < deadline:if not _inside(_pid_cgroup(), unit["cgroup"]):@@ -327,7 +328,8 @@ def _stop_job(job: dict) -> None:if home := gateway_pid_home(job["pid"]):_write_update_planned_stop_marker(Path(home), job["pid"])result = subprocess.run(["launchctl", "bootout", f"{job['domain']}/{job['label']}"],- capture_output=True, text=True, timeout=90, check=False)+ capture_output=True, text=True, encoding="utf-8", errors="replace",+ stdin=subprocess.DEVNULL, timeout=90, check=False)if result.returncode != 0 and _alive(job["pid"], None):raise PauseRefused(f"launchctl bootout {job['label']} failed: {(result.stderr or '').strip()}")_wait_gone([job["pid"]], 30.0)@@ -337,7 +339,8 @@ def _start_job(job: dict) -> None:from hermes_cli.gateway import _launchctl_bootstrap, _wait_for_launchd_service_pid_launchctl_bootstrap(job["domain"], job["plist"], job["label"])subprocess.run(["launchctl", "kickstart", f"{job['domain']}/{job['label']}"],- capture_output=True, text=True, timeout=30, check=False)+ capture_output=True, text=True, encoding="utf-8", errors="replace",+ stdin=subprocess.DEVNULL, timeout=30, check=False)if not _wait_for_launchd_service_pid(job["label"], old_pid=job["pid"], timeout=15.0, domain=job["domain"]):raise RuntimeError(f"{job['label']} did not come back under launchd")@@ -396,7 +399,7 @@ def _stop_bare(token: dict, bare: list[dict]) -> None:survivors = _wait_gone(born, _drain_timeout(acks), born)for pid in survivors:with suppress(ProcessLookupError, PermissionError):- os.kill(pid, signal.SIGKILL)+ os.kill(pid, getattr(signal, "SIGKILL", signal.SIGTERM))if _wait_gone(survivors, 10.0, born):raise PauseRefused("gateway PID(s) " + ", ".join(map(str, sorted(survivors))) + " did not stop")diff --git a/tests/e2e/core/upgrade/git/test_hostile_pause.py b/tests/e2e/core/upgrade/git/test_hostile_pause.pyindex 0076ad117f7..3f2f8f58227 100644--- a/tests/e2e/core/upgrade/git/test_hostile_pause.py+++ b/tests/e2e/core/upgrade/git/test_hostile_pause.py@@ -90,7 +90,7 @@ def w() -> Iterator[G.World]:try:with G.world(root, base=I.head_sha()) as world:cfg_path = world.sb.hermes_home / "config.yaml"- cfg = (yaml.safe_load(cfg_path.read_text(encoding="utf-8")) if cfg_path.is_file() else None) or {}+ cfg = (yaml.safe_load(cfg_path.read_text(encoding="utf-8-sig")) if cfg_path.is_file() else None) or {}cfg["updates"] = {**(cfg.get("updates") or {}), "check": False}cfg_path.write_text(yaml.safe_dump(cfg, sort_keys=False), encoding="utf-8")yield world@@ -148,7 +148,7 @@ def _record(w: G.World) -> list[dict]:found = []for p in sorted(w.sb.hermes_home.glob(".hermes-update-paused-gateways*.json")):with contextlib.suppress(OSError, ValueError):- found.append({"path": p.name, **json.loads(p.read_text(encoding="utf-8"))})+ found.append({"path": p.name, **json.loads(p.read_text(encoding="utf-8-sig"))})return found@@ -376,7 +376,7 @@ def test_sigkill_mid_stop_next_launch_restores_exactly_the_set(w):raise AssertionError("premise: the update exited before its stop request:\n"+ _read(w.sb.root / "update-e.log")[-6000:])with contextlib.suppress(OSError, ValueError):- return json.loads(marker.read_text(encoding="utf-8")).get("target_pid") == gw_pid+ return json.loads(marker.read_text(encoding="utf-8-sig")).get("target_pid") == gw_pidreturn FalseH.wait_for(_request_on_disk, timeout=900, interval=0.2, what="the updater's stop request on disk")@@ -521,7 +521,7 @@ def test_desktop_handoff_update_pauses_and_restarts_through_the_same_path(w):def finished() -> dict | None: # posix.sh re-execs itself detached (--daemonized)with contextlib.suppress(OSError, ValueError):- return json.loads(result.read_text(encoding="utf-8"))+ return json.loads(result.read_text(encoding="utf-8-sig"))return Noneres = {}with contextlib.suppress(AssertionError):diff --git a/tests/hermes_cli/test_update_posix_pause.py b/tests/hermes_cli/test_update_posix_pause.pyindex c9a8d108e7a..ec56a5e601b 100644--- a/tests/hermes_cli/test_update_posix_pause.py+++ b/tests/hermes_cli/test_update_posix_pause.py@@ -79,9 +79,9 @@ def test_a_launchd_job_is_paused_through_launchd_and_restarted_through_it(tmp_paplist = tmp_path / f"{label}.plist"plist.write_bytes(plistlib.dumps({"Label": label, "ProgramArguments": ["/bin/sleep", "600"],"RunAtLoad": True, "KeepAlive": True}))- domain = f"gui/{os.getuid()}"+ domain = f"gui/{os.getuid()}" # windows-footgun: ok — macOS-only test (platforms("macos"))if subprocess.run(["launchctl", "print", domain], capture_output=True, check=False).returncode:- domain = f"user/{os.getuid()}"+ domain = f"user/{os.getuid()}" # windows-footgun: ok — macOS-only test (platforms("macos"))def pid() -> int | None:return _gw()._launchd_print_service_pid(domain, label)[1]