Skip to content

[Bug]: Reopening Settings → Access keeps an outdated WSL distro list #35296

Closed as not planned

Description

@coygeek

Before submitting

  • I searched existing issues and did not find a duplicate.
  • I included enough detail to reproduce or investigate the problem.

Area

apps/web

Steps to reproduce

Use a checkout of the commit under Version or commit with its lockfile dependencies installed. Save the script below outside the checkout as repro.sh and run env -u NODE_ENV sh /path/to/repro.sh "$PWD" from the checkout root. It creates a private HOME, TMPDIR and T3CODE_HOME under a mktemp directory, installs one temporary test at apps/web/src/state/zz-independent-wsl-remount.test.ts (refusing to overwrite an existing file), runs it from apps/web with vp test run, and removes the test and fixture on exit.

The test imports the exported production desktopWslStateAtom and desktopNetworkAccessStateAtom and replaces only window.desktopBridge (getWslState, getAdvertisedEndpoints, getServerExposureState) with controlled responses, so both atoms run their real loaders and their real Effect Atom.swr/Atom.keepAlive composition in a fresh AtomRegistry. It mocks Date.now to control snapshot freshness. It does not install or remove real distros, and no Windows desktop app runs.

  1. Mount both atoms while the bridge reports one distro, Ubuntu (the default), with no saved distro preference (distro: null, enabled: true). Wait for both loads, then unmount both.
  2. Remount at +29,999 ms, while the snapshots are still fresh. Each atom has still made one bridge call. Unmount both.
  3. Change the bridge's WSL response to represent one change made outside T3 Code: Debian installed, Ubuntu unregistered, or Debian made the default. The saved distro preference stays unchanged. Change the network bridge response to a new endpoint as a control.
  4. Remount both atoms at +30,000 ms, when both snapshots are stale, wait for the network atom's second bridge read, and read both atoms.
  5. Call registry.refresh(desktopWslStateAtom) and read the WSL atom again.

Each of the three changes runs twice, once with registry.mount and once with registry.subscribe, the mechanism useAtomValue uses, for six cases. The script exits 0 only when, in every case, the WSL atom still returns the original Ubuntu-only snapshot with one bridge call after the stale remount, the network-access control makes its second call and returns the new endpoint, and the explicit WSL refresh makes the second call and returns the changed list. The assertions describe the current behavior.

The corresponding app sequence, traced from source and not run on Windows: with the local backend enabled and WSL available, open Settings → Access so the WSL backend row loads the distro list; close Settings and the command palette (Settings search and the palette also read this atom); install or import a distro, unregister one, or change the default distro outside T3 Code; wait more than 30 seconds; reopen Settings → Access and open the WSL backend picker. Starting or stopping a distro alone does not change this state, because it does not record whether a distro is running.

Reproduction script: repro.sh
#!/bin/sh
set -eu
checkout="${1:-$PWD}"
checkout=$(cd "$checkout" && pwd)
tmp=$(mktemp -d)
test_file="$checkout/apps/web/src/state/zz-independent-wsl-remount.test.ts"
if [ -e "$test_file" ]; then echo "Refusing to replace existing test" >&2; exit 1; fi
cleanup() { rm -f "$test_file"; rm -rf "$tmp"; }
trap cleanup EXIT HUP INT TERM
mkdir -p "$tmp/fixture-home" "$tmp/tmp" "$tmp/t3home"
export HOME="$tmp/fixture-home" TMPDIR="$tmp/tmp" T3CODE_HOME="$tmp/t3home"
export PATH="$checkout/node_modules/.bin:$PATH"
cat > "$tmp/fixture.test.ts" <<'TS'
import { it } from "@effect/vitest";
import type { DesktopWslState, DesktopServerExposureState, AdvertisedEndpoint } from "@t3tools/contracts";
import * as Effect from "effect/Effect";
import * as Option from "effect/Option";
import * as AsyncResult from "effect/reactivity/AsyncResult";
import { AtomRegistry } from "effect/reactivity";
import { expect, vi } from "vite-plus/test";
import { desktopWslStateAtom } from "./desktopWslState";
import { desktopNetworkAccessStateAtom } from "./desktopNetworkAccess";

const exposure: DesktopServerExposureState = {
  advertisedHost: "lan-host.example", endpointUrl: "http://lan-host.example:37737",
  mode: "network-accessible", tailscaleServeEnabled: false, tailscaleServePort: 443,
};
const endpoint: AdvertisedEndpoint = {
  id: "tailscale-ip:tailnet-host", httpBaseUrl: "http://tailnet-host.example:37737/",
  wsBaseUrl: "ws://tailnet-host.example:37737/", label: "Tailscale IP",
  provider: { id: "tailscale", kind: "private-network", label: "Tailscale", isAddon: true },
  reachability: "private-network", status: "available", source: "desktop-addon",
  compatibility: { hostedHttpsApp: "mixed-content-blocked", desktopApp: "compatible" },
};
const before: DesktopWslState = {
  enabled: true, distro: null, available: true, wslOnly: false,
  distros: [{ name: "Ubuntu", isDefault: true, version: 2 }], preflightError: null,
};
const log = (line: string) => process.stdout.write(line + "\n");
const changes: Array<{ change: string; after: DesktopWslState }> = [
  { change: "install", after: { ...before, distros: [...before.distros, { name: "Debian", isDefault: false, version: 2 }] } },
  { change: "remove", after: { ...before, distros: [] } },
  { change: "default", after: { ...before, distros: [{ name: "Ubuntu", isDefault: false, version: 2 }, { name: "Debian", isDefault: true, version: 2 }] } },
];
for (const mode of ["mount", "subscribe"] as const) {
  it.effect.each(changes)(`${mode}: stale WSL $change beside network control`, ({ change, after }) =>
    Effect.gen(function* () {
      const now = vi.spyOn(Date, "now").mockReturnValue(1_000_000);
      const getWslState = vi.fn(async () => before);
      const getAdvertisedEndpoints = vi.fn(async (): Promise<ReadonlyArray<AdvertisedEndpoint>> => []);
      vi.stubGlobal("window", { desktopBridge: {
        getWslState, getAdvertisedEndpoints, getServerExposureState: async () => exposure,
      } });
      const registry = AtomRegistry.make();
      const mountWsl = () => mode === "mount" ? registry.mount(desktopWslStateAtom) : registry.subscribe(desktopWslStateAtom, () => {});
      const mountNetwork = () => mode === "mount" ? registry.mount(desktopNetworkAccessStateAtom) : registry.subscribe(desktopNetworkAccessStateAtom, () => {});
      let unmountWsl = mountWsl();
      let unmountNetwork = mountNetwork();
      try {
        yield* AtomRegistry.getResult(registry, desktopWslStateAtom, { suspendOnWaiting: true });
        yield* AtomRegistry.getResult(registry, desktopNetworkAccessStateAtom, { suspendOnWaiting: true });
        unmountWsl(); unmountNetwork();
        yield* Effect.yieldNow;
        now.mockReturnValue(1_029_999);
        unmountWsl = mountWsl(); unmountNetwork = mountNetwork();
        registry.get(desktopWslStateAtom); registry.get(desktopNetworkAccessStateAtom);
        expect(getWslState).toHaveBeenCalledTimes(1);
        expect(getAdvertisedEndpoints).toHaveBeenCalledTimes(1);
        unmountWsl(); unmountNetwork();
        yield* Effect.yieldNow;
        getWslState.mockResolvedValue(after);
        let markRefreshStarted!: () => void;
        const refreshStarted = new Promise<void>((resolve) => { markRefreshStarted = resolve; });
        getAdvertisedEndpoints.mockImplementation(async () => { markRefreshStarted(); return [endpoint]; });
        now.mockReturnValue(1_030_000);
        // Same lifecycle and deferred bridge-read milestone as PR #16026's test.
        unmountWsl = mountWsl(); unmountNetwork = mountNetwork();
        registry.get(desktopWslStateAtom); registry.get(desktopNetworkAccessStateAtom);
        yield* Effect.promise(() => refreshStarted);
        const network = yield* AtomRegistry.getResult(registry, desktopNetworkAccessStateAtom, { suspendOnWaiting: true });
        const wsl = Option.getOrThrow(AsyncResult.value(registry.get(desktopWslStateAtom)));
        log(`REPRO mode=${mode} change=${change} wsl_calls=${getWslState.mock.calls.length} retained=${JSON.stringify(wsl.distros)} bridge_now=${JSON.stringify(after.distros)}`);
        log(`CONTROL mode=${mode} change=${change} network_calls=${getAdvertisedEndpoints.mock.calls.length} endpoints=${JSON.stringify(network.advertisedEndpoints.map(x => x.id))}`);
        expect(wsl).toEqual(before);
        expect(getWslState).toHaveBeenCalledTimes(1);
        expect(network.advertisedEndpoints).toEqual([endpoint]);
        expect(getAdvertisedEndpoints).toHaveBeenCalledTimes(2);
        registry.refresh(desktopWslStateAtom);
        const refreshedWsl = yield* AtomRegistry.getResult(registry, desktopWslStateAtom, { suspendOnWaiting: true });
        expect(refreshedWsl).toEqual(after);
        expect(getWslState).toHaveBeenCalledTimes(2);
        log(`RECOVERY mode=${mode} change=${change} wsl_calls=2 current=${JSON.stringify(refreshedWsl.distros)}`);
      } finally {
        unmountWsl(); unmountNetwork(); registry.dispose(); now.mockRestore(); vi.unstubAllGlobals();
      }
    }),
  );
}
TS
cp "$tmp/fixture.test.ts" "$test_file"
cd "$checkout/apps/web"
env -u NODE_ENV vp test run src/state/zz-independent-wsl-remount.test.ts
printf '%s\n' 'DEFECT PRESENT: WSL retains stale state; network control revalidates; explicit WSL refresh recovers.'

Expected behavior

The WSL atom declares staleTime: 30_000 and revalidateOnMount: true (desktopWslState.ts). When Settings → Access mounts it again after the snapshot is older than 30 seconds, it should keep showing the retained list while it re-reads the distros through the desktop bridge, then show the current list. The network-access atom in the same view states and implements this policy: "Retain the snapshot, but let the SWR wrapper revalidate when Settings remounts." (desktopNetworkAccess.ts). In the reproduction, the WSL atom should behave like the network control: a second bridge call at +30,000 ms that returns the changed list. On Windows, a distro installed, unregistered or made default outside T3 Code should then be reflected in the WSL backend picker when Access is reopened.

Actual behavior

Summary. On the Windows desktop app, the WSL backend picker in Settings → Access keeps showing the distro list it first loaded, even after Settings is closed and reopened more than 30 seconds later. The WSL state atom is configured to revalidate a stale snapshot when it is mounted again, but it does not: after the first read it makes no further desktop bridge call until something refreshes it explicitly. A distro installed or imported outside T3 Code can therefore be missing from the picker (and so cannot be selected), an unregistered distro can stay listed, and the "(default)" marker and the selected label can name the old default distro, until the renderer reloads or a WSL setting is changed. The desktop network-access atom in the same Settings view had the same Atom.keepAlive/Atom.swr order and was fixed by #16026 for #15751; the WSL atom predates that fix and neither the PR nor the issue mentions it, so this is a sibling of #16026, not a regression from it. Only Windows desktop users who change their WSL distros outside the app during a running session are affected.

In all six cases, the WSL atom makes no bridge call on the stale remount: it stays at one call and returns the original Ubuntu-only list, while the bridge now reports the changed list. The network-access control makes its second call and returns the new endpoint. An explicit refresh of the WSL atom makes the second call and returns the current list. A rerun of the script above on the tested commit passed all six cases with these results.

The Access view reads this atom through useEnvironmentQuery (caller), and the WSL backend picker derives its options, the "(default)" marker and the selected label from the retained snapshot (picker). From source, a newly installed distro is therefore absent and cannot be selected, an unregistered distro stays listed, and with no saved distro the label and marker keep naming the old default. These UI consequences follow from the observed atom values and were not observed in a running Windows app; the report makes no claim about which distro the running backend uses.

Nothing else refreshes a successfully loaded list. Changing a WSL setting in Settings refreshes the atom after the change succeeds or fails, and a Retry button appears only when the initial load failed and there is no data (refresh paths). The Retry button is defined here. There is no refresh button for a loaded list, no polling, no push invalidation from the desktop bridge and no refresh when Access opens. The command palette's folder picker reads WSL state directly but does not update this atom. The desktop bridge enumerates distros on every read (IPC handler), so a re-read would return the current list.

The WSL atom applies Atom.keepAlive after Atom.swr, while the fixed network-access atom applies it before. A plausible cause, not established here, is that keeping the SWR wrapper itself alive means it is never mounted again, so its mount-time stale check never runs. The desktop SSH hosts atom (desktopSshHosts.ts) uses the same order, but AddEnvironmentDialog.tsx refreshes it each time the SSH tab opens (refresh on open), so stale SSH suggestions can show briefly but are corrected; it is not part of this report.

Evidence

  • Expected source: the staleTime/revalidateOnMount configuration in apps/web/src/state/desktopWslState.ts lines 46-53, the remount policy comment and composition in apps/web/src/state/desktopNetworkAccess.ts lines 82-90, and the passing network-access control in the reproduction.
  • Failure source: the observed reproduction output under Logs or stack traces (wsl_calls=1 with the original list after the stale remount), and the Atom.swr(...) then Atom.keepAlive order at apps/web/src/state/desktopWslState.ts lines 47-51.
  • Evidence provenance: observed
  • Local verification: reproduced
  • Reproduction completeness: complete

The run exercises the production atoms with controlled desktop bridge responses. The Windows/Electron UI, real distro installation, removal and default changes, and the reload workaround were traced from source and not run.

Restoration check

With the script's input, the stale remount at +30,000 ms makes a second WSL bridge call and returns the changed list in all six cases (Debian present, Ubuntu absent, or Debian marked default), matching the network-access control. As controls, the fresh remount at +29,999 ms still makes no new call, and the retained snapshot stays readable while the re-read runs. The script asserts the current failing values, so its WSL expectations after the stale remount (original snapshot, one call) need updating to the restored values for this check.

References

Impact

Minor bug or occasional failure

Version or commit

0.1.9 at d9805b2, rerun with the script above from a clean checkout for this report; an earlier version of the same script, differing only in fixture host values and directory names, also passed on upstream main at e9e934b using the tested commit's installed dependency tree rather than a fresh install; on main at 156dcd8 desktopWslState.ts and desktopNetworkAccess.ts are byte-identical to the tested commit by source comparison

Environment

Affected: Windows desktop app with the local backend enabled and WSL available (not run). Test harness: Darwin arm64, Node v26.12.1, Effect 4.1.2, repository-pinned Vite+ 1.4.0 and Vitest 5.0.5; production web atoms with controlled desktop bridge responses, with no server, browser, desktop app or real WSL

Logs or stack traces

The script's output, keeping only the first case's result lines, the test summary and the final line; the other five cases print the same split:

REPRO mode=mount change=install wsl_calls=1 retained=[{"name":"Ubuntu","isDefault":true,"version":2}] bridge_now=[{"name":"Ubuntu","isDefault":true,"version":2},{"name":"Debian","isDefault":false,"version":2}]
CONTROL mode=mount change=install network_calls=2 endpoints=["tailscale-ip:tailnet-host"]
RECOVERY mode=mount change=install wsl_calls=2 current=[{"name":"Ubuntu","isDefault":true,"version":2},{"name":"Debian","isDefault":false,"version":2}]
REPRO mode=subscribe change=remove wsl_calls=1 retained=[{"name":"Ubuntu","isDefault":true,"version":2}] bridge_now=[]
REPRO mode=subscribe change=default wsl_calls=1 retained=[{"name":"Ubuntu","isDefault":true,"version":2}] bridge_now=[{"name":"Ubuntu","isDefault":false,"version":2},{"name":"Debian","isDefault":true,"version":2}]
Test Files  1 passed (1)
Tests  6 passed (6)
DEFECT PRESENT: WSL retains stale state; network control revalidates; explicit WSL refresh recovers.

Screenshots, recordings, or supporting files

No response

Workaround

Reload the window with View → Reload (Ctrl+R), which recreates renderer state and re-reads the distro list. Alternatively, change a WSL setting in Settings → Access; the list is refreshed after the change completes, but this also changes the backend configuration. The reproduction verifies that an explicit re-read returns the current list; the menu reload and the settings refresh call were traced from source.

Activity

  1. juliusmarminge commented on Nov 12, 2026

    @juliusmarminge
    Member

    I tried to reproduce this on the current build and could not.

    Not run in the real app: the bug needs the Windows desktop app with WSL distros, and the Linux VM has neither Windows nor WSL. Confirmed instead with a failing unit test against the production atom on origin/main fd8e386. New file apps/web/src/state/desktopWslState.test.ts: stub window.desktopBridge.getWslState, mount desktopWslStateAtom in an AtomRegistry whose scheduleTask queues tasks and drains them on demand, load the Ubuntu-only list, unmount, make the bridge return Ubuntu plus Debian, move Date.now to +30,000 ms (stale), remount and drain the scheduled tasks. On main, vp test run src/state/desktopWslState.test.ts (from apps/web) fails fast with expected false to be true on AsyncResult.isWaiting: no revalidation started, the bridge was called once, and the atom keeps the old list. With Atom.keepAlive moved before Atom.swr (the order desktopNetworkAccess.ts got in #16026; not committed) the same test passes: the second bridge call returns the Debian list. The test is pushed as factory/repro-35296.

    Closing as not planned. If it still happens for you, reply with the exact steps and the version you are on and it will be looked at again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions