@devries-cameron20 / t3code Mirror · read-only / commits / 5c72faa773
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 22, 04:30 UTC

fix(pi): send SIGTERM before closing Pi's stdin on teardown (#30025)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

yaacovcorcos committed Nov 4, 2026 at 01:43 UTC 5c72faa7731a9eab49094a863e83ba9df8d936c9
2 files changed +34
packages/provider-pi/src/server/adapter.test.ts
+32
@@ -4738,3 +4738,35 @@ describe("PiRpc early process exit", () => {
4738 }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
4739 );
4740 });
4741 +
4742 +describe("PiRpc teardown", () => {
4743 + // Like pi, quits once stdin ends; it survives SIGTERM, so teardown's SIGKILL ends it otherwise.
4744 + const recordShutdownCues = `
4745 +const fs = require("node:fs");
4746 +const note = (cue) => fs.appendFileSync(process.argv[1], cue + "\\n");
4747 +process.on("SIGTERM", () => note("SIGTERM"));
4748 +process.stdin.on("end", () => note("stdin end")).resume();
4749 +process.stdout.write('{"type":"ready"}\\n');
4750 +`;
4751 +
4752 + it.live.skipIf(HostProcess.Platform.defaultValue() === "win32")(
4753 + "signals pi before its stdin reaches EOF",
4754 + () =>
4755 + Effect.gen(function* () {
4756 + const fileSystem = yield* FileSystem.FileSystem;
4757 + const cuesPath = `${yield* fileSystem.makeTempDirectoryScoped()}/cues`;
4758 + yield* Effect.gen(function* () {
4759 + const connection = yield* makePiRpcConnection({
4760 + command: process.execPath,
4761 + args: ["-e", recordShutdownCues, cuesPath],
4762 + cwd: undefined,
4763 + env: {},
4764 + });
4765 + assert.equal((yield* Queue.take(connection.events))["type"], "ready");
4766 + }).pipe(Effect.scoped);
4767 +
4768 + const cues = (yield* fileSystem.readFileString(cuesPath)).split("\n").filter(Boolean);
4769 + assert.deepEqual(cues, ["SIGTERM"]);
4770 + }).pipe(Effect.provide(NodeServices.layer)),
4771 + );
4772 +});
packages/provider-pi/src/server/rpc.ts
+2
@@ -199,6 +199,8 @@ export const makePiRpcConnection = Effect.fnUntraced(function* (options: PiRpcSp
199 extendEnv: false,
200 shell: spawnCommand.shell,
201 detached: platform !== "win32",
202 + // On stdin EOF Pi quits without its SIGTERM handler, so the later SIGTERM kills it mid-cleanup.
203 + stdin: { stream: "pipe", endOnDone: false },
204 }),
205 )
206 .pipe(Effect.mapError((cause) => new PiRpcError({ operation: "spawn", cause })));