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(teams): say a device waits for approval instead of "still starting" (CUA-2835) (#6168)

cua-agents[bot]8e314e409718
diff --git a/docs/content/docs/spaces/guides/teams.mdx b/docs/content/docs/spaces/guides/teams.mdx
index 3dc5000860..55d78ad0dc 100644
--- a/docs/content/docs/spaces/guides/teams.mdx
+++ b/docs/content/docs/spaces/guides/teams.mdx
@@ -189,7 +189,8 @@ Windows and Linux apps on the [download page](https://cua.ai/download).
A member's device can open team computers only once an owner or admin approves
it.
-1. The member signs in on a new device and asks for approval.
+1. The member opens a team computer from a new device. That asks for approval
+ on its own (or run `cua team request <team>` to ask first).
2. The request shows under **Device approvals** at
[app.cua.ai/machines](https://app.cua.ai/machines) while it waits. The member
sees that it is waiting for an admin.
diff --git a/libs/cua-spacesd/crates/cua-relay/src/org_access.rs b/libs/cua-spacesd/crates/cua-relay/src/org_access.rs
index 25617d313d..ce967e60a8 100644
--- a/libs/cua-spacesd/crates/cua-relay/src/org_access.rs
+++ b/libs/cua-spacesd/crates/cua-relay/src/org_access.rs
@@ -799,7 +799,7 @@ impl OrgAccess {
message: match device {
None => "team machines need an enrolled device: run `cua devices enroll` (or sign in again)".into(),
Some(d) => format!(
- "this device ({d}) is waiting for a team admin's approval before it can open {}'s machines: ask an owner or admin to approve it at app.cua.ai/team/devices",
+ "this device ({d}) is waiting for a team admin's approval before it can open {}'s computers. An owner or admin can approve it under Computers at app.cua.ai/machines",
org.alias
),
},
diff --git a/libs/cua/crates/cua-spaces/src/host_spaces.rs b/libs/cua/crates/cua-spaces/src/host_spaces.rs
index b493bc4c4c..877b961c86 100644
--- a/libs/cua/crates/cua-spaces/src/host_spaces.rs
+++ b/libs/cua/crates/cua-spaces/src/host_spaces.rs
@@ -2503,6 +2503,24 @@ pub(crate) fn is_stopped_sharing(reason: &str) -> bool {
reason.contains("stopped sharing")
}
+/// The relay's own sentence when it refused a team computer because this
+/// device still needs a team admin's approval (or is not enrolled), from a
+/// failed connection's reason. That refusal is the whole story: the computer
+/// is not "still starting" and waiting does not help (CUA-2835).
+pub(crate) fn team_device_refusal(reason: &str) -> Option<String> {
+ const MARKERS: [&str; 2] = ["this device (", "team machines need an enrolled device"];
+ let start = MARKERS.iter().filter_map(|m| reason.find(m)).min()?;
+ let rest = &reason[start..];
+ // One line per transport tried, joined with "; ": keep the first.
+ let line = rest.split("; ").next().unwrap_or(rest).trim();
+ (line.contains("approv") || line.contains("enroll")).then(|| line.to_string())
+}
+
+/// A team computer refused because of this device, with the relay's words.
+pub(crate) fn team_device_refused(message: String) -> Error {
+ Error::Relay(cua_host::Error::PermissionDenied(message))
+}
+
/// [`HostLimit::resource`] of a host the relay sees connected whose owner
/// stopped sharing it (it refuses every call). Not a count: `used` and
/// `limit` are 0 and `reason` is the line to show. It travels with the
@@ -4566,6 +4584,26 @@ mod snapshot_takers {
#[cfg(test)]
mod tests {
+ #[test]
+ fn team_device_refusal_keeps_the_relays_sentence() {
+ let msg = "this device (dev_ab12) is waiting for a team admin's approval before it can open Acme's computers. An owner or admin can approve it at app.cua.ai/machines";
+ let reason = format!("gRPC-Web: {msg}; HTTP/2: {msg}");
+ assert_eq!(super::team_device_refusal(&reason).as_deref(), Some(msg));
+ let enroll =
+ "team machines need an enrolled device: run `cua devices enroll` (or sign in again)";
+ assert_eq!(super::team_device_refusal(enroll).as_deref(), Some(enroll));
+ assert_eq!(
+ super::team_device_refusal(
+ "nothing answered at https://x (it may still be starting; retry in a few seconds)"
+ ),
+ None
+ );
+ assert_eq!(
+ super::team_device_refusal("the host stopped sharing this machine"),
+ None
+ );
+ }
+
/// An old host (a Cua 0.7 machine, protocol revision 8) is refused up
/// front, by name, with how to update; a current one is not.
#[test]
diff --git a/libs/cua/crates/cua-spaces/src/spaces.rs b/libs/cua/crates/cua-spaces/src/spaces.rs
index 10ded0d929..8028b310f2 100644
--- a/libs/cua/crates/cua-spaces/src/spaces.rs
+++ b/libs/cua/crates/cua-spaces/src/spaces.rs
@@ -2045,6 +2045,12 @@ impl Spaces {
label.as_deref().unwrap_or(&id.to_string()),
));
}
+ if let SpaceId::Relay { .. } = &id
+ && let Some(message) = crate::host_spaces::team_device_refusal(&reason)
+ {
+ // Refused by the team, not a Space still starting.
+ return Err(crate::host_spaces::team_device_refused(message));
+ }
if !generic_ok {
return Err(Error::SpacesdNotAvailable {
space: id.to_string(),