The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test: prove a self-reaping supervisor's child is never signalled by the registry
teknium1019a34346cac
diff --git a/tests/tools/test_process_registry.py b/tests/tools/test_process_registry.pyindex 9641d001003..4b7f7c2c5a0 100644--- a/tests/tools/test_process_registry.py+++ b/tests/tools/test_process_registry.py@@ -1722,6 +1722,47 @@ class TestTerminateHostPidPosix:"Parent must receive SIGTERM before any snapshot descendant")+ @pytest.mark.skipif(sys.platform == "win32", reason="POSIX signal ordering; Windows uses taskkill")+ @pytest.mark.live_system_guard_bypass+ def test_posix_self_reaping_supervisor_child_is_never_signalled_by_registry(self, monkeypatch, tmp_path):+ """A parent that tears down its own children on SIGTERM keeps that job.++ #111598: Chromium/Electron reap their zygotes during an async SIGTERM+ shutdown; SIGTERMing the descendants first left the browser without a+ zygote and it crash-dumped (SIGTRAP). Invariant: the registry signals the+ parent first and a child the parent reaps inside the grace window is+ never signalled by the registry, so the parent exits 0.+ """+ monkeypatch.setattr(ProcessRegistry, "_daemon_term_grace_seconds",+ staticmethod(lambda: 2.0))+ log = tmp_path / "order.log"+ child_sh = tmp_path / "child.sh"+ parent_sh = tmp_path / "parent.sh"+ # Child logs a registry-delivered TERM; the parent kills it with KILL+ # (logs nothing) and reaps it, then exits 0 — like a browser reaping its zygote.+ child_sh.write_text(+ "#!/bin/bash\n"+ f"trap 'echo child-TERM >> {log}; exit 0' TERM\n"+ f"echo up >> {log}\nwhile :; do sleep 0.1; done\n")+ parent_sh.write_text(+ "#!/bin/bash\n"+ f"bash {child_sh} & kid=$!\n"+ f"trap 'echo parent-TERM >> {log}; kill -KILL $kid; wait $kid; exit 0' TERM\n"+ "while :; do sleep 0.1; done\n")+ parent = subprocess.Popen(["bash", str(parent_sh)], stdin=subprocess.DEVNULL)+ try:+ assert _wait_until(lambda: log.exists() and "up" in log.read_text(), timeout=5.0)+ ProcessRegistry._terminate_host_pid(parent.pid)+ assert _wait_until(lambda: parent.poll() is not None, timeout=5.0)+ lines = log.read_text().split()+ assert parent.returncode == 0, f"supervisor must exit cleanly, got {parent.returncode}"+ assert "parent-TERM" in lines and "child-TERM" not in lines, (+ f"registry must SIGTERM only the parent, which reaps its own child: {lines}")+ finally:+ if parent.poll() is None:+ parent.kill()+ parent.wait()+def test_posix_oserror_falls_back_to_os_kill(self, monkeypatch):from tools import process_registry as primport psutildiff --git a/tools/AGENTS.md b/tools/AGENTS.mdindex 02ba803521b..90f7972bcd0 100644--- a/tools/AGENTS.md+++ b/tools/AGENTS.md@@ -100,6 +100,17 @@ _record_scope_trust` keys trust on the home; a secondary never adopts the launchfor a same-named server, and `mcp_tool_handlers.py::_trust_gate_check` consults the callingsession's profile.+**Background-process teardown signals the parent first.** `process_registry.py::ProcessRegistry.+_terminate_host_pid` snapshots the descendants, SIGTERMs only the recorded parent, waits+`terminal.daemon_term_grace_seconds` for it to exit and reap its own children, then SIGTERMs the+snapshot survivors and SIGKILLs whatever ignored both (so a supervisor that reaps its tree — a+Chromium/Electron browser reaping its zygotes, a shell trap — exits cleanly, while a shell whose+children ignore SIGHUP still leaves no orphan). Never SIGTERM descendants before the parent: killing+a browser's zygote mid-shutdown turns exit 0 into a SIGTRAP core dump. `_stop_systemd_unit` (scope+teardown, kills the worker cgroup) runs only after that PID kill in `kill()`, or on a parent already+proven dead/recycled (`session.exited`, `_signal_kill` recycled-PID path, checkpoint recovery) —+it is never the first signal a live parent receives.+## Delegation (`tools/delegate_tool.py`)Spawns a subagent with isolated context + terminal session; the parent waits for the summary unless