The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(windows): route every bare-bash spawn through _find_bash and surface silent interpreter failures
teknium185564321be7b
diff --git a/agent/skill_preprocessing.py b/agent/skill_preprocessing.pyindex 18d90e9e76c..9d2e40e11b1 100644--- a/agent/skill_preprocessing.py+++ b/agent/skill_preprocessing.py@@ -77,6 +77,10 @@ def run_inline_shell(command: str, cwd: Path | None, timeout: int) -> str:return f"[inline-shell timeout after {timeout}s: {command}]"return f"[inline-shell error: {exc}]"output = (completed.stdout or "").rstrip("\n") or (completed.stderr or "").rstrip("\n")+ if completed.returncode != 0 and not output:+ # rc!=0 with no output at all is indistinguishable from a legit empty result; it is the+ # "interpreter never ran the command" signature (WSL stub without a distro) — say so.+ return f"[inline-shell exit {completed.returncode} with no output: {command}]"if len(output) > _INLINE_SHELL_MAX_OUTPUT:output = output[:_INLINE_SHELL_MAX_OUTPUT] + "...[truncated]"return outputdiff --git a/gateway/platforms/webhook_filters.py b/gateway/platforms/webhook_filters.pyindex b0f2b88c91c..9fbc9058512 100644--- a/gateway/platforms/webhook_filters.py+++ b/gateway/platforms/webhook_filters.py@@ -177,10 +177,16 @@ class WebhookRouteProcessor:logger.warning("[webhook] script ignored webhook: %s", error)return False, Noneis_shell = path.suffix.lower() in {".sh", ".bash"}- interpreter = (shutil.which("bash") or ("/bin/bash" if os.path.isfile("/bin/bash") else None)) if is_shell else sys.executable- if interpreter is None:- logger.warning("[webhook] script ignored webhook: bash not found")- return False, None+ interpreter = sys.executable+ if is_shell:+ # ``shutil.which("bash")`` inherits PATH order and returns System32's WSL stub on+ # Windows hosts where System32 precedes Git (#116818); ``_find_bash`` probes Git Bash first.+ from tools.environments.local import _find_bash+ try:+ interpreter = _find_bash()+ except RuntimeError as exc:+ logger.warning("[webhook] script ignored webhook: %s", exc)+ return False, Nonetry:from tools.environments.local import build_subprocess_envpopen_kwargs = {"creationflags": 0x08000000} if sys.platform == "win32" else {}@@ -202,7 +208,10 @@ class WebhookRouteProcessor:logger.warning("[webhook] Failed to redact script output: %s", exc)stdout = stderr = "[REDACTED - redaction failed]"if result.returncode != 0:- logger.info("[webhook] script ignored webhook path=%s code=%s stderr=%s", path.name, result.returncode, stderr[:200])+ # A veto normally says why; rc!=0 with NO output at all is the "interpreter never+ # started" signature (WSL stub, missing shebang target) and must reach errors.log.+ level = logging.WARNING if not stdout and not stderr else logging.INFO+ logger.log(level, "[webhook] script ignored webhook path=%s code=%s stderr=%s", path.name, result.returncode, stderr[:200])if result.returncode != 0 or not stdout or stdout == "[SILENT]":return False, Nonetry:diff --git a/hermes_cli/main_tui_launch.py b/hermes_cli/main_tui_launch.pyindex 4dc448a60f1..aac76bd8222 100644--- a/hermes_cli/main_tui_launch.py+++ b/hermes_cli/main_tui_launch.py@@ -342,11 +342,12 @@ def _ensure_tui_node() -> None:try:# Helper logs to stderr; stdout carries `command -v node` — subshell PATH# edits don't leak back into Python, so the capture is the bridge.+ from tools.environments.local import _find_bash # not a bare "bash": System32's WSL stub wins CreateProcessresult = subprocess.run(- ["bash", "-c", f'source "{helper}" >&2 && ensure_node >&2 && command -v node'],+ [_find_bash(), "-c", f'source "{helper}" >&2 && ensure_node >&2 && command -v node'],env={**os.environ, "HERMES_HOME": hermes_home},capture_output=True, text=True, encoding="utf-8", errors="replace", check=False)- except (OSError, subprocess.SubprocessError):+ except (OSError, RuntimeError, subprocess.SubprocessError): # RuntimeError: no Git Bash on Windowsreturnparts = os.environ.get("PATH", "").split(os.pathsep)diff --git a/hermes_constants.py b/hermes_constants.pyindex 5cd02949186..d4a4c37db89 100644--- a/hermes_constants.py+++ b/hermes_constants.py@@ -653,12 +653,14 @@ def _run_node_bootstrap(func: str, *, timeout: int, **extra_env: str) -> bool:return Falseimport subprocesstry:+ # Never a bare "bash": CreateProcess resolves it to System32's WSL launcher on Windows.+ from tools.environments.local import _find_bashresult = subprocess.run(- ["bash", "-c", f'source "{_NODE_BOOTSTRAP_SCRIPT}" && {func}'],+ [_find_bash(), "-c", f'source "{_NODE_BOOTSTRAP_SCRIPT}" && {func}'],env={**os.environ, "HERMES_HOME": str(get_hermes_home()), **extra_env},capture_output=True, timeout=timeout, check=False,)- except (OSError, subprocess.SubprocessError):+ except (OSError, RuntimeError, subprocess.SubprocessError): # RuntimeError: no Git Bash on Windowsreturn Falsereturn result.returncode == 0diff --git a/tests/agent/test_skill_inline_shell_output.py b/tests/agent/test_skill_inline_shell_output.pynew file mode 100644index 00000000000..16721afb30c--- /dev/null+++ b/tests/agent/test_skill_inline_shell_output.py@@ -0,0 +1,11 @@+"""Inline-shell snippets never turn a silent failure into an empty (looks-fine) result."""+from agent.skill_preprocessing import run_inline_shell+++def test_silent_nonzero_exit_returns_marker(tmp_path):+ """rc!=0 with no stdout and no stderr is the interpreter-never-ran signature (#116818)."""+ assert run_inline_shell("exit 3", tmp_path, 5) == "[inline-shell exit 3 with no output: exit 3]"+++def test_nonzero_exit_with_stderr_keeps_the_diagnostic(tmp_path):+ assert run_inline_shell('printf "diag" >&2; exit 3', tmp_path, 5) == "diag"diff --git a/tests/gateway/test_webhook_filter_interpreter.py b/tests/gateway/test_webhook_filter_interpreter.pynew file mode 100644index 00000000000..d3e5dbc5fb3--- /dev/null+++ b/tests/gateway/test_webhook_filter_interpreter.py@@ -0,0 +1,53 @@+"""Webhook filter scripts run under the Git-Bash-safe interpreter and log silent failures."""+import logging+import stat++import pytest++from gateway.platforms.webhook_filters import WebhookRouteProcessor+from tools.environments import local+++def _filter_script(body: str):+ from hermes_constants import get_hermes_home+ scripts = get_hermes_home() / "scripts"+ scripts.mkdir(parents=True, exist_ok=True)+ filt = scripts / "filter.sh"+ filt.write_text(body, encoding="utf-8")+ return filt+++def _fake_bash(tmp_path, body: str):+ script = tmp_path / "fake-bash"+ script.write_text("#!/bin/sh\n" + body, encoding="utf-8")+ script.chmod(script.stat().st_mode | stat.S_IXUSR)+ return script++[email protected]_only # POSIX shebang fixture; the Windows half is the wine2e receipt+def test_shell_filter_runs_under_find_bash_interpreter(tmp_path, monkeypatch):+ """The .sh filter must be spawned through ``_find_bash()``, never a PATH/``which`` lookup (#116818)."""+ marker = tmp_path / "ran"+ fake = _fake_bash(tmp_path, f'touch "{marker}"\nprintf \'{{"ok": true}}\'\n')+ monkeypatch.setattr(local, "_find_bash", lambda: str(fake))+ filt = _filter_script("exit 99\n") # would veto if run by a real bash++ accepted, transformed = WebhookRouteProcessor().run_route_script(str(filt), {"a": 1})++ assert marker.exists()+ assert accepted is True and transformed == {"ok": True}++[email protected]_only # POSIX shebang fixture; the Windows half is the wine2e receipt+def test_silent_nonzero_exit_is_logged_as_warning(tmp_path, monkeypatch, caplog):+ """rc!=0 with no stdout AND no stderr is the interpreter-never-ran signature: WARNING, not INFO."""+ fake = _fake_bash(tmp_path, "exit 1\n")+ monkeypatch.setattr(local, "_find_bash", lambda: str(fake))+ filt = _filter_script("")++ with caplog.at_level(logging.INFO, logger="gateway.platforms.webhook_filters"):+ accepted, _ = WebhookRouteProcessor().run_route_script(str(filt), {})++ assert accepted is False+ silent = [r for r in caplog.records if "script ignored webhook path=filter.sh" in r.getMessage()]+ assert silent and silent[0].levelno == logging.WARNING