Skip to content

fix(resolver): ignore a workspace root pin an optional peer's range rejects - #13869

Merged
zkochan merged 3 commits into
pnpm:mainfrom
lazerg:fix/issue-13867-optional-peer-root-range
Aug 31, 2026
Merged

zkochan merged 3 commits into
pnpm:mainfrom
lazerg:fix/issue-13867-optional-peer-root-range

Conversation

@lazerg

@lazerg lazerg commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

getHoistableOptionalPeers bounds its candidates by the workspace root's own specifier for the package. When that specifier cannot satisfy the peer's declared range, the bound rules out every candidate, nothing gets hoisted, and the importer falls back to the root's version through resolvePeersFromWorkspaceRoot. So a workspace whose root keeps "date-fns-v2": "npm:[email protected]" gave an importer @base-ui/[email protected]([email protected]) for an optional date-fns@^4.0.0 peer, and pnpm peers check then flagged pnpm's own resolution as unmet, with [email protected] already in the graph from a sibling importer.

The root's specifier now bounds the candidates only when it overlaps every wanted range. A pin that overlaps still wins, so the hoisting fixed in #13369 is unaffected; a pin that is disjoint is ignored, and the highest version in the graph that satisfies the peer wins again, as it did before 11.18.0.

On the reproduction from the issue, pkg-a moves from 1.7.0([email protected]) back to 1.7.0([email protected]) and pnpm peers check reports no issues.

Fixes #13867

Squash Commit Body

getHoistableOptionalPeers bounds its candidates by the workspace root's own
specifier for the package, so the root decides the version an optional peer
is hoisted at. A specifier disjoint from the declared peer range bounded the
candidates down to none: nothing was hoisted, and the importer then fell back
to the root's version through resolvePeersFromWorkspaceRoot, which is the very
version the peer range rejects. A root pinning date-fns 2.30.0 gave an
importer @base-ui/react([email protected]) for an optional date-fns@^4.0.0 peer
while [email protected] sat in the graph, and pnpm peers check then reported that
resolution as unmet.

The root's specifier is now consulted only when it overlaps every range
recorded for the peer. An overlapping pin still bounds the candidates as
before, so the hoisting corrected in pnpm/pnpm#13369 stays; a disjoint one is
dropped and the picker maximizes over the graph again.

Fixes pnpm/pnpm#13867

Checklist

  • I checked the referenced issue and verified that none of the PRs
    already linked to it solves it.
  • The change is implemented in both the TypeScript CLI and the Rust
    pnpm/ 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.

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

Summary by CodeRabbit

  • Bug Fixes
    • Fixed optional peer dependency installation when a workspace root dependency specifies an incompatible version.
    • Incompatible or invalid root version ranges no longer prevent compatible optional peer versions from being selected.
    • Optional peers now correctly fall back to the highest preferred version that satisfies the requested version range.
    • Added regression coverage for aliased root dependencies with conflicting version specifications and multiple requested ranges.

@lazerg
lazerg requested a review from zkochan as a code owner August 12, 2026 14:15
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

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

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

@coderabbitai

coderabbitai Bot commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@zkochan, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 3 minutes

Limit details: You’ve used all 10 included reviews currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

Wait for the limit to reset, then comment @coderabbitai review or push new commits to the PR.

An organization admin can change what happens after included review limits in Billing.

How do review limits work?

CodeRabbit enforces per-developer PR review limits within each organization.

For paid Pro and Pro+ reviews, CodeRabbit uses a developer's included PR review attempts over the past 7 days to set the current hourly allowance. At typical activity levels, the full plan allowance applies. Higher sustained activity can lower the allowance until earlier attempts leave the 7-day window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: ffbc4671-fcc2-4754-9494-e239f47a94c3

📥 Commits

Reviewing files that changed from the base of the PR and between 074979b and 5e3b9f1.

📒 Files selected for processing (3)
  • .changeset/optional-peer-hoist-skips-a-rejected-root-pin.md
  • pnpm/crates/resolving-deps-resolver/src/hoist_peers.rs
  • pnpm11/installing/deps-resolver/src/hoistPeers.ts

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: a42b1848-4984-4ee5-8d95-fdaa663f4700

📥 Commits

Reviewing files that changed from the base of the PR and between 8680ece and 074979b.

📒 Files selected for processing (5)
  • .changeset/optional-peer-hoist-skips-a-rejected-root-pin.md
  • pnpm/crates/resolving-deps-resolver/src/hoist_peers.rs
  • pnpm/crates/resolving-deps-resolver/src/hoist_peers/tests.rs
  • pnpm11/installing/deps-resolver/src/hoistPeers.ts
  • pnpm11/installing/deps-resolver/test/hoistPeers.test.ts
🚧 Files skipped from review as they are similar to previous changes (5)
  • pnpm/crates/resolving-deps-resolver/src/hoist_peers/tests.rs
  • pnpm/crates/resolving-deps-resolver/src/hoist_peers.rs
  • pnpm11/installing/deps-resolver/test/hoistPeers.test.ts
  • .changeset/optional-peer-hoist-skips-a-rejected-root-pin.md
  • pnpm11/installing/deps-resolver/src/hoistPeers.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 2 remain after this review.


📝 Walkthrough

Walkthrough

Optional peer hoisting now ignores incompatible workspace-root pins. Rust and TypeScript implementations select compatible preferred versions when root and peer ranges do not overlap. Regression tests and release metadata cover the behavior.

Changes

Optional peer hoisting

Layer / File(s) Summary
Hoist filtering implementation
pnpm/crates/resolving-deps-resolver/src/hoist_peers.rs, pnpm11/installing/deps-resolver/src/hoistPeers.ts
Both resolvers retain workspace-root ranges only when they intersect every requested optional-peer range.
Regression coverage and release metadata
pnpm/crates/resolving-deps-resolver/src/hoist_peers/tests.rs, pnpm11/installing/deps-resolver/test/hoistPeers.test.ts, .changeset/optional-peer-hoist-skips-a-rejected-root-pin.md
Tests cover incompatible npm: aliases and root versions accepted by only one requested range. The changeset records patch releases and documents the behavior.

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

Merge Risk: ⚪ Minimal · up to 07497

This localized resolver fix is merge-ready after normal checks and review; no actionable merge-blocking risk remains.

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

Suggested reviewers: zkochan

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

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Reviews (4): Last reviewed commit: "docs(resolver): trim the disjoint-pin ra..." | Re-trigger Greptile

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
pnpm/crates/resolving-deps-resolver/src/hoist_peers/tests.rs (1)

536-557: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Cover the every-range contract in both regression suites.

The added tests use one wanted range, so they do not prove that a root pin is ignored when it overlaps one wanted range but not another. Add the same case in both implementations: root 1.0.0, wanted ranges >=1.0.0 <3.0.0 and >=2.0.0 <4.0.0, and preferred version 2.0.0. Expect 2.0.0.

  • pnpm/crates/resolving-deps-resolver/src/hoist_peers/tests.rs#L536-L557: extend the Rust regression test with the multi-range case.
  • pnpm11/installing/deps-resolver/test/hoistPeers.test.ts#L414-L425: add the equivalent Jest assertion.

As per path instructions, REVIEW_GUIDE.md requires meaningful regression tests that fail without the fix, and pnpm/AGENTS.md requires matching TypeScript/pacquet behavior and tests.

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

In `@pnpm/crates/resolving-deps-resolver/src/hoist_peers/tests.rs` around lines
536 - 557, Extend the Rust regression test at
pnpm/crates/resolving-deps-resolver/src/hoist_peers/tests.rs:536-557 with a case
using root version 1.0.0, wanted ranges >=1.0.0 <3.0.0 and >=2.0.0 <4.0.0, and
preferred version 2.0.0, asserting 2.0.0 is selected. Add the equivalent Jest
assertion at pnpm11/installing/deps-resolver/test/hoistPeers.test.ts:414-425 so
both implementations cover the every-range contract.

Source: Path instructions

.changeset/optional-peer-hoist-skips-a-rejected-root-pin.md (1)

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

Keep the changeset user-facing and concise.

Line 7 includes implementation detail about how candidate bounds are applied. Describe the observable fix instead.

Proposed wording
- The workspace root's own dependency on a package no longer bounds an auto-installed *optional* peer when it falls outside the declared peer range. A root that pins `[email protected]` used to push that version into an importer whose only `date-fns` need was an optional `^4.0.0` peer, so pnpm reported its own resolution as unmet even though a satisfying `[email protected]` was already in the graph. The root's pin now bounds the candidates only when it overlaps the wanted range [`#13867`](https://github.com/pnpm/pnpm/issues/13867).
+ Fix optional peer resolution when a workspace root pins an incompatible version; pnpm now selects a compatible version instead of reporting the pin as an unmet peer. [`#13867`](https://github.com/pnpm/pnpm/issues/13867)

As per path instructions, changeset text must describe the user-visible resolution correction concisely and omit implementation rationale.

🤖 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 @.changeset/optional-peer-hoist-skips-a-rejected-root-pin.md at line 7,
Revise the changeset text to concisely describe the user-visible fix: optional
peer dependencies now resolve to a compatible version when the workspace root
pins an incompatible version. Remove implementation details about candidate
bounds, graph state, and resolution mechanics while retaining the issue
reference.

Source: Path instructions

🤖 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 @.changeset/optional-peer-hoist-skips-a-rejected-root-pin.md:
- Line 7: Revise the changeset text to concisely describe the user-visible fix:
optional peer dependencies now resolve to a compatible version when the
workspace root pins an incompatible version. Remove implementation details about
candidate bounds, graph state, and resolution mechanics while retaining the
issue reference.

In `@pnpm/crates/resolving-deps-resolver/src/hoist_peers/tests.rs`:
- Around line 536-557: Extend the Rust regression test at
pnpm/crates/resolving-deps-resolver/src/hoist_peers/tests.rs:536-557 with a case
using root version 1.0.0, wanted ranges >=1.0.0 <3.0.0 and >=2.0.0 <4.0.0, and
preferred version 2.0.0, asserting 2.0.0 is selected. Add the equivalent Jest
assertion at pnpm11/installing/deps-resolver/test/hoistPeers.test.ts:414-425 so
both implementations cover the every-range contract.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 9b310a37-efe2-4803-bfd6-d04e437d6b8e

📥 Commits

Reviewing files that changed from the base of the PR and between e6f2249 and 7292e40.

📒 Files selected for processing (5)
  • .changeset/optional-peer-hoist-skips-a-rejected-root-pin.md
  • pnpm/crates/resolving-deps-resolver/src/hoist_peers.rs
  • pnpm/crates/resolving-deps-resolver/src/hoist_peers/tests.rs
  • pnpm11/installing/deps-resolver/src/hoistPeers.ts
  • pnpm11/installing/deps-resolver/test/hoistPeers.test.ts

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

codecov-commenter commented Aug 12, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.19%. Comparing base (bb57938) to head (5e3b9f1).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #13869   +/-   ##
=======================================
  Coverage   88.19%   88.19%           
=======================================
  Files         646      646           
  Lines      107162   107164    +2     
=======================================
+ Hits        94509    94514    +5     
+ Misses      12653    12650    -3     

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

greptile-apps[bot]
greptile-apps Bot previously approved these changes Aug 12, 2026
@github-actions

github-actions Bot commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

Integrated-Benchmark Report (Linux)

Commit: 5e3b9f1686e8

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

The tables below show mean ± σ; Bencher thresholds on the minimum latency, which is far less perturbed by shared-runner contention (noise only adds time).

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 2.555 ± 0.157 2.362 2.784 1.77 ± 0.16
pacquet@main 2.506 ± 0.143 2.349 2.696 1.74 ± 0.15
pnpr@HEAD 1.440 ± 0.094 1.351 1.649 1.00
pnpr@main 1.550 ± 0.120 1.345 1.670 1.08 ± 0.11
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 2.55528210152,
      "stddev": 0.1567450771438212,
      "median": 2.5858442664199996,
      "user": 2.1611985999999996,
      "system": 2.01178362,
      "min": 2.36187041542,
      "max": 2.78370883942
    },
    {
      "command": "pacquet@main",
      "mean": 2.5060254170199996,
      "stddev": 0.1433545842969123,
      "median": 2.51467671592,
      "user": 2.1721180999999996,
      "system": 1.9494798199999999,
      "min": 2.3493773434199996,
      "max": 2.6957585104199997
    },
    {
      "command": "pnpr@HEAD",
      "mean": 1.4395992877200001,
      "stddev": 0.09377286939249013,
      "median": 1.41690818992,
      "user": 1.8969934,
      "system": 1.8640214199999998,
      "min": 1.3510815924200001,
      "max": 1.64936005742
    },
    {
      "command": "pnpr@main",
      "mean": 1.5503469487200001,
      "stddev": 0.12041041514913346,
      "median": 1.61650528292,
      "user": 1.7593954,
      "system": 1.64177322,
      "min": 1.34548664842,
      "max": 1.6695223414200002
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 335.7 ± 34.8 279.2 383.5 1.10 ± 0.13
pacquet@main 303.8 ± 17.8 258.0 319.1 1.00
pnpr@HEAD 334.0 ± 18.2 312.3 369.4 1.10 ± 0.09
pnpr@main 361.3 ± 23.8 337.1 416.0 1.19 ± 0.10
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.33566134577999995,
      "stddev": 0.0347696309702548,
      "median": 0.34121825088,
      "user": 0.28207213999999997,
      "system": 0.5824729200000001,
      "min": 0.27918834038,
      "max": 0.38352023438
    },
    {
      "command": "pacquet@main",
      "mean": 0.30381261447999997,
      "stddev": 0.017769033094352522,
      "median": 0.30925312738,
      "user": 0.25151793999999994,
      "system": 0.5500601199999999,
      "min": 0.25800199038,
      "max": 0.31914939538
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.33398604678000005,
      "stddev": 0.01815194305269092,
      "median": 0.33686206888000003,
      "user": 0.28317694,
      "system": 0.55684152,
      "min": 0.31230322438,
      "max": 0.36938740238
    },
    {
      "command": "pnpr@main",
      "mean": 0.36125526818000003,
      "stddev": 0.023762963103583577,
      "median": 0.35656356838000003,
      "user": 0.30548484,
      "system": 0.6083219200000001,
      "min": 0.33705371838000003,
      "max": 0.41596647138000004
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 10.0 ± 1.7 7.3 14.3 1.00
pacquet@main 10.6 ± 1.9 7.5 15.6 1.06 ± 0.26
pnpr@HEAD 11.9 ± 2.0 8.0 16.2 1.19 ± 0.28
pnpr@main 12.4 ± 2.0 7.6 15.9 1.23 ± 0.28
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.010023260733968255,
      "stddev": 0.0016623340459459447,
      "median": 0.00971498768,
      "user": 0.005993375936507935,
      "system": 0.004068308571428574,
      "min": 0.00731323268,
      "max": 0.014297380680000001
    },
    {
      "command": "pacquet@main",
      "mean": 0.010642852031020417,
      "stddev": 0.001883824429156384,
      "median": 0.010004703680000001,
      "user": 0.006450020244897958,
      "system": 0.004229565714285714,
      "min": 0.007513515680000001,
      "max": 0.015580097680000002
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.011877767213073934,
      "stddev": 0.0020209328970262857,
      "median": 0.011561114680000002,
      "user": 0.007283425603112832,
      "system": 0.004639616342412447,
      "min": 0.00801107868,
      "max": 0.01616405068
    },
    {
      "command": "pnpr@main",
      "mean": 0.012369447713149172,
      "stddev": 0.001961979219675376,
      "median": 0.012352586680000001,
      "user": 0.0074534615469613276,
      "system": 0.004955429834254145,
      "min": 0.00762619868,
      "max": 0.015940951680000003
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 8.1 ± 1.1 6.8 11.7 1.00
pacquet@main 9.4 ± 1.0 7.2 12.5 1.16 ± 0.20
pnpr@HEAD 9.2 ± 1.1 7.0 12.4 1.13 ± 0.20
pnpr@main 9.1 ± 1.0 7.3 13.2 1.12 ± 0.19
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.008094372488524588,
      "stddev": 0.0010791070568085168,
      "median": 0.007781743800000001,
      "user": 0.004848126065573772,
      "system": 0.003262613114754098,
      "min": 0.0067590703,
      "max": 0.0117203653
    },
    {
      "command": "pacquet@main",
      "mean": 0.009425750713934427,
      "stddev": 0.0010375486121216929,
      "median": 0.0093587823,
      "user": 0.005476281475409837,
      "system": 0.003909565081967211,
      "min": 0.0071795303000000005,
      "max": 0.012513894300000002
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.009180403318099547,
      "stddev": 0.0010689594311159162,
      "median": 0.0090329463,
      "user": 0.005990521900452485,
      "system": 0.003169605429864254,
      "min": 0.006980407300000001,
      "max": 0.012417960300000001
    },
    {
      "command": "pnpr@main",
      "mean": 0.00906839455378788,
      "stddev": 0.0009719634823366176,
      "median": 0.0089222178,
      "user": 0.005418727348484848,
      "system": 0.003631387878787878,
      "min": 0.007309740300000001,
      "max": 0.0131813993
    }
  ]
}

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 2.852 ± 0.064 2.757 2.993 1.79 ± 0.10
pacquet@main 2.972 ± 0.142 2.834 3.282 1.87 ± 0.13
pnpr@HEAD 1.701 ± 0.089 1.548 1.857 1.07 ± 0.08
pnpr@main 1.594 ± 0.080 1.513 1.770 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 2.8516280256799997,
      "stddev": 0.06359144074359763,
      "median": 2.85703697208,
      "user": 2.2684521399999995,
      "system": 1.70560308,
      "min": 2.75746239658,
      "max": 2.99279383958
    },
    {
      "command": "pacquet@main",
      "mean": 2.97225258678,
      "stddev": 0.14212493472066823,
      "median": 2.92070373658,
      "user": 2.5973501399999996,
      "system": 1.8783126799999998,
      "min": 2.83370660958,
      "max": 3.28214207258
    },
    {
      "command": "pnpr@HEAD",
      "mean": 1.70071306088,
      "stddev": 0.08873714951624506,
      "median": 1.68918823608,
      "user": 2.1059673399999994,
      "system": 2.0576736799999997,
      "min": 1.5477925205799998,
      "max": 1.8565357635800002
    },
    {
      "command": "pnpr@main",
      "mean": 1.59365096758,
      "stddev": 0.07981943050829003,
      "median": 1.56909633008,
      "user": 1.8551388399999997,
      "system": 1.89705528,
      "min": 1.51327778958,
      "max": 1.7704847135800001
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 442.2 ± 20.4 404.5 465.8 1.41 ± 0.09
pacquet@main 410.4 ± 21.4 375.4 445.6 1.31 ± 0.09
pnpr@HEAD 314.0 ± 12.6 298.8 334.4 1.00
pnpr@main 336.2 ± 18.4 312.8 376.2 1.07 ± 0.07
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.4421648859,
      "stddev": 0.020382273290652925,
      "median": 0.445662938,
      "user": 0.5283492599999999,
      "system": 0.6960310799999998,
      "min": 0.40445090600000005,
      "max": 0.465784152
    },
    {
      "command": "pacquet@main",
      "mean": 0.41041735530000006,
      "stddev": 0.021380970337938707,
      "median": 0.4102188915,
      "user": 0.47560836,
      "system": 0.62054098,
      "min": 0.37543993400000003,
      "max": 0.44564753100000004
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.31401932419999995,
      "stddev": 0.012640442395860207,
      "median": 0.310727609,
      "user": 0.20514095999999998,
      "system": 0.45970347999999994,
      "min": 0.298835746,
      "max": 0.334438165
    },
    {
      "command": "pnpr@main",
      "mean": 0.3362054440000001,
      "stddev": 0.01840131295039311,
      "median": 0.3350742685,
      "user": 0.22624145999999995,
      "system": 0.5014583800000001,
      "min": 0.31279386400000003,
      "max": 0.37615375900000003
    }
  ]
}

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 1.863 ± 0.036 1.805 1.918 4.99 ± 0.27
pacquet@main 1.944 ± 0.026 1.889 1.972 5.21 ± 0.27
pnpr@HEAD 0.373 ± 0.019 0.346 0.408 1.00
pnpr@main 0.377 ± 0.018 0.347 0.408 1.01 ± 0.07
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 1.8629992429200002,
      "stddev": 0.035536719395398986,
      "median": 1.8611026376200002,
      "user": 0.7472536200000001,
      "system": 0.73726244,
      "min": 1.8045111861200003,
      "max": 1.9182361701200001
    },
    {
      "command": "pacquet@main",
      "mean": 1.94377928022,
      "stddev": 0.026365387765226508,
      "median": 1.95319551362,
      "user": 0.8977622199999999,
      "system": 0.87666044,
      "min": 1.8887165791200002,
      "max": 1.9721881071200003
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.37331836332,
      "stddev": 0.018702911328836728,
      "median": 0.37046537562000004,
      "user": 0.25363182,
      "system": 0.5849226399999999,
      "min": 0.34568289512000006,
      "max": 0.40765884212000003
    },
    {
      "command": "pnpr@main",
      "mean": 0.3765658516200001,
      "stddev": 0.018361667415728863,
      "median": 0.38148117312,
      "user": 0.24309621999999997,
      "system": 0.58355884,
      "min": 0.34662731612000003,
      "max": 0.40819322012000003
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 221.7 ± 18.2 191.0 243.9 1.92 ± 0.19
pacquet@main 260.8 ± 32.9 212.1 335.0 2.26 ± 0.31
pnpr@HEAD 127.8 ± 9.7 110.9 149.3 1.11 ± 0.10
pnpr@main 115.6 ± 6.4 104.8 134.3 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.22166099313666665,
      "stddev": 0.018160345119884385,
      "median": 0.21901540772,
      "user": 0.17337158666666666,
      "system": 0.06539449,
      "min": 0.19101610522,
      "max": 0.24390362722000003
    },
    {
      "command": "pacquet@main",
      "mean": 0.26077924638666666,
      "stddev": 0.03290730504852948,
      "median": 0.25698885472,
      "user": 0.20819191999999995,
      "system": 0.09220848999999999,
      "min": 0.21210316222000003,
      "max": 0.33499629222000005
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.12781643283904764,
      "stddev": 0.009723250537845255,
      "median": 0.12711354422,
      "user": 0.042576253333333335,
      "system": 0.024806097142857145,
      "min": 0.11089653122000001,
      "max": 0.14930636622000001
    },
    {
      "command": "pnpr@main",
      "mean": 0.11562328278521739,
      "stddev": 0.006445559098985064,
      "median": 0.11433291322000001,
      "user": 0.038118398260869574,
      "system": 0.01853228347826087,
      "min": 0.10478773422000001,
      "max": 0.13429944822
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 555.9 ± 86.5 402.9 686.9 1.00
pacquet@main 589.8 ± 75.3 437.4 680.7 1.06 ± 0.21
pnpm@HEAD 3262.7 ± 328.4 2955.2 3818.0 5.87 ± 1.09
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.5558860569444445,
      "stddev": 0.08647775887028762,
      "median": 0.5526176825000001,
      "user": 0.5187372555555555,
      "system": 0.12711019999999998,
      "min": 0.40289601150000004,
      "max": 0.6868785495
    },
    {
      "command": "pacquet@main",
      "mean": 0.5897671449444445,
      "stddev": 0.07527604856349669,
      "median": 0.6129742635000001,
      "user": 0.5512544777777778,
      "system": 0.13483520000000002,
      "min": 0.43736116850000006,
      "max": 0.6807222415
    },
    {
      "command": "pnpm@HEAD",
      "mean": 3.2627269713888887,
      "stddev": 0.32838976662680297,
      "median": 3.0635967115,
      "user": 4.635881922222222,
      "system": 0.3452877555555555,
      "min": 2.9551962405,
      "max": 3.8179514685
    }
  ]
}

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 4.432 ± 0.110 4.349 4.652 1.24 ± 0.04
pacquet@main 4.467 ± 0.082 4.379 4.612 1.25 ± 0.04
pnpr@HEAD 3.583 ± 0.092 3.462 3.724 1.00
pnpr@main 3.616 ± 0.151 3.435 3.870 1.01 ± 0.05
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 4.432048168220001,
      "stddev": 0.1103540794966317,
      "median": 4.37340657872,
      "user": 1.8840705200000003,
      "system": 1.7575000799999998,
      "min": 4.34868697972,
      "max": 4.6521663357200005
    },
    {
      "command": "pacquet@main",
      "mean": 4.46739167702,
      "stddev": 0.08223539171932066,
      "median": 4.46385286922,
      "user": 2.0192281199999997,
      "system": 1.8556593799999999,
      "min": 4.37910692372,
      "max": 4.612222447720001
    },
    {
      "command": "pnpr@HEAD",
      "mean": 3.5826901821199995,
      "stddev": 0.09194363572583929,
      "median": 3.56855625022,
      "user": 2.0746510199999997,
      "system": 1.9578493799999996,
      "min": 3.4619084067199997,
      "max": 3.72385198572
    },
    {
      "command": "pnpr@main",
      "mean": 3.6155547873199994,
      "stddev": 0.1514238978305277,
      "median": 3.57366586672,
      "user": 2.0449005199999997,
      "system": 1.8998173799999996,
      "min": 3.4349028587199997,
      "max": 3.87038984072
    }
  ]
}

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. Comparable to that scenario head-to-head.

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 235.7 ± 19.3 202.1 265.0 1.07 ± 0.11
pacquet@main 234.5 ± 19.3 215.1 266.4 1.06 ± 0.11
pnpr@HEAD 248.8 ± 20.9 223.6 304.6 1.13 ± 0.12
pnpr@main 220.9 ± 15.2 201.0 245.9 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.23565292311999997,
      "stddev": 0.019260274560919763,
      "median": 0.23503419762000002,
      "user": 0.28819498,
      "system": 0.24438126,
      "min": 0.20205277312000003,
      "max": 0.26501647912000004
    },
    {
      "command": "pacquet@main",
      "mean": 0.23453112701999998,
      "stddev": 0.01933222599640003,
      "median": 0.22697065912000003,
      "user": 0.28752658,
      "system": 0.24287725999999998,
      "min": 0.21513018112,
      "max": 0.26637371012
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.24875890611999998,
      "stddev": 0.02092161515123383,
      "median": 0.24626344212,
      "user": 0.28655088,
      "system": 0.2511361509090909,
      "min": 0.22357301912000002,
      "max": 0.30457500412000005
    },
    {
      "command": "pnpr@main",
      "mean": 0.22090491812000004,
      "stddev": 0.015189998730071042,
      "median": 0.21619350712000002,
      "user": 0.2426715466666666,
      "system": 0.24088214333333335,
      "min": 0.20095541112,
      "max": 0.24585467912000003
    }
  ]
}

@github-actions

github-actions Bot commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Projectpnpm's project
Branchpr/13869
Testbedpacquet
Click to view all benchmark results
BenchmarkLatencyBenchmark Result
milliseconds (ms)
(Result Δ%)
Upper Boundary
milliseconds (ms)
(Limit %)
gvs-linker.fresh-restore.hot-cache.hot-store📈 view plot
🚷 view threshold
202.05 ms
(+12.60%)Baseline: 179.44 ms
215.33 ms
(93.83%)
isolated-linker.fresh-install.cold-cache.cold-store📈 view plot
🚷 view threshold
2,757.46 ms
(-1.19%)Baseline: 2,790.65 ms
3,348.78 ms
(82.34%)
isolated-linker.fresh-install.cold-cache.hot-store📈 view plot
🚷 view threshold
1,804.51 ms
(-6.32%)Baseline: 1,926.28 ms
2,311.54 ms
(78.07%)
isolated-linker.fresh-install.hot-cache.hot-store📈 view plot
🚷 view threshold
404.45 ms
(-11.73%)Baseline: 458.18 ms
549.82 ms
(73.56%)
isolated-linker.fresh-resolve.hot-cache.offline📈 view plot
🚷 view threshold
191.02 ms
(-11.60%)Baseline: 216.08 ms
259.30 ms
(73.67%)
isolated-linker.fresh-restore.cold-cache.cold-store📈 view plot
🚷 view threshold
2,361.87 ms
(+2.42%)Baseline: 2,306.07 ms
2,767.29 ms
(85.35%)
isolated-linker.fresh-restore.cold-cache.cold-store.cold-pnpr📈 view plot
🚷 view threshold
4,348.69 ms
(-0.03%)Baseline: 4,349.90 ms
5,219.88 ms
(83.31%)
isolated-linker.fresh-restore.hot-cache.hot-store📈 view plot
🚷 view threshold
279.19 ms
(+0.27%)Baseline: 278.42 ms
334.11 ms
(83.56%)
isolated-linker.peer-heavy-resolve.hot-cache.offline📈 view plot
🚷 view threshold
402.90 ms
(-18.43%)Baseline: 493.91 ms
592.69 ms
(67.98%)
isolated-linker.repeat-install.cold-cache.hot-store📈 view plot
🚷 view threshold
6.76 ms
(+2.22%)Baseline: 6.61 ms
7.93 ms
(85.19%)
isolated-linker.repeat-install.hot-cache.hot-store📈 view plot
🚷 view threshold
7.31 ms
(+14.79%)Baseline: 6.37 ms
7.65 ms
(95.66%)
🐰 View full continuous benchmarking report in Bencher

@github-actions

github-actions Bot commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Projectpnpm's project
Branchpr/13869
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)
gvs-linker.fresh-restore.hot-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
223.57 ms
isolated-linker.fresh-install.cold-cache.cold-store📈 view plot
⚠️ NO THRESHOLD
1,547.79 ms
isolated-linker.fresh-install.cold-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
345.68 ms
isolated-linker.fresh-install.hot-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
298.84 ms
isolated-linker.fresh-resolve.hot-cache.offline📈 view plot
⚠️ NO THRESHOLD
110.90 ms
isolated-linker.fresh-restore.cold-cache.cold-store📈 view plot
⚠️ NO THRESHOLD
1,351.08 ms
isolated-linker.fresh-restore.cold-cache.cold-store.cold-pnpr📈 view plot
⚠️ NO THRESHOLD
3,461.91 ms
isolated-linker.fresh-restore.hot-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
312.30 ms
isolated-linker.repeat-install.cold-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
6.98 ms
isolated-linker.repeat-install.hot-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
8.01 ms
🐰 View full continuous benchmarking report in Bencher

@zkochan
zkochan force-pushed the fix/issue-13867-optional-peer-root-range branch from e433c6f to 074979b Compare August 20, 2026 15:56
@coderabbitai

coderabbitai Bot commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@qodo-code-review

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

Copy link
Copy Markdown

Code Review by Qodo

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

Grey Divider


Remediation recommended

1. Extra semver parsing hot-path 🐞 Bug ➹ Performance
Description
In getHoistableOptionalPeers(), the new rootRange gate calls semver.validRange() and
semver.intersects() for every wanted range before selecting a version. This code runs inside
resolveDependencies’ hoist loop (per importer, potentially multiple rounds), so the added parsing
work can measurably increase CPU time on large workspaces.
Code

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

+    const rootSpecifierRange = rootBareSpecifier != null ? semver.validRange(getPeerVersionRange(rootBareSpecifier)) : null
+    // A root specifier disjoint from the wanted ranges bounds the candidates
+    // down to none, and the importer then falls back to the root's own
+    // out-of-range version. Such a specifier has nothing to say about this
+    // peer, so leave the candidates unbounded instead.
+    const rootRange = rootSpecifierRange != null && ranges.every(range => semver.validRange(range) != null && semver.intersects(rootSpecifierRange, range))
+      ? rootSpecifierRange
+      : null
Relevance

●● Moderate

Mixed precedent: semver parsing optimization was rejected, while broader hot-path allocation
reductions were accepted; context is not decisive.

PR-#13527
PR-#12491

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The PR adds a per-range overlap gate (validRange + intersects) to compute rootRange.
getHoistableOptionalPeers() is called from within resolveDependencies()’s iterative hoisting
loop, which can run multiple rounds across multiple importers, making additional semver
parsing/intersection work a potential CPU cost increase on large workspaces.

pnpm11/installing/deps-resolver/src/hoistPeers.ts[104-135]
pnpm11/installing/deps-resolver/src/resolveDependencies.ts[478-496]

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

### Issue description
`getHoistableOptionalPeers()` now computes `rootRange` by iterating `ranges` and calling `semver.validRange()` and `semver.intersects()` for each entry. This is additional semver parsing/intersection work that sits on a resolver hot path (executed per importer and per hoist round).

### Issue Context
This PR introduces the overlap gate:
- It is executed once per missing optional peer name.
- `getHoistableOptionalPeers()` is invoked inside the peer-hoisting loop in `resolveDependencies()`.

### Fix Focus Areas
- pnpm11/installing/deps-resolver/src/hoistPeers.ts[114-135]
- pnpm11/installing/deps-resolver/src/resolveDependencies.ts[478-496]

### Suggested fix
1. Pre-parse and cache the wanted ranges once per peer, and reuse the parsed/normalized representations:
  - e.g., `const wantedRanges = ranges.map(r => semver.validRange(r)).filter((r): r is string => r != null)` and ensure length matches `ranges.length`.
2. Use the cached `wantedRanges` both for:
  - the overlap check (`semver.intersects(rootSpecifierRange, wantedRange)`)
  - the satisfaction check in the version loop (`semver.satisfies(version, wantedRange)`), avoiding reparsing the original `ranges` strings.
3. Keep semantics identical (still only apply the root bound when it overlaps *every* wanted range).

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


Grey Divider

Context sources
✅ Compliance rules (platform): 27 rules

Grey Divider

Tip of the day
💡 Did you know, you can type 'qodo, fix this' on a finding and the fix lands right on your PR

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

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

No code suggestions found for the PR.

The comment blocks narrated behavior the regression tests already pin,
and the changeset carried resolver mechanics that belong in the commit
message rather than a release note.

Co-Authored-By: Claude Fable 5 <[email protected]>
@greptile-apps
greptile-apps Bot dismissed their stale review August 20, 2026 16:05

Dismissed because a newer commit was pushed; Greptile will re-review the current head.

@qodo-code-review

Copy link
Copy Markdown

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

@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 merged commit 4a563ba into pnpm:main Aug 31, 2026
41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Root-supplied optional peer ignores the declared peer range (regression in 11.18.0)

3 participants