The best way to control Claude Code, Codex and more from any computer or phone
fix(server): stop a Codex app-server that ignores SIGTERM (#34461)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
yaacovcorcos committed
Nov 11, 2026 at 23:22 UTC
a8ccf14d06333d5c99b3f90934106a0ea6f76a62
2 files changed
+47
apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts
+43
@@ -60,6 +60,8 @@ import * as Cause from "effect/Cause";
60
import * as PlatformError from "effect/PlatformError";
61
import { TestClock } from "effect/testing";
62
import { ChildProcess, ChildProcessSpawner } from "effect/process";
63
+import * as Scope from "effect/Scope";
64
+import * as HostProcess from "@t3tools/shared/HostProcess";
65
66
import packageJson from "../../../package.json" with { type: "json" };
67
import * as McpProviderSessions from "@t3tools/provider-core/server/McpProviderSessions";
@@ -10231,3 +10233,44 @@ describe("codexDynamicToolOutput", () => {
10233
]);
10234
});
10235
});
10236
+
10237
+describe("CodexAdapterV2 app-server process", () => {
10238
+ it.live.skipIf(HostProcess.Platform.defaultValue() === "win32")(
10239
+ "stops an app-server that ignores SIGTERM within its kill deadline",
10240
+ () =>
10241
+ Effect.gen(function* () {
10242
+ const command = yield* CodexAdapterV2.makeCodexAppServerSpawnCommand({
10243
+ command: "/bin/sh",
10244
+ args: ["-c", "trap '' TERM; echo ready; while :; do sleep 1; done"],
10245
+ });
10246
+ const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
10247
+ const scope = yield* Scope.make();
10248
+ const child = yield* spawner.spawn(command).pipe(Scope.provide(scope));
10249
+ const pid = Number(child.pid);
10250
+ const killGroup = () => {
10251
+ try {
10252
+ process.kill(-pid, "SIGKILL");
10253
+ } catch {}
10254
+ };
10255
+ yield* Effect.addFinalizer(() => Effect.sync(killGroup));
10256
+ yield* child.stdout.pipe(Stream.take(1), Stream.runDrain);
10257
+ // Scope.close cannot be interrupted, so a regression is ended by this rescue instead of
10258
+ // hanging the test; the deadline under test must make it unnecessary.
10259
+ let rescued = false;
10260
+ // oxlint-disable-next-line t3code/no-real-time-wait-in-tests -- a watchdog for a hung child, not a wait for a milestone; it must never fire.
10261
+ const rescue = yield* Effect.sleep("10 seconds").pipe(
10262
+ Effect.andThen(
10263
+ Effect.sync(() => {
10264
+ rescued = true;
10265
+ killGroup();
10266
+ }),
10267
+ ),
10268
+ Effect.forkChild,
10269
+ );
10270
+ yield* Scope.close(scope, Exit.void);
10271
+ yield* Fiber.interrupt(rescue);
10272
+ assert.isFalse(rescued, "the app-server was stopped by its own kill deadline");
10273
+ assert.isFalse(yield* child.isRunning.pipe(Effect.orElseSucceed(() => true)));
10274
+ }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
10275
+ );
10276
+});
apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts
+4
@@ -1485,6 +1485,9 @@ const decodeCodexChildThread = Schema.decodeUnknownEffect(
1485
}),
1486
);
1487
1488
+// Without a deadline the spawner waits indefinitely for a process that ignores SIGTERM.
1489
+const CODEX_APP_SERVER_FORCE_KILL_AFTER = "2 seconds";
1490
+
1491
export const makeCodexAppServerSpawnCommand = Effect.fn(
1492
"CodexAdapterV2.makeCodexAppServerSpawnCommand",
1493
)(function* (input: {
@@ -1512,6 +1515,7 @@ export const makeCodexAppServerSpawnCommand = Effect.fn(
1515
...(input.env === undefined ? {} : { env: input.env }),
1516
...(input.extendEnv === undefined ? {} : { extendEnv: input.extendEnv }),
1517
shell: spawnCommand.shell,
1518
+ forceKillAfter: CODEX_APP_SERVER_FORCE_KILL_AFTER,
1519
});
1520
});
1521