The best way to control Claude Code, Codex and more from any computer or phone
perf(server): skip Windows probes for desktop-prepared environments (#19966)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 15, 2026 at 16:07 UTC
eef0e4e1f96d38d312f44baf377f2d1953f86370
7 files changed
+116
-48
apps/desktop/src/backend/DesktopBackendConfiguration.test.ts
+44
-23
@@ -15,6 +15,7 @@ import { ChildProcessSpawner } from "effect/process";
15
16
import * as DesktopEnvironment from "../app/DesktopEnvironment.ts";
17
import * as DesktopBackendConfiguration from "./DesktopBackendConfiguration.ts";
18
+import * as DesktopShellEnvironment from "../shell/DesktopShellEnvironment.ts";
19
import * as DesktopConfig from "../app/DesktopConfig.ts";
20
import * as DesktopServerExposure from "./DesktopServerExposure.ts";
21
import * as DesktopAppSettings from "../settings/DesktopAppSettings.ts";
@@ -37,6 +38,14 @@ const isDesktopBackendObservabilitySettingsReadError = Schema.is(
38
DesktopBackendConfiguration.DesktopBackendObservabilitySettingsReadError,
39
);
40
41
+const layerShellEnvironment = (prepared = true) =>
42
+ Layer.succeed(DesktopShellEnvironment.DesktopShellEnvironment, {
43
+ installIntoProcess: Effect.succeed(prepared),
44
+ });
45
+
46
+const layerBackendConfiguration = (prepared = true) =>
47
+ DesktopBackendConfiguration.layer.pipe(Layer.provide(layerShellEnvironment(prepared)));
48
+
49
const layerServerExposure = Layer.succeed(DesktopServerExposure.DesktopServerExposure, {
50
getState: Effect.die("unexpected getState"),
51
backendConfig: Effect.succeed({
@@ -114,6 +123,7 @@ const withHarness = <A, E, R>(
123
| FileSystem.FileSystem
124
| DesktopBackendConfiguration.DesktopBackendConfiguration
125
>,
126
+ prepared = true,
127
) =>
128
Effect.gen(function* () {
129
const fileSystem = yield* FileSystem.FileSystem;
@@ -123,7 +133,7 @@ const withHarness = <A, E, R>(
133
134
return yield* effect.pipe(
135
Effect.provide(
126
- DesktopBackendConfiguration.layer.pipe(
136
+ layerBackendConfiguration(prepared).pipe(
137
Layer.provideMerge(layerServerExposure),
138
Layer.provideMerge(DesktopAppSettings.layerTest()),
139
Layer.provideMerge(DesktopWslEnvironment.layerTest()),
@@ -201,7 +211,7 @@ const withPackagedWslHarness = <A, E, R>(
211
212
return yield* effect(context).pipe(
213
Effect.provide(
204
- DesktopBackendConfiguration.layer.pipe(
214
+ layerBackendConfiguration().pipe(
215
Layer.provideMerge(layerServerExposure),
216
Layer.provideMerge(DesktopAppSettings.layerTest()),
217
Layer.provideMerge(layerServerTree),
@@ -293,7 +303,7 @@ describe("DesktopBackendConfiguration", () => {
303
return yield* configuration.resolvePrimary;
304
}).pipe(
305
Effect.provide(
296
- DesktopBackendConfiguration.layer.pipe(
306
+ layerBackendConfiguration().pipe(
307
Layer.provideMerge(layerServerExposure),
308
Layer.provideMerge(DesktopAppSettings.layerTest()),
309
Layer.provideMerge(DesktopWslEnvironment.layerTest()),
@@ -340,6 +350,17 @@ describe("DesktopBackendConfiguration", () => {
350
),
351
);
352
353
+ it.effect("keeps server hydration enabled when desktop preparation failed", () =>
354
+ withHarness(
355
+ Effect.gen(function* () {
356
+ const configuration = yield* DesktopBackendConfiguration.DesktopBackendConfiguration;
357
+ const primary = yield* configuration.resolvePrimary;
358
+ assert.equal(primary.bootstrap.shellEnvironmentPrepared, false);
359
+ }),
360
+ false,
361
+ ),
362
+ );
363
+
364
it.effect("resolveWsl reuses the primary's bootstrap token", () =>
365
withHarness(
366
Effect.gen(function* () {
@@ -370,7 +391,7 @@ describe("DesktopBackendConfiguration", () => {
391
return yield* configuration.resolveWsl({ port: 5000, distro: null });
392
}).pipe(
393
Effect.provide(
373
- DesktopBackendConfiguration.layer.pipe(
394
+ layerBackendConfiguration().pipe(
395
Layer.provideMerge(layerServerExposure),
396
Layer.provideMerge(DesktopAppSettings.layerTest()),
397
Layer.provideMerge(DesktopWslServerTree.layerTest()),
@@ -692,7 +713,7 @@ describe("DesktopBackendConfiguration", () => {
713
return yield* configuration.resolveWsl({ port: 5000, distro: "Ubuntu" });
714
}).pipe(
715
Effect.provide(
695
- DesktopBackendConfiguration.layer.pipe(
716
+ layerBackendConfiguration().pipe(
717
Layer.provideMerge(layerServerExposure),
718
Layer.provideMerge(DesktopAppSettings.layerTest()),
719
Layer.provideMerge(DesktopWslServerTree.layerTest()),
@@ -820,7 +841,7 @@ describe("DesktopBackendConfiguration", () => {
841
assert.equal(config.bootstrap.otlpLogsUrl, "http://127.0.0.1:4318/v1/logs");
842
}).pipe(
843
Effect.provide(
823
- DesktopBackendConfiguration.layer.pipe(
844
+ layerBackendConfiguration().pipe(
845
Layer.provideMerge(layerServerExposure),
846
Layer.provideMerge(DesktopAppSettings.layerTest()),
847
Layer.provideMerge(DesktopWslServerTree.layerTest()),
@@ -878,7 +899,7 @@ describe("DesktopBackendConfiguration", () => {
899
assert.equal(config.bootstrap.otlpMetricsUrl, "http://persisted:4318/v1/metrics");
900
}).pipe(
901
Effect.provide(
881
- DesktopBackendConfiguration.layer.pipe(
902
+ layerBackendConfiguration().pipe(
903
Layer.provideMerge(layerServerExposure),
904
Layer.provideMerge(DesktopAppSettings.layerTest()),
905
Layer.provideMerge(DesktopWslServerTree.layerTest()),
@@ -923,7 +944,7 @@ describe("DesktopBackendConfiguration", () => {
944
}).pipe(
945
Effect.provide(
946
Layer.mergeAll(
926
- DesktopBackendConfiguration.layer.pipe(
947
+ layerBackendConfiguration().pipe(
948
Layer.provideMerge(layerServerExposure),
949
Layer.provideMerge(DesktopAppSettings.layerTest()),
950
Layer.provideMerge(DesktopWslServerTree.layerTest()),
@@ -968,7 +989,7 @@ describe("DesktopBackendConfiguration", () => {
989
assert.notInclude(config.args, "--require");
990
}).pipe(
991
Effect.provide(
971
- DesktopBackendConfiguration.layer.pipe(
992
+ layerBackendConfiguration().pipe(
993
Layer.provideMerge(layerServerExposure),
994
Layer.provideMerge(DesktopAppSettings.layerTest()),
995
Layer.provideMerge(DesktopWslServerTree.layerTest()),
@@ -1010,7 +1031,7 @@ describe("DesktopBackendConfiguration", () => {
1031
assert.include((config.env.WSLENV ?? "").split(":"), "T3CODE_TELEMETRY_ENABLED");
1032
}).pipe(
1033
Effect.provide(
1013
- DesktopBackendConfiguration.layer.pipe(
1034
+ layerBackendConfiguration().pipe(
1035
Layer.provideMerge(layerServerExposure),
1036
Layer.provideMerge(DesktopAppSettings.layerTest()),
1037
Layer.provideMerge(DesktopWslServerTree.layerTest()),
@@ -1077,7 +1098,7 @@ describe("DesktopBackendConfiguration", () => {
1098
assert.include(wslEnv, "T3CODE_OTLP_TRACES_URL");
1099
}).pipe(
1100
Effect.provide(
1080
- DesktopBackendConfiguration.layer.pipe(
1101
+ layerBackendConfiguration().pipe(
1102
Layer.provideMerge(layerServerExposure),
1103
Layer.provideMerge(DesktopAppSettings.layerTest()),
1104
Layer.provideMerge(DesktopWslServerTree.layerTest()),
@@ -1151,7 +1172,7 @@ describe("DesktopBackendConfiguration", () => {
1172
);
1173
}).pipe(
1174
Effect.provide(
1154
- DesktopBackendConfiguration.layer.pipe(
1175
+ layerBackendConfiguration().pipe(
1176
Layer.provideMerge(layerServerExposure),
1177
Layer.provideMerge(DesktopAppSettings.layerTest()),
1178
Layer.provideMerge(DesktopWslServerTree.layerTest()),
@@ -1199,7 +1220,7 @@ describe("DesktopBackendConfiguration", () => {
1220
assert.isTrue(Option.isNone(config.preflightFailure));
1221
}).pipe(
1222
Effect.provide(
1202
- DesktopBackendConfiguration.layer.pipe(
1223
+ layerBackendConfiguration().pipe(
1224
Layer.provideMerge(layerServerExposure),
1225
Layer.provideMerge(
1226
DesktopAppSettings.layerTest({
@@ -1236,7 +1257,7 @@ describe("DesktopBackendConfiguration", () => {
1257
assert.include(failure.reason, "Removed-Distro");
1258
}).pipe(
1259
Effect.provide(
1239
- DesktopBackendConfiguration.layer.pipe(
1260
+ layerBackendConfiguration().pipe(
1261
Layer.provideMerge(layerServerExposure),
1262
Layer.provideMerge(
1263
DesktopAppSettings.layerTest({
@@ -1277,7 +1298,7 @@ describe("DesktopBackendConfiguration", () => {
1298
assert.include(failure.reason, "timed out");
1299
}).pipe(
1300
Effect.provide(
1280
- DesktopBackendConfiguration.layer.pipe(
1301
+ layerBackendConfiguration().pipe(
1302
Layer.provideMerge(layerServerExposure),
1303
Layer.provideMerge(DesktopAppSettings.layerTest()),
1304
Layer.provideMerge(DesktopWslServerTree.layerTest()),
@@ -1312,7 +1333,7 @@ describe("DesktopBackendConfiguration", () => {
1333
assert.include(failure.reason, "missing server entry");
1334
}).pipe(
1335
Effect.provide(
1315
- DesktopBackendConfiguration.layer.pipe(
1336
+ layerBackendConfiguration().pipe(
1337
Layer.provideMerge(layerServerExposure),
1338
Layer.provideMerge(DesktopAppSettings.layerTest()),
1339
Layer.provideMerge(DesktopWslServerTree.layerTest()),
@@ -1346,7 +1367,7 @@ describe("DesktopBackendConfiguration", () => {
1367
assert.include(failure.reason, "could not be extracted");
1368
}).pipe(
1369
Effect.provide(
1349
- DesktopBackendConfiguration.layer.pipe(
1370
+ layerBackendConfiguration().pipe(
1371
Layer.provideMerge(layerServerExposure),
1372
Layer.provideMerge(DesktopAppSettings.layerTest()),
1373
Layer.provideMerge(
@@ -1387,7 +1408,7 @@ describe("DesktopBackendConfiguration", () => {
1408
assert.include(failure.reason, "Removed-Distro");
1409
}).pipe(
1410
Effect.provide(
1390
- DesktopBackendConfiguration.layer.pipe(
1411
+ layerBackendConfiguration().pipe(
1412
Layer.provideMerge(layerServerExposure),
1413
Layer.provideMerge(DesktopAppSettings.layerTest()),
1414
Layer.provideMerge(DesktopWslServerTree.layerTest()),
@@ -1417,7 +1438,7 @@ describe("DesktopBackendConfiguration", () => {
1438
assert.equal(label, "WSL (Ubuntu)");
1439
}).pipe(
1440
Effect.provide(
1420
- DesktopBackendConfiguration.layer.pipe(
1441
+ layerBackendConfiguration().pipe(
1442
Layer.provideMerge(layerServerExposure),
1443
Layer.provideMerge(
1444
DesktopAppSettings.layerTest({
@@ -1466,7 +1487,7 @@ describe("DesktopBackendConfiguration", () => {
1487
assert.equal(config.bootstrap.desktopTelemetryControlFd, 5);
1488
}).pipe(
1489
Effect.provide(
1469
- DesktopBackendConfiguration.layer.pipe(
1490
+ layerBackendConfiguration().pipe(
1491
Layer.provideMerge(layerServerExposure),
1492
Layer.provideMerge(DesktopAppSettings.layerTest()),
1493
Layer.provideMerge(DesktopWslServerTree.layerTest()),
@@ -1512,7 +1533,7 @@ describe("DesktopBackendConfiguration", () => {
1533
assert.equal(config.bootstrap.resourceMonitorPath, releaseMonitorPath);
1534
}).pipe(
1535
Effect.provide(
1515
- DesktopBackendConfiguration.layer.pipe(
1536
+ layerBackendConfiguration().pipe(
1537
Layer.provideMerge(layerServerExposure),
1538
Layer.provideMerge(DesktopAppSettings.layerTest()),
1539
Layer.provideMerge(DesktopWslServerTree.layerTest()),
@@ -1556,7 +1577,7 @@ describe("DesktopBackendConfiguration", () => {
1577
assert.equal(label, "Windows");
1578
}).pipe(
1579
Effect.provide(
1559
- DesktopBackendConfiguration.layer.pipe(
1580
+ layerBackendConfiguration().pipe(
1581
Layer.provideMerge(layerServerExposure),
1582
Layer.provideMerge(
1583
DesktopAppSettings.layerTest({
@@ -1585,7 +1606,7 @@ describe("DesktopBackendConfiguration", () => {
1606
// top-level runSync, exactly as the handler does.
1607
// oxlint-disable-next-line t3code/no-manual-effect-runtime-in-tests -- This test intentionally replicates the sync IPC handler's runSync path to catch a regression to async-only resolution; it.effect would mask it.
1608
const runtime = ManagedRuntime.make(
1588
- DesktopBackendConfiguration.layer.pipe(
1609
+ layerBackendConfiguration().pipe(
1610
Layer.provideMerge(layerServerExposure),
1611
Layer.provideMerge(DesktopAppSettings.layerTest()),
1612
Layer.provideMerge(DesktopWslServerTree.layerTest()),
apps/desktop/src/backend/DesktopBackendConfiguration.ts
+12
-5
@@ -20,6 +20,7 @@ import * as DesktopBackendManager from "./DesktopBackendManager.ts";
20
import * as DesktopCliShim from "../app/DesktopCliShim.ts";
21
import * as DesktopEnvironment from "../app/DesktopEnvironment.ts";
22
import * as DesktopServerExposure from "./DesktopServerExposure.ts";
23
+import * as DesktopShellEnvironment from "../shell/DesktopShellEnvironment.ts";
24
import * as DesktopAppSettings from "../settings/DesktopAppSettings.ts";
25
import * as DesktopWslEnvironment from "../wsl/DesktopWslEnvironment.ts";
26
import * as DesktopWslServerTree from "../wsl/DesktopWslServerTree.ts";
@@ -549,6 +550,7 @@ const resolvePrimaryStartConfig = Effect.fn("desktop.backendConfiguration.resolv
550
input: SharedBootstrapInput & {
551
readonly resourceMonitorPath: Option.Option<string>;
552
readonly cliPath: Option.Option<string>;
553
+ readonly shellEnvironmentPrepared: boolean;
554
},
555
): Effect.fn.Return<
556
DesktopBackendManager.DesktopBackendStartConfig,
@@ -567,10 +569,8 @@ const resolvePrimaryStartConfig = Effect.fn("desktop.backendConfiguration.resolv
569
host: backendExposure.bindHost,
570
desktopBootstrapToken: input.bootstrapToken,
571
desktopBootstrapSecret: input.bootstrapSecret,
570
- // DesktopApp installs the shell environment into process.env before any
571
- // backend starts, and this child extends it (extendEnv below). WSL gets
572
- // a different environment, so its bootstrap never sets this.
573
- shellEnvironmentPrepared: true,
572
+ // Failed Windows probes leave server hydration enabled for another attempt.
573
+ shellEnvironmentPrepared: input.shellEnvironmentPrepared,
574
tailscaleServeEnabled: backendExposure.tailscaleServeEnabled,
575
tailscaleServePort: backendExposure.tailscaleServePort,
576
desktopTelemetryFd: 4,
@@ -842,6 +842,7 @@ const resolveWslStartConfig = Effect.fn("desktop.backendConfiguration.resolveWsl
842
/** @public Service construction is part of the canonical Effect module API. */
843
export const make = Effect.gen(function* () {
844
const environment = yield* DesktopEnvironment.DesktopEnvironment;
845
+ const shellEnvironment = yield* DesktopShellEnvironment.DesktopShellEnvironment;
846
const fileSystem = yield* FileSystem.FileSystem;
847
const serverExposure = yield* DesktopServerExposure.DesktopServerExposure;
848
const wslEnvironment = yield* DesktopWslEnvironment.DesktopWslEnvironment;
@@ -924,7 +925,13 @@ export const make = Effect.gen(function* () {
925
Effect.provideService(FileSystem.FileSystem, fileSystem),
926
Effect.provideService(DesktopEnvironment.DesktopEnvironment, environment),
927
);
927
- return yield* resolvePrimaryStartConfig({ ...shared, resourceMonitorPath, cliPath }).pipe(
928
+ const shellEnvironmentPrepared = yield* shellEnvironment.installIntoProcess;
929
+ return yield* resolvePrimaryStartConfig({
930
+ ...shared,
931
+ resourceMonitorPath,
932
+ cliPath,
933
+ shellEnvironmentPrepared,
934
+ }).pipe(
935
Effect.provideService(DesktopEnvironment.DesktopEnvironment, environment),
936
Effect.provideService(DesktopServerExposure.DesktopServerExposure, serverExposure),
937
);
apps/desktop/src/main.ts
+1
-1
@@ -195,6 +195,7 @@ const layerDesktopAppActivation = DesktopAppActivation.layer.pipe(
195
const layerDesktopBackend = DesktopBackendPool.layer.pipe(
196
Layer.provideMerge(DesktopAppIdentity.layer),
197
Layer.provideMerge(DesktopBackendConfiguration.layer),
198
+ Layer.provideMerge(DesktopShellEnvironment.layer),
199
Layer.provideMerge(DesktopWslEnvironment.layer),
200
Layer.provideMerge(DesktopWslServerTree.layer),
201
Layer.provideMerge(DesktopTelemetryPublisher.layer),
@@ -219,7 +220,6 @@ const layerDesktopApplication = Layer.mergeAll(
220
DesktopApplicationMenu.layer,
221
DesktopLinuxUrlHandler.layer,
222
DesktopCliCommand.layer,
222
- DesktopShellEnvironment.layer,
223
layerDesktopSsh,
224
).pipe(
225
Layer.provideMerge(layerDesktopSnapShot),
apps/desktop/src/shell/DesktopShellEnvironment.test.ts
+29
-2
@@ -98,7 +98,9 @@ function runShellEnvironment(input: {
98
99
const program = Effect.gen(function* () {
100
const shellEnvironment = yield* DesktopShellEnvironment.DesktopShellEnvironment;
101
- yield* shellEnvironment.installIntoProcess;
101
+ const prepared = yield* shellEnvironment.installIntoProcess;
102
+ assert.equal(yield* shellEnvironment.installIntoProcess, prepared);
103
+ return prepared;
104
}).pipe(
105
Effect.provide(
106
DesktopShellEnvironment.layer.pipe(
@@ -446,7 +448,7 @@ describe("DesktopShellEnvironment", () => {
448
USERPROFILE: "C:\\Users\\testuser",
449
};
450
449
- yield* runShellEnvironment({
451
+ const prepared = yield* runShellEnvironment({
452
env,
453
platform: "win32",
454
handler: (command) => {
@@ -462,6 +464,7 @@ describe("DesktopShellEnvironment", () => {
464
},
465
});
466
467
+ assert.isTrue(prepared);
468
assert.equal(
469
env.PATH,
470
[
@@ -486,6 +489,30 @@ describe("DesktopShellEnvironment", () => {
489
}),
490
);
491
492
+ it.effect.each([false, true])(
493
+ "leaves Windows preparation incomplete when loadProfile=%s fails",
494
+ (loadProfile) =>
495
+ Effect.gen(function* () {
496
+ const env: NodeJS.ProcessEnv = { PATH: "C:\\Windows\\System32" };
497
+ let calls = 0;
498
+ const prepared = yield* runShellEnvironment({
499
+ env,
500
+ platform: "win32",
501
+ handler: (command) => {
502
+ calls++;
503
+ if (command._tag !== "StandardCommand") return "";
504
+ return !command.args.includes("-NoProfile") === loadProfile
505
+ ? { output: "", exitCode: 1 }
506
+ : envOutput({ PATH: "C:\\Working" });
507
+ },
508
+ }).pipe(Effect.provide(Logger.layer([])));
509
+ assert.isFalse(prepared);
510
+ assert.equal(calls, 3);
511
+ assert.include(env.PATH, "C:\\Working");
512
+ assert.include(env.PATH, "C:\\Windows\\System32");
513
+ }),
514
+ );
515
+
516
it.effect("replaces a Path-spelled Windows PATH instead of adding a second key", () =>
517
Effect.gen(function* () {
518
const env: NodeJS.ProcessEnv = { Path: "C:\\Windows\\System32" };
apps/desktop/src/shell/DesktopShellEnvironment.ts
+20
-12
@@ -64,7 +64,8 @@ export class DesktopShellEnvironmentCommandTimeoutError extends Schema.TaggedErr
64
export class DesktopShellEnvironment extends Context.Service<
65
DesktopShellEnvironment,
66
{
67
- readonly installIntoProcess: Effect.Effect<void>;
67
+ // Reuses the installation result; false leaves server hydration enabled.
68
+ readonly installIntoProcess: Effect.Effect<boolean>;
69
}
70
>()("@t3tools/desktop/shell/DesktopShellEnvironment") {}
71
@@ -365,7 +366,7 @@ const readWindowsEnvironment = Effect.fn("desktop.shellEnvironment.readWindowsEn
366
const installWindowsEnvironment = Effect.fn("desktop.shellEnvironment.installWindowsEnvironment")(
367
function* (
368
config: ShellEnvironmentConfig,
368
- ): Effect.fn.Return<void, never, ChildProcessSpawner.ChildProcessSpawner> {
369
+ ): Effect.fn.Return<boolean, never, ChildProcessSpawner.ChildProcessSpawner> {
370
// Concurrent, not sequential: these two probes are independent (only their
371
// results are combined below) and each spawns its own PowerShell. Run in
372
// series they sit at offset 0 of desktop.startup, before anything else, and
@@ -394,6 +395,7 @@ const installWindowsEnvironment = Effect.fn("desktop.shellEnvironment.installWin
395
if (!config.env.FNM_MULTISHELL_PATH && profile.FNM_MULTISHELL_PATH) {
396
config.env.FNM_MULTISHELL_PATH = profile.FNM_MULTISHELL_PATH;
397
}
398
+ return Boolean(noProfile.PATH && profile.PATH);
399
},
400
);
401
@@ -514,14 +516,18 @@ const installPosixEnvironment = Effect.fn("desktop.shellEnvironment.installPosix
516
517
const installShellEnvironment = (
518
config: ShellEnvironmentConfig,
517
-): Effect.Effect<void, never, ChildProcessSpawner.ChildProcessSpawner | FileSystem.FileSystem> => {
519
+): Effect.Effect<
520
+ boolean,
521
+ never,
522
+ ChildProcessSpawner.ChildProcessSpawner | FileSystem.FileSystem
523
+> => {
524
if (config.platform === "win32") {
525
return installWindowsEnvironment(config);
526
}
527
if (config.platform === "darwin" || config.platform === "linux") {
522
- return installPosixEnvironment(config);
528
+ return installPosixEnvironment(config).pipe(Effect.as(true));
529
}
524
- return Effect.void;
530
+ return Effect.succeed(false);
531
};
532
533
/** @public Service construction is part of the canonical Effect module API. */
@@ -530,13 +536,15 @@ export const make = Effect.gen(function* () {
536
const fileSystem = yield* FileSystem.FileSystem;
537
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
538
const installIntoProcess: DesktopShellEnvironment["Service"]["installIntoProcess"] =
533
- installShellEnvironment({
534
- env: process.env,
535
- platform: environment.platform,
536
- }).pipe(
537
- Effect.provideService(FileSystem.FileSystem, fileSystem),
538
- Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
539
- Effect.withSpan("desktop.shellEnvironment.installIntoProcess"),
539
+ yield* Effect.cached(
540
+ installShellEnvironment({
541
+ env: process.env,
542
+ platform: environment.platform,
543
+ }).pipe(
544
+ Effect.provideService(FileSystem.FileSystem, fileSystem),
545
+ Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
546
+ Effect.withSpan("desktop.shellEnvironment.installIntoProcess"),
547
+ ),
548
);
549
550
return DesktopShellEnvironment.of({ installIntoProcess });
apps/server/src/os-jank.test.ts
+7
-5
@@ -130,15 +130,17 @@ effectIt.effect("keeps mise's PATH record with the login shell PATH", () =>
130
),
131
);
132
133
-effectIt.effect("repairs Windows PATH even when the desktop marks it prepared", () =>
133
+effectIt.effect("keeps the prepared Windows PATH without probing", () =>
134
Effect.gen(function* () {
135
- const env: NodeJS.ProcessEnv = { PATH: "C:\\Windows" };
135
+ const env: NodeJS.ProcessEnv = { PATH: "C:\\Prepared\\Bin;C:\\Windows" };
136
const commands: string[] = [];
137
138
yield* fixPath({ shellEnvironmentPrepared: true }).pipe(
139
Effect.provideService(HostProcess.Platform, "win32"),
140
Effect.provideService(HostProcess.Environment, env),
141
- Effect.provideService(WindowsShellEnvironment, () => ({ PATH: "C:\\Tools" })),
141
+ Effect.provideService(WindowsShellEnvironment, () => {
142
+ throw new Error("The prepared environment must not launch another shell");
143
+ }),
144
Effect.provideService(CommandAvailability, (command) =>
145
Effect.sync(() => {
146
commands.push(command);
@@ -148,8 +150,8 @@ effectIt.effect("repairs Windows PATH even when the desktop marks it prepared",
150
Effect.provide(NodeServices.layer),
151
);
152
151
- assert.deepEqual(commands, ["node"]);
152
- assert.equal(env.PATH, "C:\\Tools;C:\\Windows");
153
+ assert.deepEqual(commands, []);
154
+ assert.equal(env.PATH, "C:\\Prepared\\Bin;C:\\Windows");
155
}),
156
);
157
apps/server/src/os-jank.ts
+3
@@ -63,6 +63,9 @@ export const fixPath = Effect.fn("fixPath")(function* (options?: {
63
const env = yield* HostProcess.Environment;
64
65
if (platform === "win32") {
66
+ // The desktop already ran both PowerShell probes into the env this child
67
+ // extends. Repeating them here costs seconds of startup on Windows.
68
+ if (options?.shellEnvironmentPrepared === true) return;
69
const repairedEnvironment = yield* resolveWindowsEnvironment(env).pipe(
70
Effect.catchDefect((defect) =>
71
Effect.sync(() => {