diff --git a/apps/desktop/src/app/DesktopObservability.ts b/apps/desktop/src/app/DesktopObservability.ts index b6186ec263..340457f01c 100644 --- a/apps/desktop/src/app/DesktopObservability.ts +++ b/apps/desktop/src/app/DesktopObservability.ts @@ -399,7 +399,13 @@ const backendOutputLogFactoryLayer = Layer.effect( const makeForId = (id: string): Effect.Effect => 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] as const; }), ); diff --git a/apps/desktop/src/backend/DesktopBackendPool.ts b/apps/desktop/src/backend/DesktopBackendPool.ts index 7b6d591d18..de581b7258 100644 --- a/apps/desktop/src/backend/DesktopBackendPool.ts +++ b/apps/desktop/src/backend/DesktopBackendPool.ts @@ -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), diff --git a/apps/web/src/components/Sidebar.tsx b/apps/web/src/components/Sidebar.tsx index 909077cc43..3bba0985b5 100644 --- a/apps/web/src/components/Sidebar.tsx +++ b/apps/web/src/components/Sidebar.tsx @@ -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), ); diff --git a/apps/web/src/components/settings/ConnectionsSettings.tsx b/apps/web/src/components/settings/ConnectionsSettings.tsx index 567555ca92..59a03a14bc 100644 --- a/apps/web/src/components/settings/ConnectionsSettings.tsx +++ b/apps/web/src/components/settings/ConnectionsSettings.tsx @@ -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 diff --git a/apps/web/src/environments/local/index.ts b/apps/web/src/environments/local/index.ts index c1edca037b..d7082cab01 100644 --- a/apps/web/src/environments/local/index.ts +++ b/apps/web/src/environments/local/index.ts @@ -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: 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 {