Skip to content

Commit 13012b3

Browse files
fix(setup): add Windows-side gateway health check to pair-operator step
PairNodeStep already verifies the gateway is reachable from the Windows host (HTTP GET to localhost:{port}/) before attempting a WebSocket connection, but PairOperatorStep was missing this check. This caused pair-operator to fail with connection errors when WSL port forwarding hadn't propagated to the Windows host yet. Add the same Windows-side HTTP health check to PairOperatorStep.ExecuteAsync() immediately before the WebSocket connect attempt. The step's existing RetryPolicy (MaxAttempts: 3, InitialDelay: 3s) provides automatic retry if the port isn't ready on the first attempt. Fixes #662 Co-authored-by: Copilot <[email protected]>
1 parent 3fdfbfa commit 13012b3

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

‎src/OpenClaw.SetupEngine/SetupSteps.cs‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1692,6 +1692,18 @@ record = registry.AddOrUpdate(record);
16921692
ctx.Logger.Info($"Device identity initialized: {identity.DeviceId[..16]}...");
16931693
ctx.OperatorDeviceId = identity.DeviceId;
16941694

1695+
// Verify gateway is reachable from Windows before connecting (WSL port forwarding may lag)
1696+
try
1697+
{
1698+
using var http = new HttpClient { Timeout = TimeSpan.FromSeconds(5) };
1699+
var resp = await http.GetAsync($"http://localhost:{ctx.Config.GatewayPort}/", ct);
1700+
ctx.Logger.Debug($"Gateway health check: HTTP {(int)resp.StatusCode}");
1701+
}
1702+
catch (Exception ex)
1703+
{
1704+
return StepResult.Fail($"Gateway not reachable before operator pairing: {ex.Message}");
1705+
}
1706+
16951707
// Connect operator WebSocket — handle pairing-required flow
16961708
var wsLogger = new SetupOpenClawLogger(ctx.Logger);
16971709
OpenClawGatewayClient? client = null;

‎tests/OpenClaw.SetupEngine.Tests/SetupStepsTests.cs‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,6 +1230,25 @@ public void DefaultConfig_NoPairingScopeFields()
12301230
Assert.Empty(scopeProps);
12311231
}
12321232

1233+
// ─── PairOperatorStep: Windows-side gateway health check ───
1234+
1235+
[Fact]
1236+
public async Task PairOperatorStep_FailsWhenGatewayNotReachableFromWindows()
1237+
{
1238+
// Allocate a port and immediately release it so nothing is listening on it.
1239+
var port = GetFreeTcpPort();
1240+
1241+
var config = new SetupConfig { GatewayPort = port };
1242+
var ctx = CreateContext(config);
1243+
ctx.SharedGatewayToken = "test-shared-token";
1244+
1245+
var step = new PairOperatorStep();
1246+
var result = await step.ExecuteAsync(ctx, CancellationToken.None);
1247+
1248+
Assert.Equal(StepOutcome.Failed, result.Outcome);
1249+
Assert.Contains("not reachable", result.Message, StringComparison.OrdinalIgnoreCase);
1250+
}
1251+
12331252
private static CommandResult Ok(string stdout = "", string stderr = "")
12341253
=> new(0, stdout, stderr, TimeSpan.Zero, TimedOut: false);
12351254

0 commit comments

Comments
 (0)