Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

feat(nix): checkpoint Cyclops three-node KVM dev environment (#7634)

r33drichards5bd31bad4072
diff --git a/libs/fleet/dev/scripts/doctor.py b/libs/fleet/dev/scripts/doctor.py
new file mode 100644
index 0000000000..51b8078726
--- /dev/null
+++ b/libs/fleet/dev/scripts/doctor.py
@@ -0,0 +1,98 @@
+#!/usr/bin/env python3
+"""Read-only prerequisites; never claims the full Fleet e2e has passed."""
+import argparse
+import fcntl
+import ipaddress
+import json
+import os
+from pathlib import Path
+import shutil
+import subprocess
+
+NETWORKS = ("10.210.0.0/24", "10.211.0.0/16", "10.212.0.0/16")
+REQUIRED_COVERAGE = ("node_pod_cidrs", "service_cidrs", "outer_routes", "vpn_routes")
+
+
+def outer_evidence(value):
+ # A partial inventory can detect conflicts, but cannot authorize networking.
+ if isinstance(value, list):
+ return value, list(REQUIRED_COVERAGE)
+ routes = value["routes"]
+ if not isinstance(routes, list):
+ raise ValueError("outer evidence routes must be a list")
+ coverage = value.get("coverage", {})
+ missing = [key for key in REQUIRED_COVERAGE if coverage.get(key) is not True]
+ return routes, missing
+
+
+def overlaps(routes, networks=NETWORKS):
+ conflicts = []
+ for route in routes:
+ dst = route.get("dst", "default")
+ if dst == "default":
+ continue
+ existing = ipaddress.ip_network(dst, strict=False)
+ for candidate in networks:
+ planned = ipaddress.ip_network(candidate)
+ if existing.version == planned.version and existing.overlaps(planned):
+ conflicts.append({"route": dst, "planned": candidate})
+ return conflicts
+
+
+def kvm_probe():
+ fds = []
+ try:
+ device = os.open("/dev/kvm", os.O_RDWR | os.O_CLOEXEC)
+ fds.append(device)
+ version = fcntl.ioctl(device, 0xAE00, 0)
+ vm = fcntl.ioctl(device, 0xAE01, 0)
+ fds.append(vm)
+ vcpu = fcntl.ioctl(vm, 0xAE41, 0)
+ fds.append(vcpu)
+ return {"api_version": version, "vm_created": True, "vcpu_created": True}
+ except OSError as exc:
+ return {"error": str(exc)}
+ finally:
+ for fd in reversed(fds):
+ os.close(fd)
+
+
+def main():
+ parser = argparse.ArgumentParser(description=__doc__)
+ parser.add_argument("--data-root", default="/var/lib/cyclops-dev")
+ parser.add_argument("--outer-routes", type=Path,
+ help="JSON routes + coverage inventory captured from the outer cluster/VPN")
+ args = parser.parse_args()
+ routes = json.loads(subprocess.check_output(["ip", "-j", "route"], text=True))
+ missing_coverage = list(REQUIRED_COVERAGE)
+ if args.outer_routes:
+ outer_routes, missing_coverage = outer_evidence(json.loads(args.outer_routes.read_text()))
+ routes += outer_routes
+ memory = int(next(line.split()[1] for line in Path("/proc/meminfo").read_text()
+ .splitlines() if line.startswith("MemTotal:"))) * 1024
+ data = Path(args.data_root)
+ probe = kvm_probe()
+ report = {
+ "cpu_count": os.cpu_count(), "memory_bytes": memory,
+ "data_root": str(data), "data_is_mount": data.is_mount(),
+ "data_free_bytes": shutil.disk_usage(data).free,
+ "cgroup_v2": Path("/sys/fs/cgroup/cgroup.controllers").exists(),
+ "route_conflicts": overlaps(routes), "outer_routes_checked": bool(args.outer_routes),
+ "outer_coverage_missing": missing_coverage,
+ "kvm": probe, "full_core_e2e": False,
+ "warnings": [],
+ }
+ if report["cpu_count"] < 16 or memory < 30 * 1024**3:
+ report["warnings"].append("Below proposed 16 CPU / 32 GiB engineering budget; measure each gate.")
+ report["local_prerequisites_pass"] = bool(
+ report["data_is_mount"] and report["data_free_bytes"] >= 100 * 1024**3
+ and report["cgroup_v2"] and not report["route_conflicts"]
+ and probe.get("api_version") == 12 and probe.get("vcpu_created")
+ )
+ report["network_apply_allowed"] = report["local_prerequisites_pass"] and not missing_coverage
+ print(json.dumps(report, indent=2))
+ return 0 if report["network_apply_allowed"] else 1
+
+
+if __name__ == "__main__":
+ raise SystemExit(main())
diff --git a/libs/fleet/dev/tests/test_doctor.py b/libs/fleet/dev/tests/test_doctor.py
new file mode 100644
index 0000000000..8657704c00
--- /dev/null
+++ b/libs/fleet/dev/tests/test_doctor.py
@@ -0,0 +1,50 @@
+import importlib.util
+from pathlib import Path
+import unittest
+
+spec = importlib.util.spec_from_file_location(
+ "doctor", Path(__file__).parents[1] / "scripts" / "doctor.py")
+doctor = importlib.util.module_from_spec(spec)
+spec.loader.exec_module(doctor)
+
+
+class RoutesTest(unittest.TestCase):
+ def test_default_and_unrelated_routes(self):
+ self.assertEqual(doctor.overlaps([
+ {"dst": "default"}, {"dst": "10.0.2.0/24"}, {"dst": "::1/128"}
+ ]), [])
+
+ def test_exact_overlap(self):
+ self.assertEqual(len(doctor.overlaps([{"dst": "10.211.0.0/16"}])), 1)
+
+ def test_supernet_overlap(self):
+ self.assertEqual(len(doctor.overlaps([{"dst": "10.0.0.0/8"}])), 3)
+
+ def test_host_route_overlap(self):
+ self.assertEqual(len(doctor.overlaps([{"dst": "10.210.0.13/32"}])), 1)
+
+
+class CoverageTest(unittest.TestCase):
+ def test_legacy_list_does_not_authorize_network(self):
+ routes, missing = doctor.outer_evidence([])
+ self.assertEqual(routes, [])
+ self.assertEqual(missing, list(doctor.REQUIRED_COVERAGE))
+
+ def test_partial_inventory_stays_blocked(self):
+ _, missing = doctor.outer_evidence({
+ "routes": [], "coverage": {"node_pod_cidrs": True, "outer_routes": True}})
+ self.assertEqual(missing, ["service_cidrs", "vpn_routes"])
+
+ def test_complete_coverage(self):
+ _, missing = doctor.outer_evidence({
+ "routes": [], "coverage": dict.fromkeys(doctor.REQUIRED_COVERAGE, True)})
+ self.assertEqual(missing, [])
+
+ def test_truthy_strings_are_not_verified_coverage(self):
+ _, missing = doctor.outer_evidence({
+ "routes": [], "coverage": dict.fromkeys(doctor.REQUIRED_COVERAGE, "false")})
+ self.assertEqual(missing, list(doctor.REQUIRED_COVERAGE))
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/libs/fleet/pnpm-workspace.yaml b/libs/fleet/pnpm-workspace.yaml
index f586fa773c..6a9d8e85bd 100644
--- a/libs/fleet/pnpm-workspace.yaml
+++ b/libs/fleet/pnpm-workspace.yaml
@@ -2,7 +2,9 @@ packages:
- .
allowBuilds:
- esbuild: set this to true or false
+ esbuild: true
+ "@mongodb-js/zstd": false
+ node-liblzma: false
onlyBuiltDependencies:
- esbuild
diff --git a/libs/fleet/src/App.tsx b/libs/fleet/src/App.tsx
index 52db430468..e47a62dc08 100644
--- a/libs/fleet/src/App.tsx
+++ b/libs/fleet/src/App.tsx
@@ -236,7 +236,9 @@ function ShellLayout({
<TopNavigation
identity={{
href: "#/",
- title: "Cua Fleets",
+ title: import.meta.env.VITE_CYCLOPS_DEV_BUILD_LABEL
+ ? `Cua Fleets · ${import.meta.env.VITE_CYCLOPS_DEV_BUILD_LABEL}`
+ : "Cua Fleets",
logo: { src: cuaMark, alt: "Cua" },
}}
utilities={[