opencode api truncates large output when stdout is a pipe (un-awaited write before process.exit)
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 72/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- bun, typescript
- Domain
- cli
Research direction
Read packages/cli/src/commands/handlers/api.ts and packages/cli/src/index.ts to trace the stdout write and the exit tap. Reproduce by piping opencode api GET /openapi.json to wc -c, then check that the full output is written before exit. The issue is done when piped output is complete and the CLI exits successfully.
Written by the indexing model from the issue text.
Description
Version: opencode v2.0.32 (source read at that tag); the same write is still on the default branch
(packages/cli/src/commands/handlers/api.ts:46, fetched 2026-10-21).
Reproduce
for i in $(seq 10); do opencode api GET /openapi.json | wc -c; done # 280292 bytes expected
opencode api GET /openapi.json > out.json; wc -c out.json # always 280292
Piped, the count stops at exactly 262144 with exit status 0 in 1 of 8 and 4 of 10 runs (Linux, v2.0.32).
Redirected to a file it is complete every time. The silent exit 0 is what makes it hard to notice.
Cause (v2.0.32)
packages/cli/src/commands/handlers/api.ts:45-46: the handler readsresponse.text()and calls
process.stdout.write(output + ...)once, with no callback and no drain.packages/cli/src/index.ts:139:Effect.tap(() => Effect.sync(() => process.exit(process.exitCode ?? 0)))
runs right after the handler.- Under Bun a write to a pipe larger than the pipe buffer is asynchronous, so
process.exitdiscards what
the reader has not drained. A write to a file is synchronous, hence complete. 262144 is the pipe buffer
size, not a number in the source.
Suggested fix: wait for the write before exiting, e.g.
yield* Effect.promise(() => new Promise<void>((done) => process.stdout.write(out, () => done())))
in the handler, or have the exit tap wait for stdout to drain.
Workaround we use: redirect stdout to a file, never a pipe.
- Dominant language
- TypeScript
- Stars
- 215k
- Forks
- 28.9k
- Avg merge
- 4h 21m
- Merged PRs (30d)
- 476
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from anomalyco/opencode
-
reproduced
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
anomalyco/opencode#58247 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
anomalyco/opencode#58216 · 1 comment ·
Maintainers usually reply within 1 day
-
pending close triaging
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
anomalyco/opencode#58181 · 1 comment ·
Maintainers usually reply within 1 day
-
Opencde Github Actions Bot Cannot InstallPossibly taken @zzz-creator claimed this today. Openreproduced
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
anomalyco/opencode#57911 · 2 comments ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
anomalyco/opencode#57855 · 1 comment ·
Maintainers usually reply within 1 day
All issues in anomalyco/opencode
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
db-ux-design-system/core-web#8613 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
bug:new
Difficulty 1/5 Under an hour Newbie friendliness 78/100
callstackincubator/simlock#934 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
gchq/LD-Explorer#286 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
foxglove/mcap#1907 · 1 comment ·
Maintainers usually reply within 1 day