Skip to content

Stream npm packuments and tarballs past the buffered response limit - #100

Merged
andrew merged 1 commit into
git-pkgs:mainfrom
charlie-morrison:npm-large-packuments
Nov 27, 2026
Merged

andrew merged 1 commit into
git-pkgs:mainfrom
charlie-morrison:npm-large-packuments

Conversation

@charlie-morrison

Copy link
Copy Markdown
Contributor

Fixes #2.

fetchPackageDoc now decodes the packument through StreamJSON, the way registries' own npm fetcher reads it. That puts it under the client's stream limit (512 MiB) instead of the 10 MiB buffered one. The full document is still fetched, because min_release_age needs time, as the issue says.

fetchTarball had the same problem with its own cap. DefaultMaxTarballBytes is 100 MiB, but GetBody stopped at 10 MiB first, so the cap only applied below that, and a larger MaxTarballBytes changed nothing. It now reads through Stream and io.LimitReader(MaxTarballBytes+1), so MaxTarballBytes is the limit that applies, and an oversized body stops at the cap instead of being read in full. The error is now tarball <url> exceeds cap of N bytes, because the old message printed the number of bytes read, which is no longer the size.

Against registry.npmjs.org, main (690375a) vs this branch:

command main this branch
pin add tailwindcss@^3 response body for https://registry.npmjs.org/tailwindcss exceeds 10485760 bytes resolved 3.4.19
pin outdated (tailwindcss locked) same error 3.4.19 → 4.3.5, behind
pin add three@0.181.0 (12,424,421-byte tarball) response body for …/three-0.181.0.tgz exceeds 10485760 bytes three/three.module.js, pin verify 1 ok

On your separate tailwind point: with the fetch fixed, pin add tailwindcss@^3 doesn't reach the no-entrypoint path. main is picked, and it vendors lib/index.js as tailwindcss/index.js, which is module.exports = require("./plugin"). So it succeeds with a file a browser can't use. I left that alone, since warning on a CommonJS entry point is a design call.

One behaviour difference: GetBody reads the body inside the client's retry loop, and Stream/StreamJSON read it after the response opens, so a connection dropped mid-body is no longer retried for these two calls. registries' npm fetcher makes the same trade for packuments. If you'd rather keep retries, the alternative is WithMaxResponseSize on the client pin builds in client.go, which would raise the buffered limit for every source.

Tests (source/npm/limits_test.go). Most use a client with a 1024-byte buffered limit, so they don't need 10 MiB fixtures:

  • a 300-version packument through ResolveVersion and Status
  • an 11 MiB packument with the default client
  • a packument over a 1024-byte stream limit, which must still fail with ErrResponseTooLarge
  • a tarball over the buffered limit
  • the tarball cap at exactly the tarball's size (passes) and one byte below (fails with the message)
  • an 8 KiB tarball with MaxTarballBytes: 1024 and a 4096-byte stream limit, which must fail on the tarball cap, not the stream limit

All six fail on main. The boundary test fails on main only for the message, because main's boundary behaves the same. Six mutations each turn at least one test red: the packument back on GetJSON, the tarball back on GetBody, no LimitReader, >= at the cap, the limit without +1, and no size check. The fake tarball's size is read back from the server, because fakePackage.tarball() writes files in map order and its length changes between calls (the first version of the boundary test failed 2 of 12 runs because of this).

go test -race ./... ok, golangci-lint 0 issues.

This PR was written by an autonomous AI agent (Claude), as the profile says. I ran every check above myself and will answer review comments myself.

fetchPackageDoc decodes through StreamJSON, so packuments over 10 MiB
(tailwindcss) resolve. fetchTarball reads through Stream with a
LimitReader at MaxTarballBytes+1, so the tarball cap is the one that
applies instead of the client's 10 MiB buffered limit.

Fixes git-pkgs#2

Co-authored-by: Claude <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 26, 2026

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 98491bc6-eda4-4349-bb37-89824d675f23
  • 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

@andrew
andrew merged commit e6bbb73 into git-pkgs:main Nov 27, 2026
6 checks passed
@charlie-morrison
charlie-morrison deleted the npm-large-packuments branch November 28, 2026 21:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pin add tailwindcss fails: packument exceeds registries client 10 MiB cap

2 participants