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(ci): quarantine the linux-kvm concurrent flake, fix the TCC seed lock and the Windows portmap pick (#6365)

cua-agents[bot]16d568184853
diff --git a/.github/workflows/FLAKY.md b/.github/workflows/FLAKY.md
index 2212927f20..8ac042395e 100644
--- a/.github/workflows/FLAKY.md
+++ b/.github/workflows/FLAKY.md
@@ -33,3 +33,6 @@ failed and then passed on a rerun of the same commit.
| `handover_process` (`cua-relay`) | nothing answered on the port | unknown; relay logs are now kept on failure (PR 96) | relay | waiting for a repro with logs |
| `CD: Image linux` / `omarchy` build | `E: Some index files failed to download` fetching the xtradeb PPA index | launchpad mirror unavailable; the image build has no fallback | images | open |
| `cua-spaces-cluster` `gang_faults` / `pool_agent` tests | members "ended 39 ms apart"; relay count 2 vs 1 | timing assumptions on a 2-vCPU runner | cluster (CUA-1952 follow-up fix) | fix in review |
+| `linux-kvm (concurrent)` (Nightly: VM Space ready after boot) | 1 of 4 concurrent creates gets ghcr `Not authorized` on a public manifest; others miss the 10 s spacesd connect window | unknown: likely a token race on the shared registry client, plus 4 cold guests on a hosted runner | Spaces (CUA-3132) | quarantined: one retry, only when every failure matches those two signatures |
+| `fmt, clippy, test (windows-latest)` (cua-spacesd): `volume_portmap::serves_over_tcp_and_udp` | `PermissionDenied` (os error 10013) from `Portmap::start(0)`, all retries | the runner excludes a UDP block and Windows hands out TCP ports in order, so 32 TCP-first picks all landed in it | Spaces (CUA-3098) | fixed: picks alternate TCP-first and UDP-first and keep refused ports bound |
+| macOS hosted E2E TCC seed | sqlite `database is locked` while seeding TCC.db | tccd holds TCC.db; the seeder's sqlite3 calls had no busy timeout | cua-driver (CUA-3133) | fixed: 30 s busy timeout and `BEGIN IMMEDIATE` |
diff --git a/.github/workflows/nightly-qemu-ready.yml b/.github/workflows/nightly-qemu-ready.yml
index 7392e72d9b..6a02c36981 100644
--- a/.github/workflows/nightly-qemu-ready.yml
+++ b/.github/workflows/nightly-qemu-ready.yml
@@ -78,6 +78,35 @@ jobs:
CUA_TEST_VM_READY: "1"
CUA_TEST_VM_READY_CREATES: ${{ matrix.creates }}
CUA_TEST_VM_READY_CONCURRENCY: ${{ matrix.concurrency }}
- run: >
- cargo test --locked -p cua-sdk --test vm_ready_after_boot
- -- --ignored --nocapture
+ # Quarantine (CUA-3132, see .github/workflows/FLAKY.md): with
+ # four creates at once on a hosted runner, an anonymous ghcr manifest
+ # pull sometimes comes back "Not authorized" and some guests miss the
+ # spacesd connect window. Only the concurrent shape, and only when every
+ # failure line matches one of those two signatures, gets one more run.
+ # Any other failure, or a second failure, fails the job.
+ QUARANTINE_SHAPE: ${{ matrix.shape }}
+ run: |
+ set -uo pipefail
+ run_test() {
+ cargo test --locked -p cua-sdk --test vm_ready_after_boot \
+ -- --ignored --nocapture 2>&1 | tee "$RUNNER_TEMP/vm-ready.log"
+ return "${PIPESTATUS[0]}"
+ }
+ run_test && exit 0
+ status=$?
+ [[ "$QUARANTINE_SHAPE" == concurrent ]] || exit "$status"
+ # The failure lines are the "<sandbox>: <phase>: <error>" rows the test prints.
+ failures=$(grep -E '^cua-e2e-ready-[0-9a-f]+-[0-9]+: ' "$RUNNER_TEMP/vm-ready.log" || true)
+ known='registry: Not authorized: .*ghcr\.io/v2/trycua/|cua-spacesd is not available in sandbox .*nothing answered at'
+ if [[ -z "$failures" ]] || grep -Evq "$known" <<<"$failures"; then
+ echo "::error::linux-kvm (concurrent) failed outside the quarantined signatures"
+ exit "$status"
+ fi
+ echo "::warning::linux-kvm (concurrent): known flake (CUA-3132), running once more"
+ {
+ echo "### linux-kvm (concurrent): quarantined flake, retried once (CUA-3132)"
+ echo '```'
+ echo "$failures"
+ echo '```'
+ } >> "$GITHUB_STEP_SUMMARY"
+ run_test
diff --git a/libs/cua-driver/scripts/tests/test_macos_lume_runner.py b/libs/cua-driver/scripts/tests/test_macos_lume_runner.py
index dcc65b962a..50afa0a80a 100644
--- a/libs/cua-driver/scripts/tests/test_macos_lume_runner.py
+++ b/libs/cua-driver/scripts/tests/test_macos_lume_runner.py
@@ -346,6 +346,37 @@ def _guest_seed_assignment(name: str) -> str:
return match.group("body")
+def test_tcc_guest_seed_waits_for_tccd_lock() -> None:
+ text = SEED_TCC_GUEST.read_text(encoding="utf-8")
+ assert re.search(r'^TCC_SQLITE=\(/usr/bin/sqlite3 -cmd "\.timeout \d+"\)$', text, re.MULTILINE)
+ # Every TCC.db access goes through the busy-timeout invocation.
+ assert re.search(r'sqlite3 "\$\{TCC_DB\}"', text) is None
+ assert _guest_seed_assignment("SQL").lstrip().startswith("BEGIN IMMEDIATE;")
+
+
[email protected](shutil.which("sqlite3") is None, reason="needs the sqlite3 CLI")
+def test_tcc_guest_seed_sqlite_invocation_outlasts_a_held_write_lock(tmp_path: Path) -> None:
+ db = tmp_path / "TCC.db"
+ holder = sqlite3.connect(db, isolation_level=None)
+ holder.execute("CREATE TABLE access(service TEXT)")
+ holder.execute("BEGIN IMMEDIATE")
+ holder.execute("INSERT INTO access VALUES ('held')")
+ seed = subprocess.Popen(
+ ["sqlite3", "-cmd", ".timeout 30000", str(db), "BEGIN IMMEDIATE; INSERT INTO access VALUES ('seeded'); COMMIT;"],
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE,
+ text=True,
+ )
+ time.sleep(1.0)
+ assert seed.poll() is None, "the seed gave up while the lock was held"
+ holder.execute("COMMIT")
+ holder.close()
+ _, stderr = seed.communicate(timeout=30)
+ assert seed.returncode == 0, stderr
+ with sqlite3.connect(db) as conn:
+ assert {row[0] for row in conn.execute("SELECT service FROM access")} == {"held", "seeded"}
+
+
def test_tcc_guest_seed_sql_executes_against_modern_tcc_schema(tmp_path: Path) -> None:
sql_body = _guest_seed_assignment("SQL")
verify_sql = _guest_seed_assignment("VERIFY_SQL")
diff --git a/libs/cua-driver/tests/runners/macos-lume/seed-tcc-guest.sh b/libs/cua-driver/tests/runners/macos-lume/seed-tcc-guest.sh
index 40048d5861..6908dc2d02 100755
--- a/libs/cua-driver/tests/runners/macos-lume/seed-tcc-guest.sh
+++ b/libs/cua-driver/tests/runners/macos-lume/seed-tcc-guest.sh
@@ -234,7 +234,11 @@ if [[ "$(/usr/bin/id -u)" -ne 0 ]]; then
fi
[[ -f "${TCC_DB}" ]] || fail "system TCC.db does not exist at ${TCC_DB}"
-ACCESS_COLUMNS="$(run_sudo /usr/bin/sqlite3 "${TCC_DB}" 'PRAGMA table_info(access);')"
+# tccd keeps TCC.db open and writes to it at any time, so a bare sqlite3 call
+# can fail at once with "database is locked". Wait up to 30 s for the lock
+# instead, and take the write lock when the transaction starts.
+TCC_SQLITE=(/usr/bin/sqlite3 -cmd ".timeout 30000")
+ACCESS_COLUMNS="$(run_sudo "${TCC_SQLITE[@]}" "${TCC_DB}" 'PRAGMA table_info(access);')"
CLIENT_SQL="$(sql_escape "${CLIENT}")"
if ! /usr/bin/grep -q '|auth_value|' <<< "${ACCESS_COLUMNS}"; then
@@ -242,7 +246,7 @@ if ! /usr/bin/grep -q '|auth_value|' <<< "${ACCESS_COLUMNS}"; then
fi
SQL="
-BEGIN;
+BEGIN IMMEDIATE;
INSERT OR REPLACE INTO access(
service,client,client_type,auth_value,auth_reason,auth_version,
csreq,flags,indirect_object_identifier_type,
@@ -256,8 +260,8 @@ COMMIT;
"
VERIFY_SQL="SELECT count(*) FROM access WHERE client='${CLIENT_SQL}' AND client_type=${CLIENT_TYPE} AND auth_value=2 AND service IN ('kTCCServiceAccessibility','kTCCServiceScreenCapture');"
-run_sudo /usr/bin/sqlite3 "${TCC_DB}" "${SQL}"
-ROW_COUNT="$(run_sudo /usr/bin/sqlite3 "${TCC_DB}" "${VERIFY_SQL}")"
+run_sudo "${TCC_SQLITE[@]}" "${TCC_DB}" "${SQL}"
+ROW_COUNT="$(run_sudo "${TCC_SQLITE[@]}" "${TCC_DB}" "${VERIFY_SQL}")"
[[ "${ROW_COUNT}" == 2 ]] || fail "expected two granted rows for ${CLIENT}, found ${ROW_COUNT}"
if run_sudo /usr/bin/pgrep -x tccd >/dev/null 2>&1; then
diff --git a/libs/cua-spacesd/crates/cua-spacesd-server/src/services/volume_portmap.rs b/libs/cua-spacesd/crates/cua-spacesd-server/src/services/volume_portmap.rs
index de54f06c6a..2340a29dcd 100644
--- a/libs/cua-spacesd/crates/cua-spacesd-server/src/services/volume_portmap.rs
+++ b/libs/cua-spacesd/crates/cua-spacesd-server/src/services/volume_portmap.rs
@@ -95,20 +95,51 @@ impl Portmap {
/// `nfs`. `port` 0 picks one (tests).
pub async fn start(port: u16, nfs: Ports) -> std::io::Result<Portmap> {
// A fixed port binds once. Port 0 needs one number free for TCP and
- // for UDP, and TCP and UDP have separate port spaces (Windows keeps
+ // for UDP, and TCP and UDP have separate port spaces. Windows keeps
// separate excluded ranges, which refuse the bind with "permission
- // denied"): when the UDP bind refuses the TCP pick, pick again.
- let mut picks_left = if port == 0 { 32 } else { 1 };
- let (tcp, udp, addr) = loop {
+ // denied", and hands out ports in order, so retrying the same way can
+ // land in the same excluded block every time. Alternate which protocol
+ // picks the number, and keep refused picks bound until the end so the
+ // OS cannot hand the same number out again.
+ if port != 0 {
let tcp = TcpListener::bind(("127.0.0.1", port)).await?;
+ let udp = UdpSocket::bind(("127.0.0.1", port)).await?;
let addr = tcp.local_addr()?;
- picks_left -= 1;
- match UdpSocket::bind(("127.0.0.1", addr.port())).await {
- Ok(udp) => break (tcp, udp, addr),
- Err(e) if picks_left == 0 => return Err(e),
- Err(_) => {}
+ return Ok(Self::serve(tcp, udp, addr, nfs));
+ }
+ let mut refused_tcp = Vec::new();
+ let mut refused_udp = Vec::new();
+ let mut last_err = None;
+ for pick in 0..32 {
+ if pick % 2 == 0 {
+ let tcp = TcpListener::bind(("127.0.0.1", 0)).await?;
+ let addr = tcp.local_addr()?;
+ match UdpSocket::bind(("127.0.0.1", addr.port())).await {
+ Ok(udp) => return Ok(Self::serve(tcp, udp, addr, nfs)),
+ Err(e) => {
+ last_err = Some(e);
+ refused_tcp.push(tcp);
+ }
+ }
+ } else {
+ let udp = UdpSocket::bind(("127.0.0.1", 0)).await?;
+ let udp_port = udp.local_addr()?.port();
+ match TcpListener::bind(("127.0.0.1", udp_port)).await {
+ Ok(tcp) => {
+ let addr = tcp.local_addr()?;
+ return Ok(Self::serve(tcp, udp, addr, nfs));
+ }
+ Err(e) => {
+ last_err = Some(e);
+ refused_udp.push(udp);
+ }
+ }
}
- };
+ }
+ Err(last_err.expect("at least one pick was refused"))
+ }
+
+ fn serve(tcp: TcpListener, udp: UdpSocket, addr: SocketAddr, nfs: Ports) -> Portmap {
let log = CallLog::default();
let l = log.clone();
let tcp_task = tokio::spawn(async move {
@@ -126,11 +157,11 @@ impl Portmap {
}
}
});
- Ok(Portmap {
+ Portmap {
tasks: vec![tcp_task, udp_task],
addr,
log,
- })
+ }
}
/// Where it listens.