The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(process-registry): has_active_processes filters on the raw owner, stamp WSL chains
Brooklyn Nicholson4a5551b5948d
diff --git a/tools/process_registry.py b/tools/process_registry.pyindex 6c7377a6ee9..207a66e5a89 100644--- a/tools/process_registry.py+++ b/tools/process_registry.py@@ -542,6 +542,8 @@ class ProcessSession:detached: bool = False # Recovered from checkpoint (no pipe)pid_scope: str = "host" # "host" for local/PTY PIDs, "sandbox" for env-local PIDssystemd_unit: str = "" # transient scope unit name when spawned under systemd-run+ wsl_chain: bool = False # spawned via wsl[.exe]: the host PID is the short-lived+ # launcher; Linux-side workers outlive it (#120546)handoff_note: str = "" # why a subagent handed this process to its parent (rides the notice)persist_on_release: bool = False # opt out of agent-lifecycle cleanup (release()/turn-abandon kill# sweeps), per terminal(background=true, persist_on_release=true) (#41225)@@ -610,7 +612,7 @@ _WATCHER_ROUTE_KEYS = ("platform", "chat_id", "user_id", "user_name", "thread_id# Session fields persisted verbatim in the crash-recovery checkpoint (plus# ``session_id``; ``command`` is redacted and ``owner_task_id`` defaulted on write)._CHECKPOINT_FIELDS = (- "command", "pid", "pid_scope", "host_start_time", "systemd_unit", "cwd",+ "command", "pid", "pid_scope", "host_start_time", "systemd_unit", "wsl_chain", "cwd","started_at", "task_id", "owner_task_id", "session_key",*(f"watcher_{k}" for k in _WATCHER_ROUTE_KEYS), "watcher_interval","parent_session_id", "notify_on_complete", "completion_output_chars", "watch_patterns",@@ -622,6 +624,41 @@ _CHECKPOINT_DEFAULTS = {}+_WSL_LAUNCHER_NAMES = frozenset({"wsl", "wsl.exe"})++_WSL_CHAIN_NOTE = (+ "Spawned via a wsl[.exe] launcher: the recorded host PID is the short-lived "+ "launcher, not the Linux-side workers. Inspect them with `wsl -e ps` / "+ "`wsl --list --running` from the host."+)+++def _is_wsl_launcher_command(command: str) -> bool:+ """True when *command* routes through a ``wsl[.exe]`` launcher chain (#120546).++ The host PID recorded for such a spawn belongs to the short-lived launcher;+ grandchildren inside the VM outlive it, so the entry must say so instead of+ letting host-side hunting fail silently.+ """+ if not isinstance(command, str) or not command.strip():+ return False+ candidates = []+ try:+ candidates.append((shlex.split(command, posix=True) or [""])[0])+ except ValueError:+ pass+ # POSIX shlex eats Windows backslashes (``C:\...\wsl.exe``), so also try+ # the naive first token where path separators survive.+ words = command.strip().split()+ if words:+ candidates.append(words[0])+ for first in candidates:+ base = os.path.basename(first.replace("\\", "/")).strip("'\"").lower()+ if base in _WSL_LAUNCHER_NAMES:+ return True+ return False++class ProcessRegistry(ProcessCheckpointMixin):"""In-memory registry of running and finished background processes.Thread-safe: accessed from executor threads (terminal_tool, process handlers),@@ -1202,6 +1239,7 @@ class ProcessRegistry(ProcessCheckpointMixin):id=f"proc_{uuid.uuid4().hex[:12]}", command=command, task_id=task_id,owner_task_id=owner_task_id, session_key=session_key, cwd=cwd,parent_session_id=get_session_env("HERMES_SESSION_ID", ""),+ wsl_chain=_is_wsl_launcher_command(command),started_at=time.time(), **extra)@staticmethod@@ -2474,6 +2512,9 @@ class ProcessRegistry(ProcessCheckpointMixin):# these are the long-lived background processes a user may have forgotten about (#29177).if task_id and session_key and s.owner_task_id != task_id and s.session_key == session_key:entry["session_scoped"] = True+ if s.wsl_chain:+ entry["wsl_chain"] = True+ entry["wsl_note"] = _WSL_CHAIN_NOTE# Trigger metadata for goal-loop judges (a watcher may never exit).if s.watch_patterns and not s._watch_disabled:entry.update(watch_patterns=list(s.watch_patterns), watch_hit=s._watch_hits > 0)@@ -2503,8 +2544,12 @@ class ProcessRegistry(ProcessCheckpointMixin):return any(not s.exited and predicate(s) for s in self._running.values())def has_active_processes(self, task_id: str) -> bool:- """Whether any process for ``task_id`` is still running."""- return self._any_running(lambda s: s.task_id == task_id)+ """Whether any process for ``task_id`` is still running. Ownership is+ ``owner_task_id`` (the raw spawning id) like the other task-scoped queries:+ ``task_id`` on a session is the collapsed container key, shared across+ turns and delegate children, so a container-key match alone would miss a+ delegate child's own background work (#120546)."""+ return self._any_running(lambda s: s.owner_task_id == task_id)def running_owned_by(self, owner_task_id: str) -> List[ProcessSession]:"""Running processes whose RAW spawning owner is ``owner_task_id``."""