Repository navigation
Conversation
…alls in memory Full packuments reached the resolver's in-memory caches unstripped on plain installs through three routes: optional dependencies (fetched full for libc), minimumReleaseAge time upgrades, and disk mirrors holding full bodies. Each document was pinned twice for the whole resolution phase (metaCache and the settled-fetch memo), so per-version readmes, scripts, and descriptions accumulated to multi-GB heaps and OOM'd large workspaces (#8441). Every retained packument is now condensed to the abbreviated field set via a WeakMap-memoized clearMeta, so all layers share one condensed copy. Resolvers created with fullMetadata and no filterMetadata (pnpm outdated --long) keep full documents. The release-age upgrade path now mirrors the condensed form instead of writing full bodies into the abbreviated mirror.
|
Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (9)
💤 Files with no reviewable changes (2)
🚧 Files skipped from review as they are similar to previous changes (6)
📝 WalkthroughWalkthroughThe npm resolver now retains condensed package metadata in memory, memoizes condensed objects, preserves full metadata when configured, and applies the policy across fetch, cache, upgrade, and disk persistence paths. Tests cover metadata fields, cache behavior, memoization, optional dependencies, and bounded-memory resolution. ChangesMetadata retention and caching
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant Resolver
participant MetadataMemoizer
participant MetadataCache
participant Mirror
Resolver->>MetadataMemoizer: Fetch registry metadata
MetadataMemoizer->>MetadataCache: Retain condensed settled metadata
MetadataCache->>Mirror: Persist selected metadata representation
Mirror-->>Resolver: Load metadata for package selection
Resolver-->>Resolver: Keep full metadata only when configured
Assessment against linked issues
Possibly related PRs
Suggested labels: Suggested reviewers: ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
PR Summary by QodoCondense cached registry metadata to prevent OOM on large installs
AI Description
Diagram
High-Level Assessment
Files changed (9)
|
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
pnpm11/resolving/npm-resolver/src/pickPackage.ts (1)
650-655: 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick winLog the best-effort mirror-write failure.
This catch silently discards
saveMetafailures. Keep the write non-fatal, but log the error withpkgMirrorcontext before proceeding.As per coding guidelines, never swallow errors and include the offending path. Based on learnings, mirror-write failures must be logged while the install continues. <coding_guidelines> <retrieved_learnings>
🤖 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 `@pnpm11/resolving/npm-resolver/src/pickPackage.ts` around lines 650 - 655, Update the catch block around saveMeta in the runLimited mirror-write flow to log the failure with the pkgMirror path and caught error, while preserving the non-fatal behavior so installation continues after the log.Sources: Coding guidelines, Learnings
pnpm11/resolving/npm-resolver/src/memoizeFetchMetadata.ts (1)
64-78: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick winHandle failures from
condenseSettledMeta.If
condense(result.meta)throws, the ignoredthenpromise rejects without a handler, potentially terminating the process while leaving the full resolvedpendingentry cached. Observe that rejection, evict the entry, and report the error with package context.As per path instructions, registry metadata must be treated as attacker-controlled. <path_instructions>
🤖 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 `@pnpm11/resolving/npm-resolver/src/memoizeFetchMetadata.ts` around lines 64 - 78, Update the ignored promise chain in memoizeFetchMetadata so errors thrown while condensing result.meta are handled. Evict the cache entry when it still references pending, and report the error using the existing error-reporting mechanism with the package context available to this function. Preserve the successful metadata caching behavior and ensure the rejection is not left unhandled.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 `@pnpm11/resolving/npm-resolver/src/memoizeFetchMetadata.ts`:
- Around line 64-78: Update the ignored promise chain in memoizeFetchMetadata so
errors thrown while condensing result.meta are handled. Evict the cache entry
when it still references pending, and report the error using the existing
error-reporting mechanism with the package context available to this function.
Preserve the successful metadata caching behavior and ensure the rejection is
not left unhandled.
In `@pnpm11/resolving/npm-resolver/src/pickPackage.ts`:
- Around line 650-655: Update the catch block around saveMeta in the runLimited
mirror-write flow to log the failure with the pkgMirror path and caught error,
while preserving the non-fatal behavior so installation continues after the log.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: a055c856-abff-431a-90a1-904201242f4e
📒 Files selected for processing (9)
.changeset/condense-retained-packuments.mdpnpm11/resolving/npm-resolver/src/clearMeta.tspnpm11/resolving/npm-resolver/src/index.tspnpm11/resolving/npm-resolver/src/memoizeFetchMetadata.tspnpm11/resolving/npm-resolver/src/pickPackage.tspnpm11/resolving/npm-resolver/test/clearMeta.test.tspnpm11/resolving/npm-resolver/test/memoizeFetchMetadata.test.tspnpm11/resolving/npm-resolver/test/metaCache.test.tspnpm11/resolving/npm-resolver/test/optionalDependencies.test.ts
Confidence Score: 5/5Safe to merge; the fix is well-contained to the resolver's in-memory and on-disk caching layers with no changes to the lockfile format, CLI surface, or wire protocol. The core condensation logic, WeakMap memoization, and writeCondensed flag are all correct across every fetch path. Two deterministic regression guards fail on pre-fix code. The only uncovered path is the disk-write side of the release-age upgrade inside persistFreshMeta, which is a test gap rather than a code defect. The release-age upgrade branch of persistFreshMeta in pickPackage.ts (writeCondensed = true where resultToSave !== fetched && meta !== resultToSave.meta) has no dedicated test — metaCache.test.ts would benefit from a warm-cache scenario with minimumReleaseAge active. Reviews (5): Last reviewed commit: "docs(resolver): trim comments to the sel..." | Re-trigger Greptile |
Code Review by Qodo
Context used✅ Tickets:
🎫 pnpm install suddenly reaches heap limit every time. 🎫 pnpm install fetch all binaries ignoring os / arch✅ Compliance rules (platform):
18 rules 1.
|
Resolves 30 optional dependencies whose full documents each carry 4 MB of install-irrelevant bulk under a 100 MB --max-old-space-size cap. Retaining the parsed documents, as before the condensing fix for #8441, aborts the child with a V8 heap-limit error (verified: exit 134 against the pre-fix resolver); the condensed working set leaves roughly a 3x headroom, so the guard is deterministic rather than timing-sensitive.
PR Code Suggestions ✨Latest suggestions up to ba8844d Warning
Previous suggestionsSuggestions
|
||||||||||||||||||
|
Code review by qodo was updated up to the latest commit 9ee3975 |
PR Code Suggestions ✨Warning
|
|||||||||
There was a problem hiding this comment.
🧹 Nitpick comments (3)
pnpm11/resolving/npm-resolver/test/fixtures/resolve-bloated-metadata.mjs (2)
6-9: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueSort standard library imports alphabetically.
As per coding guidelines, standard library imports should be ordered alphabetically.
♻️ Proposed fix
-import http from 'node:http' -import { mkdtempSync } from 'node:fs' +import { mkdtempSync } from 'node:fs' +import http from 'node:http' import os from 'node:os' import path from 'node:path'🤖 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 `@pnpm11/resolving/npm-resolver/test/fixtures/resolve-bloated-metadata.mjs` around lines 6 - 9, Reorder the standard-library imports in the fixture so the imported module specifiers are alphabetized, keeping the existing imports and behavior unchanged.Source: Coding guidelines
53-56: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueClean up the temporary cache directory after successful execution.
To avoid leaving residual directories in the system's temporary folder across local test runs, consider extracting the
cacheDirpath and removing it at the end of the script.♻️ Proposed fix to prevent temp dir leakage
First, update the
node:fsimport to includermSync:-import { mkdtempSync } from 'node:fs' +import { mkdtempSync, rmSync } from 'node:fs'Next, extract the variable here:
+const cacheDir = mkdtempSync(path.join(os.tmpdir(), 'pnpm-memory-bounded-')) const { resolveFromNpm } = createNpmResolver(createFetchFromRegistry({}), () => undefined, { - cacheDir: mkdtempSync(path.join(os.tmpdir(), 'pnpm-memory-bounded-')), + cacheDir, registries: { default: registry }, })Finally, add the cleanup below
server.close()at the bottom of the file (Line 71):server.close() +rmSync(cacheDir, { recursive: true, force: true })🤖 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 `@pnpm11/resolving/npm-resolver/test/fixtures/resolve-bloated-metadata.mjs` around lines 53 - 56, Update the fixture setup around createNpmResolver to store the mkdtempSync result in a cacheDir variable and import rmSync from node:fs. After the successful execution and server.close() at the script’s end, remove that temporary cache directory with rmSync using recursive cleanup.pnpm11/resolving/npm-resolver/test/memoryBounded.test.ts (1)
25-30: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winExpose the child process stderr for accurate diagnosis.
Wrapping
execFileSyncinexpect().not.toThrow()causes Jest to swallow the customstderrbuffer attached to the error object. This defeats the intent of the comment stating "with the child's stderr attached for diagnosis". Instead, catch the error, append thestderrto the error message, and rethrow it so Jest can display the full diagnostic context. As per coding guidelines, do not swallow errors and ensure contextual information is included in error messages.♻️ Proposed fix
- expect(() => { - execFileSync(process.execPath, ['--max-old-space-size=100', fixture], { - stdio: ['ignore', 'ignore', 'pipe'], - timeout: 100_000, - }) - }).not.toThrow() + try { + execFileSync(process.execPath, ['--max-old-space-size=100', fixture], { + stdio: ['ignore', 'ignore', 'pipe'], + timeout: 100_000, + }) + } catch (err: any) { + if (err.stderr != null) { + err.message += `\n\nChild stderr:\n${err.stderr.toString()}` + } + throw err + }🤖 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 `@pnpm11/resolving/npm-resolver/test/memoryBounded.test.ts` around lines 25 - 30, Update the execFileSync assertion in memoryBounded.test.ts to catch failures explicitly, append the child process stderr to the thrown error message, and rethrow the enriched error so Jest displays the diagnostic context. Preserve the existing command options and successful execution behavior.Source: Coding guidelines
🤖 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.
Nitpick comments:
In `@pnpm11/resolving/npm-resolver/test/fixtures/resolve-bloated-metadata.mjs`:
- Around line 6-9: Reorder the standard-library imports in the fixture so the
imported module specifiers are alphabetized, keeping the existing imports and
behavior unchanged.
- Around line 53-56: Update the fixture setup around createNpmResolver to store
the mkdtempSync result in a cacheDir variable and import rmSync from node:fs.
After the successful execution and server.close() at the script’s end, remove
that temporary cache directory with rmSync using recursive cleanup.
In `@pnpm11/resolving/npm-resolver/test/memoryBounded.test.ts`:
- Around line 25-30: Update the execFileSync assertion in memoryBounded.test.ts
to catch failures explicitly, append the child process stderr to the thrown
error message, and rethrow the enriched error so Jest displays the diagnostic
context. Preserve the existing command options and successful execution
behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 3ebd7e80-c603-45ee-a86f-dc2858e991b6
📒 Files selected for processing (2)
pnpm11/resolving/npm-resolver/test/fixtures/resolve-bloated-metadata.mjspnpm11/resolving/npm-resolver/test/memoryBounded.test.ts
Deduplicate the three best-effort mirror-write blocks into saveMetaBestEffort, which debug-logs a write failure with the mirror path instead of discarding it. Guard the settled-fetch swap in memoizeFetchMetadata against a throwing condenser: the swap runs in a fire-and-forget then-callback where a throw would become an unhandled rejection, so a condense failure now falls back to retaining the uncondensed meta. Give upgradeMetaForCache an options object instead of a fourth positional parameter, surface the memory-guard child's stderr in the jest failure message, and clean up the fixture's temp cache dir.
|
Addressed the CodeRabbit review findings in 1487e0d:
Written by an agent (Claude Code, claude-fable-5). |
|
Code review by qodo was updated up to the latest commit d80a9f2 |
PR Code Suggestions ✨Warning
|
|||||||||
Summary
Fixes #8441.
pnpm installran out of memory on large dependency graphs because full registry documents were retained in memory unstripped for the whole resolution phase. On a plain install, full packuments (per-version readmes,scripts, descriptions, exports maps, maintainer info) reach the in-memory caches through three routes:libc(pnpm install fetch all binaries ignoring os / arch #9950) and cached whole.minimumReleaseAgeupgrades — recently-modified packages are re-fetched as full documents for per-versiontimeand cached whole; the full body was also written into the abbreviated disk mirror, so warm installs re-inflated from disk too.Each document was pinned twice — in the resolver's
metaCacheand inmemoizeFetchMetadata's settled-entry memo. Heap snapshots from the reproduction (haines/pnpm-memory, 1464 packages,minimumReleaseAgeactive) showed ~645 MB of full-document strings plus ~340 MB of parsed objects at the 1 GB heap limit.With this change, every packument retained in memory is condensed to the abbreviated field set (everything installation reads: dependency maps,
dist,libc/os/cpu,time,_npmUser,hasInstallScript, …). Measured on the reproduction:Ineffective mark-compacts near heap limit) at ~1176 of 1464 packages with--max-old-space-size=1024.--heapsnapshot-near-heap-limithandler never fires.Two CI regression guards ride along, both verified to fail against a build of the pre-fix source:
resolving/npm-resolver/test/memoryBounded.test.ts): a subprocess capped at--max-old-space-size=100resolves 30 optional dependencies whose documents each carry 4 MB of install-irrelevant bulk from a local server. Pre-fix: exit 134 (V8 heap-limit abort); post-fix: passes with ~3× headroom.pnpm/test/install/memoryBounded.ts): the bundledpnpm install --lockfile-onlyresolves 40 optional dependencies with 6 MB of bulk each (240 MB total) from a local registry stub under a 256 MB cap, withnetwork-concurrency=4so the cap measures retention rather than in-flight transients. Pre-fix: heap-limit abort; post-fix: passes even a 192 MB cap. This one catches a future retention route anywhere in the install pipeline, not just in the resolver package.Squash Commit Body
Checklist
pnpm/port, or the description notes what still needs porting.pnpm changeset) if this PR changes any publishedpackage. Keep it short and written for pnpm users — it becomes a release note.
Pacquet porting note
Pacquet retains full documents through the same three routes (
pick_package.rs:437-438ties stripping to the install-widefilter_metadata, cache insert atpick_package.rs:724, upgrade path atpick_package.rs:1214-1248, unstripped disk promotes atpick_package.rs:529/611/642), but the impact is materially smaller: versions are kept as lazyArc<RawValue>byte fragments rather than fully-parsed object graphs, so the retained bulk is roughly the raw document size. A follow-up should applyclear_meta(mirror.rs:323) at those sites behind the same "retains full meta" gate as this PR.Written by an agent (Claude Code, claude-fable-5).
Summary by CodeRabbit
pnpm installby condensing cached npm packument metadata to install-relevant fields.etagcontent when persisting cached metadata.