Skip to content

fix: share raw metadata across in-flight requests - #13079

Merged
zkochan merged 2 commits into
pnpm:mainfrom
Stanzilla:fix/13077-metadata-cache-oom
Jul 16, 2026
Merged

zkochan merged 2 commits into
pnpm:mainfrom
Stanzilla:fix/13077-metadata-cache-oom

Conversation

@Stanzilla

@Stanzilla Stanzilla commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • keep the raw metadata response shared while a registry request is in flight
  • replace the settled cache entry with a body-less clone to avoid retaining large response bodies
  • prevent settled requests from repopulating a cache that was cleared
  • add regression coverage and patch changesets for the resolver and CLI

Motivation

memoizeFetchMetadata previously cached the body-less derived promise immediately. Concurrent callers therefore received metadata without jsonText and each independently ran JSON.stringify(meta) before the metadata file write limiter.

For Next.js, the full registry metadata is about 31 MB and contains 3,845 versions. This fan-out can exhaust the V8 heap during installs in large workspaces. The behavior was introduced by #12870.

The cache now exposes the original promise until it settles, so all in-flight callers can reuse the raw response. It then atomically swaps in the body-less promise, preserving the existing memory-retention behavior for later cache hits.

Reproduction result

With 40 concurrent callers, the Next.js full metadata, and a 1 GiB V8 heap:

  • before: exits with status 134 due to JavaScript heap out of memory
  • after: completes in all three runs with 171-212 MiB maximum RSS

Checks

  • resolver TypeScript build
  • focused memoizeFetchMetadata.test.ts Jest suite
  • ESLint for the changed resolver files
  • repository pre-push compile, lint, Cargo clippy, formatting, and documentation checks

Closes #13077


View with Codesmith Autofix with Codesmith
Need help on this PR? Tag /codesmith with what you need. Autofix is disabled.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed an out-of-memory regression during concurrent workspace resolution of packages with large registry metadata.
    • Improved metadata in-flight request memoization so parallel requests dedupe correctly while avoiding unnecessary retention of large response bodies.
    • Updated cache-clear and failure behavior to prevent stale or redundant fetches during active requests.
  • Tests
    • Expanded concurrency coverage to ensure only one in-flight metadata fetch occurs across parallel resolutions.
  • Documentation
    • Refreshed comments describing metadata caching lifecycle and sharing behavior.
  • Chores
    • Bumped patch dependencies and recorded the release changes.

@Stanzilla
Stanzilla requested a review from zkochan as a code owner July 16, 2026 13:13
Copilot AI review requested due to automatic review settings July 16, 2026 13:13

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

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@coderabbitai

coderabbitai Bot commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 7a4b31c6-2e99-450c-ad56-689a99ee9844

📥 Commits

Reviewing files that changed from the base of the PR and between 84386c8 and 851100e.

📒 Files selected for processing (5)
  • .changeset/share-inflight-packuments.md
  • pnpm11/resolving/npm-resolver/src/fetch.ts
  • pnpm11/resolving/npm-resolver/src/memoizeFetchMetadata.ts
  • pnpm11/resolving/npm-resolver/test/memoizeFetchMetadata.test.ts
  • pnpm11/resolving/npm-resolver/test/metaCache.test.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • .changeset/share-inflight-packuments.md
  • pnpm11/resolving/npm-resolver/test/memoizeFetchMetadata.test.ts

📝 Walkthrough

Walkthrough

The npm resolver now shares the original metadata fetch promise among concurrent callers, then replaces it with a body-less cached result after settlement. Cache clearing and rejection handling avoid stale entries, with tests covering concurrency, lifecycle races, and serialization behavior.

Changes

Metadata cache behavior

Layer / File(s) Summary
Inflight cache lifecycle
pnpm11/resolving/npm-resolver/src/memoizeFetchMetadata.ts, pnpm11/resolving/npm-resolver/src/fetch.ts
Inflight callers share the raw result, while settled cache entries remove jsonText; identity checks protect replacement and clearing behavior.
Concurrency and lifecycle validation
pnpm11/resolving/npm-resolver/test/memoizeFetchMetadata.test.ts, pnpm11/resolving/npm-resolver/test/metaCache.test.ts
Tests cover shared raw results, clearing and rejection races, single-fetch concurrency, and avoiding per-project metadata serialization.
Release metadata
.changeset/share-inflight-packuments.md
Records patch updates for the npm resolver and pnpm with the concurrent metadata resolution fix.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Assessment against linked issues

Objective Addressed Explanation
Share fetched registry responses among concurrent workspace resolutions and avoid repeated metadata serialization [#13077] ✅
Release raw registry bodies after the inflight request settles [#13077] ✅

Sequence Diagram(s)

sequenceDiagram
  participant WorkspaceResolvers
  participant memoizeFetchMetadata
  participant Registry
  WorkspaceResolvers->>memoizeFetchMetadata: request package metadata
  memoizeFetchMetadata->>Registry: fetch metadata
  WorkspaceResolvers->>memoizeFetchMetadata: concurrent request
  memoizeFetchMetadata-->>WorkspaceResolvers: share raw inflight result
  Registry-->>memoizeFetchMetadata: settle request
  memoizeFetchMetadata-->>WorkspaceResolvers: store body-less settled result
Loading

Suggested labels: product: pnpm@11

Suggested reviewers: zkochan, copilot

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install timed out. The project may have too many dependencies for the sandbox.


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.

@greptile-apps

greptile-apps Bot commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

The change is safe to merge — it corrects a narrow, well-understood caching invariant without altering any external API or on-disk format.

The logic is straightforward: one Map, one identity guard, and two settlement paths that are each unit-tested and integration-tested. The microtask ordering guarantee (settlement handlers registered before the caller's await continuation) means the cache swap is always atomic from the caller's perspective. All edge cases (clear during flight, rejection after replacement, notModified pass-through) have dedicated test coverage and the tests match the implementation precisely.

No files require special attention.

Reviews (2): Last reviewed commit: "test: cover the metadata re-serializatio..." | Re-trigger Greptile

@github-actions github-actions Bot added the reviewed: coderabbit CodeRabbit submitted an approving review label Jul 16, 2026
Add a regression test at the pickPackage/memo-cache boundary: 20 projects
joining one in-flight fetch must mirror the fetched body rather than each
re-serialize it. Against the pre-fix implementation it fails with 19
re-serializations, one per non-initiating caller.

Cover the rejection-path identity guard too, which no test exercised.

Correct the jsonText contract docs, which still described the pre-fix
behaviour, and restore the rationale for dropping the body once the
request settles.
@zkochan
zkochan force-pushed the fix/13077-metadata-cache-oom branch from 84386c8 to 851100e Compare July 16, 2026 19:31
Copilot AI review requested due to automatic review settings July 16, 2026 19:31

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

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

Auto-approved notes - no code review findings
- 'auto_approve_for_no_suggestions' flag enabled

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.

Auto-approved notes - no code suggestions found
- 'approve_pr_on_self_review' flag enabled

@zkochan
zkochan merged commit 94bc420 into pnpm:main Jul 16, 2026
28 checks passed
ByronDWall added a commit to commercetools/nimbus that referenced this pull request Aug 7, 2026
Bumps the pinned packageManager version from [email protected] to
[email protected], matching the version already running cleanly in
commercetools/merchant-center-application-kit.

This version picks up two confirmed upstream memory-regression
fixes that predate nimbus's previously pinned 11.10.0:

- pnpm/pnpm#12868 (pnpm 11 resolution uses ~47% more memory than
  pnpm 10 on a cold metadata cache), fixed by pnpm/pnpm#12870.
- pnpm/pnpm#13077 (pnpm 11.11+ OOMs by re-serializing full package
  metadata for concurrent workspace cache hits), fixed by
  pnpm/pnpm#13079.

When Renovate updates lockfile artifacts on this repo, its Node
process OOM-crashes with these regressions present (#1886, #1885,
#1880 all failing with FATAL ERROR: JavaScript heap out of memory).
This bump addresses that root cause.

pnpm-lock.yaml required no changes: pnpm 11.14.0 resolves the
existing dependency graph identically to 11.10.0 for this repo.
ByronDWall added a commit to commercetools/ui-kit that referenced this pull request Aug 7, 2026
Updates the pinned packageManager field from [email protected] to
[email protected], matching the version already running cleanly in
commercetools/merchant-center-application-kit.

pnpm 11.10.0 predates two confirmed upstream memory regressions in
the resolver: pnpm/pnpm#12868, fixed by pnpm/pnpm#12870 (merged
2026-07-09), and pnpm/pnpm#13077, fixed by pnpm/pnpm#13079 (merged
2026-07-16). [email protected] was released 2026-07-17, after both fixes
landed.

ui-kit is not currently seen OOM-crashing in Renovate, unlike the
sibling nimbus repo, which is being fixed separately. This bump is
proactive, done alongside that fix to keep both repos on a pnpm
version clear of the same class of issue.

Verification performed after the bump:
- Full pnpm install (node_modules removed first) with pnpm 11.14.0;
  pnpm-lock.yaml came out byte-identical to the pre-bump lockfile.
- node scripts/check-workspace-constraints.js passes.
- pnpm typecheck passes.
- pnpm build (preconstruct build across all workspace packages, plus
  the FEC-938 declaration-leak regression guard) completes cleanly.
- Representative jest runs across packages/components/buttons,
  packages/components/inputs/text-input, packages/components/inputs/date-input,
  packages/hooks, packages/utils, packages/i18n, and design-system
  pass for the test, ts-test, eslint, and stylelint jest projects.
- publicHoistPattern (@storybook/*) and the strictDepBuilds allowBuilds
  list continue to work as expected; postinstall scripts for the
  allow-listed packages ran without error.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

product: pnpm@11 reviewed: coderabbit CodeRabbit submitted an approving review state: automerge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pnpm 11.11+ OOMs by re-serializing full package metadata for concurrent workspace cache hits

3 participants