Repository navigation
fix: bound maxDocumentBytes in bytes while the body is read - #18
Merged
Merged
Conversation
The limit was applied as `text.length` after `response.text()` had already buffered the whole body, so it bounded neither memory nor bytes. The body is now read from its stream, counted in bytes as chunks arrive, and the transfer is cancelled and aborted as soon as the count passes the limit. A response with no stream still falls back to `text()`, but is measured in UTF-8 bytes so the option means one thing either way. Closes #16 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
dmccoystephenson
force-pushed
the
fix/bound-document-bytes-while-reading
branch
from
October 8, 2026 09:19
ebcc9ee to
c209715
Compare
Contributor
Author
|
Self-review rubric (head
Judgment notes:
Do-not-auto-merge check: the changed paths are This review comment was drafted during a Gardener session (https://github.com/Stephenson-Software/gardener). drafted by Claude on behalf of Daniel Stephenson |
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
fetchMarkdowninjs/src/client.tsno longer callsresponse.text()and then comparestext.lengthtomaxDocumentBytes. The body is read fromresponse.bodychunk by chunk, counted in bytes, and the read is cancelled and the request aborted (via the existingAbortController) as soon as the count passes the limit. The oversized remainder is therefore never buffered.TextDecoder, so a multi-byte character split across chunks decodes correctly.text()) falls back totext(), but is measured in UTF-8 bytes withTextEncoder, so the option has one meaning on both paths.js/README.md's Configuration row formaxDocumentBytesnow states that it is counted in bytes and that the read stops at the limit.refuses a document larger than the limit rather than holding it in memorywas renamed torefuses a document larger than the limit: its fake has no stream, so it never could observe memory, which was one of the points raised in maxDocumentBytes is checked against string length after the whole body is read, so it bounds neither bytes nor memory #16.No
Content-Lengthpre-check was added: the streaming count already stops within a chunk of the limit, andContent-Lengthdescribes the encoded transfer rather than the decoded body, so it would be a second, differently-measured limit.Half touched:
js/only.Nothing upstream is quoted back: every new failure path returns
{status: 'unavailable'}, and the cancel rejection is swallowed rather than surfaced. No newthrowis reachable fromfetchMarkdown.Test plan
js (18 | 20 | 22): typecheck,npm test, buildstops reading an oversized body at the limit instead of draining it— a 1000×64-byte stream against a 100-byte limit pulls fewer than 10 chunks, and the request signal is abortedmeasures the limit in bytes, not in string length— 51 ×é(102 bytes) is refused at a 100-byte limit, on both the stream and thetext()-only pathdecodes a character split across chunks when the body is within the limitnodeis not available in the session sandbox, so the local anchor could not run)Closes #16
Issues #5 and #6 were not picked up this cycle: every remaining step on both is an operator action outside this repository (registry credentials, the PyPI trusted publisher, release environments), as recorded on each issue.
This PR description was drafted during a Gardener session (https://github.com/Stephenson-Software/gardener).
🤖 Generated with Claude Code
drafted by Claude on behalf of Daniel Stephenson