fix(opencode): wait for stdout writes before exit so piped JSON is not truncated - #46912
Open
andrescera wants to merge 2 commits into
Open
fix(opencode): wait for stdout writes before exit so piped JSON is not truncated#46912andrescera wants to merge 2 commits into
andrescera wants to merge 2 commits into
Conversation
…t truncated export, session list --format json and db --format json wrote their JSON and returned; src/index.ts then calls process.exit() and, when stdout is a pipe, anything still queued past the pipe buffer is dropped with exit code 0. Wait for the write callback (as generate.ts already does) before returning, and treat EPIPE as done so | head exits cleanly. Closes anomalyco#29330
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #29330
Type of change
What does this PR do?
export, non-paginatedsession list(including--format json), anddb --format jsonwrote beforeprocess.exit(). Pipes dropped data past 64 KiB with exit 0. The fix waits forprocess.stdout.writeand treats EPIPE as done. TSV and pager paths are untouched.The pattern also exists in
run --format json,models, anddebug/*; this stays with #29330’s three commands. It builds on #3049, #39577, and #26389.How did you verify your code works?
Bun 1.3.14, Linux: the CTE pipe produced 65536 before and 388896 after, equal to redirect.
jq emptychanged exit 5 to 0;head -c 20exits 0. The stdout test fails before and passes after. Typecheck is clean; failures match dev.Screenshots / recordings
Not a UI change.
Checklist
If you do not follow this template your PR will be automatically rejected.
If you paste a large clearly AI generated description here your PR may be IGNORED or CLOSED!