@devries-cameron20 / t3code-1 / commits / 0395bf93e2
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(relay): resolve cloudflared using the hydrated PATH (#19444)

James C committed Oct 18, 2026 at 20:32 UTC 0395bf93e2591ebeee618685e6e6399489d869f9
2 files changed +73 -42
packages/shared/src/relayClient.test.ts
+69 -39
@@ -26,6 +26,7 @@ const layerHostRuntime = (env: Record<string, string> = {}, platform: NodeJS.Pla
26 Layer.mergeAll(
27 Layer.succeed(HostProcess.Platform, platform),
28 Layer.succeed(HostProcess.Architecture, "x64"),
29 + Layer.succeed(HostProcess.Environment, env),
30 ConfigProvider.layer(ConfigProvider.fromEnv({ env })),
31 );
32
@@ -457,50 +458,77 @@ describe("RelayClient", () => {
458 );
459 });
460
460 - it.effect.skipIf(windowsHost)(
461 - "observes PATH changes after the manager has been constructed",
462 - () => {
463 - const env = { PATH: "" };
464 - return Effect.gen(function* () {
465 - const fileSystem = yield* FileSystem.FileSystem;
466 - const baseDir = yield* fileSystem.makeTempDirectoryScoped({
467 - prefix: "t3-cloudflared-test-",
468 - });
469 - const binDir = `${baseDir}/bin`;
470 - const executablePath = `${binDir}/cloudflared`;
471 - const manager = yield* RelayClient.makeCloudflaredRelayClient({
472 - baseDir,
473 - });
461 + it.effect("observes hydrated PATH changes after the manager has been constructed", () => {
462 + const platform = windowsHost ? "win32" : "linux";
463 + const executableName = windowsHost ? "cloudflared.exe" : "cloudflared";
464 + const configEnv = { PATH: "" };
465 + const hostEnv = { PATH: "" };
466 + return Effect.gen(function* () {
467 + const fileSystem = yield* FileSystem.FileSystem;
468 + const baseDir = yield* fileSystem.makeTempDirectoryScoped({
469 + prefix: "t3-cloudflared-test-",
470 + });
471 + const binDir = `${baseDir}/bin`;
472 + const executablePath = `${binDir}/${executableName}`;
473 + const resolvedExecutablePath = windowsHost
474 + ? executablePath.replaceAll("/", "\\")
475 + : executablePath;
476 + const manager = yield* RelayClient.makeCloudflaredRelayClient({
477 + baseDir,
478 + });
479
475 - expect(yield* manager.resolve).toEqual({
476 - status: "missing",
477 - version: RelayClient.CLOUDFLARED_VERSION,
478 - });
480 + const resolveWithStaleConfig = manager.resolve.pipe(
481 + Effect.provideService(
482 + ConfigProvider.ConfigProvider,
483 + ConfigProvider.fromEnv({ env: configEnv }),
484 + ),
485 + Effect.provideService(HostProcess.Environment, hostEnv),
486 + );
487
480 - yield* fileSystem.makeDirectory(binDir);
481 - yield* fileSystem.writeFileString(executablePath, "cloudflared");
482 - yield* fileSystem.chmod(executablePath, 0o755);
483 - env.PATH = binDir;
488 + expect(yield* resolveWithStaleConfig).toEqual({
489 + status: "missing",
490 + version: RelayClient.CLOUDFLARED_VERSION,
491 + });
492
485 - expect(yield* manager.resolve).toEqual({
486 - status: "available",
487 - executablePath,
488 - source: "path",
489 - version: RelayClient.CLOUDFLARED_VERSION,
490 - });
491 - }).pipe(
492 - Effect.scoped,
493 - Effect.provide(
494 - Layer.mergeAll(
495 - NodeServices.layer,
496 - layerHttpClient(new Uint8Array()),
497 - layerSpawner([]),
498 - layerHostRuntime(env),
499 - ),
493 + yield* fileSystem.makeDirectory(binDir);
494 + yield* fileSystem.writeFileString(executablePath, "cloudflared");
495 + if (!windowsHost) yield* fileSystem.chmod(executablePath, 0o755);
496 + hostEnv.PATH = binDir;
497 +
498 + expect(yield* resolveWithStaleConfig).toEqual({
499 + status: "available",
500 + executablePath: resolvedExecutablePath,
501 + source: "path",
502 + version: RelayClient.CLOUDFLARED_VERSION,
503 + });
504 +
505 + const resolveWithOverride = manager.resolve.pipe(
506 + Effect.provideService(
507 + ConfigProvider.ConfigProvider,
508 + ConfigProvider.fromEnv({
509 + env: { PATH: "", T3CODE_CLOUDFLARED_PATH: executablePath },
510 + }),
511 ),
512 + Effect.provideService(HostProcess.Environment, { PATH: "" }),
513 );
502 - },
503 - );
514 + expect(yield* resolveWithOverride).toEqual({
515 + status: "available",
516 + executablePath,
517 + source: "override",
518 + version: RelayClient.CLOUDFLARED_VERSION,
519 + });
520 + }).pipe(
521 + Effect.scoped,
522 + Effect.provide(
523 + Layer.mergeAll(
524 + NodeServices.layer,
525 + layerHttpClient(new Uint8Array()),
526 + layerSpawner([]),
527 + layerHostRuntime(configEnv, platform),
528 + ),
529 + ),
530 + );
531 + });
532
533 describe("version selection", () => {
534 const run = <A, E>(
@@ -544,6 +572,7 @@ describe("RelayClient", () => {
572 ConfigProvider.ConfigProvider,
573 ConfigProvider.fromEnv({ env }),
574 ),
575 + Effect.provideService(HostProcess.Environment, env),
576 ),
577 ).toEqual({
578 status: "available",
@@ -608,6 +637,7 @@ describe("RelayClient", () => {
637 ConfigProvider.ConfigProvider,
638 ConfigProvider.fromEnv({ env: { PATH: `${baseDir}/bin` } }),
639 ),
640 + Effect.provideService(HostProcess.Environment, { PATH: `${baseDir}/bin` }),
641 );
642
643 expect(yield* resolveWith).toMatchObject({ source: "managed", version: "2026.1.0" });
packages/shared/src/relayClient.ts
+4 -3
@@ -135,7 +135,6 @@ const trimmedString = (name: string) =>
135
136 const CloudflaredConfig = Config.all({
137 executableOverride: trimmedString(CLOUDFLARED_PATH_ENV_NAME),
138 - path: trimmedString("PATH"),
138 });
139
140 export interface CloudflaredRelayClientOptions {
@@ -331,8 +330,10 @@ export const makeCloudflaredRelayClient = Effect.fn("cloudflared.make")(function
330 });
331
332 const resolvePathExecutable = Effect.gen(function* () {
334 - const config = yield* loadCloudflaredConfig;
335 - const pathValue = Option.getOrUndefined(config.path);
333 + // The default ConfigProvider is cached the first time any Config is read.
334 + // Server startup reads its config before fixPath hydrates the environment,
335 + // so reading PATH through Config here can retain the service's stale PATH.
336 + const pathValue = (yield* HostProcess.Environment).PATH?.trim();
337 if (!pathValue) return null;
338 const delimiter = platform === "win32" ? ";" : ":";
339 for (const directory of pathValue.split(delimiter)) {