perf(web): park the local-secondary auto-retry on hosts with no WSL
The renderer's local-secondary reconciler was polling getLocalEnvironmentBootstraps on a fixed backoff (2s, 4s, 8s, 16s, 30s, 45s, 60s, 60s) regardless of whether the user had any WSL backend configured. On Windows hosts without WSL enabled that's eight IPC round-trips plus a setTimeout chain doing zero useful work. Probe desktopBridge.getWslState() once at module init. When the user hasn't enabled the WSL backend, latch the auto-retry chain so it parks. The settings page calls markSecondariesConfigured(state.enabled) after every WSL toggle so flipping WSL on later wakes the loop back up. For users who *do* have WSL enabled, behavior is unchanged: the loop still rides out the full 4-minute desktop-bootstrap TTL window covering cold boot.
This commit is contained in:
1 parent
05c52959f9
commit
aebb4fa3e5
2 files changed
+59
-9
No files matched your search
@@ -84,7 +84,10 @@ import {
|
||||
type ServerClientSessionRecord,
|
||||
type ServerPairingLinkRecord,
|
||||
} from "~/environments/primary";
|
||||
import { reconcileLocalSecondaryEnvironments } from "~/environments/local";
|
||||
import {
|
||||
markSecondariesConfigured,
|
||||
reconcileLocalSecondaryEnvironments,
|
||||
} from "~/environments/local";
|
||||
import type { WsRpcClient } from "~/rpc/wsRpcClient";
|
||||
import {
|
||||
type SavedEnvironmentRecord,
|
||||
@@ -2387,7 +2390,13 @@ export function ConnectionsSettings() {
|
||||
setIsUpdatingWslBackend(true);
|
||||
setDesktopWslError(null);
|
||||
try {
|
||||
setDesktopWslState(await apply());
|
||||
const next = await apply();
|
||||
setDesktopWslState(next);
|
||||
// Keep the renderer's auto-retry loop awake while the user has
|
||||
// WSL enabled, and let it park otherwise. Without this the
|
||||
// loop would never resume after a fresh desktop install where
|
||||
// the initial probe latched "no WSL configured".
|
||||
markSecondariesConfigured(next.enabled);
|
||||
// The desktop orchestrator may take a moment to register the new
|
||||
// WSL instance with bootstrap info — fire the renderer reconciler
|
||||
// now to remove stale entries (toggle-off, distro change), then
|
||||
|
||||
@@ -69,6 +69,17 @@ const AUTO_RETRY_DELAYS_MS = [2_000, 4_000, 8_000, 16_000, 30_000, 45_000, 60_00
|
||||
let autoRetryHandle: ReturnType<typeof setTimeout> | null = null;
|
||||
let autoRetryAttempt = 0;
|
||||
|
||||
// Latched once we've confirmed the user has no WSL backend configured
|
||||
// on this host. The auto-retry loop polls getLocalEnvironmentBootstraps
|
||||
// every few seconds for up to ~4 minutes (the desktop-bootstrap TTL
|
||||
// window); on machines where the user will never enable WSL that's
|
||||
// just wasted IPC. setWslBackendEnabled IPC handlers in the settings
|
||||
// page already call reconcile with resetBudget: true, so flipping the
|
||||
// switch on later resumes the loop. We default to false (keep
|
||||
// retrying) so any pre-existing WSL setup still gets retried during
|
||||
// cold boot.
|
||||
let knownNoSecondariesConfigured = false;
|
||||
|
||||
export interface LocalSecondaryReconcileBootstrapSnapshot {
|
||||
readonly id: string;
|
||||
readonly label: string;
|
||||
@@ -394,19 +405,25 @@ async function reconcileOnce(): Promise<void> {
|
||||
|
||||
function scheduleAutoRetry(): void {
|
||||
if (autoRetryHandle !== null) return;
|
||||
// For hosts where the user has no WSL backend configured the retry
|
||||
// loop never has work to do, so we'd otherwise IPC every 2-60s
|
||||
// forever. setWslBackendEnabled clears this latch (via
|
||||
// markSecondariesConfigured) when the user flips WSL on later.
|
||||
if (knownNoSecondariesConfigured) return;
|
||||
if (autoRetryAttempt >= AUTO_RETRY_DELAYS_MS.length) {
|
||||
// Budget exhausted. Surface this through the store so the sidebar
|
||||
// can switch from "Connecting..." to "Couldn't connect, retry?".
|
||||
patchReconcileState({ budgetExhausted: true });
|
||||
return;
|
||||
}
|
||||
// Note: we deliberately don't short-circuit when the current bootstraps
|
||||
// list lacks any secondary entry. The desktop pool only publishes a
|
||||
// backend's bootstrap once its first start cycle has produced a config
|
||||
// (see desktop.ipc.window.getLocalEnvironmentBootstraps), so an in-flight
|
||||
// WSL cold boot looks identical to "no WSL configured" from this side.
|
||||
// We have to keep polling until either a secondary actually shows up or
|
||||
// the budget runs out.
|
||||
// Note: we deliberately don't short-circuit on an empty bootstraps
|
||||
// list past the knownNoSecondariesConfigured check above. The desktop
|
||||
// pool only publishes a backend's bootstrap once its first start
|
||||
// cycle has produced a config (see
|
||||
// desktop.ipc.window.getLocalEnvironmentBootstraps), so an in-flight
|
||||
// WSL cold boot looks identical to "no WSL configured" from this
|
||||
// side. We have to keep polling until either a secondary actually
|
||||
// shows up or the budget runs out.
|
||||
const delay = AUTO_RETRY_DELAYS_MS[autoRetryAttempt];
|
||||
autoRetryAttempt += 1;
|
||||
autoRetryHandle = setTimeout(() => {
|
||||
@@ -455,3 +472,27 @@ function runReconcile(options: { readonly resetBudget: boolean }): Promise<void>
|
||||
export function reconcileLocalSecondaryEnvironments(): Promise<void> {
|
||||
return runReconcile({ resetBudget: true });
|
||||
}
|
||||
|
||||
// Called by the settings page when the user enables/disables WSL.
|
||||
// Flips the "no secondaries here" latch so the auto-retry loop wakes
|
||||
// back up (or stays parked) accordingly. Asynchronously probes
|
||||
// getWslState at module init so non-WSL hosts park immediately
|
||||
// instead of burning ~4 minutes of polls before the budget runs out.
|
||||
export function markSecondariesConfigured(configured: boolean): void {
|
||||
knownNoSecondariesConfigured = !configured;
|
||||
}
|
||||
|
||||
if (typeof window !== "undefined") {
|
||||
// Best-effort: any failure (no bridge, IPC error, missing field)
|
||||
// keeps the default "stay polling" behavior intact.
|
||||
void (async () => {
|
||||
try {
|
||||
const state = await window.desktopBridge?.getWslState();
|
||||
if (state && !state.enabled) {
|
||||
knownNoSecondariesConfigured = true;
|
||||
}
|
||||
} catch {
|
||||
// ignore — fall through to default polling
|
||||
}
|
||||
})();
|
||||
}
|
||||
Reference in new issue
Block a user