Skip to content

Commit 72c75b6

Browse files
fix(desktop): startup recovery offers Windows when a live WSL-only backend is unreachable
A WSL-only server that is running but misses the readiness window keeps probing, since it may still be booting, and the recovery window now offers "Use Windows for this launch". Choosing it applies the in-memory Windows fallback and replaces the WSL process, so the user can reach Settings. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 047ee10 commit 72c75b6

4 files changed

Lines changed: 45 additions & 12 deletions

File tree

‎apps/desktop/src/app/DesktopStartupRecovery.ts‎

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import * as ElectronShell from "../electron/ElectronShell.ts";
1313
import * as ElectronTheme from "../electron/ElectronTheme.ts";
1414
import * as ElectronWindow from "../electron/ElectronWindow.ts";
1515
import * as DesktopUpdates from "../updates/DesktopUpdates.ts";
16-
import type { BackendStartupFailure } from "../backend/DesktopBackendManager.ts";
1716
import * as DesktopEnvironment from "./DesktopEnvironment.ts";
1817
import * as DesktopObservability from "./DesktopObservability.ts";
1918
import * as DesktopState from "./DesktopState.ts";
@@ -35,7 +34,14 @@ export type StartupRecoveryOffer =
3534
| { readonly _tag: "Releases" }
3635
| { readonly _tag: "ManagedPolicy" };
3736

38-
const STARTUP_RECOVERY_ACTIONS = ["update", "reinstall", "releases", "copy", "quit"] as const;
37+
const STARTUP_RECOVERY_ACTIONS = [
38+
"windows",
39+
"update",
40+
"reinstall",
41+
"releases",
42+
"copy",
43+
"quit",
44+
] as const;
3945
type StartupRecoveryAction = (typeof STARTUP_RECOVERY_ACTIONS)[number];
4046

4147
/** Prefer a newer build, then the last build that started on this machine, then the releases page. */
@@ -112,7 +118,7 @@ function describeOffer(offer: StartupRecoveryOffer): { text: string; action: str
112118

113119
function buildStartupRecoveryHtml(input: {
114120
readonly appVersion: string;
115-
readonly failure: BackendStartupFailure;
121+
readonly failure: DesktopState.PrimaryBackendFailure;
116122
readonly offer: StartupRecoveryOffer;
117123
readonly logDir: string;
118124
}): string {
@@ -132,7 +138,7 @@ pre{flex:1;min-height:60px;margin:0;overflow:auto;background:var(--code);border:
132138
<h1>T3 Code could not start</h1>
133139
<p>${escapeHtml(input.failure.reason)}</p>
134140
<p>${escapeHtml(offer.text)}</p>
135-
<div class="actions">${offer.action}${actionLink("copy", "Copy details")}${actionLink("quit", "Quit")}</div>
141+
<div class="actions">${input.failure.useWindows ? actionLink("windows", "Use Windows for this launch", true) : ""}${offer.action}${actionLink("copy", "Copy details")}${actionLink("quit", "Quit")}</div>
136142
<pre>${escapeHtml(output.length > 0 ? output : "The server wrote no output.")}</pre>
137143
<p class="muted">Version ${escapeHtml(input.appVersion)}. T3 Code tries again in the background. Logs: ${escapeHtml(input.logDir)}</p>
138144
</body></html>`;
@@ -173,7 +179,7 @@ export const listen: Effect.Effect<
173179

174180
const windowRef = yield* Ref.make(Option.none<Electron.BrowserWindow>());
175181
// The failure that opened the window; later restarts do not reload its details.
176-
const failureRef = yield* Ref.make(Option.none<BackendStartupFailure>());
182+
const failureRef = yield* Ref.make(Option.none<DesktopState.PrimaryBackendFailure>());
177183
const renderedHtmlRef = yield* Ref.make("");
178184
const checkedRef = yield* Ref.make(false);
179185
let backendHasStarted = false;
@@ -210,6 +216,11 @@ export const listen: Effect.Effect<
210216
yield* logInfo("startup recovery action", { action });
211217
const current = yield* offer;
212218
switch (action) {
219+
case "windows": {
220+
const failure = yield* Ref.get(failureRef);
221+
if (Option.isSome(failure) && failure.value.useWindows) yield* failure.value.useWindows;
222+
return;
223+
}
213224
case "update": {
214225
if (current._tag !== "Update") return;
215226
const state = yield* updates.getState;

‎apps/desktop/src/app/DesktopState.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@ import type { BackendStartupFailure } from "../backend/DesktopBackendManager.ts"
1010
export type PrimaryBackendStartup =
1111
| { readonly _tag: "Starting" }
1212
| { readonly _tag: "Ready" }
13-
| ({ readonly _tag: "Failing" } & BackendStartupFailure);
13+
| ({ readonly _tag: "Failing" } & PrimaryBackendFailure);
14+
15+
export interface PrimaryBackendFailure extends BackendStartupFailure {
16+
/** Offered while a WSL-only primary is up but unreachable: switch to Windows for this launch. */
17+
readonly useWindows?: Effect.Effect<void>;
18+
}
1419

1520
export class DesktopState extends Context.Service<
1621
DesktopState,

‎apps/desktop/src/backend/DesktopBackendPool.test.ts‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ describe("DesktopBackendPool", () => {
568568
}),
569569
);
570570

571-
it.effect("keeps a live WSL primary that misses readiness on the recovery path", () =>
571+
it.effect("offers Windows from recovery when a live WSL primary misses readiness", () =>
572572
Effect.gen(function* () {
573573
const spawned = yield* Queue.unbounded<string>();
574574
const errors = yield* Ref.make<ReadonlyArray<string>>([]);
@@ -593,10 +593,15 @@ describe("DesktopBackendPool", () => {
593593
const startup = yield* SubscriptionRef.get(
594594
(yield* DesktopState.DesktopState).primaryBackendStartup,
595595
);
596-
assert.equal(startup._tag, "Failing");
597596
assert.deepEqual(yield* Queue.takeAll(spawned), ["wsl.exe"]);
598-
assert.deepEqual(yield* Ref.get(errors), []);
599597
assert.isTrue((yield* (yield* DesktopAppSettings.DesktopAppSettings).get).wslOnly);
598+
assert.isTrue(startup._tag === "Failing" && startup.useWindows !== undefined);
599+
600+
// Chosen from the recovery window: the live WSL server is replaced by Windows.
601+
if (startup._tag === "Failing" && startup.useWindows) yield* startup.useWindows;
602+
assert.equal(yield* Queue.take(spawned), "/electron");
603+
assert.isFalse((yield* (yield* DesktopAppSettings.DesktopAppSettings).get).wslOnly);
604+
assert.deepEqual(yield* Ref.get(errors), []);
600605
}).pipe(Effect.provide(layer));
601606
}),
602607
);

‎apps/desktop/src/backend/DesktopBackendPool.ts‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,11 +218,23 @@ export const layer = Layer.effect(
218218
function* (failure: DesktopBackendManager.BackendStartupFailure) {
219219
const config = yield* primary.currentConfig;
220220
const runningOnWsl = Option.exists(config, (value) => value.runningDistro !== undefined);
221-
// A live server that missed readiness may still be booting; only a crash loop falls back.
222-
const stillRunning = Option.isSome((yield* primary.snapshot).activePid);
223-
if (!runningOnWsl || stillRunning || !(yield* appSettings.get).wslOnly) {
221+
if (!runningOnWsl || !(yield* appSettings.get).wslOnly) {
224222
return yield* SubscriptionRef.set(primaryBackendStartup, { _tag: "Failing", ...failure });
225223
}
224+
// A live server that missed readiness may still be booting: keep probing, and let
225+
// the recovery window offer Windows. Forked into the pool scope because stop closes this run.
226+
if (Option.isSome((yield* primary.snapshot).activePid)) {
227+
return yield* SubscriptionRef.set(primaryBackendStartup, {
228+
_tag: "Failing",
229+
...failure,
230+
useWindows: appSettings.applyWslWindowsFallbackInMemory.pipe(
231+
Effect.andThen(
232+
Effect.forkIn(primary.stop().pipe(Effect.andThen(primary.start)), layerScope),
233+
),
234+
Effect.asVoid,
235+
),
236+
});
237+
}
226238
yield* logBackendPoolWarning(
227239
"primary WSL backend failed to start; using Windows for this launch",
228240
{ reason: failure.reason },

0 commit comments

Comments
 (0)