fix: review feedback from PR #2751

Four review comments addressed in one pass:

- Park the local-secondary auto-retry loop in wsl-only mode too. WSL
  is the primary there and the desktop never registers a wsl:<distro>
  secondary, so the loop would otherwise poll forever for something
  that can't appear. Initial probe and the post-toggle latch both
  treat enabled+wslOnly as "no secondaries".

- Key the backend output log cache by the resolved file path, not the
  raw instance id. Two ids that sanitize to the same filename (e.g.
  `wsl:default` and `wsl_default`) would otherwise produce two
  RotatingLogFileWriters racing on the same file.

- Fork registered instance scopes off the pool's layer scope instead
  of leaving them as orphan `Scope.make` handles. On app shutdown the
  pool's scope closes, which now also closes the WSL instance scope
  and runs the BackendInstance stop finalizer (graceful SIGTERM +
  grace period) rather than letting the OS hard-kill the child.

- Refresh the stale Sidebar comment that claimed we render a
  container icon on desktop-local threads. The project-level header
  already carries that icon (sidebarProjectGrouping); the thread row
  only suppresses the cloud icon now.
This commit is contained in:
Josh Gratton committed 2026-05-18 12:19:07 -04:00
1 parent aebb4fa3e5
commit c3374a85ca
5 files changed
+37 -11

No files matched your search

+8 -2
View File
@@ -399,7 +399,13 @@ const backendOutputLogFactoryLayer = Layer.effect(
const makeForId = (id: string): Effect.Effect<DesktopBackendOutputLogShape> =>
SynchronizedRef.modifyEffect(cacheRef, (cache) => {
const cached = cache.get(id);
// Key the cache by the resolved file path, not the raw id.
// Otherwise two ids that sanitize to the same filename (e.g.
// `wsl:default` and `wsl_default`) would each create their
// own RotatingLogFileWriter pointing at the same file, with
// independent currentSize tracking and a race on writes.
const cacheKey = backendLogFilePathForInstance(environment, id);
const cached = cache.get(cacheKey);
if (cached !== undefined) return Effect.succeed([cached, cache] as const);
return makeBackendOutputLogForInstance(environment, id).pipe(
Effect.provideService(FileSystem.FileSystem, fileSystem),
@@ -407,7 +413,7 @@ const backendOutputLogFactoryLayer = Layer.effect(
Scope.provide(factoryScope),
Effect.map((shape) => {
const next = new Map(cache);
next.set(id, shape);
next.set(cacheKey, shape);
return [shape, next as ReadonlyMap<string, DesktopBackendOutputLogShape>] as const;
}),
);
+12 -1
View File
@@ -187,6 +187,14 @@ export const layer = Layer.effect(
const configuration = yield* DesktopBackendConfiguration.DesktopBackendConfiguration;
const desktopWindow = yield* DesktopWindow.DesktopWindow;
const settings = yield* DesktopAppSettings.DesktopAppSettings;
// Anchor the pool's lifetime to its layer scope so registered
// instance scopes can be forked off it. Without this, instance
// scopes are orphaned: they only close via explicit unregister()
// calls, so on app shutdown the WSL backend child process gets
// hard-killed by the OS instead of receiving the graceful
// SIGTERM + grace period the instance's stop finalizer would
// otherwise run.
const layerScope = yield* Scope.Scope;
// Capture the services needed to build any future instance from the
// pool's layer scope. register() runs `makeBackendInstance` against
// a fresh child scope but reuses these services so the instance gets
@@ -235,7 +243,10 @@ export const layer = Layer.effect(
return Effect.fail(new DesktopBackendPoolInstanceAlreadyRegisteredError({ id: spec.id }));
}
return Effect.gen(function* () {
const instanceScope = yield* Scope.make("sequential");
// Forked from the pool's layer scope so the registered
// instance auto-stops on layer teardown. unregister() still
// closes the scope eagerly when invoked.
const instanceScope = yield* Scope.fork(layerScope, "sequential");
const instance = yield* DesktopBackendManager.makeBackendInstance(spec).pipe(
Scope.provide(instanceScope),
Effect.provide(factoryContext),
+3 -1
View File
@@ -364,7 +364,9 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
// desktopLocal entries (e.g. the WSL backend) live in the
// saved-environment registry alongside true remote envs, but they
// run on the user's own machine. The cloud icon is misleading for
// them, so we render a container icon instead.
// them. The project header already shows a container icon for
// desktopLocal-only projects (see sidebarProjectGrouping), so for
// threads we just suppress the cloud icon instead of doubling up.
const isDesktopLocalThread = useSavedEnvironmentRegistryStore((s) =>
Boolean(s.byId[thread.environmentId]?.desktopLocal),
);
@@ -2392,11 +2392,15 @@ export function ConnectionsSettings() {
try {
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);
// Keep the renderer's auto-retry loop awake while the user is
// running both backends, and let it park otherwise. wsl-only
// mode counts as "no secondaries": the desktop pool routes
// wsl through the primary slot and doesn't register a
// separate wsl: instance (DesktopWslBackend.reconcile gates
// on `!wslOnly`). Without this the loop would never resume
// after a fresh desktop install where the initial probe
// latched "no WSL configured".
markSecondariesConfigured(next.enabled && !next.wslOnly);
// 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
+5 -2
View File
@@ -484,11 +484,14 @@ export function markSecondariesConfigured(configured: boolean): void {
if (typeof window !== "undefined") {
// Best-effort: any failure (no bridge, IPC error, missing field)
// keeps the default "stay polling" behavior intact.
// keeps the default "stay polling" behavior intact. wsl-only mode
// also counts as "no secondaries": the desktop pool runs WSL as
// primary and skips the wsl:<distro> secondary registration, so
// the auto-retry loop has nothing to wait for.
void (async () => {
try {
const state = await window.desktopBridge?.getWslState();
if (state && !state.enabled) {
if (state && (!state.enabled || state.wslOnly)) {
knownNoSecondariesConfigured = true;
}
} catch {