You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
opencode api: output piped to another process is truncated (stdout not drained before process.exit) #60231
opencode api loses part of its output when stdout is a pipe. The response body is written with process.stdout.write(...) (packages/cli/src/commands/handlers/api.ts:44), which is asynchronous for pipes, and the
CLI then calls process.exit(process.exitCode ?? 0) right away (packages/cli/src/index.ts:142). Data that has not been
flushed yet is dropped, and the exit status stays 0, so callers get truncated JSON with no error.
Steps to reproduce
With a running server, on a response larger than 64 KB (for example the OpenAPI document):
opencode api get /openapi.json > full.json; wc -c < full.json # complete, valid JSON
opencode api get /openapi.json | wc -c # 262144
opencode api get /openapi.json | (sleep 2; wc -c) # 65536
Expected behavior
The full body reaches the pipe, as it does with a file.
Actual behavior
The output is cut at the pipe buffer size (65536 bytes with a slow reader, 262144 in our runs with a fast one); exit
status 0. Reproducible on every run.
OpenCode version
2.2.1 (source references checked at v2.2.0, same code path)
Operating System
Linux x86_64
Possible fix
Wait for stdout to drain before exiting, for example by passing a callback to the final process.stdout.write and
exiting from it, or by awaiting the drain event when write returns false. Setting process.exitCode and letting
the process end naturally would also avoid it.
Thanks for the detailed report and the analysis of the cause, @sergiopadure! I think this is a duplicate of #52925, which reports the same truncation of opencode api get output when stdout is a pipe (exit code 0, complete when redirected to a file). Your 2.2.1 report confirms it is still present in the latest release.
Possible duplicates and closely related issues, ordered from most to least likely:
The bot will close this issue as a duplicate in 1 day unless you reply explaining how your problem is different. Please add any further findings to #52925.
Closing this as a duplicate of #52925, since there was no reply about how it differs. Thanks again for the report and the analysis, @sergiopadure! Please follow #52925 and its open fix PR #52955. If you have more findings, such as your 2.2.1 results, add them there. If this turns out to be a different problem, reply here and we can reopen it.
Activity
opencodejr commentedon Oct 29, 2026
Thanks for the detailed report and the analysis of the cause, @sergiopadure! I think this is a duplicate of #52925, which reports the same truncation of
opencode api getoutput when stdout is a pipe (exit code 0, complete when redirected to a file). Your 2.2.1 report confirms it is still present in the latest release.Possible duplicates and closely related issues, ordered from most to least likely:
opencode api getoutput truncated when piped; still openapihandler before exitingopencode session export(fix PR fix(cli): flush session exports before exit #57347)opencode --completions fish(PR fix(cli): deliver large stdout writes past one pipe buffer #55893)The bot will close this issue as a duplicate in 1 day unless you reply explaining how your problem is different. Please add any further findings to #52925.
opencodejr commentedon Oct 30, 2026
Closing this as a duplicate of #52925, since there was no reply about how it differs. Thanks again for the report and the analysis, @sergiopadure! Please follow #52925 and its open fix PR #52955. If you have more findings, such as your 2.2.1 results, add them there. If this turns out to be a different problem, reply here and we can reopen it.