fix(cli): stream UTF-8 reads in read tool again#10077
Merged
chrarnoldus merged 2 commits intomainfrom May 8, 2026
Merged
Conversation
Contributor
Author
Code Review SummaryStatus: 1 Issue Found | Recommendation: Address before merge Overview
Issue Details (click to expand)WARNING
Previously Resolved
Files Reviewed (3 files)
Reviewed by claude-sonnet-4.6 · 395,357 tokens |
35d9ed1 to
3982ec3
Compare
Optimistically stream the file as UTF-8 -- the common case -- using a fatal-mode TextDecoder so the read tool can stop pulling bytes from disk once the line / 50KB byte cap is hit. Only fall back to a full-buffer iconv decode when the bytes turn out not to be valid UTF-8. The streaming + retry logic lives in a new kilo helper (packages/opencode/src/kilocode/text-stream.ts) so the read tool's `lines` function stays close to upstream OpenCode shape.
3982ec3 to
1cf0943
Compare
When the consumer (readLines) hits the line/byte cap and destroys the PassThrough, the underlying createReadStream had no link back and would keep reading chunks to EOF in the background, defeating the early-exit optimisation for large files.
bc5dc59 to
67e9fdc
Compare
catrielmuller
approved these changes
May 8, 2026
kirillk
approved these changes
May 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The previous `lines()` always called `Encoding.read`, which buffers the entire file into memory before line splitting -- even for plain UTF-8 files that never needed encoding translation. Bad for large logs and build artifacts that the caller is going to truncate at the line / 50 KB byte cap anyway.
Optimistically stream the file as UTF-8 using a fatal-mode `TextDecoder` (with `{ stream: true }` for partial multibyte sequences across chunk boundaries). Only fall back to the iconv full-file decode when the bytes turn out not to be valid UTF-8.
The streaming + retry logic lives in a new helper at `packages/opencode/src/kilocode/text-stream.ts` so the `lines` function in `tool/read.ts` stays close to upstream OpenCode's shape.