fix(opencode): await stdout drain so piped output is not truncated - #39577
Draft
jornado wants to merge 1 commit into
Draft
fix(opencode): await stdout drain so piped output is not truncated#39577jornado wants to merge 1 commit into
jornado wants to merge 1 commit into
Conversation
jornado
marked this pull request as ready for review
July 29, 2026 22:43
process.stdout.write() returns false once the pipe buffer is full, and the queued remainder is discarded when the process exits. Commands that print large results lost everything past 64 KiB while still exiting 0. console.log has the same effect and cannot be awaited, so db and session list move to a shared writeStdout() helper that waits for drain. export already used process.stdout.write but never awaited it. db renders TSV in 64 KiB chunks instead of joining the whole table, so the rendered text is not a second copy of an already materialized result set.
jornado
force-pushed
the
fix/stdout-drain
branch
from
July 29, 2026 22:54
0b947b5 to
c88f579
Compare
jornado
marked this pull request as draft
July 29, 2026 22:58
This was referenced Jul 29, 2026
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?
opencode db,session list, andexportsilently lose output past 64 KiB when piped. Exit code stays 0, so it looks like it worked.process.stdout.write()returnsfalseonce the pipe buffer is full. The rest is queued on the stream and thrown away when the process exits.console.logdoes the same thing and gives you nothing to await. That is why #3049 didn't fix it: it movedexporttoprocess.stdout.writebut never waited for the write to be accepted.This adds a small
writeStdout()that waits fordrainwhen the write is refused, and routes the three commands through it. EPIPE resolves instead of waiting for a drain that will never come, so| headstill works.dbalso renders TSV in 64 KiB chunks now. Building the whole table as one string first was a second copy of a result setdb.all()had already materialized.Worth noting the accepted explanation on #29330 is that
process.exit()insrc/index.tsfires before stdout drains. I don't think that's it: removing theprocess.exit()and waiting 2s still truncated at exactly 65536. Backpressure is the part that matters, so I leftprocess.exit()alone.How did you verify your code works?
Repro needs no existing sessions:
Also checked, before -> after:
| head -c 20returns 20 bytes and doesn't hangdb path, exit codes (0 ok / 1 bad SQL) unchangeddb.all()dominates either way.bun typecheckclean.bun testinpackages/opencodehas the same 7 failures before and after (5s timeouts in workspace/snapshot/httpapi/revert tests). Newtest/util/stdout.test.tscovers the large-payload, EPIPE, and short-payload cases, plus a control asserting an unawaited write still truncates so the test can't quietly stop testing anything.Screenshots / recordings
Not a UI change.
Checklist