Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: keep execFile's per-stream maxBuffer limit on probe stderr (#10604)
[._.]/ Adam Eivy718764336735
diff --git a/server/lib/commandExists.js b/server/lib/commandExists.jsindex 636323ba4c..6fe28e19d9 100644--- a/server/lib/commandExists.js+++ b/server/lib/commandExists.js@@ -39,7 +39,7 @@ const PROBE_KILL_GRACE_MS = 2_000;* `killProcessTree` takes the whole `cmd.exe` shim tree with `taskkill /T`;* on POSIX the child runs in its own process group (`detached`), which gets* SIGTERM and, after a short grace, SIGKILL for anything in it still alive.- * Output past `maxBuffer` fails the probe the same way. Every event after the+ * Output past `maxBuffer` on either stream fails the probe the same way. Every event after the* result is fixed — a late `error`, `close` or chunk — is ignored, and a* failure to signal or to clean up never replaces the result.*@@ -98,14 +98,13 @@ function runProbe({ prepareCliSpawn, killProcessTree, IS_WIN32 }, cmd, args, proconst child = spawn(launch.command, launch.args, {env: probeEnv,...(cwd === undefined ? {} : { cwd }),- stdio: ['ignore', 'pipe', 'ignore'],+ stdio: ['ignore', 'pipe', 'pipe'],// A POSIX process group is what lets the deadline reach the CLI's own// children; on Windows `detached` would open a console, and taskkill /T// already covers the tree.detached: !IS_WIN32,});const chunks = [];- let bytes = 0;let settled = false;let deadline = null;@@ -140,16 +139,23 @@ function runProbe({ prepareCliSpawn, killProcessTree, IS_WIN32 }, cmd, args, proescalation.unref?.();};- child.stdout?.on('data', (chunk) => {- if (settled) return;- bytes += chunk.length;- if (bytes > maxBuffer) {- terminate();- settle(null);- return;- }- chunks.push(chunk);- });+ // Each stream is held to maxBuffer separately, as execFile did; stderr is+ // only counted, never kept.+ const capStream = (stream, keep) => {+ let bytes = 0;+ stream?.on('data', (chunk) => {+ if (settled) return;+ bytes += chunk.length;+ if (bytes > maxBuffer) {+ terminate();+ settle(null);+ return;+ }+ keep?.(chunk);+ });+ };+ capStream(child.stdout, (chunk) => chunks.push(chunk));+ capStream(child.stderr);// Both listeners stay attached after settling so a late `error` (e.g. a// failed kill) never becomes an unhandled emitter error.child.on('error', () => settle(null));diff --git a/server/lib/commandExists.test.js b/server/lib/commandExists.test.jsindex 2149530c13..58caf24807 100644--- a/server/lib/commandExists.test.js+++ b/server/lib/commandExists.test.js@@ -7,6 +7,7 @@ import { existsSync } from 'node:fs'const fakeChild = (script) => {const child = new EventEmitter()child.stdout = new EventEmitter()+ child.stderr = new EventEmitter()child.exitCode = nullchild.signalCode = nullchild.kill = vi.fn()@@ -182,9 +183,12 @@ describe('commandOutput lifecycle (#10604)', () => {await expect(commandOutput('tool')).resolves.toBeNull()})- it('fails a probe whose output exceeds maxBuffer and terminates the child', async () => {+ it.each(['stdout', 'stderr'])('fails a probe whose %s exceeds maxBuffer and terminates the child', async (stream) => {let child- spawnMock.impl = () => (child = fakeChild((c) => c.stdout.emit('data', Buffer.alloc(32, 'x'))))+ spawnMock.impl = () => (child = fakeChild((c) => {+ c[stream].emit('data', Buffer.alloc(32, 'x'))+ exitWith('')(c)+ }))await expect(commandOutput('chatty', [], { maxBuffer: 16 })).resolves.toBeNull()expect(child.kill).toHaveBeenCalledWith('SIGTERM')})