fix(desktop): hide preflight-failed bootstraps + serialize WSL reconcile

Two review-feedback fixes:

- getLocalEnvironmentBootstraps was exposing the bootstrap info (URL,
  token) for backends whose configResolve produced a preflightFailure.
  Those backends never actually listen — the manager calls
  scheduleRestart instead of spawning — so the renderer would pick up
  a phantom URL, POST to /api/auth/bootstrap/bearer, fail, and register
  a broken saved-env. Skip them in the IPC handler.

- wslBackend.reconcile read pool state and settings non-atomically.
  The bootstrap fork + an in-flight setWslDistro IPC could both
  observe "no WSL instance registered", both proceed to startNew with
  different distros, and leave a stranded instance behind. Wrap the
  reconcile body in a single-permit semaphore so concurrent callers
  queue.
This commit is contained in:
Josh Gratton committed 2026-05-18 13:18:55 -04:00
1 parent ce93b7a1c4
commit b62348b0fa
2 files changed
+20 -2

No files matched your search

+7
View File
@@ -62,6 +62,13 @@ export const getLocalEnvironmentBootstraps = makeSyncIpcMethod({
// backend mid-registration, before its first start cycle). They'll
// appear on the next IPC call once they've started.
if (Option.isNone(config)) continue;
// Skip instances whose preflight failed (e.g. WSL distro
// missing node, the linux server entry was never built). The
// backend manager schedules a restart instead of actually
// listening, so exposing the bootstrap would point the renderer
// at a port nothing is bound to and trigger needless
// /api/auth/bootstrap/bearer error cycles.
if (Option.isSome(config.value.preflightFailure)) continue;
const { bootstrap, httpBaseUrl } = config.value;
bootstraps.push({
id: instance.id,
+13 -2
View File
@@ -24,6 +24,7 @@ import * as Context from "effect/Context";
import * as Effect from "effect/Effect";
import * as Layer from "effect/Layer";
import * as Option from "effect/Option";
import * as Semaphore from "effect/Semaphore";
import * as NetService from "@t3tools/shared/Net";
@@ -89,6 +90,12 @@ export const layer = Layer.effect(
const wslEnvironment = yield* DesktopWslEnvironment.DesktopWslEnvironment;
const appSettings = yield* DesktopAppSettings.DesktopAppSettings;
const net = yield* NetService.NetService;
// Serialize reconcile so the bootstrap fork and the IPC handlers
// (setWslBackendEnabled, setWslDistro) can't interleave. Without
// this, two reconciles could both observe "no WSL instance
// registered" between their pool reads and both call startNew
// with different distros, leaving the loser stranded.
const reconcileMutex = yield* Semaphore.make(1);
const findExistingWslInstance = pool.list.pipe(
Effect.map((instances) => instances.find((instance) => isWslInstanceId(instance.id))),
@@ -155,7 +162,7 @@ export const layer = Layer.effect(
});
});
const reconcile = Effect.gen(function* () {
const reconcileBody = Effect.gen(function* () {
const settings = yield* appSettings.get;
const available = yield* wslEnvironment.isAvailable;
const existing = yield* findExistingWslInstance;
@@ -196,7 +203,11 @@ export const layer = Layer.effect(
yield* wslEnvironment.preWarm(settings.wslDistro);
yield* startNew({ distro: settings.wslDistro });
}
}).pipe(Effect.withSpan("desktop.wslBackend.reconcile"));
});
const reconcile = reconcileMutex
.withPermits(1)(reconcileBody)
.pipe(Effect.withSpan("desktop.wslBackend.reconcile"));
return DesktopWslBackend.of({ reconcile });
}),