The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 13:30 UTC
fix(server): isolate Linux process launches from the RPC event loop (#30209)
Co-authored-by: maria-rcks <maria@kuuro.net> Co-authored-by: Julius Marminge <julius0216@outlook.com>
Lakshmi Tanmay committed
Nov 15, 2026 at 04:19 UTC
92595ab149138f9f2663705d50bbcf94b7314c4f
2 files changed
+23
-9
apps/server/src/process/SpawnWorker.test.ts
+13
-4
@@ -3,6 +3,7 @@ import * as NodeOS from "node:os";
3
import * as NodePath from "node:path";
4
import * as NodeServices from "@effect/platform-node/NodeServices";
5
import { describe, expect, it } from "@effect/vitest";
6
+import { vi } from "vite-plus/test";
7
import * as Deferred from "effect/Deferred";
8
import * as Effect from "effect/Effect";
9
import * as Fiber from "effect/Fiber";
@@ -15,6 +16,12 @@ import * as HostProcess from "@t3tools/shared/HostProcess";
16
17
import * as SpawnWorker from "./SpawnWorker.ts";
18
19
+const envChdir = vi.hoisted(() => ({ supported: true }));
20
+vi.mock("@t3tools/shared/envTrampoline", async (importOriginal) => ({
21
+ ...(await importOriginal<typeof import("@t3tools/shared/envTrampoline")>()),
22
+ supportsEnvChdir: () => Promise.resolve(envChdir.supported),
23
+}));
24
+
25
const layer = SpawnWorker.layer.pipe(Layer.provide(NodeServices.layer));
26
const text = <E>(stream: Stream.Stream<Uint8Array, E>) =>
27
stream.pipe(Stream.decodeText(), Stream.mkString);
@@ -22,12 +29,14 @@ const node = (script: string, args: ReadonlyArray<string> = [], options = {}) =>
29
ChildProcess.make(process.execPath, ["-e", script, ...args], options);
30
31
describe("SpawnWorker", () => {
25
- it.live("runs the server's Windows children on a launcher thread, not the server thread", () =>
32
+ it.live("runs children on a launcher thread where the server thread would wait on them", () =>
33
Effect.gen(function* () {
27
- for (const [platform, onServerThread] of [
28
- ["win32", false],
29
- ["linux", true],
34
+ for (const [platform, hasEnvChdir, onServerThread] of [
35
+ ["win32", true, false],
36
+ ["linux", true, true],
37
+ ["linux", false, false],
38
] as const) {
39
+ envChdir.supported = hasEnvChdir;
40
const launched = Effect.gen(function* () {
41
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
42
const child = yield* spawner.spawn(
apps/server/src/process/SpawnWorker.ts
+10
-5
@@ -6,10 +6,12 @@ import * as NodeWorkerThreads from "node:worker_threads";
6
import * as NodeChildProcessSpawner from "@effect/platform-node-shared/NodeChildProcessSpawner";
7
import * as Effect from "effect/Effect";
8
import * as Layer from "effect/Layer";
9
+import { supportsEnvChdir } from "@t3tools/shared/envTrampoline";
10
import * as HostProcess from "@t3tools/shared/HostProcess";
11
12
// Windows runs CreateProcess synchronously on the calling thread, and antivirus or a busy disk can
12
-// hold it for seconds. Workers own the children, so only the worker waits.
13
+// hold it for seconds; Linux's spawn waits for chdir and the PATH search, which a hung mount
14
+// stalls. Workers own the children, so only the worker waits.
15
const MAX_WORKERS = 4;
16
const MAX_IDLE_WORKERS = 1;
17
@@ -528,9 +530,12 @@ export const layer = Layer.unwrap(
530
}),
531
);
532
531
-/** Only Windows creates processes slowly enough on the calling thread to need workers. */
533
+/** Workers on Windows, and on Linux where `NonBlockingSpawner` has no GNU `env -C` to use. */
534
export const layerServer = Layer.unwrap(
533
- Effect.map(HostProcess.Platform, (platform) =>
534
- platform === "win32" ? layer : NodeChildProcessSpawner.layer,
535
- ),
535
+ Effect.gen(function* () {
536
+ const platform = yield* HostProcess.Platform;
537
+ if (platform === "win32") return layer;
538
+ if (platform === "linux" && !(yield* Effect.promise(supportsEnvChdir))) return layer;
539
+ return NodeChildProcessSpawner.layer;
540
+ }),
541
);