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(pool): a coordinator's own 404 is an answer, not "this relay has no pool API" (#6236)

dduponta9902d272655
diff --git a/libs/cua/crates/cua-spaces-cluster/src/pool/relay.rs b/libs/cua/crates/cua-spaces-cluster/src/pool/relay.rs
index 419db166a6..f743d273b9 100644
--- a/libs/cua/crates/cua-spaces-cluster/src/pool/relay.rs
+++ b/libs/cua/crates/cua-spaces-cluster/src/pool/relay.rs
@@ -259,7 +259,14 @@ impl RelayPool {
.await?;
let code = v["code"].as_str().unwrap_or_default();
match (status, code) {
- (404, "not_found") | (404, "") if v.get("error").is_none() || code == "not_found" => {
+ // The relay itself has no pool API. A coordinator's own answer is
+ // sealed whatever its status: its 404 ("no session NAME") is the
+ // answer, not a relay without the API (taking it for that made the
+ // daemon coordinate its pool runs alone from then on).
+ (404, "not_found") | (404, "")
+ if v.get("sealed").is_none()
+ && (v.get("error").is_none() || code == "not_found") =>
+ {
Err(PoolError::Unsupported(
v["error"].as_str().unwrap_or("no pool API").to_string(),
))
diff --git a/libs/cua/crates/cua-spaces-cluster/tests/pool_relay_client.rs b/libs/cua/crates/cua-spaces-cluster/tests/pool_relay_client.rs
index 9fb2de7c4d..50c4e531ef 100644
--- a/libs/cua/crates/cua-spaces-cluster/tests/pool_relay_client.rs
+++ b/libs/cua/crates/cua-spaces-cluster/tests/pool_relay_client.rs
@@ -11,7 +11,7 @@ use std::sync::atomic::{AtomicU32, Ordering};
use async_trait::async_trait;
use axum::http::{HeaderMap, StatusCode};
-use axum::routing::get;
+use axum::routing::{get, post};
use axum::{Json, Router};
use cua_spaces_cluster::pool::relay::{PoolAuth, RelayPool};
use serde_json::json;
@@ -68,3 +68,75 @@ async fn a_forgotten_device_session_is_signed_again() {
assert!(pool.status().await.is_err());
assert_eq!(auth.resets.load(Ordering::SeqCst), 2);
}
+
+/// A coordinator answers a request with 404 (`cua agent status session:typo`):
+/// the answer is sealed, and the relay passes it on. The client must hand it
+/// back, not conclude that the relay has no pool API: that sent the daemon
+/// into coordinating its pool runs alone until it was restarted, so its
+/// sessions were invisible to the other machines (found by the chaos runs).
+#[tokio::test]
+async fn a_coordinators_not_found_is_an_answer_not_a_relay_without_a_pool() {
+ let app = Router::new().route(
+ "/v1/pool/rpc",
+ post(|| async {
+ (
+ StatusCode::NOT_FOUND,
+ Json(json!({"sealed": {"v": 1, "n": "AAAA", "c": "BBBB"}})),
+ )
+ }),
+ );
+ let l = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();
+ let base = format!("http://{}", l.local_addr().unwrap());
+ tokio::spawn(async move { axum::serve(l, app).await });
+ let pool = RelayPool::new(
+ &base,
+ "ada",
+ Arc::new(Auth {
+ session: AtomicU32::new(1),
+ resets: AtomicU32::new(0),
+ }),
+ );
+ let (status, body) = pool
+ .rpc("session_get", json!({"sealed": "x"}), json!({}))
+ .await
+ .expect("the coordinator's 404 is returned, not an error");
+ assert_eq!(status, 404);
+ assert!(body.get("sealed").is_some());
+}
+
+/// A relay that has no pool API answers the route with a plain 404: that is
+/// "unsupported", and the daemon coordinates its pool runs itself.
+#[tokio::test]
+async fn a_relay_without_the_pool_api_is_unsupported() {
+ let app = Router::new().route(
+ "/v1/pool/rpc",
+ post(|| async {
+ (
+ StatusCode::NOT_FOUND,
+ Json(json!({"error": "not found", "code": "not_found"})),
+ )
+ }),
+ );
+ let l = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();
+ let base = format!("http://{}", l.local_addr().unwrap());
+ tokio::spawn(async move { axum::serve(l, app).await });
+ let pool = RelayPool::new(
+ &base,
+ "ada",
+ Arc::new(Auth {
+ session: AtomicU32::new(1),
+ resets: AtomicU32::new(0),
+ }),
+ );
+ let e = pool
+ .rpc("session_get", json!({}), json!({}))
+ .await
+ .unwrap_err();
+ assert!(
+ matches!(
+ e,
+ cua_spaces_cluster::pool::relay::PoolError::Unsupported(_)
+ ),
+ "{e:?}"
+ );
+}