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(lume): use built-in SSHClient for health checks instead of sshpass (#990)

Francesco Bonaccid7fe00244c4a
diff --git a/libs/lume/src/Resources/unattended-presets/sequoia.yml b/libs/lume/src/Resources/unattended-presets/sequoia.yml
index ad8bfdee18..2e7c04a7ef 100644
--- a/libs/lume/src/Resources/unattended-presets/sequoia.yml
+++ b/libs/lume/src/Resources/unattended-presets/sequoia.yml
@@ -235,16 +235,17 @@ boot_commands:
- "<type 'login'>"
- "<delay 2>"
- "<click 'Remote Login'>"
- - "<delay 10>"
+ - "<delay 20>"
# Enable Remote Login toggle (first toggle on the page)
- "<space>"
- - "<delay 3>"
+ - "<delay 5>"
- "<tab>"
- - "<delay 3>"
+ - "<delay 5>"
- "<space>"
- - "<delay 3>"
+ - "<delay 5>"
- "<enter>"
+ - "<delay 5>"
# Close System Settings
- "<cmd+q>"
diff --git a/libs/lume/src/Resources/unattended-presets/tahoe.yml b/libs/lume/src/Resources/unattended-presets/tahoe.yml
index 563bdd2d53..2349bbeb7d 100644
--- a/libs/lume/src/Resources/unattended-presets/tahoe.yml
+++ b/libs/lume/src/Resources/unattended-presets/tahoe.yml
@@ -250,12 +250,13 @@ boot_commands:
# Enable Remote Login toggle (first toggle on the page)
- "<space>"
- - "<delay 3>"
+ - "<delay 5>"
- "<tab>"
- - "<delay 3>"
+ - "<delay 5>"
- "<space>"
- - "<delay 3>"
+ - "<delay 5>"
- "<enter>"
+ - "<delay 5>"
# Close System Settings
- "<cmd+q>"
diff --git a/libs/lume/src/Unattended/HealthCheckRunner.swift b/libs/lume/src/Unattended/HealthCheckRunner.swift
index 8f8304fd7c..be437ea98b 100644
--- a/libs/lume/src/Unattended/HealthCheckRunner.swift
+++ b/libs/lume/src/Unattended/HealthCheckRunner.swift
@@ -36,56 +36,30 @@ struct HealthCheckRunner {
for attempt in 1...retries {
Logger.info("SSH health check attempt", metadata: ["attempt": "\(attempt)/\(retries)"])
- // Use sshpass to provide password non-interactively
- // Try to run a simple command (echo) to verify SSH works
- let process = Process()
- process.executableURL = URL(fileURLWithPath: "/usr/bin/env")
- process.arguments = [
- "sshpass", "-p", password,
- "ssh",
- "-o", "StrictHostKeyChecking=no",
- "-o", "UserKnownHostsFile=/dev/null",
- "-o", "ConnectTimeout=\(timeout)",
- "-o", "BatchMode=no",
- "\(user)@\(vmIP)",
- "echo", "health_check_ok"
- ]
-
- let outputPipe = Pipe()
- let errorPipe = Pipe()
- process.standardOutput = outputPipe
- process.standardError = errorPipe
-
do {
- try process.run()
-
- // Wait for process with timeout
- let deadline = Date().addingTimeInterval(Double(timeout))
- while process.isRunning && Date() < deadline {
- try await Task.sleep(nanoseconds: 100_000_000) // 0.1s
- }
-
- if process.isRunning {
- process.terminate()
- Logger.info("SSH health check timed out", metadata: ["attempt": "\(attempt)"])
- } else if process.terminationStatus == 0 {
- let outputData = outputPipe.fileHandleForReading.readDataToEndOfFile()
- let output = String(data: outputData, encoding: .utf8) ?? ""
-
- if output.contains("health_check_ok") {
- Logger.info("SSH health check passed", metadata: [
- "host": vmIP,
- "attempt": "\(attempt)"
- ])
- return true
- }
+ let sshClient = SSHClient(
+ host: vmIP,
+ port: 22,
+ user: user,
+ password: password
+ )
+
+ let result = try await sshClient.execute(
+ command: "echo health_check_ok",
+ timeout: TimeInterval(timeout)
+ )
+
+ if result.exitCode == 0 && result.output.contains("health_check_ok") {
+ Logger.info("SSH health check passed", metadata: [
+ "host": vmIP,
+ "attempt": "\(attempt)"
+ ])
+ return true
} else {
- let errorData = errorPipe.fileHandleForReading.readDataToEndOfFile()
- let errorOutput = String(data: errorData, encoding: .utf8) ?? ""
Logger.debug("SSH health check failed", metadata: [
"attempt": "\(attempt)",
- "exitCode": "\(process.terminationStatus)",
- "error": errorOutput.prefix(200).description
+ "exitCode": "\(result.exitCode)",
+ "output": result.output.prefix(200).description
])
}
} catch {
@@ -118,6 +92,13 @@ struct HealthCheckRunner {
"commandCount": "\(commands.count)"
])
+ let sshClient = SSHClient(
+ host: vmIP,
+ port: 22,
+ user: user,
+ password: password
+ )
+
for (index, command) in commands.enumerated() {
Logger.info("Executing SSH command", metadata: [
"index": "\(index + 1)/\(commands.count)",
@@ -127,44 +108,21 @@ struct HealthCheckRunner {
// Handle sudo commands by using sudo -S which reads password from stdin
let actualCommand: String
if command.hasPrefix("sudo ") {
- // Replace "sudo " with "echo password | sudo -S " to provide password via stdin
- let sudoCommand = String(command.dropFirst(5)) // Remove "sudo "
- // Escape single quotes in password for shell: ' becomes '\''
+ let sudoCommand = String(command.dropFirst(5))
let escapedPassword = password.replacingOccurrences(of: "'", with: "'\\''")
actualCommand = "echo '\(escapedPassword)' | sudo -S \(sudoCommand)"
} else {
actualCommand = command
}
- let process = Process()
- process.executableURL = URL(fileURLWithPath: "/usr/bin/env")
- process.arguments = [
- "sshpass", "-p", password,
- "ssh",
- "-o", "StrictHostKeyChecking=no",
- "-o", "UserKnownHostsFile=/dev/null",
- "-o", "ConnectTimeout=30",
- "-o", "BatchMode=no",
- "\(user)@\(vmIP)",
- actualCommand
- ]
-
- let outputPipe = Pipe()
- let errorPipe = Pipe()
- process.standardOutput = outputPipe
- process.standardError = errorPipe
-
do {
- try process.run()
- process.waitUntilExit()
+ let result = try await sshClient.execute(command: actualCommand, timeout: 60)
- if process.terminationStatus != 0 {
- let errorData = errorPipe.fileHandleForReading.readDataToEndOfFile()
- let errorOutput = String(data: errorData, encoding: .utf8) ?? ""
+ if result.exitCode != 0 {
Logger.info("SSH command returned non-zero exit code", metadata: [
"command": command.prefix(50).description,
- "exitCode": "\(process.terminationStatus)",
- "error": errorOutput.prefix(200).description
+ "exitCode": "\(result.exitCode)",
+ "output": result.output.prefix(200).description
])
// Continue with other commands even if one fails
}