Skip to content

Commit 047ee10

Browse files
fix(desktop): a live WSL backend that misses readiness stays on recovery
Only a WSL-only crash loop falls back to Windows. A server that is still running past the readiness window may be booting slowly, so it keeps main's recovery path instead of being stopped and replaced. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 1f54887 commit 047ee10

2 files changed

Lines changed: 12 additions & 11 deletions

File tree

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

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

571-
it.effect("replaces a live WSL primary that never becomes ready with Windows", () =>
571+
it.effect("keeps a live WSL primary that misses readiness on the recovery path", () =>
572572
Effect.gen(function* () {
573573
const spawned = yield* Queue.unbounded<string>();
574574
const errors = yield* Ref.make<ReadonlyArray<string>>([]);
@@ -590,10 +590,13 @@ describe("DesktopBackendPool", () => {
590590
// Past the manager's default readiness timeout.
591591
yield* TestClock.adjust(Duration.minutes(3));
592592

593-
assert.equal(yield* Queue.take(spawned), "wsl.exe");
594-
assert.equal(yield* Queue.take(spawned), "/electron");
595-
assert.deepEqual(yield* Ref.get(errors), ["WSL backend is still unavailable"]);
596-
assert.isFalse((yield* (yield* DesktopAppSettings.DesktopAppSettings).get).wslOnly);
593+
const startup = yield* SubscriptionRef.get(
594+
(yield* DesktopState.DesktopState).primaryBackendStartup,
595+
);
596+
assert.equal(startup._tag, "Failing");
597+
assert.deepEqual(yield* Queue.takeAll(spawned), ["wsl.exe"]);
598+
assert.deepEqual(yield* Ref.get(errors), []);
599+
assert.isTrue((yield* (yield* DesktopAppSettings.DesktopAppSettings).get).wslOnly);
597600
}).pipe(Effect.provide(layer));
598601
}),
599602
);

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -218,19 +218,17 @@ 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-
if (!runningOnWsl || !(yield* appSettings.get).wslOnly) {
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) {
222224
return yield* SubscriptionRef.set(primaryBackendStartup, { _tag: "Failing", ...failure });
223225
}
224226
yield* logBackendPoolWarning(
225227
"primary WSL backend failed to start; using Windows for this launch",
226228
{ reason: failure.reason },
227229
);
230+
// The manager's scheduled restart resolves the primary again and comes up on Windows.
228231
yield* useWindowsForThisLaunch(failure.reason);
229-
// A crash already has a restart scheduled; a live but unreachable server must be replaced.
230-
// Forked into the pool scope because this runs inside the run that stop closes.
231-
if (Option.isSome((yield* primary.snapshot).activePid)) {
232-
yield* Effect.forkIn(primary.stop().pipe(Effect.andThen(primary.start)), layerScope);
233-
}
234232
},
235233
);
236234

0 commit comments

Comments
 (0)