Lays the groundwork for the WSL second-instance orchestrator. Pool now
exposes:
- register(spec): builds a DesktopBackendInstance via the factory under
a fresh child Scope owned by the pool, adds it to the registry, and
returns the instance unstarted so the caller decides when to start.
- unregister(id): atomically removes the entry from the registry and
closes the child scope, which runs the instance's auto-stop finalizer.
Each registered instance lives under its own Scope so a single unregister
stops just that instance without disturbing the rest of the pool. The
primary instance keeps its place in the pool's own layer scope and is
guarded by a DesktopBackendPoolCannotUnregisterPrimaryError; that case
is treated as a wiring bug rather than something callers handle.
The instances Ref upgrades to a SynchronizedRef so register and
unregister can run as serialized modify-effects without racing each
other on the underlying Map. Duplicate registration on the same id
fails with a typed DesktopBackendPoolInstanceAlreadyRegisteredError.
No caller registers a second instance yet — that arrives in the next
commit when the WSL orchestrator goes in.
Backend child output and session boundaries used to land in one shared
server-child.log via the DesktopBackendOutputLog singleton. With a
second backend instance on the way, intermixing two processes' stdout
streams into one file makes triage harder than it needs to be.
Replace the singleton with DesktopBackendOutputLogFactory.forInstance(id)
that vends a rotating writer per backend id. The primary keeps the
historical server-child.log path so existing ops tooling, packaged-build
log inspection, and habit don't break; non-primary instances land in
server-child-<sanitized-id>.log. A SynchronizedRef-backed cache keyed by
id ensures repeated forInstance lookups on the same id reuse the writer
(important under restart loops that re-resolve the factory).
Each emitted record now carries an instanceId annotation so cross-file
greps can still associate records belonging to the same backend even if
log paths drift later. The redundant "instance=<id>" prefix on session
boundary details is dropped — that info now lives in the structured
annotation and in the file path.
DesktopBackendManager pulls its writer from the factory at instance
construction time so each instance carries a fixed writer for its
lifetime. DesktopBackendManager.test.ts stubs the factory directly;
DesktopObservability.test.ts asserts the new instanceId annotation.
DesktopState.backendReady was the last global coupling tying backend
lifecycle to app-wide state. With the pool owning per-instance
readiness (instance.snapshot.ready), the only remaining consumer of the
global latch is the window's auto-create-on-ready path. Move ownership
of the latch into DesktopWindow's own internals so DesktopState only
carries truly app-wide state (the quitting flag).
DesktopWindow gains handleBackendNotReady, called by the primary
instance's onShutdown callback so the latch clears on clean stop,
restart, or crash. Without it the macOS dock-click activation path could
produce a window pointing at a backend that is no longer up. The pool
spec wires both callbacks against the window service instead of the
state Ref.
Test stubs for DesktopWindowShape pick up the new handleBackendNotReady
field; DesktopWindow.test.ts drops its DesktopState dependency.
Replace the singleton DesktopBackendManager Context.Service with a
factory function makeBackendInstance(spec) that returns one
DesktopBackendInstance per call. Each instance owns its own state Ref,
mutex, restart fiber, and active child process so no state is shared
across pool members.
The pool layer calls the factory once for the Windows primary at
startup, wiring the spec's configResolve to DesktopBackendConfiguration
and the onReady/onShutdown callbacks to the legacy global side effects
(DesktopState.backendReady, DesktopWindow.handleBackendReady). Those
last couplings move per-instance in steps 2 and 3.
All five consumers (DesktopApp bootstrap + shutdown, wsl.ts swap IPC,
window.ts bootstrap IPC, DesktopUpdates installer) now read the primary
instance via pool.primary instead of the deleted manager service. Log
session boundaries are prefixed with the instance id so per-backend
output stays distinguishable until step 3 splits the output log.
DesktopBackendManager.test.ts rewritten to use the factory directly
under Effect.scoped. DesktopUpdates.test.ts swaps its backend stub from
a Layer.succeed(DesktopBackendManager, ...) to
DesktopBackendPool.layerTest([stub]).
Phase-1 foundation for running Windows and WSL backends side by side.
Introduces:
* BackendInstanceId brand + PRIMARY_INSTANCE_ID constant
* DesktopBackendInstance interface mirroring the legacy backend manager
surface so consumers can migrate one call site at a time
* DesktopBackendPool service with get/list/primary operations
* Phase-1 layer that wraps the existing singleton DesktopBackendManager
and exposes it under PRIMARY_INSTANCE_ID, no behavior change
* layerTest helper for unit tests
The pool is wired into the desktop application layer alongside the
existing manager; current consumers (window/wsl IPC, lifecycle hooks,
telemetry) still depend on DesktopBackendManager directly. The header
docblock on DesktopBackendPool.ts captures the full migration sequence
for follow-up commits: reshape the manager into an instance factory,
move per-instance state off DesktopState/DesktopBackendOutputLog, wire
WSL as a second pooled instance, widen the bootstrap IPC, and retire
the swap-mode dialog.
onWelcome subscribes with `immediate: true`, so the listener fires
synchronously with whatever welcome payload is already in the atom. The
previous code compared against `previousPrimaryEnvId` (descriptor-derived);
if the descriptor hadn't loaded yet, that was null and any non-null current
welcome would resolve the promise instantly, completing the "syncing" stage
before the new backend's welcome actually arrived. Capture the current
welcome's env-id from the atom as the baseline instead so the immediate
fire never matches the "new welcome arrived" predicate.
- remove the unused `enabled` field from WslConfig and the unreferenced
DEFAULT_WSL_CONFIG export; the toggle moved to DesktopAppSettings.wslMode
during the migration and the field was carried along by every caller as
noise that didn't influence behavior
- wrap the entire backend-swap flow (success + catch) in suppressReconnect
so the catch-block reauth doesn't fire reconnect/offline toasts on top of
the error toast the user is reading. The previous structure only
suppressed during the happy path; recovery work landed outside the window
The renderer's 180s ceiling was shorter than the IPC's worst-case duration:
setWslBackend can take up to ~2min for the initial readiness wait plus
another ~2min for the rollback readiness wait before throwing
WslBackendSwapError, so the client was firing "Backend swap took too long"
while the main process was still actively rolling back. Bump the ceiling
to 6 minutes (4min IPC worst case + ~60s reauth retry budget + 45s welcome
race) so a real hang still surfaces but a legitimate rollback completes.
The dropdown maps state.distro: null to the actual default distro's name
so the Select highlights a real option, but the no-op check still compared
target.distro (e.g. "Ubuntu") against state.distro (null). Re-picking the
visually-active row opened the confirmation dialog and triggered a full
backend restart for what was clearly a no-op. Resolve both sides through
the same null->default mapping before comparing.
- swap "__local__" / "__default__" select values for "backend:local" /
"backend:default-wsl" — the colon is rejected by DISTRO_NAME_PATTERN so
the sentinels can never collide with an actual WSL distro name
- remove VITE_DEV_SERVER_URL from WSL_FORWARDED_ENV_NAMES; the value is
delivered exclusively via the --dev-url CLI flag because WSLENV translation
of URL-shaped values is unreliable, and keeping it in both paths
contradicted the comment at the CLI-flag site
- map null distro to the actual default distro name in the backend select
so the dropdown highlights a real option instead of an orphan "__default__"
with no matching item when distros are listed
- add getUserHome to DesktopWslEnvironment (cached per distro) and pass the
resolved /home/<user> into the picker helper so ~/path expands correctly
instead of producing /home/<rest>
- surface a clearer error when the rollback backend also fails to start, so
the user knows the app is degraded rather than seeing the misleading
"Rolled back to the previous mode" message
- move clearTimeout(flowTimeoutHandle) into the finally block so it fires
on success, error, and timeout — previously the error path left a live
180s timer that would reject an unreferenced promise (unhandled rejection)
- remove the second removeEnvironmentState call after welcome; the first
call right after the IPC swap already wipes the old environment state
and nothing recreates state under the old env id during reauth/welcome
- drain stdout/stderr concurrently in runWslShell so node-gyp output
on both pipes can't deadlock the child
- short-circuit waitForReady when desiredRunning flips off, so an
external stop() during swap doesn't waste the full timeout
- guard runSwap continuations after the 180s flow timeout so an
orphaned IPC resolution can't overwrite rolled-back UI state
- drop unused refreshPrimaryEnvironmentDescriptor — descriptor URL is
stable across the swap and consumers re-fetch lazily
Lets the desktop app launch the local backend inside a WSL distro
instead of natively on Windows. Adds:
- Backend plumbing (apps/desktop/src/wsl): pure path parsing
utilities, a DesktopWslEnvironment Effect service wrapping
wsl.exe operations (listDistros, preWarm, windowsToWslPath,
ensureNodePty, isAvailable), and an explicit preflight that
checks for missing node / build tools before spawning so the
failure message names the actual problem.
- Spawn path: DesktopBackendConfiguration branches on the new
wslMode setting and assembles "wsl.exe -d <distro> -- node
<linux-entry> --bootstrap-fd 0" with the bootstrap envelope on
stdin (wsl.exe drops additional file descriptors). Sensitive env
vars forward via WSLENV; --dev-url is passed as a CLI flag so the
WSL dev backend lands in dev/ instead of userdata/ deterministi-
cally. The Windows-side T3CODE_HOME is scrubbed and extendEnv is
disabled for WSL so the WSL backend cannot accidentally share a
baseDir with the local backend via /mnt/c/...
- Settings: wslMode + wslDistro on DesktopAppSettings, with
validation that drops distro names containing control or shell
meta characters. Contracts get DesktopWslMode / DesktopWslDistro
/ DesktopWslState schemas.
- IPC: getWslState and setWslBackend on the desktop bridge. The
setter pre-warms the WSL VM, persists settings, then drives an
in-process backend stop + start with a 2-minute readiness wait
and a rollback path that reverts to the previous mode if the new
backend never reports ready. pickFolder defaults to the WSL home
UNC path when wslMode is "wsl".
- Web UI: backend-runtime selector in Connection Settings with a
three-stage swap modal (restarting / re-establishing session /
syncing) that suppresses the WS reconnect toast for the duration
of the swap, waits for the new backend's welcome event before
closing, and clears the previous env's store state so the side-
bar does not render stale threads. New suppressReconnect helper
on the connection-status atom plus exports for the descriptor
refresh and reauth used by the swap flow.
Stdin pipes inherited across the wsl.exe boundary fail to re-open
via /proc/self/fd/0, so add EACCES to the codes that drop back to
reading the fd directly. Without this the WSL desktop backend
fails to load its bootstrap envelope with "Failed to duplicate
bootstrap fd" and ends up in a scheduled-restart loop.
- Restrict release workflow defaults to read-only access
- Grant `id-token` only to the publish job
- Document safe handling for `pull_request_target` in PR size checks