Skip to content

Commit fb14564

Browse files
authored
fix(setup): gate Local AI on WSL readiness (#1203)
Gate fresh Local AI setup on authoritative WSL readiness while preserving the one-shot recovery and installed-runtime behavior landed in #1202.
1 parent 8651827 commit fb14564

11 files changed

Lines changed: 250 additions & 67 deletions

File tree

‎docs/ONBOARDING_WIZARD.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ The setup flow no longer configures remote/manual gateways inline. The Welcome p
2121
## Screen Details
2222

2323
### Welcome
24-
Displays the OpenClaw icon, app title, and a brief description. If an app-owned local WSL gateway already exists, the primary CTA reads **Install new WSL Gateway** and confirmation warns that the current OpenClaw WSL gateway and distro will be deleted. If only an external gateway exists, the CTA remains **Set up locally** and confirmation explains that the external connection remains available in Connections.
24+
Displays the OpenClaw icon, app title, and a brief description. Choosing local gateway setup runs the read-only WSL readiness gate before the Capabilities page or its Local AI decision UI can open. WSL2 environment failures, including disabled hardware virtualization, are shown as WSL readiness failures and block both Local AI and non-Local-AI local gateway setup. The readiness dialog can retry with a fresh inspection after the user resolves the reported problem. If an app-owned local WSL gateway already exists, the primary CTA reads **Install new WSL Gateway** and confirmation warns that the current OpenClaw WSL gateway and distro will be deleted. If only an external gateway exists, the CTA remains **Set up locally** and confirmation explains that the external connection remains available in Connections.
2525

2626
### Local setup progress
2727
Installs and connects a new app-owned `OpenClawGateway` WSL instance from a clean WSL baseline. If the WSL platform is missing or its optional component is not initialized, setup requests administrator approval to install it, re-inspects readiness, and reports when a Windows restart is required. Setup does not export from or mutate an existing user Ubuntu distro; if WSL cannot create the named app-owned distro directly, setup fails with an actionable update message. Cleanup automatically unregisters a distro only when durable OpenClaw evidence is paired with exactly one readable current-user WSL registration whose canonical base path matches the expected managed install path. Automatic orphan-directory cleanup requires a marker bound to that exact path. An unproven same-named distro or leftover data directory is preserved unless the user explicitly confirms its permanent replacement in the setup UI or passes `--confirm-destructive`. When replacing an app-owned local gateway, the removal step is shown as part of progress and can be retried on failure.

‎docs/SETUP_ENGINE_REDESIGN.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ Log path defaults to `%APPDATA%\OpenClawTray\Logs\Setup\setup-engine-<yyyyMMdd-H
272272

273273
The WinUI app is a **thin shell** - no business logic, just rendering pipeline state. End-user UI runs default to `RollbackOnFailure=true`; `--no-rollback-on-failure` preserves an explicit debugging opt-out.
274274

275-
### Page Flow: Security → Welcome → Capabilities → Progress → OpenClaw onboard → Complete
275+
### Page Flow: Security → Welcome → WSL readiness gate → Capabilities → Progress → OpenClaw onboard → Complete
276276

277277
**SecurityNoticePage**
278278
- Native warning InfoBar for device-trust and setup transparency

‎src/OpenClaw.SetupEngine.UI/Pages/CapabilitiesPage.xaml.cs‎

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,6 @@ private async Task InitializeLocalAiReviewAsync(bool forceNetworkingConsent)
269269
Task<HostHardwareInfo> hardwareTask = setupWindow is not null
270270
? setupWindow.GetLocalAiHardwareAsync()
271271
: Task.Run(() => new NvmlHostHardwareProbe().Probe());
272-
Task<WslViabilityResult> wslTask = setupWindow is not null
273-
? setupWindow.GetWslViabilityAsync()
274-
: InspectWslViabilityAsync();
275272

276273
string? hardwareReason = null;
277274
LocalInferenceEligibilityResult? eligibility = null;
@@ -297,19 +294,6 @@ _localAiSelectedGpuCapacityBytes is { } capacityBytes &&
297294
"Check the NVIDIA driver installation and try setup again.";
298295
}
299296

300-
WslViabilityResult wslViability;
301-
try
302-
{
303-
wslViability = await wslTask;
304-
}
305-
catch
306-
{
307-
wslViability = new(
308-
WslViabilityKind.InspectionFailed,
309-
"OpenClaw could not safely verify the WSL2 environment.",
310-
"Run wsl --status in PowerShell, resolve the reported problem, and try setup again.");
311-
}
312-
313297
string? wslNetworkingReason = null;
314298
try
315299
{
@@ -330,7 +314,6 @@ _localAiSelectedGpuCapacityBytes is { } capacityBytes &&
330314

331315
string? unavailableReason = LocalAiAvailabilityReasons.Build(
332316
hardwareReason,
333-
wslViability,
334317
wslNetworkingReason);
335318
if (unavailableReason is not null)
336319
{
@@ -352,15 +335,6 @@ _localAiSelectedGpuCapacityBytes is { } capacityBytes &&
352335
ApplySetupReviewSummary(_config);
353336
}
354337

355-
private static async Task<WslViabilityResult> InspectWslViabilityAsync()
356-
{
357-
using var logger = new SetupLogger(filePath: null);
358-
return await WslViabilityInspector.InspectAsync(
359-
new CommandRunner(logger),
360-
logger,
361-
CancellationToken.None);
362-
}
363-
364338
private static WslGlobalConfigManager CreateWslGlobalConfigManager()
365339
{
366340
var profile = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);

‎src/OpenClaw.SetupEngine.UI/Pages/WelcomePage.xaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
VerticalAlignment="Center" />
5757
<ProgressRing x:Name="InstallCheckProgress"
5858
AutomationProperties.AutomationId="WelcomeInstallCheckProgress"
59-
AutomationProperties.Name="Checking existing WSL setup"
59+
AutomationProperties.Name="Checking WSL readiness and existing setup"
6060
Width="16" Height="16"
6161
IsActive="False" Visibility="Collapsed" />
6262
<Border CornerRadius="4" Padding="7,1" VerticalAlignment="Center"

‎src/OpenClaw.SetupEngine.UI/Pages/WelcomePage.xaml.cs‎

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ private async Task DetectLocalAiAvailabilityAsync()
5454
if (setupWindow is null || config is null)
5555
return;
5656

57+
WslViabilityResult wslViability = await setupWindow.GetWslViabilityAsync();
58+
if (!IsLoaded || !ReferenceEquals(SetupWindow.Active, setupWindow))
59+
return;
60+
if (wslViability.BlocksSetup)
61+
return;
62+
5763
var hardware = await setupWindow.GetLocalAiHardwareAsync();
5864
if (!IsLoaded || !ReferenceEquals(SetupWindow.Active, setupWindow))
5965
return;
@@ -141,7 +147,10 @@ private async Task StartInstallAsync()
141147
{
142148
var config = _config ?? throw new InvalidOperationException("Setup configuration has not been loaded.");
143149
var setupWindow = SetupWindow.Active;
144-
var dataDir = setupWindow?.DataDir ?? SetupContext.ResolveDataDir();
150+
if (setupWindow is null)
151+
return;
152+
153+
var dataDir = setupWindow.DataDir;
145154

146155
// The progress ring carries the checking state (its automation name is
147156
// "Checking existing WSL setup"). Leave the option title alone: replacing it
@@ -152,6 +161,34 @@ private async Task StartInstallAsync()
152161
var navigating = false;
153162
try
154163
{
164+
while (true)
165+
{
166+
WslViabilityResult wslViability =
167+
await setupWindow.GetWslViabilityAsync(refresh: true);
168+
if (wslViability.BlocksSetup)
169+
{
170+
var readinessRoot = XamlRoot;
171+
if (setupWindow.IsClosed || readinessRoot is null)
172+
return;
173+
174+
var retry = await new ContentDialog
175+
{
176+
Title = "WSL2 is not ready",
177+
Content = wslViability.Description,
178+
PrimaryButtonText = "Try again",
179+
CloseButtonText = "Cancel",
180+
DefaultButton = ContentDialogButton.Primary,
181+
XamlRoot = readinessRoot,
182+
}.ShowAsync();
183+
184+
if (retry != ContentDialogResult.Primary)
185+
return;
186+
continue;
187+
}
188+
189+
break;
190+
}
191+
155192
ExistingConfigDetector.ExistingConfig existing;
156193
while (true)
157194
{
@@ -160,13 +197,13 @@ private async Task StartInstallAsync()
160197
existing = await Task.Run(() => ExistingConfigDetector.Detect(
161198
dataDir,
162199
config.DistroName,
163-
setupWindow?.LocalDataDir));
200+
setupWindow.LocalDataDir));
164201
break;
165202
}
166203
catch (InvalidOperationException ex)
167204
{
168205
var errorRoot = XamlRoot;
169-
if (setupWindow is null or { IsClosed: true } || errorRoot is null)
206+
if (setupWindow.IsClosed || errorRoot is null)
170207
return;
171208

172209
// Inspection failure is usually transient, so offer a way forward
@@ -187,7 +224,7 @@ private async Task StartInstallAsync()
187224
}
188225

189226
var xamlRoot = XamlRoot;
190-
if (setupWindow is null or { IsClosed: true } || xamlRoot is null)
227+
if (setupWindow.IsClosed || xamlRoot is null)
191228
return;
192229

193230
InstallCheckProgress.IsActive = false;
@@ -225,7 +262,7 @@ private async Task StartInstallAsync()
225262
}
226263
finally
227264
{
228-
if (!navigating && setupWindow is { IsClosed: false })
265+
if (!navigating && !setupWindow.IsClosed)
229266
{
230267
InstallCheckProgress.IsActive = false;
231268
InstallCheckProgress.Visibility = Visibility.Collapsed;

‎src/OpenClaw.SetupEngine.UI/SetupWindow.xaml.cs‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ public sealed partial class SetupWindow : Window
2828
private readonly string _localDataDir;
2929
private readonly object _localAiHardwareProbeLock = new();
3030
private Task<HostHardwareInfo>? _localAiHardwareProbeTask;
31-
private readonly object _wslViabilityLock = new();
32-
private Task<WslViabilityResult>? _wslViabilityTask;
31+
private readonly WslViabilityProbe _wslViabilityProbe = new(InspectWslViabilityAsync);
3332

3433
public static SetupWindow? Active { get; private set; }
3534

@@ -208,13 +207,8 @@ internal Task<HostHardwareInfo> GetLocalAiHardwareAsync()
208207
}
209208
}
210209

211-
internal Task<WslViabilityResult> GetWslViabilityAsync()
212-
{
213-
lock (_wslViabilityLock)
214-
{
215-
return _wslViabilityTask ??= InspectWslViabilityAsync();
216-
}
217-
}
210+
internal Task<WslViabilityResult> GetWslViabilityAsync(bool refresh = false) =>
211+
_wslViabilityProbe.GetAsync(refresh);
218212

219213
private static async Task<WslViabilityResult> InspectWslViabilityAsync()
220214
{

‎src/OpenClaw.SetupEngine/LocalAiAvailabilityReasons.cs‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,12 @@ internal static class LocalAiAvailabilityReasons
44
{
55
public static string? Build(
66
string? hardwareReason,
7-
WslViabilityResult wslViability,
87
string? wslNetworkingReason)
98
{
10-
ArgumentNullException.ThrowIfNull(wslViability);
11-
var reasons = new List<string>(capacity: 3);
9+
var reasons = new List<string>(capacity: 2);
1210

1311
if (!string.IsNullOrWhiteSpace(hardwareReason))
1412
reasons.Add($"Hardware: {hardwareReason.Trim()}");
15-
if (wslViability.BlocksSetup)
16-
reasons.Add($"WSL: {wslViability.Description}");
1713
if (!string.IsNullOrWhiteSpace(wslNetworkingReason))
1814
reasons.Add($"WSL networking: {wslNetworkingReason.Trim()}");
1915

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
namespace OpenClaw.SetupEngine;
2+
3+
internal sealed class WslViabilityProbe
4+
{
5+
private readonly Func<Task<WslViabilityResult>> _inspect;
6+
private readonly object _lock = new();
7+
private Task<WslViabilityResult>? _inspectionTask;
8+
9+
public WslViabilityProbe(Func<Task<WslViabilityResult>> inspect) =>
10+
_inspect = inspect ?? throw new ArgumentNullException(nameof(inspect));
11+
12+
public Task<WslViabilityResult> GetAsync(bool refresh = false)
13+
{
14+
lock (_lock)
15+
{
16+
// Share an in-flight inspection; refresh replaces only a completed result.
17+
if (refresh && _inspectionTask?.IsCompleted == true)
18+
_inspectionTask = null;
19+
20+
return _inspectionTask ??= _inspect();
21+
}
22+
}
23+
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,12 @@ public void BuildDefaultSteps_IncludesCurrentSetupFlow()
116116
Assert.IsType<StartKeepaliveStep>(steps[^1]);
117117

118118
var ensureWslIndex = steps.FindIndex(step => step is EnsureWslPlatformStep);
119+
var preflightWslIndex = steps.FindIndex(step => step is PreflightWslStep);
120+
var localAiHardwareIndex = steps.FindIndex(step => step is PreflightLocalAiHardwareStep);
119121
var runtimeDownloadIndex = steps.FindIndex(step => step is AcquireLocalAiRuntimeStep);
120122
var modelDownloadIndex = steps.FindIndex(step => step is AcquireLocalAiModelStep);
123+
Assert.True(localAiHardwareIndex < preflightWslIndex);
124+
Assert.True(preflightWslIndex < ensureWslIndex);
121125
Assert.True(ensureWslIndex < runtimeDownloadIndex);
122126
Assert.True(ensureWslIndex < modelDownloadIndex);
123127
}
@@ -147,6 +151,8 @@ public void LocalAiDisabled_SkipsEveryLocalAiMutation()
147151
];
148152

149153
Assert.All(localAiSteps, step => Assert.True(step.CanSkip(ctx), step.Id));
154+
Assert.False(steps.Single(step => step is PreflightWslStep).CanSkip(ctx));
155+
Assert.False(steps.Single(step => step is EnsureWslPlatformStep).CanSkip(ctx));
150156
}
151157

152158
[Theory]

0 commit comments

Comments
 (0)