Skip to content

Commit 12addd5

Browse files
shanselmanCopilot
andcommitted
Fix wizard startup recovery and protocol wording
Co-authored-by: Copilot App <[email protected]>
1 parent 4bbadb0 commit 12addd5

3 files changed

Lines changed: 74 additions & 8 deletions

File tree

‎docs/ONBOARDING_WIZARD.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ If the gateway doesn't support the wizard protocol or is unreachable, this scree
4747

4848
The wizard keeps recovery choices visible while setup steps are running so users can start the wizard again or skip it for now if an auth flow stalls. If the gateway restarts or the wizard connection is lost while setup is running, the same recovery choices are presented in the error state so the user is not trapped retrying a broken session.
4949

50-
Gateway-driven onboarding does not show a Back action. The Gateway wizard protocol has no rewind operation, so replaying an earlier Companion payload would display stale state while the authoritative Gateway session remained on a later step. Users can restart onboard or skip and exit from **More options** instead.
50+
Gateway-driven onboarding does not show a Back action. There is no dedicated `wizard.back` RPC. Gateways can instead provide in-band `__back` or `back` options, which protocol clients submit through `wizard.next`; Companion intentionally filters those options because its former local payload replay displayed stale state while the authoritative Gateway session remained on a later step. Users can restart onboard or skip and exit from **More options** instead.
5151

5252
Exact Gateway 2026.7.1 has a terminal compatibility path for an app-managed local WSL gateway. When the final `model-check` answer produces WebSocket close 1012 before the gateway can return `done`, setup retries the temporary `NoListener` state and the typed snapshot-changed race that can occur while the listener is restarting. Other unknown or conflicting endpoint ownership fails immediately, and no credential is sent until the managed endpoint is verified again. A retryable startup close 1013 remains inside the existing reconnect timeout. Setup completes only after a fresh authenticated `hello-ok` handshake. Other versions and steps keep the normal managed-local wizard replay behavior with the same bounded ownership wait; remote gateways and other disconnects do not enter this recovery path.
5353

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

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,14 @@ private async Task StartWizardAsync(bool clearTranscript = true)
111111
_errorState = false;
112112
_finalizationErrorState = false;
113113
_expectedTerminalRestart = false;
114-
HideRecoveryActions();
114+
ShowRecoveryActions();
115115
// Cancel any in-progress server-side wizard session before starting a
116116
// fresh one, so the gateway doesn't reject wizard.start with "wizard
117117
// already running" when recovering from a previous error.
118118
await CancelCurrentSessionAsync();
119+
if (generation != _operationGeneration)
120+
return;
121+
119122
ClearConsoleBanner();
120123
_sessionId = "";
121124
_wizardStepCount = 0;
@@ -124,7 +127,14 @@ private async Task StartWizardAsync(bool clearTranscript = true)
124127
_lastProgressStepId = "";
125128
_stepVisits.Clear();
126129
SetBusy("Connecting to gateway...");
127-
_client = await ConnectClientAsync();
130+
var client = await ConnectClientAsync();
131+
if (generation != _operationGeneration)
132+
{
133+
await DisconnectAndDisposeClientAsync(client);
134+
return;
135+
}
136+
137+
_client = client;
128138
_client.StatusChanged += OnWizardClientStatusChanged;
129139
SetBusy("Starting wizard...");
130140
StartConsoleTail();
@@ -460,8 +470,9 @@ private bool BuildOptions(JsonElement step, JsonElement initial)
460470
{
461471
SelectOptions.Visibility = Visibility.Visible;
462472

463-
// The Gateway contract has no rewind operation. Do not expose back options
464-
// as local navigation because that would desynchronize the active session.
473+
// Gateway Back is an in-band __back/back answer sent through wizard.next,
474+
// not a dedicated wizard.back RPC. Companion intentionally filters it
475+
// rather than reintroducing client-local navigation.
465476
var skipOptions = _options.Where(IsSkipOption).ToList();
466477
var moreOptions = _options.Where(IsMoreOption).ToList();
467478
var normalOptions = _options.Where(o => !IsSkipOption(o) && !IsMoreOption(o) && !IsBackOption(o)).ToList();
@@ -724,7 +735,7 @@ private async Task ExpandMoreOptionsAsync(string moreValue, List<WizardOptionVal
724735

725736
var expandedOptions = WizardAnswerBuilder.ReadOptions(step).ToList();
726737

727-
// Filter out __back and __more from expanded list
738+
// Keep Gateway navigation options out of Companion's visible choices.
728739
var filtered = expandedOptions
729740
.Where(o => !IsMoreOption(o) && !IsBackOption(o))
730741
.ToList();
@@ -767,10 +778,13 @@ private void StartOver_Click(object sender, RoutedEventArgs e) =>
767778

768779
private async Task StartOverAsync()
769780
{
770-
AdvanceOperationGeneration();
781+
var generation = AdvanceOperationGeneration();
771782
HideRecoveryActions();
772783
SetBusy("Starting over...");
773784
await CancelCurrentSessionAsync();
785+
if (generation != _operationGeneration)
786+
return;
787+
774788
await StartWizardAsync();
775789
}
776790

@@ -1562,6 +1576,18 @@ private async Task DisconnectAsync()
15621576
client.Dispose();
15631577
}
15641578

1579+
private static async Task DisconnectAndDisposeClientAsync(OpenClawGatewayClient client)
1580+
{
1581+
try
1582+
{
1583+
await client.DisconnectAsync();
1584+
}
1585+
finally
1586+
{
1587+
client.Dispose();
1588+
}
1589+
}
1590+
15651591
private static string DisplayTitleFor(string stepType) => stepType switch
15661592
{
15671593
"confirm" => "Confirm",

‎tests/OpenClaw.Tray.Tests/AppRefactorContractTests.cs‎

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1420,21 +1420,61 @@ public void WizardResetInputs_RemovesOverflowMoreButton()
14201420
}
14211421

14221422
[Fact]
1423-
public void WizardBack_IsUnavailableWithoutAuthoritativeGatewayRewind()
1423+
public void WizardBack_IsUnavailableWithoutDedicatedGatewayBackRpc()
14241424
{
14251425
var root = TestRepositoryPaths.GetRepositoryRoot();
14261426
var source = File.ReadAllText(Path.Combine(root, "src", "OpenClaw.SetupEngine.UI", "Pages", "WizardPage.xaml.cs"));
14271427
var xaml = File.ReadAllText(Path.Combine(root, "src", "OpenClaw.SetupEngine.UI", "Pages", "WizardPage.xaml"));
1428+
var buildOptions = ExtractMethod(source, "BuildOptions");
1429+
var expandMore = ExtractMethod(source, "ExpandMoreOptionsAsync");
1430+
var isBackOption = ExtractMethod(source, "IsBackOption");
14281431

14291432
Assert.DoesNotContain("WizardBackButton", xaml);
14301433
Assert.DoesNotContain("WizardBack_Click", source);
14311434
Assert.DoesNotContain("_stepHistory", source);
14321435
Assert.DoesNotContain("ApplyPayloadAsync(previousPayload)", source);
1436+
Assert.DoesNotContain("\"wizard.back\"", source);
1437+
Assert.Contains("\"__back\"", isBackOption);
1438+
Assert.Contains("\"back\"", isBackOption);
1439+
Assert.Contains("!IsBackOption(o)", buildOptions);
1440+
Assert.Contains("!IsBackOption(o)", expandMore);
1441+
Assert.Contains("\"wizard.next\"", source);
14331442
Assert.Contains("MoreOptionsButton", xaml);
14341443
Assert.Contains("StartOver_Click", xaml);
14351444
Assert.Contains("SkipWizard_Click", xaml);
14361445
}
14371446

1447+
[Fact]
1448+
public void WizardStartup_KeepsRecoveryVisibleAndRejectsStaleConnections()
1449+
{
1450+
var root = TestRepositoryPaths.GetRepositoryRoot();
1451+
var source = File.ReadAllText(Path.Combine(root, "src", "OpenClaw.SetupEngine.UI", "Pages", "WizardPage.xaml.cs"));
1452+
var start = ExtractMethod(source, "StartWizardAsync");
1453+
var startOver = ExtractMethod(source, "StartOverAsync");
1454+
var disposeStaleClient = ExtractMethod(source, "DisconnectAndDisposeClientAsync");
1455+
1456+
Assert.DoesNotContain("HideRecoveryActions()", start);
1457+
AssertInOrder(
1458+
start,
1459+
"var generation = AdvanceOperationGeneration();",
1460+
"ShowRecoveryActions();",
1461+
"await CancelCurrentSessionAsync();",
1462+
"if (generation != _operationGeneration)",
1463+
"var client = await ConnectClientAsync();",
1464+
"if (generation != _operationGeneration)",
1465+
"await DisconnectAndDisposeClientAsync(client);",
1466+
"_client = client;",
1467+
"SendWizardRequestAsync(\"wizard.start\"");
1468+
AssertInOrder(
1469+
startOver,
1470+
"var generation = AdvanceOperationGeneration();",
1471+
"await CancelCurrentSessionAsync();",
1472+
"if (generation != _operationGeneration)",
1473+
"await StartWizardAsync();");
1474+
Assert.Contains("finally", disposeStaleClient);
1475+
Assert.Contains("client.Dispose()", disposeStaleClient);
1476+
}
1477+
14381478
[Fact]
14391479
public void WizardCompletion_AppliesWindowsNodeContextBeforeSummary()
14401480
{

0 commit comments

Comments
 (0)