Skip to content

fix: reuse the version resolution would dedupe onto for a changed range - #13779

Merged
zkochan merged 3 commits into
mainfrom
locked-range
Aug 10, 2026
Merged

zkochan merged 3 commits into
mainfrom
locked-range

Conversation

@zkochan

@zkochan zkochan commented Aug 10, 2026 •

Copy link
Copy Markdown
Member

Summary

Closes #13778. Item 4 of #13696.

Item 4 asked for a range change to reuse a version already in the lockfile instead of resolving. Establishing that the resolver actually behaves that way turned up a bug in the shipped fast path, and both turn out to be the same rule.

What resolution actually does (measured, not assumed — three probes against the real resolver):

setup new range resolution picks
sibling locks [email protected], registry has 1.3.0 ^1.1.0 1.2.0 — a locked version beats a higher published one
siblings lock 1.1.0 and 1.2.0 ^1.1.0 1.2.0 — the highest locked satisfying version
[email protected] present only as a transitive dep, importer locks 100.0.0 >=100.0.0 100.1.0, and 100.0.0 is pruned

preferredVersions makes the resolver dedupe onto what the graph already holds. The fast path asked a different question — "does the locked version satisfy?" — and kept it whenever it did. The third row is where that diverges: the fast path leaves the importer on 100.0.0 and keeps a duplicate foo the resolver would have collapsed. That is #13778, present since the original fast-update work, not introduced here.

The fix, in both stacks: pick the highest version of the alias already in the lockfile that satisfies the new range, and let the shared epilogue prune whatever the move orphans. That repairs the widening case and closes item 4 (a range only an already-present version satisfies) in one rule. Bails kept for a candidate that exists under peer-suffixed keys — choosing one would be a guess — and for anything that is not plain semver.

Tested at install level in TypeScript (all three rows, asserting zero requestPackage calls, plus a fall-back case where nothing present satisfies) and as unit tests in pacquet.

Squash Commit Body

The importers fast update asked whether the locked version satisfies
the new range and kept it when it did. Resolution asks a different
question: preferredVersions makes it reuse the highest version of that
alias already in the graph, which beats picking the highest published
one. The two answers differ whenever some other importer or transitive
dependency already holds a higher satisfying version, so widening a
range through the fast path left the importer behind and kept a
duplicate the resolver would have collapsed.

Both stacks now pick the highest already-locked satisfying version,
letting the shared epilogue prune whatever the move orphans. That also
covers a range the locked version cannot satisfy at all but a present
one can, which no longer falls back to the resolver.

Bails kept for a candidate under peer-suffixed keys (the choice would
be a guess) and for anything that is not plain semver.

Closes pnpm/pnpm#13778. Item 4 of pnpm/pnpm#13696.

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.

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


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
    • Improved dependency updates to reuse the highest compatible version already recorded in the lockfile.
    • Prevented duplicate locked versions when widening dependency ranges.
    • Correctly handles ranges satisfied only by existing locked versions without unnecessary re-resolution.
    • Removes outdated, unreachable dependency entries during updates.
    • Falls back to resolution when no compatible locked version is available.
    • Avoids reusing ambiguous peer- or registry-qualified package entries.

The importers fast update asked whether the locked version satisfies
the new range and kept it when it did. Resolution asks a different
question: preferredVersions makes it reuse the highest version of that
alias already in the graph, which beats picking the highest published
one. The two answers differ whenever some other importer or transitive
dependency already holds a higher satisfying version, so widening a
range through the fast path left the importer behind and kept a
duplicate the resolver would have collapsed.

Both stacks now pick the highest already-locked satisfying version,
letting the shared epilogue prune whatever the move orphans. That also
covers a range the locked version cannot satisfy at all but a present
one can, which no longer falls back to the resolver.

Bails kept for a candidate under peer-suffixed keys (the choice would
be a guess) and for anything that is not plain semver.

Closes #13778. Item 4 of #13696.
Copilot AI lite review requested due to automatic review settings August 10, 2026 17:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 849694f0-bb47-46c7-bfc9-fb5cb3ea77e3

📥 Commits

Reviewing files that changed from the base of the PR and between 8be080f and cb2b66c.

📒 Files selected for processing (4)
  • pnpm/crates/package-manager/src/fast_update_importers.rs
  • pnpm/crates/package-manager/src/fast_update_importers/tests.rs
  • pnpm11/installing/deps-installer/src/install/tryFastUpdateImporters.ts
  • pnpm11/installing/deps-installer/test/install/lockedVersionReuse.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • pnpm/crates/package-manager/src/fast_update_importers.rs
  • pnpm11/installing/deps-installer/src/install/tryFastUpdateImporters.ts
  • pnpm/crates/package-manager/src/fast_update_importers/tests.rs

📝 Walkthrough

Walkthrough

Fast importer updates in Rust and TypeScript now reuse the highest compatible non-peer version already in the lockfile. They update references, prune replaced entries, and fall back to resolution when no safe locked version exists. Tests cover reuse, deduplication, pruning, and resolution.

Changes

Locked Version Reuse

Layer / File(s) Summary
Rust locked-version selection
pnpm/crates/package-manager/src/fast_update_importers.rs, pnpm/crates/package-manager/src/fast_update_importers/tests.rs
The Rust updater selects the highest compatible locked version, replaces changed dependency references, records dropped aliases, and validates reuse, rejection, and fallback cases.
TypeScript locked-version selection
pnpm11/installing/deps-installer/src/install/tryFastUpdateImporters.ts, pnpm11/installing/deps-installer/test/install/lockedVersionReuse.ts
The TypeScript updater scans lockfile snapshots for reusable versions, updates importer entries, prunes lower versions, and requests resolution when no match exists.
Release metadata
.changeset/locked-version-reuse.md
The changeset records patch releases and documents the locked-version reuse behavior.

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

Possibly related issues

Possibly related PRs

  • pnpm/pnpm#13464 — Modifies fast lockfile updates to reuse compatible locked versions.
  • pnpm/pnpm#13477 — Extends related fast importer logic to select the highest compatible locked version.
  • pnpm/pnpm#13761 — Modifies fast_update_importers for related lockfile update behavior.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch locked-range

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration.


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

❤️ Share

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

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Fix fast lockfile update to reuse highest locked version on range changes

🐞 Bug fix 🧪 Tests 📝 Documentation 🕐 40+ Minutes

Grey Divider

AI Description

• Reuse the highest already-locked satisfying version when a dependency range changes.
• Align fast-update behavior with full resolution/dedupe semantics and prune orphaned duplicates.
• Add unit and install-level tests for widening, reuse, and resolver fallback cases.
Diagram

graph TD
  M["Manifest range change"] --> TS["TS fast update"] --> H["Pick highest locked satisfying"] --> L[("Lockfile packages")] --> E["Graph edits (dropped)"] --> P["Shared prune epilogue"]
  M --> RS["Rust fast update"] --> H
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Always fall back to full resolver on any range change
  • ➕ Single source of truth for version choice and dedupe behavior
  • ➕ Avoids maintaining two implementations (Rust/TS) of the same rule
  • ➖ More network/registry work and slower lockfile updates
  • ➖ Misses the optimization goal of fast-update paths
2. Attempt to choose among peer-suffixed locked candidates instead of bailing
  • ➕ Fewer cases fall back to resolver when peer variants exist
  • ➖ High risk of choosing the wrong peer context; can create incorrect lockfile state
  • ➖ Would need additional peer-graph context to be safe
3. Centralize the 'highest locked satisfying' rule into a shared utility per stack
  • ➕ Reduces duplication between fast-update callers within each language stack
  • ➕ Makes future behavior changes less error-prone
  • ➖ Does not eliminate cross-language duplication (Rust vs TS)
  • ➖ May require refactors that are larger than this bug fix

Recommendation: The chosen approach is the best tradeoff: it matches resolver semantics (reuse/dedupe onto the highest already-present satisfying version) while preserving fast-path performance. Keeping conservative bails for peer-suffixed keys and non-semver avoids correctness risks where the fast path lacks enough context to safely pick a candidate.

Files changed (5) +313 / -17

Bug fix (2) +103 / -17
fast_update_importers.rsSelect highest locked satisfying version during importer fast update +59/-7

Select highest locked satisfying version during importer fast update

• Updates the Rust fast-update logic to compute the resolver-equivalent target version when a specifier changes. Adds helper 'highest_locked_version_satisfying' that scans lockfile packages, bails on peer-suffixed/non-semver entries, and updates the importer version plus dropped set for pruning.

pnpm/crates/package-manager/src/fast_update_importers.rs

tryFastUpdateImporters.tsAlign TS fast-update range handling with resolver dedupe behavior +44/-10

Align TS fast-update range handling with resolver dedupe behavior

• Replaces the old 'locked version satisfies' check with 'highestLockedVersionSatisfying', which scans lockfile packages and picks the highest satisfying locked version. Keeps conservative bailouts for peer-suffixed keys and non-semver versions, and marks moved aliases as dropped for shared pruning.

pnpm11/installing/deps-installer/src/install/tryFastUpdateImporters.ts

Tests (2) +203 / -0
tests.rsAdd unit tests for widened range reuse and resolver fallback +89/-0

Add unit tests for widened range reuse and resolver fallback

• Adds lockfile fixtures and tests ensuring a widened range moves to the highest already-locked satisfying version, even if the current locked version still satisfies. Verifies fast update rejects ranges when no locked version satisfies.

pnpm/crates/package-manager/src/fast_update_importers/tests.rs

lockedVersionReuse.tsAdd install-level regression tests for locked-version reuse +114/-0

Add install-level regression tests for locked-version reuse

• Introduces workspace install tests covering: moving to a higher version locked by another importer, moving to a higher transitive-locked version, and falling back to resolver when no locked version satisfies. Asserts zero 'requestPackage' calls in reuse cases.

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

Documentation (1) +7 / -0
locked-version-reuse.mdAdd changeset for locked-version reuse on range widening +7/-0

Add changeset for locked-version reuse on range widening

• Introduces a changeset describing the behavioral fix: range widening now reuses the highest locked satisfying version and avoids duplicate packages, matching full resolution behavior.

.changeset/locked-version-reuse.md

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

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

Inline comments:
In `@pnpm/crates/package-manager/src/fast_update_importers.rs`:
- Line 66: Update the fast update flow around candidate.packages to borrow the
package map instead of cloning all package metadata. Preserve the empty-map
fallback without allocating or copying the full collection, while allowing
candidate.importers to be mutated through disjoint field access.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 5727f271-ca44-4fbc-8a91-8c08c7405a5f

📥 Commits

Reviewing files that changed from the base of the PR and between 9f71dda and 8be080f.

📒 Files selected for processing (5)
  • .changeset/locked-version-reuse.md
  • pnpm/crates/package-manager/src/fast_update_importers.rs
  • pnpm/crates/package-manager/src/fast_update_importers/tests.rs
  • pnpm11/installing/deps-installer/src/install/tryFastUpdateImporters.ts
  • pnpm11/installing/deps-installer/test/install/lockedVersionReuse.ts

@greptile-apps

greptile-apps Bot commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Reviews (2): Last reviewed commit: "fix: exclude registry-qualified keys fro..." | Re-trigger Greptile

@qodo-code-review

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

Copy link
Copy Markdown

Code Review by Qodo

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

Grey Divider


Remediation recommended

1. Missing snapshot validation 🐞 Bug ☼ Reliability ⭐ New
Description
Rust fast-update now chooses wanted by scanning lockfile.packages only, but it never verifies
that the corresponding lockfile.snapshots entry exists for that package key (i.e. that the
dependency subtree is present). With a malformed/inconsistent lockfile, this can repoint an importer
to a version whose snapshot is missing, producing a lockfile state that later graph maintenance
silently skips rather than safely falling back.
Code

pnpm/crates/package-manager/src/fast_update_importers.rs[R86-89]

+                let Some(wanted) =
+                    highest_locked_version_satisfying(packages.as_ref(), alias, &range)
+                else {
                    return false;
Relevance

●●● Strong

Team often adds conservative fast-path guards when lockfile sections are missing/inconsistent;
missing snapshot should trigger fallback.

PR-#13477
PR-#13349

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The new fast-update selection is based on packages alone, while the lockfile stores packages and
snapshots separately and pruning/traversal uses snapshots and silently skips missing entries, so
there is no guard that the chosen version’s subtree exists.

pnpm/crates/package-manager/src/fast_update_importers.rs[76-103]
pnpm/crates/package-manager/src/fast_update_importers.rs[115-146]
pnpm/crates/lockfile/src/lib.rs[159-177]
pnpm/crates/package-manager/src/fast_update_lockfile.rs[61-99]

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

## Issue description
`apply_importers_update()` selects a target version using `highest_locked_version_satisfying(packages, ...)`, but this only looks at `Lockfile.packages` and does not ensure the corresponding `Lockfile.snapshots` entry exists. The fast path then assumes the target is "already in the lockfile, subtree and all".

Because `packages` and `snapshots` are separate optional maps, a malformed or inconsistent lockfile can contain metadata keys without a matching snapshot. In that case, the fast update may repoint an importer to a version whose snapshot is missing, leaving an inconsistent graph state that later maintenance traversals skip rather than rejecting.

## Issue Context
The lockfile structure has independent `packages` and `snapshots` maps, and graph pruning/traversal relies on `snapshots`.

## Fix Focus Areas
- pnpm/crates/package-manager/src/fast_update_importers.rs[86-90]
- pnpm/crates/package-manager/src/fast_update_importers.rs[127-146]

## Implementation notes
- Extend `highest_locked_version_satisfying` to also accept `snapshots: Option<&HashMap<PackageKey, SnapshotEntry>>` (or alternatively iterate `snapshots.keys()` instead of `packages.keys()`).
- Only consider a candidate version if a matching snapshot exists for the (non-peer-suffixed) key.
- If `snapshots` is `None`, return `None` (force fallback), since the fast path can’t guarantee the subtree is present.

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


2. Repeated lockfile scan per change 🐞 Bug ➹ Performance
Description
In TypeScript, highestLockedVersionSatisfying() scans all lockfile.packages entries for each changed
specifier, performs redundant depPath parsing, and allocates+sorts versions just to pick the
maximum. This can turn a multi-dependency update into O(changedDeps × totalPackages) work in a
performance-sensitive code path.
Code

pnpm11/installing/deps-installer/src/install/tryFastUpdateImporters.ts[R118-122]

+  const versions = new Set<string>()
+  for (const [depPath, snapshot] of Object.entries(lockfile.packages ?? {})) {
+    const { name, version, nonSemverVersion } = nameVerFromPkgSnapshot(depPath, snapshot)
+    if (name !== alias || nonSemverVersion != null) continue
+    if (dp.parseDepPath(depPath).peerDepGraphHash !== '') return null
Relevance

●● Moderate

Team has rejected similar “avoid repeated lockfile scans” optimizations; unclear if this hotspot is
worth refactor now.

PR-#13600
PR-#13477

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The new helper performs a full packages scan and extra parsing/sorting work per changed alias. The
lockfile utility already parses depPath and exposes peerDepGraphHash, making the additional parse
redundant; the review guide calls out repeated parsing/scans in lockfile loops as a performance
risk.

pnpm11/installing/deps-installer/src/install/tryFastUpdateImporters.ts[113-129]
pnpm11/lockfile/utils/src/nameVerFromPkgSnapshot.ts[14-25]
REVIEW_GUIDE.md[115-127]

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

### Issue description
`highestLockedVersionSatisfying()` currently:
- iterates `Object.entries(lockfile.packages ?? {})` for every changed dependency,
- parses `depPath` via `nameVerFromPkgSnapshot()` and then parses it again via `dp.parseDepPath()`,
- collects versions into a `Set` and sorts them to choose the max.

This is avoidable work on the fast-update path.

### Issue Context
`nameVerFromPkgSnapshot()` already calls `dp.parse(depPath)` and returns `peerDepGraphHash`, so the extra `dp.parseDepPath(depPath)` repeats parsing.

### Fix Focus Areas
- pnpm11/installing/deps-installer/src/install/tryFastUpdateImporters.ts[113-129]
- pnpm11/lockfile/utils/src/nameVerFromPkgSnapshot.ts[14-25]

### Suggested direction
- Replace the `Set` + `sort` with a running maximum (track `best: string | null` and use `semver.gt`/`semver.rcompare` logic).
- Use `peerDepGraphHash` from `nameVerFromPkgSnapshot()` instead of `dp.parseDepPath()`.
- If multiple specifiers can change in one call, consider scanning `lockfile.packages` once and building an index keyed by package name (and whether any peer-suffixed key exists), then answering each alias query from that index.

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


3. Eager packages map clone ✓ Resolved 🐞 Bug ➹ Performance
Description
In Rust, apply_importers_update() now clones candidate.packages unconditionally, duplicating
potentially large lockfile metadata even when no specifier change ends up needing it. This adds
avoidable CPU+memory overhead to pnpm’s install/update fast path.
Code

pnpm/crates/package-manager/src/fast_update_importers.rs[66]

+    let packages = candidate.packages.clone().unwrap_or_default();
Relevance

●● Moderate

Perf micro-opts on fast paths were previously rejected; but cloning packages map here may be
revisited if proven hot.

PR-#13600
PR-#13689

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The PR introduces an unconditional clone of the full packages map, and this sits on the fast-update
path whose goal is to avoid expensive work; the review guide explicitly warns against repeated
scans/allocations in lockfile handling hot paths.

pnpm/crates/package-manager/src/fast_update_importers.rs[61-113]
pnpm/crates/package-manager/src/fast_update_compose.rs[70-76]
REVIEW_GUIDE.md[115-127]

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

### Issue description
`apply_importers_update()` clones `candidate.packages` unconditionally. For large lockfiles this duplicates a big `HashMap<PackageKey, PackageMetadata>` even when we only need read access to look up versions, creating avoidable work in a hot path.

### Issue Context
`try_compose_fast_updates()` already clones the whole lockfile into `candidate`; the additional `packages.clone()` is a second deep-ish clone of the largest structure in the lockfile.

### Fix Focus Areas
- pnpm/crates/package-manager/src/fast_update_importers.rs[61-113]
- pnpm/crates/package-manager/src/fast_update_compose.rs[70-76]

### Suggested direction
- Avoid cloning `packages` by restructuring to temporarily borrow `candidate.packages` immutably only when needed (e.g. compute `wanted` in a scope before taking a mutable borrow of importer dependency), or by collecting a lightweight index (e.g. per-alias list of versions / max version) once without cloning full metadata values.
- If borrow checker constraints are the motivation, consider extracting the needed key information (name/version/peer suffix) into a small `Vec` or per-alias map rather than cloning `PackageMetadata`.

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



Informational

4. Missing trailing comma specifier 📘 Rule violation ⚙ Maintainability
Description
The multi-line parameter list in highestLockedVersionSatisfying omits a trailing comma after the
last parameter. This violates the repository’s TypeScript trailing-comma style rule and makes future
diffs noisier.
Code

pnpm11/installing/deps-installer/src/install/tryFastUpdateImporters.ts[R116-117]

+  specifier: string
+): string | null {
Relevance

● Weak

Trailing-comma “rule” suggestions in multi-line TS signatures have recent explicit rejections in
this repo.

PR-#13600
PR-#13482
PR-#13689

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
PR Compliance ID 713434 requires trailing commas in multi-line TypeScript constructs. The function
signature lists parameters on separate lines, but the last parameter specifier: string has no
trailing comma before the closing ).

Rule 713434: Require trailing commas in TypeScript collections and multi-line constructs
pnpm11/installing/deps-installer/src/install/tryFastUpdateImporters.ts[114-118]

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 multi-line TypeScript function parameter list is missing a trailing comma on the last parameter.

## Issue Context
Per the repo rule, multi-line constructs (including parameter lists) should include a trailing comma on the final item.

## Fix Focus Areas
- pnpm11/installing/deps-installer/src/install/tryFastUpdateImporters.ts[114-118]

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


Grey Divider

Context used
✅ Compliance rules (platform): 26 rules

Grey Divider

Tip of the day
💡 Did you know, you can reply 'qodo' on any finding to push back, ask questions, or dig deeper

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Previous review results

Review updated until commit cb2b66c

Results up to commit 8be080f ⚖️ Balanced


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


Remediation recommended
1. Repeated lockfile scan per change 🐞 Bug ➹ Performance
Description
In TypeScript, highestLockedVersionSatisfying() scans all lockfile.packages entries for each changed
specifier, performs redundant depPath parsing, and allocates+sorts versions just to pick the
maximum. This can turn a multi-dependency update into O(changedDeps × totalPackages) work in a
performance-sensitive code path.
Code

pnpm11/installing/deps-installer/src/install/tryFastUpdateImporters.ts[R118-122]

+  const versions = new Set<string>()
+  for (const [depPath, snapshot] of Object.entries(lockfile.packages ?? {})) {
+    const { name, version, nonSemverVersion } = nameVerFromPkgSnapshot(depPath, snapshot)
+    if (name !== alias || nonSemverVersion != null) continue
+    if (dp.parseDepPath(depPath).peerDepGraphHash !== '') return null
Relevance

●● Moderate

Team has rejected similar “avoid repeated lockfile scans” optimizations; unclear if this hotspot is
worth refactor now.

PR-#13600
PR-#13477

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The new helper performs a full packages scan and extra parsing/sorting work per changed alias. The
lockfile utility already parses depPath and exposes peerDepGraphHash, making the additional parse
redundant; the review guide calls out repeated parsing/scans in lockfile loops as a performance
risk.

pnpm11/installing/deps-installer/src/install/tryFastUpdateImporters.ts[113-129]
pnpm11/lockfile/utils/src/nameVerFromPkgSnapshot.ts[14-25]
REVIEW_GUIDE.md[115-127]

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

### Issue description
`highestLockedVersionSatisfying()` currently:
- iterates `Object.entries(lockfile.packages ?? {})` for every changed dependency,
- parses `depPath` via `nameVerFromPkgSnapshot()` and then parses it again via `dp.parseDepPath()`,
- collects versions into a `Set` and sorts them to choose the max.

This is avoidable work on the fast-update path.

### Issue Context
`nameVerFromPkgSnapshot()` already calls `dp.parse(depPath)` and returns `peerDepGraphHash`, so the extra `dp.parseDepPath(depPath)` repeats parsing.

### Fix Focus Areas
- pnpm11/installing/deps-installer/src/install/tryFastUpdateImporters.ts[113-129]
- pnpm11/lockfile/utils/src/nameVerFromPkgSnapshot.ts[14-25]

### Suggested direction
- Replace the `Set` + `sort` with a running maximum (track `best: string | null` and use `semver.gt`/`semver.rcompare` logic).
- Use `peerDepGraphHash` from `nameVerFromPkgSnapshot()` instead of `dp.parseDepPath()`.
- If multiple specifiers can change in one call, consider scanning `lockfile.packages` once and building an index keyed by package name (and whether any peer-suffixed key exists), then answering each alias query from that index.

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


2. Eager packages map clone ✓ Resolved 🐞 Bug ➹ Performance
Description
In Rust, apply_importers_update() now clones candidate.packages unconditionally, duplicating
potentially large lockfile metadata even when no specifier change ends up needing it. This adds
avoidable CPU+memory overhead to pnpm’s install/update fast path.
Code

pnpm/crates/package-manager/src/fast_update_importers.rs[66]

+    let packages = candidate.packages.clone().unwrap_or_default();
Relevance

●● Moderate

Perf micro-opts on fast paths were previously rejected; but cloning packages map here may be
revisited if proven hot.

PR-#13600
PR-#13689

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The PR introduces an unconditional clone of the full packages map, and this sits on the fast-update
path whose goal is to avoid expensive work; the review guide explicitly warns against repeated
scans/allocations in lockfile handling hot paths.

pnpm/crates/package-manager/src/fast_update_importers.rs[61-113]
pnpm/crates/package-manager/src/fast_update_compose.rs[70-76]
REVIEW_GUIDE.md[115-127]

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

### Issue description
`apply_importers_update()` clones `candidate.packages` unconditionally. For large lockfiles this duplicates a big `HashMap<PackageKey, PackageMetadata>` even when we only need read access to look up versions, creating avoidable work in a hot path.

### Issue Context
`try_compose_fast_updates()` already clones the whole lockfile into `candidate`; the additional `packages.clone()` is a second deep-ish clone of the largest structure in the lockfile.

### Fix Focus Areas
- pnpm/crates/package-manager/src/fast_update_importers.rs[61-113]
- pnpm/crates/package-manager/src/fast_update_compose.rs[70-76]

### Suggested direction
- Avoid cloning `packages` by restructuring to temporarily borrow `candidate.packages` immutably only when needed (e.g. compute `wanted` in a scope before taking a mutable borrow of importer dependency), or by collecting a lightweight index (e.g. per-alias list of versions / max version) once without cloning full metadata values.
- If borrow checker constraints are the motivation, consider extracting the needed key information (name/version/peer suffix) into a small `Vec` or per-alias map rather than cloning `PackageMetadata`.

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



Informational
3. Missing trailing comma specifier 📘 Rule violation ⚙ Maintainability
Description
The multi-line parameter list in highestLockedVersionSatisfying omits a trailing comma after the
last parameter. This violates the repository’s TypeScript trailing-comma style rule and makes future
diffs noisier.
Code

pnpm11/installing/deps-installer/src/install/tryFastUpdateImporters.ts[R116-117]

+  specifier: string
+): string | null {
Relevance

● Weak

Trailing-comma “rule” suggestions in multi-line TS signatures have recent explicit rejections in
this repo.

PR-#13600
PR-#13482
PR-#13689

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
PR Compliance ID 713434 requires trailing commas in multi-line TypeScript constructs. The function
signature lists parameters on separate lines, but the last parameter specifier: string has no
trailing comma before the closing ).

Rule 713434: Require trailing commas in TypeScript collections and multi-line constructs
pnpm11/installing/deps-installer/src/install/tryFastUpdateImporters.ts[114-118]

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 multi-line TypeScript function parameter list is missing a trailing comma on the last parameter.

## Issue Context
Per the repo rule, multi-line constructs (including parameter lists) should include a trailing comma on the final item.

## Fix Focus Areas
- pnpm11/installing/deps-installer/src/install/tryFastUpdateImporters.ts[114-118]

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


Qodo Logo

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

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

No code suggestions found for the PR.

@github-actions

github-actions Bot commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

Micro-Benchmark Results

Linux

group                                            main                                   pr
-----                                            ----                                   --
lockfile/parse_pnpm_lock                         1.00     16.9±2.29ms    22.2 MB/sec    1.06     17.9±2.32ms    20.9 MB/sec
packument/parse                                  1.00     47.9±1.79µs  1383.9 MB/sec    1.05     50.3±1.72µs  1318.5 MB/sec
tarball/download_dependency                      1.01      3.4±0.38ms  1292.5 KB/sec    1.00      3.3±0.54ms  1301.9 KB/sec
tarball_batch/cold_store_many_medium_tarballs    1.01   238.1±12.60ms 67.2 KElem/sec    1.00   236.6±15.08ms 67.6 KElem/sec
workspace_resolution/hoist_heavy                 1.00   352.4±16.35ms        ? ?/sec    1.11   391.0±26.16ms        ? ?/sec

@codecov-commenter

codecov-commenter commented Aug 10, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.88889% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.16%. Comparing base (e7e79d9) to head (cb2b66c).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...rates/package-manager/src/fast_update_importers.rs 88.88% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #13779      +/-   ##
==========================================
+ Coverage   88.13%   88.16%   +0.03%     
==========================================
  Files         623      623              
  Lines      101413   101523     +110     
==========================================
+ Hits        89383    89511     +128     
+ Misses      12030    12012      -18     

☔ 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 Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

Integrated-Benchmark Report (Linux)

Commit: cb2b66c74685

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.594 ± 0.156 2.403 2.885 1.69 ± 0.15
pacquet@main 2.707 ± 0.155 2.527 2.981 1.76 ± 0.16
pnpr@HEAD 1.537 ± 0.105 1.402 1.740 1.00
pnpr@main 1.552 ± 0.160 1.397 1.857 1.01 ± 0.12
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 2.5943583070800003,
      "stddev": 0.1559280493876055,
      "median": 2.5467727250800003,
      "user": 2.3949281399999998,
      "system": 1.78828046,
      "min": 2.40286920708,
      "max": 2.8845650380800003,
      "times": [
        2.5270574280800004,
        2.65778230108,
        2.49123154208,
        2.4597243520800003,
        2.40286920708,
        2.56648802208,
        2.79949385408,
        2.48452121608,
        2.66985011008,
        2.8845650380800003
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 2.70703286688,
      "stddev": 0.15464563869776807,
      "median": 2.7467743765800003,
      "user": 2.3868980399999997,
      "system": 1.80588636,
      "min": 2.5270360020800005,
      "max": 2.9810523530800004,
      "times": [
        2.55551629608,
        2.5669593820800003,
        2.9810523530800004,
        2.5326796880800004,
        2.72706217808,
        2.79383417208,
        2.76648657508,
        2.8427258020800004,
        2.5270360020800005,
        2.7769762200800003
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 1.5368504896800002,
      "stddev": 0.10508635368629138,
      "median": 1.5295848590799999,
      "user": 1.45280894,
      "system": 1.38629156,
      "min": 1.40185695908,
      "max": 1.73983603808,
      "times": [
        1.5306419650799998,
        1.56285636808,
        1.67574145508,
        1.43362772708,
        1.73983603808,
        1.45569781308,
        1.40185695908,
        1.48769591708,
        1.5285277530799999,
        1.55202290108
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 1.5519914188800001,
      "stddev": 0.15974449041755545,
      "median": 1.50965169658,
      "user": 1.3972507399999998,
      "system": 1.33891986,
      "min": 1.39706239208,
      "max": 1.85744889208,
      "times": [
        1.6779910740800001,
        1.49456822608,
        1.40104996508,
        1.52473516708,
        1.40913774708,
        1.44290552108,
        1.57066391408,
        1.39706239208,
        1.85744889208,
        1.74435129008
      ]
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 270.2 ± 12.7 248.2 287.1 1.00
pacquet@main 321.4 ± 20.0 304.0 362.4 1.19 ± 0.09
pnpr@HEAD 343.1 ± 56.5 287.9 475.4 1.27 ± 0.22
pnpr@main 344.8 ± 23.3 296.5 367.0 1.28 ± 0.10
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.27020800601999995,
      "stddev": 0.012691491601364775,
      "median": 0.26877020662,
      "user": 0.23927298000000002,
      "system": 0.53071012,
      "min": 0.24819239862000003,
      "max": 0.28711415862,
      "times": [
        0.28711415862,
        0.27032286362,
        0.28100440962,
        0.27536233862,
        0.26152848761999997,
        0.25763568861999997,
        0.24819239862000003,
        0.26671656162,
        0.26721754962,
        0.28698560362
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 0.32144103172,
      "stddev": 0.01996771106185293,
      "median": 0.31283904512000005,
      "user": 0.29255628,
      "system": 0.64262722,
      "min": 0.30401365662,
      "max": 0.36241991262,
      "times": [
        0.34353103062,
        0.36241991262,
        0.32925337062,
        0.30702160562,
        0.33269891762,
        0.31637872162,
        0.30569592362,
        0.30401365662,
        0.30929936862,
        0.30409780962
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.34314308482,
      "stddev": 0.05646020994928592,
      "median": 0.32613357612000005,
      "user": 0.29562237999999996,
      "system": 0.64383152,
      "min": 0.28785396562,
      "max": 0.47538486862,
      "times": [
        0.32814789762,
        0.30328720362,
        0.31310390562,
        0.30190459662,
        0.28785396562,
        0.32411925462,
        0.39060118862,
        0.37472035962,
        0.47538486862,
        0.33230760762
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.34479653961999995,
      "stddev": 0.0232714026193789,
      "median": 0.35155384662,
      "user": 0.2905865799999999,
      "system": 0.64575602,
      "min": 0.29645606862,
      "max": 0.36698906062000003,
      "times": [
        0.35938135362,
        0.36698906062000003,
        0.34633631062,
        0.33607343262,
        0.34417641162,
        0.36092993862,
        0.35677138262,
        0.36603097262,
        0.31482046462,
        0.29645606862
      ]
    }
  ]
}

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 2.664 ± 0.069 2.580 2.758 1.69 ± 0.16
pacquet@main 2.590 ± 0.027 2.572 2.660 1.65 ± 0.15
pnpr@HEAD 1.635 ± 0.166 1.429 1.823 1.04 ± 0.14
pnpr@main 1.574 ± 0.144 1.437 1.861 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 2.6642999664,
      "stddev": 0.06920456220972428,
      "median": 2.6762079743999996,
      "user": 2.00797248,
      "system": 1.57450344,
      "min": 2.5800057619,
      "max": 2.7581004289,
      "times": [
        2.7449133699,
        2.7372724409,
        2.7581004289,
        2.6855364848999996,
        2.6830343719,
        2.6693815768999998,
        2.6032732518999997,
        2.5917418719,
        2.5800057619,
        2.5897401048999997
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 2.5903235170000003,
      "stddev": 0.026770175421694086,
      "median": 2.5809057884,
      "user": 1.73107678,
      "system": 1.38570854,
      "min": 2.5716532099,
      "max": 2.6602847629,
      "times": [
        2.5943331429,
        2.5994174559,
        2.5775496198999996,
        2.5842619569,
        2.6602847629,
        2.5716532099,
        2.5958999338999997,
        2.5751445699,
        2.5723542649,
        2.5723362529
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 1.6346251160999998,
      "stddev": 0.16635328104976446,
      "median": 1.6253905209000001,
      "user": 1.2060152800000001,
      "system": 1.1774724399999998,
      "min": 1.4288936729000001,
      "max": 1.8232203489000003,
      "times": [
        1.4968873979000001,
        1.4694578089,
        1.4682601009,
        1.7873995859,
        1.7019998039000002,
        1.8097279419,
        1.8232203489000003,
        1.8116232619000001,
        1.4288936729000001,
        1.5487812379
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 1.5739605634,
      "stddev": 0.14401767917336092,
      "median": 1.5271946489000001,
      "user": 1.24524598,
      "system": 1.17917464,
      "min": 1.4365475469000002,
      "max": 1.8607476829000003,
      "times": [
        1.8607476829000003,
        1.4488374669000001,
        1.7802883499000002,
        1.4532954489,
        1.4365475469000002,
        1.5248555979,
        1.5076127029000002,
        1.5295336999000002,
        1.6358098139000001,
        1.5620773239
      ]
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 420.2 ± 19.6 391.3 444.6 1.45 ± 0.08
pacquet@main 422.0 ± 28.5 378.9 463.7 1.46 ± 0.11
pnpr@HEAD 294.9 ± 5.8 287.9 304.9 1.02 ± 0.04
pnpr@main 290.0 ± 9.8 281.7 312.8 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.42020578942000003,
      "stddev": 0.01964282189102156,
      "median": 0.42153941862,
      "user": 0.51849536,
      "system": 0.6932561399999999,
      "min": 0.39131605912,
      "max": 0.44459040712000003,
      "times": [
        0.41185618212,
        0.40575271112,
        0.43367966912,
        0.44234447912,
        0.44459040712000003,
        0.43122265512,
        0.43627460412,
        0.39590589212000005,
        0.40911523512000003,
        0.39131605912
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 0.42202473372,
      "stddev": 0.028454804434002653,
      "median": 0.41659337712,
      "user": 0.5072633599999999,
      "system": 0.69604094,
      "min": 0.37888995212000004,
      "max": 0.46372728412,
      "times": [
        0.45424031512,
        0.37888995212000004,
        0.41105397212,
        0.41136737612,
        0.44335693712,
        0.42181937812000003,
        0.46372728412,
        0.39250893812000004,
        0.44497621812000004,
        0.39830696612
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.29489233422,
      "stddev": 0.005753530960841422,
      "median": 0.29357379662000005,
      "user": 0.18905645999999998,
      "system": 0.49928014000000004,
      "min": 0.28785044612,
      "max": 0.30485386212000004,
      "times": [
        0.28785044612,
        0.30333700512,
        0.29152179512000004,
        0.29611874812,
        0.29056248612,
        0.28929502612,
        0.29388490812,
        0.30485386212000004,
        0.29823638012000003,
        0.29326268512000003
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.29001822922000003,
      "stddev": 0.009803760151633296,
      "median": 0.28691149612,
      "user": 0.19494006,
      "system": 0.5053653399999999,
      "min": 0.28166391612,
      "max": 0.31283198612,
      "times": [
        0.28570611612,
        0.29181037612,
        0.28174118812,
        0.29870829612,
        0.28166391612,
        0.28178868812,
        0.28471694012000004,
        0.29309790912,
        0.31283198612,
        0.28811687612000003
      ]
    }
  ]
}

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 1.715 ± 0.010 1.695 1.729 5.67 ± 0.36
pacquet@main 1.706 ± 0.009 1.697 1.727 5.64 ± 0.36
pnpr@HEAD 0.303 ± 0.015 0.288 0.336 1.00 ± 0.08
pnpr@main 0.303 ± 0.019 0.283 0.337 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 1.7148885737400001,
      "stddev": 0.009898711124147154,
      "median": 1.71537581164,
      "user": 0.79120278,
      "system": 0.7551707400000001,
      "min": 1.69469994914,
      "max": 1.72920286314,
      "times": [
        1.71400009214,
        1.72058417214,
        1.72528996814,
        1.71236757814,
        1.70632365414,
        1.69469994914,
        1.7167515311400001,
        1.71010154914,
        1.72920286314,
        1.71956438014
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 1.70584104994,
      "stddev": 0.009057116307962994,
      "median": 1.7026659091400003,
      "user": 0.75239088,
      "system": 0.7613546400000001,
      "min": 1.6968655321400001,
      "max": 1.72722874614,
      "times": [
        1.71156187414,
        1.6968655321400001,
        1.69864782114,
        1.71056814814,
        1.70144707714,
        1.69882458014,
        1.7022255651400002,
        1.72722874614,
        1.70793490214,
        1.70310625314
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.30349932784000005,
      "stddev": 0.01516611530541227,
      "median": 0.3003935106400001,
      "user": 0.21518898000000003,
      "system": 0.50111714,
      "min": 0.28825627414000005,
      "max": 0.33630796014000003,
      "times": [
        0.29679124514000005,
        0.28998179414,
        0.28825627414000005,
        0.29550716914,
        0.31480736014000005,
        0.31334070514000006,
        0.28840185414,
        0.30399577614000006,
        0.30760314014000006,
        0.33630796014000003
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.30255683204,
      "stddev": 0.01935336163254721,
      "median": 0.29699334114000003,
      "user": 0.20934687999999996,
      "system": 0.50720414,
      "min": 0.28287541214000006,
      "max": 0.33730195514000005,
      "times": [
        0.30879080314,
        0.28287541214000006,
        0.29602812814,
        0.33730195514000005,
        0.33482997914000007,
        0.28439814314000006,
        0.29080617214000004,
        0.29795855414000005,
        0.28973854414000005,
        0.30284062914000004
      ]
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 235.7 ± 23.2 203.3 270.4 2.54 ± 0.28
pacquet@main 249.5 ± 20.1 225.3 291.7 2.69 ± 0.25
pnpr@HEAD 97.3 ± 4.2 89.6 107.0 1.05 ± 0.07
pnpr@main 92.9 ± 4.5 86.6 106.3 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.23570804310000004,
      "stddev": 0.023209089973157612,
      "median": 0.23864160970000003,
      "user": 0.19137942000000002,
      "system": 0.08644959999999999,
      "min": 0.20328910320000002,
      "max": 0.2703544412,
      "times": [
        0.2703544412,
        0.2575107982,
        0.2036968282,
        0.21661045720000002,
        0.23936572020000002,
        0.20328910320000002,
        0.22560910820000002,
        0.25915365920000005,
        0.24357281620000004,
        0.23791749920000002
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 0.24949721110909098,
      "stddev": 0.020135974312519532,
      "median": 0.24443721820000003,
      "user": 0.2033938018181818,
      "system": 0.08802660909090909,
      "min": 0.22530400720000002,
      "max": 0.29171003120000005,
      "times": [
        0.26452358620000005,
        0.27379222420000005,
        0.2524038242,
        0.29171003120000005,
        0.23831394620000002,
        0.23768299320000003,
        0.24443721820000003,
        0.23951928920000004,
        0.22775253120000002,
        0.22530400720000002,
        0.24902967120000002
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.09732249697777776,
      "stddev": 0.004193486601002259,
      "median": 0.0973877192,
      "user": 0.02492510148148148,
      "system": 0.014514648148148153,
      "min": 0.0896384322,
      "max": 0.1069723972,
      "times": [
        0.1013236542,
        0.0976646102,
        0.0972674132,
        0.1069723972,
        0.09931098320000001,
        0.0986976982,
        0.0998571142,
        0.0960534792,
        0.0946010162,
        0.0918544352,
        0.09592236520000001,
        0.09820483420000001,
        0.09659609520000001,
        0.09575496920000001,
        0.09387449120000001,
        0.09043955520000001,
        0.09104243420000001,
        0.0973877192,
        0.1022175542,
        0.09986579920000001,
        0.09423656420000001,
        0.0896384322,
        0.09473751820000001,
        0.0992990002,
        0.0974080412,
        0.1032929652,
        0.10418627920000001
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.09289254012857143,
      "stddev": 0.004537842609561565,
      "median": 0.09331610370000001,
      "user": 0.023055762857142857,
      "system": 0.012261639285714287,
      "min": 0.08657846820000001,
      "max": 0.10625277120000001,
      "times": [
        0.0974149982,
        0.0945115532,
        0.0952680952,
        0.0983896742,
        0.10625277120000001,
        0.0976401712,
        0.09341807220000001,
        0.0966371532,
        0.0932141352,
        0.0953044692,
        0.0890400342,
        0.0925233902,
        0.09408337920000001,
        0.0977163932,
        0.08800490820000001,
        0.08657846820000001,
        0.0961723642,
        0.0869142442,
        0.08886461420000001,
        0.0911837992,
        0.09020774520000001,
        0.09079143120000001,
        0.08969252620000001,
        0.08777639720000001,
        0.09407681220000001,
        0.0883259822,
        0.0940242502,
        0.0869632912
      ]
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 773.4 ± 155.5 550.1 990.5 1.00
pacquet@main 818.8 ± 221.9 589.2 1164.5 1.06 ± 0.36
pnpm@HEAD 2905.3 ± 48.0 2873.4 3022.0 3.76 ± 0.76
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.7734217936711111,
      "stddev": 0.15549863225533042,
      "median": 0.79376278556,
      "user": 0.7079342377777776,
      "system": 0.15813566,
      "min": 0.55013017956,
      "max": 0.99052204656,
      "times": [
        0.93749465456,
        0.61803029856,
        0.74197583356,
        0.99052204656,
        0.89332572056,
        0.79376278556,
        0.82596312256,
        0.55013017956,
        0.60959150156
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 0.8188270115599999,
      "stddev": 0.22185222518356287,
      "median": 0.75323530056,
      "user": 0.7602057933333334,
      "system": 0.16102299333333334,
      "min": 0.58921973956,
      "max": 1.1644788955599998,
      "times": [
        0.67515351556,
        1.1644788955599998,
        0.75323530056,
        0.60538765156,
        0.99083103856,
        0.9542852295600001,
        0.59136066456,
        1.0454910685599998,
        0.58921973956
      ]
    },
    {
      "command": "pnpm@HEAD",
      "mean": 2.9053181477822227,
      "stddev": 0.04802248800121166,
      "median": 2.88797636756,
      "user": 4.145830904444445,
      "system": 0.3052351044444444,
      "min": 2.87339002556,
      "max": 3.02195692256,
      "times": [
        2.87441217556,
        2.88797636756,
        2.93631032556,
        2.90127791756,
        2.87813792156,
        2.8772692595600002,
        2.87339002556,
        2.89713241456,
        3.02195692256
      ]
    }
  ]
}

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 4.593 ± 0.169 4.424 4.842 1.28 ± 0.06
pacquet@main 4.497 ± 0.077 4.406 4.638 1.26 ± 0.04
pnpr@HEAD 3.581 ± 0.093 3.483 3.758 1.00
pnpr@main 3.641 ± 0.133 3.512 3.861 1.02 ± 0.05
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 4.5927868355,
      "stddev": 0.16915721807176665,
      "median": 4.5651184292,
      "user": 1.9018699600000002,
      "system": 1.40391748,
      "min": 4.4240306142,
      "max": 4.842317025200001,
      "times": [
        4.5774869632,
        4.5597344692,
        4.427354197200001,
        4.5705023892000005,
        4.468426256200001,
        4.4338624082,
        4.842317025200001,
        4.8306983572,
        4.4240306142,
        4.793455675200001
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 4.4967258529,
      "stddev": 0.07669211320360513,
      "median": 4.4868228297,
      "user": 1.8461113599999996,
      "system": 1.4616803799999998,
      "min": 4.4062937492000005,
      "max": 4.638091081200001,
      "times": [
        4.4831392892,
        4.4280141432,
        4.638091081200001,
        4.5028030972,
        4.4062937492000005,
        4.4700474132000005,
        4.4905063702,
        4.6148615072000005,
        4.4259663992,
        4.5075354792
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 3.5810825091,
      "stddev": 0.09262266985024249,
      "median": 3.5789394157,
      "user": 1.58009666,
      "system": 1.4591895799999999,
      "min": 3.4829225742,
      "max": 3.7576176232,
      "times": [
        3.5528873632,
        3.4832728772,
        3.7576176232,
        3.6376163602,
        3.4898594272,
        3.6756793491999997,
        3.6049914682,
        3.6096593852,
        3.5163186632,
        3.4829225742
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 3.6408307823999997,
      "stddev": 0.13322468024462636,
      "median": 3.5868575191999996,
      "user": 1.74816486,
      "system": 1.5340825799999998,
      "min": 3.5123794482,
      "max": 3.8614850512,
      "times": [
        3.7774197332,
        3.5123794482,
        3.6499895812,
        3.8275785812,
        3.5349545922,
        3.8614850512,
        3.5481478442,
        3.5226379542,
        3.6127462832,
        3.5609687552
      ]
    }
  ]
}

@github-actions

github-actions Bot commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Projectpnpm's project
Branchpr/13779
Testbedpacquet
Click to view all benchmark results
BenchmarkLatencyBenchmark Result
milliseconds (ms)
(Result Δ%)
Upper Boundary
milliseconds (ms)
(Limit %)
isolated-linker.fresh-install.cold-cache.cold-store📈 view plot
🚷 view threshold
2,580.01 ms
(-2.36%)Baseline: 2,642.47 ms
3,170.96 ms
(81.36%)
isolated-linker.fresh-install.cold-cache.hot-store📈 view plot
🚷 view threshold
1,694.70 ms
(-3.96%)Baseline: 1,764.65 ms
2,117.58 ms
(80.03%)
isolated-linker.fresh-install.hot-cache.hot-store📈 view plot
🚷 view threshold
391.32 ms
(-11.75%)Baseline: 443.44 ms
532.13 ms
(73.54%)
isolated-linker.fresh-resolve.hot-cache.offline📈 view plot
🚷 view threshold
203.29 ms
(-7.72%)Baseline: 220.30 ms
264.36 ms
(76.90%)
isolated-linker.fresh-restore.cold-cache.cold-store📈 view plot
🚷 view threshold
2,402.87 ms
(-0.50%)Baseline: 2,414.84 ms
2,897.81 ms
(82.92%)
isolated-linker.fresh-restore.cold-cache.cold-store.cold-pnpr📈 view plot
🚷 view threshold
4,424.03 ms
(-2.01%)Baseline: 4,514.76 ms
5,417.71 ms
(81.66%)
isolated-linker.fresh-restore.hot-cache.hot-store📈 view plot
🚷 view threshold
248.19 ms
(-10.18%)Baseline: 276.32 ms
331.58 ms
(74.85%)
isolated-linker.peer-heavy-resolve.hot-cache.offline📈 view plot
🚷 view threshold
550.13 ms
(-20.36%)Baseline: 690.75 ms
828.90 ms
(66.37%)
🐰 View full continuous benchmarking report in Bencher

The candidate scan read a key's bare semver, so a version present only
under a named-registry key (foo@work:1.2.0) counted as an ordinary
candidate and would have been written back as a plain importer
reference pointing at a key that does not exist. That semver pins a
version only within its named registry, so such keys now take the same
exit as peer-suffixed ones. pacquet was already safe here, since
version_semver excludes registry-qualified versions by design; it gains
the regression test.

The Rust side also borrows the package map through disjoint field
access instead of cloning every entry before the update begins.
Copilot AI review requested due to automatic review settings August 10, 2026 18:35

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.

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

Copy link
Copy Markdown

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

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

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

No code suggestions found for the PR.

@github-actions

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Projectpnpm's project
Branchpr/13779
Testbedpnpr

⚠️ WARNING: No Threshold found!

Without a Threshold, no Alerts will ever be generated.

Click here to create a new Threshold
For more information, see the Threshold documentation.
To only post results if a Threshold exists, set the --ci-only-thresholds flag.

Click to view all benchmark results
BenchmarkLatencymilliseconds (ms)
isolated-linker.fresh-install.cold-cache.cold-store📈 view plot
⚠️ NO THRESHOLD
1,428.89 ms
isolated-linker.fresh-install.cold-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
288.26 ms
isolated-linker.fresh-install.hot-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
287.85 ms
isolated-linker.fresh-resolve.hot-cache.offline📈 view plot
⚠️ NO THRESHOLD
89.64 ms
isolated-linker.fresh-restore.cold-cache.cold-store📈 view plot
⚠️ NO THRESHOLD
1,401.86 ms
isolated-linker.fresh-restore.cold-cache.cold-store.cold-pnpr📈 view plot
⚠️ NO THRESHOLD
3,482.92 ms
isolated-linker.fresh-restore.hot-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
287.85 ms
🐰 View full continuous benchmarking report in Bencher

@zkochan
zkochan merged commit 996297c into main Aug 10, 2026
44 checks passed
@zkochan
zkochan deleted the locked-range branch August 10, 2026 19:51
zkochan added a commit that referenced this pull request Aug 11, 2026
pnpm remove already skips resolution when the lockfile proves the
outcome; its twin did not. `pnpm add <pkg>@<version>` re-resolved the
whole graph even when the requested version was one the lockfile
already held — promoting a transitive dependency to a direct one, or
adding to a second workspace package what a first one already depends
on.

The rule is the one #13779 established: resolution reuses the
already-locked version it would dedupe onto rather than fetching a
higher one, because preferredVersions biases it toward what the graph
already holds. The importers handler now records a brand-new importer
edge at that version, under the group the manifest declares, alongside
the whole-new-project entry #13803 added. It reuses that
change's guards: a range several locked versions satisfy under
`resolutionMode: time-based` or `lowest-direct` keeps the resolver,
since those pick the low end and only for a run that leaves the
manifest alone, and so does a plain range on a workspace project's
name, which may resolve to a link instead. A lockfile carrying `time`
keeps it too: `time` records a publish date per direct dependency and
is only pruned on save, never extended, so a package promoted into
that position would be missing the one a resolution records.

`installSome` cannot edit the manifests in place the way
`uninstallSome` does — the resolution path reads them to tell a new
dependency from a re-added one, and reads them again to pick the range
style it saves — so the edit is staged on copies, handed to the fast
update and its freshness gates, and the context takes it only once the
rewrite commits. The range a selector saves is computed with the
resolver's own rule, extracted as `calcVersionRange` in
`@pnpm/pkg-manifest.utils` alongside the `inferRangeSpecStyle` it needs.

pacquet needed only the gate: `add` already pins the manifest before
the install runs, so `may_fast_update_lockfile` admits `InstallSome`
and `add` stops forcing `preferFrozenLockfile` off. `update` is also
`InstallSome` and keeps its explicit opt-out, so it is unaffected. Its
manifest pin still consults the registry packument; only the
install-side resolution is skipped.

The narrow cut is a plain registry specifier. A dist tag, an alias, a
`workspace:`/`catalog:`/git/tarball specifier, `--save-peer`, a
`catalogMode` other than `manual`, an overridden package, and a version
nothing locked satisfies all keep the resolver.

Closes #13798.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
zkochan added a commit that referenced this pull request Aug 11, 2026
pnpm remove already skips resolution when the lockfile proves the
outcome; its twin did not. `pnpm add <pkg>@<version>` re-resolved the
whole graph even when the requested version was one the lockfile
already held — promoting a transitive dependency to a direct one, or
adding to a second workspace package what a first one already depends
on.

The rule is the one #13779 established: resolution reuses the
already-locked version it would dedupe onto rather than fetching a
higher one, because preferredVersions biases it toward what the graph
already holds. The importers handler now records a brand-new importer
edge at that version, under the group the manifest declares, alongside
the whole-new-project entry #13803 added. It reuses that
change's guards: a range several locked versions satisfy under
`resolutionMode: time-based` or `lowest-direct` keeps the resolver,
since those pick the low end and only for a run that leaves the
manifest alone, and so does a plain range on a workspace project's
name, which may resolve to a link instead. A lockfile carrying `time`
keeps it too: `time` records a publish date per direct dependency and
is only pruned on save, never extended, so a package promoted into
that position would be missing the one a resolution records.

`installSome` cannot edit the manifests in place the way
`uninstallSome` does — the resolution path reads them to tell a new
dependency from a re-added one, and reads them again to pick the range
style it saves — so the edit is staged on copies, handed to the fast
update and its freshness gates, and the context takes it only once the
rewrite commits. The range a selector saves is computed with the
resolver's own rule, extracted as `calcVersionRange` in
`@pnpm/pkg-manifest.utils` alongside the `inferRangeSpecStyle` it needs.

pacquet needed only the gate: `add` already pins the manifest before
the install runs, so `may_fast_update_lockfile` admits `InstallSome`
and `add` stops forcing `preferFrozenLockfile` off. `update` is also
`InstallSome` and keeps its explicit opt-out, so it is unaffected. Its
manifest pin still consults the registry packument; only the
install-side resolution is skipped.

The narrow cut is a plain registry specifier. A dist tag, an alias, a
`workspace:`/`catalog:`/git/tarball specifier, `--save-peer`, a
`catalogMode` other than `manual`, an overridden package, and a version
nothing locked satisfies all keep the resolver.

Closes #13798.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
zkochan added a commit that referenced this pull request Aug 11, 2026
)

pnpm remove already skips resolution when the lockfile proves the
outcome; its twin did not. `pnpm add <pkg>@<version>` re-resolved the
whole graph even when the requested version was one the lockfile
already held — promoting a transitive dependency to a direct one, or
adding to a second workspace package what a first one already depends
on.

The rule is the one #13779 established: resolution reuses the
already-locked version it would dedupe onto rather than fetching a
higher one, because preferredVersions biases it toward what the graph
already holds. The importers handler now records a brand-new importer
edge at that version, under the group the manifest declares, alongside
the whole-new-project entry #13803 added. It reuses that
change's guards: a range several locked versions satisfy under
`resolutionMode: time-based` or `lowest-direct` keeps the resolver,
since those pick the low end and only for a run that leaves the
manifest alone, and so does a plain range on a workspace project's
name, which may resolve to a link instead. A lockfile carrying `time`
keeps it too: `time` records a publish date per direct dependency and
is only pruned on save, never extended, so a package promoted into
that position would be missing the one a resolution records.

`installSome` cannot edit the manifests in place the way
`uninstallSome` does — the resolution path reads them to tell a new
dependency from a re-added one, and reads them again to pick the range
style it saves — so the edit is staged on copies, handed to the fast
update and its freshness gates, and the context takes it only once the
rewrite commits. The range a selector saves is computed with the
resolver's own rule, extracted as `calcVersionRange` in
`@pnpm/pkg-manifest.utils` alongside the `inferRangeSpecStyle` it needs.

pacquet needed only the gate: `add` already pins the manifest before
the install runs, so `may_fast_update_lockfile` admits `InstallSome`
and `add` stops forcing `preferFrozenLockfile` off. `update` is also
`InstallSome` and keeps its explicit opt-out, so it is unaffected. Its
manifest pin still consults the registry packument; only the
install-side resolution is skipped.

The narrow cut is a plain registry specifier. A dist tag, an alias, a
`workspace:`/`catalog:`/git/tarball specifier, `--save-peer`, a
`catalogMode` other than `manual`, an overridden package, and a version
nothing locked satisfies all keep the resolver.

Closes #13798.
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.

Fast lockfile update keeps an older version on a widened range where resolution would dedupe to a higher already-locked one

3 participants