Skip to content

fix: auto-install transitive peers shared at different workspace depths - #14841

Merged
zkochan merged 3 commits into
mainfrom
fix-14840
Sep 11, 2026
Merged

zkochan merged 3 commits into
mainfrom
fix-14840

Conversation

@zkochan

@zkochan zkochan commented Sep 11, 2026 •

Copy link
Copy Markdown
Member

Summary

Fixes missing transitive peers when workspace projects share a dependency at different depths. A peer supplied by one project no longer prevents autoInstallPeers from installing it for another project, and the lockfile contains one complete peer context.

Closes #14840.

This is a pnpm v11 bug fix. The original reproduction passes on pnpm v12, so no Rust changes are needed.

Validation:

  • The new regression fails without the fix in both importer orders and passes with it, including a frozen-lockfile reinstall.
  • All 27 auto-install-peers tests and 91 related peer-dependency/cyclic-determinism tests passed (one existing test is skipped).
  • Four collector tests cover dense cycles, a 20,000-package chain, provider visibility, and linear traversal for distinct absent peers.
  • Rebuilt the v11 CLI and ran the original reproduction: pnpm peers check reports no issues.
  • Ran the original reproduction on pnpm v12.4.0: no peer issues.

Squash Commit Body

Shared child-resolution results can omit peers supplied by the owning
importer's ancestors. A deeper occurrence also cannot safely await the
shallower owner's promise because that can deadlock on dependency cycles.

Before auto-installing peers, collect missing required peers from the
resolved dependency graph and filter providers at each dependency level.
Collect peers with no possible provider directly in one graph pass. For
peers with possible providers, visit each package at most once per name
and stop at subtrees with a provider. Use iterative traversal to handle deep graphs
and dense dependency cycles without enumerating paths. Keep optional-peer
collection and the child-resolution ownership rules unchanged.

Cover two workspace projects sharing a local package at different depths,
both importer orders, strict peer checks, one complete child snapshot,
and a frozen-lockfile reinstall.

Closes pnpm/pnpm#14840.

Checklist

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

Written by an agent (Codex, GPT-6).

Summary by CodeRabbit

  • Bug Fixes
    • pnpm install now automatically installs missing transitive peer dependencies when workspace projects share dependencies at different levels.
    • Improved peer dependency resolution and validation, including installations that do not require the workspace root.
    • Removed incomplete duplicate peer contexts from the lockfile, improving frozen-lockfile reproducibility and consistency across workspace installations.

Collect required peers from the resolved dependency graph before auto-installing them.
Shared child-resolution results can omit peers supplied by another importer, and
 deeper occurrences cannot safely await the owner promise. Keep optional-peer
 discovery unchanged and filter providers at each dependency level.

Closes #14840.
@coderabbitai

coderabbitai Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview 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: Advanced

Run ID: f8b168a6-6ae4-4c83-b7b6-2e412d4eb69f

📥 Commits

Reviewing files that changed from the base of the PR and between 5bf6b0d and 3cb2efb.

📒 Files selected for processing (2)
  • pnpm11/installing/deps-resolver/src/resolveDependencies.ts
  • pnpm11/installing/deps-resolver/test/collectMissingRequiredPeers.test.ts

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


📝 Walkthrough

Walkthrough

The resolver now discovers missing transitive peers from resolved dependency graphs during auto-installation. Tests cover cycles, deep dependency chains, workspace dependency depths, importer order, peer validation, and frozen-lockfile reproducibility. A changeset declares patch releases.

Changes

Transitive peer resolution

Layer / File(s) Summary
Collect transitive missing peers
pnpm11/installing/deps-resolver/src/resolveDependencies.ts
collectMissingRequiredPeers uses iterative graph traversal with cycle tracking and subtree-scoped peer checks. Root resolution merges the collected peers during auto-installation.
Resolver and workspace regression coverage
pnpm11/installing/deps-resolver/test/collectMissingRequiredPeers.test.ts, pnpm11/installing/deps-installer/test/install/autoInstallPeers.ts, .changeset/fix-transitive-auto-install-peers.md
Tests cover dense cycles, deep chains, dependency depths, importer order, peer validation, and frozen-lockfile reproducibility. The changeset declares patch releases.

Priority: ➖ Normal

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

Change: Bug fix · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant WorkspaceInstall
  participant resolveRootDependencies
  participant collectMissingRequiredPeers
  participant Lockfile
  WorkspaceInstall->>resolveRootDependencies: resolve importers with autoInstallPeers
  resolveRootDependencies->>collectMissingRequiredPeers: inspect resolved dependency roots
  collectMissingRequiredPeers-->>resolveRootDependencies: return transitive missing peers
  resolveRootDependencies->>Lockfile: resolve complete peer contexts
  Lockfile-->>WorkspaceInstall: support frozen-lockfile installation
Loading

Assessment against linked issues

Objective Addressed Explanation
Install missing transitive peers for dependency closures at different workspace depths and pass peer validation [#14840] ✅
Avoid incomplete duplicate peer contexts in the lockfile [#14840] ✅

Suggested labels: product: pnpm@11

Suggested reviewers: ayush442842q

Merge Risk: ⚪ Minimal · up to 3cb2e

The peer-resolution change preserves dependency-level provider handling and is covered by workspace and lockfile regression tests.

✨ 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 fix-14840

Warning

Some tools did not complete. Review the errors below.

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

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

ESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox.

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

ESLint skipped: the matched ESLint configuration already failed (missing-dependency).


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 transitive peer auto-installation across workspace depths

🐞 Bug fix 🧪 Tests 🕐 20-40 Minutes

Grey Divider

AI Description

• Discovers missing required peers across shared dependency graphs before auto-installation.
• Handles cycles safely while preserving importer-level providers and deterministic lockfiles.
• Adds importer-order, strict-peer, snapshot, and frozen-lockfile regression coverage.
Diagram

graph TD
  A["Workspace importers"] --> B["Resolved graph"] --> C["Collect required peers"] --> D{"Cycle encountered?"}
  D -- "No" --> E["Memoize subtree"] --> F["Merge peer ranges"] --> G["Auto-install peers"] --> H["Complete lockfile"]
  D -- "Yes" --> F
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Context-key shared child resolution
  • ➕ Could preserve peer-provider context during initial child resolution.
  • ➕ Would avoid a separate graph-discovery pass for missing peers.
  • ➖ Requires broader changes to resolution ownership and cache keys.
  • ➖ May duplicate child resolutions across importers and increase memory usage.
  • ➖ Introduces greater regression risk in pnpm v11 resolution behavior.
2. Resolve each importer independently
  • ➕ Naturally isolates ancestor-provided peers between workspace projects.
  • ➕ Simplifies reasoning about importer-specific peer contexts.
  • ➖ Sacrifices shared resolution work across the workspace.
  • ➖ Can increase installation time and produce harder lockfile deduplication problems.

Recommendation: Keep the PR’s cycle-aware graph collection approach. It is a focused v11 correction that retains existing child-resolution ownership and optional-peer behavior, while avoiding the deadlock risk of awaiting a shallower owner and the overhead of importer-specific resolution.

Files changed (3) +84 / -0

Bug fix (1) +43 / -0
resolveDependencies.tsDiscover missing required peers from the resolved graph +43/-0

Discover missing required peers from the resolved graph

• Collects non-optional missing peers before auto-installation, filtering providers at each dependency level. The traversal memoizes acyclic subtrees while avoiding reuse of path-dependent results cut by cycles.

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

Tests (1) +35 / -0
autoInstallPeers.tsCover shared transitive peers at different workspace depths +35/-0

Cover shared transitive peers at different workspace depths

• Adds a parameterized regression test for both importer orders with strict peer validation. It verifies a single complete child snapshot and an unchanged frozen-lockfile reinstall.

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

Documentation (1) +6 / -0
fix-transitive-auto-install-peers.mdDocument corrected transitive peer auto-installation +6/-0

Document corrected transitive peer auto-installation

• Adds patch release notes for the dependency resolver and pnpm CLI. It documents complete peer installation and removal of incomplete duplicate lockfile contexts.

.changeset/fix-transitive-auto-install-peers.md

@github-actions github-actions Bot added the reviewed: coderabbit CodeRabbit submitted an approving review label Sep 11, 2026
Visit each package once per required peer name and stop at provider subtrees.

Use iterative traversal to avoid stack overflow in deep graphs. Cover dense cycles,

a 20,000-package chain, and provider visibility across shared subtrees.
@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.

@qodo-code-review

qodo-code-review Bot commented Sep 11, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

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

Grey Divider


Action required

1. Crafted peer graphs stall installs ✓ Resolved 🐞 Bug ⛨ Security
Description
collectMissingRequiredPeers creates a new visited set and rescans the reachable package graph
once for every distinct required peer name. Because registry manifests control those names and
automatic peer installation is enabled by default, a chain of packages that each declares a
different absent peer causes quadratic resolver work on every importer-loop pass and can exhaust
install CPU.
Code

pnpm11/installing/deps-resolver/src/resolveDependencies.ts[R832-835]

+  for (const peerName of peerNames) {
+    const visited = new Set<PkgResolutionId>()
+    pending.push(...roots.map(({ pkgId }) => pkgId))
+    while (pending.length) {
Relevance

●● Moderate

Quadratic traversal is plausible, but history is mixed and lacks a closely matching security
rejection or acceptance.

PR-#12855
PR-#11373

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The first pass records every reachable package and gathers all distinct peer names, after which the
outer loop allocates a fresh visited set and traverses child edges separately for each name. This
collector runs inside the repeated auto-install loop for every importer, while auto-installation is
enabled by default; the repository also explicitly treats manifests and registry metadata as
attacker-controlled.

pnpm11/installing/deps-resolver/src/resolveDependencies.ts[818-829]
pnpm11/installing/deps-resolver/src/resolveDependencies.ts[831-847]
pnpm11/installing/deps-resolver/src/resolveDependencies.ts[425-433]
pnpm11/installing/deps-installer/src/install/extendInstallOptions.ts[282-292]
REVIEW_GUIDE.md[30-46]

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

## Issue description
`collectMissingRequiredPeers` performs a complete reachable-graph traversal for every distinct required peer name. Attacker-controlled package metadata can therefore turn a linear dependency graph with unique absent peers into quadratic resolver work on the default install path.

## Fix Focus Areas
- pnpm11/installing/deps-resolver/src/resolveDependencies.ts[818-849]
- pnpm11/installing/deps-resolver/test/collectMissingRequiredPeers.test.ts[18-26]

## Recommended Fix
Replace the per-peer traversal with one provider-aware graph analysis that aggregates all unresolved peer constraints together. Memoize acyclic subtree summaries while retaining cycle-safe path handling, and add an adversarial test where each node in a long chain declares a unique absent peer, using deterministic visit-count instrumentation rather than wall-clock timing to verify near-linear traversal.

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



Informational

2. New resolver types omit trailing commas 📘 Rule violation ⚙ Maintainability
Description
collectMissingRequiredPeers leaves the final roots parameter and final members of its inline
object types without trailing commas. Later edits to this multi-line signature and its type
collections will produce noisier diffs and preserve inconsistent punctuation in the new resolver
helper.
Code

pnpm11/installing/deps-resolver/src/resolveDependencies.ts[810]

+  roots: Array<Pick<PkgAddress, 'alias' | 'pkgId'>>
Relevance

● Weak

Recent resolver precedents reject trailing-comma style findings, including this exact file and
signature pattern.

PR-#14175
PR-#13387
PR-#14223

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
Compliance rule 713434 requires trailing commas on the final item of TypeScript multi-line parameter
lists and type structures. The added roots parameter at line 810 is the final item in a multi-line
parameter list but has no trailing comma; the nearby added inline types follow the same noncompliant
pattern.

Rule 713434: Require trailing commas in TypeScript collections and multi-line constructs
pnpm11/installing/deps-resolver/src/resolveDependencies.ts[806-817]

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

## Issue description
The new multi-line `collectMissingRequiredPeers` signature and inline object types omit required trailing commas.

## Fix Focus Areas
- pnpm11/installing/deps-resolver/src/resolveDependencies.ts[806-817]

## Recommended Fix
Add trailing commas after the final `roots` parameter and after the final members of each multi-line inline object type introduced by this helper.

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


Grey Divider

Context sources
✅ Compliance rules (platform): 26 rules
✅ Cross-repo context — repo relationships
Review mode: ⚖️ Balanced: This is a localized but behaviorally significant dependency-graph traversal change with correctness and performance implications, warranting a careful single-pass review.

Grey Divider

Tip of the day
💡 Did you know, you can switch off images and animations for a plain-text comment

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.

Avoid rescanning the graph for each distinct absent peer. Collect their constraints

directly, and reserve provider-aware traversal for names with a possible provider.

Add a deterministic regression covering 500 distinct peers along a dependency chain.
@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 3cb2efb

@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 2b39d19 into main Sep 11, 2026
30 checks passed
@zkochan
zkochan deleted the fix-14840 branch September 11, 2026 23:36
biisal pushed a commit to biisal/pnpm that referenced this pull request Sep 15, 2026
…hs (pnpm#14841)

Shared child-resolution results can omit peers supplied by the owning
importer's ancestors. A deeper occurrence also cannot safely await the
shallower owner's promise because that can deadlock on dependency cycles.

Before auto-installing peers, collect missing required peers from the
resolved dependency graph and filter providers at each dependency level.
Collect peers with no possible provider directly in one graph pass. For
peers with possible providers, visit each package at most once per name
and stop at subtrees with a provider. Use iterative traversal to handle deep graphs
and dense dependency cycles without enumerating paths. Keep optional-peer
collection and the child-resolution ownership rules unchanged.

Cover two workspace projects sharing a local package at different depths,
both importer orders, strict peer checks, one complete child snapshot,
and a frozen-lockfile reinstall.

Closes pnpm#14840.
u9g pushed a commit to u9g/pnpm that referenced this pull request Sep 25, 2026
…hs (pnpm#14841)

Shared child-resolution results can omit peers supplied by the owning
importer's ancestors. A deeper occurrence also cannot safely await the
shallower owner's promise because that can deadlock on dependency cycles.

Before auto-installing peers, collect missing required peers from the
resolved dependency graph and filter providers at each dependency level.
Collect peers with no possible provider directly in one graph pass. For
peers with possible providers, visit each package at most once per name
and stop at subtrees with a provider. Use iterative traversal to handle deep graphs
and dense dependency cycles without enumerating paths. Keep optional-peer
collection and the child-resolution ownership rules unchanged.

Cover two workspace projects sharing a local package at different depths,
both importer orders, strict peer checks, one complete child snapshot,
and a frozen-lockfile reinstall.

Closes pnpm#14840.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

autoInstallPeers misses transitive peers and creates duplicate peer contexts in pnpm 11.15+

1 participant