Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
fix(marketplace): detect AMD hardware before enabling connect
rubenluetke10-beep085bc09a7d0b
diff --git a/jarvis/marketplace/amd_mcp.py b/jarvis/marketplace/amd_mcp.pyindex 92c804fdf0..0fe64dbd69 100644--- a/jarvis/marketplace/amd_mcp.py+++ b/jarvis/marketplace/amd_mcp.py@@ -7,10 +7,58 @@ import jsonimport shutilimport subprocessimport sys+from pathlib import Pathfrom typing import Anyfrom jarvis.core.process_utils import NO_WINDOW_CREATIONFLAGS+_PCI_DEVICES = Path("/sys/bus/pci/devices")+_DRM_DEVICES = Path("/sys/class/drm")+++def _amd_hardware_unavailable_reason() -> str | None:+ """Read Linux device metadata only; an installed CLI is not hardware evidence.++ PCI display/accelerator class filtering avoids treating AMD CPU chipsets as+ GPUs. DRM is a fallback for hosts exposing graphics devices but not the+ complete PCI tree. Restricted/container sysfs is explicitly unverifiable,+ not evidence that the physical host has no AMD GPU.+ """+ readable_root = False+ incomplete = False+ for root, drm in ((_PCI_DEVICES, False), (_DRM_DEVICES, True)):+ try:+ devices = list(root.iterdir())+ readable_root = True+ except OSError:+ # An alternative sysfs view can still prove GPU presence.+ continue+ for entry in devices:+ if drm and not (entry.name.startswith("card") and entry.name[4:].isdigit()):+ continue+ device = entry / "device" if drm else entry+ try:+ vendor = (device / "vendor").read_text(encoding="ascii").strip().lower()+ if vendor != "0x1002":+ continue+ if drm:+ return None+ device_class = int((device / "class").read_text(encoding="ascii").strip(), 16)+ if device_class >> 16 in (0x03, 0x12):+ return None+ except (OSError, UnicodeError, ValueError):+ # Hot unplug and unreadable sysfs must not escape into the UI.+ incomplete = True+ if not readable_root or incomplete:+ return (+ "AMD GPU availability could not be verified from Linux device information. "+ "Check hardware access and permissions, including container device access."+ )+ return (+ "No AMD GPU is visible to this connector. A compatible AMD GPU must be exposed "+ "to this Linux environment before connecting."+ )+def amd_unavailable_reason() -> str | None:"""Cheap preflight for UI availability; connect still checks actual device data."""@@ -24,7 +72,7 @@ def amd_unavailable_reason() -> str | None:"AMD SMI is unavailable. Install AMD's supported SMI/ROCm tooling ""on a compatible AMD host. Missing metrics are never reported as zero.")- return None+ return _amd_hardware_unavailable_reason()def read_amd_status() -> dict[str, Any]:diff --git a/tests/contract/test_service_connectors.py b/tests/contract/test_service_connectors.pyindex a65f63e6a5..304bc903b7 100644--- a/tests/contract/test_service_connectors.py+++ b/tests/contract/test_service_connectors.py@@ -249,13 +249,20 @@ def test_amd_absence_degrades_without_importing_native_libraries(monkeypatch, plamd_mcp.read_amd_status()-def test_amd_reads_only_fixed_json_commands(monkeypatch):+def test_amd_reads_only_fixed_json_commands(monkeypatch, tmp_path):from jarvis.core.process_utils import NO_WINDOW_CREATIONFLAGSfrom jarvis.marketplace import amd_mcpcalls = []monkeypatch.setattr(amd_mcp.sys, "platform", "linux")monkeypatch.setattr(amd_mcp.shutil, "which", lambda _: "/opt/rocm/bin/amd-smi")+ pci = tmp_path / "pci"+ gpu = pci / "gpu-device"+ gpu.mkdir(parents=True)+ (gpu / "vendor").write_text("0x1002\n", encoding="ascii")+ (gpu / "class").write_text("0x030000\n", encoding="ascii")+ monkeypatch.setattr(amd_mcp, "_PCI_DEVICES", pci)+ monkeypatch.setattr(amd_mcp, "_DRM_DEVICES", tmp_path / "drm")def run(args, **kwargs):calls.append(args)diff --git a/tests/unit/marketplace/test_amd_preflight.py b/tests/unit/marketplace/test_amd_preflight.pyindex 3e075dd257..3e45866028 100644--- a/tests/unit/marketplace/test_amd_preflight.py+++ b/tests/unit/marketplace/test_amd_preflight.py@@ -24,9 +24,67 @@ def test_unsupported_os_does_not_launch_cli(monkeypatch, platform):@pytest.fixture-def linux_cli(monkeypatch):+def linux_cli(monkeypatch, tmp_path):monkeypatch.setattr(amd_mcp.sys, "platform", "linux")monkeypatch.setattr(amd_mcp.shutil, "which", lambda _: "/opt/rocm/bin/amd-smi")+ pci = tmp_path / "pci"+ gpu = pci / "gpu-device"+ gpu.mkdir(parents=True)+ (gpu / "vendor").write_text("0x1002\n", encoding="ascii")+ (gpu / "class").write_text("0x030000\n", encoding="ascii")+ monkeypatch.setattr(amd_mcp, "_PCI_DEVICES", pci)+ monkeypatch.setattr(amd_mcp, "_DRM_DEVICES", tmp_path / "drm")+ return gpu++[email protected]("vendor,device_class", [("0x10de", "0x030000"), ("0x1002", "0x060000")])+def test_installed_cli_without_amd_gpu_cannot_connect(monkeypatch, linux_cli, vendor, device_class):+ (linux_cli / "vendor").write_text(vendor, encoding="ascii")+ (linux_cli / "class").write_text(device_class, encoding="ascii")++ def forbidden(*args, **kwargs):+ pytest.fail("Missing AMD hardware must be detected before starting the CLI")++ monkeypatch.setattr(amd_mcp.subprocess, "run", forbidden)+ assert "No AMD GPU is visible" in amd_mcp.amd_unavailable_reason()+ with pytest.raises(RuntimeError, match="No AMD GPU is visible"):+ amd_mcp.read_amd_status()++[email protected]("device_class", ["0x030000", "0x038000", "0x120000"])+def test_pci_amd_graphics_and_compute_devices_pass_preflight(linux_cli, device_class):+ (linux_cli / "class").write_text(device_class, encoding="ascii")+ assert amd_mcp.amd_unavailable_reason() is None+++def test_drm_fallback_can_verify_host_without_pci_view(monkeypatch, linux_cli, tmp_path):+ monkeypatch.setattr(amd_mcp, "_PCI_DEVICES", tmp_path / "hidden-pci")+ device = tmp_path / "drm" / "card1" / "device"+ device.mkdir(parents=True)+ (device / "vendor").write_text("0x1002\n", encoding="ascii")+ assert amd_mcp.amd_unavailable_reason() is None+++def test_missing_sysfs_is_unverifiable_not_false_hardware_absence(monkeypatch, linux_cli, tmp_path):+ monkeypatch.setattr(amd_mcp, "_PCI_DEVICES", tmp_path / "hidden-pci")+ reason = amd_mcp.amd_unavailable_reason()+ assert "could not be verified" in reason+ assert "container" in reason+++def test_unreadable_device_metadata_has_safe_preflight_message(monkeypatch, linux_cli):+ original = amd_mcp.Path.read_text++ def read(path, *args, **kwargs):+ if path == linux_cli / "vendor":+ raise PermissionError("private hardware path")+ return original(path, *args, **kwargs)++ monkeypatch.setattr(amd_mcp.Path, "read_text", read)+ reason = amd_mcp.amd_unavailable_reason()+ assert "could not be verified" in reason+ assert "permissions" in reason+ assert "private" not in reason@pytest.mark.parametrize(