Repository navigation
refactor: extract WslGatewayKeepAliveService from App.xaml.cs - #605
Conversation
Move the WSL gateway keepalive logic (the fire-and-forget task that keeps the local gateway's WSL2 VM alive after the tray exits, plus stale-process and stale-marker cleanup) out of App.xaml.cs into a dedicated service. App.xaml.cs kept nine private methods (~220 lines) for this concern. They are moved verbatim into Services/WslGatewayKeepAliveService.cs; the only adaptation is that the two App fields they read, _settings and _gatewayRegistry, now enter as Func<> delegates instead of direct field access. No logic, ordering, threading, or side effect changes. The keep-alive *window* (_keepAliveWindow, the WinUI XamlRoot anchor) is a separate concern and stays in App. Seam unchanged: OnLaunchedAsync still fires the work via Task.Run before InitializeGatewayClient(), off the UI thread. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
|
Codex review: needs maintainer review before merge. Reviewed May 30, 2026, 1:46 PM ET / 17:46 UTC. Summary Reproducibility: not applicable. This PR is a behavior-preserving refactor rather than a bug report. The relevant runtime path is the WSL keepalive startup, which the attached recording and log line demonstrate after the extraction. Review metrics: 1 noteworthy metric.
Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Risk before merge
Maintainer options:
Next step before merge
Security Review detailsBest possible solution: Land the focused extraction once normal CI/build validation is green, leaving the broader god-file decomposition tracked in #554. Do we have a high-confidence way to reproduce the issue? Not applicable: this PR is a behavior-preserving refactor rather than a bug report. The relevant runtime path is the WSL keepalive startup, which the attached recording and log line demonstrate after the extraction. Is this the best way to solve the issue? Yes. Extracting the keepalive concern into a dedicated service while preserving the AGENTS.md: found and applied where relevant. Codex review notes: model gpt-5.5, reasoning high; reviewed against eb06fba21c44. Label changesLabel changes:
Label justifications:
Evidence reviewedWhat I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
|
Summary
App.xaml.cscarried the WSL gateway keepalive logic inline: a fire-and-forget task that keeps the local gateway's WSL2 VM alive after the tray exits, plus cleanup of stale keepalive processes and markers. This moves that concern into a dedicatedWslGatewayKeepAliveService.What changed
Services/WslGatewayKeepAliveService.cs— holds the nine methods (~220 lines) that previously lived inApp: the entry task, distro resolution, stale-process/marker cleanup, and the WSL process spawn.App.xaml.cs— the startup seam inOnLaunchedAsyncnow constructs the service and delegates; the original methods are removed.Appfields the code reads,_settingsand_gatewayRegistry, enter the service asFunc<>delegates instead of direct field access. Nothing else changes — same logic, same ordering, same threading, same side effects._keepAliveWindow, the WinUIXamlRootanchor) is an unrelated concern and stays inApp.Testing
./build.ps1dotnet test ./tests/OpenClaw.Shared.Tests/OpenClaw.Shared.Tests.csproj --no-restoredotnet test ./tests/OpenClaw.Tray.Tests/OpenClaw.Tray.Tests.csproj --no-restoreNo new tests: the decision logic is already covered by
WslKeepAlivePolicyTests(unchanged); the moved methods are process/filesystem orchestration that was not unit-tested before and is not behavior-changed here.Proof
Manual run after the extraction. With the local WSL gateway active, the keepalive fires through the new service on startup, identical to the pre-refactor path:
Grabacion.de.pantalla.2026-05-30.191314.mp4
Notes
No behavior change is intended. The seam (
Task.RunbeforeInitializeGatewayClient(), off the UI thread), the WSL command (wsl.exe -d <distro> -- sleep infinity), distro resolution precedence, and the stale-cleanup path are all preserved exactly.Addresses part of #554.
Co-Authored-By: Claude Sonnet 4.6 [email protected]