Skip to content

fix(deps-restorer): materialize each global-virtual-store slot once - #13669

Merged
zkochan merged 3 commits into
mainfrom
gvs-slot-dedup
Aug 6, 2026
Merged

zkochan merged 3 commits into
mainfrom
gvs-slot-dedup

Conversation

@zkochan

@zkochan zkochan commented Aug 5, 2026 •

Copy link
Copy Markdown
Member

Installs with enableGlobalVirtualStore failed nondeterministically on projects with injected file: dependencies in peer-heavy graphs:

failed to remove existing directory ".../links/<pkg>/directory/<hash>/node_modules/<pkg>" prior to swap: Directory not empty (os error 39)

(or No such file or directory (os error 2), depending on interleaving — a different package each run.)

Cause

The link pass spawns one CreateVirtualDirBySnapshot per snapshot key. Under the global virtual store, peer variants of a package whose recursive dependency hashes are equal map to one slot directory — that sharing is the point of the hashing. Immutable packages tolerate the duplicate imports (marker-gated, safe_to_skip), but a mutable file: source forces stage_and_swap on every install, and its remove-then-rename assumes an exclusive owner (see the step-5 comment in import_indexed_dir.rs). Two rayon workers targeting the same slot race: one's remove_dir_all interleaves with the other's rename.

pnpm v11 never faces this because lockfileToDepGraph keys its graph by directory (graph[dir] = ...), so one node per location survives graph construction.

Fix

Group slot links by layout.slot_dir(key) before the rayon pass (group_slots_by_dir): the first variant materializes the directory, the remaining variants only emit their progress events (package counts stay in step with the lockfile), and removed_aliases recorded against any variant are unioned so obsolete-child cleanup still covers all of them. Without the global virtual store every group is a singleton and the pass is unchanged.

Found running Bit's own repository (334 injected components, 5 peer variants each of the racing packages) under the global virtual store — it failed on every install, on a different package each time, and passes reliably with this fix.

🤖 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 installation failures when peer variants of injected local dependencies share the same virtual-store slot.
    • Ensured each unique slot directory is materialized only once when the global virtual store is enabled, improving installation reliability.
  • Tests
    • Added coverage for slot grouping, alias cleanup, differing variants, and behavior when the global virtual store is disabled.
  • Release
    • Included patch releases for pnpm and pacquet.

The link pass spawned one CreateVirtualDirBySnapshot per snapshot key.
Under the global virtual store, peer variants of a package whose
recursive dependency hashes are equal map to one slot directory - that
sharing is the point of the hashing - so hash-equal variants raced
concurrent imports against a single path. Immutable packages tolerate
this (their import is marker-gated and safe to skip), but a mutable
`file:` source forces a stage-and-swap, whose remove-then-rename
assumes an exclusive owner: one worker's `remove_dir_all` interleaves
with another's rename and the install fails with `Directory not empty`
or `NotFound` depending on timing. Injected workspace packages in a
peer-heavy monorepo hit this on every install.

pnpm v11 never faces the race because `lockfileToDepGraph` keys its
graph by directory, so one node per location survives graph
construction. Restore that invariant here by grouping slot links by
`slot_dir` before the rayon pass: the first variant materializes the
directory, the rest only report progress, and obsolete-child aliases
recorded against any variant are unioned so stale links still get
removed no matter which variant runs. Without the global virtual store
every group is a singleton and the pass is unchanged.

Co-Authored-By: Claude Fable 5 <[email protected]>
Copilot AI lite review requested due to automatic review settings August 5, 2026 22: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.

@coderabbitai

coderabbitai Bot commented Aug 5, 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: ea7d4d7f-3900-428d-84b3-347d41301b09

📥 Commits

Reviewing files that changed from the base of the PR and between 9236789 and d8bde85.

📒 Files selected for processing (3)
  • pnpm/crates/deps-restorer/src/create_virtual_dir_by_snapshot/tests.rs
  • pnpm/crates/deps-restorer/src/create_virtual_store.rs
  • pnpm/crates/deps-restorer/src/create_virtual_store/tests.rs
🚧 Files skipped from review as they are similar to previous changes (3)
  • pnpm/crates/deps-restorer/src/create_virtual_store/tests.rs
  • pnpm/crates/deps-restorer/src/create_virtual_store.rs
  • pnpm/crates/deps-restorer/src/create_virtual_dir_by_snapshot/tests.rs

📝 Walkthrough

Walkthrough

The virtual-store restorer groups slots that resolve to the same directory, materializes each directory once, merges cleanup aliases, preserves progress reporting, and adds tests for grouped and ungrouped variants.

Changes

Global virtual-store slot deduplication

Layer / File(s) Summary
Slot grouping and linking
pnpm/crates/deps-restorer/src/create_virtual_store.rs
Slots that resolve to the same directory are grouped before parallel linking. Duplicate snapshots receive progress updates. Cleanup merges aliases across grouped variants, and logs report unique directories.
Grouping validation and release metadata
pnpm/crates/deps-restorer/src/create_virtual_store/tests.rs, pnpm/crates/deps-restorer/src/create_virtual_dir_by_snapshot/tests.rs, .changeset/gvs-dedup-slot-materialization.md
Tests cover identical peer variants, differing dependency subtrees, disabled global virtual stores, and cumulative link-task counts. The changeset records the pacquet fix.

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

Sequence Diagram(s)

sequenceDiagram
  participant CreateVirtualStore
  participant SlotGrouping
  participant LinkTasks
  participant VirtualStore
  CreateVirtualStore->>SlotGrouping: group slots by virtual-store directory
  SlotGrouping->>LinkTasks: create one task per unique directory
  LinkTasks->>VirtualStore: materialize representative slot
  LinkTasks->>CreateVirtualStore: report representative and duplicate progress
Loading

Possibly related PRs

  • pnpm/pnpm#13648: Modifies global virtual-store slot materialization and import safety.
  • pnpm/pnpm#13383: Covers shared-slot materialization for injected file: dependency peer variants.
  • pnpm/pnpm#13649: Modifies the virtual-store linking and materialization flow.

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 gvs-slot-dedup

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

Fix GVS install race by deduplicating slot directory materialization

🐞 Bug fix 🧪 Tests 🕐 40+ Minutes

Grey Divider

AI Description

• Deduplicate link tasks by global-virtual-store slot directory to prevent concurrent writes.
• Merge per-variant removed-alias data so obsolete-child cleanup remains correct.
• Add regression tests for hash-equal vs diverging peer variants and non-GVS behavior.
Diagram

graph TD
  A["Link slots pass"] --> B["group_slots_by_dir"] --> C["Unique slot dir group"] --> D["CreateVirtualDirBySnapshot"] --> E["import_indexed_dir stage_and_swap"]
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Per-slot directory lock (mutex/fs lock)
  • ➕ Preserves existing per-snapshot task structure
  • ➕ Can protect other future operations on the same directory
  • ➖ Adds lock management complexity and potential contention
  • ➖ Still does redundant planning/work per peer variant (only serialized)
2. Deduplicate earlier by building the dep graph keyed by directory
  • ➕ Prevents duplicate nodes earlier; could reduce work beyond linking
  • ➕ Aligns with pnpm v11’s invariant as described in the PR context
  • ➖ Likely larger refactor with broader behavioral risk
  • ➖ Harder to scope and test compared to localized link-pass grouping

Recommendation: The chosen approach (grouping link tasks by resolved slot_dir right before the rayon pass) is the best trade-off: it directly removes the race by ensuring single-writer materialization per physical directory, keeps progress reporting consistent, and limits the change scope to the linking phase while still preserving correctness via removed-alias unioning.

Files changed (3) +279 / -8

Bug fix (1) +98 / -8
create_virtual_store.rsGroup slot links by slot_dir to avoid concurrent materialization races +98/-8

Group slot links by slot_dir to avoid concurrent materialization races

• Introduces SlotDirGroup and group_slots_by_dir to collapse hash-equal peer variants that map to the same global-virtual-store slot directory. Updates the parallel link pass to run one CreateVirtualDirBySnapshot per unique directory while still emitting warm-progress events per variant and merging removed_aliases for correct cleanup; adds logging for unique directory count.

pnpm/crates/deps-restorer/src/create_virtual_store.rs

Tests (1) +175 / -0
tests.rsAdd unit tests for slot_dir grouping behavior under GVS and non-GVS +175/-0

Add unit tests for slot_dir grouping behavior under GVS and non-GVS

• Adds helper constructors for a GVS VirtualStoreLayout and SlotLink instances. Introduces tests verifying that hash-equal peer variants collapse into one group with merged removed aliases, diverging variants stay separate, and non-GVS grouping is identity.

pnpm/crates/deps-restorer/src/create_virtual_store/tests.rs

Documentation (1) +6 / -0
gvs-dedup-slot-materialization.mdAdd changeset for GVS slot materialization race fix +6/-0

Add changeset for GVS slot materialization race fix

• Adds a patch changeset for pnpm/pacquet describing the nondeterministic install failure under enableGlobalVirtualStore with injected file: deps. Documents that slot directories are now materialized once per unique slot path to avoid concurrent stage-and-swap races.

.changeset/gvs-dedup-slot-materialization.md

@greptile-apps

greptile-apps Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

The PR appears safe to merge.

The previously reported changeset issue is fixed at the current HEAD, and no blocking failure remains.

Reviews (3): Last reviewed commit: "docs(deps-restorer): let the tests carry..." | 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 @.changeset/gvs-dedup-slot-materialization.md:
- Around line 2-6: Update the changeset frontmatter to release only pacquet by
removing the pnpm patch entry. Revise the description to focus solely on the
observed installation failure under enableGlobalVirtualStore, omitting
link-pass, slot materialization, and force-mode import implementation details.

In `@pnpm/crates/deps-restorer/src/create_virtual_store/tests.rs`:
- Around line 554-600: Extend the regression coverage beyond group_slots_by_dir
by adding a fixture-based link-pass test using two peer variants that resolve to
the same slot directory. Execute link_slots_parallel with a LinkConcurrencyProbe
and assert the shared directory is materialized exactly once. Use
RecordingReporter to verify the event sequence contains one warm-progress event
for each warm variant.
🪄 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: a33b018e-1e46-4580-9e2c-51e1044fc811

📥 Commits

Reviewing files that changed from the base of the PR and between b0e8194 and 8394b53.

📒 Files selected for processing (3)
  • .changeset/gvs-dedup-slot-materialization.md
  • pnpm/crates/deps-restorer/src/create_virtual_store.rs
  • pnpm/crates/deps-restorer/src/create_virtual_store/tests.rs

@qodo-code-review

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

Copy link
Copy Markdown

Code Review by Qodo

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

Grey Divider


Remediation recommended

1. Historical pnpm v11 comment ✓ Resolved 📘 Rule violation ⚙ Maintainability
Description
The new doc comment references historical behavior (pnpm v11) and compares to the previous
implementation (“behaves exactly as before”), instead of describing only the current code’s behavior
and invariants. This can become stale and is disallowed by the comment policy.
Code

pnpm/crates/deps-restorer/src/create_virtual_store.rs[R886-889]

+/// depending on interleaving. pnpm v11 never faces this because
+/// `lockfileToDepGraph` keys its graph by directory, so only one node
+/// per location survives graph construction; grouping here restores
+/// that invariant. Without GVS, `slot_dir` embeds the full
Relevance

●●● Strong

Repo repeatedly enforces no-historical/temporal phrasing in comments; mentions like “pnpm v11” get
flagged.

PR-#13662
PR-#13349
PR-#13306

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
PR Compliance ID 772199 forbids comments that reference past behavior or historical implementations.
The added comment explicitly mentions pnpm v11 and frames the logic relative to prior behavior
(“behaves exactly as before”), which is historical phrasing rather than a description of the current
contract.

Rule 772199: Comments must describe current behavior, not historical implementations
pnpm/crates/deps-restorer/src/create_virtual_store.rs[886-891]

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 newly added doc comment describes historical/previous behavior (e.g., mentions `pnpm v11` and “behaves exactly as before”) instead of documenting the current behavior/invariant.

## Issue Context
Inline comments should remain accurate over time and describe current behavior and rationale without referencing older implementations/versions.

## Fix Focus Areas
- pnpm/crates/deps-restorer/src/create_virtual_store.rs[886-891]

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


2. Unconditional grouping overhead ✓ Resolved 🐞 Bug ➹ Performance
Description
link_slots_parallel always calls group_slots_by_dir, even when the global virtual store is
disabled (where grouping is an identity). This adds per-slot slot_dir() computation, PathBuf
hashing, and HashMap/Vec allocations on the install hot path with no behavioral benefit in
non-GVS installs.
Code

pnpm/crates/deps-restorer/src/create_virtual_store.rs[R996-1001]

+    // One task per unique slot directory, not per snapshot key — see
+    // `SlotDirGroup` for why colliding peer variants must not
+    // materialize the same directory concurrently.
+    let groups = group_slots_by_dir(slots, layout);
    let link_work = || {
-        slots.par_iter().try_for_each(|slot| {
+        groups.par_iter().try_for_each(|group| {
Relevance

●● Moderate

Skipping grouping when GVS disabled is plausible, but similar “extra allocations” optimizations have
mixed prior outcomes.

PR-#13170
PR-#13368

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The new code always builds groups before the rayon pass. VirtualStoreLayout::slot_dir()
clones/allocates a suffix string and constructs a PathBuf, so doing this once per slot purely to
group is non-trivial overhead when grouping cannot actually merge anything (non-GVS). The repo
review guide explicitly warns against adding extra work in common install flows.

pnpm/crates/deps-restorer/src/create_virtual_store.rs[995-1012]
pnpm/crates/deps-restorer/src/virtual_store_layout.rs[327-339]
REVIEW_GUIDE.md[115-127]

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

### Issue description
`link_slots_parallel()` unconditionally groups slots by `layout.slot_dir(...)`, even when `layout.enable_global_virtual_store()` is false. In non-GVS mode every slot remains unique per key, so this adds extra work without changing behavior.

### Issue Context
This is on pnpm's install/linking hot path. REVIEW_GUIDE.md asks reviewers to avoid adding extra work in common flows unless measured/justified.

### Fix Focus Areas
- pnpm/crates/deps-restorer/src/create_virtual_store.rs[995-1003]

### Suggested fix
- Add a fast-path:
 - If `!layout.enable_global_virtual_store()`, keep the old behavior (`slots.par_iter().try_for_each(...)`) and set `unique_dirs = slots.len()` for logging.
 - Only build `groups` and use `groups.par_iter()` when GVS is enabled.
- Keep the progress emission semantics the same in both branches.

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



Informational

3. Duplicate slot_dir recompute ✓ Resolved 🐞 Bug ➹ Performance
Description
group_slots_by_dir computes layout.slot_dir(...) for every slot to build groups, and then
CreateVirtualDirBySnapshot::run computes layout.slot_dir(package_key) again for each group
representative. This duplicates path construction (and GVS suffix cloning) work on every install,
even in non-GVS mode where groups are singletons.
Code

pnpm/crates/deps-restorer/src/create_virtual_store.rs[R927-931]

+    let mut index_by_dir: HashMap<PathBuf, usize> = HashMap::with_capacity(slots.len());
+    let mut groups: Vec<SlotDirGroup<'a>> = Vec::with_capacity(slots.len());
+    for slot in slots {
+        match index_by_dir.entry(layout.slot_dir(slot.snapshot_key)) {
+            std::collections::hash_map::Entry::Vacant(entry) => {
Relevance

●● Moderate

Team sometimes accepts removing redundant hot-path work, but often rejects micro-optimizations
without clear impact.

PR-#13170
PR-#13368

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The grouping function computes layout.slot_dir(...) for each slot to build the `HashMap<PathBuf,
usize>. Later, materialization recomputes layout.slot_dir(package_key)` again inside
CreateVirtualDirBySnapshot::run(). slot_dir() itself allocates by cloning the GVS suffix String
and joining into a new PathBuf, so repeated calls increase allocations and CPU.

pnpm/crates/deps-restorer/src/create_virtual_store.rs[923-953]
pnpm/crates/deps-restorer/src/create_virtual_dir_by_snapshot.rs[151-156]
pnpm/crates/deps-restorer/src/virtual_store_layout.rs[327-339]

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

### Issue description
`group_slots_by_dir()` calls `layout.slot_dir(key)` to determine grouping, but `CreateVirtualDirBySnapshot::run()` later calls `layout.slot_dir(package_key)` again. This results in duplicated directory computation and allocations.

### Issue Context
`VirtualStoreLayout::slot_dir()` clones a String suffix (in GVS) and builds a new `PathBuf`. This duplication is measurable overhead for large lockfiles and is compounded by the new unconditional grouping pass.

### Fix Focus Areas
- pnpm/crates/deps-restorer/src/create_virtual_store.rs[923-955]
- pnpm/crates/deps-restorer/src/create_virtual_dir_by_snapshot.rs[151-156]
- pnpm/crates/deps-restorer/src/virtual_store_layout.rs[327-339]

### Suggested fix
- Store the computed slot directory in `SlotDirGroup` (e.g., `slot_dir: PathBuf`) when building groups.
- Thread the precomputed `slot_dir` into the materialization path to avoid recomputing it:
 - Option A: extend `CreateVirtualDirBySnapshot` to accept an optional precomputed `slot_dir`.
 - Option B: add a new `CreateVirtualDirBySnapshot::run_with_slot_dir(slot_dir: &Path, ...)` helper.
- Keep existing behavior unchanged; this is strictly a perf/alloc reduction.

ⓘ 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 d8bde85 ⚖️ Balanced

Results up to commit 8394b53 ⚖️ Balanced


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


Remediation recommended
1. Historical pnpm v11 comment ✓ Resolved 📘 Rule violation ⚙ Maintainability
Description
The new doc comment references historical behavior (pnpm v11) and compares to the previous
implementation (“behaves exactly as before”), instead of describing only the current code’s behavior
and invariants. This can become stale and is disallowed by the comment policy.
Code

pnpm/crates/deps-restorer/src/create_virtual_store.rs[R886-889]

+/// depending on interleaving. pnpm v11 never faces this because
+/// `lockfileToDepGraph` keys its graph by directory, so only one node
+/// per location survives graph construction; grouping here restores
+/// that invariant. Without GVS, `slot_dir` embeds the full
Relevance

●●● Strong

Repo repeatedly enforces no-historical/temporal phrasing in comments; mentions like “pnpm v11” get
flagged.

PR-#13662
PR-#13349
PR-#13306

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
PR Compliance ID 772199 forbids comments that reference past behavior or historical implementations.
The added comment explicitly mentions pnpm v11 and frames the logic relative to prior behavior
(“behaves exactly as before”), which is historical phrasing rather than a description of the current
contract.

Rule 772199: Comments must describe current behavior, not historical implementations
pnpm/crates/deps-restorer/src/create_virtual_store.rs[886-891]

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 newly added doc comment describes historical/previous behavior (e.g., mentions `pnpm v11` and “behaves exactly as before”) instead of documenting the current behavior/invariant.

## Issue Context
Inline comments should remain accurate over time and describe current behavior and rationale without referencing older implementations/versions.

## Fix Focus Areas
- pnpm/crates/deps-restorer/src/create_virtual_store.rs[886-891]

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


2. Unconditional grouping overhead ✓ Resolved 🐞 Bug ➹ Performance
Description
link_slots_parallel always calls group_slots_by_dir, even when the global virtual store is
disabled (where grouping is an identity). This adds per-slot slot_dir() computation, PathBuf
hashing, and HashMap/Vec allocations on the install hot path with no behavioral benefit in
non-GVS installs.
Code

pnpm/crates/deps-restorer/src/create_virtual_store.rs[R996-1001]

+    // One task per unique slot directory, not per snapshot key — see
+    // `SlotDirGroup` for why colliding peer variants must not
+    // materialize the same directory concurrently.
+    let groups = group_slots_by_dir(slots, layout);
    let link_work = || {
-        slots.par_iter().try_for_each(|slot| {
+        groups.par_iter().try_for_each(|group| {
Relevance

●● Moderate

Skipping grouping when GVS disabled is plausible, but similar “extra allocations” optimizations have
mixed prior outcomes.

PR-#13170
PR-#13368

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The new code always builds groups before the rayon pass. VirtualStoreLayout::slot_dir()
clones/allocates a suffix string and constructs a PathBuf, so doing this once per slot purely to
group is non-trivial overhead when grouping cannot actually merge anything (non-GVS). The repo
review guide explicitly warns against adding extra work in common install flows.

pnpm/crates/deps-restorer/src/create_virtual_store.rs[995-1012]
pnpm/crates/deps-restorer/src/virtual_store_layout.rs[327-339]
REVIEW_GUIDE.md[115-127]

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

### Issue description
`link_slots_parallel()` unconditionally groups slots by `layout.slot_dir(...)`, even when `layout.enable_global_virtual_store()` is false. In non-GVS mode every slot remains unique per key, so this adds extra work without changing behavior.

### Issue Context
This is on pnpm's install/linking hot path. REVIEW_GUIDE.md asks reviewers to avoid adding extra work in common flows unless measured/justified.

### Fix Focus Areas
- pnpm/crates/deps-restorer/src/create_virtual_store.rs[995-1003]

### Suggested fix
- Add a fast-path:
 - If `!layout.enable_global_virtual_store()`, keep the old behavior (`slots.par_iter().try_for_each(...)`) and set `unique_dirs = slots.len()` for logging.
 - Only build `groups` and use `groups.par_iter()` when GVS is enabled.
- Keep the progress emission semantics the same in both branches.

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



Informational
3. Duplicate slot_dir recompute ✓ Resolved 🐞 Bug ➹ Performance
Description
group_slots_by_dir computes layout.slot_dir(...) for every slot to build groups, and then
CreateVirtualDirBySnapshot::run computes layout.slot_dir(package_key) again for each group
representative. This duplicates path construction (and GVS suffix cloning) work on every install,
even in non-GVS mode where groups are singletons.
Code

pnpm/crates/deps-restorer/src/create_virtual_store.rs[R927-931]

+    let mut index_by_dir: HashMap<PathBuf, usize> = HashMap::with_capacity(slots.len());
+    let mut groups: Vec<SlotDirGroup<'a>> = Vec::with_capacity(slots.len());
+    for slot in slots {
+        match index_by_dir.entry(layout.slot_dir(slot.snapshot_key)) {
+            std::collections::hash_map::Entry::Vacant(entry) => {
Relevance

●● Moderate

Team sometimes accepts removing redundant hot-path work, but often rejects micro-optimizations
without clear impact.

PR-#13170
PR-#13368

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The grouping function computes layout.slot_dir(...) for each slot to build the `HashMap<PathBuf,
usize>. Later, materialization recomputes layout.slot_dir(package_key)` again inside
CreateVirtualDirBySnapshot::run(). slot_dir() itself allocates by cloning the GVS suffix String
and joining into a new PathBuf, so repeated calls increase allocations and CPU.

pnpm/crates/deps-restorer/src/create_virtual_store.rs[923-953]
pnpm/crates/deps-restorer/src/create_virtual_dir_by_snapshot.rs[151-156]
pnpm/crates/deps-restorer/src/virtual_store_layout.rs[327-339]

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

### Issue description
`group_slots_by_dir()` calls `layout.slot_dir(key)` to determine grouping, but `CreateVirtualDirBySnapshot::run()` later calls `layout.slot_dir(package_key)` again. This results in duplicated directory computation and allocations.

### Issue Context
`VirtualStoreLayout::slot_dir()` clones a String suffix (in GVS) and builds a new `PathBuf`. This duplication is measurable overhead for large lockfiles and is compounded by the new unconditional grouping pass.

### Fix Focus Areas
- pnpm/crates/deps-restorer/src/create_virtual_store.rs[923-955]
- pnpm/crates/deps-restorer/src/create_virtual_dir_by_snapshot.rs[151-156]
- pnpm/crates/deps-restorer/src/virtual_store_layout.rs[327-339]

### Suggested fix
- Store the computed slot directory in `SlotDirGroup` (e.g., `slot_dir: PathBuf`) when building groups.
- Thread the precomputed `slot_dir` into the materialization path to avoid recomputing it:
 - Option A: extend `CreateVirtualDirBySnapshot` to accept an optional precomputed `slot_dir`.
 - Option B: add a new `CreateVirtualDirBySnapshot::run_with_slot_dir(slot_dir: &Path, ...)` helper.
- Keep existing behavior unchanged; this is strictly a perf/alloc reduction.

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


Results up to commit 9236789 ⚖️ Balanced


No changes from previous review

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 commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Micro-Benchmark Results

Linux

group                                            main                                   pr
-----                                            ----                                   --
lockfile/parse_pnpm_lock                         1.25     18.9±2.79ms    19.8 MB/sec    1.00     15.1±1.00ms    24.8 MB/sec
packument/parse                                  1.02     46.7±3.34µs  1421.0 MB/sec    1.00     45.8±1.61µs  1447.4 MB/sec
tarball/download_dependency                      1.12      4.4±1.25ms   987.1 KB/sec    1.00      3.9±0.84ms  1105.1 KB/sec
tarball_batch/cold_store_many_medium_tarballs    1.05   261.3±42.61ms 61.2 KElem/sec    1.00    248.8±9.93ms 64.3 KElem/sec
workspace_resolution/hoist_heavy                 1.00   403.9±62.71ms        ? ?/sec    1.02   413.1±35.77ms        ? ?/sec

@codecov-commenter

codecov-commenter commented Aug 5, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.21429% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 88.10%. Comparing base (34347bc) to head (d8bde85).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
...m/crates/deps-restorer/src/create_virtual_store.rs 98.21% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #13669      +/-   ##
==========================================
+ Coverage   88.08%   88.10%   +0.01%     
==========================================
  Files         608      608              
  Lines       99033    99080      +47     
==========================================
+ Hits        87231    87292      +61     
+ Misses      11802    11788      -14     

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

- Release only pacquet: the race lives in the Rust link pass; pnpm v11
  keys its graph by directory and never runs duplicate imports, so the
  TypeScript CLI has nothing to release.
- Skip grouping work when the global virtual store is off: project-local
  slot names embed the peer-suffixed key, every group is a singleton,
  and the common layout should not pay per-slot path construction and
  map bookkeeping for an identity transform.
- Cover the wiring, not just the grouping function: a lifetime counter
  on LinkConcurrencyProbe records one enter() per link task, and a new
  end-to-end test drives CreateVirtualStore::run over two hash-equal
  peer variants plus a distinct package under the global virtual store,
  asserting exactly two link tasks execute and the shared slot is
  materialized. The test fails against the ungrouped pass, which a unit
  test of group_slots_by_dir alone cannot.

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

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 9236789

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

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

🧹 Nitpick comments (1)
pnpm/crates/deps-restorer/src/create_virtual_store/tests.rs (1)

333-338: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Assert that the solo slot is also materialized.

The test asserts total_entered() == 2 and that the shared slot manifest exists. It does not assert that the second link task produced the solo slot. A regression that ran two tasks but materialized only one directory would still pass. Add the symmetric check to make the "distinct packages run separately" claim explicit.

♻️ Proposed assertion for the distinct slot
     assert!(shared_manifest.is_file(), "the shared slot must be materialized: {shared_manifest:?}");
+    let solo_manifest = layout
+        .slot_dir(&key("solo", "1.0.0"))
+        .join("node_modules")
+        .join("solo")
+        .join("package.json");
+    assert!(solo_manifest.is_file(), "the distinct slot must be materialized: {solo_manifest:?}");
 }
🤖 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/deps-restorer/src/create_virtual_store/tests.rs` around lines 333
- 338, In the test assertions alongside the existing shared_manifest check, add
a symmetric is_file assertion for the solo slot’s node_modules/solo/package.json
using the appropriate solo key and a message confirming that the solo slot must
be materialized. Keep the existing total_entered and shared-slot assertions
unchanged.
🤖 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 `@pnpm/crates/deps-restorer/src/create_virtual_store/tests.rs`:
- Around line 333-338: In the test assertions alongside the existing
shared_manifest check, add a symmetric is_file assertion for the solo slot’s
node_modules/solo/package.json using the appropriate solo key and a message
confirming that the solo slot must be materialized. Keep the existing
total_entered and shared-slot assertions unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 2f9b2cac-9e81-452f-b67d-c1a6c8b11c9b

📥 Commits

Reviewing files that changed from the base of the PR and between 8394b53 and 9236789.

📒 Files selected for processing (4)
  • .changeset/gvs-dedup-slot-materialization.md
  • pnpm/crates/deps-restorer/src/create_virtual_dir_by_snapshot/tests.rs
  • pnpm/crates/deps-restorer/src/create_virtual_store.rs
  • pnpm/crates/deps-restorer/src/create_virtual_store/tests.rs
💤 Files with no reviewable changes (1)
  • .changeset/gvs-dedup-slot-materialization.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • pnpm/crates/deps-restorer/src/create_virtual_store.rs

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

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Integrated-Benchmark Report (Linux)

Commit: 9236789daa7d

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.853 ± 0.198 2.598 3.126 1.60 ± 0.18
pacquet@main 2.904 ± 0.167 2.563 3.118 1.63 ± 0.17
pnpr@HEAD 1.782 ± 0.158 1.631 2.145 1.00
pnpr@main 1.793 ± 0.150 1.606 1.981 1.01 ± 0.12
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 2.85288958126,
      "stddev": 0.19848033074983928,
      "median": 2.85289368706,
      "user": 2.5775349,
      "system": 1.8902157599999998,
      "min": 2.5975217095599996,
      "max": 3.12610366856,
      "times": [
        2.5975217095599996,
        3.05713745656,
        3.0690630945599997,
        2.7724027745599997,
        2.93338459956,
        3.12610366856,
        2.70918093256,
        2.95148761156,
        2.70932748756,
        2.6032864775599998
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 2.90422021276,
      "stddev": 0.16660496317603615,
      "median": 2.90995094006,
      "user": 2.7743143,
      "system": 2.0852080600000003,
      "min": 2.56338343056,
      "max": 3.11761739556,
      "times": [
        2.88910851856,
        2.80505692256,
        2.9961956915599997,
        2.56338343056,
        2.75473498256,
        2.99438854756,
        2.90963925756,
        3.11761739556,
        2.91026262256,
        3.1018147585599998
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 1.7822547251600003,
      "stddev": 0.15770244984979112,
      "median": 1.7368154285600002,
      "user": 2.0170991,
      "system": 2.19844496,
      "min": 1.6305706075600002,
      "max": 2.14456109756,
      "times": [
        2.14456109756,
        1.73902366956,
        1.7346071875600002,
        1.6305706075600002,
        1.65542031356,
        1.66497399856,
        1.9292626815600002,
        1.75138452056,
        1.8669241495600002,
        1.70581902556
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 1.7931135407599998,
      "stddev": 0.1495124661023066,
      "median": 1.8287125900600003,
      "user": 1.7668433999999997,
      "system": 1.9002100599999998,
      "min": 1.6063558515600003,
      "max": 1.98097227656,
      "times": [
        1.90751054256,
        1.93404735656,
        1.98097227656,
        1.6106528525600001,
        1.6578416365600002,
        1.7773968825600002,
        1.6063558515600003,
        1.9271376695600002,
        1.64919204156,
        1.8800282975600002
      ]
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 340.5 ± 27.2 296.1 373.9 1.00
pacquet@main 359.7 ± 27.1 327.7 408.6 1.06 ± 0.12
pnpr@HEAD 398.6 ± 40.3 351.9 465.8 1.17 ± 0.15
pnpr@main 356.5 ± 26.2 309.4 388.2 1.05 ± 0.11
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.34049841428,
      "stddev": 0.027184021821635797,
      "median": 0.33989245448,
      "user": 0.29100055999999996,
      "system": 0.6455105399999999,
      "min": 0.29614107648,
      "max": 0.37394601148,
      "times": [
        0.33646188548,
        0.30726732248,
        0.32033436748,
        0.33086129648,
        0.34332302348,
        0.35971221248,
        0.29614107648,
        0.37394601148,
        0.36960105348,
        0.36733589348
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 0.35966181708,
      "stddev": 0.0271324379819469,
      "median": 0.35079555098000004,
      "user": 0.31184855999999994,
      "system": 0.6754327399999999,
      "min": 0.32765452648,
      "max": 0.40863524348,
      "times": [
        0.34259316148,
        0.37486522948,
        0.32765452648,
        0.35120572148,
        0.33897519948,
        0.33777720648,
        0.36502815548,
        0.35038538048,
        0.39949834648,
        0.40863524348
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.39862167047999997,
      "stddev": 0.04029090448037713,
      "median": 0.39118647598,
      "user": 0.33859066,
      "system": 0.7023559399999998,
      "min": 0.35194567248,
      "max": 0.46581289048,
      "times": [
        0.44181152148,
        0.36558161648,
        0.36095096148,
        0.36071753248,
        0.38453130948,
        0.43619636548,
        0.39784164248000004,
        0.42082719248,
        0.46581289048,
        0.35194567248
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.35650669308,
      "stddev": 0.026227954651906322,
      "median": 0.35979694298,
      "user": 0.29975516,
      "system": 0.64760014,
      "min": 0.30937501448,
      "max": 0.38815091348,
      "times": [
        0.37149508248,
        0.37202987948,
        0.38815091348,
        0.35981001748,
        0.31507711348,
        0.30937501448,
        0.35577311948,
        0.38341200648,
        0.35978386848,
        0.35015991548000003
      ]
    }
  ]
}

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 3.014 ± 0.111 2.863 3.193 1.73 ± 0.18
pacquet@main 2.886 ± 0.070 2.787 3.000 1.66 ± 0.16
pnpr@HEAD 1.741 ± 0.168 1.557 2.039 1.00
pnpr@main 1.755 ± 0.166 1.537 2.005 1.01 ± 0.14
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 3.0142558824999997,
      "stddev": 0.11112441181648273,
      "median": 2.9963190824,
      "user": 2.499935979999999,
      "system": 2.0236509,
      "min": 2.8625898709,
      "max": 3.1929066619,
      "times": [
        2.9140026869,
        2.9321960798999998,
        2.9390101589,
        3.1185574518999997,
        3.1929066619,
        2.8625898709,
        2.9328311789,
        3.0536280059,
        3.1149560489,
        3.0818806809
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 2.8862690764999996,
      "stddev": 0.06979665505788558,
      "median": 2.8887179684,
      "user": 2.26910558,
      "system": 1.8610992999999998,
      "min": 2.7874513799,
      "max": 2.9997796829,
      "times": [
        2.9579035558999998,
        2.9125244019,
        2.8649115349,
        2.7874513799,
        2.8279398329,
        2.8129944619,
        2.9338741039,
        2.9997796829,
        2.8387596709,
        2.9265521399
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 1.740720199,
      "stddev": 0.16758416521088784,
      "median": 1.6755386019,
      "user": 1.50105728,
      "system": 1.5786175,
      "min": 1.5567104889,
      "max": 2.0394308689,
      "times": [
        1.9187220369,
        1.8742235689,
        1.6028557609,
        2.0394308689,
        1.6378037059,
        1.6834092649,
        1.5710112399,
        1.8553671159,
        1.5567104889,
        1.6676679389
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 1.7546366589999998,
      "stddev": 0.1656083811141056,
      "median": 1.7700512944,
      "user": 1.5299298799999999,
      "system": 1.6990621999999997,
      "min": 1.5374412329,
      "max": 2.0047174548999998,
      "times": [
        1.5374412329,
        1.9497571379,
        2.0047174548999998,
        1.5593317989,
        1.7753443889,
        1.8214335849,
        1.8542030599000001,
        1.7386163339,
        1.7647581999,
        1.5407633979
      ]
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 669.1 ± 103.1 550.3 865.6 1.54 ± 0.25
pacquet@main 629.1 ± 102.6 483.5 848.1 1.45 ± 0.25
pnpr@HEAD 442.8 ± 46.7 371.3 515.1 1.02 ± 0.12
pnpr@main 433.9 ± 22.1 408.2 479.1 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.6691295167,
      "stddev": 0.10312400465203692,
      "median": 0.6391530606,
      "user": 0.9263878,
      "system": 0.96577366,
      "min": 0.5503216886,
      "max": 0.8656118826,
      "times": [
        0.5503216886,
        0.5902084946,
        0.6615716376,
        0.6762443866,
        0.6253132326,
        0.6200696316,
        0.6105957996,
        0.6529928886,
        0.8656118826,
        0.8383655246
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 0.6291370732000001,
      "stddev": 0.10255505485265905,
      "median": 0.6229951011,
      "user": 0.854554,
      "system": 0.9493826599999998,
      "min": 0.48351571060000004,
      "max": 0.8481123046,
      "times": [
        0.8481123046,
        0.48351571060000004,
        0.6152895006,
        0.6487214796,
        0.6307007016,
        0.5959748496,
        0.6320831406,
        0.5271205186,
        0.5772139196,
        0.7326386066
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.4428144871,
      "stddev": 0.04670975041679743,
      "median": 0.45688950860000005,
      "user": 0.34068060000000006,
      "system": 0.69779726,
      "min": 0.3713331206,
      "max": 0.5150517646,
      "times": [
        0.3713331206,
        0.4028990096,
        0.5150517646,
        0.4314716416,
        0.47008472260000006,
        0.3760414046,
        0.45337491960000004,
        0.4687305956,
        0.46040409760000006,
        0.47875359460000005
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.43387537639999996,
      "stddev": 0.022074866362520762,
      "median": 0.42798322610000006,
      "user": 0.3176822,
      "system": 0.71952096,
      "min": 0.40822369360000005,
      "max": 0.4790951366,
      "times": [
        0.41776081860000003,
        0.4248899346,
        0.45394558360000004,
        0.40822369360000005,
        0.4284330666,
        0.42753338560000004,
        0.4790951366,
        0.41282397460000003,
        0.45440900460000005,
        0.43163916560000004
      ]
    }
  ]
}

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 2.172 ± 0.113 2.041 2.392 4.90 ± 0.44
pacquet@main 2.163 ± 0.167 1.975 2.517 4.88 ± 0.52
pnpr@HEAD 0.443 ± 0.033 0.414 0.527 1.00
pnpr@main 0.488 ± 0.041 0.433 0.561 1.10 ± 0.12
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 2.1715936675199994,
      "stddev": 0.11333675935420653,
      "median": 2.1515376892199995,
      "user": 1.47119504,
      "system": 1.2005264599999999,
      "min": 2.04095659622,
      "max": 2.3923149162199997,
      "times": [
        2.3923149162199997,
        2.07291741922,
        2.2053553572199998,
        2.17667154822,
        2.16799933122,
        2.04095659622,
        2.0973971732199996,
        2.1350760472199997,
        2.33307233122,
        2.09417595522
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 2.16307147712,
      "stddev": 0.16662457411685747,
      "median": 2.10446067522,
      "user": 1.46338124,
      "system": 1.2479856599999999,
      "min": 1.9748671552200001,
      "max": 2.51730708322,
      "times": [
        2.21456622922,
        2.51730708322,
        2.35551319022,
        2.11675762922,
        2.21014804022,
        1.9748671552200001,
        2.0398462082199997,
        2.09216372122,
        2.07980979922,
        2.0297357152199997
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.44290879062000005,
      "stddev": 0.03255019463934222,
      "median": 0.44114413672,
      "user": 0.33685334,
      "system": 0.6949945599999999,
      "min": 0.41399551522,
      "max": 0.5274249582200001,
      "times": [
        0.44364486922,
        0.42230415922000003,
        0.44473302622,
        0.41399551522,
        0.44795066722000004,
        0.44998458122,
        0.5274249582200001,
        0.41888006922000004,
        0.43864340422000003,
        0.42152665622
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.48757152212,
      "stddev": 0.040662439640470616,
      "median": 0.48891614372000003,
      "user": 0.35433254,
      "system": 0.7798445599999999,
      "min": 0.43250210622,
      "max": 0.5611950322200001,
      "times": [
        0.49703709422000003,
        0.46058620922000004,
        0.44253806822,
        0.49329110922,
        0.45705144022,
        0.43250210622,
        0.5611950322200001,
        0.5272868792200001,
        0.5196861042200001,
        0.48454117822000004
      ]
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 254.3 ± 27.8 225.3 300.6 2.60 ± 0.32
pacquet@main 235.8 ± 16.8 209.6 265.0 2.41 ± 0.22
pnpr@HEAD 98.0 ± 5.4 90.4 114.5 1.00
pnpr@main 98.5 ± 3.3 92.3 105.2 1.01 ± 0.06
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.25432349698,
      "stddev": 0.02784527905733934,
      "median": 0.24897579888,
      "user": 0.24400313999999995,
      "system": 0.08959935999999999,
      "min": 0.22528166438000002,
      "max": 0.30057383538,
      "times": [
        0.26843128738,
        0.22528166438000002,
        0.22781510038000002,
        0.22806763438000002,
        0.23017538238000002,
        0.30057383538,
        0.28083297738,
        0.23963309538000002,
        0.25831850238,
        0.28410549038
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 0.23583733110727276,
      "stddev": 0.016758848108463266,
      "median": 0.23831571238000002,
      "user": 0.2177002309090909,
      "system": 0.09176157818181818,
      "min": 0.20956603238000002,
      "max": 0.26504171438,
      "times": [
        0.25215436137999997,
        0.24315047838000003,
        0.21689261738,
        0.20956603238000002,
        0.22408643038000003,
        0.24408221738000002,
        0.23831571238000002,
        0.22300008138000002,
        0.24871691838,
        0.22920407838000004,
        0.26504171438
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.09795337993999999,
      "stddev": 0.005406164496873337,
      "median": 0.09740695438000001,
      "user": 0.026753500000000003,
      "system": 0.012982039999999999,
      "min": 0.09044333138,
      "max": 0.11445598938,
      "times": [
        0.11445598938,
        0.10053208038,
        0.09761907138,
        0.10391602338,
        0.10132568038,
        0.09179858538,
        0.09640661638,
        0.10105382038,
        0.09364764738,
        0.09527963038000001,
        0.09592397038,
        0.10880725638000001,
        0.10135839138,
        0.09740695438000001,
        0.09490005838,
        0.09180529838,
        0.09621057838,
        0.09868318038,
        0.09803258838000001,
        0.09855923738,
        0.09880364638,
        0.09580252138,
        0.09457253338,
        0.09148980738,
        0.09044333138
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.09851714386275862,
      "stddev": 0.0032589205319544247,
      "median": 0.09814888638,
      "user": 0.026234312413793107,
      "system": 0.013028285517241377,
      "min": 0.09231725038000001,
      "max": 0.10520649538,
      "times": [
        0.09473613038,
        0.09693507738,
        0.10088955238,
        0.09231725038000001,
        0.09861121538,
        0.09688428338,
        0.10214811438,
        0.10209159838,
        0.09789101338,
        0.09659269638,
        0.09302321438,
        0.10302500038,
        0.10295289538,
        0.09943945038,
        0.10230365638,
        0.09886489038,
        0.10001543038,
        0.10072000438,
        0.09814888638,
        0.09258645438,
        0.10520649538,
        0.10141102138000001,
        0.09566601638,
        0.09862829638000001,
        0.09564572738,
        0.09806906738,
        0.09797520138,
        0.09613044838,
        0.09808808338
      ]
    }
  ]
}

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 1.145 ± 0.359 0.667 1.746 1.20 ± 0.45
pacquet@main 0.957 ± 0.202 0.602 1.279 1.00
pnpm@HEAD 3.308 ± 0.158 3.139 3.549 3.46 ± 0.75
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 1.1450563661355557,
      "stddev": 0.3591855602279567,
      "median": 1.09662400758,
      "user": 1.0852734799999997,
      "system": 0.21711637777777776,
      "min": 0.66726014258,
      "max": 1.74562061358,
      "times": [
        1.74562061358,
        1.27492050158,
        1.65299620758,
        0.8578307875800001,
        1.1205496505800001,
        0.9814045935800001,
        1.09662400758,
        0.90830079058,
        0.66726014258
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 0.9569867502466667,
      "stddev": 0.2023718082707899,
      "median": 0.92710693458,
      "user": 0.8871794799999999,
      "system": 0.20637271111111113,
      "min": 0.60194627258,
      "max": 1.27941542958,
      "times": [
        1.07595416558,
        0.60194627258,
        0.88349683858,
        1.11847369458,
        1.07986623858,
        1.27941542958,
        0.92710693458,
        0.81195396458,
        0.8346672135800001
      ]
    },
    {
      "command": "pnpm@HEAD",
      "mean": 3.308389414913333,
      "stddev": 0.15846173328463986,
      "median": 3.24833615858,
      "user": 5.077280924444445,
      "system": 0.31411048888888893,
      "min": 3.1390204275799998,
      "max": 3.54933051558,
      "times": [
        3.54933051558,
        3.39865079358,
        3.48513489458,
        3.15333211458,
        3.22723150058,
        3.42799204558,
        3.24833615858,
        3.1464762835799998,
        3.1390204275799998
      ]
    }
  ]
}

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 4.634 ± 0.120 4.497 4.852 1.31 ± 0.04
pacquet@main 4.568 ± 0.137 4.485 4.953 1.29 ± 0.05
pnpr@HEAD 3.543 ± 0.076 3.473 3.730 1.00
pnpr@main 3.619 ± 0.144 3.466 3.859 1.02 ± 0.05
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 4.63421498234,
      "stddev": 0.12043138099608346,
      "median": 4.60903022344,
      "user": 2.0225307799999994,
      "system": 1.56986184,
      "min": 4.49680767094,
      "max": 4.85194110894,
      "times": [
        4.58223879494,
        4.57386234094,
        4.85194110894,
        4.53168840994,
        4.69002764994,
        4.6627359969399995,
        4.63582165194,
        4.51311626594,
        4.80390993294,
        4.49680767094
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 4.56837807184,
      "stddev": 0.13745053049779557,
      "median": 4.52873715994,
      "user": 2.01588848,
      "system": 1.5951923399999997,
      "min": 4.48499935394,
      "max": 4.95262667794,
      "times": [
        4.51573636294,
        4.52340873694,
        4.55186750094,
        4.51374876294,
        4.95262667794,
        4.53406558294,
        4.57050648994,
        4.4938228879399995,
        4.54299836194,
        4.48499935394
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 3.5427353860400004,
      "stddev": 0.07602297563917539,
      "median": 3.5180286284399997,
      "user": 1.4015478799999999,
      "system": 1.36550234,
      "min": 3.47330545794,
      "max": 3.72999751694,
      "times": [
        3.59121519294,
        3.48162729394,
        3.49633921194,
        3.47330545794,
        3.52968191694,
        3.54211050494,
        3.72999751694,
        3.5726977069399997,
        3.50637533994,
        3.50400371794
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 3.6191496012399993,
      "stddev": 0.14424382395457205,
      "median": 3.57508897494,
      "user": 1.2843499799999998,
      "system": 1.3196683399999998,
      "min": 3.4656375749399997,
      "max": 3.85910957994,
      "times": [
        3.7811400419399996,
        3.80961984694,
        3.55880113294,
        3.5235118549399997,
        3.5939411999399997,
        3.4656375749399997,
        3.46572002994,
        3.59137681694,
        3.54263793394,
        3.85910957994
      ]
    }
  ]
}

@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Projectpnpm's project
Branchpr/13669
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,862.59 ms
(+5.59%)Baseline: 2,711.01 ms
3,253.22 ms
(87.99%)
isolated-linker.fresh-install.cold-cache.hot-store📈 view plot
🚷 view threshold
2,040.96 ms
(+12.09%)Baseline: 1,820.78 ms
2,184.94 ms
(93.41%)
isolated-linker.fresh-install.hot-cache.hot-store📈 view plot
🚷 view threshold
550.32 ms
(+18.98%)Baseline: 462.54 ms
555.05 ms
(99.15%)
isolated-linker.fresh-resolve.hot-cache.offline📈 view plot
🚷 view threshold
225.28 ms
(+5.77%)Baseline: 212.99 ms
255.58 ms
(88.14%)
isolated-linker.fresh-restore.cold-cache.cold-store📈 view plot
🚷 view threshold
2,597.52 ms
(+6.06%)Baseline: 2,449.10 ms
2,938.92 ms
(88.38%)
isolated-linker.fresh-restore.cold-cache.cold-store.cold-pnpr📈 view plot
🚷 view threshold
4,496.81 ms
(-0.31%)Baseline: 4,510.63 ms
5,412.76 ms
(83.08%)
isolated-linker.fresh-restore.hot-cache.hot-store📈 view plot
🚷 view threshold
296.14 ms
(+0.20%)Baseline: 295.55 ms
354.66 ms
(83.50%)
isolated-linker.peer-heavy-resolve.hot-cache.offline📈 view plot
🚷 view threshold
667.26 ms
(-8.28%)Baseline: 727.48 ms
872.97 ms
(76.44%)
🐰 View full continuous benchmarking report in Bencher

@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Projectpnpm's project
Branchpr/13669
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,556.71 ms
isolated-linker.fresh-install.cold-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
414.00 ms
isolated-linker.fresh-install.hot-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
371.33 ms
isolated-linker.fresh-resolve.hot-cache.offline📈 view plot
⚠️ NO THRESHOLD
90.44 ms
isolated-linker.fresh-restore.cold-cache.cold-store📈 view plot
⚠️ NO THRESHOLD
1,630.57 ms
isolated-linker.fresh-restore.cold-cache.cold-store.cold-pnpr📈 view plot
⚠️ NO THRESHOLD
3,473.31 ms
isolated-linker.fresh-restore.hot-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
351.95 ms
🐰 View full continuous benchmarking report in Bencher

The grouping's contract is specified by its four tests; keep the code
comments to what a reader needs at the site and leave the race
narrative to the changeset and PR.

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

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 merged commit 74577d7 into main Aug 6, 2026
29 checks passed
@zkochan
zkochan deleted the gvs-slot-dedup branch August 6, 2026 07:55
@qodo-code-review

Copy link
Copy Markdown

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

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

zkochan added a commit to zkochan/bit that referenced this pull request Aug 7, 2026
…ript

rc.1 carries the slot-materialization dedup (pnpm/pnpm#13669), the last
engine change the global virtual store needed from a checkout, so the
script that installed a locally built engine over the released one goes
away as promised. It also adds `allowUnusedPatches`, which unblocks the
version-scoped patch approach parked in teambit#10572 if it is ever wanted over
the packageExtensions built-ins.

Verified on the released engine: two consecutive self-hosted
global-virtual-store installs of this repo (the workload whose peer
variants previously raced the link pass on every install), zero race
errors, lint green.

Co-Authored-By: Claude Fable 5 <[email protected]>
zkochan added a commit to zkochan/bit that referenced this pull request Aug 7, 2026
…ript

rc.1 carries the slot-materialization dedup (pnpm/pnpm#13669), the last
engine change the global virtual store needed from a checkout, so the
script that installed a locally built engine over the released one goes
away as promised. It also adds `allowUnusedPatches`, which unblocks the
version-scoped patch approach parked in teambit#10572 if it is ever wanted over
the packageExtensions built-ins.

Verified on the released engine: two consecutive self-hosted
global-virtual-store installs of this repo (the workload whose peer
variants previously raced the link pass on every install), zero race
errors, lint green.

Co-Authored-By: Claude Fable 5 <[email protected]>
zkochan added a commit to zkochan/bit that referenced this pull request Aug 7, 2026
…ript

rc.1 carries the slot-materialization dedup (pnpm/pnpm#13669), the last
engine change the global virtual store needed from a checkout, so the
script that installed a locally built engine over the released one goes
away as promised. It also adds `allowUnusedPatches`, which unblocks the
version-scoped patch approach parked in teambit#10572 if it is ever wanted over
the packageExtensions built-ins.

Verified on the released engine: two consecutive self-hosted
global-virtual-store installs of this repo (the workload whose peer
variants previously raced the link pass on every install), zero race
errors, lint green.

Co-Authored-By: Claude Fable 5 <[email protected]>
zkochan added a commit to teambit/bit that referenced this pull request Aug 8, 2026
Opt-in support for pnpm's global virtual store: dependency directories
are created once in a store shared by every workspace on the machine,
instead of being re-created inside each `node_modules/.pnpm`. Capsules
deliberately keep the project-local layout — see below.

Every engine dependency is in a published `@pnpm/napi`: the settings
surface (pnpm/pnpm#13648) and the `link:` slot fix (pnpm/pnpm#13658) in
12.0.0-rc.0, and the slot-materialization dedup (pnpm/pnpm#13669) in
12.0.0-rc.1, which this branch pins. The local-engine bootstrap script
is gone.

## Effect

After a fresh install the project-local virtual store holds nothing but
`lock.yaml` and the hoisted `node_modules` — every dependency directory,
including injected workspace components, lives in the shared store:

| workspace | `node_modules/.pnpm` entries, no GVS | with GVS |
|---|---|---|
| a Bit Cloud workspace | 20832 | 0 |
| the bit repo itself | 6441 | 0 |
| bitdev-envs | 4017 | 0 |

Bit uses pnpm's own `<storeDir>/links`, so slots are reused across bit
versions and shared with every other pnpm project on the machine,
upgrades stay incremental, and `pnpm store prune` accounts for them.

Migration note: switching an existing workspace over does not remove
what the previous project-local store already contains — pnpm does not
prune it once the effective virtual store points elsewhere — so the old
directories linger until `node_modules/.pnpm` is deleted. New workspaces
never see them.

## Turning it on

Off by default. Per workspace under
`teambit.dependencies/dependency-resolver`, machine-wide with `bit
config set enable_global_virtual_store true`, or per run with
`BIT_ENABLE_GLOBAL_VIRTUAL_STORE=true`. It has no effect when
`nodeLinker` is `hoisted`, which uses no virtual store at all.

## What it took to behave identically

A shared store breaks one assumption that runs through Bit: that a
package can walk *up* out of `node_modules/.pnpm` into the workspace.
Consequences:

- **Core aspects (CJS).** Bit deliberately does not declare `@teambit/*`
core aspects as dependencies of the envs and aspects that use them —
they have to be the single copy from the running installation, and
declaring them would install duplicates. Project-locally they resolved
by walking up into the workspace root; nothing in a shared store can.
This branch uses pnpm's documented mechanism for hoisted dependencies in
this layout: the privately hoisted directory stays project-local at
`node_modules/.pnpm/node_modules` even under the global virtual store,
the core aspects are linked there, and `bootstrap` puts that directory
on `NODE_PATH` before any aspect loads. Nothing is written inside the
store itself, which is what allows the shared `<storeDir>/links` to be
used at all.
- **Core aspects (ESM).** Node ignores `NODE_PATH` for ESM, and bit
supports ESM components, so the same hoisted-directory fallback is
provided to the ESM resolver via a `module.register()` loader (adapted
from pnpm's `@pnpm/plugin-esm-node-path`, MIT), installed at bootstrap
and propagated to child processes through `NODE_OPTIONS`.
- **Phantom `tsconfig` `extends` in published envs.** TypeScript
resolves `extends` with its own resolver — neither `NODE_PATH` nor the
ESM loader applies — and several published envs extend a package they
never declare (`@teambit/react/typescript/tsconfig.json` from the node
mocha envs, `base-react-env`, `rspack.envs.react-env` and `react-env`
1.x; `rspack.envs.react-env/config/tsconfig.json` from `cloud-react`).
Project-locally the walk up out of `.pnpm` passed the privately hoisted
directory and caught these by accident. Fixed with pnpm's documented
remedy: built-in `packageExtensions` declaring the missing dependency
for the known envs, merged under the workspace's own `packageExtensions`
so users can cover third-party envs the same way. Extensions only add
what a manifest lacks, an unmatched entry is not an error (react-env's
is scoped to `@1` — 2.x inlined the config), and none of these envs
import their extends-target at runtime, so the added copy cannot shadow
the host-provided singletons. (#10572 explored a
`patchedDependencies`-based variant for react-env 1.x and is closed —
the extensions cover it.)
- **The bit repo itself.** A workspace that *authors* the core aspects
bridges them into the hoisted store only until they compile, then
removes the bridge. Right project-locally, fatal from a shared store.
The bridge now persists, repointed at the compiled workspace copy.
- **Injected dirs.** `getInjectedDirs` reports an injected copy absolute
when it cannot be made relative to the lockfile dir — under a shared
store, always. `compiler.task.ts` joined it onto the capsule root
regardless, hard-linking build artifacts into a path that does not
exist. (`node-modules-linker` and `workspace-compiler` already guarded
this; only that one site did not.)
- **`bit deps diagnose`.** Its duplicate-copy counts came from scanning
`node_modules/.pnpm`. The shared store holds every workspace's packages,
so it cannot answer that question for one workspace; the counts now come
from the current lockfile pnpm writes next to the hoisted directory,
whose dep paths map one-to-one onto the project-local directory names.
- **Capsules stay project-local.** A capsule is a self-contained build
sandbox and TypeScript's declaration emit depends on that: it names an
inferred type through the package that declares it, which it can only do
while that package sits inside the capsule. Moving env/aspect packages
out made `bit build` of any custom env fail with `TS2742`. Workspace
installs — the ones users wait on repeatedly — still get the shared
store.

## Also here: `patchedDependencies`

The branch adds pnpm's `patchedDependencies` as a dependency-resolver
setting (it began as the vehicle for the react-env `tsconfig` fix above,
and is useful on its own):

```json
{
  "teambit.dependencies/dependency-resolver": {
    "patchedDependencies": { "[email protected]": "patches/is-positive.patch" }
  }
}
```

Paths are relative to the workspace root. pnpm resolves a relative patch
path from the directory it is installing in, so capsule installs — which
run in the capsules directory — get the paths resolved against the
workspace root first; workspace installs keep the configured spelling,
which pnpm records in `pnpm-lock.yaml` and which must stay
machine-independent there.

## Self-hosting: a workspace whose node_modules provides the running bit

Both layouts are safe in steady state: repeat installs preserve the
top-level package directories the running process resolves from
(verified by sampling them through live installs), and the
end-of-install compile refreshes the per-variant copies. A layout
*switch* is different — it relocates every injected component package,
rebuilding the top-level directories from source, so their compiled
`dist` disappears mid-install and a bit running from them dies before
reaching the compile that would restore it, leaving `node_modules`
unusable. The installer now detects the combination (current layout read
off `.modules.yaml`, self-hosting by realpath of the running module) and
refuses up front with instructions to run the one-time transition from
an external bit installation.

With that and the engine fix, the bit repo itself runs under the global
virtual store: full install + compile of all 332 components, repeat
self-hosted installs in ~50s, `npm run lint` green. The repo's own tsc
needed the type-layer counterpart of the runtime bridges —
`tsconfig.json` `paths` routing react typings and `@teambit/*` through
the workspace's `node_modules`, since a published package's `.d.ts`
cannot reach undeclared `@types`/core aspects from a store slot either.

## Phantom dependencies, generally

A shared store makes an under-declared package fail loudly: it lives
outside the project, so nothing the project hoisted is on its resolution
path any more. That is a real constraint, not a bug to work around, and
it applies to pnpm generally rather than to Bit. Every failure this
branch hit was a genuine phantom dependency — an env's undeclared
`tsconfig` base, a fixture env with detection switched off
(`@bit-no-check` removed so the dependency gets declared),
`@teambit/webpack.webpack-bundler` requiring `events/` without declaring
it (covered by `packageExtensions`, documented in the aspect docs), and
the repo's own undeclared `@types/graceful-fs` (now declared).

## One CI change

`bit_pr` now runs on a temp lane (dropped `--keep-lane`). A reused PR
lane serves components unchanged since an earlier export with artifacts
from older commits, so capsules mix generations of `@teambit` packages
and cross-copy `instanceof` checks start failing — deterministic red
that looks exactly like branch breakage and defeats bisection (on this
branch: run 1 green on a fresh lane, every later push red, across 11
runs and 2 lanes). Filed as #10583; the temp-lane flow is
self-consistent per run.

## Testing

- New e2e: `global-virtual-store.e2e.ts` (nothing materialized in the
workspace, dependencies linked from the shared store, component loads
and compiles, patched dependencies under the store) and
`patched-dependencies.e2e.ts` (a workspace-relative patch applies both
in the workspace and in the capsule — verified to fail before the
capsule-path fix).
- The bit repo (332 components): full global-virtual-store install,
repeat self-hosted installs, transition guard verified in both
directions (clean refusal, workspace intact), lint green. Runs on the
released rc.1 engine.
- A Bit Cloud workspace, 105 components: wiped-`node_modules` install +
compile, slot reuse verified (a repeat install creates 0 of 30766
slots), core-aspect resolution through `NODE_PATH` verified positively
and negatively, `bit start` working.
- bitdev-envs (609 components, 20 apps): `bit app list` byte-identical
to the non-GVS baseline, apps running — against an earlier revision of
the core-aspect mechanism.
- The full e2e suite under `BIT_ENABLE_GLOBAL_VIRTUAL_STORE=true` was
run locally against an earlier revision: no GVS-specific failures (the
`validate command` failures reproduce with the store off). CI runs the
suite in its default store-off configuration, where this branch has been
green including the 40-shard e2e.

The first commit (`fix(doctor)`) is unrelated to the rest and can be
split out — it surfaced because the e2e temp dir contains a dot, which
is why `doctor-infra.e2e.ts` fails locally but passes on CI.

---------

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
@coderabbitai coderabbitai Bot mentioned this pull request Aug 11, 2026
5 tasks done
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