Skip to content

fix(deps-resolver): let a hoisted required peer follow its provider - #16474

Merged
zkochan merged 7 commits into
pnpm:mainfrom
officialaritro:fix/required-peer-follows-provider
Oct 4, 2026
Merged

zkochan merged 7 commits into
pnpm:mainfrom
officialaritro:fix/required-peer-follows-provider

Conversation

@officialaritro

@officialaritro officialaritro commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

When a dependency moves an exact dependency of its own to an older version, a required peer that auto-install-peers hoisted now moves with it, in both pnpm v11 and pnpm v12. Before, pnpm kept the newer locked version, so the lockfile held two copies of the peer.

Closes pnpm/tasks#61

Cause

The required-peer hoist picked the highest preferred version that satisfied the peer range. The preferred versions include the versions seeded from the wanted lockfile. With the repro from pnpm/tasks#61, after provider moves vue from 3.5.43 to 3.5.40, the hoist sees both versions and picks 3.5.43:

  • v12, hoisted_specifier in pnpm/crates/resolving-deps-resolver/src/hoist_peers.rs: candidates ["3.5.40", "3.5.43"], picked 3.5.43.
  • v11, hoistPeers in pnpm11/installing/deps-resolver/src/hoistPeers.ts: {"3.5.43":{"selectorType":"version","weight":1000000},"3.5.40":"version"}, picked 3.5.43.

3.5.40 is the version this run resolves through provider. 3.5.43 exists only as a lockfile weight. The upgrade direction converged only because the new version was also the highest. pnpm update converged because an update target drops the lockfile pins.

Fix

The required-peer hoist now takes the highest satisfying version that this run resolved. When none of those satisfies the range, it falls back to every preferred version, as before.

  • v12: HoistPeersOptions gets resolved_versions, filled by the new TreeCtx::run_resolved_versions in hoist_missing_required. optional_peer_version_tiers now uses the same method, so the lookup stays in one place.
  • v11: resolving a version records it as a plain selector, so a version that only the lockfile pins stays weighted. getLockfileOnlyVersions records those weighted versions once, after every importer's direct dependencies resolved and before any importer hoists, and maxSatisfyingDemotingLockfileOnly in hoistPeers.ts picks one of them only when no other version satisfies the range. Importers hoist concurrently and keep adding plain selectors, so reading the live selectors would make the pick depend on which importer finishes first. pnpm v12 avoids the same problem by deriving its run-resolved versions from the settled tree. Without auto-install-peers there are no lockfile seeds, so nothing changes there. An update target already drops the lockfile pins, so it is unchanged.

Only the reported case changes. A peer that nothing else resolves keeps its locked version, so a repeat install does not move it. In the claim on pnpm/tasks#61 I proposed the three tiers that #16445 uses for optional peers. I narrowed the fix to this rule because the tiers also kept a lower locked version over a higher version the run resolved, which changes a case nobody reported. They would also need v11 to parse the importer's peer suffixes. Both CLIs already record "resolved this run", so they now pick the same version.

Results with the repro from pnpm/tasks#61 (v12)

Build @vue/test-utils peers after vue 3.5.43 → 3.5.40 Copies in the lockfile
main (351377b) (@vue/[email protected])(@vue/[email protected])([email protected]) vue 3.5.40 and 3.5.43, @vue/server-renderer 3.5.40 and 3.5.43
this PR (@vue/[email protected])(@vue/[email protected])([email protected]) one vue, one @vue/server-renderer

With this PR, the upgrade direction still converges, a repeat install leaves the lockfile byte-identical, and pnpm dedupe keeps the single copy.

Tests

  • v12 CLI: optional_peer_pins takes the host package as a parameter, and runs the optional cases and two new required cases with @pnpm.e2e/wants-peer-c-1. On main, required_peer_follows_its_provider_down_to_an_older_version fails with left: ["@pnpm.e2e/[email protected](@pnpm.e2e/[email protected])"], right: ["@pnpm.e2e/[email protected](@pnpm.e2e/[email protected])"]. Each case also checks that a repeat install leaves the lockfile unchanged.
  • v12 unit: 3 tests in hoist_peers/tests.rs. A run-resolved version beats a higher lockfile-only one, the highest run-resolved version wins, and the pick falls back when no run-resolved version satisfies the range. With the preference removed, the first 2 fail. With the fallback removed, the 3rd fails.
  • v11 integration: an automatically installed peer dependency follows its provider down to an older version in deps-installer/test/install/autoInstallPeers.ts, with the same fixtures. Without the fix it fails with Expected: "1.0.0(@pnpm.e2e/[email protected])", Received: "1.0.0(@pnpm.e2e/[email protected])".
  • v11 unit: the same 3 cases in deps-resolver/test/hoistPeers.test.ts, plus one that keeps demoting a lockfile-only version that another importer resolves while peers are hoisted. With the lockfile-only set ignored, the 2 preference tests and that one fail.

Local runs

  • v12: pnpm-resolving-deps-resolver (429 passed), pnpm test:rust-affected --no-fail-fast (5398 of 5399 passed). The one failure was cli_args::global::activation::tests::rollback::rollback_continues_after_bin_removal_failure, killed by SIGKILL after 7 ms. That module passes 3 of 3 times on its own, and this PR does not touch pnpm/crates/cli/src. A different test in the same module was killed the same way in an earlier full run. The formatter, workspace clippy, rustdoc, dylint on the changed crates, and typos pass.
  • v11: @pnpm/installing.deps-resolver (219 passed, compile and lint included), and 13 deps-installer install suites on peers, dedupe, update and lockfiles (213 passed, 1 skipped).
  • The pre-push hook passed in full.

Squash Commit Body

The required-peer hoist took the highest preferred version that
satisfied the peer range. The preferred versions include the versions
seeded from the wanted lockfile, so after a provider such as `vue`
moved its exact dependency from 3.5.43 to 3.5.40, the hoisted `vue`
peer of `@vue/test-utils` stayed on 3.5.43 and the lockfile kept two
copies. `pnpm dedupe` took the same path. The upgrade direction
converged only because the new version was also the highest.

Both CLIs now take the highest satisfying version that this run
resolved, and fall back to every preferred version when none of those
satisfies the range. A peer that nothing else resolves keeps its
locked version, so a repeat install does not move it.

In v12, `HoistPeersOptions` gets `resolved_versions` from the new
`TreeCtx::run_resolved_versions`, which the optional-peer tiers now use
as well. It is derived from the settled tree, so concurrent importers
do not change it. In v11, a lockfile-only version is a weighted
selector. `getLockfileOnlyVersions` records those once, before any
importer hoists, because importers hoist concurrently and keep adding
plain selectors. The pick demotes exactly those versions. An update
target already drops the lockfile pins and is unchanged.

The three tiers that pnpm/pnpm#16445 uses for optional peers would also
have kept a lower locked version over a higher version the run
resolved, which changes a case nobody reported, and v11 could not
reproduce them without parsing the importer's peer suffixes.

Closes pnpm/tasks#61

Checklist

  • I checked the referenced issue and verified that none of the PRs
    already linked to it solves it.
  • New features are implemented only in the Rust pnpm v12 CLI. Bug fixes
    are implemented in every affected version.
  • Added a changeset (pnpm changeset) if this PR changes any published
    package. Keep it short and written for pnpm users — it becomes a release note.
  • Added or updated tests.

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

Summary by CodeRabbit

  • Bug Fixes
    • Automatically installed peer dependencies now follow provider version changes in both upgrade and downgrade scenarios, including local file-based providers.
    • When multiple versions satisfy a peer dependency’s range, installation now prefers the highest version resolved in the current run. If none qualifies, it uses the highest satisfying preferred version.
    • Repeated lockfile-only installs leave the lockfile unchanged when peer resolutions are up to date.
    • Downgrading a provider no longer leaves an automatically installed peer dependency locked to a newer version.

@coderabbitai

coderabbitai Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

⚙️ Run configuration
  • Configuration used: Repository: pnpm/pnpm/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1b089c1d-5a3d-4f05-bf77-4451440bf5b5
📥 Commits

Reviewing files that changed from the base of the PR and between 042a806 and 02d736e.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: pnpm/pnpm/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: e7af393c-2797-4ed2-a45e-58aede90cfdd

📥 Commits

Reviewing files that changed from the base of the PR and between b52f25e and 042a806.

📒 Files selected for processing (3)
  • pnpm11/installing/deps-resolver/src/hoistPeers.ts
  • pnpm11/installing/deps-resolver/src/resolveRootDependencies.ts
  • pnpm11/installing/deps-resolver/test/hoistPeers.test.ts

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


📝 Walkthrough

Walkthrough

The Rust and TypeScript dependency resolvers now prefer satisfying peer versions resolved during the current run over stale lockfile candidates. Tests cover required and optional peers, provider upgrades and downgrades, fallback selection, and lockfile stability.

Changes

Peer version selection

Layer / File(s) Summary
Rust resolver selection and regression coverage
pnpm/crates/resolving-deps-resolver/src/hoist_peers.rs, pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/tree_ctx.rs, pnpm/crates/resolving-deps-resolver/src/resolve_importer/hoist_rounds.rs, pnpm/crates/resolving-deps-resolver/src/hoist_peers/tests.rs, pnpm/crates/cli/tests/suite/optional_peer_pins.rs
The resolver passes current-run peer versions into hoisting and prefers a satisfying version resolved in that run. Tests cover required and optional peer hosts, provider upgrades and downgrades, and fallback selection.
TypeScript resolver selection and regression coverage
pnpm11/installing/deps-resolver/src/hoistPeers.ts, pnpm11/installing/deps-resolver/src/resolveRootDependencies.ts, pnpm11/installing/deps-resolver/test/hoistPeers.test.ts, pnpm11/installing/deps-installer/test/install/autoInstallPeers.ts, .changeset/required-peer-follows-its-provider.md
The resolver identifies lockfile-only peer versions and prefers other satisfying versions, with fallback when needed. Tests cover version selection and fallback, plus a local-provider downgrade and lockfile stability. The Changeset records patch releases.

Priority: ➖ Normal

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

Change: Bug fix · Severity of issue fixed: Medium

Assessment against linked issues

Objective Addressed Explanation
[#61] Update an auto-installed required peer after its provider moves to an older exact version, in both CLIs. ✅

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

Merge Risk: ⚪ Minimal · up to 042a8

The resolvers prefer satisfying current-install peer versions while preserving fallback selection. No actionable merge-blocking issue remains; merge after normal checks pass.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 042a8

The change prioritizes compatible versions already resolved during installation without removing existing selection controls. No new security issue was established, but failure recovery and downstream installation behavior were not fully validated.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The demonstrated effect is a different compatible peer version entering the affected project or workspace dependency graph. The inspected selector changes do not themselves add package-fetching authority or credential access; downstream package execution was not evaluated.

Trust Boundaries and Controls

  • observed — Dependency-provided peer ranges and preferred selectors still pass through existing override and workspace-root precedence before the changed ranking step. Semver satisfaction and auto-install fallback remain enforced; TypeScript update targets still omit lockfile pins before ranking. These controls predate this PR.

Resilience and Maintainability Implications

  • inferred — The new TypeScript provenance map belongs to one peer-hoisting invocation and is reconstructed on normal re-entry. Later selector mutations cannot alter its copied Sets. This limits stale auxiliary-state exposure after failure, but does not establish atomic lockfile writes or safe reuse of partially mutated importer results.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


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.

@codecov-commenter

codecov-commenter commented Oct 1, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.30%. Comparing base (5dbff2e) to head (02d736e).

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #16474   +/-   ##
=======================================
  Coverage   92.29%   92.30%           
=======================================
  Files        1564     1564           
  Lines      207703   207731   +28     
=======================================
+ Hits       191702   191736   +34     
+ Misses      16001    15995    -6     

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

@github-actions

github-actions Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Same-run regression check

HEAD and main are measured on the same runner. The tolerance is 5% of the main median or 2 ms, whichever is larger. A regression requires both the median slowdown and the gap between the fastest retained HEAD sample and slowest retained main sample to exceed this tolerance, after trimming up to 10% from each tail. Suspected regressions are rerun once with target order reversed and only fail if reproduced. This conservative noise guard is not a statistical confidence interval.

Inconclusive rows do not fail the check. They remain visible for performance review. Bencher retains absolute minimum timings for historical tracking; historical alerts do not gate this PR. Sequential measurements can still be affected by runner drift.

Scenario Engine main median HEAD median Change Tolerance Result
isolated-fresh-restore-cold-cache-cold-store pacquet 2346.72 ms 2316.26 ms -1.3% 117.34 ms Within tolerance
isolated-fresh-restore-cold-cache-cold-store pnpr 1368.91 ms 1374.58 ms 0.4% 68.45 ms Within tolerance
isolated-fresh-restore-hot-cache-hot-store pacquet 233.83 ms 238.64 ms 2.1% 11.69 ms Within tolerance
isolated-fresh-restore-hot-cache-hot-store pnpr 256.94 ms 265.26 ms 3.2% 12.85 ms Within tolerance
isolated-repeat-install-hot-cache-hot-store pacquet 13.26 ms 11.94 ms -10.0% 2.00 ms Within tolerance
isolated-repeat-install-hot-cache-hot-store pnpr 7.52 ms 7.27 ms -3.3% 2.00 ms Within tolerance
isolated-repeat-install-cold-cache-hot-store pacquet 9.26 ms 8.91 ms -3.7% 2.00 ms Within tolerance
isolated-repeat-install-cold-cache-hot-store pnpr 9.57 ms 9.44 ms -1.4% 2.00 ms Within tolerance
isolated-fresh-install-cold-cache-cold-store pacquet 2550.74 ms 2544.76 ms -0.2% 127.54 ms Within tolerance
isolated-fresh-install-cold-cache-cold-store pnpr 1460.56 ms 1585.47 ms 8.6% 73.03 ms Inconclusive (overlapping samples)
isolated-fresh-install-hot-cache-hot-store pacquet 438.53 ms 456.58 ms 4.1% 21.93 ms Within tolerance
isolated-fresh-install-hot-cache-hot-store pnpr 292.63 ms 292.73 ms 0.0% 14.63 ms Within tolerance
isolated-fresh-install-cold-cache-hot-store pacquet 1653.26 ms 1647.60 ms -0.3% 82.66 ms Within tolerance
isolated-fresh-install-cold-cache-hot-store pnpr 351.95 ms 338.71 ms -3.8% 17.60 ms Within tolerance
isolated-fresh-resolve-hot-cache-offline pacquet 272.07 ms 273.40 ms 0.5% 13.60 ms Within tolerance
isolated-fresh-resolve-hot-cache-offline pnpr 93.98 ms 95.25 ms 1.4% 4.70 ms Within tolerance
isolated-peer-heavy-resolve-hot-cache-offline pacquet 215.01 ms 210.14 ms -2.3% 10.75 ms Within tolerance
isolated-linked-workspace-resolve-hot-cache-offline pacquet 300.69 ms 302.72 ms 0.7% 15.03 ms Within tolerance
isolated-fresh-restore-cold-cache-cold-store-cold-pnpr pacquet 4432.76 ms 4519.77 ms 2.0% 221.64 ms Within tolerance
isolated-fresh-restore-cold-cache-cold-store-cold-pnpr pnpr 3453.72 ms 3485.76 ms 0.9% 172.69 ms Within tolerance
gvs-fresh-restore-hot-cache-hot-store pacquet 113.57 ms 112.57 ms -0.9% 5.68 ms Within tolerance
gvs-fresh-restore-hot-cache-hot-store pnpr 125.75 ms 128.13 ms 1.9% 6.29 ms Within tolerance

Integrated-Benchmark Report (Linux)

Commit: 02d736e20313

Regular scenarios report direct and pnpr installs. The peer-heavy resolver scenario compares current Rust, main Rust, and TypeScript pnpm; the linked-workspace scenario compares current Rust against main Rust. Bencher consumes pacquet@HEAD and pnpr@HEAD.

The tables below show mean ± σ. Bencher tracks absolute minimum latency; PR regression checks compare HEAD and main samples from the same runner. Historical timing alerts do not gate PRs.

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 2.376 ± 0.118 2.256 2.556 1.70 ± 0.15
pacquet@main 2.411 ± 0.160 2.233 2.620 1.72 ± 0.17
pnpr@HEAD 1.427 ± 0.145 1.296 1.678 1.02 ± 0.13
pnpr@main 1.400 ± 0.099 1.292 1.562 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 2.37575825592,
      "stddev": 0.11764682256962279,
      "median": 2.31625878992,
      "user": 1.28362606,
      "system": 1.30467164,
      "min": 2.25561224092,
      "max": 2.55559005992
    },
    {
      "command": "pacquet@main",
      "mean": 2.41110726032,
      "stddev": 0.15963615813638182,
      "median": 2.3467237769200002,
      "user": 1.22046966,
      "system": 1.27847134,
      "min": 2.23347998792,
      "max": 2.62042364392
    },
    {
      "command": "pnpr@HEAD",
      "mean": 1.42664477492,
      "stddev": 0.14492213395035547,
      "median": 1.3745789894200002,
      "user": 1.17859006,
      "system": 1.20832604,
      "min": 1.2963659979200002,
      "max": 1.67841815992
    },
    {
      "command": "pnpr@main",
      "mean": 1.3999693476200004,
      "stddev": 0.09922006676937313,
      "median": 1.36890964892,
      "user": 1.1498712599999998,
      "system": 1.24879804,
      "min": 1.2922842139200001,
      "max": 1.5620121419200002
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 240.9 ± 11.6 225.3 262.0 1.02 ± 0.08
pacquet@main 235.3 ± 14.8 215.6 266.9 1.00
pnpr@HEAD 266.5 ± 4.9 259.1 277.0 1.13 ± 0.07
pnpr@main 257.6 ± 7.5 248.0 272.4 1.10 ± 0.08
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.24087088996,
      "stddev": 0.011606458864485771,
      "median": 0.23864282326000003,
      "user": 0.2642474,
      "system": 0.5853220199999999,
      "min": 0.22534544526000003,
      "max": 0.26200024826
    },
    {
      "command": "pacquet@main",
      "mean": 0.23527098566,
      "stddev": 0.0148311454847877,
      "median": 0.23383247626000003,
      "user": 0.26463129999999996,
      "system": 0.5754362199999998,
      "min": 0.21561609826000003,
      "max": 0.26691596226000003
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.26646652106,
      "stddev": 0.004948947963364755,
      "median": 0.26526259776000005,
      "user": 0.28151329999999997,
      "system": 0.6276390199999999,
      "min": 0.25912060026,
      "max": 0.27698998526
    },
    {
      "command": "pnpr@main",
      "mean": 0.25763094176,
      "stddev": 0.007463726140712534,
      "median": 0.25693727826,
      "user": 0.2876691,
      "system": 0.56028242,
      "min": 0.24797143326,
      "max": 0.27235121126
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 11.5 ± 3.7 6.8 20.2 1.57 ± 0.51
pacquet@main 13.1 ± 2.6 7.1 18.7 1.80 ± 0.37
pnpr@HEAD 7.3 ± 0.4 6.6 9.9 1.00
pnpr@main 7.7 ± 0.5 6.8 10.7 1.05 ± 0.09
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.011466051492750805,
      "stddev": 0.0036802902139899795,
      "median": 0.011936610140000001,
      "user": 0.006812732556634303,
      "system": 0.0056499295792880235,
      "min": 0.006841433140000001,
      "max": 0.02015823114
    },
    {
      "command": "pacquet@main",
      "mean": 0.013114063866315794,
      "stddev": 0.0026221360787388186,
      "median": 0.013258825640000001,
      "user": 0.007126834736842101,
      "system": 0.0071030861052631565,
      "min": 0.007068248140000001,
      "max": 0.01874309214
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.007299355955873016,
      "stddev": 0.0003774129463998731,
      "median": 0.007267991140000001,
      "user": 0.0043716653968253975,
      "system": 0.0035459406984126984,
      "min": 0.006604910140000001,
      "max": 0.00985242914
    },
    {
      "command": "pnpr@main",
      "mean": 0.00765078847240223,
      "stddev": 0.0005298648977485407,
      "median": 0.00751716364,
      "user": 0.004766855642458098,
      "system": 0.0036181448044692757,
      "min": 0.006788535140000001,
      "max": 0.010663257140000002
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 9.1 ± 0.7 7.6 12.4 1.00
pacquet@main 9.4 ± 0.9 7.7 12.3 1.04 ± 0.12
pnpr@HEAD 9.6 ± 0.7 8.3 11.8 1.06 ± 0.11
pnpr@main 9.6 ± 0.7 8.1 12.2 1.06 ± 0.11
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.009064940503629342,
      "stddev": 0.0006783089534351958,
      "median": 0.00891263116,
      "user": 0.005084947027027026,
      "system": 0.004765130038610041,
      "min": 0.00764262716,
      "max": 0.012420657160000001
    },
    {
      "command": "pacquet@main",
      "mean": 0.009400464273636364,
      "stddev": 0.0008696413200359565,
      "median": 0.00925691766,
      "user": 0.005439446818181819,
      "system": 0.004749417878787878,
      "min": 0.007662574160000001,
      "max": 0.012306443160000001
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.009563589663875969,
      "stddev": 0.0007143825979302888,
      "median": 0.00943637466,
      "user": 0.00544457891472868,
      "system": 0.005024422790697676,
      "min": 0.00827577616,
      "max": 0.01175943716
    },
    {
      "command": "pnpr@main",
      "mean": 0.009639297794980989,
      "stddev": 0.0007061174267068386,
      "median": 0.00956641916,
      "user": 0.005810965627376429,
      "system": 0.004692373992395438,
      "min": 0.00809290216,
      "max": 0.01216012916
    }
  ]
}

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 2.575 ± 0.094 2.502 2.824 1.72 ± 0.11
pacquet@main 2.562 ± 0.043 2.527 2.679 1.72 ± 0.09
pnpr@HEAD 1.615 ± 0.139 1.459 1.824 1.08 ± 0.11
pnpr@main 1.493 ± 0.074 1.411 1.635 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 2.5745409388800002,
      "stddev": 0.09438480195107518,
      "median": 2.54475947068,
      "user": 2.07692772,
      "system": 1.7038193000000004,
      "min": 2.50244146668,
      "max": 2.82408435668
    },
    {
      "command": "pacquet@main",
      "mean": 2.56154236428,
      "stddev": 0.042547814353117774,
      "median": 2.55073864318,
      "user": 1.9759082199999998,
      "system": 1.6932945999999998,
      "min": 2.52665594668,
      "max": 2.67861579768
    },
    {
      "command": "pnpr@HEAD",
      "mean": 1.61483093318,
      "stddev": 0.13853228338614504,
      "median": 1.58547132268,
      "user": 1.29442142,
      "system": 1.4303116,
      "min": 1.45882371368,
      "max": 1.82407672568
    },
    {
      "command": "pnpr@main",
      "mean": 1.4933467355799999,
      "stddev": 0.0741273701735277,
      "median": 1.4605553266800002,
      "user": 1.3005470199999998,
      "system": 1.3315692,
      "min": 1.41084393668,
      "max": 1.63533583268
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 473.2 ± 59.6 430.9 638.7 1.61 ± 0.21
pacquet@main 439.3 ± 18.8 407.1 469.5 1.50 ± 0.08
pnpr@HEAD 293.0 ± 9.7 275.1 307.9 1.00
pnpr@main 307.9 ± 53.7 274.0 458.2 1.05 ± 0.19
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.47315948244,
      "stddev": 0.05961889735292946,
      "median": 0.45658368274,
      "user": 0.64746858,
      "system": 0.76572412,
      "min": 0.43092288124,
      "max": 0.63866964524
    },
    {
      "command": "pacquet@main",
      "mean": 0.43934922944,
      "stddev": 0.018806891677104236,
      "median": 0.43852705374,
      "user": 0.59903368,
      "system": 0.7352913199999999,
      "min": 0.40708165024000004,
      "max": 0.46945292724000004
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.29300589033999996,
      "stddev": 0.009723353316974328,
      "median": 0.29272522073999996,
      "user": 0.25606218,
      "system": 0.5685614199999999,
      "min": 0.27505670724,
      "max": 0.30788083824
    },
    {
      "command": "pnpr@main",
      "mean": 0.30788492743999996,
      "stddev": 0.05374512538999152,
      "median": 0.29263474623999997,
      "user": 0.28094518,
      "system": 0.6046466199999999,
      "min": 0.27398580224,
      "max": 0.45822439524
    }
  ]
}

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 1.644 ± 0.012 1.619 1.659 4.84 ± 0.20
pacquet@main 1.652 ± 0.017 1.616 1.676 4.87 ± 0.21
pnpr@HEAD 0.339 ± 0.014 0.321 0.356 1.00
pnpr@main 0.350 ± 0.010 0.336 0.365 1.03 ± 0.05
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 1.6440723454200004,
      "stddev": 0.011952055364552218,
      "median": 1.6475990011200001,
      "user": 0.8927303,
      "system": 0.9370725599999998,
      "min": 1.6191331541200003,
      "max": 1.6587781271200002
    },
    {
      "command": "pacquet@main",
      "mean": 1.6518098682200002,
      "stddev": 0.017342350250040165,
      "median": 1.65325547162,
      "user": 0.9515751000000001,
      "system": 0.9164874599999999,
      "min": 1.61572855212,
      "max": 1.6761173261200002
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.33935331512000005,
      "stddev": 0.014095905628271883,
      "median": 0.3387068241200001,
      "user": 0.31196389999999996,
      "system": 0.6860952599999999,
      "min": 0.32108039512000003,
      "max": 0.35585266212000005
    },
    {
      "command": "pnpr@main",
      "mean": 0.35044987281999995,
      "stddev": 0.009979862784462482,
      "median": 0.35195402162000006,
      "user": 0.32404089999999997,
      "system": 0.6991044599999998,
      "min": 0.33585143112000004,
      "max": 0.36481158412000003
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 270.3 ± 14.5 249.5 291.1 2.86 ± 0.17
pacquet@main 271.8 ± 15.0 242.4 292.1 2.87 ± 0.17
pnpr@HEAD 95.8 ± 2.6 91.1 101.6 1.01 ± 0.04
pnpr@main 94.5 ± 2.2 91.0 99.2 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.27031423398,
      "stddev": 0.01447997335235529,
      "median": 0.27340260308000003,
      "user": 0.24583406000000002,
      "system": 0.10077904,
      "min": 0.24945469008,
      "max": 0.29113538508000003
    },
    {
      "command": "pacquet@main",
      "mean": 0.27180063718,
      "stddev": 0.014961065963223033,
      "median": 0.27207259208,
      "user": 0.23446836000000001,
      "system": 0.10935083999999999,
      "min": 0.24236005908000002,
      "max": 0.29206264308
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.09576940838000003,
      "stddev": 0.0026376252803337057,
      "median": 0.09525229408000001,
      "user": 0.03813922666666667,
      "system": 0.016459573333333335,
      "min": 0.09108920508000001,
      "max": 0.10158632608000001
    },
    {
      "command": "pnpr@main",
      "mean": 0.09454763657999998,
      "stddev": 0.002232156009352002,
      "median": 0.09397881258000002,
      "user": 0.03688126,
      "system": 0.014900878666666664,
      "min": 0.09098439508000002,
      "max": 0.09915588308
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 208.7 ± 11.2 189.1 223.7 1.00
pacquet@main 218.4 ± 9.1 205.0 235.1 1.05 ± 0.07
pnpm@HEAD 3533.1 ± 99.2 3434.7 3706.8 16.93 ± 1.03
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.20869764644444444,
      "stddev": 0.011221525423427808,
      "median": 0.21013615300000002,
      "user": 0.21692992888888887,
      "system": 0.04980025111111111,
      "min": 0.189118449,
      "max": 0.22366756200000001
    },
    {
      "command": "pacquet@main",
      "mean": 0.21840797199999998,
      "stddev": 0.009081338082604733,
      "median": 0.215006411,
      "user": 0.21614915111111113,
      "system": 0.04885891777777778,
      "min": 0.204951205,
      "max": 0.235148923
    },
    {
      "command": "pnpm@HEAD",
      "mean": 3.5330705006666667,
      "stddev": 0.09920928732158134,
      "median": 3.4831455420000004,
      "user": 5.2999197066666675,
      "system": 0.39185947333333326,
      "min": 3.4347183730000004,
      "max": 3.706795533
    }
  ]
}

Scenario: Isolated linker: linked-workspace resolve, hot cache, offline

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 290.9 ± 65.1 222.4 358.8 1.00
pacquet@main 295.1 ± 63.0 227.1 372.2 1.01 ± 0.31
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.29085261646769234,
      "stddev": 0.0650822645555775,
      "median": 0.30271942716,
      "user": 0.23406502461538461,
      "system": 0.11019284153846153,
      "min": 0.22235342516,
      "max": 0.35877348116
    },
    {
      "command": "pacquet@main",
      "mean": 0.29509257225999996,
      "stddev": 0.06302623173629998,
      "median": 0.30069373316000003,
      "user": 0.23745634000000004,
      "system": 0.11242788000000001,
      "min": 0.22712822216,
      "max": 0.37220774016
    }
  ]
}

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 4.521 ± 0.156 4.354 4.821 1.29 ± 0.07
pacquet@main 4.532 ± 0.172 4.348 4.790 1.29 ± 0.07
pnpr@HEAD 3.554 ± 0.145 3.433 3.830 1.01 ± 0.06
pnpr@main 3.515 ± 0.141 3.407 3.778 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 4.521449321940001,
      "stddev": 0.1558789967347856,
      "median": 4.519769198740001,
      "user": 1.4320042,
      "system": 1.49396588,
      "min": 4.35377672424,
      "max": 4.82061480824
    },
    {
      "command": "pacquet@main",
      "mean": 4.5316335388399995,
      "stddev": 0.1722453998805299,
      "median": 4.43275854474,
      "user": 1.575968,
      "system": 1.44504638,
      "min": 4.34841003124,
      "max": 4.78982581124
    },
    {
      "command": "pnpr@HEAD",
      "mean": 3.5540937928400007,
      "stddev": 0.14533455065609308,
      "median": 3.48576011574,
      "user": 1.4573566999999998,
      "system": 1.4061937800000002,
      "min": 3.43312071424,
      "max": 3.82954669324
    },
    {
      "command": "pnpr@main",
      "mean": 3.5153159119399993,
      "stddev": 0.14080960779174845,
      "median": 3.45371894724,
      "user": 1.3745286999999997,
      "system": 1.3592123800000002,
      "min": 3.40662177624,
      "max": 3.77794200224
    }
  ]
}

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

Same install as the isolated fresh-restore hot/hot scenario, into the shared virtual store, the layout pnpm 12 installs into by default. Scenarios run on separate machines, so compare main and branch within each table.

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 113.7 ± 5.0 107.5 130.8 1.01 ± 0.05
pacquet@main 112.9 ± 3.6 105.6 118.3 1.00
pnpr@HEAD 129.4 ± 8.9 117.2 153.8 1.15 ± 0.09
pnpr@main 125.8 ± 4.4 118.6 135.2 1.11 ± 0.05
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.1137342837763636,
      "stddev": 0.005029350075930191,
      "median": 0.11256670414,
      "user": 0.14265325818181818,
      "system": 0.12407871999999998,
      "min": 0.10752424314,
      "max": 0.13078439214
    },
    {
      "command": "pacquet@main",
      "mean": 0.11285089853130437,
      "stddev": 0.0035876783346818993,
      "median": 0.11356916614000001,
      "user": 0.1446275052173913,
      "system": 0.12337339391304346,
      "min": 0.10555685814,
      "max": 0.11833482914000001
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.12940489999714286,
      "stddev": 0.008860487566051164,
      "median": 0.12812517814000002,
      "user": 0.14856094,
      "system": 0.13409636285714285,
      "min": 0.11717462914000001,
      "max": 0.15378456314
    },
    {
      "command": "pnpr@main",
      "mean": 0.1257718162828571,
      "stddev": 0.004438088479789551,
      "median": 0.12575326214000002,
      "user": 0.14868241619047623,
      "system": 0.12716288666666664,
      "min": 0.11855261714000001,
      "max": 0.13515300814
    }
  ]
}

@officialaritro
officialaritro marked this pull request as ready for review October 1, 2026 11:48
Copilot AI balanced review requested due to automatic review settings October 1, 2026 11:48

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

PR Summary by Qodo

Make hoisted required peers follow their provider's resolved version

🐞 Bug fix 🧪 Tests 📝 Documentation 🕐 40+ Minutes

Grey Divider

AI Description

• Prefer a version resolved during this install over a stale lockfile pin when hoisting required
 peers.
• Apply the same rule in pnpm v11 and v12, while retaining locked-version fallback.
• Test provider downgrades, version selection, and repeat-install lockfile stability.
Diagram

graph TD
  Provider["Provider dependency"] --> Run["Run resolutions"] --> Choice{"Satisfying version?"} -->|Yes| Peer["Required peer"] --> Snapshot["Lockfile snapshot"]
  Choice -->|No| Pins["Preferred versions"] --> Peer
Loading
High-Level Assessment

Keep the targeted resolved-first rule. It fixes stale lockfile pins in both CLIs without changing how an otherwise unprovided peer uses its locked version. Reusing the optional-peer version tiers would broaden selection behavior beyond the reported case and require additional v11 plumbing.

Files changed (9) +238 / -25

Bug fix (4) +63 / -15
hoist_peers.rsPrefer run-resolved versions for Rust required-peer hoisting +22/-4

Prefer run-resolved versions for Rust required-peer hoisting

• Adds run-resolved versions to hoist options and selects the highest satisfying one before considering all preferred versions. Retains the existing fallback when no run-resolved version satisfies the peer range.

pnpm/crates/resolving-deps-resolver/src/hoist_peers.rs

tree_ctx.rsShare the current-run version lookup +22/-6

Share the current-run version lookup

• Extracts a lookup for versions resolved into the current tree. Both required-peer hoisting and the existing optional-peer tier calculation use it.

pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/tree_ctx.rs

hoist_rounds.rsPass resolved versions into required-peer hoisting +5/-4

Pass resolved versions into required-peer hoisting

• Collects current-run versions for missing peers and supplies them alongside preferred versions to the Rust hoister.

pnpm/crates/resolving-deps-resolver/src/resolve_importer/hoist_rounds.rs

hoistPeers.tsPrefer resolved selectors when v11 hoists required peers +14/-1

Prefer resolved selectors when v11 hoists required peers

• Selects the highest satisfying plain version selector before falling back to all preferred versions. This keeps a lockfile-only weighted selector from outranking a version resolved during the install.

pnpm11/installing/deps-resolver/src/hoistPeers.ts

Tests (4) +168 / -10
optional_peer_pins.rsExercise optional and required peer provider moves +31/-9

Exercise optional and required peer provider moves

• Extends the CLI tests to cover required peers when their provider moves up or down. Verifies that only the destination peer remains and a repeat install leaves the lockfile unchanged.

pnpm/crates/cli/tests/suite/optional_peer_pins.rs

tests.rsCover Rust required-peer selection and fallback +52/-1

Cover Rust required-peer selection and fallback

• Adds tests for preferring a resolved downgrade over a stale higher candidate, choosing the highest resolved candidate, and falling back when resolved candidates do not satisfy the range.

pnpm/crates/resolving-deps-resolver/src/hoist_peers/tests.rs

autoInstallPeers.tsVerify v11 peer downgrade and lockfile stability +38/-0

Verify v11 peer downgrade and lockfile stability

• Adds an install-level regression test in which a provider downgrades its exact dependency. Checks the required peer follows, no older snapshot remains, and a repeat install preserves the lockfile.

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

hoistPeers.test.tsCover v11 resolved-first selection and fallback +47/-0

Cover v11 resolved-first selection and fallback

• Tests stale weighted pins, selection among multiple resolved versions, and fallback to a locked version when none resolved during the install satisfies the range.

pnpm11/installing/deps-resolver/test/hoistPeers.test.ts

Documentation (1) +7 / -0
required-peer-follows-its-provider.mdDocument the required-peer downgrade fix +7/-0

Document the required-peer downgrade fix

• Declares patch releases for the affected packages and describes how the fix prevents duplicate peer versions after a provider downgrades.

.changeset/required-peer-follows-its-provider.md

@qodo-code-review

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

Copy link
Copy Markdown

Code Review by Qodo

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

Grey Divider


Action required

1. All peer-provider CLI tests fail ✗ Dismissed
Description
assert_peer_follows_provider writes host: as a literal JSON key instead of using the host
argument, so the manifest depends on a package named host. In all four cases, host_keys searches
for the requested fixture package and the first assertion finds no matching snapshot key before the
peer-hoisting behavior is tested.
Code

pnpm/crates/cli/tests/suite/optional_peer_pins.rs[44]

+                host: "1.0.0",
Relevance

●●● Strong

Literal JSON key makes every peer-provider test target the wrong package; recent test-correctness
fixes are accepted.

PR-#15750
PR-#15369

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The new manifest entry uses host: while the assertion filters snapshot keys using the host
argument. Existing tests use parenthesized expressions for dynamic keys in serde_json::json!,
demonstrating the required syntax.

pnpm/crates/cli/tests/suite/optional_peer_pins.rs[35-55]
pnpm/crates/cli/tests/suite/optional_peer_pins.rs[95-101]
pnpm/crates/cli/tests/suite/hooks.rs[360-364]

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 shared CLI test helper writes a literal `host` dependency instead of the selected fixture package, so all four peer-provider tests fail before exercising the fix.

## Fix Focus Areas
- pnpm/crates/cli/tests/suite/optional_peer_pins.rs[41-51]

## Recommended Fix
Change the JSON object key from `host` to `(host)` so `serde_json::json!` evaluates the variable as the dependency name. Run the four peer-provider CLI tests.

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



Remediation recommended

2. Installs rescan incompatible peer versions 🐞 Bug ➹ Performance ⭐ New
Description
maxSatisfyingDemotingLockfileOnly repeats semver.maxSatisfying on the same candidates when
lockfileOnly is absent, while Rust’s preferred_version_specifier searches its in_run
candidates and then searches all versions again when the first search fails. Missing required peers
with incompatible preferred versions reach these paths during hoisting, causing repeated candidate
scans and range parsing before a locked version or the requested range is chosen.
Code

pnpm11/installing/deps-resolver/src/hoistPeers.ts[R128-130]

+  const resolved = lockfileOnly == null ? versions : versions.filter((version) => !lockfileOnly.has(version))
+  return semver.maxSatisfying(resolved, range, { includePrerelease: true }) ??
+    semver.maxSatisfying(versions, range, { includePrerelease: true })
Relevance

●●● Strong

Recent history accepts concrete resolver performance fixes that eliminate repeated graph or
candidate scans.

PR-#14841
PR-#12491

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
Without a lockfile-only set, the TypeScript helper’s first and fallback searches have identical
inputs, and the required-peer loop reaches it through pickPreferredPeerSpec. In Rust, the fallback
calls max_satisfying after the run-resolved search fails; each call parses the range and iterates
candidates, and required-peer hoisting can repeat across rounds.

pnpm11/installing/deps-resolver/src/hoistPeers.ts[37-45]
pnpm11/installing/deps-resolver/src/hoistPeers.ts[100-104]
pnpm11/installing/deps-resolver/src/hoistPeers.ts[127-130]
pnpm11/installing/deps-resolver/src/resolveRootDependencies.ts[78-80]
pnpm/crates/resolving-deps-resolver/src/hoist_peers.rs[127-139]
pnpm/crates/resolving-deps-resolver/src/hoist_peers.rs[372-390]
pnpm/crates/resolving-deps-resolver/src/resolve_importer/hoist_rounds.rs[128-153]

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

## Issue description
Peer preference selection repeats candidate searches when its preferred search finds no matching version. In TypeScript, the fallback is redundant when there are no lockfile-only versions; in Rust, the fallback reparses the range and revisits candidates.

## Fix Focus Areas
- pnpm11/installing/deps-resolver/src/hoistPeers.ts[127-130]
- pnpm/crates/resolving-deps-resolver/src/hoist_peers.rs[127-139]
- pnpm/crates/resolving-deps-resolver/src/hoist_peers.rs[372-390]

## Recommended Fix
In TypeScript, return the result of one `semver.maxSatisfying` call when `lockfileOnly` is absent or empty, retaining the two-tier search only when it changes the candidate set. In Rust, parse the range once and scan candidate versions once, tracking both the highest satisfying run-resolved version and the highest satisfying version overall; choose the run-resolved result when present and otherwise use the overall result.

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

Dismiss ↗ | View ↗


3. Fresh installs crash on constructor peers ✓ Resolved
Description
getLockfileOnlyVersions creates a plain object, so looking up a peer named constructor with no
lockfile pin returns the inherited Object constructor rather than an absent set. On a fresh
install where a provider resolves that peer, maxSatisfyingDemotingLockfileOnly calls .has on the
inherited function and throws before the peer can be hoisted.
Code

pnpm11/installing/deps-resolver/src/hoistPeers.ts[138]

+  const lockfileOnlyVersions: Record<string, Set<string>> = {}
Relevance

●●● Strong

Accepted bug precedents favor fixing concrete resolver crashes and cross-version edge cases in
hoistPeers.

PR-#13369
PR-#14841

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The new map is initialized with {} and later indexed by peer name; the new selection helper calls
.has on any value returned by that lookup. The repository explicitly tests constructor as a
valid package name, while the preferred-version map uses a null prototype. Rust's corresponding
version lookup uses a hash map, so this edge case also diverges between the two implementations.

Rule 713428: Keep pnpm v11 and v12 observable behavior aligned when fixing shared bugs
pnpm11/installing/deps-resolver/src/hoistPeers.ts[78-80]
pnpm11/installing/deps-resolver/src/hoistPeers.ts[127-145]
pnpm11/installing/deps-installer/test/install/prototypeKeyFastUpdate.test.ts[12-13]
pnpm/crates/resolving-deps-resolver/src/hoist_peers.rs[100-103]

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 peer named `constructor` can read an inherited property from the new lockfile-only version map and crash v11 installs.

## Fix Focus Areas
- pnpm11/installing/deps-resolver/src/hoistPeers.ts[127-145]
- pnpm11/installing/deps-resolver/test/hoistPeers.test.ts[292-357]

## Recommended Fix
Create the map with a null prototype or use a `Map`, and add a test with a resolved `constructor` peer that has no lockfile-only version.

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


4. Workspace peers differ across versions 📘 Rule violation ⌂ Architecture
Description
lockfileOnlyVersions is captured before peer hoisting and keeps treating a pinned version as
lockfile-only even after a hoist resolves it. If one importer hoists that version before another
chooses a peer, v11 can prefer a lower version while v12 counts the newly resolved version and
prefers the higher one.
Code

pnpm11/installing/deps-resolver/src/hoistPeers.ts[R127-128]

+function maxSatisfyingDemotingLockfileOnly (versions: string[], lockfileOnly: Set<string> | undefined, range: string): string | null {
+  const resolved = lockfileOnly == null ? versions : versions.filter((version) => !lockfileOnly.has(version))
Relevance

●●● Strong

Cross-version behavior alignment and stale snapshot handling match accepted hoisting fixes.

PR-#13369

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The new v11 snapshot is taken before hoisting and passed unchanged to each importer. Its selection
filter excludes every version in that snapshot, even if resolution subsequently replaces its
selector with a plain one; the new unit test explicitly asserts that behavior. In v12, the hoist
instead obtains resolved versions from the current tree for each pick, and its tree tests show that
newly recorded reachable roots enter that set.

Rule 713428: Keep pnpm v11 and v12 observable behavior aligned when fixing shared bugs
pnpm11/installing/deps-resolver/src/resolveRootDependencies.ts[75-80]
pnpm11/installing/deps-resolver/src/hoistPeers.ts[127-130]
pnpm11/installing/deps-resolver/test/hoistPeers.test.ts[309-322]
pnpm/crates/resolving-deps-resolver/src/resolve_importer/hoist_rounds.rs[185-196]
pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/workspace_ctx/tests.rs[317-335]

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 v11 lockfile-only snapshot cannot recognize a pinned version resolved during peer hoisting, while v12 includes versions resolved into its growing tree.

## Fix Focus Areas
- pnpm11/installing/deps-resolver/src/hoistPeers.ts[127-130]
- pnpm11/installing/deps-resolver/src/resolveRootDependencies.ts[75-105]
- pnpm11/installing/deps-resolver/test/hoistPeers.test.ts[309-323]

## Recommended Fix
Make v11 selection account for versions resolved in completed hoist rounds without making a pick depend on concurrent importer timing. Add a multi-importer regression test comparing the resulting peer versions with v12.

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

Dismiss ↗ | View ↗


View medium (5)
5. A stray older pin downgrades a locked peer ✓ Resolved
Description
preferred_version_specifier (and maxSatisfyingPreferringResolved in v11) restricts the pick to
versions in resolved_versions, which covers every package any importer resolved this run, and
falls back to the locked versions only when none of those fits the range. When any unrelated
dependency pins a lower version that still fits the peer range, a plain install with no manifest
changes rewrites the host's peer from its locked higher version to that lower one, because the
host's own locked peer is resolved only after the hoist.
Code

pnpm/crates/resolving-deps-resolver/src/hoist_peers.rs[R127-138]

+    let satisfying_version = is_semver_range
+        .then(|| {
+            resolved_versions
+                .and_then(|resolved| {
+                    let in_run: Vec<&str> = versions
+                        .iter()
+                        .copied()
+                        .filter(|version| resolved.contains(*version))
+                        .collect();
+                    max_satisfying(&in_run, &range_for_match)
+                })
+                .or_else(|| max_satisfying(&versions, &range_for_match))
Relevance

●●● Strong

Exact recent precedent accepted filtering stale lockfile candidates when a provider downgrades
during resolution.

PR-#16445

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
run_preferred_versions folds versions from every importer's reachable tree. hoist_rounds passes
that set into hoist_peers before the missing peer is resolved, so the locked version is absent
from it. max_satisfying(in_run) then returns the unrelated pinned lower version and the or_else
fallback to the locked versions is never reached. In v11, recordPreferredVersionOfResolvedPackage
marks every resolved version as a plain 'version' selector, while lockfile-seeded versions stay
weighted objects, so the filter in maxSatisfyingPreferringResolved behaves the same way.

pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/workspace_ctx/version_snapshot.rs[113-134]
pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/tree_ctx.rs[553-568]
pnpm11/installing/deps-resolver/src/resolveDependency.ts[166-174]
pnpm11/lockfile/preferred-versions/src/index.ts[72-81]
PR-#16445

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 required-peer hoist now prefers any version resolved this run. That set is workspace-wide and is computed before the peer itself is hoisted. A lower satisfying version pinned by an unrelated package therefore beats the host's locked peer version, which downgrades the peer on a plain repeat install after a pnpm upgrade. The PR's stated goal is to change only the case where the locked version's provider moved on.

## Fix Focus Areas
- pnpm/crates/resolving-deps-resolver/src/hoist_peers.rs[125-140]
- pnpm11/installing/deps-resolver/src/hoistPeers.ts[118-122]
- pnpm/crates/resolving-deps-resolver/src/resolve_importer/hoist_rounds.rs[185-188]

## Recommended Fix
Only let a run-resolved version beat a higher locked candidate when that locked candidate is stale, meaning nothing in the run still reaches it (reuse the stale-pin signal). Alternatively, prefer resolved versions only when they are at least as high as the best locked candidate. Add tests in both v12 and v11 for the case where an unrelated dependency pins a lower satisfying version and the locked hoisted version is kept.

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


6. New peer helper omits its null case ✓ Resolved
Description
The JSDoc for maxSatisfyingPreferringResolved describes how it chooses a satisfying version but
does not document that it returns null when neither candidate set satisfies range. That boundary
case reaches pickPreferredPeerSpec, which then either uses the original range or leaves the peer
unhoisted depending on autoInstallPeers.
Code

pnpm11/installing/deps-resolver/src/hoistPeers.ts[R111-113]

+/**
+ * The highest of `versions` satisfying `range`, taken from the versions this
+ * install resolved when one of them satisfies it. Resolving a version records
Relevance

●●● Strong

Recent TypeScript precedents accept JSDoc revisions that document contracts, boundary behavior, and
return cases.

PR-#16207
PR-#14810
PR-#13369

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
Rule 713430 requires JSDoc to cover return guarantees and boundary inputs. The new comment covers
the selection preference, while the implementation can return null and its caller handles that
result.

Rule 713430: JSDoc must document function contracts, not re-describe implementation
pnpm11/installing/deps-resolver/src/hoistPeers.ts[89-109]
pnpm11/installing/deps-resolver/src/hoistPeers.ts[111-122]

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 new helper's JSDoc omits its return-value guarantee when no version satisfies the range.

## Fix Focus Areas
- pnpm11/installing/deps-resolver/src/hoistPeers.ts[111-118]

## Recommended Fix
Add a contract-focused sentence stating that the helper returns `null` if neither the resolved versions nor the remaining preferred versions satisfy the range.

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


7. Large installs repeatedly copy peer versions 🐞 Bug ➹ Performance
Description
hoist_missing_required calls preferred_versions_for_names and then run_resolved_versions for
the same missing peers, cloning their version strings into two maps before selecting a peer. The
required-peer loop repeats this work across hoist rounds, so projects with many missing peers or
many versions of a peer incur additional CPU use and temporary memory on the install path.
Code

pnpm/crates/resolving-deps-resolver/src/resolve_importer/hoist_rounds.rs[188]

+        let resolved_versions = self.ctx.run_resolved_versions(names());
Relevance

●●● Strong

Resolver performance findings targeting repeated allocations and hot-path cloning are regularly
accepted.

PR-#13431
PR-#13855
PR-#13172

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The two adjacent calls request identical names. Both helpers iterate the cached run-version buckets
and clone version keys into separate owned collections; the enclosing required-peer loop can invoke
them again in subsequent rounds.

pnpm/crates/resolving-deps-resolver/src/resolve_importer/hoist_rounds.rs[139-164]
pnpm/crates/resolving-deps-resolver/src/resolve_importer/hoist_rounds.rs[182-200]
pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/tree_ctx.rs[499-526]
pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/tree_ctx.rs[553-568]

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

## Issue description
Required-peer hoisting independently copies the same run-resolved version buckets into preferred selectors and resolved-version sets on every hoist round.
## Fix Focus Areas
- pnpm/crates/resolving-deps-resolver/src/resolve_importer/hoist_rounds.rs[185-188]
- pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/tree_ctx.rs[499-526]
- pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/tree_ctx.rs[553-568]
## Recommended Fix
Produce the preferred selectors and resolved-version membership together while visiting each requested bucket once, avoiding a second clone of every version string where possible.

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

Dismiss ↗ | View ↗


8. Workspace peer pick can change between installs ✓ Resolved
Description
maxSatisfyingPreferringResolved treats any plain-string selector in the shared
ctx.allPreferredVersions as resolved this run, but recordPreferredVersionOfResolvedPackage keeps
adding such selectors while other importers' hoist rounds run concurrently. Whether a lower
satisfying version beats the higher locked one therefore depends on resolution timing across
importers, so repeat workspace installs can rewrite peer suffixes and duplicate copies.
Code

pnpm11/installing/deps-resolver/src/hoistPeers.ts[R118-121]

+function maxSatisfyingPreferringResolved (selectors: VersionSelectors, versions: string[], range: string): string | null {
+  const resolved = versions.filter((version) => typeof selectors[version] === 'string')
+  return semver.maxSatisfying(resolved, range, { includePrerelease: true }) ??
+    semver.maxSatisfying(versions, range, { includePrerelease: true })
Relevance

●●● Strong

Concurrency-dependent resolution and nondeterministic lockfile behavior are treated as reliability
bugs requiring fixes.

PR-#12514
PR-#16445
PR-#14841

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
Importers hoist concurrently, and resolution writes plain 'version' selectors into the shared map
that the new rule reads. Before this PR the pick was the highest satisfying version, so a lower
version recorded concurrently could not change it. v12 explicitly avoids an arrival-ordered fold for
this reason.

pnpm11/installing/deps-resolver/src/resolveRootDependencies.ts[91-100]
pnpm11/installing/deps-resolver/src/resolveDependency.ts[166-174]
pnpm11/installing/deps-resolver/src/resolveRootDependencies.ts[127-140]
pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/workspace_ctx/version_snapshot.rs[113-133]

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

## Issue description
In v11, `maxSatisfyingPreferringResolved` decides which versions were resolved this run by checking `typeof selectors[version] === 'string'` on the shared `ctx.allPreferredVersions`. `hoistPeersToImporters` runs every importer's required-peer hoist concurrently with `Promise.all`. Each hoist round awaits resolution, and that resolution records new plain selectors into the same object. The chosen peer version therefore depends on timing.

## Fix Focus Areas
- pnpm11/installing/deps-resolver/src/hoistPeers.ts[118-122]
- pnpm11/installing/deps-resolver/src/resolveRootDependencies.ts[91-100]
- pnpm11/installing/deps-resolver/src/resolveRootDependencies.ts[127-140]

## Recommended Fix
At the start of each outer hoisting round, before the `Promise.all`, compute a snapshot of the versions resolved so far for each peer name: the plain-selector entries. Pass this snapshot to `hoistPeers` through a new `resolvedVersions` option, and use it in `maxSatisfyingPreferringResolved` instead of the live selector type. Every importer then sees the same set. Add a workspace test where two importers' hoist rounds overlap.

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


9. Peer-free installs scan every lockfile pin 🐞 Bug ➹ Performance
Description
startPeerHoisting calls getLockfileOnlyVersions over every entry in ctx.allPreferredVersions
and allocates sets for weighted versions before checking whether any importer has missing peers.
Because peer hoisting runs on the normal install path, large lockfiles incur this additional scan
and retained allocations even when no peer needs hoisting.
Code

pnpm11/installing/deps-resolver/src/resolveRootDependencies.ts[R78-80]

+    lockfileOnlyVersions: ctx.autoInstallPeers && ctx.allPreferredVersions != null
+      ? getLockfileOnlyVersions(ctx.allPreferredVersions)
+      : undefined,
Relevance

●● Moderate

Performance concern is plausible, but precedent rejects related scan optimizations in different
resolver contexts.

PR-#12855

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The resolver seeds preferred versions from wanted-lockfile packages, calls peer hoisting whenever
ctx.hoistPeers is enabled, and constructs the snapshot before hoistRequiredPeersOfImporter
checks for missing peers. The snapshot enumerates every preferred package and its selectors,
creating sets for weighted entries.

pnpm11/installing/deps-resolver/src/resolveRootDependencies.ts[51-62]
pnpm11/installing/deps-resolver/src/resolveRootDependencies.ts[75-80]
pnpm11/installing/deps-resolver/src/resolveRootDependencies.ts[110-125]
pnpm11/installing/deps-resolver/src/hoistPeers.ts[137-145]

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 lockfile-only snapshot scans all preferred versions on installs with no peers to hoist.
## Fix Focus Areas
- pnpm11/installing/deps-resolver/src/resolveRootDependencies.ts[59-80]
- pnpm11/installing/deps-resolver/src/hoistPeers.ts[133-147]
## Recommended Fix
Add a cheap no-peer fast path before building the snapshot, while preserving the requirement that any snapshot used by concurrent importer hoists is captured once before those hoists begin.

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

Dismiss ↗ | View ↗



Informational

10. One release note mixes both versions 📘 Rule violation § Compliance
Description
The changeset combines the pnpm v11 and pacquet v12 bumps in one file instead of providing a
separate changeset for each. Because this PR changes both implementations, a later version-specific
release-note edit would affect a file targeting both release lines.
Code

.changeset/required-peer-follows-its-provider.md[R2-4]

+"@pnpm/installing.deps-resolver": patch
+"pnpm": patch
+"pacquet": patch
Relevance

● Weak

Recent repository precedents reject splitting coordinated pnpm/pacquet changesets despite the same
rule pattern.

PR-#15418
PR-#15443
PR-#16462

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
Rule 713436 requires separate changesets when a PR touches both stacks. The single added changeset
lists both pnpm and pacquet.

Rule 713436: Changesets for pnpm v11 vs v12 (pacquet) must target the correct package and bump type
.changeset/required-peer-follows-its-provider.md[1-7]
pnpm11/installing/deps-resolver/src/hoistPeers.ts[91-95]
pnpm/crates/resolving-deps-resolver/src/hoist_peers.rs[119-140]

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 PR changes both pnpm v11 and pacquet v12, but one changeset targets both release lines.

## Fix Focus Areas
- .changeset/required-peer-follows-its-provider.md[2-7]

## Recommended Fix
Create separate changeset files: one targeting the v11 packages, including `pnpm` with a patch bump, and one targeting only `pacquet` for v12. Give each the applicable release-note text.

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

Dismiss ↗ | View ↗


Grey Divider

Context sources
✅ Compliance rules (platform): 63 rules
✅ Skills: review-code
✅ Cross-repo context — repo relationships
  Explored: repo: pnpm/update (sha: fcaa952e) — View relationship
  Explored: repo: pnpm/exec (sha: d9dca8d2) — View relationship
  Explored: repo: pnpm/node-semver-rs (sha: 3d74d6b7) — View relationship
Review mode: Auto: ⚖️ Balanced: This changes dependency-resolution and peer-hoisting behavior across pnpm v11 and v12 with concurrency, lockfile, and install-path implications, warranting a careful single-pass review.

Grey Divider

Tip of the day
💡 Did you know, you can describe a rule in plain language on the Rules page and Qodo drafts it for you

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Previous reviews

Review updated until commit 02d736e

Results up to commit 5f1aeec 🧠 Deep


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


Action required
1. All peer-provider CLI tests fail ✗ Dismissed
Description
assert_peer_follows_provider writes host: as a literal JSON key instead of using the host
argument, so the manifest depends on a package named host. In all four cases, host_keys searches
for the requested fixture package and the first assertion finds no matching snapshot key before the
peer-hoisting behavior is tested.
Code

pnpm/crates/cli/tests/suite/optional_peer_pins.rs[44]

+                host: "1.0.0",
Relevance

●●● Strong

Literal JSON key makes every peer-provider test target the wrong package; recent test-correctness
fixes are accepted.

PR-#15750
PR-#15369

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The new manifest entry uses host: while the assertion filters snapshot keys using the host
argument. Existing tests use parenthesized expressions for dynamic keys in serde_json::json!,
demonstrating the required syntax.

pnpm/crates/cli/tests/suite/optional_peer_pins.rs[35-55]
pnpm/crates/cli/tests/suite/optional_peer_pins.rs[95-101]
pnpm/crates/cli/tests/suite/hooks.rs[360-364]

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 shared CLI test helper writes a literal `host` dependency instead of the selected fixture package, so all four peer-provider tests fail before exercising the fix.

## Fix Focus Areas
- pnpm/crates/cli/tests/suite/optional_peer_pins.rs[41-51]

## Recommended Fix
Change the JSON object key from `host` to `(host)` so `serde_json::json!` evaluates the variable as the dependency name. Run the four peer-provider CLI tests.

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



Remediation recommended
2. A stray older pin downgrades a locked peer ✓ Resolved
Description
preferred_version_specifier (and maxSatisfyingPreferringResolved in v11) restricts the pick to
versions in resolved_versions, which covers every package any importer resolved this run, and
falls back to the locked versions only when none of those fits the range. When any unrelated
dependency pins a lower version that still fits the peer range, a plain install with no manifest
changes rewrites the host's peer from its locked higher version to that lower one, because the
host's own locked peer is resolved only after the hoist.
Code

pnpm/crates/resolving-deps-resolver/src/hoist_peers.rs[R127-138]

+    let satisfying_version = is_semver_range
+        .then(|| {
+            resolved_versions
+                .and_then(|resolved| {
+                    let in_run: Vec<&str> = versions
+                        .iter()
+                        .copied()
+                        .filter(|version| resolved.contains(*version))
+                        .collect();
+                    max_satisfying(&in_run, &range_for_match)
+                })
+                .or_else(|| max_satisfying(&versions, &range_for_match))
Relevance

●●● Strong

Exact recent precedent accepted filtering stale lockfile candidates when a provider downgrades
during resolution.

PR-#16445

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
run_preferred_versions folds versions from every importer's reachable tree. hoist_rounds passes
that set into hoist_peers before the missing peer is resolved, so the locked version is absent
from it. max_satisfying(in_run) then returns the unrelated pinned lower version and the or_else
fallback to the locked versions is never reached. In v11, recordPreferredVersionOfResolvedPackage
marks every resolved version as a plain 'version' selector, while lockfile-seeded versions stay
weighted objects, so the filter in maxSatisfyingPreferringResolved behaves the same way.

pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/workspace_ctx/version_snapshot.rs[113-134]
pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/tree_ctx.rs[553-568]
pnpm11/installing/deps-resolver/src/resolveDependency.ts[166-174]
pnpm11/lockfile/preferred-versions/src/index.ts[72-81]
PR-#16445

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 required-peer hoist now prefers any version resolved this run. That set is workspace-wide and is computed before the peer itself is hoisted. A lower satisfying version pinned by an unrelated package therefore beats the host's locked peer version, which downgrades the peer on a plain repeat install after a pnpm upgrade. The PR's stated goal is to change only the case where the locked version's provider moved on.

## Fix Focus Areas
- pnpm/crates/resolving-deps-resolver/src/hoist_peers.rs[125-140]
- pnpm11/installing/deps-resolver/src/hoistPeers.ts[118-122]
- pnpm/crates/resolving-deps-resolver/src/resolve_importer/hoist_rounds.rs[185-188]

## Recommended Fix
Only let a run-resolved version beat a higher locked candidate when that locked candidate is stale, meaning nothing in the run still reaches it (reuse the stale-pin signal). Alternatively, prefer resolved versions only when they are at least as high as the best locked candidate. Add tests in both v12 and v11 for the case where an unrelated dependency pins a lower satisfying version and the locked hoisted version is kept.

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


Results up to commit b52f25e ⚖️ Balanced


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


Remediation recommended
1. Fresh installs crash on constructor peers ✓ Resolved
Description
getLockfileOnlyVersions creates a plain object, so looking up a peer named constructor with no
lockfile pin returns the inherited Object constructor rather than an absent set. On a fresh
install where a provider resolves that peer, maxSatisfyingDemotingLockfileOnly calls .has on the
inherited function and throws before the peer can be hoisted.
Code

pnpm11/installing/deps-resolver/src/hoistPeers.ts[138]

+  const lockfileOnlyVersions: Record<string, Set<string>> = {}
Relevance

●●● Strong

Accepted bug precedents favor fixing concrete resolver crashes and cross-version edge cases in
hoistPeers.

PR-#13369
PR-#14841

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The new map is initialized with {} and later indexed by peer name; the new selection helper calls
.has on any value returned by that lookup. The repository explicitly tests constructor as a
valid package name, while the preferred-version map uses a null prototype. Rust's corresponding
version lookup uses a hash map, so this edge case also diverges between the two implementations.

Rule 713428: Keep pnpm v11 and v12 observable behavior aligned when fixing shared bugs
pnpm11/installing/deps-resolver/src/hoistPeers.ts[78-80]
pnpm11/installing/deps-resolver/src/hoistPeers.ts[127-145]
pnpm11/installing/deps-installer/test/install/prototypeKeyFastUpdate.test.ts[12-13]
pnpm/crates/resolving-deps-resolver/src/hoist_peers.rs[100-103]

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 peer named `constructor` can read an inherited property from the new lockfile-only version map and crash v11 installs.

## Fix Focus Areas
- pnpm11/installing/deps-resolver/src/hoistPeers.ts[127-145]
- pnpm11/installing/deps-resolver/test/hoistPeers.test.ts[292-357]

## Recommended Fix
Create the map with a null prototype or use a `Map`, and add a test with a resolved `constructor` peer that has no lockfile-only version.

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


Grey Divider

Qodo Logo

@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 5f1aeec

@github-actions github-actions Bot added the reviewed: coderabbit CodeRabbit submitted an approving review label Oct 1, 2026
Copilot AI balanced review requested due to automatic review settings October 1, 2026 12:00

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.

@officialaritro

Copy link
Copy Markdown
Contributor Author

Replies to the Qodo review:

  1. The JSDoc does not mention the null case. Fixed in b52f25e. The helper is now maxSatisfyingDemotingLockfileOnly, and its doc comment states that it returns null when no version satisfies the range.
  2. Two maps per hoist round. Not changed. Both maps hold only the missing peers of one round, and the optional-peer hoist from fix(deps-resolver): drop a stale locked optional-peer version #16445 builds the same pair.
  3. The v11 pick depends on importer timing. Fixed in b52f25e. Importers hoist concurrently and each resolve adds plain selectors, so the live selectors were the wrong source. getLockfileOnlyVersions now records the lockfile-only versions once, after every importer's direct dependencies resolved and before any importer hoists, and the pick demotes exactly those. A new unit test covers a lockfile-only version that another importer resolves while peers are hoisted. v12 is not affected, because run_preferred_versions is derived from the settled tree, not from resolution order.
  4. One changeset for both versions. Not changed. The release note is the same for both CLIs, and the repository guide allows one changeset for several release lines when the same text applies to every target.

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

@qodo-code-review

Copy link
Copy Markdown

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

@officialaritro

Copy link
Copy Markdown
Contributor Author

Replies to the updated Qodo review:

  1. A stray older pin downgrades a locked peer. This is the intended result. A locked host peer at a higher version, while another dependency pins a lower one that fits the range, is the duplicated lockfile that main writes. A fresh resolve gives one copy at the lower version. The first install with this fix moves the peer to it, and later installs keep the lockfile unchanged. If anything else in the graph still resolves the higher version, that version stays a candidate and wins as the higher one, so nothing moves.
  2. v11 and v12 can pick differently. They differ only when a version that only the lockfile held is hoisted by another importer during the same install. v12 then counts it as resolved, because run_preferred_versions reads the settled tree. v11 cannot read the settled tree, so it takes the lockfile-only set before any importer hoists. That keeps v11 independent of importer timing. Both CLIs stay deterministic, and both pick a version that satisfies the range.
  3. Peer-free installs scan every lockfile pin. Not changed. getLockfileOnlyVersions runs only with auto-install-peers, in one pass over the map that the install already built. After resolution, a resolved version is a plain selector, so sets are allocated only for the lockfile-only versions. Computing the set lazily, at the first pick, would make it depend on importer timing again.

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

@qodo-code-review

Copy link
Copy Markdown

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

Copilot AI balanced review requested due to automatic review settings October 1, 2026 14:22

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.

@officialaritro

Copy link
Copy Markdown
Contributor Author

Fresh installs crash on constructor peers. Confirmed and fixed in 947cee4. getLockfileOnlyVersions returned a plain object, so a peer named constructor with no lockfile pin read the inherited Object.prototype.constructor, and the pick threw TypeError: lockfileOnly.has is not a function. It now returns a Map. The new test hoistPeers hoists a peer named constructor when no lockfile pins it fails with that TypeError on the plain-object version and passes with the Map. v12 is not affected, because a Rust HashMap has no inherited keys.


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

@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 042a806

1 similar comment
@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 042a806

The peer-pin tests take the host package as a parameter, so the
optional-peer cases from pnpm#16445 also run against
`@pnpm.e2e/wants-peer-c-1`, which declares `peer-c` as a required
peer. After the provider moves `peer-c` down, the required peer keeps
the old locked version (pnpm/tasks#61). Each case also checks that a
repeat install leaves the lockfile unchanged.
The required-peer hoist took the highest preferred version that
satisfied the peer range. Lockfile seeding keeps every locked version a
candidate, so after a provider such as `vue` moved its exact
dependency from 3.5.43 to 3.5.40, the hoisted `vue` peer of
`@vue/test-utils` stayed on 3.5.43 and the lockfile kept two copies.
`pnpm dedupe` took the same path. The upgrade direction converged only
because the new version was also the highest.

The required-peer hoist now tries the version tiers that
pnpm#16445 added for optional peers: the locked versions this run
resolved, every version this run resolved, then the locked versions,
before the rest of the preferred versions. A locked version something
else still resolves keeps winning, and a peer nothing else resolves
keeps its locked version, so a repeat install does not move it.
`optional_peer_version_tiers` becomes `peer_version_tiers`, since both
pickers use it.

Refs pnpm/tasks#61
…peer

Narrow the previous commit. Instead of the three tiers the optional-peer
hoist uses, the required-peer hoist now takes the highest satisfying
version this run resolved, and falls back to every preferred version, as
before, when none satisfies the range.

The stale version in pnpm/tasks#61 is one that only the wanted lockfile
holds, so this is the whole fix. The tiers also kept a lower locked
version over a higher one the run resolved, which changed a case nobody
reported, and pnpm v11 cannot reproduce them without parsing the
importer's peer suffixes. "Resolved this run" is something both CLIs
already record, so they now pick the same version.

`TreeCtx::run_resolved_versions` returns the versions per name, and
`optional_peer_version_tiers` uses it as well, so the lookup stays in
one place.

Refs pnpm/tasks#61
@zkochan
zkochan force-pushed the fix/required-peer-follows-provider branch from 042a806 to 02d736e Compare October 4, 2026 20:30
Copilot AI balanced review requested due to automatic review settings October 4, 2026 20:30

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 02d736e

@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

zkochan commented Oct 4, 2026

Copy link
Copy Markdown
Member

Rebased onto main (head 02d736e, no conflicts) and re-reviewed the full diff. No code changes were needed.

Replies to the Qodo review on 02d736e:

  1. All peer-provider CLI tests fail. Not a bug. serde_json::json! inserts an object key as ($($key)+).into(), so the bare host key evaluates the variable. The four optional_peer_pins tests pass in CI and locally. Answered in the inline thread.
  2. Installs rescan incompatible peer versions. Not changed. The second scan runs only for a missing required peer that no run-resolved version satisfies. It covers the candidate versions of one package, once per missing peer per hoist round. That is not a hot path. In Rust, the second max_satisfying call is the fallback itself. In v11, the case with no lockfile-only set could skip it, but it costs one extra scan of the same short list.

Findings 4, 7, 9, and 10 were answered earlier in this thread and are unchanged.

Status on 02d736e:

  • CI: all 65 checks green, 2 skipped.
  • CodeRabbit reviewed this head and reported no actionable comments.
  • Qodo updated its review to this head. It has no new findings beyond item 2 above.
  • Local runs: hoistPeers.test.ts (39 passed, with compile and lint), plus the hoist_peers and optional_peer_pins/workspace_peer_pins Rust tests (51 passed).

Nothing remains within the scope of this review. The PR's ready status was kept.


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

@zkochan
zkochan merged commit 3c6a942 into pnpm:main Oct 4, 2026
68 checks passed
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-installed required peers keep a stale locked version after a provider downgrade

4 participants