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(spaces): mount a Space's Cua Volume again once it is back, instead of saying its cua-spacesd predates the volume (CUA-1759) (#5300)

ddupont2fa609c12a65
diff --git a/libs/cua/crates/cua-spaces-ext/src/drive_runtime.rs b/libs/cua/crates/cua-spaces-ext/src/drive_runtime.rs
index ec72f3763a..0a0e0dbbd7 100644
--- a/libs/cua/crates/cua-spaces-ext/src/drive_runtime.rs
+++ b/libs/cua/crates/cua-spaces-ext/src/drive_runtime.rs
@@ -258,6 +258,23 @@ impl SpacesDrive for Spaces {
}
let s = self.space(&id).await?;
let Some(backend) = s.volume_backend() else {
+ let answered_before = self
+ .registry()
+ .get(&id)
+ .ok()
+ .flatten()
+ .is_some_and(|r| !r.spacesd_version.is_empty());
+ if not_up_yet(s.has_spacesd(), answered_before) {
+ // Connected while its cua-spacesd was still starting (a
+ // fresh or restarted container): the connection has no
+ // capabilities, not a guest without the volume. Connect
+ // afresh next time, and fail so the supervisor retries.
+ let _ = self.forget_connection(&id).await;
+ let why = "its cua-spacesd is not answering yet (the Space is still starting); \
+ Cua Volume mounts once it does";
+ ext.runtime.note_unavailable(&id, Some(why.into()));
+ return Err(Error::extension("precondition_failed", why));
+ }
let why = s
.feature(VOLUME_FEATURE)
.map(|f| f.limitation.clone())
@@ -447,6 +464,14 @@ pub(crate) fn spawn_attach(spaces: &Spaces, id: &str) {
}
}
+/// Whether a Space without the volume feature on this connection is only
+/// still starting: no cua-spacesd answered when it connected, though one did
+/// before. A guest whose cua-spacesd answers without the feature predates
+/// the volume; one that never ran cua-spacesd has nothing to mount.
+fn not_up_yet(has_spacesd: bool, answered_before: bool) -> bool {
+ !has_spacesd && answered_before
+}
+
/// Mounts the Space's volume and keeps it mounted: when the guest daemon
/// restarts (an update, a crash, a reboot) its mount and its half of the
/// socket are gone, so the volume is mounted again, with a backoff while the
@@ -542,3 +567,18 @@ async fn remount(spaces: &Spaces, key: &str) -> Result<Option<VolumeInfo>> {
}
Ok(info)
}
+
+#[cfg(test)]
+mod not_up_yet_tests {
+ use super::not_up_yet;
+
+ #[test]
+ fn a_daemon_that_answered_before_is_still_starting() {
+ assert!(not_up_yet(false, true));
+ // It answered on this connection: the feature list is real.
+ assert!(!not_up_yet(true, true));
+ assert!(!not_up_yet(true, false));
+ // An image that never ran cua-spacesd.
+ assert!(!not_up_yet(false, false));
+ }
+}
diff --git a/libs/cua/crates/cua-spaces/src/spaces.rs b/libs/cua/crates/cua-spaces/src/spaces.rs
index 38db6264e8..4fd9e23b38 100644
--- a/libs/cua/crates/cua-spaces/src/spaces.rs
+++ b/libs/cua/crates/cua-spaces/src/spaces.rs
@@ -2948,6 +2948,11 @@ impl Spaces {
self.drop_connection(&id).await;
let state = if on {
sandboxes.power_on(name).await?;
+ // What extensions keep for a connected Space (its Cua
+ // Volume) ended with the connection above: start it
+ // again now, not only when something next connects.
+ #[cfg(feature = "mcp")]
+ self.notify_connected(&id);
cua_sandbox_core::PowerState::Running
} else {
sandboxes.power_off(name).await?