diff --git a/apps/desktop/src/backend/DesktopBackendConfiguration.test.ts b/apps/desktop/src/backend/DesktopBackendConfiguration.test.ts index b2063b8f53..e965dab5d1 100644 --- a/apps/desktop/src/backend/DesktopBackendConfiguration.test.ts +++ b/apps/desktop/src/backend/DesktopBackendConfiguration.test.ts @@ -280,4 +280,43 @@ describe("DesktopBackendConfiguration", () => { } }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)), ); + + it.effect( + "resolvePrimary falls back to the Windows primary when wsl-only but WSL is unavailable", + () => + Effect.gen(function* () { + const fileSystem = yield* FileSystem.FileSystem; + const baseDir = yield* fileSystem.makeTempDirectoryScoped({ + prefix: "t3-desktop-backend-config-test-", + }); + + yield* Effect.gen(function* () { + const environment = yield* DesktopEnvironment.DesktopEnvironment; + const configuration = yield* DesktopBackendConfiguration.DesktopBackendConfiguration; + const config = yield* configuration.resolvePrimary; + + // wsl-only is persisted but WSL is unavailable, so the primary must + // not spawn wsl.exe (which would loop on preflight failures while the + // Connections backend control is hidden). Resolve the Windows primary. + assert.equal(config.executablePath, process.execPath); + assert.equal(config.bootstrap.t3Home, environment.baseDir); + assert.isTrue(Option.isNone(config.preflightFailure)); + }).pipe( + Effect.provide( + DesktopBackendConfiguration.layer.pipe( + Layer.provideMerge(serverExposureLayer), + Layer.provideMerge( + DesktopAppSettings.layerTest({ + ...DesktopAppSettings.DEFAULT_DESKTOP_SETTINGS, + wslBackendEnabled: true, + wslOnly: true, + }), + ), + Layer.provideMerge(DesktopWslEnvironment.layerTest({ isAvailable: false })), + Layer.provideMerge(makeEnvironmentLayer(baseDir, { platform: "win32" })), + ), + ), + ); + }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)), + ); }); diff --git a/apps/desktop/src/backend/DesktopBackendConfiguration.ts b/apps/desktop/src/backend/DesktopBackendConfiguration.ts index 4acb18fde9..a64a4a0abc 100644 --- a/apps/desktop/src/backend/DesktopBackendConfiguration.ts +++ b/apps/desktop/src/backend/DesktopBackendConfiguration.ts @@ -501,7 +501,19 @@ export const layer = Layer.effect( // configResolve fires each time the backend (re)starts. const persistedSettings = yield* settings.get; if (persistedSettings.wslOnly && persistedSettings.wslBackendEnabled) { - return yield* buildWslPrimaryConfig; + // Only honor wsl-only when WSL is actually usable. If the user + // persisted wsl-only but WSL has since become unavailable (wsl.exe + // removed, no distro), fall back to the Windows primary instead of + // looping forever on preflight failures: the Connections backend + // control is hidden while WSL is unavailable, so a stuck WSL + // primary would otherwise leave no in-app way back to Windows. + const wslAvailable = yield* wslEnvironment.isAvailable; + if (wslAvailable) { + return yield* buildWslPrimaryConfig; + } + yield* Effect.logWarning( + "WSL-only backend requested but WSL is unavailable; starting the Windows primary instead.", + ); } return yield* buildWindowsPrimaryConfig; }).pipe(Effect.withSpan("desktop.backendConfiguration.resolvePrimary")),