Merge pull request #1704 from kaitranntt/kai/fix/delegation-stdout-flush

fix(delegation): flush stdout before exit to prevent piped output truncation
This commit is contained in:
Kai (Tam Nhu) Tran authored and GitHub committed 2026-08-19 16:32:20 -04:00
commit e10577804d
1 file changed
+13 -2
+13 -2
View File
@@ -35,6 +35,17 @@ function isFlag(arg: string): boolean {
return arg.startsWith('-');
}
/**
* Write to stdout and wait for the flush to complete.
* process.exit() right after a large piped write truncates output at the
* pipe buffer (~64 KiB), so delegation results must be drained first.
*/
function writeStdoutAndFlush(text: string): Promise<void> {
return new Promise((resolve) => {
process.stdout.write(text + '\n', () => resolve());
});
}
function isInlineCcsValueFlag(arg: string): boolean {
return Array.from(CCS_FLAGS_WITH_VALUE).some(
(flag) => flag.startsWith('--') && arg.startsWith(`${flag}=`)
@@ -147,7 +158,7 @@ export class DelegationHandler {
// 5. Format and display results
const formatted = await ResultFormatter.format(result);
console.log(formatted);
await writeStdoutAndFlush(formatted);
// 6. Exit with proper code
process.exit(result.exitCode || 0);
@@ -192,7 +203,7 @@ export class DelegationHandler {
});
const formatted = await ResultFormatter.format(result);
console.log(formatted);
await writeStdoutAndFlush(formatted);
process.exit(result.exitCode || 0);
}