The best way to control Claude Code, Codex and more from any computer or phone
fix(server): stop Windows terminal processes when closing (#10771)
Dara Adedeji committed
Sep 8, 2026 at 11:50 UTC
47eed9face4186635488fba5f2494eddd13f6491
2 files changed
+49
-11
apps/server/src/terminal/NodePtyAdapter.test.ts
+43
-8
@@ -21,15 +21,50 @@ const spawn = vi.fn(() => ({
21
22
vi.mock("node-pty", () => ({ spawn }));
23
24
-const testLayer = NodePtyAdapter.layer.pipe(
25
- Layer.provide(
26
- Layer.mergeAll(
27
- NodeServices.layer,
28
- Layer.succeed(HostProcessPlatform, "win32"),
29
- Layer.succeed(HostProcessArchitecture, "x64"),
24
+const makeTestLayer = (platform: NodeJS.Platform = "win32") =>
25
+ NodePtyAdapter.layer.pipe(
26
+ Layer.provide(
27
+ Layer.mergeAll(
28
+ NodeServices.layer,
29
+ Layer.succeed(HostProcessPlatform, platform),
30
+ Layer.succeed(HostProcessArchitecture, "x64"),
31
+ ),
32
),
31
- ),
32
-);
33
+ );
34
+
35
+const testLayer = makeTestLayer();
36
+
37
+for (const platform of ["win32", "linux", "darwin"] as const) {
38
+ it.effect(`terminates through node-pty using ${platform} semantics`, () =>
39
+ Effect.gen(function* () {
40
+ const adapter = yield* PtyAdapter.PtyAdapter;
41
+ const process = yield* adapter.spawn({
42
+ shell: "test-shell",
43
+ cwd: ".",
44
+ cols: 80,
45
+ rows: 24,
46
+ env: {},
47
+ });
48
+ const nativeProcess = spawn.mock.results.at(-1)!.value;
49
+ nativeProcess.kill.mockImplementation((signal?: string) => {
50
+ if (platform === "win32" && signal) {
51
+ throw new Error("Signals not supported on windows.");
52
+ }
53
+ });
54
+
55
+ process.kill("SIGTERM");
56
+ process.kill("SIGKILL");
57
+ process.kill();
58
+
59
+ assert.deepEqual(
60
+ nativeProcess.kill.mock.calls,
61
+ platform === "win32"
62
+ ? [[undefined], [undefined], [undefined]]
63
+ : [["SIGTERM"], ["SIGKILL"], [undefined]],
64
+ );
65
+ }).pipe(Effect.provide(makeTestLayer(platform))),
66
+ );
67
+}
68
69
it.effect("spawns through the public adapter with the provided host references", () =>
70
Effect.gen(function* () {
apps/server/src/terminal/NodePtyAdapter.ts
+6
-3
@@ -69,9 +69,11 @@ const ensureNodePtySpawnHelperExecutable = Effect.fn(function* () {
69
70
class NodePtyProcess implements PtyAdapter.PtyProcess {
71
private readonly process: import("node-pty").IPty;
72
+ private readonly platform: NodeJS.Platform;
73
73
- constructor(process: import("node-pty").IPty) {
74
+ constructor(process: import("node-pty").IPty, platform: NodeJS.Platform) {
75
this.process = process;
76
+ this.platform = platform;
77
}
78
79
get pid(): number {
@@ -87,7 +89,8 @@ class NodePtyProcess implements PtyAdapter.PtyProcess {
89
}
90
91
kill(signal?: string): void {
90
- this.process.kill(signal);
92
+ // node-pty terminates the Windows process tree without a POSIX signal.
93
+ this.process.kill(this.platform === "win32" ? undefined : signal);
94
}
95
96
onData(callback: (data: string) => void): () => void {
@@ -164,7 +167,7 @@ export const make = Effect.fn("NodePtyAdapter.make")(function* (
167
cause,
168
}),
169
});
167
- return new NodePtyProcess(ptyProcess);
170
+ return new NodePtyProcess(ptyProcess, platform);
171
}),
172
});
173
});