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(cua-daemon): list Spaces added by address in the sandbox list (#6414)

injaneity7cf687424434
diff --git a/libs/cua/crates/cua-daemon/src/runtime.rs b/libs/cua/crates/cua-daemon/src/runtime.rs
index db9afa108a..1910465101 100644
--- a/libs/cua/crates/cua-daemon/src/runtime.rs
+++ b/libs/cua/crates/cua-daemon/src/runtime.rs
@@ -816,6 +816,15 @@ impl Runtime {
})
.collect()
};
+ #[cfg(feature = "spaces")]
+ let held: Vec<(String, SandboxRef)> = held
+ .into_iter()
+ .chain(
+ self.registered_direct()
+ .into_iter()
+ .filter_map(|(id, n)| Some((n, SandboxRef::parse(&id).ok()?))),
+ )
+ .collect();
return Ok(self
.inner
.sandboxes
@@ -955,6 +964,28 @@ impl Runtime {
Ok(record_of(&key, h, status))
}
+ /// `(id, name)` of the cua-spacesd Spaces added by address (`cua
+ /// spaces add`): sandboxes too, though no state file records them.
+ #[cfg(feature = "spaces")]
+ fn registered_direct(&self) -> Vec<(String, String)> {
+ let registry = self.inner.spaces.registry();
+ registry
+ .list()
+ .unwrap_or_default()
+ .into_iter()
+ .filter(|s| {
+ s.id.strip_prefix("direct:")
+ .is_some_and(|a| cua_spaces::id::routed_host(a).is_none())
+ && registry
+ .credential(&s.id)
+ .ok()
+ .flatten()
+ .is_none_or(|c| c.service_urls.is_empty())
+ })
+ .map(|s| (s.id, s.name))
+ .collect()
+ }
+
/// Every known sandbox: state files, local instances and live handles.
pub async fn list(&self, provider: Option<ProviderKind>) -> Result<Vec<SandboxRecord>> {
// A sandbox deleted behind this runtime is not listed as running.
@@ -1010,6 +1041,29 @@ impl Runtime {
},
);
}
+ #[cfg(feature = "spaces")]
+ for (id, name) in self.registered_direct() {
+ out.entry(id.clone()).or_insert_with(|| SandboxRecord {
+ location: location_of(ProviderKind::Direct).into(),
+ id,
+ kind: String::new(),
+ runtime: String::new(),
+ name,
+ provider: ProviderKind::Direct,
+ runtime_type: "direct".into(),
+ status: Status::Running,
+ ephemeral: false,
+ services: BTreeMap::new(),
+ image: None,
+ labels: BTreeMap::new(),
+ endpoints: BTreeMap::new(),
+ created_at: None,
+ expires_at: None,
+ provider_details: BTreeMap::new(),
+ image_info: None,
+ stop_reason: None,
+ });
+ }
{
let handles = self.inner.handles.lock().unwrap();
for (key, h) in handles.iter() {
diff --git a/libs/cua/crates/cua-daemon/tests/registered_direct.rs b/libs/cua/crates/cua-daemon/tests/registered_direct.rs
new file mode 100644
index 0000000000..bcb221996a
--- /dev/null
+++ b/libs/cua/crates/cua-daemon/tests/registered_direct.rs
@@ -0,0 +1,65 @@
+//! A Space added by address (`cua spaces add host:port`) is a direct
+//! sandbox too: `cua sb ls` lists it and `cua sb` finds it by name, though
+//! no state file records it. Registry entries only (no network).
+
+use cua_daemon::{Runtime as DaemonRuntime, RuntimeConfig};
+use cua_proto::daemon::v1 as dpb;
+use cua_sandbox_core::ProviderKind;
+use cua_spaces::registry::Credential;
+
+fn space(id: &str, name: &str) -> dpb::Space {
+ dpb::Space {
+ id: id.into(),
+ name: name.into(),
+ ..Default::default()
+ }
+}
+
+#[tokio::test]
+async fn spaces_added_by_address_are_listed_and_resolve_by_name() {
+ let dir = tempfile::tempdir().unwrap();
+ let d = DaemonRuntime::new(RuntimeConfig {
+ state_dir: Some(dir.path().join("sandboxes")),
+ spaces_home: Some(dir.path().to_path_buf()),
+ ..Default::default()
+ })
+ .unwrap();
+ let registry = d.spaces().registry();
+ let token = |t: &str| Credential {
+ token: Some(t.into()),
+ ..Default::default()
+ };
+ registry
+ .upsert(space("direct:127.0.0.1:43211", "studio"), token("t"))
+ .unwrap();
+ // Not sandboxes: a plain MCP endpoint, and a Space a host forwards.
+ let mut mcp = token("bearer");
+ mcp.service_urls
+ .insert("mcp".into(), "http://127.0.0.1:8765/mcp".into());
+ registry
+ .upsert(space("direct:127.0.0.1:8765", "tools"), mcp)
+ .unwrap();
+ let routed = cua_spaces::id::routed_authority("m-4f2a9c", 40123);
+ registry
+ .upsert(space(&format!("direct:{routed}"), "provided"), token("t"))
+ .unwrap();
+
+ let listed = d.list(None).await.unwrap();
+ let ids: Vec<&str> = listed.iter().map(|r| r.id.as_str()).collect();
+ assert_eq!(ids, ["direct:127.0.0.1:43211"], "{listed:?}");
+ let studio = &listed[0];
+ assert_eq!(studio.name, "studio");
+ assert_eq!(studio.location, "direct");
+ assert_eq!(studio.provider, ProviderKind::Direct);
+ assert!(d.list(Some(ProviderKind::Local)).await.unwrap().is_empty());
+
+ assert_eq!(
+ d.resolve("studio").await.unwrap().to_string(),
+ "direct:127.0.0.1:43211"
+ );
+ assert!(d.resolve("tools").await.is_err());
+
+ // Forgotten with the Space.
+ registry.remove("direct:127.0.0.1:43211").unwrap();
+ assert!(d.list(None).await.unwrap().is_empty());
+}