Repository navigation
Read registry responses within a size limit and one timeout - #5
Merged
Merged
Conversation
apiGet parsed every registry response whole, with no size limit, and cleared its timeout once headers arrived, so a slow body never timed out. Docs pages were fetched with no timeout at all. A package's metadata can carry 10,000 versions with a 128 KB lpmConfig each, which the server parsed to read about ten fields. Bodies are now read up to 10 MB (the CLI's output limit) under one 30 s timeout that covers the request and the body. A larger body is cancelled and returned as an error without a retry. lpm_browse_source lists at most 2,000 paths and reports the total, since a tarball can hold 20,000 entries. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Findings from independent reviews (Opus 5.5, Sol 6.1) of the first commit:
- An auth or not-found response whose body broke off, stalled or was too
large lost its status, and auth failures were retried. Error bodies are now
read leniently: the status is kept and the body reads as `{}`.
- Decoding the bounded bytes with Buffer kept a byte-order mark, so BOM-led
JSON parsed as `{}`. TextDecoder drops it, as response.text() does.
- The 30 s timeout covered the whole download, so a large body that kept
arriving was cut off. Requests now have an idle timeout, restarted by each
chunk, and a 2-minute total. The size limit is 50 MB, since a package
document can legitimately pass 10 MB with large lpmConfig values.
- A Retry-After longer than the backoff allows was slept on, up to hours. The
call now returns rate limited instead.
- Bodies of fetch replacements without a stream reader were read unbounded;
Node streams are now bounded too, and only a body-less response uses json().
- lpm_docs search returned an empty success when every matching page failed;
it now returns an error naming them.
- The tree cap cut the alphabetically first 2,000 paths, so whole directories
could vanish, and `path` didn't help. A truncated tree now has a summary by
top-level entry, and with `path` it lists that directory's paths.
- The session cache is bounded at 500 entries.
- Tests now cover each of these, the cancelled body of a retried response,
that a declared oversized body is never read, and lpm_docs.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Findings from re-checks (Opus 5.5, Sol 6.1) of the second commit: - The tree summary stopped at 100 entries without saying so, so a directory could be left out of both the listing and the summary, and a package could hide files from a model browsing it. lpm_browse_source now takes a treeOffset argument and lists a long tree a page at a time, so every path can be reached, and a truncated summary says so. - Scoping a long tree to `path` was silent, and a `path` with no paths under it gave an empty tree. The scope is now named in treeScope, and an unmatched path lists the whole package with a note. Directory entries in the tree aren't counted as files, and slashes are trimmed with a loop instead of a trailing-run pattern. - The 2-minute total timeout applied per attempt, so a trickling server held a call for about 6 minutes. It now spans the retries, and a retry isn't waited out past it. Body reads also race the abort signal, so a fetch replacement whose reads ignore it can't hang a call. - MemoryCache rejected nothing for maxEntries, and 0 looped forever. - lpm_docs names the pages it couldn't read after the ones it could. - The Retry-After test no longer depends on wall-clock time. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Bounds how much of a registry response the server reads, and for how long. Two independent reviews (Opus 5.5 and Sol 6.1) of the first commit found regressions and gaps, which the second commit fixes; re-checks of the second found more, which the third fixes.
Problem
apiGetparsed every response withresponse.json(), with no size limit, on the server's only thread.lpm_docshad no timeout at all.lpm_browse_sourcepassed the whole tree to the model, up to 20,000 entries.The server is a local stdio process for one user, so the impact is limited to that user's session.
Change
Response was larger than 50 MBwithout a retry.lpmConfig), and parsing 50 MB takes about 80 ms.json().data: {}, without a retry.TextDecoder, which drops a leading byte-order mark asresponse.text()does.Retry-After: a request to wait longer than the backoff allows (10 s) returns rate limited instead of sleeping, which could otherwise last hours.lpm_docs: uses the same limits throughtextGet. A search where every matching page failed returns an error naming them, not an empty success, and one where some failed names them after the pages it read.lpm_browse_source: returns the whole tree when it fits, and lists a longer one 2,000 paths at a time.treeOffsetargument gives the next page, and the response says where it starts. Every path can be reached, so a package can't hide a directory behind the limit from a model browsing it.treeTotal,treeOffset,treeTruncated, and atreeSummarycounting files by top-level entry. A summary of more than 100 entries says so.path, a tree too large to list whole is scoped to that directory and names it intreeScope. Apathwith no paths under it lists the whole package and says so.Tests
Responsestreams):Retry-Afterreturns rate limited at once.textGetreads, strips a BOM, rejects oversized bodies and times out.lpm_docstests: page and caching, 404, timeout, index, query, partial failure, all failing, and an unreadable index.treeOffsetis rejected.289eba8.vitest rungives 354 tests in 26 files, all passing.biome check .is clean.🤖 Generated with Claude Code