The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(verify): a verify run's app server dies with the Hermes process running it (orphans after kill -9: 3 -> 0)
kshitijk4poorb4031c37c838
diff --git a/agent/verify/runner.py b/agent/verify/runner.pyindex 1941a452066..be12e5ac3f5 100644--- a/agent/verify/runner.py+++ b/agent/verify/runner.py@@ -19,6 +19,7 @@ from pathlib import Pathfrom typing import Any, Callablefrom agent.verify.recipes import Recipe+from hermes_cli.process_identity import release_process_groups, spawn_ownedDEFAULT_PHASE_TIMEOUT = 600.0DEFAULT_READY_TIMEOUT = 60.0@@ -172,13 +173,16 @@ def _run_start_phase(port = port_override or recipe.port or 8000url = f"http://127.0.0.1:{port}{recipe.readiness_path}"started = time.monotonic()- # start_new_session: own process group for clean teardown.- proc = subprocess.Popen(recipe.start, cwd=str(root), start_new_session=True, **_SUBPROCESS_KW)+ # Owned: the app leads its own group (clean group teardown below) and that group dies with this+ # process if it is killed mid-poll, instead of leaving the dev server running on the port.+ proc = spawn_owned(recipe.start, purpose="verify-app", cwd=str(root), **_SUBPROCESS_KW)output = ""try:ready, status, error = _poll_readiness(url, ready_timeout)finally:_terminate_process_group(proc)+ if proc.poll() is not None:+ release_process_groups([proc.pid])try:output = proc.stdout.read() or "" if proc.stdout is not None else ""except (OSError, ValueError):diff --git a/tests/hermes_cli/test_owned_agent_subprocs.py b/tests/hermes_cli/test_owned_agent_subprocs.pyindex f8ee2453b1b..06eab9775dd 100644--- a/tests/hermes_cli/test_owned_agent_subprocs.py+++ b/tests/hermes_cli/test_owned_agent_subprocs.py@@ -55,6 +55,13 @@ _OWNERS = {"a._host, a._path, a._bridge_token, a._bridge_process = '127.0.0.1', '/wake', 't', None\n""a._spawn_bridge(1)\n"),+ # A dev server that never answers readiness: the owner dies mid-poll.+ "verify-app": (+ "from agent.verify import runner\n"+ "from agent.verify.recipes import Recipe\n"+ "threading.Thread(target=runner._run_start_phase, daemon=True,\n"+ " args=(Recipe(name='x', start=child_cmd, port=1), out, 120.0)).start()\n"+ ),}@@ -134,6 +141,17 @@ def _sleeper() -> subprocess.Popen:start_new_session=True)+def owned(monkeypatch):+ """In-process cases: record registrations instead of starting a real supervisor in pytest."""+ from hermes_cli import process_identity++ groups: list = []+ monkeypatch.setattr(process_identity, "own_process_groups", lambda pgids: groups.extend(pgids))+ monkeypatch.setattr(process_identity, "register_child", lambda pid, purpose: None)+ return groups++def _reap(proc: subprocess.Popen) -> None:if proc.poll() is None:proc.kill()@@ -174,3 +192,14 @@ def test_raft_stop_releases_the_bridge_it_stopped(monkeypatch):assert released == [[bridge.pid]]finally:_reap(bridge)+++def test_verify_start_phase_owns_then_releases_the_app_group(monkeypatch, tmp_path, owned):+ from agent.verify import runner+ from agent.verify.recipes import Recipe++ released = []+ monkeypatch.setattr(runner, "release_process_groups", lambda pgids: released.append(list(pgids)))+ result = runner._run_start_phase(Recipe(name="x", start="sleep 30", port=1), tmp_path, 0.3)+ assert not result.ready+ assert len(owned) == 1 and released == [owned]