Skip to content

The agent that grows with you

refactor(tools): move WSL launcher detection to process_registry_wsl

Teknium1cea505a540d
diff --git a/tools/process_registry.py b/tools/process_registry.py
index 0a83b2db9bb..c4d91ee0b17 100644
--- a/tools/process_registry.py
+++ b/tools/process_registry.py
@@ -37,6 +37,7 @@ from tools.process_registry_checkpoint import ProcessCheckpointMixin
from tools.process_registry_termination import ProcessTerminationMixin
from tools.process_registry_results import load_completed_results, save_completed_result
from tools.process_registry_env_log import log_delta_command
+from tools.process_registry_wsl import _is_wsl_launcher_command
logger = logging.getLogger(__name__)
@@ -661,8 +662,6 @@ _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` / "
@@ -670,32 +669,6 @@ _WSL_CHAIN_NOTE = (
)
-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(ProcessTerminationMixin, ProcessCheckpointMixin):
"""In-memory registry of running and finished background processes.
Thread-safe: accessed from executor threads (terminal_tool, process handlers),
diff --git a/tools/process_registry_wsl.py b/tools/process_registry_wsl.py
new file mode 100644
index 00000000000..d20f6e43ef4
--- /dev/null
+++ b/tools/process_registry_wsl.py
@@ -0,0 +1,34 @@
+"""Detect background spawns routed through a ``wsl[.exe]`` launcher chain (#120546)."""
+
+from __future__ import annotations
+
+import os
+import shlex
+
+_WSL_LAUNCHER_NAMES = frozenset({"wsl", "wsl.exe"})
+
+
+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