From 485aaf69b7f0930a5f6631752172d90a4a5575c6 Mon Sep 17 00:00:00 2001 From: Gille <4317663+helix4u@users.noreply.github.com> Date: Thu, 3 Sep 2026 16:04:09 -0600 Subject: [PATCH] fix(local-runtime): find nvidia-smi in WSL driver path --- hermes_cli/local_runtime/hardware.py | 8 +++++++- tests/hermes_cli/test_unified_pool_quirk.py | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/hermes_cli/local_runtime/hardware.py b/hermes_cli/local_runtime/hardware.py index 9dc51bc9af..0f8e2c1ce3 100644 --- a/hermes_cli/local_runtime/hardware.py +++ b/hermes_cli/local_runtime/hardware.py @@ -117,7 +117,7 @@ _smi_path_cache: "tuple[str | None] | None" = None def _nvidia_smi_path() -> str | None: """Absolute path to nvidia-smi, or None. PATH first (respects user overrides), then the - driver's known Windows install locations; on Linux/WSL the PATH lookup is the whole ladder.""" + driver's known install locations on Windows and WSL.""" global _smi_path_cache if _smi_path_cache is not None: return _smi_path_cache[0] @@ -132,6 +132,12 @@ def _nvidia_smi_path() -> str | None: / "NVIDIA Corporation" / "NVSMI" / "nvidia-smi.exe", ) found = next((str(c) for c in candidates if c.exists()), None) + elif found is None and sys.platform.startswith("linux"): + # The Windows display driver exposes nvidia-smi here inside WSL, but does not guarantee + # that the directory is present on PATH. + candidate = Path("/usr/lib/wsl/lib/nvidia-smi") + if candidate.exists(): + found = str(candidate) _smi_path_cache = (found,) return found diff --git a/tests/hermes_cli/test_unified_pool_quirk.py b/tests/hermes_cli/test_unified_pool_quirk.py index 39c7c23ed7..881fc9a557 100644 --- a/tests/hermes_cli/test_unified_pool_quirk.py +++ b/tests/hermes_cli/test_unified_pool_quirk.py @@ -14,6 +14,10 @@ any discrete card.""" from __future__ import annotations +from pathlib import Path + +import pytest + import hermes_cli.local_runtime.hardware as hw GIB = 1 << 30 @@ -185,6 +189,18 @@ def test_smi_resolver_caches_and_survives_empty_path(monkeypatch): assert len(calls) == 1 +@pytest.mark.linux_only +def test_smi_resolver_uses_wsl_driver_path_when_path_is_empty(monkeypatch): + """WSL exposes nvidia-smi through the Windows driver directory even + when a service PATH cannot resolve it.""" + wsl_smi = Path("/usr/lib/wsl/lib/nvidia-smi") + monkeypatch.setattr(hw, "_smi_path_cache", None) + monkeypatch.setattr(hw.shutil, "which", lambda name: None) + monkeypatch.setattr(hw.Path, "exists", lambda candidate: candidate == wsl_smi) + + assert hw._nvidia_smi_path() == str(wsl_smi) + + # ── probe cache ──────────────────────────────────────────────