Skip to content

fix(resolver): keep hoisted peer providers out of the root peer context - #12847

Merged
zkochan merged 6 commits into
pnpm:mainfrom
spencerbeggs:bug/peer-closures
Jul 9, 2026
Merged

zkochan merged 6 commits into
pnpm:mainfrom
spencerbeggs:bug/peer-closures

Conversation

@spencerbeggs

@spencerbeggs spencerbeggs commented Jul 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

With autoInstallPeers: true, a package version present in a workspace project's own dependencies can leak into the peer resolution of packages deep inside a transitive dependency's closure, overriding the version that closure provides for itself — nearest-dependent resolution should win, and didn't. Fixes #4993 (related analysis in https://github.com/orgs/pnpm/discussions/6450).

Concrete case: a project declares effect@^4.0.0-beta.93 (dev + peer) plus a bundler whose transitive dependency ships a fully self-contained Effect v3 closure ([email protected] and every @effect/* package as regular dependencies). The resolver bound the effect peer of some of those packages to the importer's 4.0.0-beta.93, producing an incoherent snapshot that mixes ([email protected]) and ([email protected]) suffixes under one parent, and crashing at runtime with ERR_MODULE_NOT_FOUND when a v3-built package gets Effect v4 linked as its peer. A minimal public reproduction lives at spencerbeggs/pnpm-closure-minimal.

Root cause. When autoInstallPeers is enabled, resolveRootDependencies attaches every peer that was resolved at an intermediate depth to the root importer's pkgAddresses so other subtrees can reuse it (introduced in #4855). Those attached entries alias tree nodes that already have a position deep in the graph, and resolvePeers walked them a second time as root children. The two walks raced on the shared per-node dep-path state (pathsByNodeId plus its single-shot promises), so each node's final peer binding depended on which context wrote last — hence only some siblings being poisoned. In pacquet the walker is sequential, so the root-context walk deterministically overwrote every in-place resolution and the whole closure was poisoned.

Fix. The attached providers stay visible as root-level peer providers (other subtrees can still resolve their missing peers against them — the behavior the existing "hoist a peer dependency in order to reuse it" tests codify), but they are no longer peer-resolved in the root context. Their own peers now resolve only at their true tree position, with a fallback to the root context only when that position was pruned by the peers cache and nothing else resolved them. Same fix in both stacks: the pushed addresses are flagged (PkgAddress.hoistedPeerProvider in TypeScript, ResolvePeersOptions::hoisted_peer_provider_node_ids in pacquet) and both peer walks skip flagged entries unless unresolved after the main traversal.

Follow-up: fallback deadlock. The root-context fallback originally resolved each pruned provider in its own peer-resolution pass. A pass only detects peer cycles among its own children, and providers frequently peer-depend on each other (the closure fixture's two libs do exactly that), so two pruned providers would leave their dep path calculations awaiting each other forever and hang the install. The TypeScript fallback now resolves all still-pruned providers in a single pass, restoring the cycle short-circuit. Pacquet's sequential walker already self-heals here — build_peer_id falls back to a provisional name@version id and the SCC finalization pass corrects the suffixes — so it needed no code change. Mirrored unit tests in both stacks pin identical dep-path output for the pruned single-provider and mutual-peer-cycle scenarios.

Verification. New registry fixtures (@pnpm.e2e/closure-*) model the shape minimally: a self-contained closure whose two libs peer-depend on each other and on a shared peer, plus an incompatible root version of that peer. Matching tests in both stacks were confirmed to fail before the fix and pass after. On the real-world reproduction, all four cells of the isolation matrix (incompatible root version present/absent × autoInstallPeers on/off) now resolve every effect peer in the closure to 3.21.4, with pnpm peers check clean, in both the TypeScript CLI and pacquet.

Squash Commit Body

With autoInstallPeers, peers resolved inside a dependency subtree are
attached to the root importer's direct dependencies so other subtrees
can reuse them. Those entries alias tree nodes that already have a
position deep in the graph, and the peer-resolution pass walked them a
second time as root children. The two walks raced on the shared
per-node dep-path state, so a package inside a self-contained closure
could get its peers bound to the root project's incompatible version
of a peer instead of the provider next to it in the tree, producing a
lockfile that mixes both versions and a peer mismatch at run time.

The peer-resolution pass now keeps the attached providers visible as
root-level peer providers but resolves their own peers only at their
true tree position, falling back to the root context only when that
position was pruned by the peers cache. All pruned providers are
resolved in a single fallback pass, because a pass only detects peer
cycles among its own children and mutually peer-depending providers
would otherwise await each other's dep path forever. The fix lands in both stacks:
the TypeScript `@pnpm/installing.deps-resolver` and pacquet's
`resolving-deps-resolver` crate.

Fixes https://github.com/pnpm/pnpm/issues/4993

Checklist

  • The change is implemented in both the TypeScript CLI and the Rust
    pacquet/ port, or the description notes what still needs porting.
  • Added a changeset (pnpm changeset) if this PR changes any published
    package. Keep it short and written for pnpm users — it becomes a release note.
  • Added or updated tests.

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

Signed-off-by: C. Spencer Beggs [email protected]

Summary by CodeRabbit

  • Bug Fixes
    • Fixed peer dependency resolution in workspace installs so root-level peers no longer override peers inside self-contained dependency subtrees.
    • Improved handling of auto-installed peers to keep compatible versions bound within the correct part of the dependency tree.
    • Resolved edge cases where peer providers are not directly traversed, including cases with peer cycles, so installs complete with the expected dependency bindings.

@welcome

welcome Bot commented Jul 7, 2026

Copy link
Copy Markdown

💖 Thanks for opening this pull request! 💖
Please be patient and we will get back to you as soon as we can.

@coderabbitai

coderabbitai Bot commented Jul 7, 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: 38d69303-afab-4dac-968f-e6668fed0966

📥 Commits

Reviewing files that changed from the base of the PR and between 51dd7f7 and 3241953.

⛔ Files ignored due to path filters (1)
  • pnpm11/__fixtures__/with-git-protocol-dep/pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml, !**/__fixtures__/**
📒 Files selected for processing (3)
  • pacquet/crates/resolving-deps-resolver/src/resolve_peers/tests.rs
  • pnpm11/installing/deps-resolver/src/resolvePeers.ts
  • pnpm11/installing/deps-resolver/test/resolvePeers.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • pnpm11/installing/deps-resolver/src/resolvePeers.ts

📝 Walkthrough

Walkthrough

This PR fixes a peer-dependency resolution bug where root-attached peer providers were being re-resolved in the root context, incorrectly binding self-contained subtree packages to the root's incompatible package version. It threads hoisted peer-provider node ids through pnpm11 and pacquet resolution paths, adds fixtures, and adds regression tests.

Changes

Hoisted Peer Provider Resolution Fix

Layer / File(s) Summary
Self-contained closure fixtures
pnpr/.fixtures/packages/@pnpm.e2e/closure-lib-a/1.0.0/package.json, closure-lib-b/1.0.0/package.json, closure-peer-x/1.0.0/package.json, closure-peer-x/2.0.0/package.json, closure-plugins/1.0.0/package.json
Adds e2e fixture packages forming a peer-dependency closure with two conflicting versions of closure-peer-x.
pnpm11 peer-provider data flow
pnpm11/installing/deps-resolver/src/resolveDependencies.ts, resolveDependencyTree.ts, index.ts
Marks appended peer addresses as hoistedPeerProvider, collects their node ids into hoistedPeerProviderNodeIds on ResolvedImporters, and forwards the set into ProjectToLink.
pnpm11 peer walk fallback
pnpm11/installing/deps-resolver/src/resolvePeers.ts
Partitions direct children into own vs hoisted-provider groups per project, resolves own children first, then resolves pruned hoisted providers via a root-context fallback.
pnpm11 regression tests
pnpm11/installing/deps-installer/test/install/autoInstallPeers.ts, pnpm11/installing/deps-resolver/test/resolvePeers.ts
Adds tests for the closure subtree install scenario, mutual peer-dependent hoisted providers, and pruned-provider fallback resolution.
pacquet importer hoist state
pacquet/crates/resolving-deps-resolver/src/resolve_importer.rs
Adds hoisted_peer_provider_node_ids tracking to ImporterHoistState, threads it into ResolvePeersOptions, and changes into_direct to also return the collected node ids.
pacquet workspace peer resolution
pacquet/crates/resolving-deps-resolver/src/resolve_peers.rs, resolve_workspace.rs, tests.rs
Adds hoisted_peer_provider_node_ids to ResolvePeersOptions, partitions direct deps in resolve_peers_workspace and Walker::walk, and aggregates provider ids across importers.
pacquet regression tests and changeset
pacquet/crates/package-manager/src/install/tests.rs, pacquet/crates/resolving-deps-resolver/src/resolve_peers/tests.rs, .changeset/peer-closures-root-context.md
Adds integration and unit tests covering the closure subtree scenario and pruned-provider fallback with peer cycles, plus a patch changeset.

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

Sequence Diagram(s)

sequenceDiagram
  participant Installer
  participant resolveDependencyTree
  participant resolveDependencies
  participant resolvePeers
  participant Lockfile

  Installer->>resolveDependencies: resolve root and subtree deps
  resolveDependencies->>resolveDependencies: mark appended peer addresses as hoistedPeerProvider
  resolveDependencies->>resolveDependencyTree: return pkgAddresses
  resolveDependencyTree->>resolveDependencyTree: collect hoistedPeerProviderNodeIds
  resolveDependencyTree->>resolvePeers: pass importers with hoistedPeerProviderNodeIds
  resolvePeers->>resolvePeers: partition own vs hoisted-provider direct children
  resolvePeers->>resolvePeers: resolve own children in main pass
  resolvePeers->>resolvePeers: resolve pruned hoisted providers via root-context fallback
  resolvePeers->>Lockfile: bind subtree peers to closure-provided versions
Loading

Possibly related PRs

  • pnpm/pnpm#11784: Both PRs modify pacquet's auto-install-peers hoisting flow in resolve_importer/resolve_peers.
  • pnpm/pnpm#11906: Both PRs change the same Walker peer-resolution traversal logic in resolve_peers.rs.
  • pnpm/pnpm#12273: Both PRs modify parent-context handling in the core peer-resolution traversal of resolve_peers.rs.

Suggested labels: product: pnpm@11, product: pacquet, product: pnpr

Suggested reviewers: zkochan

✨ 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 failed. For unrecoverable errors, disable the tool in CodeRabbit configuration.


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.

@spencerbeggs
spencerbeggs marked this pull request as ready for review July 7, 2026 18:35
@spencerbeggs
spencerbeggs requested a review from zkochan as a code owner July 7, 2026 18:35
Copilot AI review requested due to automatic review settings July 7, 2026 18:35
@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 →

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.

Pull request overview

Fixes a peer-resolution bug with autoInstallPeers: true where peer providers that were hoisted/attached to the root importer for reuse were also being peer-resolved again in the root context, allowing an incompatible root dependency to “poison” a self-contained transitive closure’s peer graph. The change is implemented in both the TypeScript pnpm CLI resolver and the Rust pacquet/ resolver, and is covered by new fixtures and regression tests.

Changes:

  • TypeScript: mark “hoisted peer providers” and skip traversing them as root children during the root-context peer walk, with a targeted fallback when their real tree position was pruned by the peers cache.
  • Rust (pacquet): thread hoisted-provider node IDs through ResolvePeersOptions and apply the same “skip unless pruned” behavior in the peer walker.
  • Add minimal registry fixtures plus mirrored regression tests in both stacks, and a changeset for the published resolver package + pnpm.

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated no comments.

Show a summary per file
File Description
pnpr/.fixtures/packages/@pnpm.e2e/closure-plugins/1.0.0/package.json Adds a minimal fixture package that represents a self-contained closure root.
pnpr/.fixtures/packages/@pnpm.e2e/closure-peer-x/1.0.0/package.json Adds fixture for the “correct” peer version inside the closure.
pnpr/.fixtures/packages/@pnpm.e2e/closure-peer-x/2.0.0/package.json Adds fixture for the incompatible root-level peer version used in the regression scenario.
pnpr/.fixtures/packages/@pnpm.e2e/closure-lib-a/1.0.0/package.json Adds fixture library participating in mutual peer dependencies within the closure.
pnpr/.fixtures/packages/@pnpm.e2e/closure-lib-b/1.0.0/package.json Adds fixture library participating in mutual peer dependencies within the closure.
pnpm11/installing/deps-resolver/src/resolvePeers.ts Skips hoisted peer providers in the root traversal and adds a cache-prune fallback resolution path.
pnpm11/installing/deps-resolver/src/resolveDependencyTree.ts Collects hoistedPeerProviderNodeIds per importer so the peer resolver can recognize hoisted providers.
pnpm11/installing/deps-resolver/src/resolveDependencies.ts Flags hoisted peer-provider PkgAddress entries when they’re attached to the root importer for reuse.
pnpm11/installing/deps-resolver/src/index.ts Threads hoistedPeerProviderNodeIds through project inputs to the peer-resolution passes.
pnpm11/installing/deps-installer/test/install/autoInstallPeers.ts Adds a regression test asserting closure peers don’t bind to an incompatible root dependency.
pacquet/crates/resolving-deps-resolver/src/tests.rs Updates test options construction to use defaults after adding a new options field.
pacquet/crates/resolving-deps-resolver/src/resolve_workspace.rs Aggregates hoisted-provider node IDs from importers and passes them into workspace peer resolution.
pacquet/crates/resolving-deps-resolver/src/resolve_peers.rs Implements “skip hoisted providers as root children unless pruned” in the Rust peer walker.
pacquet/crates/resolving-deps-resolver/src/resolve_importer.rs Tracks and exports the hoisted-provider node IDs attached during auto-install-peers hoisting.
pacquet/crates/package-manager/src/install/tests.rs Adds the mirrored Rust regression test asserting no poisoning of closure peers by the root.
.changeset/peer-closures-root-context.md Publishes the fix as a patch changeset for @pnpm/installing.deps-resolver and pnpm.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov-commenter

codecov-commenter commented Jul 7, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.34%. Comparing base (abb6f41) to head (3241953).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #12847      +/-   ##
==========================================
- Coverage   85.35%   85.34%   -0.01%     
==========================================
  Files         453      453              
  Lines       70868    71074     +206     
==========================================
+ Hits        60488    60661     +173     
- Misses      10380    10413      +33     

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

@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)
pnpm11/installing/deps-installer/test/install/autoInstallPeers.ts (1)

778-786: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider asserting root's own choice is preserved too.

Adding a check that the root importer's own closure-peer-x binding still resolves to 2.0.0 (e.g. via lockfile.importers['.'].dependencies) would confirm the fix doesn't accidentally suppress the root's explicit version choice while fixing the subtree, strengthening confidence in the regression coverage.

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

In `@pnpm11/installing/deps-installer/test/install/autoInstallPeers.ts` around
lines 778 - 786, The current test in autoInstallPeers only checks the closure
subtree, but it should also verify the root importer keeps its explicit
closure-peer-x version choice. Extend the assertions around
project.readLockfile() and lockfile.importers['.'] to confirm the root
dependency binding still resolves to 2.0.0 while the closure-lib snapshots
remain free of that version, using the existing lockfile and pluginsSnapshot
checks as the anchor.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@pnpm11/installing/deps-installer/test/install/autoInstallPeers.ts`:
- Around line 778-786: The current test in autoInstallPeers only checks the
closure subtree, but it should also verify the root importer keeps its explicit
closure-peer-x version choice. Extend the assertions around
project.readLockfile() and lockfile.importers['.'] to confirm the root
dependency binding still resolves to 2.0.0 while the closure-lib snapshots
remain free of that version, using the existing lockfile and pluginsSnapshot
checks as the anchor.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 9e097a86-3db4-4ddd-b93f-67c70c50b9cd

📥 Commits

Reviewing files that changed from the base of the PR and between be8e8ea and 914e1fd.

📒 Files selected for processing (16)
  • .changeset/peer-closures-root-context.md
  • pacquet/crates/package-manager/src/install/tests.rs
  • pacquet/crates/resolving-deps-resolver/src/resolve_importer.rs
  • pacquet/crates/resolving-deps-resolver/src/resolve_peers.rs
  • pacquet/crates/resolving-deps-resolver/src/resolve_workspace.rs
  • pacquet/crates/resolving-deps-resolver/src/tests.rs
  • pnpm11/installing/deps-installer/test/install/autoInstallPeers.ts
  • pnpm11/installing/deps-resolver/src/index.ts
  • pnpm11/installing/deps-resolver/src/resolveDependencies.ts
  • pnpm11/installing/deps-resolver/src/resolveDependencyTree.ts
  • pnpm11/installing/deps-resolver/src/resolvePeers.ts
  • pnpr/.fixtures/packages/@pnpm.e2e/closure-lib-a/1.0.0/package.json
  • pnpr/.fixtures/packages/@pnpm.e2e/closure-lib-b/1.0.0/package.json
  • pnpr/.fixtures/packages/@pnpm.e2e/closure-peer-x/1.0.0/package.json
  • pnpr/.fixtures/packages/@pnpm.e2e/closure-peer-x/2.0.0/package.json
  • pnpr/.fixtures/packages/@pnpm.e2e/closure-plugins/1.0.0/package.json

@github-actions github-actions Bot added the reviewed: coderabbit CodeRabbit submitted an approving review label Jul 7, 2026
@spencerbeggs

Copy link
Copy Markdown
Contributor Author

Addressed both review points in 85eb9a9:

  • CodeRabbit's suggestion (root's own choice preserved): the regression tests in both stacks now also assert that the root importer's explicitly declared @pnpm.e2e/[email protected] binding is kept while the subtree resolves to its own 1.0.0 — the fix scopes the change to the subtree without suppressing the root's version choice.
  • Codecov patch coverage (resolve_peers.rs 85.36%): the uncovered lines were the pruned-provider fallback bodies in Walker::walk and resolve_peers_workspace — the path taken only when a hoisted provider's tree position was pruned by the peers cache. Two new unit tests (pruned_hoisted_provider_falls_back_to_root_resolution, pruned_hoisted_provider_falls_back_in_workspace_pass) construct that scenario directly and exercise both entry points.

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

@github-actions

github-actions Bot commented Jul 7, 2026 •

Copy link
Copy Markdown
Contributor

Integrated-Benchmark Report (Linux)

Commit: 3241953808ee

Each scenario reports direct installs and pnpr installs. Bencher consumes pacquet@HEAD and pnpr@HEAD.

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 4.147 ± 0.326 3.794 4.769 1.75 ± 0.18
pacquet@main 4.390 ± 0.460 3.849 5.054 1.85 ± 0.23
pnpr@HEAD 2.374 ± 0.162 2.171 2.570 1.00
pnpr@main 2.446 ± 0.227 2.047 2.799 1.03 ± 0.12
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 4.1473925951399995,
      "stddev": 0.32631338336930465,
      "median": 4.05970961164,
      "user": 3.50364948,
      "system": 1.9662776000000002,
      "min": 3.79428592764,
      "max": 4.76879687564,
      "times": [
        4.76879687564,
        3.92173931564,
        4.16324862064,
        3.95617060264,
        4.39743698664,
        4.31282191464,
        3.90176479264,
        3.79428592764,
        4.45197777064,
        3.8056831446399997
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 4.39004037754,
      "stddev": 0.4604065260533572,
      "median": 4.37679846514,
      "user": 3.4518422799999997,
      "system": 1.9395692,
      "min": 3.84858435264,
      "max": 5.05363439364,
      "times": [
        4.97437212764,
        4.37529764664,
        4.1970784306399995,
        4.91275387764,
        3.87954945764,
        5.05363439364,
        4.40190211964,
        4.37829928364,
        3.87893208564,
        3.84858435264
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 2.37367811204,
      "stddev": 0.16167775271845192,
      "median": 2.39343528764,
      "user": 2.3364623799999995,
      "system": 1.5782994,
      "min": 2.17075138364,
      "max": 2.57005029764,
      "times": [
        2.49283380264,
        2.23152045364,
        2.50119209164,
        2.29403677264,
        2.25076550364,
        2.57005029764,
        2.17075138364,
        2.18021519264,
        2.49485624164,
        2.55055938064
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 2.4459468638399997,
      "stddev": 0.22725482184401752,
      "median": 2.4246699221399997,
      "user": 2.31545588,
      "system": 1.6225341999999998,
      "min": 2.04689768564,
      "max": 2.79865289064,
      "times": [
        2.46902099064,
        2.79865289064,
        2.4339847896399998,
        2.6653181026399997,
        2.41535505464,
        2.38809746364,
        2.31201742064,
        2.04689768564,
        2.23116956164,
        2.69895467864
      ]
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 699.5 ± 169.9 545.5 1119.6 1.00
pacquet@main 701.0 ± 121.5 555.7 914.0 1.00 ± 0.30
pnpr@HEAD 1226.3 ± 409.4 733.6 2024.2 1.75 ± 0.72
pnpr@main 875.2 ± 300.2 572.6 1651.7 1.25 ± 0.53
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.6995343802,
      "stddev": 0.1699346978578369,
      "median": 0.7019307425000001,
      "user": 0.33211244,
      "system": 0.6758831399999998,
      "min": 0.545492675,
      "max": 1.1196289700000002,
      "times": [
        0.710815928,
        1.1196289700000002,
        0.720408176,
        0.580326168,
        0.721467972,
        0.555374754,
        0.693045557,
        0.545492675,
        0.780100912,
        0.5686826899999999
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 0.7010048815,
      "stddev": 0.1215031471367424,
      "median": 0.7060116745,
      "user": 0.33244413999999994,
      "system": 0.69211324,
      "min": 0.555745854,
      "max": 0.913976859,
      "times": [
        0.662700476,
        0.740599669,
        0.555745854,
        0.848505897,
        0.573248803,
        0.67142368,
        0.743795563,
        0.556771078,
        0.743280936,
        0.913976859
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 1.2263443606,
      "stddev": 0.40942526936416956,
      "median": 1.0979703340000002,
      "user": 0.35306983999999997,
      "system": 0.7138330399999998,
      "min": 0.73360446,
      "max": 2.024184336,
      "times": [
        1.285407001,
        1.055046683,
        0.73360446,
        0.818761458,
        0.948472937,
        1.671063549,
        1.556811807,
        2.024184336,
        1.1408939850000002,
        1.02919739
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.8752456439999998,
      "stddev": 0.30023249797484397,
      "median": 0.7869880335,
      "user": 0.34035434,
      "system": 0.68186484,
      "min": 0.572615756,
      "max": 1.651672658,
      "times": [
        0.766627009,
        0.983929746,
        0.774231872,
        0.751061127,
        0.884654047,
        0.799744195,
        1.651672658,
        0.934195299,
        0.633724731,
        0.572615756
      ]
    }
  ]
}

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 4.188 ± 0.258 3.946 4.730 1.71 ± 0.28
pacquet@main 4.362 ± 0.270 4.081 4.961 1.78 ± 0.29
pnpr@HEAD 2.840 ± 0.564 2.072 3.716 1.16 ± 0.29
pnpr@main 2.448 ± 0.370 2.059 3.334 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 4.188354350799999,
      "stddev": 0.2584168560386458,
      "median": 4.074678799199999,
      "user": 3.28137926,
      "system": 1.8351941799999998,
      "min": 3.9461073762,
      "max": 4.7299223592,
      "times": [
        4.7299223592,
        4.137075461199999,
        4.073781084199999,
        4.0755765142,
        3.9461073762,
        4.062077544199999,
        4.012859210199999,
        4.006794364199999,
        4.2896135852,
        4.549736009199999
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 4.361624450999999,
      "stddev": 0.270367899406952,
      "median": 4.3429640362,
      "user": 3.3267678600000004,
      "system": 1.85267078,
      "min": 4.081316397199999,
      "max": 4.9613552701999994,
      "times": [
        4.2338588262,
        4.3017376692,
        4.0821919412,
        4.9613552701999994,
        4.4898129531999995,
        4.1077360402,
        4.081316397199999,
        4.3841904032,
        4.5533412671999995,
        4.4207037422
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 2.8401677561999996,
      "stddev": 0.56440913085692,
      "median": 2.8667800996999997,
      "user": 2.1302661600000006,
      "system": 1.5367911799999998,
      "min": 2.0716738732,
      "max": 3.7160956412,
      "times": [
        3.5689822712,
        3.7160956412,
        2.9049802802,
        2.2525882852,
        2.8719777092,
        3.3316242422,
        2.3179627802,
        2.0716738732,
        2.5042099892,
        2.8615824902
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 2.4478584816,
      "stddev": 0.36972893607675983,
      "median": 2.3516714967,
      "user": 2.15156526,
      "system": 1.5462514799999998,
      "min": 2.0592333082,
      "max": 3.3342881042,
      "times": [
        2.7049938842,
        2.2886469212000002,
        3.3342881042,
        2.2968197422,
        2.1468857912,
        2.5782462452,
        2.4778360252000002,
        2.1851115432,
        2.4065232512,
        2.0592333082
      ]
    }
  ]
}

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 1.249 ± 0.124 1.148 1.586 2.13 ± 0.23
pacquet@main 1.213 ± 0.074 1.157 1.386 2.07 ± 0.15
pnpr@HEAD 0.586 ± 0.021 0.568 0.639 1.00
pnpr@main 0.718 ± 0.187 0.573 1.090 1.23 ± 0.32
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 1.2486408528600001,
      "stddev": 0.12433489589695074,
      "median": 1.2127411600600002,
      "user": 1.1547391,
      "system": 0.90987036,
      "min": 1.1482783835600001,
      "max": 1.58589981756,
      "times": [
        1.23372272856,
        1.2296272535600001,
        1.1873514735600001,
        1.19585506656,
        1.1482783835600001,
        1.27743234756,
        1.18468141956,
        1.19155833956,
        1.58589981756,
        1.25200169856
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 1.21309091806,
      "stddev": 0.07442697533378176,
      "median": 1.17918497156,
      "user": 1.1430656,
      "system": 0.9183881599999999,
      "min": 1.15680550456,
      "max": 1.38588190856,
      "times": [
        1.25228104056,
        1.15716916856,
        1.18481137856,
        1.16164410856,
        1.38588190856,
        1.2796940805600001,
        1.17355856456,
        1.16114929856,
        1.15680550456,
        1.21791412756
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.58562724876,
      "stddev": 0.021089363568745696,
      "median": 0.58368198056,
      "user": 0.2932916,
      "system": 0.6488904599999998,
      "min": 0.5678997775600001,
      "max": 0.63892037956,
      "times": [
        0.5856913675600001,
        0.5905384705600001,
        0.63892037956,
        0.59528381856,
        0.5823153815600001,
        0.58504857956,
        0.56970315656,
        0.57195484456,
        0.5678997775600001,
        0.56891671156
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.71818784566,
      "stddev": 0.18675597499918967,
      "median": 0.5995290310600001,
      "user": 0.29910709999999996,
      "system": 0.65721136,
      "min": 0.5733650935600001,
      "max": 1.08984754856,
      "times": [
        1.08984754856,
        0.82837129756,
        0.9675216635600001,
        0.7579975655600001,
        0.5959511005600001,
        0.5734660355600001,
        0.5733650935600001,
        0.59630008956,
        0.59994499556,
        0.5991130665600001
      ]
    }
  ]
}

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 2.772 ± 0.104 2.688 3.037 4.72 ± 0.25
pacquet@main 2.770 ± 0.134 2.666 3.082 4.72 ± 0.28
pnpr@HEAD 0.587 ± 0.021 0.571 0.638 1.00
pnpr@main 0.607 ± 0.042 0.572 0.721 1.03 ± 0.08
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 2.7719904235799997,
      "stddev": 0.10384553650259275,
      "median": 2.73489988988,
      "user": 1.5934499400000002,
      "system": 1.0857152600000002,
      "min": 2.68821879738,
      "max": 3.03743310438,
      "times": [
        2.72143518838,
        2.8355307283799998,
        2.69789748738,
        2.7904514953799997,
        2.7483083813799998,
        2.72149139838,
        2.70842023238,
        2.68821879738,
        2.77071742238,
        3.03743310438
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 2.76980935518,
      "stddev": 0.13382668850750218,
      "median": 2.71641448138,
      "user": 1.58027134,
      "system": 1.0752591599999999,
      "min": 2.66645610938,
      "max": 3.08236767538,
      "times": [
        2.72875209638,
        2.67386515438,
        2.69785961338,
        2.7874135073799997,
        2.70407686638,
        2.66645610938,
        2.74049003338,
        2.68950678738,
        3.08236767538,
        2.92730570838
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.5867393423800001,
      "stddev": 0.021147208570332292,
      "median": 0.58129012738,
      "user": 0.29260014,
      "system": 0.6482467599999999,
      "min": 0.5706908013800001,
      "max": 0.63833700638,
      "times": [
        0.5718519883800001,
        0.58456918138,
        0.5706908013800001,
        0.58685261538,
        0.5710899633800001,
        0.58074600138,
        0.58183425338,
        0.57424597438,
        0.60717563838,
        0.63833700638
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.6070401809800001,
      "stddev": 0.04243891473810144,
      "median": 0.59787939088,
      "user": 0.2928960400000001,
      "system": 0.66644446,
      "min": 0.57228654038,
      "max": 0.7208901443800001,
      "times": [
        0.7208901443800001,
        0.6130805583800001,
        0.59861260638,
        0.60981823438,
        0.58910973738,
        0.57228654038,
        0.5796462063800001,
        0.57973366338,
        0.59714617538,
        0.61007794338
      ]
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 553.8 ± 7.9 542.8 565.1 5.89 ± 0.16
pacquet@main 550.7 ± 11.4 537.6 566.5 5.85 ± 0.19
pnpr@HEAD 94.1 ± 2.1 89.9 97.5 1.00 ± 0.03
pnpr@main 94.1 ± 2.3 89.6 96.6 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.5538038535800001,
      "stddev": 0.00788958008423962,
      "median": 0.55099944148,
      "user": 0.53371052,
      "system": 0.09848979999999999,
      "min": 0.54282558648,
      "max": 0.5651378634800001,
      "times": [
        0.56117773248,
        0.54949984148,
        0.54628983548,
        0.56183568948,
        0.5651378634800001,
        0.56167744048,
        0.55173877248,
        0.54759566348,
        0.55026011048,
        0.54282558648
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 0.55067408748,
      "stddev": 0.011353046987556379,
      "median": 0.5493537149800001,
      "user": 0.5361510199999999,
      "system": 0.09424809999999999,
      "min": 0.53760737848,
      "max": 0.56654686448,
      "times": [
        0.56654686448,
        0.56201315548,
        0.56109278948,
        0.56172404648,
        0.53760737848,
        0.55174175648,
        0.53896381848,
        0.54696567348,
        0.54018432748,
        0.53990106448
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.09413705298000001,
      "stddev": 0.0021211802876510265,
      "median": 0.09490272898000002,
      "user": 0.023493753333333332,
      "system": 0.010494599999999996,
      "min": 0.08991499248000001,
      "max": 0.09747496248000001,
      "times": [
        0.09295770748000001,
        0.09423379848,
        0.09133919848000001,
        0.09052425648000001,
        0.09747496248000001,
        0.09431820648000001,
        0.09648209248,
        0.09522425748,
        0.09373162548000001,
        0.09517657048000001,
        0.09135103748000001,
        0.09595005248,
        0.09505914048000001,
        0.09491937948000001,
        0.09075767548000001,
        0.09116193648000001,
        0.09672369648000001,
        0.09436268748000001,
        0.09609168448000001,
        0.09510504148000001,
        0.09554431248,
        0.09590770448000001,
        0.09530757848,
        0.09539643948000001,
        0.08991499248000001,
        0.09093596048000001,
        0.09488607848000001,
        0.09233012948000001,
        0.09466961548000001,
        0.09627377048
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.09409678864666667,
      "stddev": 0.0022648003271246984,
      "median": 0.09522484398,
      "user": 0.02278505333333333,
      "system": 0.010995000000000001,
      "min": 0.08964305648000001,
      "max": 0.09664054148000001,
      "times": [
        0.09278159648,
        0.09534551048,
        0.09461726848,
        0.09072987548000001,
        0.09083348748,
        0.09071016948,
        0.09044471348000001,
        0.08964305648000001,
        0.09145261748000001,
        0.09573135048,
        0.09551018048000001,
        0.09664054148000001,
        0.09485057048000001,
        0.09603742548000001,
        0.09584692848000001,
        0.09625409848000001,
        0.09522011348000001,
        0.09546506048,
        0.09495771148000001,
        0.09526541148,
        0.09512405848000001,
        0.09635204948000001,
        0.09619938848000001,
        0.09563607848000001,
        0.09382648848000001,
        0.09527498348,
        0.09522957448000001,
        0.08991812648000001,
        0.09134679548,
        0.09565842848
      ]
    }
  ]
}

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 9.368 ± 1.693 7.050 12.314 1.34 ± 0.44
pacquet@main 7.744 ± 0.779 6.805 9.033 1.11 ± 0.32
pnpr@HEAD 7.530 ± 1.419 5.540 9.313 1.07 ± 0.36
pnpr@main 7.007 ± 1.917 5.705 12.168 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 9.36771167222,
      "stddev": 1.6934955485425083,
      "median": 9.47241098582,
      "user": 3.461398199999999,
      "system": 2.03497874,
      "min": 7.049972257319999,
      "max": 12.313761014319999,
      "times": [
        12.313761014319999,
        10.63133213432,
        8.72502102232,
        8.02776206832,
        7.712905495319999,
        7.049972257319999,
        10.21980094932,
        10.54369035232,
        10.46491980432,
        7.98795162432
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 7.744223406719999,
      "stddev": 0.7785262117022373,
      "median": 7.645787499819999,
      "user": 3.4711092,
      "system": 2.04451174,
      "min": 6.804824743319999,
      "max": 9.03314351232,
      "times": [
        8.15518848332,
        7.806293216319999,
        9.03314351232,
        7.432235900319999,
        6.804824743319999,
        7.48528178332,
        7.04703317432,
        8.87730799132,
        7.933244440319999,
        6.86768082232
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 7.53039467832,
      "stddev": 1.4188188320862667,
      "median": 7.85567319682,
      "user": 2.4179025999999997,
      "system": 1.68714674,
      "min": 5.53979244232,
      "max": 9.31344081232,
      "times": [
        5.53979244232,
        5.61835123132,
        5.84940768032,
        7.2608614843199994,
        7.68982021932,
        8.30747611632,
        8.67906688732,
        9.31344081232,
        8.02152617432,
        9.02420373532
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 7.00684309202,
      "stddev": 1.9170140146517745,
      "median": 6.39329141382,
      "user": 2.4232840999999996,
      "system": 1.7246344399999998,
      "min": 5.70498070032,
      "max": 12.16750637432,
      "times": [
        12.16750637432,
        7.37168293432,
        6.5112928833199994,
        6.10495678732,
        6.27528994432,
        5.85811712932,
        5.70498070032,
        7.59112534632,
        5.93496426532,
        6.54851455532
      ]
    }
  ]
}

@github-actions

github-actions Bot commented Jul 7, 2026 •

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Branchpr/12847
Testbedpacquet

🚨 1 Alert

BenchmarkMeasure
Units
ViewBenchmark Result
(Result Δ%)
Upper Boundary
(Limit %)
isolated-linker.fresh-restore.cold-cache.cold-store.cold-pnprLatency
seconds (s)
📈 plot
🚷 threshold
🚨 alert (🔔)
9.37 s
(+38.68%)Baseline: 6.75 s
8.11 s
(115.57%)

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
4,188.35 ms
(-1.41%)Baseline: 4,248.28 ms
5,097.93 ms
(82.16%)
isolated-linker.fresh-install.cold-cache.hot-store📈 view plot
🚷 view threshold
2,771.99 ms
(-8.70%)Baseline: 3,036.06 ms
3,643.27 ms
(76.09%)
isolated-linker.fresh-install.hot-cache.hot-store📈 view plot
🚷 view threshold
1,248.64 ms
(-8.11%)Baseline: 1,358.84 ms
1,630.61 ms
(76.58%)
isolated-linker.fresh-resolve.hot-cache.offline📈 view plot
🚷 view threshold
553.80 ms
(-13.95%)Baseline: 643.57 ms
772.28 ms
(71.71%)
isolated-linker.fresh-restore.cold-cache.cold-store📈 view plot
🚷 view threshold
4,147.39 ms
(+3.47%)Baseline: 4,008.19 ms
4,809.83 ms
(86.23%)
isolated-linker.fresh-restore.cold-cache.cold-store.cold-pnpr📈 view plot
🚷 view threshold
🚨 view alert (🔔)
9,367.71 ms
(+38.68%)Baseline: 6,754.72 ms
8,105.66 ms
(115.57%)

isolated-linker.fresh-restore.hot-cache.hot-store📈 view plot
🚷 view threshold
699.53 ms
(+8.93%)Baseline: 642.19 ms
770.63 ms
(90.77%)
🐰 View full continuous benchmarking report in Bencher

@github-actions

github-actions Bot commented Jul 7, 2026 •

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Branchpr/12847
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
2,204.82 ms
isolated-linker.fresh-install.cold-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
695.11 ms
isolated-linker.fresh-install.hot-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
726.00 ms
isolated-linker.fresh-resolve.hot-cache.offline📈 view plot
⚠️ NO THRESHOLD
112.01 ms
isolated-linker.fresh-restore.cold-cache.cold-store📈 view plot
⚠️ NO THRESHOLD
2,194.71 ms
isolated-linker.fresh-restore.cold-cache.cold-store.cold-pnpr📈 view plot
⚠️ NO THRESHOLD
4,918.19 ms
isolated-linker.fresh-restore.hot-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
724.33 ms
🐰 View full continuous benchmarking report in Bencher

With autoInstallPeers, peers resolved inside a dependency subtree are
attached to the root importer's direct dependencies so other subtrees
can reuse them. Those entries alias tree nodes that already have a
position deep in the graph, and the peer-resolution pass walked them a
second time as root children. The two walks raced on the shared
per-node dep-path state, so a package inside a self-contained closure
could get its peers bound to the root project's incompatible version
of a peer instead of the provider next to it in the tree, producing a
lockfile that mixes both versions and a peer mismatch at run time.

The peer-resolution pass now keeps the attached providers visible as
root-level peer providers but resolves their own peers only at their
true tree position, falling back to the root context only when that
position was pruned by the peers cache. The fix lands in both stacks:
the TypeScript `@pnpm/installing.deps-resolver` and pacquet's
`resolving-deps-resolver` crate.

Fixes pnpm#4993

Signed-off-by: C. Spencer Beggs <[email protected]>
Address review feedback on the closure-poisoning fix: unit tests now
exercise the root-context fallback for a hoisted peer provider whose
tree position was pruned (both the single-importer walk and the
workspace pass), and the regression tests in both stacks additionally
assert that the root importer's own explicitly declared peer version
is preserved while the subtree keeps its own.

Signed-off-by: C. Spencer Beggs <[email protected]>
Copilot AI review requested due to automatic review settings July 9, 2026 14:36
@zkochan
zkochan force-pushed the bug/peer-closures branch from 85eb9a9 to 51dd7f7 Compare July 9, 2026 14:36

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

qodo-code-review Bot commented Jul 9, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (3) 📎 Requirement gaps (0) 📜 Skill insights (0)

Context used
✅ Compliance rules (platform): 51 rules

Grey Divider


Remediation recommended

1. Rust test doc comment wrong 📘 Rule violation ⚙ Maintainability ⭐ New
Description
The doc comment claims the fallback collapses mutual-peer cycles to name@version, but the test
asserts dep paths with peer suffixes, so the comment does not describe current behavior and can
mislead future changes.
Code

pacquet/crates/resolving-deps-resolver/src/resolve_peers/tests.rs[R1329-1333]

+/// Mirror of the TS test "pruned hoisted peer providers that peer-depend on
+/// each other are resolved together" (`deps-resolver/test/resolvePeers.ts`):
+/// two pruned providers form a peer cycle, so each one's suffix depends on
+/// the other's. Both must come out of the fallback with the cycle collapsed
+/// to `name@version`, matching the in-place cycle handling.
Evidence
Rule 772199 requires comments to describe current behavior. The added doc comment claims the cycle
is collapsed to name@version, but the same test asserts resolved dep paths that include mutual
peer suffixes, so the comment is not describing current behavior.

Rule 772199: Comments must describe current behavior, not historical implementations
pacquet/crates/resolving-deps-resolver/src/resolve_peers/tests.rs[1329-1333]
pacquet/crates/resolving-deps-resolver/src/resolve_peers/tests.rs[1385-1399]

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 Rust test doc comment states that the fallback resolves a mutual-peer cycle with the cycle collapsed to `name@version`, but the test assertions expect peer-suffixed dep paths (e.g., `[email protected]([email protected])`). This means the comment does not reflect the current behavior.

## Issue Context
This comment is part of a new regression test around pruned hoisted peer providers. Incorrect commentary can cause future maintainers to “fix” the code toward the wrong behavior or misunderstand what the regression is actually protecting.

## Fix Focus Areas
- pacquet/crates/resolving-deps-resolver/src/resolve_peers/tests.rs[1329-1333]

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


2. Unbatched provider fallback ✓ Resolved 🐞 Bug ➹ Performance
Description
In resolvePeers(), each pruned hoisted peer provider is resolved via a separate
resolvePeersOfChildren() call, repeating per-call setup and cycle-analysis work. With many hoisted
providers pruned by peersCache, this adds avoidable overhead on pnpm’s install hot path.
Code

pnpm11/installing/deps-resolver/src/resolvePeers.ts[R150-171]

+    // Hoisted peer providers stay visible as providers (via pkgsByName) but are
+    // not traversed as direct children: their nodeIds point into subtrees, and
+    // resolving them a second time in the project's root context would bind
+    // their peers to the project's own dependencies instead of the providers
+    // next to them in the tree, racing with the in-place resolution on
+    // pathsByNodeId and producing peer graphs that mix both contexts.
+    const ownDirectChildren: Record<string, NodeId> = {}
+    const hoistedProviderChildren: Record<string, NodeId> = {}
+    for (const [alias, nodeId] of directNodeIdsByAlias.entries()) {
+      if (hoistedPeerProviderNodeIds?.has(nodeId)) {
+        hoistedProviderChildren[alias] = nodeId
+      } else {
+        ownDirectChildren[alias] = nodeId
+      }
+    }
+    const parentPkgsOfNode: ParentPkgsOfNode = new Map()
+    const projectPeersContext = {
      allPeerDepNames: opts.allPeerDepNames,
-      parentPkgsOfNode: new Map(),
+      parentPkgsOfNode,
      dependenciesTree: opts.dependenciesTree,
      depGraph,
      lockfileDir: opts.lockfileDir,
Evidence
The new fallback loop calls resolvePeersOfChildren() once per provider. resolvePeersOfChildren()
performs per-call work including nodeId promise initialization and may run analyzeGraph() for
cycle detection, so repeated calls amplify that cost.

pnpm11/installing/deps-resolver/src/resolvePeers.ts[150-205]
pnpm11/installing/deps-resolver/src/resolvePeers.ts[1014-1116]

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

### Issue description
`resolvePeers()` loops over `hoistedProviderChildren` and calls `resolvePeersOfChildren({ [alias]: nodeId }, ...)` for each pruned provider. Each call does non-trivial per-invocation work (node-id dedupe, deferred promise setup, and potentially `analyzeGraph()`), so doing it N times can be noticeably slower when many providers are pruned.

### Issue Context
This code runs during peer-resolution, which is in pnpm’s install/add/update hot path. The fallback is meant to be rare, but when it triggers it may do repeated work.

### Fix Focus Areas
- pnpm11/installing/deps-resolver/src/resolvePeers.ts[150-205]
- pnpm11/installing/deps-resolver/src/resolvePeers.ts[1014-1116]

### Suggested fix
1. Build a single `unresolvedHoistedProviders` record containing only entries where `!parentPkgsOfNode.has(nodeId)`.
2. If non-empty, call `resolvePeersOfChildren(unresolvedHoistedProviders, pkgsByName, projectPeersContext)` once (instead of once per provider).
3. Push the returned `finishing` once.

This preserves the “only fallback for pruned providers” behavior while reducing repeated traversal overhead.

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


3. Test doc repeats scenario details 📘 Rule violation ⚙ Maintainability
Description
The new Rust test’s doc comment largely restates the same concrete scenario and version details
already encoded in the test body and assertions. This duplicates the test scenario explanation
instead of keeping the comment focused on why the scenario matters.
Code

pacquet/crates/package-manager/src/install/tests.rs[R1723-1735]

+/// Mirror of the TS test "a root dependency does not override the
+/// peers provided inside a self-contained subtree"
+/// (`deps-installer/test/install/autoInstallPeers.ts`).
+///
+/// `@pnpm.e2e/closure-plugins` provides every peer of its own subtree
+/// (`closure-lib-a` and `closure-lib-b` peer-depend on each other and
+/// on `closure-peer-x`, and all three are its regular dependencies).
+/// The root project additionally depends on the incompatible
+/// `[email protected]`. With `autoInstallPeers` (the default), the
+/// peers resolved inside the subtree are attached to the root project
+/// for reuse — but they must not be peer-resolved again in the root
+/// context, where `[email protected]` is the nearest provider, or
+/// the subtree's peer graph gets a mix of both versions.
Evidence
PR Compliance ID 713470 forbids duplicating detailed scenario explanations in test comments when the
test code/assertions already express those specifics. The added doc comment repeats the exact
dependency/version narrative that the test then sets up and asserts on.

Rule 713470: Avoid duplicating test scenario explanations in both code and doc comments
pacquet/crates/package-manager/src/install/tests.rs[1723-1735]

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

## Issue description
The doc comment for the new test repeats detailed scenario mechanics (package relationships and exact versions) that are already represented by the test setup and assertions.

## Issue Context
Compliance requires avoiding duplicative test scenario narration in both comments and tests; comments should add *why* the scenario matters rather than re-listing the same facts the test already encodes.

## Fix Focus Areas
- pacquet/crates/package-manager/src/install/tests.rs[1723-1735]

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


View more (1)
4. hoisted_peer_provider_node_ids docs too detailed 📘 Rule violation ⚙ Maintainability
Description
The new doc comment for ResolvePeersOptions::hoisted_peer_provider_node_ids narrates internal
traversal mechanics and internal state (node_dep_paths) rather than documenting the option’s
contract. This makes the docs fragile to refactors and harder to maintain.
Code

pacquet/crates/resolving-deps-resolver/src/resolve_peers.rs[R141-151]

+    /// `NodeIds` of the peer providers the auto-install-peers loop
+    /// attached to importers' direct dependencies for reuse by other
+    /// subtrees. Each such node keeps its original position inside
+    /// the dependency tree, so the walk resolves its peers there;
+    /// walking it a second time as a root child would bind its peers
+    /// against the importer's own dependencies instead of the
+    /// providers next to it in the tree, and the root-context result
+    /// would overwrite the in-place one in `node_dep_paths`. The walk
+    /// therefore skips these direct entries unless the tree position
+    /// was pruned (an ancestor hit the peers cache) and nothing else
+    /// resolved them.
Evidence
PR Compliance ID 713450 requires doc comments to describe contracts rather than re-describing
implementation. The added documentation contains detailed internal-walk and internal-state
narration, which is implementation-focused.

Rule 713450: Doc comments must describe the function contract, not its implementation
pacquet/crates/resolving-deps-resolver/src/resolve_peers.rs[141-151]

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

## Issue description
The doc comment describes the implementation (walker behavior and internal bookkeeping) instead of the stable contract: what this option *means* and what behavior it guarantees.

## Issue Context
Rust doc comments should describe preconditions/postconditions/purpose and observable behavior, not step-by-step implementation details that will drift.

## Fix Focus Areas
- pacquet/crates/resolving-deps-resolver/src/resolve_peers.rs[141-151]

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



Informational

5. Fixture lockfile mismatch ✓ Resolved 🐞 Bug ⚙ Maintainability ⭐ New
Description
The with-git-protocol-dep lockfile fixture now declares is-number as a direct root dependency
even though the fixture’s package.json does not, so tests starting from this fixture begin from an
inconsistent manifest/lock state and may reconcile/rewrite the lockfile before the intended scenario
runs.
Code

pnpm11/fixtures/with-git-protocol-dep/pnpm-lock.yaml[R14-16]

+      is-number:
+        specifier: ^7.0.0
+        version: 7.0.0
Evidence
The lockfile fixture adds is-number as a root importer dependency, but the fixture manifest does
not declare it; the consuming test reads the manifest and then adds is-number, so starting with it
already in the lockfile reduces determinism and test signal.

pnpm11/fixtures/with-git-protocol-dep/pnpm-lock.yaml[9-17]
pnpm11/fixtures/with-git-protocol-dep/package.json[1-6]
pnpm11/installing/deps-installer/test/install/fromRepo.ts[331-359]

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

### Issue description
`pnpm11/__fixtures__/with-git-protocol-dep/pnpm-lock.yaml` lists `is-number` under the root importer, but `pnpm11/__fixtures__/with-git-protocol-dep/package.json` only declares `is-negative`. This makes the fixture inconsistent and can cause fixture-consuming tests to start by reconciling the lockfile rather than exercising the scenario cleanly.

### Issue Context
This fixture is used by `pnpm11/installing/deps-installer/test/install/fromRepo.ts` (the test reads `package.json`, runs `install()`, then adds `is-number`). Starting with `is-number` already present in the lockfile weakens the test’s intent and can mask lockfile-upgrade/rewrite behavior.

### Fix Focus Areas
- pnpm11/__fixtures__/with-git-protocol-dep/pnpm-lock.yaml[14-16]

### Suggested fix
Remove `is-number` from the fixture lockfile’s root importer (and the corresponding `packages`/`snapshots` entries if they are only present to support that root dep), so the fixture lockfile matches the fixture `package.json` and the test adds `is-number` from a clean baseline.

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


6. HashSet cloned per round 🐞 Bug ➹ Performance
Description
ImporterHoistState::peers_opts() clones hoisted_peer_provider_node_ids every time it is called,
and it is called inside the run_required_round() fixpoint loop. If many providers are attached and
multiple rounds occur, this adds avoidable O(|set|) work on pacquet’s resolver hot path.
Code

pacquet/crates/resolving-deps-resolver/src/resolve_importer.rs[R386-392]

            lockfile_dir: self.lockfile_dir.clone(),
            modules_dir: self.modules_dir.clone(),
            hoist_missing_scope: None,
+            hoisted_peer_provider_node_ids: self.hoisted_peer_provider_node_ids.clone(),
        }
    }
Evidence
peers_opts() performs a full clone of the hoisted-provider set, and the fixpoint loop constructs
options each iteration before calling resolve_peers(), so clone cost scales with (rounds × set
size).

pacquet/crates/resolving-deps-resolver/src/resolve_importer.rs[381-391]
pacquet/crates/resolving-deps-resolver/src/resolve_importer.rs[415-431]

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

### Issue description
`peers_opts()` currently clones `self.hoisted_peer_provider_node_ids` and `run_required_round()` calls `peers_opts()` inside a loop. If the hoisted-provider set grows large, cloning it every iteration is unnecessary overhead.

### Issue Context
This code is in the peer hoist loop and can execute multiple rounds to reach a fixpoint.

### Fix Focus Areas
- pacquet/crates/resolving-deps-resolver/src/resolve_importer.rs[381-431]
- pacquet/crates/resolving-deps-resolver/src/resolve_importer.rs[502-531]

### Suggested fix
Use copy-on-write sharing for the set:
- Change `ImporterHoistState.hoisted_peer_provider_node_ids` to `std::sync::Arc<HashSet<NodeId>>`.
- Update insert sites to use `Arc::make_mut(&mut self.hoisted_peer_provider_node_ids).insert(...)`.
- Change `ResolvePeersOptions.hoisted_peer_provider_node_ids` to `Arc<HashSet<NodeId>>` (or similar), and in `peers_opts()` just `Arc::clone(&self.hoisted_peer_provider_node_ids)`.

This keeps mutation behavior while making per-iteration option construction cheap.

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


Grey Divider

Previous review results

Review updated until commit 3241953

Results up to commit 51dd7f7


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


Remediation recommended
1. Test doc repeats scenario details 📘 Rule violation ⚙ Maintainability
Description
The new Rust test’s doc comment largely restates the same concrete scenario and version details
already encoded in the test body and assertions. This duplicates the test scenario explanation
instead of keeping the comment focused on why the scenario matters.
Code

pacquet/crates/package-manager/src/install/tests.rs[R1723-1735]

+/// Mirror of the TS test "a root dependency does not override the
+/// peers provided inside a self-contained subtree"
+/// (`deps-installer/test/install/autoInstallPeers.ts`).
+///
+/// `@pnpm.e2e/closure-plugins` provides every peer of its own subtree
+/// (`closure-lib-a` and `closure-lib-b` peer-depend on each other and
+/// on `closure-peer-x`, and all three are its regular dependencies).
+/// The root project additionally depends on the incompatible
+/// `[email protected]`. With `autoInstallPeers` (the default), the
+/// peers resolved inside the subtree are attached to the root project
+/// for reuse — but they must not be peer-resolved again in the root
+/// context, where `[email protected]` is the nearest provider, or
+/// the subtree's peer graph gets a mix of both versions.
Evidence
PR Compliance ID 713470 forbids duplicating detailed scenario explanations in test comments when the
test code/assertions already express those specifics. The added doc comment repeats the exact
dependency/version narrative that the test then sets up and asserts on.

Rule 713470: Avoid duplicating test scenario explanations in both code and doc comments
pacquet/crates/package-manager/src/install/tests.rs[1723-1735]

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

## Issue description
The doc comment for the new test repeats detailed scenario mechanics (package relationships and exact versions) that are already represented by the test setup and assertions.

## Issue Context
Compliance requires avoiding duplicative test scenario narration in both comments and tests; comments should add *why* the scenario matters rather than re-listing the same facts the test already encodes.

## Fix Focus Areas
- pacquet/crates/package-manager/src/install/tests.rs[1723-1735]

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


2. hoisted_peer_provider_node_ids docs too detailed 📘 Rule violation ⚙ Maintainability
Description
The new doc comment for ResolvePeersOptions::hoisted_peer_provider_node_ids narrates internal
traversal mechanics and internal state (node_dep_paths) rather than documenting the option’s
contract. This makes the docs fragile to refactors and harder to maintain.
Code

pacquet/crates/resolving-deps-resolver/src/resolve_peers.rs[R141-151]

+    /// `NodeIds` of the peer providers the auto-install-peers loop
+    /// attached to importers' direct dependencies for reuse by other
+    /// subtrees. Each such node keeps its original position inside
+    /// the dependency tree, so the walk resolves its peers there;
+    /// walking it a second time as a root child would bind its peers
+    /// against the importer's own dependencies instead of the
+    /// providers next to it in the tree, and the root-context result
+    /// would overwrite the in-place one in `node_dep_paths`. The walk
+    /// therefore skips these direct entries unless the tree position
+    /// was pruned (an ancestor hit the peers cache) and nothing else
+    /// resolved them.
Evidence
PR Compliance ID 713450 requires doc comments to describe contracts rather than re-describing
implementation. The added documentation contains detailed internal-walk and internal-state
narration, which is implementation-focused.

Rule 713450: Doc comments must describe the function contract, not its implementation
pacquet/crates/resolving-deps-resolver/src/resolve_peers.rs[141-151]

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

## Issue description
The doc comment describes the implementation (walker behavior and internal bookkeeping) instead of the stable contract: what this option *means* and what behavior it guarantees.

## Issue Context
Rust doc comments should describe preconditions/postconditions/purpose and observable behavior, not step-by-step implementation details that will drift.

## Fix Focus Areas
- pacquet/crates/resolving-deps-resolver/src/resolve_peers.rs[141-151]

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


3. Unbatched provider fallback ✓ Resolved 🐞 Bug ➹ Performance
Description
In resolvePeers(), each pruned hoisted peer provider is resolved via a separate
resolvePeersOfChildren() call, repeating per-call setup and cycle-analysis work. With many hoisted
providers pruned by peersCache, this adds avoidable overhead on pnpm’s install hot path.
Code

pnpm11/installing/deps-resolver/src/resolvePeers.ts[R150-171]

+    // Hoisted peer providers stay visible as providers (via pkgsByName) but are
+    // not traversed as direct children: their nodeIds point into subtrees, and
+    // resolving them a second time in the project's root context would bind
+    // their peers to the project's own dependencies instead of the providers
+    // next to them in the tree, racing with the in-place resolution on
+    // pathsByNodeId and producing peer graphs that mix both contexts.
+    const ownDirectChildren: Record<string, NodeId> = {}
+    const hoistedProviderChildren: Record<string, NodeId> = {}
+    for (const [alias, nodeId] of directNodeIdsByAlias.entries()) {
+      if (hoistedPeerProviderNodeIds?.has(nodeId)) {
+        hoistedProviderChildren[alias] = nodeId
+      } else {
+        ownDirectChildren[alias] = nodeId
+      }
+    }
+    const parentPkgsOfNode: ParentPkgsOfNode = new Map()
+    const projectPeersContext = {
      allPeerDepNames: opts.allPeerDepNames,
-      parentPkgsOfNode: new Map(),
+      parentPkgsOfNode,
      dependenciesTree: opts.dependenciesTree,
      depGraph,
      lockfileDir: opts.lockfileDir,
Evidence
The new fallback loop calls resolvePeersOfChildren() once per provider. resolvePeersOfChildren()
performs per-call work including nodeId promise initialization and may run analyzeGraph() for
cycle detection, so repeated calls amplify that cost.

pnpm11/installing/deps-resolver/src/resolvePeers.ts[150-205]
pnpm11/installing/deps-resolver/src/resolvePeers.ts[1014-1116]

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

### Issue description
`resolvePeers()` loops over `hoistedProviderChildren` and calls `resolvePeersOfChildren({ [alias]: nodeId }, ...)` for each pruned provider. Each call does non-trivial per-invocation work (node-id dedupe, deferred promise setup, and potentially `analyzeGraph()`), so doing it N times can be noticeably slower when many providers are pruned.

### Issue Context
This code runs during peer-resolution, which is in pnpm’s install/add/update hot path. The fallback is meant to be rare, but when it triggers it may do repeated work.

### Fix Focus Areas
- pnpm11/installing/deps-resolver/src/resolvePeers.ts[150-205]
- pnpm11/installing/deps-resolver/src/resolvePeers.ts[1014-1116]

### Suggested fix
1. Build a single `unresolvedHoistedProviders` record containing only entries where `!parentPkgsOfNode.has(nodeId)`.
2. If non-empty, call `resolvePeersOfChildren(unresolvedHoistedProviders, pkgsByName, projectPeersContext)` once (instead of once per provider).
3. Push the returned `finishing` once.

This preserves the “only fallback for pruned providers” behavior while reducing repeated traversal overhead.

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



Informational
4. HashSet cloned per round 🐞 Bug ➹ Performance
Description
ImporterHoistState::peers_opts() clones hoisted_peer_provider_node_ids every time it is called,
and it is called inside the run_required_round() fixpoint loop. If many providers are attached and
multiple rounds occur, this adds avoidable O(|set|) work on pacquet’s resolver hot path.
Code

pacquet/crates/resolving-deps-resolver/src/resolve_importer.rs[R386-392]

            lockfile_dir: self.lockfile_dir.clone(),
            modules_dir: self.modules_dir.clone(),
            hoist_missing_scope: None,
+            hoisted_peer_provider_node_ids: self.hoisted_peer_provider_node_ids.clone(),
        }
    }
Evidence
peers_opts() performs a full clone of the hoisted-provider set, and the fixpoint loop constructs
options each iteration before calling resolve_peers(), so clone cost scales with (rounds × set
size).

pacquet/crates/resolving-deps-resolver/src/resolve_importer.rs[381-391]
pacquet/crates/resolving-deps-resolver/src/resolve_importer.rs[415-431]

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

### Issue description
`peers_opts()` currently clones `self.hoisted_peer_provider_node_ids` and `run_required_round()` calls `peers_opts()` inside a loop. If the hoisted-provider set grows large, cloning it every iteration is unnecessary overhead.

### Issue Context
This code is in the peer hoist loop and can execute multiple rounds to reach a fixpoint.

### Fix Focus Areas
- pacquet/crates/resolving-deps-resolver/src/resolve_importer.rs[381-431]
- pacquet/crates/resolving-deps-resolver/src/resolve_importer.rs[502-531]

### Suggested fix
Use copy-on-write sharing for the set:
- Change `ImporterHoistState.hoisted_peer_provider_node_ids` to `std::sync::Arc<HashSet<NodeId>>`.
- Update insert sites to use `Arc::make_mut(&mut self.hoisted_peer_provider_node_ids).insert(...)`.
- Change `ResolvePeersOptions.hoisted_peer_provider_node_ids` to `Arc<HashSet<NodeId>>` (or similar), and in `peers_opts()` just `Arc::clone(&self.hoisted_peer_provider_node_ids)`.

This keeps mutation behavior while making per-iteration option construction cheap.

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


Qodo Logo

@qodo-code-review

qodo-code-review Bot commented Jul 9, 2026 •

Copy link
Copy Markdown

PR Code Suggestions ✨

Latest suggestions up to 3241953

Warning

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

CategorySuggestion                                                                                                                                    Impact
Possible issue
Use per-importer provider tracking

Move the hoisted_peer_provider_node_ids set to ImporterPeerInput instead of
ResolvePeersOptions to track hoisted providers per-importer rather than globally
for the workspace.

pacquet/crates/resolving-deps-resolver/src/resolve_workspace.rs [247-282]

 let mut per_importer_inputs: Vec<ImporterPeerInput> = Vec::with_capacity(importers.len());
-let mut hoisted_peer_provider_node_ids = std::collections::HashSet::new();
 for ((importer, state), (project_dir, modules_dir)) in
     importers.iter().zip(states).zip(input_dirs)
 {
-    let (direct, importer_provider_node_ids) = state.into_direct();
-    hoisted_peer_provider_node_ids.extend(importer_provider_node_ids);
+    let (direct, hoisted_peer_provider_node_ids) = state.into_direct();
     per_importer_inputs.push(ImporterPeerInput {
         id: importer.id.clone(),
         direct,
+        hoisted_peer_provider_node_ids,
         root_dir: project_dir,
         modules_dir,
     });
 }
 ...
-    hoisted_peer_provider_node_ids,
+    hoisted_peer_provider_node_ids: std::collections::HashSet::new(),

[To ensure code accuracy, apply this suggestion manually]

Suggestion importance[1-10]: 9

__

Why: Using a global set for hoisted peer providers risks causing one workspace importer to incorrectly treat its normal direct dependency as a hoisted provider if it shares a NodeId with another importer's hoisted provider.

High
  • More

Previous suggestions

Suggestions up to commit ebf9261
CategorySuggestion                                                                                                                                    Impact
Possible issue
Scope provider skipping per importer

Scope hoisted_peer_provider_node_ids per importer instead of globally.

pacquet/crates/resolving-deps-resolver/src/resolve_peers.rs [348-351]

 let (own_direct, provider_direct): (Vec<&DirectDep>, Vec<&DirectDep>) = importer
     .direct
     .iter()
-    .partition(|dep| !walker.opts.hoisted_peer_provider_node_ids.contains(&dep.node_id));
+    .partition(|dep| !importer.hoisted_peer_provider_node_ids.contains(&dep.node_id));
Suggestion importance[1-10]: 10

__

Why: The suggestion catches a major bug where NodeId::Leaf reuse combined with a workspace-global hoisted_peer_provider_node_ids set causes legitimate direct dependencies in other importers to be incorrectly pruned.

High
Preserve importer-local provider ownership

Store hoisted_peer_provider_node_ids individually in each ImporterPeerInput
rather than aggregating them into a single global set.

pacquet/crates/resolving-deps-resolver/src/resolve_workspace.rs [247-260]

 let mut per_importer_inputs: Vec<ImporterPeerInput> = Vec::with_capacity(importers.len());
-let mut hoisted_peer_provider_node_ids = std::collections::HashSet::new();
 for ((importer, state), (project_dir, modules_dir)) in
     importers.iter().zip(states).zip(input_dirs)
 {
-    let (direct, importer_provider_node_ids) = state.into_direct();
-    hoisted_peer_provider_node_ids.extend(importer_provider_node_ids);
+    let (direct, hoisted_peer_provider_node_ids) = state.into_direct();
     per_importer_inputs.push(ImporterPeerInput {
         id: importer.id.clone(),
         direct,
+        hoisted_peer_provider_node_ids,
         root_dir: project_dir,
         modules_dir,
     });
 }
Suggestion importance[1-10]: 10

__

Why: This correctly prevents aggregating hoisted_peer_provider_node_ids across importers, fixing a logic bug where a hoisted dependency in one importer affects direct dependency resolution in another due to NodeId reuse.

High
Suggestions up to commit 0b3d834
CategorySuggestion                                                                                                                                    Impact
Possible issue
Use per-importer provider sets

Use a per-importer set of hoisted_peer_provider_node_ids instead of a
workspace-wide set to partition direct dependencies. Thread the provider set
through ImporterPeerInput to prevent breaking genuine direct dependencies across
different workspace packages.

pacquet/crates/resolving-deps-resolver/src/resolve_peers.rs [348-351]

 let (own_direct, provider_direct): (Vec<&DirectDep>, Vec<&DirectDep>) = importer
     .direct
     .iter()
-    .partition(|dep| !walker.opts.hoisted_peer_provider_node_ids.contains(&dep.node_id));
+    .partition(|dep| !importer.hoisted_peer_provider_node_ids.contains(&dep.node_id));
Suggestion importance[1-10]: 10

__

Why: Using a globally combined set of hoisted_peer_provider_node_ids in a workspace correctly identifies providers for one importer but inadvertently skips genuine direct dependencies for others due to shared NodeId::Leaf values, causing incorrect peer resolution for multi-package workspaces.

High
Suggestions up to commit 3ccc80f
CategorySuggestion                                                                                                                                    Impact
Possible issue
Scope provider skipping per importer

Move hoisted_peer_provider_node_ids to ImporterPeerInput instead of a global
option. This scopes the skipped provider nodes to their respective importer and
avoids cross-importer leakage.

pacquet/crates/resolving-deps-resolver/src/resolve_peers.rs [228-351]

 pub struct ImporterPeerInput {
     ...
+    pub hoisted_peer_provider_node_ids: HashSet<NodeId>,
 }
 
 ...
 
 let (own_direct, provider_direct): (Vec<&DirectDep>, Vec<&DirectDep>) = importer
     .direct
     .iter()
-    .partition(|dep| !walker.opts.hoisted_peer_provider_node_ids.contains(&dep.node_id));
+    .partition(|dep| !importer.hoisted_peer_provider_node_ids.contains(&dep.node_id));
Suggestion importance[1-10]: 9

__

Why: Moving hoisted_peer_provider_node_ids to ImporterPeerInput prevents a critical bug where shared NodeId::Leaf instances could incorrectly skip direct dependencies across different workspace importers.

High
Avoid cross-importer provider leakage

Assign each importer's hoisted_peer_provider_node_ids directly to its own
ImporterPeerInput rather than aggregating them in a global set.

pacquet/crates/resolving-deps-resolver/src/resolve_workspace.rs [247-260]

 let mut per_importer_inputs: Vec<ImporterPeerInput> = Vec::with_capacity(importers.len());
-let mut hoisted_peer_provider_node_ids = std::collections::HashSet::new();
 for ((importer, state), (project_dir, modules_dir)) in
     importers.iter().zip(states).zip(input_dirs)
 {
-    let (direct, importer_provider_node_ids) = state.into_direct();
-    hoisted_peer_provider_node_ids.extend(importer_provider_node_ids);
+    let (direct, hoisted_peer_provider_node_ids) = state.into_direct();
     per_importer_inputs.push(ImporterPeerInput {
         id: importer.id.clone(),
         direct,
         root_dir: project_dir,
         modules_dir,
+        hoisted_peer_provider_node_ids,
     });
 }
Suggestion importance[1-10]: 9

__

Why: This aligns with scoping provider tracking per importer, ensuring that reused NodeId instances in the workspace don't cause other importers to incorrectly treat their standard dependencies as hoisted providers.

High
Suggestions up to commit 51dd7f7
CategorySuggestion                                                                                                                                    Impact
Possible issue
Scope provider skips per importer

Store the hoisted_peer_provider_node_ids set per importer rather than globally.
This prevents NodeId::Leaf reuse from incorrectly skipping real direct
dependencies in other importers.

pacquet/crates/resolving-deps-resolver/src/resolve_workspace.rs [247-260]

 let mut per_importer_inputs: Vec<ImporterPeerInput> = Vec::with_capacity(importers.len());
-let mut hoisted_peer_provider_node_ids = std::collections::HashSet::new();
 for ((importer, state), (project_dir, modules_dir)) in
     importers.iter().zip(states).zip(input_dirs)
 {
-    let (direct, importer_provider_node_ids) = state.into_direct();
-    hoisted_peer_provider_node_ids.extend(importer_provider_node_ids);
+    let (direct, hoisted_peer_provider_node_ids) = state.into_direct();
     per_importer_inputs.push(ImporterPeerInput {
         id: importer.id.clone(),
         direct,
+        hoisted_peer_provider_node_ids,
         root_dir: project_dir,
         modules_dir,
     });
 }
Suggestion importance[1-10]: 9

__

Why: This correctly identifies a crucial bug where global aggregation of NodeId::Leaf values causes cross-importer poisoning, leading real direct dependencies to be incorrectly processed as hoisted providers (though ImporterPeerInput struct itself will also need to be updated to support the new field).

High
Prevent duplicate fallback resolution

Add a check for pathsByNodeId.has(nodeId) before running fallback resolution for
hoisted providers. This prevents re-resolving a node already processed by
another importer or cache hit.

pnpm11/installing/deps-resolver/src/resolvePeers.ts [198-205]

 for (const [alias, nodeId] of Object.entries(hoistedProviderChildren)) {
-  if (parentPkgsOfNode.has(nodeId)) continue
+  if (pathsByNodeId.has(nodeId) || parentPkgsOfNode.has(nodeId)) continue
   // eslint-disable-next-line no-await-in-loop
   const { finishing } = await resolvePeersOfChildren({ [alias]: nodeId }, pkgsByName, projectPeersContext)
   if (finishing) {
     finishingList.push(finishing)
   }
 }
Suggestion importance[1-10]: 9

__

Why: This catches a missing safeguard in the TypeScript implementation that was correctly added in the Rust counterpart, preventing duplicate resolutions from incorrectly overwriting shared workspace graphs.

High

Each resolvePeersOfChildren call only detects peer cycles among its own
children. The root-context fallback resolved every pruned hoisted peer
provider in its own call, so two pruned providers that peer-depend on
each other (the usual shape of a self-contained closure) left their dep
path calculations awaiting each other forever and the install hung.
Resolving all still-pruned providers in one call restores the cycle
short-circuit.

Pacquet's sequential walker already handles this shape — build_peer_id
falls back to a provisional name@version id and the SCC finalization
pass corrects the suffixes — so it needs no code change and only gains
the mirrored regression tests proving both stacks emit identical dep
paths. The TS side also gains a unit test mirroring pacquet's
single-pruned-provider fallback coverage.

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

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.

The identifiers liba and libb fail the repository spellcheck; the
hyphenated names also match the closure-lib-a fixture naming the rest
of the PR uses.

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

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 0b3d834

…ts manifest

The pruned-provider rename commit accidentally carried a regenerated
lockfile for this fixture that lists is-number, which the fixture's
package.json does not declare. prepare-fixtures installs every fixture
with a frozen lockfile, so all CI test jobs failed before running any
tests.

Co-Authored-By: Claude Fable 5 <[email protected]>
Copilot AI review requested due to automatic review settings July 9, 2026 17:11

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.

A local install over the fixtures workspace reformatted seven fixture
lockfiles that are unrelated to this PR; restore them to their previous
committed state.

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

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

@zkochan
zkochan merged commit fecfe83 into pnpm:main Jul 9, 2026
33 of 34 checks passed
spencerbeggs added a commit to spencerbeggs/pnpm that referenced this pull request Jul 11, 2026
When deduplicating a missing peer onto the workspace's preferred
versions, hoistPeers matched candidates against '*' unless the wanted
range was an exact version. In a multi-importer workspace,
allPreferredVersions aggregates versions from every importer, so a peer
declared as ^1.0.0 inside one importer's closure could be auto-installed
as a 2.x resolved for another importer, silently producing a peer graph
that mixes incompatible majors. This survived pnpm#12847 (which
fixed the single-importer case in resolvePeers) and is independent of
the pnpm#12921 deadlock fix: the wrong version is chosen upstream
of peer resolution, during peer hoisting.

Both stacks now dedupe onto the highest preferred version that
satisfies the wanted range and fall back to resolving the range from
the registry when no candidate satisfies it. Non-semver specifiers
(workspace:, npm: aliases, dist-tags) keep the dedupe-to-highest
behavior.

Fixing this exposed a pacquet-only divergence the old behavior masked:
resolve_peers indexed a node's children into ParentRefs only by their
install alias, so an npm-alias child could never provide a peer under
its real package name below the importer level, and the binding fell
through to the importer-level hoisted entry. Descent-time children are
now indexed by both alias and real name, matching resolvePeers.ts.

Measured on the multi-importer reproduction: 46 poisoned snapshots on
pnpm 11.11.0, 0 with this change, in both the TypeScript CLI and
pacquet.

Signed-off-by: C. Spencer Beggs <[email protected]>
zkochan pushed a commit to spencerbeggs/pnpm that referenced this pull request Jul 11, 2026
When deduplicating a missing peer onto the workspace's preferred
versions, hoistPeers matched candidates against '*' unless the wanted
range was an exact version. In a multi-importer workspace,
allPreferredVersions aggregates versions from every importer, so a peer
declared as ^1.0.0 inside one importer's closure could be auto-installed
as a 2.x resolved for another importer, silently producing a peer graph
that mixes incompatible majors. This survived pnpm#12847 (which
fixed the single-importer case in resolvePeers) and is independent of
the pnpm#12921 deadlock fix: the wrong version is chosen upstream
of peer resolution, during peer hoisting.

Both stacks now dedupe onto the highest preferred version that
satisfies the wanted range and fall back to resolving the range from
the registry when no candidate satisfies it. Non-semver specifiers
(workspace:, npm: aliases, dist-tags) keep the dedupe-to-highest
behavior.

Fixing this exposed a pacquet-only divergence the old behavior masked:
resolve_peers indexed a node's children into ParentRefs only by their
install alias, so an npm-alias child could never provide a peer under
its real package name below the importer level, and the binding fell
through to the importer-level hoisted entry. Descent-time children are
now indexed by both alias and real name, matching resolvePeers.ts.

Measured on the multi-importer reproduction: 46 poisoned snapshots on
pnpm 11.11.0, 0 with this change, in both the TypeScript CLI and
pacquet.

Signed-off-by: C. Spencer Beggs <[email protected]>
zkochan added a commit that referenced this pull request Jul 11, 2026
…ge (#12932)

When deduplicating a missing peer onto the workspace's preferred
versions, hoistPeers matched candidates against '*' unless the wanted
range was an exact version. In a multi-importer workspace,
allPreferredVersions aggregates versions from every importer, so a peer
declared as ^1.0.0 inside one importer's closure could be auto-installed
as a 2.x resolved for another importer, silently producing a peer graph
that mixes incompatible majors. This survived #12847 (which
fixed the single-importer case in resolvePeers) and is independent of
the #12921 deadlock fix: the wrong version is chosen upstream
of peer resolution, during peer hoisting.

Both stacks now dedupe onto the highest preferred version that
satisfies the wanted range and fall back to resolving the range from
the registry when no candidate satisfies it. Non-semver specifiers
(workspace:, npm: aliases, dist-tags) keep the dedupe-to-highest
behavior.

Fixing this exposed a pacquet-only divergence the old behavior masked:
resolve_peers indexed a node's children into ParentRefs only by their
install alias, so an npm-alias child could never provide a peer under
its real package name below the importer level, and the binding fell
through to the importer-level hoisted entry. Descent-time children are
now indexed by both alias and real name, matching resolvePeers.ts.

Measured on the multi-importer reproduction: 46 poisoned snapshots on
pnpm 11.11.0, 0 with this change, in both the TypeScript CLI and
pacquet.

Additionally, hoistPeers now binds the same peer on a re-resolve with
an existing lockfile as on a fresh install of the same manifest: root
dependencies reused from the lockfile skip full resolution and were
invisible to the workspace-root branch of the hoist, so the picked
version depended on whether a lockfile was present. The root-dep table
falls back to the importer's wanted specifiers, and its entry type is
narrowed to HoistableRootDep — the fields hoistPeers reads, matching
the Rust port's WorkspaceRootDep.

Related to #12847 and #12921.

---------

Signed-off-by: C. Spencer Beggs <[email protected]>
Co-authored-by: Zoltan Kochan <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

auto-install-peers picks incorrect dependency version

4 participants