Skip to content

Commit 8c7199f

Browse files
shanselmanCopilot
andcommitted
fix(local-ai): gate device eligibility, avoid step-3 dead-end, add checking progress
- CapabilitiesPage/WelcomePage: gate availability on device-level LocalInferenceEligibility.Evaluate(hardware), reconciling a stale or removed SelectedModelId to a valid/recommended model instead of hiding the badge or marking a capable device unavailable (Codex HIGH). - CapabilitiesPage: localize the remaining .wslconfig inspection failure reason through SetupLocalization (Codex MEDIUM). - LocalAiPageViewModel: guarantee the availability probe CTS is disposed on every stale/non-enqueued/rejected callback path via a new ApplyAvailabilityResultOnUiThread wrapper, and release the current-probe slot (not just dispose the token) when the dispatcher refuses the enqueue, so the ViewModel is never stuck reporting IsCheckingAvailability or throws ObjectDisposedException on a later deactivate/cancel (Codex LOW, hardened after a second-pass review finding on the rejected-enqueue path). - CapabilitiesPage.UpdatePrimaryButtonState: do not block Continue at step 3 while Local AI availability is merely Checking/Unknown; only a concrete negative/busy result gates forward progress. The install stage already tolerates Local AI resolving unavailable later, so this closes a dead end where neither the toggle nor Continue could be used (Opus HIGH). - LocalAiPage (Hub): distinguish a definitive unavailable result from a probe-unknown/checking state with a different localized title and severity, and show explicit checking/recheck progress (progress ring, checking title/message) instead of silently hiding all availability chrome while a probe is in flight (Opus MEDIUM x2). - SetupLocalization/LocalAiPageViewModel/CapabilitiesPage: replace Debug.WriteLine (compiled out in Release) with a release logger path so probe/localization failures remain diagnosable (Opus LOW). - LocalAiPageViewModel.RecheckAvailability: enforce CanRecheckAvailability in the command itself, not only in UI binding (Opus LOW). - WelcomePage: make the Local AI badge's accessible-name suffix idempotent across repeated detections and raise a live-region automation event so it is announced (Opus LOW). - Add regression coverage: device-eligibility gating and stale-model reconciliation, checking-state visibility, recheck command gating, step-3 non-dead-end, Hub title/severity distinction, Welcome accessible-name idempotency, and rejected-enqueue CTS release. Co-authored-by: Copilot App <[email protected]>
1 parent 50f6a84 commit 8c7199f

14 files changed

Lines changed: 588 additions & 51 deletions

File tree

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

Lines changed: 65 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -289,10 +289,13 @@ private async Task InitializeLocalAiReviewAsync(
289289
if (!CanApplyLocalAiAvailability(checking.Generation, setupWindow))
290290
return;
291291
_localAiHardware = hardware;
292-
eligibility = LocalInferenceEligibility.Evaluate(
293-
_localAiHardware,
294-
_config!.LocalAi.SelectedModelId);
295-
if (eligibility.FailureCode == LocalInferenceEligibilityFailureCode.HardwareFactsIncomplete)
292+
293+
// Gate on device-level eligibility (the best catalog model this hardware can run),
294+
// not the currently configured model. A stale/removed SelectedModelId must not make
295+
// an otherwise-capable device look unavailable and hide the badge/option; it only
296+
// means the configured model needs to fall back to a valid one below.
297+
LocalInferenceEligibilityResult deviceEligibility = LocalInferenceEligibility.Evaluate(_localAiHardware);
298+
if (deviceEligibility.FailureCode == LocalInferenceEligibilityFailureCode.HardwareFactsIncomplete)
296299
{
297300
// Incomplete facts (a partial/transient NVML read) are inconclusive, not a
298301
// definitive "this device cannot run Local AI". Report it the same way as a
@@ -307,18 +310,44 @@ private async Task InitializeLocalAiReviewAsync(
307310
}
308311
return;
309312
}
310-
_localAiSelectedGpuCapacityBytes = eligibility.DetectedTotalMemoryBytes;
313+
_localAiSelectedGpuCapacityBytes = deviceEligibility.DetectedTotalMemoryBytes;
311314
_localAiRecommendedModelId = LocalModelCatalog.Models
312315
.OrderByDescending(model => model.Weights.SizeBytes)
313316
.FirstOrDefault(model =>
314317
_localAiSelectedGpuCapacityBytes is { } capacityBytes &&
315318
LocalInferenceEligibility.GetRequiredMemoryBytes(model) <= capacityBytes)?.Id;
316-
if (!eligibility.CanInstall || eligibility.Plan is null || eligibility.SelectedGpu is null)
317-
hardwareReason = DescribeLocalAiUnavailable(eligibility);
319+
320+
if (!deviceEligibility.CanInstall || deviceEligibility.Plan is null || deviceEligibility.SelectedGpu is null)
321+
{
322+
hardwareReason = DescribeLocalAiUnavailable(deviceEligibility);
323+
}
324+
else
325+
{
326+
// The device can run Local AI. Reconcile the configured model selection: a
327+
// model that no longer exists in the catalog, or exists but this specific
328+
// hardware cannot run at all (e.g. the config was moved to a machine with a
329+
// smaller GPU), falls back to the recommended (or the device-eligible default)
330+
// model instead of leaving setup stuck on a known-incompatible selection. A
331+
// merely busy GPU (EligibleButBusy) is not reconciled away: the same model would
332+
// still work once the GPU frees up, and CanInstall already covers that case.
333+
if (_config!.LocalAi.SelectedModelId is { } selectedModelId &&
334+
!LocalInferenceEligibility.Evaluate(_localAiHardware, selectedModelId).CanInstall)
335+
{
336+
_config.LocalAi.SelectedModelId = null;
337+
}
338+
_config.LocalAi.SelectedModelId ??= _localAiRecommendedModelId ?? deviceEligibility.Plan.Model.Id;
339+
340+
eligibility = LocalInferenceEligibility.Evaluate(
341+
_localAiHardware,
342+
_config.LocalAi.SelectedModelId);
343+
}
318344
}
319345
catch (Exception ex)
320346
{
321-
Debug.WriteLine($"Local AI hardware probe failed: {ex}");
347+
// Trace.TraceWarning is not compiled out in Release (unlike Debug.WriteLine) and its
348+
// default listener forwards to OutputDebugString, so this stays visible via
349+
// DebugView/ETW instead of silently disappearing in a packaged build.
350+
Trace.TraceWarning($"Local AI hardware probe failed: {ex}");
322351
if (_localAiAvailability.TryApplyProbeFailure(
323352
checking.Generation,
324353
LocalAiProbeFailureReason,
@@ -341,10 +370,8 @@ _localAiSelectedGpuCapacityBytes is { } capacityBytes &&
341370
}
342371
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or InvalidDataException)
343372
{
344-
Debug.WriteLine($"WSL networking inspection failed: {ex}");
345-
wslNetworkingReason =
346-
"OpenClaw cannot safely read the global .wslconfig file. " +
347-
"Check that the file is valid and readable, then try setup again.";
373+
Trace.TraceWarning($"WSL networking inspection failed: {ex}");
374+
wslNetworkingReason = SetupLocalization.GetString("Onboarding_LocalAi_WslConfigReadFailureReason");
348375
}
349376

350377
if (!CanApplyLocalAiAvailability(checking.Generation, setupWindow))
@@ -412,6 +439,7 @@ private void ShowLocalAiAvailabilityChecking(LocalAiSetupAvailabilitySnapshot sn
412439
SetLocalAiOptionAvailability(
413440
isAvailable: false,
414441
SetupLocalization.GetString("Onboarding_LocalAi_CheckingHelpText"));
442+
RestoreLocalAiToggleAsPendingStateEscapeHatch();
415443
ApplySetupReviewSummary(_config);
416444
UpdatePrimaryButtonState();
417445
}
@@ -429,10 +457,29 @@ private void ShowLocalAiProbeUnknown(LocalAiSetupAvailabilitySnapshot snapshot)
429457
SetLocalAiOptionAvailability(
430458
isAvailable: false,
431459
SetupLocalization.GetString("Onboarding_LocalAi_ProbeUnknownHelpText"));
460+
RestoreLocalAiToggleAsPendingStateEscapeHatch();
432461
ApplySetupReviewSummary(_config);
433462
UpdatePrimaryButtonState();
434463
}
435464

465+
/// <summary>
466+
/// SetLocalAiOptionAvailability(isAvailable: false) sets LocalAiOptionContent.IsHitTestVisible
467+
/// to false, which suppresses pointer input for its entire subtree regardless of any
468+
/// descendant's own IsEnabled value; setting LocalAiToggle.IsEnabled back to true alone would
469+
/// not make it clickable. Availability being merely pending (Checking/ProbeUnknown), not yet a
470+
/// definitive result, must not remove the user's only way out, so this restores hit-testing on
471+
/// the shared container and re-enables just the toggle: turning Local AI off unblocks Continue
472+
/// via the existing LocalAiToggle.IsOn != true branch, instead of ever letting Continue itself
473+
/// bypass an as-yet-undetermined WSL networking-consent requirement. The other Local AI
474+
/// controls (model selector, consent checkbox) stay genuinely non-interactive because their
475+
/// own IsEnabled is still false, independent of the container's hit-testability.
476+
/// </summary>
477+
private void RestoreLocalAiToggleAsPendingStateEscapeHatch()
478+
{
479+
LocalAiOptionContent.IsHitTestVisible = true;
480+
LocalAiToggle.IsEnabled = true;
481+
}
482+
436483
private void ShowLocalAiUnavailable(LocalAiSetupAvailabilitySnapshot snapshot)
437484
{
438485
_localAiSelectionEligible = false;
@@ -720,6 +767,12 @@ private void SetLocalAiNetworkingConsent(bool value)
720767

721768
private void UpdatePrimaryButtonState()
722769
{
770+
// Local AI availability being merely pending (Checking/ProbeUnknown) must never let
771+
// Continue bypass eligibility or an as-yet-undetermined WSL networking-consent
772+
// requirement. ShowLocalAiAvailabilityChecking/ShowLocalAiProbeUnknown keep
773+
// LocalAiToggle itself interactive during those states specifically so the user always
774+
// has a way out: turning Local AI off satisfies the LocalAiToggle.IsOn != true branch
775+
// below immediately, without needing Continue to advance on incomplete information.
723776
PrimaryButton.IsEnabled =
724777
_step != 3 ||
725778
LocalAiToggle.IsOn != true ||

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

Lines changed: 1 addition & 0 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">

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Microsoft.UI.Composition;
22
using Microsoft.UI.Xaml;
33
using Microsoft.UI.Xaml.Automation;
4+
using Microsoft.UI.Xaml.Automation.Peers;
45
using Microsoft.UI.Xaml.Controls;
56
using Microsoft.UI.Xaml.Hosting;
67
using Microsoft.UI.Xaml.Navigation;
@@ -17,6 +18,7 @@ public sealed partial class WelcomePage : Page
1718
private SetupConfig? _config;
1819
private bool _installSelected = true; // default selection
1920
private bool _suppressSelectionWrite;
21+
private string? _installChoiceBaseAutomationName;
2022

2123
public WelcomePage()
2224
{
@@ -65,17 +67,26 @@ private async Task DetectLocalAiAvailabilityAsync()
6567
if (!IsLoaded || !ReferenceEquals(SetupWindow.Active, setupWindow))
6668
return;
6769

68-
LocalInferenceEligibilityResult eligibility = LocalInferenceEligibility.Evaluate(
69-
hardware,
70-
config.LocalAi.SelectedModelId);
70+
LocalInferenceEligibilityResult eligibility = LocalInferenceEligibility.Evaluate(hardware);
7171
if (!eligibility.CanInstall || eligibility.SelectedGpu is null)
7272
return;
7373

7474
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);
7579
AutomationProperties.SetName(
7680
InstallChoice,
77-
$"{AutomationProperties.GetName(InstallChoice)}, " +
81+
$"{_installChoiceBaseAutomationName}, " +
7882
$"{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);
7990
}
8091

8192
private void StartMascotBreatheAnimation()

‎src/OpenClaw.SetupEngine.UI/SetupLocalization.cs‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@ public static string GetString(string resourceKey)
5454
}
5555
catch (Exception ex)
5656
{
57-
Debug.WriteLine($"SetupLocalization: resource lookup failed for '{resourceKey}': {ex.Message}");
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}");
5862
return null;
5963
}
6064
}
@@ -72,7 +76,7 @@ public static string Format(string resourceKey, params object?[] args)
7276
}
7377
catch (FormatException)
7478
{
75-
Debug.WriteLine($"SetupLocalization: format failed for '{resourceKey}': template='{template}'");
79+
Trace.TraceWarning($"SetupLocalization: format failed for '{resourceKey}': template='{template}'");
7680
return template;
7781
}
7882
}

‎src/OpenClaw.Tray.WinUI/Pages/LocalAiPage.xaml‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,20 @@
2929
Click="LocalAiUnavailableDetails_Click"/>
3030
</InfoBar.ActionButton>
3131
</InfoBar>
32-
<HyperlinkButton x:Name="LocalAiRecheckAvailabilityButton"
33-
x:Uid="LocalAiPage_RecheckAvailabilityButton"
34-
Content="Recheck"
35-
HorizontalAlignment="Left"
36-
AutomationProperties.AutomationId="LocalAiRecheckAvailabilityButton"
37-
Click="LocalAiRecheckAvailability_Click"
38-
Visibility="Collapsed"/>
32+
<StackPanel Orientation="Horizontal" Spacing="8">
33+
<ProgressRing x:Name="LocalAiAvailabilityProgressRing"
34+
Width="16"
35+
Height="16"
36+
IsActive="False"
37+
AutomationProperties.AccessibilityView="Raw"/>
38+
<HyperlinkButton x:Name="LocalAiRecheckAvailabilityButton"
39+
x:Uid="LocalAiPage_RecheckAvailabilityButton"
40+
Content="Recheck"
41+
HorizontalAlignment="Left"
42+
AutomationProperties.AutomationId="LocalAiRecheckAvailabilityButton"
43+
Click="LocalAiRecheckAvailability_Click"
44+
Visibility="Collapsed"/>
45+
</StackPanel>
3946
<TeachingTip x:Name="LocalAiUnavailableDetailsTip"
4047
x:Uid="LocalAiPage_UnavailableDetailsTip"
4148
Title="Why Local AI is unavailable"

‎src/OpenClaw.Tray.WinUI/Pages/LocalAiPage.xaml.cs‎

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,30 @@ private void RefreshFromViewModel()
9292
_viewModel.ShowAvailabilityInfoBar
9393
? Visibility.Visible
9494
: Visibility.Collapsed;
95-
LocalAiUnavailableInfoBar.Message = LocalizationHelper.GetString(
96-
_viewModel.HasAvailabilityProbeError
97-
? "LocalAiPage_UnavailableProbeMessage"
98-
: "LocalAiPage_UnavailableRequirementsMessage");
95+
LocalAiAvailabilityProgressRing.IsActive = _viewModel.IsCheckingAvailability;
96+
LocalAiAvailabilityProgressRing.Visibility = _viewModel.IsCheckingAvailability
97+
? Visibility.Visible
98+
: Visibility.Collapsed;
99+
if (_viewModel.IsCheckingAvailability)
100+
{
101+
LocalAiUnavailableInfoBar.Title = LocalizationHelper.GetString("LocalAiPage_CheckingTitle");
102+
LocalAiUnavailableInfoBar.Severity = InfoBarSeverity.Informational;
103+
LocalAiUnavailableInfoBar.Message = LocalizationHelper.GetString("LocalAiPage_CheckingMessage");
104+
}
105+
else
106+
{
107+
LocalAiUnavailableInfoBar.Title = LocalizationHelper.GetString(
108+
_viewModel.HasAvailabilityProbeError
109+
? "LocalAiPage_UnavailableProbeTitle"
110+
: "LocalAiPage_UnavailableInfoBar.Title");
111+
LocalAiUnavailableInfoBar.Severity = _viewModel.HasAvailabilityProbeError
112+
? InfoBarSeverity.Warning
113+
: InfoBarSeverity.Informational;
114+
LocalAiUnavailableInfoBar.Message = LocalizationHelper.GetString(
115+
_viewModel.HasAvailabilityProbeError
116+
? "LocalAiPage_UnavailableProbeMessage"
117+
: "LocalAiPage_UnavailableRequirementsMessage");
118+
}
99119
LocalAiRecheckAvailabilityButton.Visibility = _viewModel.HasAvailabilityProbeError
100120
? Visibility.Visible
101121
: Visibility.Collapsed;

0 commit comments

Comments
 (0)