@devries-cameron20 / t3code-1 / commits / ad5ba437bd
Fork 0

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

fix(server): restore Linux session display for editor launches (#25228)

Co-authored-by: Inaya Yousfi <193243337+inayayousfi@users.noreply.github.com>

maria committed Oct 29, 2026 at 18:03 UTC ad5ba437bd0b467879915efa9a14411b71a54fe7
2 files changed +126 -1
apps/server/src/process/externalLauncher.test.ts
+73
@@ -140,6 +140,79 @@ it.effect.skipIf(windowsHost)(
140 }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
141 );
142
143 +// Windows drive letters cannot resolve the POSIX editor stub.
144 +it.effect.skipIf(windowsHost)(
145 + "a Linux editor launch without a display takes the desktop session's display from the systemd user manager",
146 + () =>
147 + Effect.gen(function* () {
148 + const fileSystem = yield* FileSystem.FileSystem;
149 + const path = yield* Path.Path;
150 + const binDir = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-editors-" });
151 + const codiumPath = path.join(binDir, "codium");
152 + yield* fileSystem.writeFileString(codiumPath, "#!/bin/sh\n");
153 + yield* fileSystem.chmod(codiumPath, 0o755);
154 +
155 + const launchEnv = (sessionManager: MockSpawnResult) =>
156 + Effect.gen(function* () {
157 + const spawned: ChildProcess.StandardCommand[] = [];
158 + yield* Effect.gen(function* () {
159 + const launcher = yield* ExternalLauncher.ExternalLauncher;
160 + yield* launcher.launchEditor({ editor: "vscodium", cwd: "/workspace" });
161 + yield* launcher.launchBrowser("https://example.com");
162 + }).pipe(
163 + Effect.provide(
164 + layerTest({
165 + platform: "linux",
166 + env: { PATH: binDir },
167 + onSpawn: (command) => spawned.push(command),
168 + spawnResult: (command) =>
169 + command.command === "busctl" ? sessionManager : undefined,
170 + }),
171 + ),
172 + Effect.provideService(HostProcess.Environment, { PATH: binDir }),
173 + );
174 + // Only editors borrow the session display; a browser must not open on that screen.
175 + assert.deepEqual(spawned.find((command) => command.command === "xdg-open")?.options.env, {
176 + PATH: binDir,
177 + });
178 + return spawned.find((command) => command.command === "codium")?.options.env;
179 + });
180 +
181 + assert.deepEqual(
182 + yield* launchEnv({
183 + stdout: JSON.stringify({
184 + type: "as",
185 + data: [
186 + "DISPLAY=:0",
187 + "HOME=/home/user",
188 + "WAYLAND_DISPLAY=wayland-1",
189 + "XAUTHORITY=/home/user/auth files/cookie",
190 + ],
191 + }),
192 + }),
193 + {
194 + PATH: binDir,
195 + DISPLAY: ":0",
196 + WAYLAND_DISPLAY: "wayland-1",
197 + // Raw, not the $'...' quoting `systemctl show-environment` would print.
198 + XAUTHORITY: "/home/user/auth files/cookie",
199 + },
200 + );
201 + assert.deepEqual(yield* launchEnv({ stdout: "invalid JSON" }), { PATH: binDir });
202 + assert.deepEqual(yield* launchEnv({ stdout: '{"data":[42]}' }), { PATH: binDir });
203 + assert.deepEqual(
204 + yield* launchEnv({
205 + spawnError: PlatformError.systemError({
206 + _tag: "NotFound",
207 + module: "ChildProcess",
208 + method: "spawn",
209 + }),
210 + }),
211 + { PATH: binDir },
212 + );
213 + }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
214 +);
215 +
216 it.effect("launches an installed editor with platform-safe arguments", () =>
217 Effect.gen(function* () {
218 const fileSystem = yield* FileSystem.FileSystem;
apps/server/src/process/externalLauncher.ts
+53 -1
@@ -31,6 +31,7 @@ import * as Layer from "effect/Layer";
31 import * as Option from "effect/Option";
32 import * as Path from "effect/Path";
33 import * as Ref from "effect/Ref";
34 +import * as Schema from "effect/Schema";
35 import * as Scope from "effect/Scope";
36 import * as Stream from "effect/Stream";
37 import * as ChildProcess from "effect/process/ChildProcess";
@@ -672,6 +673,56 @@ const launchEditor = Effect.fn("externalLauncher.launchEditor")(function* (
673 yield* launchEditorProcess(launch);
674 });
675
676 +const GRAPHICAL_SESSION_ENV_KEYS: ReadonlySet<string> = new Set([
677 + "DISPLAY",
678 + "WAYLAND_DISPLAY",
679 + "XAUTHORITY",
680 +]);
681 +
682 +// The user manager's environment over D-Bus. `systemctl show-environment` would
683 +// shell-quote values with spaces as $'...', while this JSON carries them raw.
684 +const decodeManagerEnvironment = Schema.decodeUnknownEffect(
685 + Schema.fromJsonString(Schema.Struct({ data: Schema.Array(Schema.String) })),
686 +);
687 +
688 +// Boot services miss the desktop environment imported later into the systemd user manager.
689 +const readGraphicalSessionEnv = Effect.fn("externalLauncher.readGraphicalSessionEnv")(
690 + function* () {
691 + const hostEnv = yield* HostProcess.Environment;
692 + if ((yield* HostProcess.Platform) !== "linux" || hasGraphicalLinuxSession(hostEnv)) {
693 + return {};
694 + }
695 + const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
696 + const output = yield* spawner.string(
697 + ChildProcess.make(
698 + "busctl",
699 + [
700 + "--user",
701 + "--json=short",
702 + "get-property",
703 + "org.freedesktop.systemd1",
704 + "/org/freedesktop/systemd1",
705 + "org.freedesktop.systemd1.Manager",
706 + "Environment",
707 + ],
708 + { stdin: "ignore", stderr: "ignore" },
709 + ),
710 + );
711 + const { data } = yield* decodeManagerEnvironment(output);
712 + return Object.fromEntries(
713 + data.flatMap((line) => {
714 + const separator = line.indexOf("=");
715 + const key = line.slice(0, separator);
716 + return separator > 0 && GRAPHICAL_SESSION_ENV_KEYS.has(key)
717 + ? [[key, line.slice(separator + 1)]]
718 + : [];
719 + }),
720 + );
721 + },
722 + Effect.timeout("2 seconds"),
723 + Effect.orElseSucceed((): NodeJS.ProcessEnv => ({})),
724 +);
725 +
726 const launchAndUnref = Effect.fn("externalLauncher.launchAndUnref")(function* (
727 launch: ProcessLaunch,
728 onError: (cause: unknown) => ExternalLauncherError,
@@ -681,7 +732,7 @@ const launchAndUnref = Effect.fn("externalLauncher.launchAndUnref")(function* (
732 const { ELECTRON_RUN_AS_NODE: _runAsNode, ...env } = yield* HostProcess.Environment;
733 const command = ChildProcess.make(launch.command, launch.args, {
734 ...launch.options,
684 - env,
735 + env: { ...env, ...launch.options.env },
736 extendEnv: false,
737 });
738
@@ -735,6 +786,7 @@ const launchEditorProcess = Effect.fn("externalLauncher.launchEditorProcess")(fu
786 options: {
787 detached: launch.detached ?? true,
788 shell: spawnCommand.shell,
789 + env: yield* readGraphicalSessionEnv(),
790 stdin: "ignore",
791 stdout: "ignore",
792 stderr: "ignore",