Fix transient memory amplification in batch_get_documents_tool#4
Merged
mattpodwysocki merged 1 commit intomainfrom Mar 9, 2026
Merged
Fix transient memory amplification in batch_get_documents_tool#4mattpodwysocki merged 1 commit intomainfrom
mattpodwysocki merged 1 commit intomainfrom
Conversation
Intra-batch cache-busting URLs (e.g. 20 variants of the same normalized URL) previously triggered 20 concurrent HTTP fetches and 20 buffered response bodies before the cache could help. - Deduplicate by normalized URL within a batch: one in-flight fetch per unique normalized key; duplicate inputs share the same Promise - Add readBodyWithLimit: checks Content-Length before reading and aborts the stream if the body exceeds the 2 MB cache entry limit - Apply the same body size cap to get_document_tool - Add 6 tests covering deduplication, size limits, and error paths Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Valiunia
approved these changes
Mar 9, 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 cache fix bounded persistent memory growth but left a transient amplification path open: a batch of 20 URLs that all normalize to the same page would still trigger 20 concurrent HTTP fetches and buffer 20 response bodies before the cache could help.
Promise— so 20 cache-busting variants of one URL result in exactly 1 HTTP request, not 20.readBodyWithLimit): checksContent-Lengthupfront and rejects before reading; ifContent-Lengthis absent, aborts the stream as soon as accumulated bytes exceed the 2 MB limit. Avoids buffering oversized responses entirely.get_document_tool.Test plan
test/tools/batch-get-documents-tool/BatchGetDocumentsTool.test.tsContent-Lengthover limit → per-URL error, batch continues🤖 Generated with Claude Code