The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): stop scraping /mnt/ PATH entries into WSL interop unit PATH
Brooklyn Nicholson985d0749ed1a
diff --git a/hermes_cli/gateway.py b/hermes_cli/gateway.pyindex b99488bee70..c0c74c2a165 100644--- a/hermes_cli/gateway.py+++ b/hermes_cli/gateway.py@@ -3009,11 +3009,17 @@ def _build_user_local_paths(home: Path, path_entries: list[str]) -> list[str]:def _build_wsl_interop_paths(path_entries: list[str]) -> list[str]:"""WSL Windows-interop PATH entries for generated units: systemd services don't inherit the- Windows PATH (``/mnt/c/WINDOWS/System32``…), so ``powershell.exe``/``cmd.exe`` break unless persisted."""+ Windows PATH (``/mnt/c/WINDOWS/System32``…), so ``powershell.exe``/``cmd.exe`` break unless persisted.++ Only the which()-resolved tool dirs and the hardcoded System32 family belong here. The+ shell PATH is deliberately NOT scraped: WSL appends every Windows PATH entry (Desktop app,+ git, node dirs under ``/mnt/``) ahead of the interop defaults, and persisting those into the+ unit makes the gateway open 9p (Plan 9 interop) connections to each of them at start — enough+ to exhaust the 9p server connection limit (#73163). Interop tools don't need them."""if not is_wsl():return []- candidates = [entry for entry in os.environ.get("PATH", "").split(os.pathsep) if entry.startswith("/mnt/")]+ candidates: list[str] = []for executable in ("powershell.exe", "cmd.exe", "explorer.exe", "wsl.exe"):resolved = shutil.which(executable)if resolved:diff --git a/tests/hermes_cli/test_gateway_service.py b/tests/hermes_cli/test_gateway_service.pyindex c18e0fed126..0698a70d422 100644--- a/tests/hermes_cli/test_gateway_service.py+++ b/tests/hermes_cli/test_gateway_service.py@@ -394,6 +394,76 @@ class TestGeneratedSystemdUnits:assert "SoftResourceLimits" not in plist+class TestWslInteropPaths:+ """_build_wsl_interop_paths() — only Windows-interop tool dirs belong in the unit's PATH.++ #73163: scraping every ``/mnt/`` entry from the shell PATH persisted heavy+ Desktop-app/git/node dirs into the gateway unit's Environment=PATH, and the+ Plan 9 interop (9p) connections those dirs force at gateway start can+ exhaust the 9p server connection limit. which()-resolved tool dirs and the+ hardcoded System32 set already cover interop.+ """++ def test_arbitrary_mount_entries_are_not_scraped_from_shell_path(self, monkeypatch):+ monkeypatch.setattr(gateway_cli, "is_wsl", lambda: True)+ monkeypatch.setenv(+ "PATH",+ os.pathsep.join(+ [+ "/usr/local/bin",+ "/mnt/d/heavy-app/bin",+ "/mnt/d/tools/git/cmd",+ "/mnt/c/Users/me/AppData/Local/Programs/desktop/bin",+ ]+ ),+ )+ monkeypatch.setattr(gateway_cli.shutil, "which", lambda name: None)+ # The hardcoded candidates (System32…) don't exist on this macOS host, so the+ # expected result is empty — no /mnt/ entry survives.+ monkeypatch.setattr(Path, "exists", lambda self: False)++ result = gateway_cli._build_wsl_interop_paths([])++ assert result == []++ def test_which_resolved_tool_dirs_and_system32_set_are_included(self, monkeypatch):+ monkeypatch.setattr(gateway_cli, "is_wsl", lambda: True)+ monkeypatch.setenv(+ "PATH",+ "/usr/local/bin:/mnt/d/heavy-app/bin:/mnt/c/WINDOWS/system32",+ )++ def fake_which(name):+ resolved = {+ "powershell.exe": "/mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0/powershell.exe",+ "cmd.exe": "/mnt/c/WINDOWS/system32/cmd.exe",+ "explorer.exe": "/mnt/c/WINDOWS/explorer.exe",+ "wsl.exe": "/mnt/c/Windows/System32/wsl.exe",+ }+ return resolved.get(name)++ monkeypatch.setattr(gateway_cli.shutil, "which", fake_which)+ monkeypatch.setattr(Path, "exists", lambda self: True)++ result = gateway_cli._build_wsl_interop_paths(["/mnt/d/heavy-app/bin"])++ # which()-resolved dirs land even when absent from the caller's PATH entry list.+ assert "/mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0" in result+ assert "/mnt/c/WINDOWS/system32" in result+ # Hardcoded System32 family, gated on existence like on a real install.+ assert "/mnt/c/WINDOWS" in result+ assert "/mnt/c/WINDOWS/System32/Wbem" in result+ # Heavy shell-PATH /mnt/ entries never enter, and dedupe keeps out the+ # entry the caller already has.+ assert "/mnt/d/heavy-app/bin" not in result++ def test_outside_wsl_nothing_is_added(self, monkeypatch):+ monkeypatch.setattr(gateway_cli, "is_wsl", lambda: False)+ monkeypatch.setenv("PATH", "/usr/local/bin:/mnt/c/WINDOWS/system32")++ assert gateway_cli._build_wsl_interop_paths([]) == []++class TestGatewayStopCleanup:@pytest.mark.platforms("linux")def test_stop_only_kills_current_profile_by_default(self, tmp_path, monkeypatch):