fix(cli): await the stdout flush so large --json output isn't truncated at exit
Summary
superset <cmd> --json silently truncates large output when stdout is a pipe whose reader is momentarily slow (command substitution, | jq under load). superset tasks list --json (~157KB) reliably comes back cut at a 16KB multiple (81920, 114688, ...), so $(...) capture and jq see unparseable JSON. Redirecting to a file never truncates.
Root cause: the runner prints the result with console.log and returns; nothing awaits the write. Bun queues pipe writes it can't complete immediately, and when the process exits with the reader still catching up, the queued tail is dropped.
Fix: execute() now writes the formatted output via process.stdout.write and awaits its completion callback, keeping the process alive until the whole payload has reached the pipe. One-line call-site change plus a small helper.
Verification
Repro: tasks list --json | (sleep 0.5; cat) | wc -c against a workspace with a full task list (~157KB expected).
| run 1 | run 2 | run 3 | |
|---|---|---|---|
| dev CLI, before | 81920 | 114688 | — |
| dev CLI, after | 157612 | 157612 | 157612 |
| compiled darwin-arm64, after | 157612 | 157612 | 157612 |
out=$(superset tasks list --json) with the fixed binary parses cleanly (jq length = 50); the currently installed CLI truncates on the same machine.
No regression test is included: a hermetic fixture CLI (300KB payload through run(), slow shell reader, with and without a keep-alive fetch) does not reproduce the truncation — the trigger needs something about the full CLI's process state I couldn't isolate. Verified behaviorally as above instead; existing runner.test.ts still passes and tsc --noEmit is clean.
Context
Found while shipping #6762: the standup/10x skill scripts hit this and now capture CLI stdout via a temp file. With this fix that workaround is belt-and-suspenders rather than load-bearing.
https://claude.ai/code/session_01SudpHaYT4rQ1msxeVpWwC1
Summary by cubic
Prevents truncation of large --json output and error messages on slow pipes and ensures prompt exit on interrupt. Previously we returned after unawaited writes and dropped queued bytes; we now await stdout/stderr writes and abort a stuck drain on SIGINT/SIGTERM.
- Replace
console.log(output)with an awaitedwriteStream(process.stdout, ...). - Errors use the same helper and are awaited in
run(), draining the message and hint in onestderrwrite and preserving a non-zero exit even if the write fails. - SIGINT/SIGTERM abort a drain-write stuck on a full pipe so Ctrl-C exits promptly.
- Side effect: under backpressure the process may exit slightly later; interrupted runs may drop the tail by design. File redirects behave the same.
- No migration required; consumers of
--jsonand error output now receive complete payloads when runs complete.
Summary by CodeRabbit
- Bug Fixes
- Improved reliability of command output when writing to slow or buffered streams.
- Commands now respond promptly to cancellation, even when output streams do not drain.
- Improved handling of standard output and error messages during shutdown.
- Error output failures are handled gracefully without interrupting command termination.
- Commands continue to preserve exit code
1when error output cannot be written.