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.

fix(cli): warn when a durable agent can move to a machine that does not see its files (#6246)

ddupontb1b567975bab
diff --git a/docs/content/docs/spaces/guides/keep-an-agent-running.mdx b/docs/content/docs/spaces/guides/keep-an-agent-running.mdx
index f75e5c52c6..3cf325596e 100644
--- a/docs/content/docs/spaces/guides/keep-an-agent-running.mdx
+++ b/docs/content/docs/spaces/guides/keep-an-agent-running.mdx
@@ -131,7 +131,10 @@ the conversation or the working folder of the old one. Plan for it:
[Cua Volume](/spaces/guides/cua-volume). The default storage, This Mac, is a
folder on one machine, so another machine does not see it. Use your own
S3-compatible bucket (AWS S3, R2, MinIO) so every machine reaches the same
- files.
+ files. `cua agent add --durable --on auto` says so when more than one
+ machine is signed in and Cua Volume is still on This Mac. The same goes for
+ a durable Space (`durable=true`): it is created again on another machine
+ with an empty disk, and a Volume on This Mac is not visible from there.
- Write the task so running it again from the start is safe.
- A session makes at most 5 drives by default (`--max-attempts`), counting the
first one and every restart for any reason. When they are used up it ends
diff --git a/libs/cua/crates/cua-cli/src/agent_cmd.rs b/libs/cua/crates/cua-cli/src/agent_cmd.rs
index e2c65d661a..12c5aaa4c8 100644
--- a/libs/cua/crates/cua-cli/src/agent_cmd.rs
+++ b/libs/cua/crates/cua-cli/src/agent_cmd.rs
@@ -809,7 +809,7 @@ async fn run_one(
}
if let AgentCmd::Run(a) = cmd {
if a.durable {
- return crate::agent_session_cmd::start(*a, json, out).await;
+ return crate::agent_session_cmd::start(cua, *a, json, out).await;
}
return start(cua, *a, json, out).await;
}
diff --git a/libs/cua/crates/cua-cli/src/agent_session_cmd.rs b/libs/cua/crates/cua-cli/src/agent_session_cmd.rs
index 0528c9564e..e8a543f3ad 100644
--- a/libs/cua/crates/cua-cli/src/agent_session_cmd.rs
+++ b/libs/cua/crates/cua-cli/src/agent_session_cmd.rs
@@ -271,7 +271,12 @@ fn state_line(v: &Value) -> String {
}
/// `cua agent run --durable`.
-pub async fn start(a: RunArgs, json: bool, out: &mut dyn Write) -> Result<i32, CuaError> {
+pub async fn start(
+ cua: &std::sync::Arc<cua_sdk::Cua>,
+ a: RunArgs,
+ json: bool,
+ out: &mut dyn Write,
+) -> Result<i32, CuaError> {
let name = a
.name
.clone()
@@ -288,6 +293,11 @@ pub async fn start(a: RunArgs, json: bool, out: &mut dyn Write) -> Result<i32, C
v["epoch"]
))
);
+ if a.on.as_deref() == Some("auto")
+ && let Some(w) = storage_warning(cua).await
+ {
+ eprintln!("{}", crate::util::hint(&w));
+ }
}
if !a.follow {
return Ok(0);
@@ -297,6 +307,43 @@ pub async fn start(a: RunArgs, json: bool, out: &mut dyn Write) -> Result<i32, C
Ok(if v["state"] == "done" { 0 } else { 1 })
}
+/// What a durable agent placed on `auto` should know when Cua may move it to
+/// another machine and the Cua Volume keeps its files on one machine: `None`
+/// when one machine is signed in or the Volume is in a bucket every machine
+/// reaches (`machines` machines, Volume `backend`).
+pub(crate) fn storage_warning_text(machines: usize, backend: &str) -> Option<String> {
+ if machines < 2 || backend != "fs" {
+ return None;
+ }
+ Some(format!(
+ "{machines} machines are signed in, but Cua Volume keeps its files on This Mac, so a machine \
+ that takes over this agent after a failure does not see the files the agent wrote or needs; \
+ the task starts from the beginning there. Put Cua Volume in your own S3 bucket so every \
+ machine reaches the same files: `cua volume config set --backend s3` (see \
+ https://cua.ai/docs/spaces/guides/keep-an-agent-running)."
+ ))
+}
+
+/// [`storage_warning_text`] for this account now. Best effort: a question
+/// that is not answered quickly is no warning.
+async fn storage_warning(cua: &std::sync::Arc<cua_sdk::Cua>) -> Option<String> {
+ let ask = async {
+ let status = crate::runs::request("pool", "status", Value::Null)
+ .await
+ .ok()?;
+ let machines = status["machines"].as_array().map_or(0, |m| m.len());
+ if machines < 2 {
+ return None;
+ }
+ let backend = cua.spaces().volume_storage().await.ok()?.backend;
+ storage_warning_text(machines, &backend)
+ };
+ tokio::time::timeout(Duration::from_secs(4), ask)
+ .await
+ .ok()
+ .flatten()
+}
+
/// `cua agent sessions`.
pub async fn sessions(json: bool, out: &mut dyn Write) -> Result<i32, CuaError> {
let mut all: Vec<Value> = vec![];
@@ -552,6 +599,16 @@ mod tests {
);
}
+ #[test]
+ fn the_storage_warning_is_for_several_machines_and_the_fs_volume_only() {
+ let w = storage_warning_text(3, "fs").unwrap();
+ assert!(w.contains("3 machines") && w.contains("S3 bucket"), "{w}");
+ assert!(!w.contains("computer") && !w.contains("device") && !w.contains('\u{b7}'));
+ assert!(storage_warning_text(1, "fs").is_none());
+ assert!(storage_warning_text(0, "fs").is_none());
+ assert!(storage_warning_text(3, "s3").is_none());
+ }
+
#[test]
fn durable_run_refuses_what_it_cannot_do() {
let none = |_: &str| None;