Skip to content

perf(resolver): serve cached packument fragments from the mirror file - #13686

Merged
zkochan merged 12 commits into
mainfrom
fix-13681
Aug 6, 2026
Merged

zkochan merged 12 commits into
mainfrom
fix-13681

Conversation

@zkochan

@zkochan zkochan commented Aug 6, 2026 •

Copy link
Copy Markdown
Member

Summary

Related to #13681 (the single-importer resolution peak; the multi-importer link-phase burst is discussed below).

Profiling the issue's @teambit/[email protected] repro attributed the resolution-phase peak to the in-memory packument cache: every consulted packument kept its entire JSON body resident for the whole install — as raw response fragments after a network fetch, or as the whole mirror-file buffer after a warm disk load. The repro's mirror holds 1.7 GB of packument JSON (mostly a few hundred multi-megabyte bit.cloud documents), and a phase-boundary RSS probe showed ~2.4 GB live right after the importer init waves, against a 3.18 GB total peak.

This change stops retaining packument bodies:

  • FragmentSource::FileSpan (replacing BufferSpan): a loaded mirror keeps its file handle open and reads each version fragment on demand with a positioned read. Holding the handle pins the inode — mirror rewrites go through temp-file + rename, so recorded spans can never shift under a reader. Fragment bytes now live in the (reclaimable) page cache instead of anonymous memory.
  • Warm loads (load_meta) parse only the header + index records; the fragment section is never buffered.
  • Cold fetches (fetch_full_metadata_cached) and release-age upgrade persists (persist_upgraded_to_mirror) return/cache the just-persisted mirror in its file-backed form, so the multi-megabyte response body drops as soon as it is written instead of living in the packument cache for the rest of the install.
  • Because the cache now holds one open descriptor per consulted packument, the soft RLIMIT_NOFILE is raised once toward the hard limit (the same startup adjustment the Go runtime performs; macOS falls back to the historic 10240 ceiling). Windows needs no adjustment.

Measurements

Linux x64, 32 cores, same fixture as the issue (single importer, @teambit/[email protected], ~3850 packages, hoisted + autoInstallPeers config), peak RSS via /usr/bin/time -v:

Scenario Before After
--lockfile-only resolve, warm metadata mirror (offline) 3.18 GB 1.31 GB
--lockfile-only resolve, cold metadata (online) 3.33 GB 1.86 GB
Full install, no lockfile, cold store — 1.99 GB

The issue's expectation ("peak in the same ballpark as pnpm v10, ≤ ~2 GB for the single-importer repro"; v10's full install measures 2.13 GB there) is met. Wall time is unchanged: 6-run A/B of the warm offline resolve is ~5.2 s for both binaries.

Phase probes after the change put the packument cache at ~0.2 GB; the largest remaining block is the peer-discovery walk state (~0.65 GB at this scale), which is the follow-up lever if more is needed.

Lockfile stability

The emitted lockfile is unchanged modulo a pre-existing race: on this fixture, unmodified main already produces different lockfiles across identical runs (6 runs → 4 distinct hashes; classnames: 2.2.6 ↔ 2.5.1 edge flips). The race is arrival-ordered children recording for overlay-affected picks — filed separately with the mechanism and a bounded-fix sketch as #13685. This PR does not change the distribution of outcomes (verified by running both binaries 6×; the hash sets overlap), and byte-compares on race-free fixtures are unaffected — the crate and workspace test suites pass unchanged.

On the multi-importer link-phase burst

The issue's second observation (a ~1300-importer workspace bursting 12 GB → 31 GB after downloads complete) could not be reproduced at that scale locally. Two data points from this investigation:

  • The hoisted-graph builder itself measures small at real workspace scale: lockfile_to_hoisted_dep_graph over a 343-importer / 6349-snapshot workspace lockfile allocates ~47 MB (10.6k graph nodes).
  • The fetch-phase plateau the burst sits on includes the retained metadata this PR removes (a bit-scale workspace consults strictly more bit.cloud packuments than the single-importer repro), so the whole curve should shift down by several GB.

A re-test of the CI workspace against this change would tell how much of the burst remains; the hoisted_dep_graph re-expansion path deserves its own profiling pass if it still spikes.

This is Rust-only: the change is an internal memory representation of the metadata cache (the on-disk mirror format is unchanged), so there is no TypeScript-side behavior to port.

Squash Commit Body

Stop retaining packument bodies in the install-scoped metadata cache
(Related to pnpm/pnpm#13681).

Every consulted packument kept its entire JSON body resident for the
whole install: raw response fragments after a network fetch, or the
whole mirror-file buffer after a warm disk load. On the issue's
@teambit/bit repro that is 1.7 GB of JSON and the dominant share of the
3.18 GB resolution peak.

Version fragments now stay on disk behind the loaded mirror's held-open
file handle (FragmentSource::FileSpan) and are read on demand with a
positioned read; holding the handle pins the inode, so rename-based
mirror rewrites can never shift bytes under the recorded spans. Warm
loads parse only the header and index records. Cold fetches and
release-age upgrade persists return the just-persisted mirror in its
file-backed form so the response body drops at write time. The soft
RLIMIT_NOFILE is raised once toward the hard limit to cover the held
descriptors (one per consulted packument).

Every declared length in a mirror is treated as untrusted: the header,
index, and per-fragment spans are bounded and validated against the
real file size before any allocation. Held handles are counted against
a descriptor-budget cap sized from the post-raise soft limit; a load
past the cap buffers its fragments span by span (bounded by a
cumulative budget) and closes the file, so a full cache can never turn
File::open failures into cache misses elsewhere. An over-limit
fragment reads as an absent version on both the save and load sides,
keeping the persisted and served views agreeing.

Peak RSS on the repro: 3.18 GB -> 1.31 GB (warm offline resolve),
3.33 GB -> 1.86 GB (cold online resolve); a full cold install stays
under 2 GB, below the pnpm v10 baseline from the issue. Wall time is
unchanged (6-run A/B). The fixture's lockfile flips predate this change
(pre-existing arrival-order race, filed as pnpm/pnpm#13685).

Checklist

  • I checked the referenced issue and verified that none of the PRs
    already linked to it solves it.
  • The change is implemented in both the TypeScript CLI and the Rust
    pnpm/ port, or the description notes what still needs porting.
  • Added a changeset (pnpm changeset) if this PR changes any published
    package. Keep it short and written for pnpm users — it becomes a release note.
  • Added or updated tests.

Written by an agent (Claude Code, claude-fable-5).

zkochan and others added 3 commits August 6, 2026 16:47
Stop retaining packument bodies in the install-scoped metadata cache
(#13681). Version fragments now hydrate on demand through the
loaded mirror's held-open file handle instead of anonymous buffers;
warm loads parse only the header and index records, and cold fetches
return the just-persisted mirror in its file-backed form so the
response body drops at write time. The soft RLIMIT_NOFILE is raised
once toward the hard limit to cover the held descriptors.

Peak RSS on the issue's repro: 3.18 GB -> 1.31 GB (warm offline
resolve), 3.33 GB -> 1.86 GB (cold online resolve); a full cold
install stays under 2 GB. Wall time unchanged in a 6-run A/B.

Co-Authored-By: Claude Fable 5 <[email protected]>
The rustdoc gate rejects a public item linking to the private
FragmentSource enum; the inode-pinning rationale now lives on
PackageVersions::from_file_spans.

Co-Authored-By: Claude Fable 5 <[email protected]>
Copilot AI lite review requested due to automatic review settings August 6, 2026 14:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Indexed registry mirrors now keep metadata fragments as file-backed spans. Version data loads on demand through positioned file reads. Successful mirror persistence reloads the file-backed representation, with tests covering hydration, fallback buffering, and invalid spans.

Changes

File-backed mirror metadata

Layer / File(s) Summary
Lazy file-span hydration
pnpm/crates/registry/src/package_versions.rs, pnpm/crates/registry/src/lib.rs
PackageVersions reads file-backed fragments on demand with positioned Unix or Windows I/O. MirrorFile limits held files, and raw fragments provide the fallback path.
Indexed mirror loading and validation
pnpm/crates/resolving-npm-resolver/src/mirror.rs, pnpm/crates/resolving-npm-resolver/Cargo.toml, pnpm/crates/resolving-npm-resolver/src/mirror/tests.rs
Indexed mirrors read bounded records, validate lengths and spans, and select file-backed or buffered fragments based on the descriptor cap. Tests cover mirror replacement, fallback buffering, and oversized records.
Persistence reload and caching
pnpm/crates/resolving-npm-resolver/src/fetch_full_metadata_cached.rs, pnpm/crates/resolving-npm-resolver/src/pick_package.rs, .changeset/mirror-file-span-metadata.md
Successful unfiltered indexed saves reload metadata for caching. Filtered or failed saves return no reloaded package. The changeset records the memory measurements.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Resolver
  participant load_meta
  participant MirrorFile
  participant PackageVersions
  Resolver->>load_meta: Load indexed mirror
  load_meta->>MirrorFile: Read bounded header and index records
  load_meta->>PackageVersions: Create file-backed or raw-fragment spans
  PackageVersions->>MirrorFile: Read requested fragment range
  MirrorFile-->>PackageVersions: Return fragment JSON
Loading

Possibly related PRs

  • pnpm/pnpm#13014 — Both changes modify Rust metadata-cache loading and persistence.
  • pnpm/pnpm#13492 — Both changes modify metadata-mirror reads in pick_package.rs.
  • pnpm/pnpm#13512 — This change extends the indexed mirror layout with lazy file-span hydration.

Suggested labels: product: pacquet

Suggested reviewers: copilot

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-13681

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

Comment @coderabbitai help to get the list of available commands.

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

perf(resolver): lazily hydrate cached packument versions from on-disk mirrors

✨ Enhancement 🧪 Tests 📝 Documentation ⚙️ Configuration changes 🕐 40+ Minutes

Grey Divider

AI Description

• Read cached packument version fragments on-demand from the metadata mirror file.
• Reload just-persisted mirrors so the install cache stores file-backed metadata, not bodies.
• Raise Unix open-file limits and add inode-pinning tests + release note.
Diagram

graph TD
  A["Resolver pick"] --> B["Install meta cache"] --> C["PackageVersions"] --> D[("Mirror file")]
  E["Network fetch"] --> F["Persist indexed mirror"] --> D[("Mirror file")] --> G["load_meta (headers+index)"] --> C["PackageVersions"]
  G["load_meta (headers+index)"] --> H{{"OS ulimit"}}

  subgraph Legend
    direction LR
    _p["Process"] ~~~ _f[("File")] ~~~ _o{{"OS"}}
  end
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Memory-map (mmap) mirror fragments
  • ➕ Avoids per-hydration allocation/copy of fragment bytes
  • ➕ Can leverage OS paging efficiently with fewer syscalls
  • ➖ More platform-specific edge cases (Windows mappings, file truncation semantics)
  • ➖ Harder to reason about safety with concurrent rewrites than pinned FD + positioned reads
2. LRU/size-based in-memory packument cache eviction
  • ➕ Keeps current in-memory hydration strategy without increasing open FDs
  • ➕ Can cap memory without changing file IO patterns
  • ➖ Evictions can regress CPU/network by re-reading/re-fetching frequently used packuments
  • ➖ Hard to tune across workloads; still requires holding large bodies until eviction
3. Stream parse and store only needed fields from HTTP responses
  • ➕ Avoids holding full response bodies even before writing mirror
  • ➕ Could further reduce peak memory on cold fetches
  • ➖ Complex incremental JSON parsing; risks correctness regressions for uncommon metadata shapes
  • ➖ Still needs a representation for version fragments (likely converges on file spans anyway)

Recommendation: The PR’s approach (file-backed spans with a pinned file handle + warm-load parsing only header/index) is the most robust tradeoff: it directly eliminates resident-body retention while keeping correctness under concurrent mirror rewrites via inode pinning. The added RLIMIT_NOFILE adjustment and regression test address the primary operational risks. Alternatives (mmap, eviction, streaming parse) add complexity or leave performance/behavior tradeoffs that are less predictable for large workspaces.

Files changed (8) +280 / -73

Enhancement (4) +228 / -73
package_versions.rsSwitch mirror-backed fragments from in-memory buffers to file spans +65/-25

Switch mirror-backed fragments from in-memory buffers to file spans

• Replaces buffered mirror fragment storage with FileSpan entries holding an Arc<File> plus offset/length. Adds cross-platform positioned reads to hydrate fragments on demand and updates constructors/docs accordingly.

pnpm/crates/registry/src/package_versions.rs

fetch_full_metadata_cached.rsServe persisted indexed mirrors instead of caching response bodies +31/-13

Serve persisted indexed mirrors instead of caching response bodies

• After successfully writing an indexed mirror, reloads it via load_meta and returns the file-backed Package to the caller. Keeps NDJSON filtered persistence best-effort without forcing reload.

pnpm/crates/resolving-npm-resolver/src/fetch_full_metadata_cached.rs

mirror.rsWarm-load mirrors by parsing headers+index and keeping file handle open +88/-13

Warm-load mirrors by parsing headers+index and keeping file handle open

• Updates load_meta to avoid buffering the fragment section for indexed mirrors, constructing PackageVersions from file spans backed by an open File. Adds a one-time Unix RLIMIT_NOFILE soft-limit raise (with macOS fallback) to support many concurrently open mirrors; NDJSON mirrors still read the full body.

pnpm/crates/resolving-npm-resolver/src/mirror.rs

pick_package.rsCache file-backed mirrors after release-age upgrades +44/-22

Cache file-backed mirrors after release-age upgrades

• Changes upgrade persistence to return an optional reloaded, file-backed Package for indexed mirrors and updates callers to cache that representation. Avoids retaining large upgraded packument bodies in the install-scoped cache.

pnpm/crates/resolving-npm-resolver/src/pick_package.rs

Tests (1) +45 / -0
tests.rsAdd inode-pinning regression test for rewritten mirrors +45/-0

Add inode-pinning regression test for rewritten mirrors

• Adds a test ensuring a loaded mirror continues to hydrate correct fragments even after the mirror path is rewritten with different offsets. Reinforces the file-handle/inode pinning contract of file spans.

pnpm/crates/resolving-npm-resolver/src/mirror/tests.rs

Documentation (1) +5 / -0
mirror-file-span-metadata.mdAdd release note for reduced resolver peak memory +5/-0

Add release note for reduced resolver peak memory

• Introduces a changeset documenting the shift to on-demand reading of cached registry metadata from disk mirrors. Includes before/after peak RSS numbers and references the motivating issue.

.changeset/mirror-file-span-metadata.md

Other (2) +2 / -0
Cargo.lockLock libc dependency for resolver crate usage +1/-0

Lock libc dependency for resolver crate usage

• Updates the workspace lockfile to include libc as a dependency where needed for Unix RLIMIT_NOFILE handling.

Cargo.lock

Cargo.tomlAdd libc workspace dependency for Unix open-file limit adjustment +1/-0

Add libc workspace dependency for Unix open-file limit adjustment

• Adds libc to the resolver crate dependencies to support getrlimit/setrlimit on Unix.

pnpm/crates/resolving-npm-resolver/Cargo.toml

@greptile-apps

greptile-apps Bot commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Reviews (7): Last reviewed commit: "docs(registry): state one cursor contrac..." | Re-trigger Greptile

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pnpm/crates/resolving-npm-resolver/src/mirror.rs`:
- Around line 541-560: In the mirror-reading flow, obtain the file size and
return a cache miss when fragment_base exceeds it before allocating records.
Move the file.metadata check currently after deserialization ahead of the
records Vec allocation, while preserving the existing Arc-wrapping and
subsequent parsing behavior.

In `@pnpm/crates/resolving-npm-resolver/src/mirror/tests.rs`:
- Around line 152-189: The test load_meta_survives_mirror_rewrite currently
permits eager body caching, so add a test hook or fixture that makes reading
version fragments before loaded.versions.get("1.0.0") fail. Keep the real
TempDir setup, perform the mirror overwrite as before, and ensure the assertion
triggers deferred hydration only when accessing the version so the test fails
with the old from_buffer_spans behavior while still verifying rewrite safety.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 3b3fe83e-645b-4e3e-9d7e-36c98b6dbff0

📥 Commits

Reviewing files that changed from the base of the PR and between dd0e058 and 5f68930.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock, !Cargo.lock
📒 Files selected for processing (7)
  • .changeset/mirror-file-span-metadata.md
  • pnpm/crates/registry/src/package_versions.rs
  • pnpm/crates/resolving-npm-resolver/Cargo.toml
  • pnpm/crates/resolving-npm-resolver/src/fetch_full_metadata_cached.rs
  • pnpm/crates/resolving-npm-resolver/src/mirror.rs
  • pnpm/crates/resolving-npm-resolver/src/mirror/tests.rs
  • pnpm/crates/resolving-npm-resolver/src/pick_package.rs

@qodo-code-review

qodo-code-review Bot commented Aug 6, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (1) 📜 Skill insights (0)

Grey Divider


Action required

1. Unbounded mirror length allocation ✓ Resolved 🐞 Bug ⛨ Security
Description
mirror::load_meta() allocates records using attacker-controlled headers_len/index_len from
the mirror magic line before validating those lengths against the actual file size, so a tiny
corrupted mirror can trigger huge allocations (OOM/kill) even though the subsequent read fails.
Code

pnpm/crates/resolving-npm-resolver/src/mirror.rs[R546-547]

+    let mut records = vec![0u8; fragment_base.checked_sub(filled.min(fragment_base))?];
+    file.read_exact(&mut records).ok()?;
Relevance

●● Moderate

Potential OOM from untrusted mirror header; fix seems reasonable, but no matching prior review
decisions found.

PR-#13549

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
load_meta() parses headers_len/index_len and uses them to size a new Vec before any
file-size validation, enabling a large allocation from a hostile mirror header. The same module
already acknowledges this threat model by bounding declared header length in
read_mirror_headers(), but load_meta() doesn’t apply an equivalent bound.

pnpm/crates/resolving-npm-resolver/src/mirror.rs[515-551]
pnpm/crates/resolving-npm-resolver/src/mirror.rs[447-474]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`load_meta()` trusts the declared `headers_len` and `index_len` from the mirror magic line to compute `fragment_base`, then immediately allocates a `Vec` of size `fragment_base - filled` before confirming that `fragment_base` is plausible for the file. A malformed/poisoned mirror can declare enormous lengths and cause a large allocation (DoS) even for a small file.

### Issue Context
You already harden this class of bug in `read_mirror_headers()` by bounding the declared headers length (`MAX_HEADERS_LEN`). `load_meta()` should apply the same hostile-input discipline and also ensure section ends are within the actual file length before allocating.

### Fix Focus Areas
- pnpm/crates/resolving-npm-resolver/src/mirror.rs[515-551]
- pnpm/crates/resolving-npm-resolver/src/mirror.rs[447-474]

### Suggested fix approach
- Fetch `file_size = file.metadata()?.len()` early (right after `File::open`).
- Apply explicit bounds to `headers_len` and `index_len` (at least `headers_len <= MAX_HEADERS_LEN`, and `index_len` bounded to something reasonable like `min(file_size, MAX_INDEX_LEN)`), and **return `None`** if `fragment_base as u64 > file_size`.
- Only then allocate `records` for the remaining header+index bytes.
- Consider reusing the existing `MAX_HEADERS_LEN` constant (or factoring it) and adding a `MAX_INDEX_LEN` to avoid “declare huge lengths” allocations even when the file is also huge.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

2. Sparse mirror gap OOM ✓ Resolved 🐞 Bug ⛨ Security
Description
In load_meta_with_hold_cap()'s held-handle fallback, the code buffers the entire byte range from
fragment_base to the maximum span end, so a corrupted/sparse mirror with a tiny fragment at a huge
offset can make read_to_end() allocate gigabytes and OOM. This is reachable whenever
MirrorFile::try_hold fails (cap exhausted), turning a locally attacker-controlled or corrupted
cache file into a process-wide install DoS.
Code

pnpm/crates/resolving-npm-resolver/src/mirror.rs[R620-622]

+            let remaining =
+                (fragment_end - fragment_base as u64).saturating_sub(fragments.len() as u64);
+            io::BufReader::new(file).take(remaining).read_to_end(&mut fragments).ok()?;
Relevance

●●● Strong

Repo recently accepts security hardening for untrusted inputs; this adds a real DoS/OOM guardrail.

PR-#13549
PR-#13371

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The fallback path derives fragment_end from the maximum span end and then buffers the whole range
up to that point, so a sparse file with a high-offset span can make remaining extremely large and
drive read_to_end() to allocate/append that entire logical range. Current validation only bounds
each span’s len and checks end <= file_size, which does not prevent huge offsets/gaps in sparse
files.

pnpm/crates/resolving-npm-resolver/src/mirror.rs[604-622]
pnpm/crates/resolving-npm-resolver/src/mirror.rs[589-595]
pnpm/crates/resolving-npm-resolver/src/mirror.rs[131-136]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`load_meta_with_hold_cap()` has a fallback branch (when the mirror file cannot be held open) that buffers bytes using `take(remaining).read_to_end(&mut fragments)`, where `remaining` is derived from the maximum declared span end. With sparse files, a hostile/corrupted mirror can set a very large offset (still within `file_size`) with a small `len`, causing `remaining` to be enormous and forcing a huge allocation/append.

### Issue Context
Per-fragment `len` is bounded (`MAX_FRAGMENT_LEN`), but the fallback buffering strategy is based on `fragment_end` (max span end), which is not bounded relative to `fragment_base`. Sparse files make the logical range huge even if physical storage is small.

### Fix Focus Areas
- pnpm/crates/resolving-npm-resolver/src/mirror.rs[597-622]
- pnpm/crates/resolving-npm-resolver/src/mirror.rs[589-595]

### Suggested fix approach
Implement one of:
1) **Per-span reads in the fallback**: instead of buffering `[fragment_base..fragment_end]`, read each span individually using positioned reads (like `FileExt::read_exact_at`/`seek_read`) and parse it into `RawValue`, avoiding ever materializing gaps.

2) **Hard cap the total fallback buffered range**: compute `max_end = max(span_end)` and if `(max_end - fragment_base) > MAX_FALLBACK_BUFFER` then treat the mirror as unreadable (`None`) or switch to per-span reads.

Add a regression test that constructs an indexed mirror with a small `len` but a very large `offset` (and a sparse `set_len(...)` to satisfy `file_size`), and asserts `load_meta_with_hold_cap(..., 0)` does not attempt to allocate the full gap (e.g., returns `None` or succeeds via per-span reads).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


3. Unreadable saved mirrors ✓ Resolved 🐞 Bug ➹ Performance
Description
load_meta() now rejects an indexed mirror if any version span length exceeds MAX_FRAGMENT_LEN,
but save_meta_indexed() can still write larger spans, creating mirrors pnpm persists but will
never serve. This degrades warm-cache behavior (forces refetch / keeps in-memory meta) and can break
offline installs for such packages because the on-disk mirror is treated as a miss.
Code

pnpm/crates/resolving-npm-resolver/src/mirror.rs[R589-592]

    for (version, offset, len) in index.versions {
        let absolute = (fragment_base as u64).checked_add(offset)?;
-        if absolute.checked_add(u64::from(len))? > file_size {
+        if len > MAX_FRAGMENT_LEN || absolute.checked_add(u64::from(len))? > file_size {
            return None;
Relevance

●●● Strong

Likely accepted: prevents writing mirrors the loader will always reject; aligns with cache
correctness/perf intent.

PR-#13131

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The new MAX_FRAGMENT_LEN cap is enforced during mirror load; any oversized span makes
load_meta() return None. However, the indexed writer does not apply this cap, so it can produce
mirrors that the loader will reject. Callers that attempt to reload the saved mirror only benefit if
load_meta() succeeds; otherwise they keep/return the in-memory meta, defeating the disk-backed
memory win and turning the mirror into a cache miss/offline failure for that package.

pnpm/crates/resolving-npm-resolver/src/mirror.rs[131-136]
pnpm/crates/resolving-npm-resolver/src/mirror.rs[588-595]
pnpm/crates/resolving-npm-resolver/src/mirror.rs[281-293]
pnpm/crates/resolving-npm-resolver/src/fetch_full_metadata_cached.rs[186-223]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`load_meta()` enforces `MAX_FRAGMENT_LEN` when validating mirror spans, but `save_meta_indexed()` does not enforce the same limit. That means pnpm can successfully persist an indexed mirror file and then immediately (or on the next run) treat that same mirror as unreadable, turning it into a perpetual cache miss.

### Issue Context
- The reader rejects the entire mirror when **any** `len > MAX_FRAGMENT_LEN`.
- The writer currently only guards against `>4GiB` (u32 overflow) and otherwise writes the fragment.
- Callers (e.g. `fetch_full_metadata_cached`) try to reload and serve the on-disk mirror; when reload fails, they fall back to the in-memory parsed `Package`.

### Fix Focus Areas
- pnpm/crates/resolving-npm-resolver/src/mirror.rs[131-137]
- pnpm/crates/resolving-npm-resolver/src/mirror.rs[281-293]
- pnpm/crates/resolving-npm-resolver/src/mirror.rs[588-595]

### Suggested fix direction
- Enforce the same fragment-size contract at write time:
 - If any version fragment exceeds `MAX_FRAGMENT_LEN`, either (a) fall back to writing the legacy NDJSON mirror for that package, or (b) skip persisting the mirror (debug-log) to avoid creating an unusable cache entry.
- Ideally define the limit once (shared constant) so writer/reader can’t drift again.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


4. FD cap can exceed limit ✓ Resolved 🐞 Bug ☼ Reliability
Description
held_mirror_file_cap() clamps the held-open mirror file count to at least 128 and does not bound
it by the effective soft descriptor limit, so environments with a very low RLIMIT_NOFILE (or where
the limit remains low) can exhaust file descriptors before the “buffer fragments instead” fallback
kicks in. This can cause File::open/socket opens to fail during install, turning valid cache
entries into misses or breaking unrelated I/O.
Code

pnpm/crates/resolving-npm-resolver/src/mirror.rs[R639-642]

+    *CAP.get_or_init(|| {
+        raise_open_file_limit_once();
+        soft_open_file_limit().map_or(1 << 19, |soft| (soft / 2).clamp(128, 1 << 19))
+    })
Relevance

●● Moderate

FD-exhaustion concern seems plausible, but cap policy is behavioral and precedent for this exact
clamp is unclear.

PR-#12502
PR-#12953

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The cap computation enforces a minimum of 128 held mirror files via clamp(128, ...) and does not
ensure the result is <= the effective soft open-file limit, which can lead to descriptor exhaustion
in low-limit environments before the fallback path can take effect.

pnpm/crates/resolving-npm-resolver/src/mirror.rs[632-662]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`held_mirror_file_cap()` computes the maximum number of mirror files that `load_meta` may keep open. The current formula uses `(soft / 2).clamp(128, 1 << 19)`, which can yield a cap that is too high for low-limit environments (e.g., soft limits < 128, or soft=128 where a cap of 128 leaves no FD headroom for other install activity).

## Issue Context
The cap is meant to prevent descriptor exhaustion and force a safe fallback (buffer fragments and close the file). If the cap itself can exceed the effective usable FD budget, descriptor exhaustion can happen *before* the counter reaches the cap, defeating the safeguard.

## Fix Focus Areas
- pnpm/crates/resolving-npm-resolver/src/mirror.rs[632-642]

Suggested direction:
- Ensure the computed cap never exceeds the effective soft limit minus a reserved headroom (e.g., `reserve = 64` or similar).
- Avoid a hard minimum (`128`) that can exceed the available limit; pick a smaller minimum or derive the minimum from `soft`.
- Keep the existing upper clamp, but make the lower clamp conditional on `soft` (e.g., `min_cap = soft.saturating_sub(reserve).min(128)` or similar).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


View more (1)
5. Unbounded fragment read allocation ✓ Resolved 🐞 Bug ⛨ Security
Description
FragmentSource::FileSpan::json() allocates a buffer of size len from the mirror index with no
upper bound; a poisoned/corrupted mirror (or an unusually large cached mirror) can therefore trigger
very large allocations and OOM when a version is hydrated.
Code

pnpm/crates/registry/src/package_versions.rs[R79-81]

+                let mut bytes = vec![0u8; *len as usize];
+                if let Err(error) = read_exact_at(file, &mut bytes, *offset) {
+                    tracing::warn!(
Relevance

●● Moderate

Security hardening likely valued, but no close precedent on bounding mirror fragment span
allocations in this crate.

PR-#13549

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The new FileSpan hydration path allocates len bytes directly and reads at offset. While
load_meta() verifies spans fit inside the file, it does not constrain len to a safe maximum, so
a corrupted/poisoned mirror can still drive large allocations during hydration.

pnpm/crates/registry/src/package_versions.rs[71-101]
pnpm/crates/resolving-npm-resolver/src/mirror.rs[556-568]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
When hydrating a file-backed version fragment, `FragmentSource::FileSpan::json()` allocates `vec![0u8; len]` with no maximum. Even though `load_meta()` ensures the span lies within the file, the file itself (and its index) are untrusted cache inputs, so `len` can still be extremely large and cause memory exhaustion when that fragment is accessed.

### Issue Context
`load_meta()` currently validates only `absolute + len <= file_size` for each span. That prevents out-of-bounds reads but not oversized allocations.

### Fix Focus Areas
- pnpm/crates/registry/src/package_versions.rs[71-101]
- pnpm/crates/resolving-npm-resolver/src/mirror.rs[556-568]

### Suggested fix approach
Pick one of:
1) **Hard cap per-fragment length**: enforce `len <= MAX_FRAGMENT_LEN` either when constructing spans in `load_meta()` (reject mirror / return `None`) or inside `json()` (warn and treat as absent). Choose a cap that still covers real-world big fragments (e.g. 64–256 MiB), and consider making it a constant near the mirror parser.
2) **Streaming parse without full buffering**: avoid allocating `len` bytes by implementing a positioned reader that reads a fragment in chunks and parses via `serde_json::from_reader`. This is more work but eliminates the OOM vector while preserving support for very large fragments.

Additionally, if you keep buffering: consider parsing directly from bytes (`serde_json::from_slice`) to avoid the extra `String` allocation/copy.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Informational

6. Cursor semantics comment conflict ✓ Resolved 🐞 Bug ⚙ Maintainability ⭐ New
Description
read_exact_at is documented as not using or disturbing the file handle’s cursor, but the
Windows-specific comment immediately below implies the opposite for seek_read. This contradiction
makes the API contract unclear and risks future platform-specific misuse or needless synchronization
decisions.
Code

pnpm/crates/registry/src/package_versions.rs[R156-157]

+/// See the unix sibling; Windows' `seek_read` moves the cursor, but no
+/// caller relies on it.
Relevance

●●● Strong

Team often updates/softens misleading docs to match real guarantees; comment-API contract clarity
changes are accepted.

PR-#13652
PR-#13392

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The file contains adjacent comments that describe incompatible cursor behavior for the same API,
making the contract ambiguous to maintainers.

pnpm/crates/registry/src/package_versions.rs[148-157]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`read_exact_at` has a function-level contract comment that it does not use/disturb the file cursor (safe for concurrent readers), but the Windows-specific comment says `seek_read` moves the cursor. These two statements conflict and make the intended cross-platform semantics unclear.

### Issue Context
This helper is re-exported and used for on-demand fragment reads from held-open mirror files; keeping its contract unambiguous matters for future refactors and platform-specific behavior.

### Fix Focus Areas
- pnpm/crates/registry/src/package_versions.rs[148-157]

### Suggested fix
Update comments so they state one consistent contract across platforms. If the Windows implementation is indeed cursor-independent (positioned read), say so explicitly; if it is cursor-affecting, then either (a) change the function-level doc to reflect that, and/or (b) wrap the Windows implementation with the required synchronization / per-read handle duplication and document the behavior.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


7. Redundant HELD_MIRROR_FILES comment ✓ Resolved 📘 Rule violation ⚙ Maintainability
Description
The comment above HELD_MIRROR_FILES largely restates the identifier without adding intent,
constraints, or rationale. This adds noise and can go stale without improving readability.
Code

pnpm/crates/registry/src/package_versions.rs[R63-64]

+/// Descriptors currently held by live [`MirrorFile`]s.
+static HELD_MIRROR_FILES: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);
Relevance

●●● Strong

Repo often accepts removing/trimming comments that restate code to reduce drift/noise.

PR-#13350
PR-#13468

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
PR Compliance ID 713467 requires avoiding comments that merely restate the code. The added doc
comment just rephrases HELD_MIRROR_FILES without adding new information.

Rule 713467: Avoid redundant comments that restate the code
pnpm/crates/registry/src/package_versions.rs[63-64]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
A new comment duplicates what the code already states (`HELD_MIRROR_FILES`), without adding additional intent or constraints.

## Issue Context
Per the repo’s comment hygiene rule, comments should explain *why* / invariants / constraints, not restate names.

## Fix Focus Areas
- pnpm/crates/registry/src/package_versions.rs[63-64]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


8. Changeset missing pnpm entry 📘 Rule violation § Compliance
Description
The new changeset only declares a bump for pacquet and omits pnpm, which violates the
requirement that changesets explicitly include a valid pnpm bump entry. This can lead to incorrect
release/versioning behavior for pnpm.
Code

.changeset/mirror-file-span-metadata.md[R1-3]

+---
+"pacquet": patch
+---
Relevance

● Weak

Exact precedents show missing pnpm changeset entry often left unfixed despite same compliance bot
warning.

PR-#13587
PR-#13594

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
PR Compliance ID 713436 requires each added/modified changeset to include an explicit pnpm entry
with a valid bump type. The added changeset front-matter lists only pacquet and has no pnpm
entry.

Rule 713436: Explicitly declare pnpm package and correct bump type in changesets
.changeset/mirror-file-span-metadata.md[1-3]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The changeset `.changeset/mirror-file-span-metadata.md` is missing a required `pnpm` entry in its front-matter.

## Issue Context
Compliance requires changesets to explicitly declare the `pnpm` package with a valid bump type (`patch`/`minor`/`major`).

## Fix Focus Areas
- .changeset/mirror-file-span-metadata.md[1-3]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Context used
✅ Compliance rules (platform): 24 rules

To customize comments, go to the Qodo configuration screen, or learn more in the docs.

Previous review results

Review updated until commit b406eba

Results up to commit 5f68930 ⚖️ Balanced


🐞 Bugs (0) 📘 Rule violations (1) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)


Action required
1. Unbounded mirror length allocation ✓ Resolved 🐞 Bug ⛨ Security
Description
mirror::load_meta() allocates records using attacker-controlled headers_len/index_len from
the mirror magic line before validating those lengths against the actual file size, so a tiny
corrupted mirror can trigger huge allocations (OOM/kill) even though the subsequent read fails.
Code

pnpm/crates/resolving-npm-resolver/src/mirror.rs[R546-547]

+    let mut records = vec![0u8; fragment_base.checked_sub(filled.min(fragment_base))?];
+    file.read_exact(&mut records).ok()?;
Relevance

●● Moderate

Potential OOM from untrusted mirror header; fix seems reasonable, but no matching prior review
decisions found.

PR-#13549

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
load_meta() parses headers_len/index_len and uses them to size a new Vec before any
file-size validation, enabling a large allocation from a hostile mirror header. The same module
already acknowledges this threat model by bounding declared header length in
read_mirror_headers(), but load_meta() doesn’t apply an equivalent bound.

pnpm/crates/resolving-npm-resolver/src/mirror.rs[515-551]
pnpm/crates/resolving-npm-resolver/src/mirror.rs[447-474]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`load_meta()` trusts the declared `headers_len` and `index_len` from the mirror magic line to compute `fragment_base`, then immediately allocates a `Vec` of size `fragment_base - filled` before confirming that `fragment_base` is plausible for the file. A malformed/poisoned mirror can declare enormous lengths and cause a large allocation (DoS) even for a small file.

### Issue Context
You already harden this class of bug in `read_mirror_headers()` by bounding the declared headers length (`MAX_HEADERS_LEN`). `load_meta()` should apply the same hostile-input discipline and also ensure section ends are within the actual file length before allocating.

### Fix Focus Areas
- pnpm/crates/resolving-npm-resolver/src/mirror.rs[515-551]
- pnpm/crates/resolving-npm-resolver/src/mirror.rs[447-474]

### Suggested fix approach
- Fetch `file_size = file.metadata()?.len()` early (right after `File::open`).
- Apply explicit bounds to `headers_len` and `index_len` (at least `headers_len <= MAX_HEADERS_LEN`, and `index_len` bounded to something reasonable like `min(file_size, MAX_INDEX_LEN)`), and **return `None`** if `fragment_base as u64 > file_size`.
- Only then allocate `records` for the remaining header+index bytes.
- Consider reusing the existing `MAX_HEADERS_LEN` constant (or factoring it) and adding a `MAX_INDEX_LEN` to avoid “declare huge lengths” allocations even when the file is also huge.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended
2. Unbounded fragment read allocation ✓ Resolved 🐞 Bug ⛨ Security
Description
FragmentSource::FileSpan::json() allocates a buffer of size len from the mirror index with no
upper bound; a poisoned/corrupted mirror (or an unusually large cached mirror) can therefore trigger
very large allocations and OOM when a version is hydrated.
Code

pnpm/crates/registry/src/package_versions.rs[R79-81]

+                let mut bytes = vec![0u8; *len as usize];
+                if let Err(error) = read_exact_at(file, &mut bytes, *offset) {
+                    tracing::warn!(
Relevance

●● Moderate

Security hardening likely valued, but no close precedent on bounding mirror fragment span
allocations in this crate.

PR-#13549

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The new FileSpan hydration path allocates len bytes directly and reads at offset. While
load_meta() verifies spans fit inside the file, it does not constrain len to a safe maximum, so
a corrupted/poisoned mirror can still drive large allocations during hydration.

pnpm/crates/registry/src/package_versions.rs[71-101]
pnpm/crates/resolving-npm-resolver/src/mirror.rs[556-568]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
When hydrating a file-backed version fragment, `FragmentSource::FileSpan::json()` allocates `vec![0u8; len]` with no maximum. Even though `load_meta()` ensures the span lies within the file, the file itself (and its index) are untrusted cache inputs, so `len` can still be extremely large and cause memory exhaustion when that fragment is accessed.

### Issue Context
`load_meta()` currently validates only `absolute + len <= file_size` for each span. That prevents out-of-bounds reads but not oversized allocations.

### Fix Focus Areas
- pnpm/crates/registry/src/package_versions.rs[71-101]
- pnpm/crates/resolving-npm-resolver/src/mirror.rs[556-568]

### Suggested fix approach
Pick one of:
1) **Hard cap per-fragment length**: enforce `len <= MAX_FRAGMENT_LEN` either when constructing spans in `load_meta()` (reject mirror / return `None`) or inside `json()` (warn and treat as absent). Choose a cap that still covers real-world big fragments (e.g. 64–256 MiB), and consider making it a constant near the mirror parser.
2) **Streaming parse without full buffering**: avoid allocating `len` bytes by implementing a positioned reader that reads a fragment in chunks and parses via `serde_json::from_reader`. This is more work but eliminates the OOM vector while preserving support for very large fragments.

Additionally, if you keep buffering: consider parsing directly from bytes (`serde_json::from_slice`) to avoid the extra `String` allocation/copy.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Informational
3. Changeset missing pnpm entry 📘 Rule violation § Compliance
Description
The new changeset only declares a bump for pacquet and omits pnpm, which violates the
requirement that changesets explicitly include a valid pnpm bump entry. This can lead to incorrect
release/versioning behavior for pnpm.
Code

.changeset/mirror-file-span-metadata.md[R1-3]

+---
+"pacquet": patch
+---
Relevance

● Weak

Exact precedents show missing pnpm changeset entry often left unfixed despite same compliance bot
warning.

PR-#13587
PR-#13594

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
PR Compliance ID 713436 requires each added/modified changeset to include an explicit pnpm entry
with a valid bump type. The added changeset front-matter lists only pacquet and has no pnpm
entry.

Rule 713436: Explicitly declare pnpm package and correct bump type in changesets
.changeset/mirror-file-span-metadata.md[1-3]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The changeset `.changeset/mirror-file-span-metadata.md` is missing a required `pnpm` entry in its front-matter.

## Issue Context
Compliance requires changesets to explicitly declare the `pnpm` package with a valid bump type (`patch`/`minor`/`major`).

## Fix Focus Areas
- .changeset/mirror-file-span-metadata.md[1-3]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Results up to commit ff31977 ⚖️ Balanced


🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)


Remediation recommended
1. FD cap can exceed limit ✓ Resolved 🐞 Bug ☼ Reliability
Description
held_mirror_file_cap() clamps the held-open mirror file count to at least 128 and does not bound
it by the effective soft descriptor limit, so environments with a very low RLIMIT_NOFILE (or where
the limit remains low) can exhaust file descriptors before the “buffer fragments instead” fallback
kicks in. This can cause File::open/socket opens to fail during install, turning valid cache
entries into misses or breaking unrelated I/O.
Code

pnpm/crates/resolving-npm-resolver/src/mirror.rs[R639-642]

+    *CAP.get_or_init(|| {
+        raise_open_file_limit_once();
+        soft_open_file_limit().map_or(1 << 19, |soft| (soft / 2).clamp(128, 1 << 19))
+    })
Relevance

●● Moderate

FD-exhaustion concern seems plausible, but cap policy is behavioral and precedent for this exact
clamp is unclear.

PR-#12502
PR-#12953

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The cap computation enforces a minimum of 128 held mirror files via clamp(128, ...) and does not
ensure the result is <= the effective soft open-file limit, which can lead to descriptor exhaustion
in low-limit environments before the fallback path can take effect.

pnpm/crates/resolving-npm-resolver/src/mirror.rs[632-662]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`held_mirror_file_cap()` computes the maximum number of mirror files that `load_meta` may keep open. The current formula uses `(soft / 2).clamp(128, 1 << 19)`, which can yield a cap that is too high for low-limit environments (e.g., soft limits < 128, or soft=128 where a cap of 128 leaves no FD headroom for other install activity).

## Issue Context
The cap is meant to prevent descriptor exhaustion and force a safe fallback (buffer fragments and close the file). If the cap itself can exceed the effective usable FD budget, descriptor exhaustion can happen *before* the counter reaches the cap, defeating the safeguard.

## Fix Focus Areas
- pnpm/crates/resolving-npm-resolver/src/mirror.rs[632-642]

Suggested direction:
- Ensure the computed cap never exceeds the effective soft limit minus a reserved headroom (e.g., `reserve = 64` or similar).
- Avoid a hard minimum (`128`) that can exceed the available limit; pick a smaller minimum or derive the minimum from `soft`.
- Keep the existing upper clamp, but make the lower clamp conditional on `soft` (e.g., `min_cap = soft.saturating_sub(reserve).min(128)` or similar).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Informational
2. Redundant HELD_MIRROR_FILES comment ✓ Resolved 📘 Rule violation ⚙ Maintainability
Description
The comment above HELD_MIRROR_FILES largely restates the identifier without adding intent,
constraints, or rationale. This adds noise and can go stale without improving readability.
Code

pnpm/crates/registry/src/package_versions.rs[R63-64]

+/// Descriptors currently held by live [`MirrorFile`]s.
+static HELD_MIRROR_FILES: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);
Relevance

●●● Strong

Repo often accepts removing/trimming comments that restate code to reduce drift/noise.

PR-#13350
PR-#13468

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
PR Compliance ID 713467 requires avoiding comments that merely restate the code. The added doc
comment just rephrases HELD_MIRROR_FILES without adding new information.

Rule 713467: Avoid redundant comments that restate the code
pnpm/crates/registry/src/package_versions.rs[63-64]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
A new comment duplicates what the code already states (`HELD_MIRROR_FILES`), without adding additional intent or constraints.

## Issue Context
Per the repo’s comment hygiene rule, comments should explain *why* / invariants / constraints, not restate names.

## Fix Focus Areas
- pnpm/crates/registry/src/package_versions.rs[63-64]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Results up to commit 4c26109 ⚖️ Balanced


🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)


Remediation recommended
1. Unreadable saved mirrors ✓ Resolved 🐞 Bug ➹ Performance
Description
load_meta() now rejects an indexed mirror if any version span length exceeds MAX_FRAGMENT_LEN,
but save_meta_indexed() can still write larger spans, creating mirrors pnpm persists but will
never serve. This degrades warm-cache behavior (forces refetch / keeps in-memory meta) and can break
offline installs for such packages because the on-disk mirror is treated as a miss.
Code

pnpm/crates/resolving-npm-resolver/src/mirror.rs[R589-592]

    for (version, offset, len) in index.versions {
        let absolute = (fragment_base as u64).checked_add(offset)?;
-        if absolute.checked_add(u64::from(len))? > file_size {
+        if len > MAX_FRAGMENT_LEN || absolute.checked_add(u64::from(len))? > file_size {
            return None;
Relevance

●●● Strong

Likely accepted: prevents writing mirrors the loader will always reject; aligns with cache
correctness/perf intent.

PR-#13131

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The new MAX_FRAGMENT_LEN cap is enforced during mirror load; any oversized span makes
load_meta() return None. However, the indexed writer does not apply this cap, so it can produce
mirrors that the loader will reject. Callers that attempt to reload the saved mirror only benefit if
load_meta() succeeds; otherwise they keep/return the in-memory meta, defeating the disk-backed
memory win and turning the mirror into a cache miss/offline failure for that package.

pnpm/crates/resolving-npm-resolver/src/mirror.rs[131-136]
pnpm/crates/resolving-npm-resolver/src/mirror.rs[588-595]
pnpm/crates/resolving-npm-resolver/src/mirror.rs[281-293]
pnpm/crates/resolving-npm-resolver/src/fetch_full_metadata_cached.rs[186-223]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`load_meta()` enforces `MAX_FRAGMENT_LEN` when validating mirror spans, but `save_meta_indexed()` does not enforce the same limit. That means pnpm can successfully persist an indexed mirror file and then immediately (or on the next run) treat that same mirror as unreadable, turning it into a perpetual cache miss.

### Issue Context
- The reader rejects the entire mirror when **any** `len > MAX_FRAGMENT_LEN`.
- The writer currently only guards against `>4GiB` (u32 overflow) and otherwise writes the fragment.
- Callers (e.g. `fetch_full_metadata_cached`) try to reload and serve the on-disk mirror; when reload fails, they fall back to the in-memory parsed `Package`.

### Fix Focus Areas
- pnpm/crates/resolving-npm-resolver/src/mirror.rs[131-137]
- pnpm/crates/resolving-npm-resolver/src/mirror.rs[281-293]
- pnpm/crates/resolving-npm-resolver/src/mirror.rs[588-595]

### Suggested fix direction
- Enforce the same fragment-size contract at write time:
 - If any version fragment exceeds `MAX_FRAGMENT_LEN`, either (a) fall back to writing the legacy NDJSON mirror for that package, or (b) skip persisting the mirror (debug-log) to avoid creating an unusable cache entry.
- Ideally define the limit once (shared constant) so writer/reader can’t drift again.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Results up to commit 7f5e683 ⚖️ Balanced


🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)


Remediation recommended
1. Sparse mirror gap OOM ✓ Resolved 🐞 Bug ⛨ Security
Description
In load_meta_with_hold_cap()'s held-handle fallback, the code buffers the entire byte range from
fragment_base to the maximum span end, so a corrupted/sparse mirror with a tiny fragment at a huge
offset can make read_to_end() allocate gigabytes and OOM. This is reachable whenever
MirrorFile::try_hold fails (cap exhausted), turning a locally attacker-controlled or corrupted
cache file into a process-wide install DoS.
Code

pnpm/crates/resolving-npm-resolver/src/mirror.rs[R620-622]

+            let remaining =
+                (fragment_end - fragment_base as u64).saturating_sub(fragments.len() as u64);
+            io::BufReader::new(file).take(remaining).read_to_end(&mut fragments).ok()?;
Relevance

●●● Strong

Repo recently accepts security hardening for untrusted inputs; this adds a real DoS/OOM guardrail.

PR-#13549
PR-#13371

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The fallback path derives fragment_end from the maximum span end and then buffers the whole range
up to that point, so a sparse file with a high-offset span can make remaining extremely large and
drive read_to_end() to allocate/append that entire logical range. Current validation only bounds
each span’s len and checks end <= file_size, which does not prevent huge offsets/gaps in sparse
files.

pnpm/crates/resolving-npm-resolver/src/mirror.rs[604-622]
pnpm/crates/resolving-npm-resolver/src/mirror.rs[589-595]
pnpm/crates/resolving-npm-resolver/src/mirror.rs[131-136]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`load_meta_with_hold_cap()` has a fallback branch (when the mirror file cannot be held open) that buffers bytes using `take(remaining).read_to_end(&mut fragments)`, where `remaining` is derived from the maximum declared span end. With sparse files, a hostile/corrupted mirror can set a very large offset (still within `file_size`) with a small `len`, causing `remaining` to be enormous and forcing a huge allocation/append.

### Issue Context
Per-fragment `len` is bounded (`MAX_FRAGMENT_LEN`), but the fallback buffering strategy is based on `fragment_end` (max span end), which is not bounded relative to `fragment_base`. Sparse files make the logical range huge even if physical storage is small.

### Fix Focus Areas
- pnpm/crates/resolving-npm-resolver/src/mirror.rs[597-622]
- pnpm/crates/resolving-npm-resolver/src/mirror.rs[589-595]

### Suggested fix approach
Implement one of:
1) **Per-span reads in the fallback**: instead of buffering `[fragment_base..fragment_end]`, read each span individually using positioned reads (like `FileExt::read_exact_at`/`seek_read`) and parse it into `RawValue`, avoiding ever materializing gaps.

2) **Hard cap the total fallback buffered range**: compute `max_end = max(span_end)` and if `(max_end - fragment_base) > MAX_FALLBACK_BUFFER` then treat the mirror as unreadable (`None`) or switch to per-span reads.

Add a regression test that constructs an indexed mirror with a small `len` but a very large `offset` (and a sparse `set_len(...)` to satisfy `file_size`), and asserts `load_meta_with_hold_cap(..., 0)` does not attempt to allocate the full gap (e.g., returns `None` or succeeds via per-span reads).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Qodo Logo

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

/improve is deprecated. Use /agentic_review instead (removal date not yet scheduled).

No code suggestions found for the PR.

@codecov-commenter

codecov-commenter commented Aug 6, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 78.88889% with 38 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.13%. Comparing base (dd0e058) to head (b406eba).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
pnpm/crates/resolving-npm-resolver/src/mirror.rs 80.43% 18 Missing ⚠️
.../crates/resolving-npm-resolver/src/pick_package.rs 50.00% 14 Missing ⚠️
...ing-npm-resolver/src/fetch_full_metadata_cached.rs 66.66% 4 Missing ⚠️
pnpm/crates/registry/src/package_versions.rs 95.83% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #13686      +/-   ##
==========================================
- Coverage   88.16%   88.13%   -0.03%     
==========================================
  Files         612      612              
  Lines       99579    99717     +138     
==========================================
+ Hits        87791    87889      +98     
- Misses      11788    11828      +40     

☔ 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.

@github-actions

github-actions Bot commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Micro-Benchmark Results

Linux

group                                            main                                   pr
-----                                            ----                                   --
lockfile/parse_pnpm_lock                         1.04     15.1±2.32ms    24.7 MB/sec    1.00     14.5±1.74ms    25.8 MB/sec
packument/parse                                  1.01     40.5±1.26µs  1638.7 MB/sec    1.00     40.0±1.61µs  1659.6 MB/sec
tarball/download_dependency                      1.03      2.7±0.27ms  1635.2 KB/sec    1.00      2.6±0.16ms  1676.2 KB/sec
tarball_batch/cold_store_many_medium_tarballs    1.05   222.6±12.45ms 71.9 KElem/sec    1.00    212.6±8.24ms 75.3 KElem/sec
workspace_resolution/hoist_heavy                 1.00   388.8±74.85ms        ? ?/sec    1.06   411.5±81.92ms        ? ?/sec

zkochan and others added 2 commits August 6, 2026 17:09
…ndles

Review follow-ups for the file-backed metadata cache: reject declared
header/index lengths that exceed their bounds or the actual file size
before allocating (a corrupted or hostile mirror could otherwise drive
an arbitrarily large allocation), and count held mirror handles
against a descriptor-budget cap — a load past the cap buffers its
fragments and closes the file instead of letting a full cache turn
File::open failures into cache misses elsewhere.

Co-Authored-By: Claude Fable 5 <[email protected]>
Copilot AI review requested due to automatic review settings August 6, 2026 15:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@zkochan

zkochan commented Aug 6, 2026

Copy link
Copy Markdown
Member Author

On the micro-benchmark bot's numbers: those deltas are shared-runner noise — the same run reports lockfile/parse_pnpm_lock 1.64x slower, and this PR does not touch lockfile parsing at all. A controlled back-to-back comparison on a quiet dedicated box (fresh worktree of main vs this branch, same machine, criterion defaults) gives:

bench main this PR
workspace_resolution/hoist_heavy 194.2 ms ±1 197.1 ms ±1 (+1.5%)
lockfile/parse_pnpm_lock 11.15 ms 11.12 ms
packument/parse 34.10 µs 34.45 µs

which matches the end-to-end result (6-run A/B of the issue repro's warm offline resolve: ~5.2 s on both binaries).

The macOS test failure is import_indexed_dir::tests::concurrent_importers_of_one_shared_slot_both_succeed — a shared-slot concurrency test in deps-restorer, untouched by this diff (one importer's staging write hit NotFound after the other replaced the slot directory). Rerunning the job.


Written by an agent (Claude Code, claude-fable-5).

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
pnpm/crates/registry/src/package_versions.rs (1)

107-122: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Bound each indexed fragment before allocation.

The loader validates that a span ends within file_size, but it permits an individual len up to u32::MAX. A corrupt sparse mirror can therefore reach FileSpan::json and request a multi-gigabyte allocation. This can terminate the process before the fragment read reports an error.

  • pnpm/crates/registry/src/package_versions.rs#L107-L122: reject spans above a defined fragment-size limit before constructing FileSpan, and use fallible allocation when reading the accepted span.
  • pnpm/crates/resolving-npm-resolver/src/mirror/tests.rs#L199-L205: add a sparse-mirror fixture with a valid header and index but an over-limit fragment span. Assert that load_meta returns None without hydration.

As per path instructions, treat mirror spans and declared lengths as untrusted input and bound allocations.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pnpm/crates/registry/src/package_versions.rs` around lines 107 - 122, The
FragmentSource loader must bound untrusted fragment lengths before allocation.
In pnpm/crates/registry/src/package_versions.rs:107-122, define and enforce a
fragment-size limit before constructing FileSpan, and make FragmentSource::json
use fallible allocation for accepted spans; in
pnpm/crates/resolving-npm-resolver/src/mirror/tests.rs:199-205, add a
sparse-mirror fixture with a valid header and index but an over-limit fragment
span, asserting load_meta returns None without hydration.

Source: Path instructions

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@pnpm/crates/registry/src/package_versions.rs`:
- Around line 107-122: The FragmentSource loader must bound untrusted fragment
lengths before allocation. In
pnpm/crates/registry/src/package_versions.rs:107-122, define and enforce a
fragment-size limit before constructing FileSpan, and make FragmentSource::json
use fallible allocation for accepted spans; in
pnpm/crates/resolving-npm-resolver/src/mirror/tests.rs:199-205, add a
sparse-mirror fixture with a valid header and index but an over-limit fragment
span, asserting load_meta returns None without hydration.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: a74efa1b-162f-4141-8d05-2020d03158ab

📥 Commits

Reviewing files that changed from the base of the PR and between 5f68930 and ff31977.

📒 Files selected for processing (4)
  • pnpm/crates/registry/src/lib.rs
  • pnpm/crates/registry/src/package_versions.rs
  • pnpm/crates/resolving-npm-resolver/src/mirror.rs
  • pnpm/crates/resolving-npm-resolver/src/mirror/tests.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • pnpm/crates/resolving-npm-resolver/src/mirror.rs

@github-actions github-actions Bot added the reviewed: coderabbit CodeRabbit submitted an approving review label Aug 6, 2026
@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit ff31977

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

/improve is deprecated. Use /agentic_review instead (removal date not yet scheduled).

No code suggestions found for the PR.

… limit

A sparse mirror makes file size untrustworthy, so each declared
fragment span is bounded before FileSpan construction; and the
held-handle cap no longer has a floor that could exceed a very low
soft descriptor limit.

Co-Authored-By: Claude Fable 5 <[email protected]>
Copilot AI review requested due to automatic review settings August 6, 2026 15:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI review requested due to automatic review settings August 6, 2026 15:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit b406eba

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

/improve is deprecated. Use /agentic_review instead (removal date not yet scheduled).

No code suggestions found for the PR.

@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Integrated-Benchmark Report (Linux)

Commit: b406eba237dc

Regular scenarios report direct and pnpr installs. The peer-heavy resolver scenario compares current Rust, main Rust, and TypeScript pnpm. Bencher consumes pacquet@HEAD and pnpr@HEAD.

The tables below show mean ± σ; Bencher thresholds on the minimum latency, which is far less perturbed by shared-runner contention (noise only adds time).

Scenario: Isolated linker: fresh restore, cold cache + cold store

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 2.503 ± 0.162 2.372 2.785 1.65 ± 0.17
pacquet@main 2.415 ± 0.089 2.337 2.559 1.59 ± 0.14
pnpr@HEAD 1.514 ± 0.119 1.363 1.748 1.00
pnpr@main 1.638 ± 0.142 1.433 1.888 1.08 ± 0.13
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 2.50265336084,
      "stddev": 0.1618023512580806,
      "median": 2.42920301944,
      "user": 1.7809936,
      "system": 1.3837261,
      "min": 2.3717658624399998,
      "max": 2.78480842344,
      "times": [
        2.3717658624399998,
        2.38011129844,
        2.78480842344,
        2.40199108744,
        2.4564149514399998,
        2.64040091044,
        2.47642553844,
        2.38083326444,
        2.75240952444,
        2.38137274744
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 2.41531904524,
      "stddev": 0.08938400296086497,
      "median": 2.35897216544,
      "user": 1.6275669000000001,
      "system": 1.3665771000000002,
      "min": 2.33712143244,
      "max": 2.55901500444,
      "times": [
        2.53063441344,
        2.5159922244399997,
        2.35220987044,
        2.33712143244,
        2.34112251444,
        2.34773033244,
        2.55901500444,
        2.35890250744,
        2.35904182344,
        2.45142032944
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 1.5144771084400002,
      "stddev": 0.11945768913914166,
      "median": 1.50966966594,
      "user": 1.3261718,
      "system": 1.3263124999999998,
      "min": 1.36272274044,
      "max": 1.74833652144,
      "times": [
        1.51675610844,
        1.41335351644,
        1.3927342514399998,
        1.43415904844,
        1.6138960994399998,
        1.74833652144,
        1.5025832234399998,
        1.36272274044,
        1.56329302444,
        1.59693655044
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 1.63798234524,
      "stddev": 0.14233636768286967,
      "median": 1.6711551734399999,
      "user": 1.6859046,
      "system": 1.6038641999999999,
      "min": 1.43261622744,
      "max": 1.8875310864400001,
      "times": [
        1.66576703644,
        1.76945728044,
        1.53645672644,
        1.43261622744,
        1.69614142444,
        1.49609484444,
        1.67654331044,
        1.8875310864400001,
        1.71663610644,
        1.50257940944
      ]
    }
  ]
}

Scenario: Isolated linker: fresh restore, hot cache + hot store

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 293.8 ± 19.1 273.7 327.4 1.00 ± 0.07
pacquet@main 301.2 ± 15.4 276.7 326.1 1.03 ± 0.06
pnpr@HEAD 292.4 ± 9.9 277.2 309.3 1.00
pnpr@main 308.7 ± 18.1 283.3 332.3 1.06 ± 0.07
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.2937931965,
      "stddev": 0.019115459507020063,
      "median": 0.28700276329999996,
      "user": 0.24682104,
      "system": 0.56319152,
      "min": 0.2736828213,
      "max": 0.3273809603,
      "times": [
        0.3097364243,
        0.3217849843,
        0.2864622363,
        0.2875432903,
        0.2736828213,
        0.2749710093,
        0.2846591243,
        0.2914140113,
        0.3273809603,
        0.2802971033
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 0.3011691547,
      "stddev": 0.015414173015229382,
      "median": 0.2968080513,
      "user": 0.25415254,
      "system": 0.60970312,
      "min": 0.2766503363,
      "max": 0.3261337383,
      "times": [
        0.3261337383,
        0.2968841313,
        0.3107788513,
        0.29054989529999997,
        0.2967319713,
        0.2869010843,
        0.2953552983,
        0.2766503363,
        0.3168986503,
        0.3148075903
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.29242089160000007,
      "stddev": 0.00990354508399458,
      "median": 0.29186205379999997,
      "user": 0.24693174,
      "system": 0.5458083199999999,
      "min": 0.2771826343,
      "max": 0.3093446433,
      "times": [
        0.3031765993,
        0.3093446433,
        0.2855684673,
        0.2829178413,
        0.2998708473,
        0.2771826343,
        0.2867925833,
        0.2893081613,
        0.2956311923,
        0.2944159463
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.3086536949,
      "stddev": 0.018074722115989168,
      "median": 0.3098381658,
      "user": 0.24670163999999994,
      "system": 0.5831608199999999,
      "min": 0.2832599783,
      "max": 0.3323031863,
      "times": [
        0.3027745433,
        0.2909817383,
        0.2832599783,
        0.2954204723,
        0.3169017883,
        0.3323031863,
        0.3187743793,
        0.2908812603,
        0.3296686013,
        0.3255710013
      ]
    }
  ]
}

Scenario: Isolated linker: fresh install, cold cache + cold store

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 2.645 ± 0.027 2.592 2.690 1.54 ± 0.12
pacquet@main 2.628 ± 0.022 2.590 2.670 1.53 ± 0.12
pnpr@HEAD 1.719 ± 0.133 1.567 1.921 1.00
pnpr@main 1.764 ± 0.138 1.544 1.952 1.03 ± 0.11
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 2.64528987786,
      "stddev": 0.027173937250398624,
      "median": 2.64434704476,
      "user": 1.9606602199999998,
      "system": 1.5462858599999998,
      "min": 2.59232407526,
      "max": 2.6903126052600004,
      "times": [
        2.64824186426,
        2.6620866422600002,
        2.63712929226,
        2.6903126052600004,
        2.6591143352600004,
        2.6675930942600004,
        2.63600033926,
        2.6404522252600002,
        2.6196443052600005,
        2.59232407526
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 2.6279651942600006,
      "stddev": 0.022044600301654588,
      "median": 2.6278512062600003,
      "user": 1.86938382,
      "system": 1.4745070599999999,
      "min": 2.58966759826,
      "max": 2.66975505026,
      "times": [
        2.60456647826,
        2.58966759826,
        2.63837789926,
        2.6310843962600003,
        2.66975505026,
        2.6173187382600003,
        2.6246180162600004,
        2.63724399826,
        2.6440643602600002,
        2.62295540726
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 1.7188237959600001,
      "stddev": 0.13280084023267302,
      "median": 1.69169657426,
      "user": 1.5839275199999998,
      "system": 1.4294253600000002,
      "min": 1.5666212562600002,
      "max": 1.9205536712600002,
      "times": [
        1.63694689926,
        1.5666212562600002,
        1.56673740326,
        1.7436023042600002,
        1.9205536712600002,
        1.6441777882600002,
        1.73921536026,
        1.62641121026,
        1.83344598226,
        1.91052608426
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 1.76376656656,
      "stddev": 0.13753567015351856,
      "median": 1.76318290126,
      "user": 1.6854185200000003,
      "system": 1.6248966599999999,
      "min": 1.54424147626,
      "max": 1.95216222926,
      "times": [
        1.56243661626,
        1.82515457226,
        1.74112577826,
        1.7779692822600002,
        1.74839652026,
        1.89738042026,
        1.54424147626,
        1.95216222926,
        1.69052889826,
        1.89826987226
      ]
    }
  ]
}

Scenario: Isolated linker: fresh install, hot cache + hot store

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 553.4 ± 46.5 504.3 642.8 1.57 ± 0.15
pacquet@main 551.2 ± 45.0 485.5 618.3 1.56 ± 0.15
pnpr@HEAD 352.4 ± 17.7 325.2 389.3 1.00
pnpr@main 368.5 ± 25.7 333.2 409.5 1.05 ± 0.09
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.5534274801400001,
      "stddev": 0.04654600564752713,
      "median": 0.54338791574,
      "user": 0.7489077799999999,
      "system": 0.9159329199999998,
      "min": 0.50428678174,
      "max": 0.64275982974,
      "times": [
        0.53180264274,
        0.56674253874,
        0.55765673974,
        0.54218241974,
        0.51057532274,
        0.54459341174,
        0.50428678174,
        0.51188108374,
        0.62179403074,
        0.64275982974
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 0.55124469804,
      "stddev": 0.044960967127549295,
      "median": 0.54807760624,
      "user": 0.7414427800000001,
      "system": 0.99247412,
      "min": 0.48546085274000006,
      "max": 0.61828474174,
      "times": [
        0.54461203274,
        0.53171672574,
        0.49574816474000005,
        0.48546085274000006,
        0.55154317974,
        0.59466471474,
        0.60340758474,
        0.61828474174,
        0.56738063974,
        0.51962834374
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.35244176864,
      "stddev": 0.017656389299240738,
      "median": 0.35071526774000006,
      "user": 0.25997597999999994,
      "system": 0.58811592,
      "min": 0.32523939674,
      "max": 0.38933134674000003,
      "times": [
        0.38933134674000003,
        0.35712586674,
        0.35517177774,
        0.32523939674,
        0.33733529474,
        0.35308686374000003,
        0.34258578574000004,
        0.34834367174,
        0.36969555574,
        0.34650212674
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.36853195624,
      "stddev": 0.025747212977743877,
      "median": 0.36138578874000005,
      "user": 0.26021047999999997,
      "system": 0.6553650199999999,
      "min": 0.33318930674,
      "max": 0.40947290774000006,
      "times": [
        0.37994805574,
        0.36201233474000005,
        0.36075924274000004,
        0.35237810674000003,
        0.34064693674,
        0.33318930674,
        0.39676255774,
        0.40947290774000006,
        0.39613029574,
        0.35401981774
      ]
    }
  ]
}

Scenario: Isolated linker: fresh install, cold cache + hot store

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 1.878 ± 0.031 1.827 1.922 5.60 ± 0.22
pacquet@main 1.834 ± 0.035 1.784 1.898 5.47 ± 0.22
pnpr@HEAD 0.335 ± 0.012 0.316 0.357 1.00
pnpr@main 0.380 ± 0.012 0.368 0.400 1.13 ± 0.05
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 1.8780314805000002,
      "stddev": 0.03146765348334777,
      "median": 1.8777645315,
      "user": 1.1431681799999998,
      "system": 1.0649446399999998,
      "min": 1.8270540205,
      "max": 1.9221472495,
      "times": [
        1.8684893145,
        1.8415951805000002,
        1.8270540205,
        1.8733451415000002,
        1.8510866615000001,
        1.9004604945,
        1.9221472495,
        1.9084685775,
        1.9054842435000001,
        1.8821839215
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 1.8344686168,
      "stddev": 0.03542887001916729,
      "median": 1.8283530325,
      "user": 1.00480068,
      "system": 0.9789152400000001,
      "min": 1.7839210655,
      "max": 1.8976439495,
      "times": [
        1.8757849645000002,
        1.8563390285,
        1.8035042855,
        1.8234555365,
        1.8976439495,
        1.8122382775,
        1.8332505285,
        1.7839210655,
        1.8076456005,
        1.8509029315
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.3353181491,
      "stddev": 0.011717859773015628,
      "median": 0.3345052725,
      "user": 0.23773068,
      "system": 0.55547374,
      "min": 0.3158333025,
      "max": 0.35712190450000003,
      "times": [
        0.35712190450000003,
        0.3290390065,
        0.3158333025,
        0.33025514650000004,
        0.34315541650000003,
        0.33702446350000004,
        0.32491788650000003,
        0.3468238195,
        0.3323318195,
        0.3366787255
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.3797710947,
      "stddev": 0.01194484163774665,
      "median": 0.3776242195,
      "user": 0.26882868000000004,
      "system": 0.6629259399999999,
      "min": 0.3680662505,
      "max": 0.39968212750000004,
      "times": [
        0.36869361650000004,
        0.39968212750000004,
        0.38825157450000003,
        0.3693309845,
        0.3755485705,
        0.37969986850000004,
        0.36966437750000003,
        0.3809567245,
        0.39781685250000004,
        0.3680662505
      ]
    }
  ]
}

Scenario: Isolated linker: fresh resolve, hot cache, offline

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 264.4 ± 21.8 242.7 311.8 2.72 ± 0.25
pacquet@main 224.6 ± 14.3 206.1 260.9 2.31 ± 0.18
pnpr@HEAD 98.6 ± 5.0 90.3 112.0 1.02 ± 0.07
pnpr@main 97.1 ± 4.2 90.0 112.3 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.2643639899145455,
      "stddev": 0.02179691785049322,
      "median": 0.25791622646000006,
      "user": 0.22325806909090906,
      "system": 0.10811872545454544,
      "min": 0.24271335746,
      "max": 0.31182514946000006,
      "times": [
        0.24424530946,
        0.25065298446000006,
        0.26318336946000004,
        0.25791622646000006,
        0.26673226546000006,
        0.24916667146000002,
        0.24271335746,
        0.25409545346000006,
        0.29601299046,
        0.31182514946000006,
        0.27146011146000004
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 0.22457129337666668,
      "stddev": 0.014317097247888428,
      "median": 0.22228134296000002,
      "user": 0.1985122433333333,
      "system": 0.12051451333333335,
      "min": 0.20609506546,
      "max": 0.26094634846000003,
      "times": [
        0.23225773346,
        0.21980593546000002,
        0.21427538746000002,
        0.22386896646,
        0.21903719846,
        0.22127439146,
        0.22328829446,
        0.26094634846000003,
        0.23345675046,
        0.23129636746,
        0.20609506546,
        0.20925308146000002
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.09864440309333335,
      "stddev": 0.005027765860519229,
      "median": 0.09861263296,
      "user": 0.025265860000000005,
      "system": 0.015396413333333334,
      "min": 0.09032231146,
      "max": 0.11197869446,
      "times": [
        0.09288914046,
        0.09729081146,
        0.09803296246,
        0.09126450546,
        0.09617131446,
        0.10006218846,
        0.10462514846,
        0.09961361446,
        0.11197869446,
        0.09979249146000001,
        0.10438252246,
        0.10142196146,
        0.10377045846,
        0.09657231446,
        0.09470060346,
        0.09517070146,
        0.09763463346,
        0.09211396646,
        0.09090091846,
        0.09610119046,
        0.09919230346,
        0.09604496846,
        0.10483808646000001,
        0.10243351346,
        0.09421105546,
        0.10534050346,
        0.09987847246,
        0.10046930946,
        0.09032231146,
        0.10211142646
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.09706782352896556,
      "stddev": 0.004158866188767274,
      "median": 0.09665383246,
      "user": 0.02271805655172414,
      "system": 0.01720855931034483,
      "min": 0.08997173146,
      "max": 0.11225530546,
      "times": [
        0.09562095846,
        0.10237458946,
        0.08997173146,
        0.09473847146,
        0.09713492046,
        0.09883622646,
        0.09434202246,
        0.11225530546,
        0.09415934246,
        0.09423496046,
        0.09692861146,
        0.09916297246,
        0.10092825246,
        0.09719707946,
        0.09301683846,
        0.09824727246,
        0.09410966846,
        0.09985638446,
        0.09875675346,
        0.09681213346,
        0.09557887246,
        0.09473462846,
        0.09970631546,
        0.09575991246,
        0.09394064546,
        0.09665383246,
        0.09588122646,
        0.10231814246,
        0.09170881146
      ]
    }
  ]
}

Scenario: Isolated linker: peer-heavy resolve, hot cache, offline

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 768.0 ± 140.0 627.7 1005.5 1.00
pacquet@main 1039.1 ± 243.2 754.6 1412.9 1.35 ± 0.40
pnpm@HEAD 2946.8 ± 80.3 2870.2 3073.9 3.84 ± 0.71
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.7679911774844443,
      "stddev": 0.14001366527959289,
      "median": 0.73125649504,
      "user": 0.7259842644444443,
      "system": 0.14066135333333332,
      "min": 0.62770153304,
      "max": 1.00554930304,
      "times": [
        0.65414229304,
        0.62770153304,
        1.00554930304,
        0.74316120104,
        0.68676728704,
        0.91209831304,
        0.63722522404,
        0.9140189480400001,
        0.73125649504
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 1.0390951105955555,
      "stddev": 0.24318289736849363,
      "median": 0.95856759104,
      "user": 0.983282708888889,
      "system": 0.2524543533333333,
      "min": 0.75463352604,
      "max": 1.41285146104,
      "times": [
        0.76236435604,
        0.75463352604,
        0.84573766604,
        1.1538141930399999,
        0.95856759104,
        0.93374497904,
        1.31822208804,
        1.41285146104,
        1.21192013504
      ]
    },
    {
      "command": "pnpm@HEAD",
      "mean": 2.946768758817778,
      "stddev": 0.08034852493008936,
      "median": 2.90639689404,
      "user": 4.232194597777776,
      "system": 0.2902909088888889,
      "min": 2.8701538110400002,
      "max": 3.07387329304,
      "times": [
        3.07387329304,
        2.90091841004,
        2.93875406404,
        2.88093149404,
        2.8701538110400002,
        3.02387953904,
        3.04965842204,
        2.8763529020400003,
        2.90639689404
      ]
    }
  ]
}

Scenario: Isolated linker: fresh restore, cold cache + cold store + cold pnpr

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 4.606 ± 0.163 4.466 4.945 1.30 ± 0.07
pacquet@main 4.499 ± 0.126 4.420 4.840 1.27 ± 0.06
pnpr@HEAD 3.586 ± 0.146 3.458 3.859 1.01 ± 0.06
pnpr@main 3.554 ± 0.132 3.460 3.853 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 4.606315834839999,
      "stddev": 0.1627286704157926,
      "median": 4.568653358839999,
      "user": 1.93220216,
      "system": 1.48397992,
      "min": 4.4662918413399995,
      "max": 4.94501331634,
      "times": [
        4.609436381339999,
        4.8077402953399995,
        4.47873577434,
        4.4662918413399995,
        4.94501331634,
        4.4682178623399995,
        4.47062783934,
        4.62765016834,
        4.5278703363399995,
        4.66157453334
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 4.499331533039999,
      "stddev": 0.12557691005201665,
      "median": 4.455456863839999,
      "user": 1.8403794599999999,
      "system": 1.4144441200000002,
      "min": 4.419516315339999,
      "max": 4.84038019334,
      "times": [
        4.5511466683399995,
        4.49416790834,
        4.84038019334,
        4.46129730934,
        4.448488569339999,
        4.4300091973399995,
        4.453631199339999,
        4.4572825283399995,
        4.43739544134,
        4.419516315339999
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 3.58555454444,
      "stddev": 0.14562200200542222,
      "median": 3.5266832798400003,
      "user": 1.3592461599999999,
      "system": 1.2740554200000003,
      "min": 3.45765025334,
      "max": 3.8591858983400003,
      "times": [
        3.6559159193400004,
        3.46659694034,
        3.4734088993400003,
        3.8591858983400003,
        3.79697153034,
        3.55541561234,
        3.47017722334,
        3.62227222034,
        3.49795094734,
        3.45765025334
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 3.5536798178400004,
      "stddev": 0.13156015272778038,
      "median": 3.48694264234,
      "user": 1.3060688599999997,
      "system": 1.2781719200000001,
      "min": 3.45960244834,
      "max": 3.85338153734,
      "times": [
        3.85338153734,
        3.49097338334,
        3.4612868213400003,
        3.47579292034,
        3.48291190134,
        3.46411792634,
        3.55073210234,
        3.70964703834,
        3.45960244834,
        3.58835209934
      ]
    }
  ]
}

@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Projectpnpm's project
Branchpr/13686
Testbedpacquet
Click to view all benchmark results
BenchmarkLatencyBenchmark Result
milliseconds (ms)
(Result Δ%)
Upper Boundary
milliseconds (ms)
(Limit %)
isolated-linker.fresh-install.cold-cache.cold-store📈 view plot
🚷 view threshold
2,592.32 ms
(-4.36%)Baseline: 2,710.57 ms
3,252.69 ms
(79.70%)
isolated-linker.fresh-install.cold-cache.hot-store📈 view plot
🚷 view threshold
1,827.05 ms
(+1.36%)Baseline: 1,802.50 ms
2,163.00 ms
(84.47%)
isolated-linker.fresh-install.hot-cache.hot-store📈 view plot
🚷 view threshold
504.29 ms
(+10.98%)Baseline: 454.40 ms
545.28 ms
(92.48%)
isolated-linker.fresh-resolve.hot-cache.offline📈 view plot
🚷 view threshold
242.71 ms
(+14.80%)Baseline: 211.42 ms
253.70 ms
(95.67%)
isolated-linker.fresh-restore.cold-cache.cold-store📈 view plot
🚷 view threshold
2,371.77 ms
(-3.76%)Baseline: 2,464.49 ms
2,957.39 ms
(80.20%)
isolated-linker.fresh-restore.cold-cache.cold-store.cold-pnpr📈 view plot
🚷 view threshold
4,466.29 ms
(-0.95%)Baseline: 4,509.23 ms
5,411.08 ms
(82.54%)
isolated-linker.fresh-restore.hot-cache.hot-store📈 view plot
🚷 view threshold
273.68 ms
(-9.47%)Baseline: 302.30 ms
362.75 ms
(75.45%)
isolated-linker.peer-heavy-resolve.hot-cache.offline📈 view plot
🚷 view threshold
627.70 ms
(-13.25%)Baseline: 723.58 ms
868.30 ms
(72.29%)
🐰 View full continuous benchmarking report in Bencher

@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Projectpnpm's project
Branchpr/13686
Testbedpnpr

⚠️ WARNING: No Threshold found!

Without a Threshold, no Alerts will ever be generated.

Click here to create a new Threshold
For more information, see the Threshold documentation.
To only post results if a Threshold exists, set the --ci-only-thresholds flag.

Click to view all benchmark results
BenchmarkLatencymilliseconds (ms)
isolated-linker.fresh-install.cold-cache.cold-store📈 view plot
⚠️ NO THRESHOLD
1,566.62 ms
isolated-linker.fresh-install.cold-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
315.83 ms
isolated-linker.fresh-install.hot-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
325.24 ms
isolated-linker.fresh-resolve.hot-cache.offline📈 view plot
⚠️ NO THRESHOLD
90.32 ms
isolated-linker.fresh-restore.cold-cache.cold-store📈 view plot
⚠️ NO THRESHOLD
1,362.72 ms
isolated-linker.fresh-restore.cold-cache.cold-store.cold-pnpr📈 view plot
⚠️ NO THRESHOLD
3,457.65 ms
isolated-linker.fresh-restore.hot-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
277.18 ms
🐰 View full continuous benchmarking report in Bencher

@zkochan
zkochan merged commit ea90e2d into main Aug 6, 2026
42 of 57 checks passed
@zkochan
zkochan deleted the fix-13681 branch August 6, 2026 20:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

product: pacquet reviewed: coderabbit CodeRabbit submitted an approving review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants