From 41590f03f9f41451e1564f69e38e4920cf57a160 Mon Sep 17 00:00:00 2001 From: Tu Nombre Real Date: Mon, 26 Jan 2026 11:27:42 +0100 Subject: [PATCH] fix(macos): trigger ControlChannel reconnect when gateway becomes available After app restart, the ControlChannel would fail to connect if the gateway wasn't ready yet, entering a .degraded state. When the gateway later became available (.running or .attachedExisting), nothing triggered a reconnection attempt, leaving the menubar icon in a "sleeping" state despite the gateway being functional. Now, when gatewayManager.status changes to .running or .attachedExisting and the ControlChannel is in .degraded state, we automatically call refreshEndpoint() to attempt reconnection. Co-Authored-By: Claude Opus 4.5 --- apps/macos/Sources/Clawdbot/MenuBar.swift | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/apps/macos/Sources/Clawdbot/MenuBar.swift b/apps/macos/Sources/Clawdbot/MenuBar.swift index 26a467e91..01c91a743 100644 --- a/apps/macos/Sources/Clawdbot/MenuBar.swift +++ b/apps/macos/Sources/Clawdbot/MenuBar.swift @@ -69,8 +69,15 @@ struct ClawdbotApp: App { .onChange(of: self.controlChannel.state) { _, _ in self.applyStatusItemAppearance(paused: self.state.isPaused, sleeping: self.isGatewaySleeping) } - .onChange(of: self.gatewayManager.status) { _, _ in + .onChange(of: self.gatewayManager.status) { _, newStatus in self.applyStatusItemAppearance(paused: self.state.isPaused, sleeping: self.isGatewaySleeping) + // Trigger ControlChannel reconnect when gateway becomes available + if case .running = newStatus, case .degraded = self.controlChannel.state { + Task { await self.controlChannel.refreshEndpoint(reason: "gateway-running") } + } + if case .attachedExisting = newStatus, case .degraded = self.controlChannel.state { + Task { await self.controlChannel.refreshEndpoint(reason: "gateway-attached") } + } } .onChange(of: self.state.connectionMode) { _, mode in Task { await ConnectionModeCoordinator.shared.apply(mode: mode, paused: self.state.isPaused) }