Skip to content

fix(opencode): wait for stdout writes before exit so piped JSON is not truncated - #46912

Open
andrescera wants to merge 2 commits into
anomalyco:devfrom
andrescera:fix/cli-stdout-drain
Open

fix(opencode): wait for stdout writes before exit so piped JSON is not truncated#46912
andrescera wants to merge 2 commits into
anomalyco:devfrom
andrescera:fix/cli-stdout-drain

Conversation

@andrescera

Copy link
Copy Markdown

Issue for this PR

Closes #29330

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

export, non-paginated session list (including --format json), and db --format json wrote before process.exit(). Pipes dropped data past 64 KiB with exit 0. The fix waits for process.stdout.write and treats EPIPE as done. TSV and pager paths are untouched.

The pattern also exists in run --format json, models, and debug/*; 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 empty changed exit 5 to 0; head -c 20 exits 0. The stdout test fails before and passes after. Typecheck is clean; failures match dev.

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

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!

…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
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.

opencode export <id> | jq produces truncated / invalid JSON when piped (large sessions)

1 participant