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) 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