Skip to content

fix: wait for stdout to flush in generate command - #3821

Merged
rekram1-node merged 1 commit into
anomalyco:devfrom
pagerguild:fix/generate-stdout-flush
Nov 3, 2025
Merged

fix: wait for stdout to flush in generate command#3821
rekram1-node merged 1 commit into
anomalyco:devfrom
pagerguild:fix/generate-stdout-flush

Conversation

@tylergannon

Copy link
Copy Markdown
Contributor

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

Prevents truncation of OpenAPI spec output at 64KB when piping to jq/yq.
The process.exit() call in the finally block was terminating before
stdout could finish flushing asynchronous writes to the pipe.

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
@rekram1-node
rekram1-node merged commit 7652a96 into anomalyco:dev Nov 3, 2025
3 checks passed
xywsxp pushed a commit to xywsxp/opencode that referenced this pull request Apr 24, 2026
Rwanbt pushed a commit to Rwanbt/opencode that referenced this pull request May 5, 2026
AIALRA-0 pushed a commit to AIALRA-0/opencode-turn-engine that referenced this pull request Jun 10, 2026
AIALRA-0 pushed a commit to AIALRA-0/opencode-turn-engine that referenced this pull request Jun 10, 2026
avion23 pushed a commit to avion23/opencode that referenced this pull request Jun 10, 2026
Rwanbt pushed a commit to Rwanbt/opencode that referenced this pull request Jun 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants