The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(computer-use): doctor and status report a configured cua-driver daemon whose `serve` is not listening
teknium1f9d6d043320c
diff --git a/hermes_cli/subcommands/computer_use.py b/hermes_cli/subcommands/computer_use.pyindex ac0d52f4b88..76476aca7dc 100644--- a/hermes_cli/subcommands/computer_use.py+++ b/hermes_cli/subcommands/computer_use.py@@ -54,6 +54,15 @@ def _cu_status(args) -> int:else:print(" Run: hermes computer-use install")return 1+ rc = 0+ if sys.platform == "linux": # hand-written daemon units: dead `serve` is invisible to the binary contract (#114748)+ from tools.computer_use.cua_backend import cua_daemon_listening+ from tools.computer_use.doctor import cua_daemon_units+ for _kind, unit, _target, serve, socket in cua_daemon_units():+ if serve and cua_daemon_listening(path, socket) is False:+ print(f" ✗ Daemon unit {unit}: no `cua-driver serve` is listening on {socket or 'the default socket'}")+ print(f" Check: systemctl --user status {unit} (reinstalling the driver does not start it)")+ rc = 1try:st = cua_driver_update_check()if st and st.get("update_available"):@@ -67,7 +76,7 @@ def _cu_status(args) -> int:print(" Refresh to latest: hermes computer-use install --upgrade")except Exception:print(" Refresh to latest: hermes computer-use install --upgrade")- return 0+ return rcdef _cu_doctor(args) -> None:diff --git a/tests/tools/test_computer_use_doctor_stale_units.py b/tests/tools/test_computer_use_doctor_stale_units.pyindex 6c465554789..60e6623a2d3 100644--- a/tests/tools/test_computer_use_doctor_stale_units.py+++ b/tests/tools/test_computer_use_doctor_stale_units.py@@ -1,4 +1,5 @@-"""`hermes computer-use doctor` names a daemon unit whose cua-driver Exec target was pruned (#114748).+"""`hermes computer-use doctor` names a daemon unit whose cua-driver Exec target was pruned, and a configured+`cua-driver serve` unit whose daemon is not listening (#114748).Linux has no managed cua-driver autostart, so users hand-write systemd user units / XDGautostart entries against a concrete ``packages/releases/<version>/`` directory. The installer@@ -37,10 +38,12 @@ def _fake_health_report_proc() -> MagicMock:return proc-def _run_doctor_json(monkeypatch, home):+def _run_doctor_json(monkeypatch, home, daemon_probe=lambda *_a, **_kw: None):+ """``daemon_probe`` stands in for ``cua_daemon_listening`` (the Popen double below breaks ``subprocess.run``)."""monkeypatch.setenv("HOME", str(home))if "XDG_CONFIG_HOME" in os.environ and not os.environ["XDG_CONFIG_HOME"].startswith(str(home)):monkeypatch.delenv("XDG_CONFIG_HOME") # the host's own config dir must not leak into the scan+ monkeypatch.setattr("tools.computer_use.cua_backend.cua_daemon_listening", daemon_probe)monkeypatch.setattr(doctor, "_read_cli_version", lambda binary, timeout=5.0: "cua-driver 0.28.2")out = StringIO()with patch("shutil.which", return_value="/fake/cua-driver"), \@@ -97,3 +100,36 @@ def test_doctor_is_silent_for_current_and_live_release_references(tmp_path, monkassert code == 0 and report["overall"] == "ok"assert not [c for c in report["checks"] if c["name"].startswith("daemon unit")]+++def _write_current_serve_unit(home):+ unit_dir = home / ".config" / "systemd" / "user"+ unit_dir.mkdir(parents=True)+ (unit_dir / "cua-driver-screenshot.service").write_text(+ "[Service]\nExecStart=%h/.cua-driver/packages/current/cua-driver serve --socket %h/.cache/cua-driver/cua-driver.sock\n",+ encoding="utf-8")+++def test_doctor_fails_a_configured_daemon_unit_whose_serve_is_not_listening(tmp_path, monkeypatch):+ """#114748: a healthy binary + a dead `serve` daemon used to be reported as ok; the probe runs against the+ unit's own --socket path (%h expanded), and a reinstall is named as the wrong remedy."""+ _write_current_serve_unit(tmp_path)+ probes = []++ code, report = _run_doctor_json(monkeypatch, tmp_path,+ lambda binary, socket=None, **_kw: probes.append((binary, socket)) or False)++ rows = [c for c in report["checks"] if c["name"] == "daemon (cua-driver-screenshot.service)"]+ assert code == 1 and report["overall"] == "degraded"+ assert rows[0]["status"] == "fail" and "no daemon is listening" in rows[0]["message"]+ assert "reinstall" in rows[0]["hint"]+ assert probes == [("/fake/cua-driver", str(tmp_path / ".cache" / "cua-driver" / "cua-driver.sock"))]+++def test_doctor_passes_a_configured_daemon_unit_whose_serve_answers(tmp_path, monkeypatch):+ _write_current_serve_unit(tmp_path)+ code, report = _run_doctor_json(monkeypatch, tmp_path, lambda *_a, **_kw: True)++ rows = [c for c in report["checks"] if c["name"] == "daemon (cua-driver-screenshot.service)"]+ assert code == 0 and report["overall"] == "ok"+ assert rows[0]["status"] == "pass" and "listening" in rows[0]["message"]diff --git a/tools/computer_use/cua_backend.py b/tools/computer_use/cua_backend.pyindex a93bac895cf..ff64fd8ea67 100644--- a/tools/computer_use/cua_backend.py+++ b/tools/computer_use/cua_backend.py@@ -142,6 +142,19 @@ def _run_driver(driver_cmd: str, *args: str, timeout: float, swallow: Any = ())return _run_quiet([driver_cmd, *args], timeout=timeout, swallow=swallow, encoding="utf-8",errors="replace", creationflags=windows_hide_flags(), env=sanitized_cua_driver_env())+def cua_daemon_listening(driver_cmd: str, socket_path: Optional[str] = None, *, timeout: float = 3.0) -> Optional[bool]:+ """Socket-level liveness of a ``cua-driver serve`` daemon: ``cua-driver status`` connects to the daemon+ socket (the driver's default, or ``socket_path``) and exits 0 only when a daemon answers. False when the+ CLI reports the daemon is not running, None when the probe itself failed (unknown). Never raises.+ The binary-level runtime contract (``manifest``) cannot see this — a dead daemon looks healthy there (#114748)."""+ args = ("status", "--socket", socket_path) if socket_path else ("status",)+ proc = _run_driver(driver_cmd, *args, timeout=timeout, swallow=(OSError, subprocess.SubprocessError))+ if proc is None:+ return None+ if proc.returncode == 0:+ return True+ return False if "not running" in f"{proc.stdout}\n{proc.stderr}".lower() else None+def _linux_session_locked() -> Optional[bool]:"""Is the graphical session locked? (Linux; best-effort.) A locked KDE/GNOME session freezes renderers andhalf-disables the AX tree, so discovery legitimately returns nothing — which otherwise reads as a driver bug.diff --git a/tools/computer_use/doctor.py b/tools/computer_use/doctor.pyindex 1efe3407aa4..66d2832d4fd 100644--- a/tools/computer_use/doctor.py+++ b/tools/computer_use/doctor.py@@ -30,6 +30,10 @@ _IO_EXC = (OSError, subprocess.TimeoutExpired)_PRUNED_UNIT_MSG = "Exec targets {target} which no longer exists — a cua-driver upgrade pruned that release directory"_PRUNED_UNIT_HINT = ("Point the {kind} at ~/.cua-driver/packages/current/cua-driver — `current` survives upgrades; ""versioned packages/releases/<version>/ dirs are pruned (only the last 5 are kept)")+_DEAD_DAEMON_MSG = ("{unit} is configured to run `cua-driver serve` but no daemon is listening on {socket} — "+ "the unit is not running (crash loop, stopped, or never started)")+_DEAD_DAEMON_HINT = ("Check `systemctl --user status {unit}` / `journalctl --user -u {unit}`; a driver reinstall does not "+ "start the daemon and cannot fix a broken unit")Report = Dict[str, Any]_Row = Tuple[str, str, Report] # (status, message, extra {hint?, data?}) for one check@@ -284,19 +288,14 @@ def _apply_display_count_guard(report: Report) -> Report:report["overall"] = "degraded"return report-def _stale_cua_exec_references(config_dir: Optional[str] = None) -> List[Tuple[str, str, str]]:- """(kind, unit, target) for systemd user units / XDG autostart entries whose cua-driver Exec points at a- pruned ``packages/releases/<version>/`` directory.-- Linux has no managed cua-driver autostart (Windows-only), so daemon units are hand-written against a concrete- release dir. The installer prunes all but the last five, so a versioned reference crash-loops with 203/EXEC- after every upgrade while every binary-level check stays green (#114748). ``packages/current`` and- still-present release dirs are healthy by construction and never reported.- """- # systemd --user and XDG autostart both honour $XDG_CONFIG_HOME; a host that sets it keeps its units there.+def cua_daemon_units(config_dir: Optional[str] = None) -> List[Tuple[str, str, str, bool, Optional[str]]]:+ """(kind, unit, exec_target, runs_serve, --socket path or None) for every systemd user unit / XDG autostart+ entry whose Exec runs cua-driver — the hand-written daemon units Linux relies on (there is no managed+ autostart). ``%h`` is expanded in the socket path so it can be probed; the exec target is left as written."""home = os.path.expanduser("~")+ # systemd --user and XDG autostart both honour $XDG_CONFIG_HOME; a host that sets it keeps its units there.base = config_dir or os.environ.get("XDG_CONFIG_HOME") or os.path.join(home, ".config")- findings: List[Tuple[str, str, str]] = []+ units: List[Tuple[str, str, str, bool, Optional[str]]] = []sources = (("systemd user unit", os.path.join(base, "systemd", "user"), ".service", "ExecStart"),("XDG autostart entry", os.path.join(base, "autostart"), ".desktop", "Exec"))for kind, directory, suffix, key in sources:@@ -313,15 +312,50 @@ def _stale_cua_exec_references(config_dir: Optional[str] = None) -> List[Tuple[sfor line in text.splitlines():stripped = line.strip()tokens = stripped.split("=", 1)[1].split() if stripped.startswith(key + "=") else []- if not tokens:- continue# first token = executable; systemd's prefix modifiers (-, +, !, :) never start a path- target = tokens[0].lstrip("-+:!")- resolved = os.path.expanduser(target.replace("%h", home))- if "/packages/releases/" in resolved and not os.path.exists(resolved):- findings.append((kind, name, target))+ if not tokens or "cua-driver" not in tokens[0]:+ continue+ socket = next((tokens[i + 1] for i, t in enumerate(tokens[:-1]) if t == "--socket"), None)+ units.append((kind, name, tokens[0].lstrip("-+:!"), "serve" in tokens[1:],+ os.path.expanduser(socket.replace("%h", home)) if socket else None))+ return units++def _stale_cua_exec_references(config_dir: Optional[str] = None) -> List[Tuple[str, str, str]]:+ """(kind, unit, target) for daemon units whose cua-driver Exec points at a pruned ``packages/releases/<version>/``+ directory. The installer prunes all but the last five, so a versioned reference crash-loops with 203/EXEC after+ every upgrade while every binary-level check stays green (#114748). ``packages/current`` and still-present+ release dirs are healthy by construction and never reported."""+ home = os.path.expanduser("~")+ findings: List[Tuple[str, str, str]] = []+ for kind, unit, target, _serve, _socket in cua_daemon_units(config_dir):+ resolved = os.path.expanduser(target.replace("%h", home))+ if "/packages/releases/" in resolved and not os.path.exists(resolved):+ findings.append((kind, unit, target))return findings+def _apply_daemon_liveness_guard(report: Report, binary: str) -> Report:+ """Append one check per configured daemon unit whose ``cua-driver serve`` is not answering on its socket+ (pass when it is). Only configured daemons are probed: on Linux the MCP runtime needs no daemon, so an+ unconfigured, silent socket is not a finding. Unknown probe results add nothing (#114748)."""+ from tools.computer_use.cua_backend import cua_daemon_listening++ checks = report.get("checks")+ if sys.platform != "linux" or not isinstance(checks, list):+ return report+ for _kind, unit, _target, serve, socket in cua_daemon_units():+ listening = cua_daemon_listening(binary, socket) if serve else None+ if listening is None:+ continue+ shown = socket or "the default socket"+ if listening:+ checks.append({"name": f"daemon ({unit})", "status": "pass", "message": f"cua-driver serve is listening on {shown}"})+ continue+ checks.append({"name": f"daemon ({unit})", "status": "fail", "message": _DEAD_DAEMON_MSG.format(unit=unit, socket=shown),+ "hint": _DEAD_DAEMON_HINT.format(unit=unit)})+ if report.get("overall") == "ok":+ report["overall"] = "degraded"+ return report+def _apply_stale_unit_guard(report: Report) -> Report:"""Append a fail check per hand-written unit/autostart entry whose cua-driver Exec target was pruned — thedaemon can crash-loop (203/EXEC) for days while every binary-level check stays green (#114748). Binary-level@@ -408,6 +442,7 @@ def run_doctor(driver_cmd: Optional[str] = None, *, include: Sequence[str] = (),return 2report = _apply_display_count_guard(report)report = _apply_stale_unit_guard(report)+ report = _apply_daemon_liveness_guard(report, binary)identity = _build_identity(binary, report)environment = _wayland_environment_context(report)if json_output:diff --git a/website/docs/user-guide/features/computer-use.md b/website/docs/user-guide/features/computer-use.mdindex 27efbea742c..dced6a9b6f2 100644--- a/website/docs/user-guide/features/computer-use.md+++ b/website/docs/user-guide/features/computer-use.md@@ -204,6 +204,17 @@ The check matrix is platform-aware: `bundle_identity` / `tcc_*` are`ax_capability` checks AX on macOS, UIA on Windows, AT-SPI on Linux —each with the right diagnostic hint when it can't reach.+On Linux, where the daemon is a hand-written systemd user unit or XDG+autostart entry rather than a managed autostart, doctor also reads those+units: a `cua-driver` `ExecStart` pointing at a pruned+`packages/releases/<version>/` directory is reported as a failing+`daemon unit (...)` check (point it at `~/.cua-driver/packages/current/cua-driver`),+and a unit that runs `cua-driver serve` gets a `daemon (...)` check that+connects to its socket — `fail` when nothing is listening (crash loop,+stopped, never started), `pass` when the daemon answers. Reinstalling the+driver does not start a daemon; `systemctl --user status <unit>` does.+`hermes computer-use status` prints the same dead-daemon line and exits 1.+## The agent cursor and sessionsWhen the agent acts, you'll see a **tinted overlay cursor** glide