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(agents): install Hermes in a job Space without git, and fail a permanent install error at once (#6229)
ddupont6e029a92cfaa
diff --git a/libs/cua/crates/cua-agents/src/durable.rs b/libs/cua/crates/cua-agents/src/durable.rsindex 56921a1ea3..9ef03cd81a 100644--- a/libs/cua/crates/cua-agents/src/durable.rs+++ b/libs/cua/crates/cua-agents/src/durable.rs@@ -341,6 +341,23 @@ pub fn guard_env(h: &harness::Harness) -> Vec<(String, String)> {}}+/// Install errors that no retry fixes (a missing tool the job Space cannot+/// add, a checksum or commit that does not match, no build for this CPU): the+/// driver exits 78 and the session fails at once instead of five drives later.+/// A failed download or a package manager error stays a plain exit 1 (retried).+const PERMANENT_INSTALL_ERRORS: &str = "git is not available|commit mismatch|integrity mismatch|sha256 mismatch|not published for|npm is not available";++/// What the driver does when its install step fails (run in `sh`, in the+/// driver's directory): exit 78 for an error no retry fixes, else exit 1.+fn install_failure_handler() -> String {+ format!(+ "tail -n 20 install.log >&2; \+ if grep '\"phase\":\"error\"' install.log | tail -n 1 | grep -Eq '{PERMANENT_INSTALL_ERRORS}'; then \+ echo 'driver: this harness cannot be installed in the job Space; not retrying' >&2; exit 78; fi; \+ echo 'driver: install failed; see install.log' >&2; exit 1;"+ )+}+/// The driver's launcher: installs what the harness needs (idempotent, fast/// when present), then runs the durable runner under the session env.fn driver_script(ids: &[&str], install: bool) -> Result<String> {@@ -356,8 +373,9 @@ fn driver_script(ids: &[&str], install: bool) -> Result<String> {exec \"$HOME/.cua/bin/node\" ./acp-runner.mjs \"$CUA_RUN_DIR\"\n",if install {format!(- "(\n{}\n) >> install.log 2>&1 || {{ echo 'driver: install failed; see install.log' >&2; tail -n 20 install.log >&2; exit 1; }}\n",- installables::script(ids)?+ "(\n{}\n) >> install.log 2>&1 || {{ {} }}\n",+ installables::script(ids)?,+ install_failure_handler())} else {"export PATH=\"$HOME/.cua/bin:$PATH\"\n".to_string()@@ -721,6 +739,37 @@ mod tests {}}+ #[test]+ fn a_permanent_install_failure_exits_78_and_a_transient_one_exits_1() {+ let run = |detail: &str| {+ let dir = tempfile::tempdir().unwrap();+ std::fs::write(+ dir.path().join("install.log"),+ format!("{{\"id\":\"hermes\",\"phase\":\"error\",\"detail\":\"{detail}\"}}\n"),+ )+ .unwrap();+ let out = std::process::Command::new("/bin/sh")+ .current_dir(dir.path())+ .arg("-c")+ .arg(format!("false || {{ {} }}", install_failure_handler()))+ .output()+ .unwrap();+ (+ out.status.code(),+ String::from_utf8_lossy(&out.stderr).to_string(),+ )+ };+ let (code, err) = run("git is not available");+ assert_eq!(code, Some(78), "{err}");+ assert!(+ err.contains("cannot be installed in the job Space"),+ "{err}"+ );+ assert_eq!(run("commit mismatch").0, Some(78));+ assert_eq!(run("download failed").0, Some(1));+ assert_eq!(run("uv sync failed").0, Some(1));+ }+#[test]fn the_state_dir_defaults_and_may_be_left_to_the_job() {let mut o = opts();diff --git a/libs/cua/crates/cua-agents/src/installables.rs b/libs/cua/crates/cua-agents/src/installables.rsindex 2e5e51ef44..0a42561e2f 100644--- a/libs/cua/crates/cua-agents/src/installables.rs+++ b/libs/cua/crates/cua-agents/src/installables.rs@@ -505,15 +505,44 @@ fn step(id: &str, it: &Installable) -> String {.map(|e| format!("--extra {}", quote(e))).collect::<Vec<_>>().join(" ");+ // git when the sandbox has it (the commit is then checked with+ // `git rev-parse`). A job Space has no git and no root, so for a+ // GitHub repository the pinned commit's own archive is fetched+ // instead (the commit is in the URL; the dependencies are still+ // checked against the project's `uv.lock` hashes).+ let archive = repo.strip_prefix("https://github.com/").map(|r| {+ format!(+ "https://github.com/{}/archive/{commit}.tar.gz",+ r.trim_end_matches('/')+ )+ });+ let no_git = match &archive {+ Some(url) => format!(+ "cua_progress {qid} download {commit_q}\n\+ mkdir -p \"$CUA_STAGE\" \"$CUA_DEST\"\n\+ (cua_fetch {url} \"$CUA_STAGE/src.tgz\" && tar -xzf \"$CUA_STAGE/src.tgz\" -C \"$CUA_DEST\" --strip-components=1 && [ -f \"$CUA_DEST/uv.lock\" ]) \+ || {{ rm -rf \"$CUA_STAGE\" \"$CUA_DEST\"; cua_unlock \"$CUA_TOOLS/{id}-{version}\"; cua_fail {qid} 'download failed'; }}\n",+ url = quote(url),+ commit_q = quote(commit),+ version = it.version,+ ),+ None => format!(+ "{{ rm -rf \"$CUA_DEST\"; cua_unlock \"$CUA_TOOLS/{id}-{version}\"; cua_fail {qid} 'git is not available'; }}\n",+ version = it.version,+ ),+ };s.push_str(&format!(- "command -v git >/dev/null 2>&1 || {{ cua_progress {qid} install 'git (apt)'; cua_apt git; }}\n\- command -v git >/dev/null 2>&1 || {{ cua_unlock \"$CUA_TOOLS/{id}-{version}\"; cua_fail {qid} 'git is not available'; }}\n\+ "CUA_DEST=\"$CUA_TOOLS/{id}/{version}\"; rm -rf \"$CUA_DEST\"; mkdir -p \"$CUA_TOOLS/{id}\"\n\+ command -v git >/dev/null 2>&1 || cua_apt git >/dev/null 2>&1 || true\n\+ if command -v git >/dev/null 2>&1; then\n\cua_progress {qid} download {commit_q}\n\- CUA_DEST=\"$CUA_TOOLS/{id}/{version}\"; rm -rf \"$CUA_DEST\"; mkdir -p \"$CUA_TOOLS/{id}\"\n\(git init -q \"$CUA_DEST\" && cd \"$CUA_DEST\" && git fetch -q --depth 1 {repo} {commit_q} && git checkout -q FETCH_HEAD) \|| {{ rm -rf \"$CUA_STAGE\" \"$CUA_DEST\"; cua_unlock \"$CUA_TOOLS/{id}-{version}\"; cua_fail {qid} 'git fetch failed'; }}\n\cua_progress {qid} verify commit\n\[ \"$(cd \"$CUA_DEST\" && git rev-parse HEAD)\" = {commit_q} ] || {{ rm -rf \"$CUA_STAGE\" \"$CUA_DEST\"; cua_unlock \"$CUA_TOOLS/{id}-{version}\"; cua_fail {qid} 'commit mismatch'; }}\n\+ else\n\+ {no_git}\+ fi\n\cua_progress {qid} install 'uv sync --frozen'\n\(cd \"$CUA_DEST\" && UV_PYTHON_INSTALL_DIR=\"$CUA_TOOLS/python\" uv sync --quiet --frozen --no-dev {extras} --python {python} >\"$CUA_STAGE/uv.log\" 2>&1) \|| {{ tail -5 \"$CUA_STAGE/uv.log\" >&2; rm -rf \"$CUA_STAGE\" \"$CUA_DEST\"; cua_unlock \"$CUA_TOOLS/{id}-{version}\"; cua_fail {qid} 'uv sync failed'; }}\n",@@ -796,6 +825,24 @@ mod tests {);}+ /// A git-uv item installs without git (a job Space has none and no root):+ /// the pinned commit's own archive is fetched, the commit is in its URL.+ #[test]+ fn a_git_uv_item_falls_back_to_the_commit_archive_without_git() {+ let s = script(&["hermes"]).unwrap();+ let Source::GitUv { repo, commit, .. } = &get("hermes").unwrap().how else {+ panic!("hermes is a git-uv item");+ };+ assert!(+ s.contains(&format!("{repo}/archive/{commit}.tar.gz")),+ "{s}"+ );+ assert!(s.contains("--strip-components=1"));+ assert!(!s.contains("'git is not available'"));+ // With git present the commit is still checked.+ assert!(s.contains("git rev-parse HEAD"));+ }+/// Against a temp HOME with a fake cached install: nothing is fetched,/// the bin is linked and progress says `cached`.#[test]