diff --git a/strata_cli/cli.py b/strata_cli/cli.py index ff7995b8..001ae125 100644 --- a/strata_cli/cli.py +++ b/strata_cli/cli.py @@ -1069,9 +1069,27 @@ def _runtime(a: argparse.Namespace) -> int: (" config/launch verified" if result.get("launch_attested") else "") + (f" {readiness_label}" if readiness_label else "") + (f" {result['error']}" if result.get("error") else "")) + if not result["ok"] and a.runtime_command in ("start", "restart", "verify"): + for line in _engine_log_hint(a.profile): + print(line, file=sys.stderr) return 0 if result["ok"] else result.get("exit_code", 6) +def _engine_log_hint(profile: str) -> list[str]: + """Where the engine wrote why it stopped, and its last lines: "server_exited" alone names nothing to read.""" + try: + path, _saved, _revision = profiles.resolve(profile) + log = profiles.read_run_config(path).get("log") + if not isinstance(log, str) or not log: + return [] + text = Path(log).expanduser().read_text(encoding="utf-8", errors="replace") + except (ProfileError, OSError, ValueError, KeyError): + return [] + lines = [line.strip() for line in text.splitlines() if line.strip()] + tail = lines[-3:] + return [f"engine log: {log}"] + [f" {line[:300]}" for line in tail] + + def _ops(a: argparse.Namespace) -> int: from strata_control import journal, recipes machine = a.output == "json" diff --git a/strata_control/doctor.py b/strata_control/doctor.py index 1538796c..3691febb 100644 --- a/strata_control/doctor.py +++ b/strata_control/doctor.py @@ -9,6 +9,7 @@ import os import re import shutil import subprocess +import sys from importlib import metadata, util from pathlib import Path @@ -221,6 +222,9 @@ def inspect(config_path: Path | None, *, profile_id: str | None = None, live: bo if item["status"] in ("missing", "invalid") and item["required"]: report["issues"].append({"code": "COMPONENT_" + item["status"].upper(), "severity": "error", "component": item["name"], "message": item.get("reason") or "required component unavailable"}) + access = _device_access_issue(cfg.get("backend")) + if access: + report["issues"].append(access) if live: report["live_gpu_probe"], live_issues = _live_probe(cfg, report["backend"]) report["issues"].extend(live_issues) @@ -229,6 +233,22 @@ def inspect(config_path: Path | None, *, profile_id: str | None = None, live: bo return report +def _device_access_issue(backend: str | None, dev_root: str = "/dev") -> dict | None: + """Linux Intel (SYCL) and AMD (HIP) open the card through /dev/dri/renderD* (and /dev/kfd): a user outside the `render` + group gets "No device of requested type available" from the engine, which names nothing to fix. None when it is fine, + cannot apply (other OS, other backend) or there is no such device node at all.""" + if backend not in ("sycl", "hip") or not sys.platform.startswith("linux"): + return None + nodes = sorted(Path(dev_root, "dri").glob("renderD*")) + if backend == "hip" and Path(dev_root, "kfd").exists(): + nodes.append(Path(dev_root, "kfd")) + if not nodes or any(os.access(node, os.R_OK | os.W_OK) for node in nodes): + return None + return {"code": "GPU_DEVICE_ACCESS", "severity": "warning", + "message": f"this user cannot open {', '.join(str(n) for n in nodes)}; the {backend} engine will not see the card. " + "Add the user to the `render` group (and `video` for some distributions), then log in again"} + + def _monitor_component() -> dict: component = {"name": "monitor_tui", "kind": "python_module", "required": False, "expected_version": MONITOR_TEXTUAL_VERSION} diff --git a/tests/terminal/test_archive_gaps.py b/tests/terminal/test_archive_gaps.py index 96357800..efe7cec8 100644 --- a/tests/terminal/test_archive_gaps.py +++ b/tests/terminal/test_archive_gaps.py @@ -117,6 +117,27 @@ class HipPackageForAnotherCard(unittest.TestCase): self.assertEqual(ec.resolve(root, backend="hip").backend, "hip") +class DeviceAccess(unittest.TestCase): + def test_a_render_node_the_user_cannot_open_is_named(self): + from strata_control import doctor + if not sys.platform.startswith("linux"): + self.skipTest("Linux device nodes") + with tempfile.TemporaryDirectory() as d: + (Path(d) / "dri").mkdir() + node = Path(d) / "dri" / "renderD128" + node.write_text("", encoding="utf-8") + os.chmod(node, 0) + if os.access(node, os.R_OK): + self.skipTest("running as a user that can open anything") + issue = doctor._device_access_issue("sycl", d) + self.assertEqual(issue["code"], "GPU_DEVICE_ACCESS") + self.assertIn("render", issue["message"]) + os.chmod(node, 0o666) + self.assertIsNone(doctor._device_access_issue("sycl", d)) + self.assertIsNone(doctor._device_access_issue("cuda", d)) + self.assertIsNone(doctor._device_access_issue("hip", tempfile.gettempdir() + "/none")) + + class ArchiveContents(unittest.TestCase): def test_the_fingerprint_table_models_import_reads_is_in_the_payload(self): sys.path.insert(0, str(ROOT / "packaging"))