From 58be73e179530a860e623ddafd9bcef85cb0e940 Mon Sep 17 00:00:00 2001 From: Kenny Lee Date: Mon, 26 Jan 2026 11:49:41 -0800 Subject: [PATCH] fix(macos): allow disabling launchd job when switching to remote mode Previously, GatewayLaunchAgentManager.set() returned early for ANY launchd change in remote mode. This prevented the launchd job from being unloaded when switching from local to remote mode, causing a crash-loop as the job kept trying to bind to port 18789 (which the SSH tunnel was using). Now only 'enable' is blocked in remote mode; 'disable' (uninstall) proceeds normally so the job is properly unloaded. Fixes #2354 --- apps/macos/Sources/Clawdbot/GatewayLaunchAgentManager.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/apps/macos/Sources/Clawdbot/GatewayLaunchAgentManager.swift b/apps/macos/Sources/Clawdbot/GatewayLaunchAgentManager.swift index f0896e691..09c598f65 100644 --- a/apps/macos/Sources/Clawdbot/GatewayLaunchAgentManager.swift +++ b/apps/macos/Sources/Clawdbot/GatewayLaunchAgentManager.swift @@ -51,8 +51,10 @@ enum GatewayLaunchAgentManager { static func set(enabled: Bool, bundlePath: String, port: Int) async -> String? { _ = bundlePath - guard !CommandResolver.connectionModeIsRemote() else { - self.logger.info("launchd change skipped (remote mode)") + // In remote mode, never enable the local gateway, but still allow disabling it + // so switching from local→remote properly unloads the launchd job. + if enabled, CommandResolver.connectionModeIsRemote() { + self.logger.info("launchd enable skipped (remote mode)") return nil } if enabled, self.isLaunchAgentWriteDisabled() {