Skip to content

Commit 98d0760

Browse files
ranjeshjCopilot
authored andcommitted
Make WSL setup deterministic
Replace the local setup path that exported/imported an existing Ubuntu distro with a clean, app-owned WSL install flow. Tighten preflight, cleanup, install-path validation, rollback, documentation, and regression coverage so setup has explicit success and failure conditions. Co-authored-by: Copilot <[email protected]>
1 parent ca8c677 commit 98d0760

12 files changed

Lines changed: 580 additions & 94 deletions

File tree

‎docs/ONBOARDING_WIZARD.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ On first launch, the wizard appears only when there is no usable saved gateway c
99
The V2 setup flow walks users through:
1010

1111
1. **Welcome** — Greeting and introduction
12-
2. **Local setup progress** — App-owned `OpenClawGateway` WSL installation
12+
2. **Local setup progress** — Fresh app-owned `OpenClawGateway` WSL installation
1313
3. **Gateway setup** — Gateway-driven provider/model configuration hosted by `GatewayWizardPage`
1414
4. **Permissions** — Windows system permission review
1515
5. **All set** — Feature summary and completion
@@ -22,7 +22,7 @@ The setup flow no longer configures remote/manual gateways. The Welcome page's *
2222
Displays the OpenClaw lobster 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.
2323

2424
### Local setup progress
25-
Installs and connects a new app-owned `OpenClawGateway` WSL instance. When replacing an app-owned local gateway, the removal step is shown as part of progress and can be retried on failure.
25+
Installs and connects a new app-owned `OpenClawGateway` WSL instance from a clean WSL baseline. 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. When replacing an app-owned local gateway, the removal step is shown as part of progress and can be retried on failure.
2626

2727
### Wizard
2828
Renders server-defined setup steps via RPC (`wizard.start` / `wizard.next`). The gateway controls the flow — steps can be:

‎docs/SETUP_ENGINE_REDESIGN.md‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,12 @@ Executed sequentially. Each step is a small class (30–120 lines) in `SetupStep
164164

165165
| # | Step Class | What It Does |
166166
|---|-----------|-------------|
167-
| 1 | `CleanupStaleDistroStep` | Unregister leftover WSL distro if `CleanBeforeRun` |
168-
| 2 | `CleanupStaleGatewayStep` | Stop orphaned gateway service, remove config |
169-
| 3 | `PreflightOsStep` | Validate Windows 64-bit, version ≥ 22H2 |
170-
| 4 | `PreflightWslStep` | Verify WSL installed and version ≥ 2 |
167+
| 1 | `PreflightOsStep` | Validate Windows 64-bit, version ≥ 22H2 |
168+
| 2 | `PreflightWslStep` | Verify WSL is installed and supports direct named clean installs |
169+
| 3 | `CleanupStaleDistroStep` | Unregister leftover app-owned WSL distro and remove its VHD directory if `CleanBeforeRun` |
170+
| 4 | `CleanupStaleGatewayStep` | Stop orphaned gateway service, remove config |
171171
| 5 | `PreflightPortStep` | Check gateway port is available |
172-
| 6 | `CreateWslInstanceStep` | Export base distro → import as new instance |
172+
| 6 | `CreateWslInstanceStep` | Directly install a fresh app-owned WSL distro; never export a user's Ubuntu distro |
173173
| 7 | `ConfigureWslInstanceStep` | Write wsl.conf, create user, set dirs |
174174
| 8 | `ValidateWslLockdownStep` | Verify WSL isolation settings are applied |
175175
| 9 | `InstallCliStep` | Run install script inside WSL |

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ public sealed partial class ProgressPage : Page
2424
// Map pipeline step IDs to display groups (N:1)
2525
private static readonly (string GroupId, string DisplayName, string[] StepIds)[] StepGroups =
2626
[
27+
("preflight", "Check system", ["preflight-os", "preflight-wsl"]),
2728
("cleanup", "Removing existing gateway", ["cleanup-distro", "cleanup-gateway"]),
28-
("preflight", "Check system", ["preflight-os", "preflight-wsl", "preflight-port"]),
29-
("wsl-create", "Installing Ubuntu", ["wsl-create"]),
29+
("port", "Checking gateway port", ["preflight-port"]),
30+
("wsl-create", "Installing clean WSL gateway", ["wsl-create"]),
3031
("wsl-configure", "Configuring instance", ["wsl-configure", "validate-wsl-lockdown"]),
3132
("install-cli", "Installing OpenClaw", ["install-cli"]),
3233
("configure", "Preparing gateway", ["configure-gateway", "install-service"]),

‎src/OpenClaw.SetupEngine/CommandRunner.cs‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,27 @@ namespace OpenClaw.SetupEngine;
77

88
public sealed record CommandResult(int ExitCode, string Stdout, string Stderr, TimeSpan Elapsed, bool TimedOut);
99

10-
public sealed class CommandRunner
10+
public interface ICommandRunner
11+
{
12+
Task<CommandResult> RunAsync(
13+
string executable,
14+
string[] arguments,
15+
TimeSpan timeout,
16+
IReadOnlyDictionary<string, string>? environment = null,
17+
string? workingDirectory = null,
18+
string? stdinInput = null,
19+
CancellationToken ct = default);
20+
21+
Task<CommandResult> RunInWslAsync(
22+
string distroName,
23+
string command,
24+
TimeSpan timeout,
25+
IReadOnlyDictionary<string, string>? environment = null,
26+
CancellationToken ct = default,
27+
string? user = null);
28+
}
29+
30+
public sealed class CommandRunner : ICommandRunner
1131
{
1232
private readonly SetupLogger _logger;
1333
private const int DrainTimeoutMs = 5000; // bounded drain for orphan WSL processes

‎src/OpenClaw.SetupEngine/SetupContext.cs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public sealed class SetupConfig
99
{
1010
public string DistroName { get; set; } = "OpenClawGateway";
1111
public int GatewayPort { get; set; } = 18789;
12-
public string BaseDistro { get; set; } = "";
12+
public string BaseDistro { get; set; } = "Ubuntu-24.04";
1313
public bool SkipPermissions { get; set; }
1414
public bool SkipWizard { get; set; }
1515
public bool Headless { get; set; }
@@ -255,7 +255,7 @@ public sealed class SetupContext
255255
public SetupConfig Config { get; }
256256
public SetupLogger Logger { get; }
257257
public TransactionJournal Journal { get; }
258-
public CommandRunner Commands { get; }
258+
public ICommandRunner Commands { get; }
259259
public CancellationToken CancellationToken { get; }
260260

261261
// Accumulated state from steps
@@ -274,7 +274,7 @@ public sealed class SetupContext
274274
// WSL PATH prefix using configured user
275275
public string WslPathPrefix => WslConstants.GetPathPrefix(Config.Wsl.User);
276276

277-
public SetupContext(SetupConfig config, SetupLogger logger, TransactionJournal journal, CommandRunner commands, CancellationToken ct)
277+
public SetupContext(SetupConfig config, SetupLogger logger, TransactionJournal journal, ICommandRunner commands, CancellationToken ct)
278278
{
279279
Config = config;
280280
Logger = logger;

‎src/OpenClaw.SetupEngine/SetupPipeline.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ public static List<SetupStep> BuildDefaultSteps()
4242
{
4343
return
4444
[
45-
new CleanupStaleDistroStep(),
46-
new CleanupStaleGatewayStep(),
4745
new PreflightOsStep(),
4846
new PreflightWslStep(),
47+
new CleanupStaleDistroStep(),
48+
new CleanupStaleGatewayStep(),
4949
new PreflightPortStep(),
5050
new CreateWslInstanceStep(),
5151
new ConfigureWslInstanceStep(),

0 commit comments

Comments
 (0)