The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test(update): kill the frozen completion child on every exit path
Teknium04cf0eb9a899
diff --git a/tests/e2e/core/upgrade/git/test_hostile_lock.py b/tests/e2e/core/upgrade/git/test_hostile_lock.pyindex a86d103edf8..3df65eab8ab 100644--- a/tests/e2e/core/upgrade/git/test_hostile_lock.py+++ b/tests/e2e/core/upgrade/git/test_hostile_lock.py@@ -99,7 +99,7 @@ if mode == "owner":result["rc"], result["out"] = update("home-a")result["marker_kept"] = marker.exists() and marker.read_text(encoding="utf-8") == bodyowner.kill()-elif mode == "kill-mid-completion":+elif mode in ("kill-mid-completion", "orphan-reader"):first = subprocess.Popen(ARGV, env=envs["home-a"], cwd=checkout, stdin=subprocess.DEVNULL,stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)child = None@@ -108,41 +108,28 @@ elif mode == "kill-mid-completion":child = completion_child(envs["home-a"]["HERMES_HOME"])time.sleep(0.05)result["child_seen"] = child is not None- # Freeze the child (it keeps its fds) so it cannot finish its real work and free the lock- # before the probe below reaches it: on a fast runner it otherwise exits first.- if child is not None:- os.kill(child, signal.SIGSTOP)- os.kill(first.pid, signal.SIGKILL)- first.wait()- result["child_alive_before"] = child is not None and alive(child)- result["rc"], result["out"] = update("home-b")- result["child_alive_after"] = child is not None and alive(child)- if child is not None and alive(child):- os.kill(child, signal.SIGKILL)-elif mode == "orphan-reader":- first = subprocess.Popen(ARGV, env=envs["home-a"], cwd=checkout, stdin=subprocess.DEVNULL,- stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)- child = None- deadline = time.time() + 240- while child is None and time.time() < deadline and first.poll() is None:- child = completion_child(envs["home-a"]["HERMES_HOME"])- time.sleep(0.05)- result["child_seen"] = child is not None- # Freeze the child (it keeps its fds) so it cannot finish its real work and free the lock- # before the probe below reaches it: on a fast runner it otherwise exits first.- if child is not None:- os.kill(child, signal.SIGSTOP)- os.kill(first.pid, signal.SIGKILL)- first.wait()- # The killed owner's marker is gone (any reader compare-and-deletes a dead claim).- (Path(envs["home-a"]["HERMES_HOME"]) / ".hermes-update-in-progress").unlink(missing_ok=True)- reader = subprocess.run([sys.executable, "-c", READER, checkout], env=envs["home-b"], cwd=checkout,- stdin=subprocess.DEVNULL, capture_output=True, text=True, timeout=120)- result["reader_out"] = reader.stdout[-2000:] + reader.stderr[-2000:]- result["reader"] = json.loads(reader.stdout.strip().splitlines()[-1]) if reader.returncode == 0 else None- result["child_alive_after"] = child is not None and alive(child)- if child is not None and alive(child):- os.kill(child, signal.SIGKILL)+ try:+ # Freeze the child (it keeps its fds) so it cannot finish its real work and free the lock+ # before the probe below reaches it: on a fast runner it otherwise exits first.+ if child is not None:+ os.kill(child, signal.SIGSTOP)+ os.kill(first.pid, signal.SIGKILL)+ first.wait()+ result["child_alive_before"] = child is not None and alive(child)+ if mode == "kill-mid-completion":+ result["rc"], result["out"] = update("home-b")+ else:+ # The killed owner's marker is gone (any reader compare-and-deletes a dead claim).+ (Path(envs["home-a"]["HERMES_HOME"]) / ".hermes-update-in-progress").unlink(missing_ok=True)+ reader = subprocess.run([sys.executable, "-c", READER, checkout], env=envs["home-b"], cwd=checkout,+ stdin=subprocess.DEVNULL, capture_output=True, text=True, timeout=120)+ result["reader_out"] = reader.stdout[-2000:] + reader.stderr[-2000:]+ result["reader"] = json.loads(reader.stdout.strip().splitlines()[-1]) if reader.returncode == 0 else None+ result["child_alive_after"] = child is not None and alive(child)+ finally:+ # A stopped child never exits on its own: a failed probe must not leave it holding the lock.+ if child is not None and alive(child):+ os.kill(child, signal.SIGKILL)result["out"] = result.get("out", "")[-4000:]print(json.dumps(result))'''