Skip to content

fix(deps.graph-builder): relink a global virtual store slot the current lockfile records - #16663

Merged
zkochan merged 1 commit into
mainfrom
fix-16642-v11
Oct 6, 2026
Merged

zkochan merged 1 commit into
mainfrom
fix-16642-v11

Conversation

@zkochan

@zkochan zkochan commented Oct 6, 2026 •

Copy link
Copy Markdown
Member

Summary

The pnpm v11 half of #16649, which fixed pnpm v12 only.

With enableGlobalVirtualStore, checkPkgDirReuse in @pnpm/deps.graph-builder returned up-to-date for any slot the project's current lockfile records, and that slot was dropped from the graph. A global virtual store slot is shared, so another project's interrupted install may re-create it without its dependency links after the record was written. An install that rebuilt node_modules then kept the incomplete slot.

Under the global virtual store, such a slot is now reusable. It stays in the graph without a fetch, so the linker restores its children.

#16649 said a v11 fix would have to undo skipGvsInternalLinking (#11073). That was wrong. The skip applies only when depGraph.added === 0, and added counts fetched nodes. Reusable nodes don't count, so an install that fetches nothing still skips linking, the same as v12's no-op path. An install that fetches something, like the issue's field case where slots in a new store were missing, now repairs the incomplete slots too.

Related to #16642. Once this lands, both versions behave the same. What remains is the no-op install that never checks the store, which is by design.

Squash Commit Body

A project's current lockfile vouches only for slots that project alone
writes. A global virtual store slot is shared, so another project's
interrupted install may have re-created it without its child links.
Such a slot now stays in the dependency graph as reusable instead of
up to date, so the linker restores its children.

skipGvsInternalLinking (pnpm/pnpm#11073) still skips linking when the
install fetches nothing, because reusable nodes do not count as added.
This matches pnpm v12 after pnpm/pnpm#16649.

Related to pnpm/pnpm#16642.

Checklist

  • I checked the referenced issue and verified that none of the PRs
    already linked to it solves it.
  • New features are implemented only in the Rust pnpm v12 CLI. Bug fixes
    are implemented in every affected version.
  • 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-opus-5-5).

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

Summary by CodeRabbit

  • Bug Fixes

    • Fixed installs with the global virtual store so they restore missing dependency links for packages left incomplete by an interrupted install, including when the project already records the package.
  • Tests

    • Added a regression test covering restoration of a missing dependency link during a frozen-lockfile reinstall.

…nt lockfile records

A project's current lockfile vouches only for slots that project alone
writes. A global virtual store slot is shared, so another project's
interrupted install may have re-created it without its child links.
Such a slot now stays in the dependency graph as reusable instead of
up to date, so the linker restores its children.

skipGvsInternalLinking (#11073) still skips linking when the
install fetches nothing, because reusable nodes do not count as added.
This matches pnpm v12 after #16649.

Related to #16642

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: pnpm/pnpm/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3d8348a8-db2f-4c35-962d-0c963461c5d6
📥 Commits

Reviewing files that changed from the base of the PR and between 5b87f8f and 39ec374.

📒 Files selected for processing (3)
  • .changeset/gvs-relink-incomplete-slots.md
  • pnpm11/deps/graph-builder/src/buildGraphFromPackages.ts
  • pnpm11/installing/deps-installer/test/install/globalVirtualStore.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.


📝 Walkthrough

Walkthrough

When the global virtual store is enabled, unchanged packages remain in the graph. A regression test checks that a frozen-lockfile reinstall restores a dependency link removed from an installed package slot.

Changes

Global virtual-store relinking

Layer / File(s) Summary
Graph inclusion and reinstall validation
pnpm11/deps/graph-builder/src/buildGraphFromPackages.ts, pnpm11/installing/deps-installer/test/install/globalVirtualStore.ts, .changeset/gvs-relink-incomplete-slots.md
The graph builder bypasses the unchanged-package fast path when the global virtual store is enabled. The regression test checks that reinstalling restores a missing dependency link. The changeset records patch releases for @pnpm/deps.graph-builder and pnpm.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Low

Suggested labels: product: pnpm@11

Merge Risk: ⚪ Minimal · up to 39ec3

No merge-blocking issue is established. Proceed with normal validation; installs that fetch nothing are not expected to relink incomplete slots.

✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

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

pnpm11/deps/graph-builder/src/buildGraphFromPackages.ts

ESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox.

pnpm11/installing/deps-installer/test/install/globalVirtualStore.ts

ESLint skipped: the matched ESLint configuration already failed (missing-dependency).


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.

@zkochan
zkochan marked this pull request as ready for review October 6, 2026 16:49
Copilot AI balanced review requested due to automatic review settings October 6, 2026 16:49
@zkochan

zkochan commented Oct 6, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

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.

@greptile-apps greptile-apps 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.

Your trial has ended. Reactivate Greptile to resume code reviews.

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Relink reusable global virtual store slots during pnpm v11 installs

🐞 Bug fix 🧪 Tests 🕐 20-40 Minutes

Grey Divider

AI Description

• Keep existing global virtual store slots in the dependency graph so installs can restore missing
 child links.
• Fetch missing slots as before while preserving the no-fetch linking shortcut.
• Add a regression test and patch release notes for pnpm v11.
Diagram

graph TD
  Lockfile["Lockfile snapshots"] --> Builder["Graph builder"] --> Slot{"Slot exists?"} -->|reusable| Graph["Dependency graph"] -->|fetched nodes| Linker["Isolated linker"] --> Links["GVS child links"]
  Slot -->|missing| Fetch["Fetch package"] --> Graph
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Validate child links on every install
  • ➕ Could detect and repair incomplete slots even when no package is fetched.
  • ➖ Adds filesystem checks to otherwise no-op installs and changes their intentional shortcut.

Recommendation: Keep the PR's targeted reuse change. It lets installs already fetching packages repair incomplete shared slots without adding checks to no-op installs or changing the existing linking shortcut.

Files changed (3) +37 / -1

Bug fix (1) +6 / -1
buildGraphFromPackages.tsRetain existing global-store slots as reusable graph nodes +6/-1

Retain existing global-store slots as reusable graph nodes

• Disables the unchanged-package up-to-date shortcut when the global virtual store is enabled. Existing slots instead remain in the graph as reusable nodes, allowing their children to be linked when the install performs linking without fetching those slots again.

pnpm11/deps/graph-builder/src/buildGraphFromPackages.ts

Tests (1) +25 / -0
globalVirtualStore.tsTest repair of a missing dependency link during install +25/-0

Test repair of a missing dependency link during install

• Adds an integration test that removes a parent slot's child link and its child's store slot, then reinstalls with a frozen lockfile. It verifies that fetching the missing child also restores the link in the reusable parent slot.

pnpm11/installing/deps-installer/test/install/globalVirtualStore.ts

Documentation (1) +6 / -0
gvs-relink-incomplete-slots.mdDocument the global virtual store repair fix +6/-0

Document the global virtual store repair fix

• Adds patch changesets for @pnpm/deps.graph-builder and pnpm. The release note explains that installs updating node_modules can restore dependency links left missing by an interrupted install.

.changeset/gvs-relink-incomplete-slots.md

@qodo-code-review

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

Copy link
Copy Markdown

Code Review by Qodo

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

Grey Divider


Remediation recommended

1. Missing store slots are checked twice 🐞 Bug ➹ Performance
Description
With the new global-store condition, checkPkgDirReuse leaves dirExists undefined and calls
isPkgDirReusable in both its unchanged-package and global-store branches. When a recorded slot is
missing, both branches call pathExists for the same directory before fetching it, adding a
redundant filesystem check per missing slot during store recovery.
Code

pnpm11/deps/graph-builder/src/buildGraphFromPackages.ts[205]

+    !opts.enableGlobalVirtualStore
Relevance

●●● Strong

Redundant pathExists calls on missing slots are a deterministic local filesystem-performance issue
with no semantic tradeoff.

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The changed predicate no longer initializes dirExists for an unchanged global-store slot. On a
missing slot, the unchanged-package check calls pathExists and returns false; the following
global-store fallback calls it again because dirExists remains undefined.

pnpm11/deps/graph-builder/src/buildGraphFromPackages.ts[165-205]
pnpm11/deps/graph-builder/src/buildGraphFromPackages.ts[218-224]

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

## Issue description
Missing global virtual store slots receive two identical existence checks after the unchanged-package fast path is disabled.
## Fix Focus Areas
- pnpm11/deps/graph-builder/src/buildGraphFromPackages.ts[165-205]
- pnpm11/deps/graph-builder/src/buildGraphFromPackages.ts[218-224]
## Recommended Fix
Cache the first existence result in `checkPkgDirReuse` and pass it to the global-store fallback, so a missing slot is checked only once before fetching.

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

Dismiss ↗ | View ↗


2. Small updates relink the entire store 🐞 Bug ➹ Performance
Description
Disabling isUnchangedWithoutOptionalDeps for the global virtual store retains every unchanged
package in the graph, so linkAllModules and linkAllBins process those packages rather than only
the packages needed for the update. When an install fetches even one package, the linker runs over
all retained nodes, including their child links and bins; this makes a small update scale with the
full dependency graph.
Code

pnpm11/deps/graph-builder/src/buildGraphFromPackages.ts[205]

+    !opts.enableGlobalVirtualStore
Relevance

●●● Strong

Accepted precedent preserves unchanged-link optimization while checking only missing or dangling
links, matching this full-graph relinking concern.

PR-#13464

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The new condition sends unchanged global-store packages through the reusable branch, which adds them
to the graph. If any package is fetched, added is nonzero and the linker passes all graph nodes to
module and bin linking; the worker iterates every retained child edge and calls the synchronous
symlink operation.

pnpm11/deps/graph-builder/src/buildGraphFromPackages.ts[164-205]
pnpm11/installing/deps-restorer/src/createHeadlessDepGraph.ts[52-60]
pnpm11/installing/deps-restorer/src/linkIsolatedLayout.ts[20-36]
pnpm11/installing/deps-restorer/src/linkIsolatedLayout.ts[45-78]
pnpm11/installing/deps-restorer/src/linkAllModules.ts[21-47]
pnpm11/worker/src/start.ts[150-158]

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

## Issue description
Retaining every unchanged global virtual store package makes a one-package update relink the whole dependency graph.
## Fix Focus Areas
- pnpm11/deps/graph-builder/src/buildGraphFromPackages.ts[165-205]
- pnpm11/installing/deps-restorer/src/linkIsolatedLayout.ts[45-78]
- pnpm11/installing/deps-restorer/src/linkAllModules.ts[21-47]
## Recommended Fix
Check which existing slots have missing or stale child links and pass only those nodes, plus nodes otherwise requiring linking, through internal relinking. Preserve repair of an unchanged parent when another slot must be fetched.

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

Dismiss ↗ | View ↗


Grey Divider

Context sources
✅ Compliance rules (platform): 55 rules
✅ Cross-repo context — repo relationships
  Explored: repo: pnpm/symlink-dir (sha: bfbaef3f) — View relationship
Review mode: Auto: ⚖️ Balanced: Core global-store graph behavior has subtle correctness and performance implications.

Grey Divider

Tip of the day
💡 Did you know, you can add REVIEW.md to your repo root and Qodo follows it on every PR

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

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.

@github-actions github-actions Bot added the reviewed: coderabbit CodeRabbit submitted an approving review label Oct 6, 2026
@coderabbitai

coderabbitai Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor
⚠️ Action not completed

Already reviewed the last commit. Use @coderabbitai full review to rerun a review of the entire changeset.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@zkochan
zkochan merged commit f4b9616 into main Oct 6, 2026
40 checks passed
@zkochan
zkochan deleted the fix-16642-v11 branch October 6, 2026 23:12
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants