@devries-cameron20 / t3code Mirror · read-only / commits / 207fc2c48b
Fork 0

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, 07:15 UTC

fix(server): closing a terminal also stops its background jobs (#34444)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>

Wish committed Nov 19, 2026 at 11:27 UTC 207fc2c48b64e6cf33c01aaea6d4333ba07a5055
2 files changed +38 -1
apps/server/src/terminal/Manager.test.ts
+27 -1
@@ -993,6 +993,29 @@ it.layer(
993 }),
994 );
995
996 + it.effect.each([
997 + ["linux", ["SIGHUP", "SIGTERM"]],
998 + ["win32", ["SIGTERM"]],
999 + ] as const)("closing a %s terminal hangs up the shell's jobs", ([platform, signals]) =>
1000 + Effect.gen(function* () {
1001 + const { manager, ptyAdapter } = yield* createManager(5).pipe(
1002 + Effect.provide(layerWithHostPlatform(platform)),
1003 + );
1004 + yield* manager.open(openInput());
1005 + const shell = ptyAdapter.processes[0]!;
1006 + const terminated = yield* Deferred.make<void>();
1007 + shell.onKill = (signal) => {
1008 + if (signal === "SIGTERM") Deferred.doneUnsafe(terminated, Effect.void);
1009 + };
1010 +
1011 + yield* manager.close({ threadId: "thread-1" });
1012 + yield* Deferred.await(terminated);
1013 +
1014 + expect(shell.killSignals).toEqual(signals);
1015 + shell.emitExit({ exitCode: 0, signal: 0 });
1016 + }).pipe(Effect.provide(TestClock.layer())),
1017 + );
1018 +
1019 it.effect("keeps a terminal whose shell was replaced by exec open on settlement", () =>
1020 Effect.gen(function* () {
1021 const { manager, ptyAdapter } = yield* createManager(5, {
@@ -2790,7 +2813,10 @@ it.layer(
2813 yield* TestClock.adjust("1 second");
2814 yield* Fiber.join(shutdown);
2815
2793 - expect(process.killSignals).toEqual(["SIGTERM", "SIGKILL"]);
2816 + const platform = yield* HostProcess.Platform;
2817 + expect(process.killSignals).toEqual(
2818 + platform === "win32" ? ["SIGTERM", "SIGKILL"] : ["SIGHUP", "SIGTERM", "SIGKILL"],
2819 + );
2820 expect(process.exitListenerCount).toBe(0);
2821 }).pipe(Effect.provide(TestClock.layer())),
2822 );
apps/server/src/terminal/Manager.ts
+11
@@ -2166,6 +2166,17 @@ export const makeWithOptions = Effect.fn("TerminalManager.makeWithOptions")(func
2166 Deferred.doneUnsafe(exited, Effect.void);
2167 });
2168 yield* Effect.gen(function* () {
2169 + // Interactive shells ignore SIGTERM but pass SIGHUP to their background jobs, skipping nohup'd and disowned ones.
2170 + // Windows ignores the signal and node-pty kills the whole tree there.
2171 + if (platform !== "win32") {
2172 + yield* Effect.sync(() => {
2173 + try {
2174 + process.kill("SIGHUP");
2175 + } catch {
2176 + // The SIGTERM below reports a shell that can no longer be signalled.
2177 + }
2178 + });
2179 + }
2180 const terminated = yield* Effect.try({
2181 try: () => process.kill("SIGTERM"),
2182 catch: (cause) =>