[PR #3821] fix: wait for stdout to flush in generate command #10771

Closed
opened 2026-02-16 18:15:31 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/3821

State: closed
Merged: Yes


Summary

Fixes truncation of OpenAPI spec output at 64KB when piping to jq or yq.

Problem

The generate command was writing JSON output to stdout without waiting for the write to complete. When the process exits via process.exit() in the finally block, stdout buffers are not fully flushed when writing to a pipe, causing output to be truncated at exactly 65,536 bytes (64KB).

Before this fix:

bun run src/index.ts generate | jq
# jq: parse error: Unfinished JSON term at EOF at line 2605, column 2

After this fix:

bun run src/index.ts generate | jq
# Successfully parses full 181KB spec

Solution

Wait for the process.stdout.write() callback to complete before allowing the process to exit. This ensures all buffered data is flushed to the pipe.

Testing

Verified that piping to both jq and yq now works correctly:

  • bun run src/index.ts generate | jq . - parses successfully
  • bun run src/index.ts generate | yq -p json -o yaml - converts successfully
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/3821 **State:** closed **Merged:** Yes --- ## Summary Fixes truncation of OpenAPI spec output at 64KB when piping to `jq` or `yq`. ## Problem The `generate` command was writing JSON output to stdout without waiting for the write to complete. When the process exits via `process.exit()` in the finally block, stdout buffers are not fully flushed when writing to a pipe, causing output to be truncated at exactly 65,536 bytes (64KB). **Before this fix:** ```bash bun run src/index.ts generate | jq # jq: parse error: Unfinished JSON term at EOF at line 2605, column 2 ``` **After this fix:** ```bash bun run src/index.ts generate | jq # Successfully parses full 181KB spec ``` ## Solution Wait for the `process.stdout.write()` callback to complete before allowing the process to exit. This ensures all buffered data is flushed to the pipe. ## Testing Verified that piping to both `jq` and `yq` now works correctly: - `bun run src/index.ts generate | jq .` - ✅ parses successfully - `bun run src/index.ts generate | yq -p json -o yaml` - ✅ converts successfully
yindo added the pull-request label 2026-02-16 18:15:31 -05:00
yindo closed this issue 2026-02-16 18:15:31 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#10771