Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

opencode api truncates large output when stdout is a pipe (un-awaited write before process.exit)

Đã đóng Phù hợp với người mới
#57,816 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
72/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
bun, typescript
Lĩnh vực
cli

Hướng nghiên cứu

Đọc packages/cli/src/commands/handlers/api.ts và packages/cli/src/index.ts để theo dõi thao tác ghi vào stdout và exit tap. Tái hiện bằng cách chuyển opencode api GET /openapi.json qua wc -c, sau đó kiểm tra xem toàn bộ đầu ra có được ghi trước khi thoát hay không. Sự cố được khắc phục khi đầu ra qua pipe đầy đủ và CLI thoát thành công.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

pending close triaging

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 reads response.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.exit discards 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.

Ngôn ngữ chính
TypeScript
Star
215k
Fork
28.9k
Merge trung bình
4 giờ 21 phút
Pull request đã merge (30 ngày)
476

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của anomalyco/opencode

Tất cả issue của anomalyco/opencode

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.