From 31fd5d93427583439d5381df893efcde592ab3c4 Mon Sep 17 00:00:00 2001 From: Kiet Ho Date: Sun, 23 Aug 2026 21:30:04 -0700 Subject: [PATCH 1/4] fix(cli): await the stdout flush so large --json output isn't truncated at exit Claude-Session: https://claude.ai/code/session_01SudpHaYT4rQ1msxeVpWwC1 --- packages/cli-framework/src/runner.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/cli-framework/src/runner.ts b/packages/cli-framework/src/runner.ts index a9b21ee2574..6812171e094 100644 --- a/packages/cli-framework/src/runner.ts +++ b/packages/cli-framework/src/runner.ts @@ -400,6 +400,19 @@ async function execute( json: isJson, quiet: isQuiet, }); - if (output) console.log(output); + if (output) await writeStdout(`${output}\n`); } } + +/** + * console.log queues pipe writes asynchronously; when the process exits while + * the reader is slow, Bun drops the still-queued tail, truncating output + * beyond ~64KB (seen with `superset tasks list --json | jq` and `$(...)` + * capture). Awaiting the write callback keeps the process alive until the + * whole payload reaches the pipe. + */ +function writeStdout(text: string): Promise { + return new Promise((resolve, reject) => { + process.stdout.write(text, (error) => (error ? reject(error) : resolve())); + }); +} From 391ea47f9c61235a8228a3475e3de784e1c79862 Mon Sep 17 00:00:00 2001 From: Kiet Ho Date: Sun, 23 Aug 2026 21:41:10 -0700 Subject: [PATCH 2/4] fix(cli): drain stderr the same way before exiting on error Claude-Session: https://claude.ai/code/session_01SudpHaYT4rQ1msxeVpWwC1 --- packages/cli-framework/src/runner.ts | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/packages/cli-framework/src/runner.ts b/packages/cli-framework/src/runner.ts index 6812171e094..ddb97532d47 100644 --- a/packages/cli-framework/src/runner.ts +++ b/packages/cli-framework/src/runner.ts @@ -41,7 +41,7 @@ export async function run(opts: RunOptions): Promise { try { await execute(opts, opts.tree, ac.signal); } catch (error) { - handleError(error, opts.name); + await handleError(error, opts.name); } finally { process.off("SIGINT", onSignal); process.off("SIGTERM", onSignal); @@ -108,10 +108,15 @@ export function formatError( return { message: String(error) }; } -function handleError(error: unknown, cliName: string): never { +async function handleError(error: unknown, cliName: string): Promise { const { message, hint } = formatError(error, cliName); - process.stderr.write(`Error: ${message}\n`); - if (hint) process.stderr.write(`Hint: ${hint}\n`); + // Same drain rule as stdout (see writeStream): exiting before the pipe + // reader catches up would drop the message. Best effort; a failed stderr + // write must not mask the exit code. + await writeStream(process.stderr, `Error: ${message}\n`).catch(() => {}); + if (hint) { + await writeStream(process.stderr, `Hint: ${hint}\n`).catch(() => {}); + } process.exit(1); } @@ -400,7 +405,9 @@ async function execute( json: isJson, quiet: isQuiet, }); - if (output) await writeStdout(`${output}\n`); + // All command output must leave through writeStream; a bare console.log + // here reintroduces truncation for any payload past the pipe buffer. + if (output) await writeStream(process.stdout, `${output}\n`); } } @@ -411,8 +418,8 @@ async function execute( * capture). Awaiting the write callback keeps the process alive until the * whole payload reaches the pipe. */ -function writeStdout(text: string): Promise { +function writeStream(stream: NodeJS.WriteStream, text: string): Promise { return new Promise((resolve, reject) => { - process.stdout.write(text, (error) => (error ? reject(error) : resolve())); + stream.write(text, (error) => (error ? reject(error) : resolve())); }); } From 3f8901fc557da88396531756b7c4505e4093b827 Mon Sep 17 00:00:00 2001 From: Kiet Ho Date: Mon, 24 Aug 2026 07:26:43 -0700 Subject: [PATCH 3/4] fix(cli): let SIGINT/SIGTERM abort a drain-write stuck on a full pipe Claude-Session: https://claude.ai/code/session_01SudpHaYT4rQ1msxeVpWwC1 --- packages/cli-framework/src/runner.ts | 43 +++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/packages/cli-framework/src/runner.ts b/packages/cli-framework/src/runner.ts index ddb97532d47..d6123ecca73 100644 --- a/packages/cli-framework/src/runner.ts +++ b/packages/cli-framework/src/runner.ts @@ -41,7 +41,7 @@ export async function run(opts: RunOptions): Promise { try { await execute(opts, opts.tree, ac.signal); } catch (error) { - await handleError(error, opts.name); + await handleError(error, opts.name, ac.signal); } finally { process.off("SIGINT", onSignal); process.off("SIGTERM", onSignal); @@ -108,14 +108,22 @@ export function formatError( return { message: String(error) }; } -async function handleError(error: unknown, cliName: string): Promise { +async function handleError( + error: unknown, + cliName: string, + signal?: AbortSignal, +): Promise { const { message, hint } = formatError(error, cliName); // Same drain rule as stdout (see writeStream): exiting before the pipe // reader catches up would drop the message. Best effort; a failed stderr // write must not mask the exit code. - await writeStream(process.stderr, `Error: ${message}\n`).catch(() => {}); + await writeStream(process.stderr, `Error: ${message}\n`, signal).catch( + () => {}, + ); if (hint) { - await writeStream(process.stderr, `Hint: ${hint}\n`).catch(() => {}); + await writeStream(process.stderr, `Hint: ${hint}\n`, signal).catch( + () => {}, + ); } process.exit(1); } @@ -407,7 +415,7 @@ async function execute( }); // All command output must leave through writeStream; a bare console.log // here reintroduces truncation for any payload past the pipe buffer. - if (output) await writeStream(process.stdout, `${output}\n`); + if (output) await writeStream(process.stdout, `${output}\n`, signal); } } @@ -418,8 +426,29 @@ async function execute( * capture). Awaiting the write callback keeps the process alive until the * whole payload reaches the pipe. */ -function writeStream(stream: NodeJS.WriteStream, text: string): Promise { +function writeStream( + stream: NodeJS.WriteStream, + text: string, + signal?: AbortSignal, +): Promise { return new Promise((resolve, reject) => { - stream.write(text, (error) => (error ? reject(error) : resolve())); + let settled = false; + const settle = (fn: () => void) => { + if (settled) return; + settled = true; + fn(); + }; + stream.write(text, (error) => + settle(() => (error ? reject(error) : resolve())), + ); + // A full pipe whose reader never drains would otherwise wait forever + // and swallow SIGINT/SIGTERM (run() replaces their default exit). On + // abort, stop waiting and let the exit path proceed; losing the tail + // is the right trade once the user asked to stop. + if (signal?.aborted) settle(resolve); + else + signal?.addEventListener("abort", () => settle(resolve), { + once: true, + }); }); } From 3b93326a9c32f33a7686e3e884dfc124d474797a Mon Sep 17 00:00:00 2001 From: Kiet Ho Date: Mon, 24 Aug 2026 08:58:46 -0700 Subject: [PATCH 4/4] refactor(cli): drain the error message and hint in one stderr write Claude-Session: https://claude.ai/code/session_01SudpHaYT4rQ1msxeVpWwC1 --- packages/cli-framework/src/runner.ts | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/packages/cli-framework/src/runner.ts b/packages/cli-framework/src/runner.ts index d6123ecca73..984ec72fdd6 100644 --- a/packages/cli-framework/src/runner.ts +++ b/packages/cli-framework/src/runner.ts @@ -114,17 +114,11 @@ async function handleError( signal?: AbortSignal, ): Promise { const { message, hint } = formatError(error, cliName); + const text = `Error: ${message}\n${hint ? `Hint: ${hint}\n` : ""}`; // Same drain rule as stdout (see writeStream): exiting before the pipe // reader catches up would drop the message. Best effort; a failed stderr // write must not mask the exit code. - await writeStream(process.stderr, `Error: ${message}\n`, signal).catch( - () => {}, - ); - if (hint) { - await writeStream(process.stderr, `Hint: ${hint}\n`, signal).catch( - () => {}, - ); - } + await writeStream(process.stderr, text, signal).catch(() => {}); process.exit(1); }