fix(desktop): namespace backend-runtime select sentinels and drop redundant WSLENV entry

- 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
This commit is contained in:
Josh Gratton committed 2026-05-16 11:38:36 -04:00
1 parent 3b18e6dfe2
commit b6c25caaa1
2 files changed
+24 -20

No files matched your search

@@ -49,15 +49,10 @@ const DESKTOP_BACKEND_ENV_NAMES = [
] as const;
// Sensitive env vars that the WSL backend needs but Windows process.env won't
// forward across the wsl.exe boundary without WSLENV. VITE_DEV_SERVER_URL is
// included so the WSL backend can tell it is running in dev mode and use the
// `dev/` subdir instead of `userdata/` for its state — otherwise the dev
// build collides with the user's daily-driver packaged WSL backend.
const WSL_FORWARDED_ENV_NAMES = [
"OPENAI_API_KEY",
"ANTHROPIC_API_KEY",
"VITE_DEV_SERVER_URL",
] as const;
// forward across the wsl.exe boundary without WSLENV. The dev-server URL is
// handled separately via a `--dev-url` CLI flag because WSLENV translation of
// URL-shaped values (colons / slashes) is unreliable.
const WSL_FORWARDED_ENV_NAMES = ["OPENAI_API_KEY", "ANTHROPIC_API_KEY"] as const;
const backendChildEnvPatch = (): Record<string, string | undefined> =>
Object.fromEntries(DESKTOP_BACKEND_ENV_NAMES.map((name) => [name, undefined]));
@@ -108,6 +108,12 @@ import { useServerConfig } from "~/rpc/serverState";
const DEFAULT_TAILSCALE_SERVE_PORT = 443;
// Select-value sentinels for the backend-runtime dropdown. The colon is
// rejected by DISTRO_NAME_PATTERN (validated by the desktop side), so these
// values can never collide with a real WSL distro name.
const BACKEND_VALUE_LOCAL = "backend:local";
const BACKEND_VALUE_DEFAULT_WSL = "backend:default-wsl";
const accessTimestampFormatter = new Intl.DateTimeFormat(undefined, {
dateStyle: "medium",
timeStyle: "short",
@@ -2362,9 +2368,12 @@ export function ConnectionsSettings() {
(value: string) => {
if (!desktopWslState) return;
const target =
value === "__local__"
value === BACKEND_VALUE_LOCAL
? { mode: "local" as const, distro: null }
: { mode: "wsl" as const, distro: value === "__default__" ? null : value };
: {
mode: "wsl" as const,
distro: value === BACKEND_VALUE_DEFAULT_WSL ? null : value,
};
if (target.mode === desktopWslState.mode && target.distro === desktopWslState.distro) {
return;
}
@@ -2476,17 +2485,17 @@ export function ConnectionsSettings() {
if (!desktopWslState || !desktopWslState.available) return null;
// When distro is null ("track the WSL default"), map to the actual default
// distro's name if we know one so the Select highlights a real option
// instead of an orphan "__default__" with no matching item. Falls back to
// "__default__" only when no distros are listed yet — in that case the
// dropdown renders a single placeholder option that matches.
// instead of an orphan default sentinel with no matching item. Falls back
// to BACKEND_VALUE_DEFAULT_WSL only when no distros are listed yet — in
// that case the dropdown renders a single placeholder option that matches.
const defaultDistroName =
desktopWslState.distros.find((distro) => distro.isDefault)?.name ?? null;
const wslSelectValue = desktopWslState.distro ?? defaultDistroName ?? "__default__";
const currentValue = desktopWslState.mode === "wsl" ? wslSelectValue : "__local__";
const wslSelectValue = desktopWslState.distro ?? defaultDistroName ?? BACKEND_VALUE_DEFAULT_WSL;
const currentValue = desktopWslState.mode === "wsl" ? wslSelectValue : BACKEND_VALUE_LOCAL;
const currentLabel =
currentValue === "__local__"
currentValue === BACKEND_VALUE_LOCAL
? "Local (Windows)"
: currentValue === "__default__"
: currentValue === BACKEND_VALUE_DEFAULT_WSL
? "WSL: default distro"
: `WSL: ${currentValue}`;
const pendingTargetLabel =
@@ -2528,11 +2537,11 @@ export function ConnectionsSettings() {
<SelectValue>{currentLabel}</SelectValue>
</SelectTrigger>
<SelectPopup align="end" alignItemWithTrigger={false}>
<SelectItem hideIndicator value="__local__">
<SelectItem hideIndicator value={BACKEND_VALUE_LOCAL}>
Local (Windows)
</SelectItem>
{desktopWslState.distros.length === 0 ? (
<SelectItem hideIndicator value="__default__">
<SelectItem hideIndicator value={BACKEND_VALUE_DEFAULT_WSL}>
WSL: default distro
</SelectItem>
) : (