From 5178198f7248ec3d9733f680ddaa5d4f0dc7db5f Mon Sep 17 00:00:00 2001 From: Freeman Date: Fri, 1 May 2026 15:22:46 +0100 Subject: [PATCH 1/3] fix: use process.exitCode in main() to flush help output on pipe MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Apply the same producer-side flush fix from PR #7 to the remaining exits in main(). console.log(USAGE) followed by synchronous process.exit(0) can drop buffered output when stdout is a pipe (e.g. `fullcontext --help | head`). Set process.exitCode and return so the Node runtime exits naturally once the help text has been flushed to the OS. The EPIPE-path process.exit(0) calls in executeCommand's error handlers stay synchronous — those fire when the downstream pipe is already broken and there is nothing to flush. --- src/index.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index a2b9b5f..2408c25 100644 --- a/src/index.ts +++ b/src/index.ts @@ -214,7 +214,12 @@ function main(): void { // Display usage if no arguments provided or help requested if (args.length === 0 || args[0] === '--help' || args[0] === '-h') { console.log(USAGE); - process.exit(0); + // Set exitCode + return rather than process.exit(): when stdout is a + // pipe (e.g. `fullcontext --help | head`), synchronous process.exit + // can drop buffered writes before libuv has flushed them to the OS. + // See the matching pattern in executeCommand's 'close' handler. + process.exitCode = 0; + return; } // Join all arguments into a single command string for shell execution From 4ba2d2fa91b3b79ab3d2f5663dadcb7565642a66 Mon Sep 17 00:00:00 2001 From: Freeman Date: Fri, 1 May 2026 15:23:00 +0100 Subject: [PATCH 2/3] docs: add PR write-up for Fix help-path output truncation when piped --- .../2026-05-01-fix-help-path-flush.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 documentation/PULL_REQUESTS/2026-05-01-fix-help-path-flush.md diff --git a/documentation/PULL_REQUESTS/2026-05-01-fix-help-path-flush.md b/documentation/PULL_REQUESTS/2026-05-01-fix-help-path-flush.md new file mode 100644 index 0000000..f0929e1 --- /dev/null +++ b/documentation/PULL_REQUESTS/2026-05-01-fix-help-path-flush.md @@ -0,0 +1,18 @@ +## Problem + +After PR #7 eliminated one data-loss bug (truncated output when piping large command output), a review noted that the same bug class lingered in our help / version output paths. Someone running `fullcontext --help | head` could theoretically see a truncated help message — the same mechanism as before: our code prints output and then exits synchronously, which on Node doesn't wait for buffered pipe writes to reach the operating system. + +## Solution + +Apply the identical fix to the remaining exits after writes. Tell Node the exit code we want and let the runtime exit naturally once all output has flushed. No new bug, no new test, just the same correct pattern applied consistently. + +## Impact + +- No more silent truncation bugs anywhere in the CLI. +- No behavior change for non-piped usage — exit codes and help output are identical. +- Small follow-up to PR #7; single-file change. + +# Credits + +- Nabs (Architect) +- JENA (Lead Developer) From e2bc238068011194d3bdbc5ecacc6b3989889e34 Mon Sep 17 00:00:00 2001 From: Freeman Date: Fri, 1 May 2026 15:24:16 +0100 Subject: [PATCH 3/3] ci: verify no flakes