The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(git): a bounded git maintenance run dies with its owner; the commit-graph refresh is marked detached
kshitijk4poorfc67e99e9987
diff --git a/hermes_cli/git_commit_graph.py b/hermes_cli/git_commit_graph.pyindex af090ed4a6f..b71d4677119 100644--- a/hermes_cli/git_commit_graph.py+++ b/hermes_cli/git_commit_graph.py@@ -113,18 +113,21 @@ def run_bounded_git(repo_root: str, args: Sequence[str], timeout: float, env: OpReturns the exit code, or None when the timeout killed it; a failure is logged with git's laststderr line. ``repack`` forks ``pack-objects``; ``subprocess.run(timeout=)`` killed only theparent and left the grandchild packing for days, and a daemon thread's child outlived the CLI the- same way. A new session/process group + ``atexit`` reaps both cases, SIGTERM first so git can- delete its own lock and tmp files.+ same way. An owned process group (``spawn_owned``) + ``atexit`` reaps both cases, SIGTERM first so+ git can delete its own lock and tmp files, and the owner-death supervisor kills the group when we+ are SIGKILLed or OOM-killed mid-repack."""+ from hermes_cli.process_identity import release_process_group_once_empty, spawn_owned+cmd = ["git", *args]if os.name == "posix":cmd = ["nice", "-n", "19", *cmd]- group_kw: dict = {"process_group": 0}+ group_kw: dict = {}else:group_kw = {"creationflags": getattr(subprocess, "CREATE_NEW_PROCESS_GROUP", 0)}with tempfile.TemporaryFile() as err:- proc = subprocess.Popen(cmd, cwd=repo_root, stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL,- stderr=err, env=env, **group_kw)+ proc = spawn_owned(cmd, purpose=f"git {args[0]}", cwd=repo_root, stdin=subprocess.DEVNULL,+ stdout=subprocess.DEVNULL, stderr=err, env=env, **group_kw)def _reap() -> None:if proc.poll() is None:@@ -139,6 +142,7 @@ def run_bounded_git(repo_root: str, args: Sequence[str], timeout: float, env: Opreturn Nonefinally:atexit.unregister(_reap)+ release_process_group_once_empty(proc.pid, proc=proc)if rc:err.seek(0)lines = err.read()[-4096:].decode("utf-8", "replace").strip().splitlines()@@ -273,6 +277,7 @@ def spawn_commit_graph_refresh(repo_root: Path) -> bool:stderr=subprocess.DEVNULL, close_fds=True)try:try:+ # detached-spawn: ok — the refresh must neither delay the update nor die with it; slot-locked, boundedsubprocess.Popen(argv, **kwargs, **windows_detach_popen_kwargs())except OSError:if not IS_WINDOWS:diff --git a/tests/hermes_cli/test_owned_agent_subprocs.py b/tests/hermes_cli/test_owned_agent_subprocs.pyindex a2950096075..5817f1d33be 100644--- a/tests/hermes_cli/test_owned_agent_subprocs.py+++ b/tests/hermes_cli/test_owned_agent_subprocs.py@@ -81,6 +81,16 @@ _OWNERS = {"messaging._ensure_whatsapp_bridge_dependencies = lambda bridge_dir: None\n""messaging._spawn_whatsapp_pairing_process(out / 'session', 'bot')\n"),+ # `git repack` (here a `git` on PATH that execs the child, the way repack forks pack-objects): the+ # owner dies inside the bounded wait.+ "git-maintenance": (+ "bindir = out / 'bin'; bindir.mkdir()\n"+ "(bindir / 'git').write_text('#!/bin/sh\\nexec ' + child_cmd + '\\n', encoding='utf-8')\n"+ "(bindir / 'git').chmod(0o755)\n"+ "os.environ['PATH'] = str(bindir) + os.pathsep + os.environ['PATH']\n"+ "from hermes_cli.git_commit_graph import run_bounded_git\n"+ "threading.Thread(target=run_bounded_git, args=(str(out), ['repack', '-d'], 120.0), daemon=True).start()\n"+ ),# A command provider that stalls: the owner dies inside its 120 s idle timeout."tts-command": ("from tools.tts_command_provider import run_command_provider\n"