Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.
Rust agentai-agentapplecomputer-usecomputer-use-agentcontainerizationcuadesktop-automationhacktoberfestlumemacosmanusoperatorswiftvirtualizationvirtualization-frameworkwindowswindows-sandbox
fix(lume): suppress repetitive clipboard sync error logs (#1077)
Francesco Bonacci975a9b01ca60
diff --git a/libs/lume/src/Clipboard/ClipboardWatcher.swift b/libs/lume/src/Clipboard/ClipboardWatcher.swiftindex 1f864511b7..f159eecf24 100644--- a/libs/lume/src/Clipboard/ClipboardWatcher.swift+++ b/libs/lume/src/Clipboard/ClipboardWatcher.swift@@ -14,9 +14,23 @@ public actor ClipboardWatcher {private var lastVMContent: String = ""private var lastHostChangeCount: Int = 0+ // Cached SSH client to avoid reconnecting every poll cycle+ private var cachedSSHClient: SSHClient?+ private var cachedIPAddress: String?++ // Error suppression to avoid flooding logs with repeated failures+ private var consecutiveFailures: Int = 0+ private var lastLoggedError: String?+/// Polling interval for clipboard changesprivate static let pollInterval: TimeInterval = 1.0+ /// Backoff interval when SSH is unavailable+ private static let backoffInterval: TimeInterval = 5.0++ /// Number of consecutive failures before suppressing logs+ private static let errorLogThreshold: Int = 3+/// Delay before starting to watch (allows VM to boot and get IP)/// Set to 0 since we gracefully handle SSH not being available yetprivate static let startupDelay: TimeInterval = 0@@ -49,7 +63,8 @@ public actor ClipboardWatcher {while !Task.isCancelled {await self.syncBidirectional()- try? await Task.sleep(nanoseconds: UInt64(Self.pollInterval * 1_000_000_000))+ let interval = await self.currentPollInterval()+ try? await Task.sleep(nanoseconds: UInt64(interval * 1_000_000_000))}Logger.info("Clipboard sync stopped", metadata: ["vm": self.vmName])@@ -61,6 +76,14 @@ public actor ClipboardWatcher {watchTask?.cancel()watchTask = nilisRunning = false+ cachedSSHClient = nil+ cachedIPAddress = nil+ }++ private func currentPollInterval() -> TimeInterval {+ consecutiveFailures >= Self.errorLogThreshold+ ? Self.backoffInterval+ : Self.pollInterval}private func initializeState() {@@ -121,6 +144,7 @@ public actor ClipboardWatcher {let result = try await sshClient.execute(command: command, timeout: 10)if result.exitCode == 0 {+ resetFailureState()Logger.debug("Clipboard synced to VM", metadata: ["vm": vmName,"size": "\(content.utf8.count)"@@ -129,10 +153,7 @@ public actor ClipboardWatcher {}return false} catch {- Logger.debug("Failed to sync clipboard to VM", metadata: [- "vm": vmName,- "error": error.localizedDescription- ])+ handleSyncError("Failed to sync clipboard to VM", error: error)return false}}@@ -167,16 +188,48 @@ public actor ClipboardWatcher {lastHostChangeCount = NSPasteboard.general.changeCountlastHostContent = content+ resetFailureState()Logger.debug("Clipboard synced from VM", metadata: ["vm": vmName,"size": "\(content.utf8.count)"])} catch {- Logger.debug("Failed to sync clipboard from VM", metadata: [+ handleSyncError("Failed to sync clipboard from VM", error: error)+ }+ }++ /// Log sync errors with suppression to avoid flooding output.+ /// Logs the first occurrence and when the error changes, then suppresses+ /// repeated identical errors.+ private func handleSyncError(_ message: String, error: Error) {+ // Invalidate cached client on error so we reconnect next cycle+ cachedSSHClient = nil++ consecutiveFailures += 1+ let errorDesc = error.localizedDescription++ if errorDesc != lastLoggedError {+ // New error type — always log it+ Logger.debug(message, metadata: ["vm": vmName,- "error": error.localizedDescription+ "error": errorDesc+ ])+ lastLoggedError = errorDesc+ } else if consecutiveFailures == Self.errorLogThreshold {+ // Threshold reached — log once that we're suppressing+ Logger.debug("Clipboard sync errors repeating, suppressing further logs until resolved", metadata: [+ "vm": vmName])}+ // Otherwise: same error, already suppressed — don't log+ }++ private func resetFailureState() {+ if consecutiveFailures >= Self.errorLogThreshold {+ Logger.debug("Clipboard sync recovered", metadata: ["vm": vmName])+ }+ consecutiveFailures = 0+ lastLoggedError = nil}private func getSSHClient() async -> SSHClient? {@@ -192,12 +245,20 @@ public actor ClipboardWatcher {return nil}- return SSHClient(+ // Reuse cached client if IP hasn't changed+ if let cached = cachedSSHClient, cachedIPAddress == ipAddress {+ return cached+ }++ let client = SSHClient(host: ipAddress,port: 22,user: "lume",password: "lume")+ cachedSSHClient = client+ cachedIPAddress = ipAddress+ return client} catch {return nil}diff --git a/libs/lume/src/Commands/Run.swift b/libs/lume/src/Commands/Run.swiftindex dcf4df54e2..b7188ec9ae 100644--- a/libs/lume/src/Commands/Run.swift+++ b/libs/lume/src/Commands/Run.swift@@ -56,6 +56,9 @@ struct Run: AsyncParsableCommand {help: "Optional network override: 'nat', 'bridged', or 'bridged:<interface>' (e.g. 'bridged:en0'). Defaults to the VM's configured mode.")var network: String?+ @Flag(name: .customLong("clipboard"), help: "Enable bidirectional clipboard sync with the VM via SSH (experimental)")+ var clipboard: Bool = false+private var parsedNetworkMode: NetworkMode? {get throws {guard let network else {@@ -133,7 +136,8 @@ struct Run: AsyncParsableCommand {recoveryMode: recoveryMode,storage: storage,usbMassStoragePaths: parsedUSBStorageDevices.isEmpty ? nil : parsedUSBStorageDevices,- networkMode: parsedNetworkMode+ networkMode: parsedNetworkMode,+ clipboard: clipboard)}}diff --git a/libs/lume/src/LumeController.swift b/libs/lume/src/LumeController.swiftindex 2608a8f68a..8892383477 100644--- a/libs/lume/src/LumeController.swift+++ b/libs/lume/src/LumeController.swift@@ -900,7 +900,8 @@ final class LumeController {recoveryMode: Bool = false,storage: String? = nil,usbMassStoragePaths: [Path]? = nil,- networkMode: NetworkMode? = nil+ networkMode: NetworkMode? = nil,+ clipboard: Bool = false) async throws {let normalizedName = normalizeVMName(name: name)Logger.info(@@ -998,7 +999,8 @@ final class LumeController {vncPort: vncPort,recoveryMode: recoveryMode,usbMassStoragePaths: usbMassStoragePaths,- networkMode: networkMode)+ networkMode: networkMode,+ clipboard: clipboard)Logger.info("VM started successfully", metadata: ["name": normalizedName])} catch {SharedVM.shared.removeVM(name: normalizedName)diff --git a/libs/lume/src/Server/APIDocExtractor.swift b/libs/lume/src/Server/APIDocExtractor.swiftindex 0e6c722d64..723f8afd92 100644--- a/libs/lume/src/Server/APIDocExtractor.swift+++ b/libs/lume/src/Server/APIDocExtractor.swift@@ -306,7 +306,8 @@ enum APIDocExtractor {APIFieldDoc(name: "noDisplay", type: "boolean", required: false, description: "Run without VNC display", defaultValue: "false"),APIFieldDoc(name: "sharedDirectories", type: "array", required: false, description: "Directories to share with the VM", defaultValue: nil),APIFieldDoc(name: "recoveryMode", type: "boolean", required: false, description: "Boot macOS VM in recovery mode", defaultValue: "false"),- APIFieldDoc(name: "storage", type: "string", required: false, description: "VM storage location", defaultValue: nil)+ APIFieldDoc(name: "storage", type: "string", required: false, description: "VM storage location", defaultValue: nil),+ APIFieldDoc(name: "clipboard", type: "boolean", required: false, description: "Enable bidirectional clipboard sync via SSH (experimental)", defaultValue: "false")]),responseBody: APIResponseDoc(diff --git a/libs/lume/src/Server/Handlers.swift b/libs/lume/src/Server/Handlers.swiftindex 5c49eb3c2f..c590a13f90 100644--- a/libs/lume/src/Server/Handlers.swift+++ b/libs/lume/src/Server/Handlers.swift@@ -340,7 +340,7 @@ extension Server {body.flatMap { try? JSONDecoder().decode(RunVMRequest.self, from: $0) }?? RunVMRequest(noDisplay: nil, sharedDirectories: nil, recoveryMode: nil, storage: nil,- network: nil)+ network: nil, clipboard: nil)// Record telemetryTelemetryClient.shared.record(event: TelemetryEvent.apiVMRun, properties: [@@ -372,7 +372,8 @@ extension Server {sharedDirectories: dirs,recoveryMode: request.recoveryMode ?? false,storage: request.storage,- networkMode: networkMode+ networkMode: networkMode,+ clipboard: request.clipboard ?? false)Logger.info("VM start initiated in background", metadata: ["name": name])@@ -825,7 +826,8 @@ extension Server {sharedDirectories: [SharedDirectory] = [],recoveryMode: Bool = false,storage: String? = nil,- networkMode: NetworkMode? = nil+ networkMode: NetworkMode? = nil,+ clipboard: Bool = false) {Logger.info("Starting VM in detached task",@@ -855,7 +857,8 @@ extension Server {sharedDirectories: sharedDirectories,recoveryMode: recoveryMode,storage: storage,- networkMode: networkMode+ networkMode: networkMode,+ clipboard: clipboard)Logger.info("VM started successfully in background task", metadata: ["name": name])} catch {diff --git a/libs/lume/src/Server/MCPServer.swift b/libs/lume/src/Server/MCPServer.swiftindex 2a7c65abc0..492a64653b 100644--- a/libs/lume/src/Server/MCPServer.swift+++ b/libs/lume/src/Server/MCPServer.swift@@ -565,6 +565,7 @@ final class LumeMCPServer {let storage = args?["storage"]?.stringValuelet noDisplay = args?["no_display"]?.boolValue ?? true+ let clipboard = args?["clipboard"]?.boolValue ?? falsevar sharedDirectories: [SharedDirectory] = []if let sharedDir = args?["shared_dir"]?.stringValue {@@ -581,7 +582,8 @@ final class LumeMCPServer {name: name,noDisplay: noDisplay,sharedDirectories: sharedDirectories,- storage: storage+ storage: storage,+ clipboard: clipboard)} catch {Logger.error(diff --git a/libs/lume/src/Server/Requests.swift b/libs/lume/src/Server/Requests.swiftindex 1a39bdb5ca..7778ce8359 100644--- a/libs/lume/src/Server/Requests.swift+++ b/libs/lume/src/Server/Requests.swift@@ -17,6 +17,7 @@ struct RunVMRequest: Codable {let recoveryMode: Bool?let storage: String?let network: String?+ let clipboard: Bool?struct SharedDirectoryRequest: Codable {let hostPath: Stringdiff --git a/libs/lume/src/VM/VM.swift b/libs/lume/src/VM/VM.swiftindex 9716b4a9cd..014ebf483a 100644--- a/libs/lume/src/VM/VM.swift+++ b/libs/lume/src/VM/VM.swift@@ -136,7 +136,7 @@ class VM {func run(noDisplay: Bool, sharedDirectories: [SharedDirectory], mount: Path?, vncPort: Int = 0,recoveryMode: Bool = false, usbMassStoragePaths: [Path]? = nil,- networkMode: NetworkMode? = nil+ networkMode: NetworkMode? = nil, clipboard: Bool = false) async throws {Logger.info("VM.run method called",@@ -261,8 +261,10 @@ class VM {// Start clipboard watcher for automatic host-to-VM clipboard sync// Requires SSH/Remote Login to be enabled on the VM- clipboardWatcher = ClipboardWatcher(vmName: vmDirContext.name, storage: vmDirContext.storage)- await clipboardWatcher?.start()+ if clipboard {+ clipboardWatcher = ClipboardWatcher(vmName: vmDirContext.name, storage: vmDirContext.storage)+ await clipboardWatcher?.start()+ }while true {try await Task.sleep(nanoseconds: UInt64(1e9))