From 045eabbbf95344cf29963eaf5b73fc5beb63b54d Mon Sep 17 00:00:00 2001 From: David Kay Date: Fri, 20 Mar 2026 23:05:15 -0500 Subject: [PATCH] fix: use fs.writeSync for stdout to prevent pipe truncation process.stdout.write() is async when stdout is a pipe. The immediate process.exit(0) tears down the process before the downstream reader (jq, python3, etc) consumes the buffer, producing truncated JSON. Replace with fs.writeSync(1, data) which blocks until the kernel pipe buffer accepts the bytes, and drop process.exit(0) on the success path so the event loop drains naturally. Fixes #1275 Related: #493 (addressed >50KB case, this fixes <50KB) --- get-shit-done/bin/lib/core.cjs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/get-shit-done/bin/lib/core.cjs b/get-shit-done/bin/lib/core.cjs index a068d9ac6..1fba6f877 100644 --- a/get-shit-done/bin/lib/core.cjs +++ b/get-shit-done/bin/lib/core.cjs @@ -147,8 +147,9 @@ function reapStaleTempFiles(prefix = 'gsd-', { maxAgeMs = 5 * 60 * 1000, dirsOnl } function output(result, raw, rawValue) { + let data; if (raw && rawValue !== undefined) { - process.stdout.write(String(rawValue)); + data = String(rawValue); } else { const json = JSON.stringify(result, null, 2); // Large payloads exceed Claude Code's Bash tool buffer (~50KB). @@ -157,16 +158,20 @@ function output(result, raw, rawValue) { reapStaleTempFiles(); const tmpPath = path.join(require('os').tmpdir(), `gsd-${Date.now()}.json`); fs.writeFileSync(tmpPath, json, 'utf-8'); - process.stdout.write('@file:' + tmpPath); + data = '@file:' + tmpPath; } else { - process.stdout.write(json); + data = json; } } - process.exit(0); + // process.stdout.write() is async when stdout is a pipe — process.exit() + // can tear down the process before the reader consumes the buffer. + // fs.writeSync(1, ...) blocks until the kernel accepts the bytes, and + // skipping process.exit() lets the event loop drain naturally. + fs.writeSync(1, data); } function error(message) { - process.stderr.write('Error: ' + message + '\n'); + fs.writeSync(2, 'Error: ' + message + '\n'); process.exit(1); }