Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.
Rust agentai-agentapplecomputer-usecomputer-use-agentcontainerizationcuadesktop-automationhacktoberfestlumemacosmanusoperatorswiftvirtualizationvirtualization-frameworkwindowswindows-sandbox
fix(cua-host): warn when host setup falls back to a plain process (#6087)
injaneityd6fde9926e10
diff --git a/docs/content/docs/spaces/guides/add-a-computer.mdx b/docs/content/docs/spaces/guides/add-a-computer.mdxindex 375ed972a6..b62fa857c8 100644--- a/docs/content/docs/spaces/guides/add-a-computer.mdx+++ b/docs/content/docs/spaces/guides/add-a-computer.mdx@@ -88,7 +88,7 @@ and rotates the token.| `--relay URL` | Use a different relay (`CUA_RELAY_URL`). The default is `https://relay.cua.ai`. || `--name NAME` | Display name (default: host name). || `--allow ACCOUNT` | Also allow this account (id or email). Repeatable. |-| `--runner KIND` | `auto`, `systemd`, `launchd`, `windows-task` or `process`. |+| `--runner KIND` | `auto`, `systemd`, `launchd`, `windows-task` or `process`. On Linux, `auto` uses systemd when it is running, otherwise `process`. || `--profile spare` | A spare computer: do not share its desktop, create Spaces for your devices (`--no-desktop --provide-spaces`). See [Use a spare Mac to host Spaces](#use-a-spare-mac-to-host-spaces). || `--no-desktop` / `--provide-spaces` | Each of the two settings on its own. `cua host config` changes them later. || `--no-provide-spaces` | Share this desktop only. A computer set up for the first time provides Spaces to your devices by default; a computer set up before keeps its setting. |@@ -99,7 +99,9 @@ and rotates the token.|---|---|---|| macOS | LaunchAgent `com.trycua.spacesd.host` in your GUI session | Grant cua-spacesd **Screen Recording** and **Accessibility** in System Settings, and [Cua Driver](/cua-driver/quickstart) its own permissions. Setup can't do it for you. || Windows | Scheduled task `Cua\SpacesdHost` at logon, in your interactive session | Stay signed in and unlocked. After a restart, sign in once. |-| Linux | systemd unit `cua-spacesd-host.service` (user unit; system unit as root) | Nothing more. |+| Linux | systemd unit `cua-spacesd-host.service` (user unit; system unit as root). Without systemd (a container, or WSL without systemd): a plain process, and setup warns about it. | With systemd, nothing more. A plain process does not come back after a reboot or a crash: turn on systemd and run `cua host setup --runner systemd` again with the same options, or run `cua host start` after each boot. |++`cua host status` shows the runner in use.On Windows the host runs in your signed-in session, so your devices reach thedesktop only while it is signed in, unlocked and on screen:diff --git a/libs/cua/crates/cua-cli/src/host.rs b/libs/cua/crates/cua-cli/src/host.rsindex 48f83395b7..af1a277176 100644--- a/libs/cua/crates/cua-cli/src/host.rs+++ b/libs/cua/crates/cua-cli/src/host.rs@@ -1666,7 +1666,7 @@ fn render(s: &HostStatus, out: &mut dyn Write) {line(out,format!(- " service: {} {}{}",+ " runner: {} {}{}",s.service.kind,if s.service.running {"running"@@ -1682,6 +1682,9 @@ fn render(s: &HostStatus, out: &mut dyn Write) {}),);+ if s.service.kind == "process" {+ hint_line(out, cua_host::service::PROCESS_RUNNER_NOTE);+ }if s.service.kind == "app-helper" && s.legacy_service {hint_line(out,@@ -1908,6 +1911,34 @@ pub async fn run_host(manager: Option<Arc<dyn ServiceManager>>,json: bool,out: &mut dyn Write,+) -> Result<i32, CuaError> {+ run_host_to(+ cmd,+ home,+ tokens,+ device,+ manager,+ json,+ out,+ &mut std::io::stderr(),+ RunnerKind::detect(),+ )+ .await+}++/// [`run_host`] with an explicit stderr stream (warnings under `--json`) and+/// the runner `auto` detects on this machine.+#[allow(clippy::too_many_arguments)]+pub async fn run_host_to(+ cmd: HostCmd,+ home: &Path,+ tokens: &dyn AccountTokens,+ device: Option<&DeviceAuth>,+ manager: Option<Arc<dyn ServiceManager>>,+ json: bool,+ out: &mut dyn Write,+ err: &mut dyn Write,+ detected: RunnerKind,) -> Result<i32, CuaError> {let mut host = Host::new(home);if let Some(m) = manager {@@ -1967,6 +1998,7 @@ pub async fn run_host(opts.allow = allow;opts.driver_bin = driver_bin;opts.runner = RunnerKind::parse(&runner).map_err(host_err)?;+ let requested_runner = opts.runner;opts = opts.profile(cua_host::HostProfile::parse(profile.as_deref().unwrap_or("desktop")).map_err(host_err)?,@@ -2011,7 +2043,10 @@ pub async fn run_host(};let state = crate::onboard::HostState::read(&host).await;if state.is_up(&want) || state.is_down(&want) {- return setup_unchanged(&host, state, &want, pair.is_some(), json, out).await;+ let code =+ setup_unchanged(&host, state, &want, pair.is_some(), json, out).await?;+ warn_setup_runner(&host, requested_runner, detected, json, out, err)?;+ return Ok(code);}}// A pairing code stands in for the account: nothing to sign in.@@ -2038,6 +2073,7 @@ pub async fn run_host(host_error(e, message)})?;emit(&s, json, out)?;+ warn_setup_runner(&host, requested_runner, detected, json, out, err)?;if s.provide_spaces && !json {line(out,@@ -2293,6 +2329,31 @@ pub async fn run_host(Ok(0)}+/// Warns after `cua host setup --runner auto` fell back to a plain process:+/// to `out`, or to `err` with `--json` so stdout stays JSON. Reads the+/// stored runner (the resolved name), not the live service kind.+fn warn_setup_runner(+ host: &Host,+ requested: RunnerKind,+ detected: RunnerKind,+ json: bool,+ out: &mut dyn Write,+ err: &mut dyn Write,+) -> Result<(), CuaError> {+ // Warn only when auto detection here really finds no systemd: a process+ // runner kept from an explicit choice (or another OS) is not a fallback.+ if requested != RunnerKind::Auto || detected != RunnerKind::Process {+ return Ok(());+ }+ let Some(config) = host.config().map_err(host_err)? else {+ return Ok(());+ };+ if let Some(text) = cua_host::service::auto_fallback_warning(requested, &config.runner) {+ hint_line(if json { err } else { out }, text);+ }+ Ok(())+}+/// `cua host setup` on a machine that already is the host asked for: says/// so (with the accelerators found), or starts its stopped service again.async fn setup_unchanged(@@ -4395,6 +4456,240 @@ mod tests {assert!(text.contains("direct http://127.0.0.1:3299"), "{text}");}+ /// Runs `cua host <args>` against the fake manager on a machine where+ /// `auto` finds no systemd; returns (stdout, stderr).+ async fn run_fake_io(+ home: &Path,+ manager: &Arc<FakeServiceManager>,+ args: &[&str],+ json: bool,+ detected: RunnerKind,+ ) -> (String, String) {+ let (mut out, mut err) = (Vec::new(), Vec::new());+ run_host_to(+ parse(args),+ home,+ &StaticToken("acct".into()),+ None,+ Some(manager.clone()),+ json,+ &mut out,+ &mut err,+ detected,+ )+ .await+ .unwrap();+ (+ String::from_utf8(out).unwrap(),+ String::from_utf8(err).unwrap(),+ )+ }++ /// Runs `cua host <args>` against the fake manager; returns stdout.+ async fn run_fake(home: &Path, manager: &Arc<FakeServiceManager>, args: &[&str]) -> String {+ run_fake_io(home, manager, args, false, RunnerKind::Process)+ .await+ .0+ }++ fn direct_args<'a>(driver: &'a str, extra: &[&'a str]) -> Vec<&'a str> {+ let mut v = vec![+ "setup",+ "--direct",+ "127.0.0.1:3299",+ "--driver-bin",+ driver,+ ];+ v.extend_from_slice(extra);+ v+ }++ #[tokio::test]+ async fn auto_setup_that_falls_back_to_a_process_warns() {+ let dir = tempfile::tempdir().unwrap();+ let driver = dir.path().join("drv");+ std::fs::write(&driver, b"x").unwrap();+ let manager = Arc::new(FakeServiceManager::default());+ let text = run_fake(+ &dir.path().join(".cua"),+ &manager,+ &direct_args(driver.to_str().unwrap(), &[]),+ )+ .await;+ assert_eq!(+ text.matches("will not come back after a reboot").count(),+ 1,+ "{text}"+ );+ }++ #[tokio::test]+ async fn explicit_process_runner_setup_does_not_warn() {+ let dir = tempfile::tempdir().unwrap();+ let driver = dir.path().join("drv");+ std::fs::write(&driver, b"x").unwrap();+ let manager = Arc::new(FakeServiceManager::default());+ let text = run_fake(+ &dir.path().join(".cua"),+ &manager,+ &direct_args(driver.to_str().unwrap(), &["--runner", "process"]),+ )+ .await;+ assert!(!text.contains("will not come back"), "{text}");+ }++ #[tokio::test]+ async fn setup_runner_warning_goes_to_stderr_with_json() {+ let dir = tempfile::tempdir().unwrap();+ let home = dir.path().join(".cua");+ let driver = dir.path().join("drv");+ std::fs::write(&driver, b"x").unwrap();+ let manager = Arc::new(FakeServiceManager::default());+ let mut out = Vec::new();+ run_host(+ parse(&direct_args(+ driver.to_str().unwrap(),+ &["--runner", "process"],+ )),+ &home,+ &StaticToken("acct".into()),+ None,+ Some(manager.clone()),+ true,+ &mut out,+ )+ .await+ .unwrap();+ let host = Host::new(&home).with_service_manager(manager.clone());+ for json in [true, false] {+ let (mut o, mut e) = (Vec::new(), Vec::new());+ warn_setup_runner(+ &host,+ RunnerKind::Auto,+ RunnerKind::Process,+ json,+ &mut o,+ &mut e,+ )+ .unwrap();+ let (o, e) = (String::from_utf8(o).unwrap(), String::from_utf8(e).unwrap());+ let (warned, quiet) = if json { (e, o) } else { (o, e) };+ assert!(warned.contains("will not come back"), "{warned}");+ assert!(quiet.is_empty(), "{quiet}");+ }+ // A full --json auto setup keeps stdout as JSON; the warning is on stderr.+ let dir2 = tempfile::tempdir().unwrap();+ let home2 = dir2.path().join(".cua");+ let m2 = Arc::new(FakeServiceManager::default());+ let args = direct_args(driver.to_str().unwrap(), &[]);+ let (o, e) = run_fake_io(&home2, &m2, &args, true, RunnerKind::Process).await;+ assert!(!o.contains("warning:"), "{o}");+ serde_json::from_str::<serde_json::Value>(o.trim()).unwrap();+ assert_eq!(e.matches("will not come back").count(), 1, "{e}");+ // Re-running (unchanged path) keeps JSON on stdout, warning on stderr.+ let relay = FakeRelay::start().await;+ relay.add_account("acct", "user-1", Some("[email protected]"));+ let m3 = Arc::new(FakeServiceManager::default());+ let home3 = dir2.path().join(".cua3");+ let setup = ["setup", "--relay", relay.url.as_str(), "--name", "lab-box"];+ let first = [&setup[..], &["--driver-bin", driver.to_str().unwrap()]].concat();+ run_fake_io(&home3, &m3, &first, true, RunnerKind::Process).await;+ let (o, e) = run_fake_io(&home3, &m3, &setup, true, RunnerKind::Process).await;+ serde_json::from_str::<serde_json::Value>(o.trim()).unwrap();+ assert_eq!(e.matches("will not come back").count(), 1, "{e}");+ }++ #[tokio::test]+ async fn retained_process_runner_without_auto_detection_does_not_warn() {+ let relay = FakeRelay::start().await;+ relay.add_account("acct", "user-1", Some("[email protected]"));+ let dir = tempfile::tempdir().unwrap();+ let home = dir.path().join(".cua");+ let driver = dir.path().join("drv");+ std::fs::write(&driver, b"x").unwrap();+ let manager = Arc::new(FakeServiceManager::default());+ let setup = ["setup", "--relay", relay.url.as_str(), "--name", "lab-box"];+ let first = [+ &setup[..],+ &[+ "--driver-bin",+ driver.to_str().unwrap(),+ "--runner",+ "process",+ ],+ ]+ .concat();+ run_fake(&home, &manager, &first).await;+ // Default rerun (unchanged path) where auto detection would pick systemd.+ let (o, e) = run_fake_io(&home, &manager, &setup, false, RunnerKind::Systemd).await;+ assert!(!o.contains("will not come back") && e.is_empty(), "{o}{e}");+ let host = Host::new(&home).with_service_manager(manager.clone());+ assert_eq!(host.config().unwrap().unwrap().runner, "process");+ }++ #[tokio::test]+ async fn auto_setup_rerun_on_a_process_host_warns() {+ let relay = FakeRelay::start().await;+ relay.add_account("acct", "user-1", Some("[email protected]"));+ let dir = tempfile::tempdir().unwrap();+ let home = dir.path().join(".cua");+ let driver = dir.path().join("drv");+ std::fs::write(&driver, b"x").unwrap();+ let manager = Arc::new(FakeServiceManager::default());+ let setup = ["setup", "--relay", relay.url.as_str(), "--name", "lab-box"];+ let first = run_fake(+ &home,+ &manager,+ &[&setup[..], &["--driver-bin", driver.to_str().unwrap()]].concat(),+ )+ .await;+ assert_eq!(first.matches("will not come back").count(), 1, "{first}");+ let again = run_fake(&home, &manager, &setup).await;+ assert_eq!(again.matches("will not come back").count(), 1, "{again}");+ manager.stop().unwrap();+ let restarted = run_fake(&home, &manager, &setup).await;+ assert!(+ restarted.contains("Started the host service again"),+ "{restarted}"+ );+ assert_eq!(+ restarted.matches("will not come back").count(),+ 1,+ "{restarted}"+ );+ }++ #[test]+ fn status_names_the_runner_and_notes_a_process_runner() {+ let text = |kind: &str, running: bool, detail: &str| {+ let s = HostStatus {+ configured: true,+ mode: Some("relay".into()),+ service: cua_host::ServiceState {+ installed: true,+ running,+ kind: kind.into(),+ detail: detail.into(),+ },+ ..Default::default()+ };+ let mut out = Vec::new();+ render(&s, &mut out);+ String::from_utf8(out).unwrap()+ };+ let p = text("process", true, "pid 42");+ assert!(p.contains("\n runner: process running (pid 42)\n"), "{p}");+ assert!(+ p.contains("does not start the host again after a reboot"),+ "{p}"+ );+ let s = text("systemd", false, "");+ assert!(+ s.contains(" runner: systemd installed, not running"),+ "{s}"+ );+ assert!(!s.contains("does not start the host again"), "{s}");+ }#[test]fn relay_and_direct_conflict() {#[derive(clap::Parser)]diff --git a/libs/cua/crates/cua-host/src/service.rs b/libs/cua/crates/cua-host/src/service.rsindex c914b6a580..52bb5a7939 100644--- a/libs/cua/crates/cua-host/src/service.rs+++ b/libs/cua/crates/cua-host/src/service.rs@@ -189,10 +189,8 @@ impl RunnerKind {}} else if cfg!(windows) {RunnerKind::WindowsTask- } else if Path::new("/run/systemd/system").is_dir() {- RunnerKind::Systemd} else {- RunnerKind::Process+ linux_runner(Path::new("/run/systemd/system"))}}@@ -1160,8 +1158,34 @@ mod windows_procs {}}+/// Systemd when `systemd_dir` (`/run/systemd/system`) exists, else the plain+/// process. A seam for tests: it checks the filesystem.+fn linux_runner(systemd_dir: &Path) -> RunnerKind {+ if systemd_dir.is_dir() {+ RunnerKind::Systemd+ } else {+ RunnerKind::Process+ }+}++/// The warning `cua host setup` prints when `requested` was `Auto` and the+/// stored runner `resolved` is the plain process; `None` otherwise.+pub fn auto_fallback_warning(requested: RunnerKind, resolved: &str) -> Option<&'static str> {+ (requested == RunnerKind::Auto && resolved == RunnerKind::Process.as_str()).then_some(+ "warning: systemd is not running here, so `--runner auto` set the host up as a plain process.\n\+It will not come back after a reboot or a crash. To fix it, either:\n\+\x20 - turn on systemd (on WSL: systemd=true under [boot] in /etc/wsl.conf, then wsl --shutdown) and run `cua host setup --runner systemd` again with the same options, or\n\+\x20 - run `cua host start` after each boot (from your init system or container start script).\n\+Pass `--runner process` to keep the plain process without this warning.",+ )+}++/// The note `cua host status` prints under a `process` runner.+pub const PROCESS_RUNNER_NOTE: &str = " note: the process runner does not start the host again after a reboot or a crash; run `cua host start` after each boot.";+/// A detached process with a pidfile: the fallback where no init system-/// runs (containers). Not restarted on reboot or crash.+/// runs (containers). Not restarted on reboot or crash; `cua host setup`+/// warns about it ([`auto_fallback_warning`]).pub struct ProcessRunner {/// Directory for `service.json` and `driver.pid`.pub dir: PathBuf,@@ -1954,6 +1978,32 @@ mod tests {}use super::*;+ #[test]+ fn auto_detection_falls_back_to_a_process_without_systemd() {+ let dir = tempfile::tempdir().unwrap();+ let probe = dir.path().join("system");+ assert_eq!(linux_runner(&probe), RunnerKind::Process);+ std::fs::create_dir(&probe).unwrap();+ assert_eq!(linux_runner(&probe), RunnerKind::Systemd);+ }++ #[test]+ fn only_auto_resolved_to_a_process_warns() {+ let text = auto_fallback_warning(RunnerKind::Auto, "process").expect("warns");+ assert!(text.contains("will not come back after a reboot"), "{text}");+ assert!(text.contains("host setup --runner systemd"), "{text}");+ assert!(text.contains("host start"), "{text}");+ for (req, resolved) in [+ (RunnerKind::Process, "process"),+ (RunnerKind::Auto, "systemd"),+ (RunnerKind::Auto, "launchd"),+ (RunnerKind::Auto, "app-helper"),+ (RunnerKind::Auto, "windows-task"),+ ] {+ assert_eq!(auto_fallback_warning(req, resolved), None, "{resolved}");+ }+ }+fn spec() -> ServiceSpec {ServiceSpec {program: "/home/ada/.cua/host/bin/cua-spacesd".into(),