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 <noreply@anthropic.com>
This commit is contained in:
Tu Nombre Real 2026-01-26 11:27:42 +01:00
parent 6859e1e6a6
commit 41590f03f9

View File

@ -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) }