Skip to content

Commit ae766dc

Browse files
authored
fix(local-ai): clarify unavailable Local AI setup states (#1263)
Add device-level availability, retryable probe states, installed-runtime controls, five-locale presentation, step-3 escape, and race-safe probe lifecycle.
1 parent 56a169f commit ae766dc

27 files changed

Lines changed: 2728 additions & 202 deletions

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

Lines changed: 90 additions & 70 deletions
Large diffs are not rendered by default.

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

Lines changed: 269 additions & 51 deletions
Large diffs are not rendered by default.
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
namespace OpenClaw.SetupEngine.UI.Pages;
2+
3+
internal enum LocalAiSetupAvailabilityStatus
4+
{
5+
Checking,
6+
Unknown,
7+
Available,
8+
Unsupported,
9+
}
10+
11+
internal readonly record struct LocalAiSetupAvailabilitySnapshot(
12+
int Generation,
13+
LocalAiSetupAvailabilityStatus Status,
14+
string? Reason)
15+
{
16+
public bool IsChecking => Status == LocalAiSetupAvailabilityStatus.Checking;
17+
public bool IsUnknown => Status == LocalAiSetupAvailabilityStatus.Unknown;
18+
public bool IsAvailable => Status == LocalAiSetupAvailabilityStatus.Available;
19+
public bool IsUnsupported => Status == LocalAiSetupAvailabilityStatus.Unsupported;
20+
public bool CanRecheck => Status == LocalAiSetupAvailabilityStatus.Unknown;
21+
}
22+
23+
internal sealed class LocalAiSetupAvailabilityCoordinator
24+
{
25+
private int _generation;
26+
private LocalAiSetupAvailabilitySnapshot _current;
27+
28+
public LocalAiSetupAvailabilitySnapshot Current => _current;
29+
30+
public LocalAiSetupAvailabilitySnapshot StartProbe()
31+
{
32+
int generation = unchecked(++_generation);
33+
_current = new(generation, LocalAiSetupAvailabilityStatus.Checking, Reason: null);
34+
return _current;
35+
}
36+
37+
public bool TryStartRecheck(out LocalAiSetupAvailabilitySnapshot snapshot)
38+
{
39+
if (!_current.CanRecheck)
40+
{
41+
snapshot = _current;
42+
return false;
43+
}
44+
45+
snapshot = StartProbe();
46+
return true;
47+
}
48+
49+
public bool TryApplyAvailable(int generation, out LocalAiSetupAvailabilitySnapshot snapshot) =>
50+
TryApply(generation, LocalAiSetupAvailabilityStatus.Available, reason: null, out snapshot);
51+
52+
public bool TryApplyUnsupported(
53+
int generation,
54+
string reason,
55+
out LocalAiSetupAvailabilitySnapshot snapshot) =>
56+
TryApply(generation, LocalAiSetupAvailabilityStatus.Unsupported, reason, out snapshot);
57+
58+
public bool TryApplyProbeFailure(
59+
int generation,
60+
string reason,
61+
out LocalAiSetupAvailabilitySnapshot snapshot) =>
62+
TryApply(generation, LocalAiSetupAvailabilityStatus.Unknown, reason, out snapshot);
63+
64+
public void CancelCurrent()
65+
{
66+
unchecked { _generation++; }
67+
}
68+
69+
public bool IsCurrent(int generation) => generation == _generation;
70+
71+
private bool TryApply(
72+
int generation,
73+
LocalAiSetupAvailabilityStatus status,
74+
string? reason,
75+
out LocalAiSetupAvailabilitySnapshot snapshot)
76+
{
77+
if (!IsCurrent(generation))
78+
{
79+
snapshot = _current;
80+
return false;
81+
}
82+
83+
_current = new(generation, status, reason);
84+
snapshot = _current;
85+
return true;
86+
}
87+
}

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,17 @@ protected override void OnNavigatedTo(NavigationEventArgs e)
101101

102102
private void RenderProgressPreview()
103103
{
104-
bool localAiPreview = SetupPreview.RequestedPage == "progress-local-ai";
104+
bool localAiPreview =
105+
_config?.LocalAi.Enabled == true ||
106+
SetupPreview.RequestedPage == "progress-local-ai";
105107
TitleText.Text = localAiPreview ? "Setting up OpenClaw and Local AI" : "Setting up OpenClaw";
106108
SubtitleText.Text = localAiPreview
107109
? "Downloading the selected Hugging Face model: about 18 minutes left"
108110
: "Creating OpenClawGateway WSL instance: about 4 minutes left";
109111
var ids = StepGroups.Select(g => g.GroupId).ToArray();
110-
int previewRunningIndex = localAiPreview
111-
? Array.IndexOf(ids, "local-ai-model")
112-
: 3;
112+
int previewRunningIndex = Array.IndexOf(
113+
ids,
114+
localAiPreview ? "local-ai-model" : "wsl-create");
113115
for (int i = 0; i < ids.Length; i++)
114116
{
115117
var status = i < previewRunningIndex
@@ -131,18 +133,21 @@ private void RenderProgressPreview()
131133

132134
private void BuildStepRows()
133135
{
134-
foreach (var (groupId, displayName, _) in StepGroups)
136+
foreach (var (groupId, displayName, stepIds) in StepGroups)
135137
{
136138
var row = new StepRow(
137139
displayName,
138140
showDetailProgress: groupId is "local-ai-engine" or "local-ai-model");
139141
_rows[groupId] = row;
140142
StepsPanel.Children.Add(row.Element);
141-
if (_config?.LocalAi.Enabled != true && groupId.StartsWith("local-ai", StringComparison.Ordinal))
143+
if (_config?.LocalAi.Enabled != true && IsLocalAiOnlyGroup(stepIds))
142144
row.Element.Visibility = Visibility.Collapsed;
143145
}
144146
}
145147

148+
private static bool IsLocalAiOnlyGroup(string[] stepIds) =>
149+
stepIds.All(stepId => stepId.Contains("local-ai", StringComparison.Ordinal));
150+
146151
private void StartPipeline() =>
147152
AsyncEventHandlerGuard.Run(
148153
StartPipelineAsync,

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

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
<ListViewItem x:Name="InstallChoice"
4040
AutomationProperties.AutomationId="WelcomeInstallLocalGatewayChoice"
4141
AutomationProperties.Name="Install a local gateway (WSL), recommended"
42+
AutomationProperties.LiveSetting="Polite"
4243
HorizontalContentAlignment="Stretch"
4344
VerticalContentAlignment="Center"
4445
Padding="16,12">
@@ -65,30 +66,28 @@
6566
Style="{StaticResource CaptionTextBlockStyle}"
6667
Foreground="{ThemeResource AccentTextFillColorPrimaryBrush}" />
6768
</Border>
69+
<Border x:Name="LocalAiAvailabilityBadge"
70+
AutomationProperties.AutomationId="WelcomeLocalAiAvailable"
71+
AutomationProperties.AccessibilityView="Raw"
72+
CornerRadius="4" Padding="7,1" VerticalAlignment="Center"
73+
BorderBrush="{ThemeResource SystemFillColorSuccessBrush}"
74+
BorderThickness="1" Visibility="Collapsed">
75+
<StackPanel Orientation="Horizontal" Spacing="4">
76+
<FontIcon Glyph="&#xE950;" FontSize="11"
77+
IsTextScaleFactorEnabled="False"
78+
Foreground="{ThemeResource SystemFillColorSuccessBrush}"
79+
AutomationProperties.AccessibilityView="Raw" />
80+
<TextBlock x:Uid="Onboarding_Welcome_LocalAiAvailableBadge"
81+
Text="Local AI available"
82+
Style="{StaticResource CaptionTextBlockStyle}"
83+
Foreground="{ThemeResource SystemFillColorSuccessBrush}" />
84+
</StackPanel>
85+
</Border>
6886
</StackPanel>
6987
<TextBlock TextWrapping="Wrap"
7088
Style="{StaticResource CaptionTextBlockStyle}"
7189
Foreground="{ThemeResource TextFillColorSecondaryBrush}"
7290
Text="A private, self-hosted OpenClaw gateway in an isolated Ubuntu WSL instance. We'll show exactly what gets installed before anything runs." />
73-
<StackPanel x:Name="LocalAiAvailabilityPanel"
74-
AutomationProperties.AutomationId="WelcomeLocalAiAvailable"
75-
AutomationProperties.LiveSetting="Polite"
76-
Spacing="2" Margin="0,5,0,0" Visibility="Collapsed">
77-
<StackPanel Orientation="Horizontal" Spacing="6">
78-
<FontIcon Glyph="&#xE73E;" FontSize="12"
79-
IsTextScaleFactorEnabled="False"
80-
Foreground="{ThemeResource SystemFillColorSuccessBrush}" />
81-
<TextBlock Text="Local AI available"
82-
Style="{StaticResource CaptionTextBlockStyle}"
83-
FontWeight="SemiBold"
84-
Foreground="{ThemeResource SystemFillColorSuccessBrush}" />
85-
</StackPanel>
86-
<TextBlock x:Name="LocalAiAvailabilityText"
87-
AutomationProperties.AutomationId="WelcomeLocalAiHardware"
88-
TextWrapping="Wrap"
89-
Style="{StaticResource CaptionTextBlockStyle}"
90-
Foreground="{ThemeResource TextFillColorSecondaryBrush}" />
91-
</StackPanel>
9291
</StackPanel>
9392
</Grid>
9493
</ListViewItem>

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

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using Microsoft.UI.Composition;
22
using Microsoft.UI.Xaml;
3+
using Microsoft.UI.Xaml.Automation;
4+
using Microsoft.UI.Xaml.Automation.Peers;
35
using Microsoft.UI.Xaml.Controls;
46
using Microsoft.UI.Xaml.Hosting;
57
using Microsoft.UI.Xaml.Navigation;
@@ -16,6 +18,7 @@ public sealed partial class WelcomePage : Page
1618
private SetupConfig? _config;
1719
private bool _installSelected = true; // default selection
1820
private bool _suppressSelectionWrite;
21+
private string? _installChoiceBaseAutomationName;
1922

2023
public WelcomePage()
2124
{
@@ -64,15 +67,26 @@ private async Task DetectLocalAiAvailabilityAsync()
6467
if (!IsLoaded || !ReferenceEquals(SetupWindow.Active, setupWindow))
6568
return;
6669

67-
LocalInferenceEligibilityResult eligibility = LocalInferenceEligibility.Evaluate(
68-
hardware,
69-
config.LocalAi.SelectedModelId);
70-
if (!eligibility.CanInstall || eligibility.SelectedGpu is not { } gpu)
70+
LocalInferenceEligibilityResult eligibility = LocalInferenceEligibility.Evaluate(hardware);
71+
if (!eligibility.CanInstall || eligibility.SelectedGpu is null)
7172
return;
7273

73-
LocalAiAvailabilityText.Text =
74-
$"{gpu.Name} detected. Install a local gateway to use local AI inference on this PC.";
75-
LocalAiAvailabilityPanel.Visibility = Visibility.Visible;
74+
LocalAiAvailabilityBadge.Visibility = Visibility.Visible;
75+
// Capture the control's base accessible name once, so repeated detections (e.g. the
76+
// page is re-loaded after navigating back) rebuild the announcement from the same
77+
// starting point instead of appending the badge suffix again on every call.
78+
_installChoiceBaseAutomationName ??= AutomationProperties.GetName(InstallChoice);
79+
AutomationProperties.SetName(
80+
InstallChoice,
81+
$"{_installChoiceBaseAutomationName}, " +
82+
$"{SetupLocalization.GetString("Onboarding_Welcome_LocalAiAvailableBadge.Text")}");
83+
// FromElement returns null until a screen reader (or other AT client) has already
84+
// queried this element for a peer. This probe can complete before that happens, so the
85+
// live-region announcement would otherwise be silently skipped; force peer creation so
86+
// the event always has somewhere to go.
87+
AutomationPeer automationPeer = FrameworkElementAutomationPeer.FromElement(InstallChoice)
88+
?? FrameworkElementAutomationPeer.CreatePeerForElement(InstallChoice);
89+
automationPeer.RaiseAutomationEvent(AutomationEvents.LiveRegionChanged);
7690
}
7791

7892
private void StartMascotBreatheAnimation()
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
using System.Diagnostics;
2+
using Microsoft.Windows.ApplicationModel.Resources;
3+
4+
namespace OpenClaw.SetupEngine.UI;
5+
6+
/// <summary>
7+
/// Resource-string lookup for <see cref="OpenClaw.SetupEngine.UI"/> code-behind. This project has
8+
/// no <c>.resw</c> files of its own and cannot reference the Tray app project (which references
9+
/// this project, so the reverse would be circular). There is no standalone Setup UI executable in
10+
/// Release builds: this project is always hosted inside the Tray app process, so string keys
11+
/// resolve against the same merged app resource map that the Tray app's own localization helper
12+
/// reads, using keys defined in the Tray app's <c>Strings\*\Resources.resw</c> files (the existing
13+
/// <c>x:Uid="Onboarding_LocalAi_RecheckAvailabilityButton"</c> binding already relies on the same
14+
/// mechanism for XAML-declared strings).
15+
/// </summary>
16+
internal static class SetupLocalization
17+
{
18+
private static ResourceManager? s_resourceManager;
19+
20+
private static ResourceManager Manager => s_resourceManager ??= new ResourceManager();
21+
22+
public static string GetString(string resourceKey)
23+
{
24+
string? value = TryGetValueAsString(resourceKey);
25+
if (!string.IsNullOrEmpty(value))
26+
return value;
27+
28+
// XAML property resources (the ones an x:Uid="Key" binding resolves for a "Key.Property"
29+
// entry, e.g. "Onboarding_Welcome_LocalAiAvailableBadge.Text") are stored under a
30+
// "Key/Property" path, not a literal dot. Retry that shape so code-behind can share the
31+
// same resw entry an x:Uid binding already uses, instead of duplicating the string under
32+
// a second key.
33+
int propertySeparator = resourceKey.LastIndexOf('.');
34+
if (propertySeparator > 0 && propertySeparator < resourceKey.Length - 1)
35+
{
36+
string propertyResourcePath =
37+
$"{resourceKey[..propertySeparator]}/{resourceKey[(propertySeparator + 1)..]}";
38+
value = TryGetValueAsString(propertyResourcePath);
39+
if (!string.IsNullOrEmpty(value))
40+
return value;
41+
}
42+
43+
return resourceKey;
44+
}
45+
46+
private static string? TryGetValueAsString(string resourceKey)
47+
{
48+
try
49+
{
50+
ResourceCandidate? candidate = Manager.MainResourceMap.GetValue(
51+
$"Resources/{resourceKey}",
52+
Manager.CreateResourceContext());
53+
return candidate?.ValueAsString;
54+
}
55+
catch (Exception ex)
56+
{
57+
// Trace.TraceWarning (unlike Debug.WriteLine) is not compiled out in Release: the
58+
// TRACE constant is defined in both build configurations by default, and the
59+
// default trace listener forwards to OutputDebugString, so this remains visible via
60+
// DebugView/ETW in a packaged Release build instead of silently disappearing.
61+
Trace.TraceWarning($"SetupLocalization: resource lookup failed for '{resourceKey}': {ex.Message}");
62+
return null;
63+
}
64+
}
65+
66+
/// <summary>
67+
/// Localized <see cref="string.Format(string, object?[])"/>. Catches <see cref="FormatException"/>
68+
/// caused by a malformed translation so a translator typo can't crash the UI thread.
69+
/// </summary>
70+
public static string Format(string resourceKey, params object?[] args)
71+
{
72+
string template = GetString(resourceKey);
73+
try
74+
{
75+
return string.Format(template, args);
76+
}
77+
catch (FormatException)
78+
{
79+
Trace.TraceWarning($"SetupLocalization: format failed for '{resourceKey}': template='{template}'");
80+
return template;
81+
}
82+
}
83+
}

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,19 @@ public SetupWindow(
198198
public bool IsWelcomeInstallSelected => _isWelcomeInstallSelected;
199199
public void SetWelcomeInstallSelected(bool installSelected) => _isWelcomeInstallSelected = installSelected;
200200

201-
internal Task<HostHardwareInfo> GetLocalAiHardwareAsync()
201+
internal Task<HostHardwareInfo> GetLocalAiHardwareAsync(bool forceRefresh = false)
202202
{
203203
lock (_localAiHardwareProbeLock)
204204
{
205-
return _localAiHardwareProbeTask ??=
206-
Task.Run(() => new NvmlHostHardwareProbe().Probe());
205+
if (forceRefresh ||
206+
_localAiHardwareProbeTask is null ||
207+
_localAiHardwareProbeTask.IsFaulted ||
208+
_localAiHardwareProbeTask.IsCanceled)
209+
{
210+
_localAiHardwareProbeTask = Task.Run(() => new NvmlHostHardwareProbe().Probe());
211+
}
212+
213+
return _localAiHardwareProbeTask;
207214
}
208215
}
209216

0 commit comments

Comments
 (0)