From 96b5f889cd2d1fd4a6dd82bed50c23a6844f768e Mon Sep 17 00:00:00 2001 From: "t3-code[bot]" <269035359+t3-code[bot]@users.noreply.github.com> Date: Wed, 12 Aug 2026 20:25:46 +0000 Subject: [PATCH] fix(server): avoid macos path walks in terminal polling Co-authored-by: Exotic <118054752+extoci@users.noreply.github.com> --- apps/server/src/terminal/Manager.test.ts | 47 ++++++++++++++++++++++++ apps/server/src/terminal/Manager.ts | 10 +++-- 2 files changed, 53 insertions(+), 4 deletions(-) diff --git a/apps/server/src/terminal/Manager.test.ts b/apps/server/src/terminal/Manager.test.ts index ed25a0880b..1b9c09340e 100644 --- a/apps/server/src/terminal/Manager.test.ts +++ b/apps/server/src/terminal/Manager.test.ts @@ -24,6 +24,7 @@ import * as Ref from "effect/Ref"; import * as Schedule from "effect/Schedule"; import * as Scope from "effect/Scope"; import * as TestClock from "effect/testing/TestClock"; +import * as ChildProcessSpawner from "effect/unstable/process/ChildProcessSpawner"; import { expect } from "vite-plus/test"; import * as ProcessRunner from "../processRunner.ts"; @@ -953,6 +954,52 @@ it.layer( }), ); + it.effect("uses absolute utility paths for macOS subprocess polling", () => + Effect.gen(function* () { + const calls: ProcessRunner.ProcessRunInput[] = []; + const runner = ProcessRunner.ProcessRunner.of({ + run: (input) => { + calls.push(input); + const stdout = + input.args[0] === "-P" + ? "10001\n" + : input.args[0] === "-eo" + ? "10001 9000\n" + : input.args.includes("comm=") + ? "" + : "/usr/bin/node\n"; + return Effect.succeed({ + stdout, + stderr: "", + code: ChildProcessSpawner.ExitCode(0), + timedOut: false, + stdoutTruncated: false, + stderrTruncated: false, + stdoutInvalidUtf8: false, + stderrInvalidUtf8: false, + }); + }, + }); + + const { manager } = yield* createManager(5, { subprocessPollIntervalMs: 20 }).pipe( + Effect.provideService(ProcessRunner.ProcessRunner, runner), + Effect.provide(withHostPlatform("darwin")), + ); + yield* manager.open(openInput()); + yield* waitFor( + Effect.sync(() => calls.length >= 4), + "1200 millis", + ); + + expect(calls.slice(0, 4).map(({ command }) => command)).toEqual([ + "/usr/bin/pgrep", + "/bin/ps", + "/bin/ps", + "/bin/ps", + ]); + }), + ); + it.effect("caps persisted history to configured line limit", () => Effect.gen(function* () { const { manager, ptyAdapter } = yield* createManager(3); diff --git a/apps/server/src/terminal/Manager.ts b/apps/server/src/terminal/Manager.ts index 6dc9e1892b..5c155d2eb2 100644 --- a/apps/server/src/terminal/Manager.ts +++ b/apps/server/src/terminal/Manager.ts @@ -703,9 +703,11 @@ const posixInspectSubprocess = Effect.fn("terminal.posixInspectSubprocess")(func ProcessRunner.ProcessRunner > { const processRunner = yield* ProcessRunner.ProcessRunner; + const pgrepCommand = platform === "darwin" ? "/usr/bin/pgrep" : "pgrep"; + const psCommand = platform === "darwin" ? "/bin/ps" : "ps"; const runPgrep = processRunner .run({ - command: "pgrep", + command: pgrepCommand, args: ["-P", String(terminalPid)], timeout: "1 second", maxOutputBytes: 32_768, @@ -725,7 +727,7 @@ const posixInspectSubprocess = Effect.fn("terminal.posixInspectSubprocess")(func const runPs = processRunner .run({ - command: "ps", + command: psCommand, args: ["-eo", "pid=,ppid="], timeout: "1 second", maxOutputBytes: 262_144, @@ -776,7 +778,7 @@ const posixInspectSubprocess = Effect.fn("terminal.posixInspectSubprocess")(func } const runComm = processRunner.run({ - command: "ps", + command: psCommand, args: ["-p", String(childPid), "-o", "comm="], timeout: "1 second", maxOutputBytes: 8_192, @@ -792,7 +794,7 @@ const posixInspectSubprocess = Effect.fn("terminal.posixInspectSubprocess")(func if (!rawComm || rawComm.length === 0) { const runArgs = processRunner.run({ - command: "ps", + command: psCommand, args: ["-p", String(childPid), "-o", "args="], timeout: "1 second", maxOutputBytes: 16_384,