Repository navigation
fix(cli): flush api output before exit - #52955
Shalin-Shah-2002 wants to merge 1 commit into
Conversation
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
|
The following comment was made by an LLM, it may be inaccurate: |
|
Independently checked A 503 response also delivered the complete body through all three readers and retained exit 1 plus the HTTP diagnostic. Closing the helper's pipe after 4 KiB exited 0 without stderr. The five |
Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01HfXsWoKF5h7tmdmyUEw1rD
abe4fed to
6444614
Compare
|
Thanks for the independent verification, @r266-tech! I've rebased onto the latest |
|
Automated PR Cleanup Thank you for contributing to opencode. Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions. This PR was closed because it matched the following cleanup criteria:
PRs created within the last month are not affected by this cleanup. If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate. Thanks again for taking the time to contribute. |
|
This still addresses the API pipe-truncation reports in #60395 and #60231. Please consider reopening it rather than starting a duplicate implementation. Linux/Bun 1.4.4 synthetic validation of this implementation in an integration branch delivered the complete JSON through a real OS pipe, with matching byte count and SHA-256. The unpatched writer truncated the same response despite exiting 0. This is scoped pipe validation, not a claim that the entire upstream suite passed. One behavior is worth reconsidering: if (error) return reject(error);
resolve();The regression can avoid sleeps: spawn a writer blocked on stdin, close its stdout reader, then release stdin. Handle the stream's A tested follow-up preserving this PR's original history is available at matt8s@99e7f1c. The two changed blobs match the successful Linux integration validation, including full Core/CLI tests and compiler checks. No separate duplicate implementation PR was opened. |
Issue for this PR
Fixes #52925
Type of change
What does this PR do?
opencode api getwrote its output withprocess.stdout.write(...)and returned, then the CLI entrypoint calledprocess.exit(). When stdout is a pipe, Bun writes asynchronously, so a large response was cut off mid-flush (always on a 4096 multiple, exit code 0). File redirects are synchronous, which is why they worked.The handler now waits for the write callback via a small
writeStdout()helper (same approachsession listalready uses). The helper ignoresEPIPE, so| headstill exits quietly. I tried flushing with an empty write inindex.tsfirst; Bun calls that callback immediately, so it does nothing.Other handlers (
session export,auth export,stats) have the same pattern. I left them out to keep this PR scoped to the issue.How did you verify your code works?
Bun 1.4.2, real CLI against a local server returning a 600,012-byte response, read through a slow pipe (4 KiB every 5 ms):
Added
src/stdio.test.ts: a slow-reader pipeline assertswriteStdoutdelivers all 600,000 bytes acrossprocess.exit, with a control showing a plainprocess.stdout.writeis truncated.bun test src/stdio.test.ts src/commands/handlers/api.test.tspasses, and lint passes.bun run typecheckinpackages/cliis clean. (An earlier run showed unrelated errors inpackages/core; they came from stale dependencies in my checkout and are gone afterbun install.)Screenshots / recordings
N/A
Checklist
🤖 Generated with Claude Code
https://claude.ai/code/session_01HfXsWoKF5h7tmdmyUEw1rD