Skip to content

Align FileTokenizer partial-read completion - #1361

Merged
Borewit merged 1 commit into
masterfrom
improvement/partial-read-completion
Nov 13, 2026
Merged

Borewit merged 1 commit into
masterfrom
improvement/partial-read-completion

Conversation

@Borewit

@Borewit Borewit commented Nov 13, 2026 •

Copy link
Copy Markdown
Owner

Align FileTokenizer partial-read completion

With mayBeLess: true, FileTokenizer previously returned after a single physical
read, while built-in stream tokenizers combined input fragments. Consequently,
a short result could reflect file-read fragmentation rather than EOF.

Make file buffer reads and peeks fill the requested range or stop at a zero-byte
read. mayBeLess controls whether insufficient input at EOF returns the available
byte count or throws EndOfStreamError; it does not select a single physical read.
Reuse the existing file completion loop so transport fragmentation stays below
token decoding and does not require consumer-specific retry logic.

Preserve method signatures, caller-owned buffers, read-position progress, peek
positioning and zero-length behavior. Other I/O errors still propagate. This
change does not alter file cancellation policy or introduce a shared lifecycle
abstraction. Consumers must still honor the returned count at actual EOF.

Compatibility

Following a short physical read, a file request may now perform additional I/O,
return more bytes and, for reads, advance further. It may also encounter a later
I/O error where it previously returned successfully. The existing public option
allows short results but does not promise one physical read or nonblocking
completion.

Suggested release note

File buffer reads and peeks now combine short physical reads. With
mayBeLess: true, requests fill the requested range or return the available
bytes at EOF instead of stopping at the first short physical read.

Summary by CodeRabbit

  • Bug Fixes
    • Buffer reads and peeks now continue across short transport fragments until the requested range is filled or EOF is reached.
    • When mayBeLess is enabled, a short result is allowed only at EOF; otherwise, an incomplete request at EOF reports an error.
    • Short results indicate how many bytes are valid. Peeks leave the cursor unchanged, while failed reads retain any progress already made.
    • Other I/O errors continue to propagate.

@Borewit Borewit self-assigned this Nov 13, 2026
@Borewit Borewit added the improvement Improvements to existing functionality, usability, or performance. label Nov 13, 2026
@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Buffer reads now continue across short reads until the requested range is filled or EOF occurs. mayBeLess permits a partial result at EOF. Tests cover fragmented streams, partial progress, and I/O errors.

Changes: Buffer Read Semantics

Layer / File(s) Summary
EOF-based short-read behavior
lib/FileTokenizer.ts, lib/stream/AbstractStreamReader.ts, lib/types.ts, README.md
FileTokenizer continues after short reads until the request is filled or a zero-byte read occurs. Documentation describes EOF handling, returned valid bytes, position behavior, and propagation of other I/O errors.
Fragmented-read and partial-progress tests
test/test-buffer-limits.ts, test/test-regular-files.ts
Tests cover fragmented stream input, partial reads and peeks at EOF or after truncation, and errors after partial progress. They check returned counts, destination bytes, and tokenizer positions.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Merge Risk: Minimal · up to bd0b6

This change makes file buffer reads behave like stream reads: they keep reading until the requested range is full or the file ends. It may perform a little more I/O than before, which the PR documents. No merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: FileTokenizer partial-read completion is aligned with the built-in stream tokenizers. The changeset makes FileTokenizer.readBufferAt keep reading after a short read un…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: FileTokenizer partial-read completion is aligned with the built-in stream tokenizers. The changeset makes FileTokenizer.readBufferAt keep reading after a short read until the requested length is filled or EOF is reached, and updates the README, types, and tests to match. The title is specific and does not describe unrelated work.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 29ac38e and bd0b664.

Files selected for processing: 6

  • README.md
  • lib/FileTokenizer.ts
  • lib/stream/AbstractStreamReader.ts
  • lib/types.ts
  • test/test-buffer-limits.ts
  • test/test-regular-files.ts

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@codecov

codecov Bot commented Nov 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.43%. Comparing base (29ac38e) to head (bd0b664).

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Borewit
Borewit merged commit b0bb25a into master Nov 13, 2026
31 checks passed
@Borewit
Borewit deleted the improvement/partial-read-completion branch November 13, 2026 13:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

improvement Improvements to existing functionality, usability, or performance.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant