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-spaces): retire interrupted-create journals whose sandbox is gone (#6650)
injaneity1bb7e7f2b54e
diff --git a/libs/cua/crates/cua-sandbox-core/src/sandbox.rs b/libs/cua/crates/cua-sandbox-core/src/sandbox.rsindex 5c89ffa302..6797d1ffd5 100644--- a/libs/cua/crates/cua-sandbox-core/src/sandbox.rs+++ b/libs/cua/crates/cua-sandbox-core/src/sandbox.rs@@ -1469,6 +1469,18 @@ impl Sandboxes {}}+ /// Whether `name` is provably gone locally: a local runtime is+ /// configured, nothing is recorded under it and the runtime answers+ /// [`crate::RuntimeError::NotFound`]. Any other answer (no runtime, an+ /// engine that is down) is not proof.+ pub async fn local_name_gone(&self, name: &str) -> bool {+ let Ok(rt) = self.local() else {+ return false;+ };+ self.inner.state.load(name).is_none()+ && matches!(rt.status(name).await, Err(crate::RuntimeError::NotFound(_)))+ }+/// Deletes local instance `name` straight through the local runtime,/// whether or not this machine recorded it: an instance whose create/// was cut off (its process died between starting it and recordingdiff --git a/libs/cua/crates/cua-spaces/src/spaces.rs b/libs/cua/crates/cua-spaces/src/spaces.rsindex fea198e7c6..72a12ead82 100644--- a/libs/cua/crates/cua-spaces/src/spaces.rs+++ b/libs/cua/crates/cua-spaces/src/spaces.rs@@ -3300,7 +3300,9 @@ impl Spaces {/// Recovers local creates left by a dead process when their cua-spacesd/// authenticates within `budget`. Failed, cancelled or borrowed local- /// attempts retain their resources and journals for explicit cleanup.+ /// attempts retain their resources and journals for explicit cleanup;+ /// a journal whose sandbox the local runtime says is gone (and that no+ /// state file records) has nothing left to inspect and is removed./// Live processes are left alone; nonlocal creates retain cancellation/// cleanup. The daemon runs this at startup.pub async fn recover_interrupted_creates(&self, budget: Duration) -> Vec<RecoveredCreate> {@@ -3332,7 +3334,20 @@ impl Spaces {let id = SpaceId::Local {name: j.name.clone(),};- let outcome = if crate::creating::cancel_marked(&home, &stem)+ let unregistered = || {+ self.inner+ .registry+ .get(&id.to_string())+ .ok()+ .flatten()+ .is_none()+ };+ let outcome = if !j.name.is_empty()+ && unregistered()+ && self.inner.sandboxes.local_name_gone(&j.name).await+ {+ RecoveryOutcome::NothingLeft+ } else if crate::creating::cancel_marked(&home, &stem)|| local_made == Some(false)|| j.token.trim().is_empty()|| !j.spacesddiff --git a/libs/cua/crates/cua-spaces/tests/cancel.rs b/libs/cua/crates/cua-spaces/tests/cancel.rsindex c62639fd6f..2b8ae63af7 100644--- a/libs/cua/crates/cua-spaces/tests/cancel.rs+++ b/libs/cua/crates/cua-spaces/tests/cancel.rs@@ -300,6 +300,30 @@ async fn a_cancel_after_a_restart_undoes_the_journal() {assert!(dir.join(format!("{name}.cancel")).exists());}assert_eq!(e.rt.deleted.lock().unwrap().as_slice(), ["orphan"]);++ // Once the retained sandbox is gone (removed by hand, or never started),+ // the next recovery retires its journal and marker instead of reporting+ // it again on every restart. One whose sandbox still exists stays.+ e.rt.running.lock().unwrap().remove("marked");+ let got = e+ .spaces+ .recover_interrupted_creates(Duration::from_secs(1))+ .await;+ let outcome = |id: &str| got.iter().find(|r| r.id == id).map(|r| r.outcome.clone());+ assert_eq!(+ outcome("local:marked"),+ Some(cua_spaces::RecoveryOutcome::NothingLeft),+ "{got:?}"+ );+ assert!(matches!(+ outcome("local:borrowed"),+ Some(cua_spaces::RecoveryOutcome::Failed(_))+ ));+ assert!(!dir.join("marked.json").exists());+ assert!(!dir.join("marked.cancel").exists());+ assert!(dir.join("borrowed.json").exists());+ assert!(e.rt.running.lock().unwrap().contains_key("borrowed"));+ assert_eq!(e.rt.deleted.lock().unwrap().as_slice(), ["orphan"]);}/// Cancelled after the instance is up, while the create waits for itsdiff --git a/libs/cua/crates/cua-spaces/tests/providers.rs b/libs/cua/crates/cua-spaces/tests/providers.rsindex b35f5db5fd..56a187f18e 100644--- a/libs/cua/crates/cua-spaces/tests/providers.rs+++ b/libs/cua/crates/cua-spaces/tests/providers.rs@@ -382,10 +382,9 @@ async fn an_interrupted_local_create_is_registered_or_preserved() {Some(RecoveryOutcome::Registered),"{got:?}");- assert!(matches!(- outcome("local:early"),- Some(RecoveryOutcome::Failed(_))- ));+ // Nothing was ever started for "early": no state file, and the runtime+ // has no such instance. Its journal has nothing left to inspect.+ assert_eq!(outcome("local:early"), Some(RecoveryOutcome::NothingLeft));assert!(matches!(outcome("local:cut"), Some(RecoveryOutcome::Failed(_))),"{got:?}"@@ -406,10 +405,9 @@ async fn an_interrupted_local_create_is_registered_or_preserved() {);assert!(creating.join("busy.json").exists());assert!(!creating.join("half.json").exists());- for name in ["early", "cut"] {- assert!(creating.join(format!("{name}.json")).exists());- std::fs::remove_file(creating.join(format!("{name}.json"))).unwrap();- }+ assert!(!creating.join("early.json").exists());+ assert!(creating.join("cut.json").exists());+ std::fs::remove_file(creating.join("cut.json")).unwrap();assert_eq!(good.running.lock().unwrap().get("cut"), Some(&true));assert!(good.deleted.lock().unwrap().is_empty());