@devries-cameron20 / t3code Mirror · read-only / commits / 77d3358a1f
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, 14:45 UTC

fix(server): ACP teardown survives processes exiting during the /proc scan (#36719)

Julius Marminge committed Nov 14, 2026 at 04:56 UTC 77d3358a1f6f49a6a0da05d815c52ddf0485caee
2 files changed +32 -3
apps/server/src/provider/acp/AcpSessionRuntime.processTree.test.ts
+28
@@ -1,6 +1,7 @@
1 // @effect-diagnostics nodeBuiltinImport:off
2 import * as NodeChildProcess from "node:child_process";
3 import * as NodeFS from "node:fs";
4 +import * as NodeModule from "node:module";
5 import * as NodePath from "node:path";
6
7 import { describe, expect, it, vi } from "@effect/vitest";
@@ -813,6 +814,33 @@ describe("terminatePosixOwnedProcessTree", () => {
814 }),
815 );
816
817 + it.skipIf(HostProcess.Platform.defaultValue() !== "linux")(
818 + "snapshots /proc when a process exits while its entry is being typed",
819 + () => {
820 + const fs = NodeModule.createRequire(import.meta.url)("node:fs") as typeof NodeFS;
821 + const realReaddirSync = fs.readdirSync;
822 + // Node lstat()s a dirent of unknown type; a process that exits meanwhile makes it throw.
823 + fs.readdirSync = ((path: NodeFS.PathLike, options?: unknown) => {
824 + if (path === "/proc" && typeof options === "object" && options !== null) {
825 + throw Object.assign(new Error("ENOENT: no such file or directory, lstat '/proc/4563'"), {
826 + code: "ENOENT",
827 + syscall: "lstat",
828 + path: "/proc/4563",
829 + });
830 + }
831 + return Reflect.apply(realReaddirSync, fs, [path, options]);
832 + }) as typeof NodeFS.readdirSync;
833 + NodeModule.syncBuiltinESMExports();
834 + try {
835 + const snapshot = AcpSessionRuntime.makePosixProcessTreeController("linux").snapshot();
836 + expect(snapshot.some((entry) => entry.pid === process.pid)).toBe(true);
837 + } finally {
838 + fs.readdirSync = realReaddirSync;
839 + NodeModule.syncBuiltinESMExports();
840 + }
841 + },
842 + );
843 +
844 it("fails closed where a stable POSIX identity provider is unavailable", () => {
845 try {
846 AcpSessionRuntime.makePosixProcessTreeController("darwin");
packages/provider-acp/src/server/AcpSessionRuntime.ts
+4 -3
@@ -623,9 +623,10 @@ function makeLinuxProcessTreeController(): AcpPosixProcessTreeController {
623 }),
624 identity: readLinuxProcessIdentity,
625 snapshot: () =>
626 - NodeFS.readdirSync("/proc", { withFileTypes: true }).flatMap((entry) => {
627 - if (!entry.isDirectory() || !/^[1-9][0-9]*$/.test(entry.name)) return [];
628 - const identity = readLinuxProcessIdentity(Number(entry.name));
626 + // By name only: withFileTypes lstats entries, which throws when a process exits mid-scan.
627 + NodeFS.readdirSync("/proc").flatMap((entry) => {
628 + if (!/^[1-9][0-9]*$/.test(entry)) return [];
629 + const identity = readLinuxProcessIdentity(Number(entry));
630 return identity === undefined ? [] : [identity];
631 }),
632 signalProcess: (pid, signal) => process.kill(pid, signal),