Skip to content

fix(deps-resolver): dedupe injected deps despite unrelated peer-suffix mismatch - #12800

Merged
zkochan merged 7 commits into
pnpm:mainfrom
omril1:fix/dedupe-injected-deps-unrelated-peer-suffix
Jul 13, 2026
Merged

zkochan merged 7 commits into
pnpm:mainfrom
omril1:fix/dedupe-injected-deps-unrelated-peer-suffix

Conversation

@omril1

@omril1 omril1 commented Jul 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The problem

With injectWorkspacePackages: true, a workspace package injected into a consumer sometimes fails to dedupe back to link: even when it safely could, staying as a peer-suffixed file:packages/pkg-c(...) entry instead. This shows up as pnpm-lock.yaml churn after an unrelated pnpm install/pnpm update against an existing lockfile — the affected package itself, and everything it depends on, is untouched by the triggering change. With nodeLinker: hoisted, the file: entry makes pnpm copy a stale/unbuilt snapshot into node_modules instead of linking to the live workspace source.

Standalone minimal reproduction: https://github.com/omril1/pnpm-workspace-link-corruption-repro

Root cause

getDedupeMap decides whether an injected occurrence's resolved children match the target project's own resolved dependencies via strict depPath string equality:

const isSubset = children
  .every(([alias, depPath]) => targetProjectDeps.get(alias) === depPath)

This can fail even when the injected package itself resolves identically on both sides, because a completely unrelated, ordinary (non-workspace) shared dependency can legitimately resolve to two different-but-compatible depPaths:

  • resolveDependencies/resolvePeers runs twice per install — a first pass with no lockfile influence, then a second pass seeded with resolvedPeerProviderPaths from the first, which only runs when the tree has any lockedPeerContext (i.e. only when reconciling against an existing lockfile with a peer-resolved package somewhere).
  • In that second pass, a package with its own optional peer (debug's supports-color is a concrete, public instance) can get pinned to its previously-locked peer-suffixed depPath for the target project's own resolution, while the injected occurrence of the workspace package resolves that same shared dependency fresh, without the suffix.
  • Both [email protected] and [email protected]([email protected]) are valid resolutions of the same package. dedupePeerDependents's deduplicateDepPaths already has a notion of this ("compatible and has more deps" — isCompatibleAndHasMoreDeps), but dedupeInjectedDeps runs before that pass and has no way to see it.

The fix

isSubset now also accepts a target depPath that isCompatibleAndHasMoreDeps than the injected occurrence's depPath, instead of requiring the two strings to be byte-identical — reusing the exact compatibility notion the codebase already applies to this class of problem elsewhere, rather than introducing a new one.

How to verify the analysis

  • Added a unit test directly against dedupeInjectedDeps with a hand-built depGraph/dependenciesByProjectId reproducing the exact confirmed shape (injected occurrence: [email protected]; target project: [email protected]([email protected])). It fails on main and passes with this change.
  • Confirmed via instrumented logging against the full-scale public repro that the corruption is fully deterministic given the same lockfile and triggering change (byte-identical result across 4 repeated runs from an identical starting snapshot) — not a timing race.
  • Re-ran the original full-scale repro (~544 resolved packages) against a build with this fix: the previously-corrupted pkg-c/pkg-d entries correctly stay link:.
  • injectWorkspacePackagesPersistence.test.ts (the fix: dedupe workspace deps with children in single-project mode #11448 regression suite) and the full deps-resolver test suite (125 tests) still pass unmodified.

Note on scope

The issue as filed (#10433) is broader than this specific mechanism — it doesn't mention peer dependencies and was reported against plain pnpm update. This PR fixes a confirmed, reproducible cause within the same link:→file: symptom family; it may not be the only one, so I'm not claiming to fully close it.

Squash Commit Body

getDedupeMap's isSubset check required byte-identical depPath strings
between an injected workspace occurrence's resolved children and the
target project's own resolved dependencies. A completely unrelated,
ordinary shared dependency can legitimately resolve differently on each
side: when reconciling against an existing lockfile, a package with its
own optional peer (e.g. debug's supports-color) can get pinned to its
previously-locked peer-suffixed variant for the target project's own
copy while the injected occurrence resolves fresh without one. Both are
valid resolutions of the same package, but the strict string equality
treated them as incompatible and left the entry as file:(...) instead of
collapsing to link:, silently causing nodeLinker: hoisted setups to copy
a stale/unbuilt snapshot into node_modules instead of linking to the
live workspace source.

Fix the comparison to accept a target dependency that
isCompatibleAndHasMoreDeps than the injected occurrence needed, reusing
the same compatibility notion dedupePeerDependents's deduplicateDepPaths
already relies on elsewhere in this file, instead of requiring the two
depPath strings to be identical.

Confirmed against a standalone minimal reproduction
(github.com/omril1/pnpm-workspace-link-corruption-repro) and an
independent real-world monorepo replay: the corruption is fully
deterministic given the same lockfile and triggering change (verified
across repeated runs from an identical starting state), not a timing
race.

Related to pnpm/pnpm#10433

Checklist

  • The change is implemented in both the TypeScript CLI and the Rust pacquet/ port, or the description notes what still needs porting. — Now implemented in both. The pacquet port mirrors the fix in pnpm/crates/resolving-deps-resolver/src/dedupe_injected_deps.rs (build_dedupe_map now tolerates a same-identity, isCompatibleAndHasMoreDeps peer-suffix mismatch), extracts node_deps_count/is_compatible_and_has_more_deps into a shared dep_path_compatibility module, and adds a matching Rust regression test.
  • Added a changeset.
  • Added or updated tests.
  • Updated the documentation if needed. — not applicable, no user-facing behavior/API changed beyond the bug fix itself.

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

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Improved deduping for injected workspace dependencies so injected resolutions more reliably switch to linked workspace packages when peer-suffixed variants are involved.
    • Fixed an edge case where injected resolutions could incorrectly remain file: instead of switching to link: when dependency compatibility differs.
  • Tests

    • Added regression coverage for peer-suffix and mixed-resolution scenarios to prevent future dedupe regressions.

@welcome

welcome Bot commented Jul 4, 2026

Copy link
Copy Markdown

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

@coderabbitai

coderabbitai Bot commented Jul 4, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

This PR updates injected workspace dependency deduplication to accept compatible peer-suffixed variants with matching package identities. It centralizes compatibility helpers, adds regression tests for positive and negative cases, and records patch releases.

Changes

Dedupe compatibility fix

Layer / File(s) Summary
Centralize dependency-path compatibility checks
pnpm11/installing/deps-resolver/src/depPathCompatibility.ts, pnpm11/installing/deps-resolver/src/resolvePeers.ts
Adds shared helpers for comparing resolved dependency and peer sets, and replaces duplicated local implementations in peer resolution.
Apply compatibility-aware injected deduplication
pnpm11/installing/deps-resolver/src/dedupeInjectedDeps.ts
Allows exact matches and compatible same-package depPath variants while rejecting missing nodes and differing package identities.
Regression coverage and release metadata
pnpm11/installing/deps-resolver/test/dedupeInjectedDeps.test.ts, .changeset/dedupe-injected-deps-unrelated-peer-suffix.md
Tests successful deduplication for unrelated peer suffixes and preservation of file: references for different dependency versions, and records patch releases.

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

Sequence Diagram(s)

sequenceDiagram
  participant Consumer
  participant dedupeInjectedDeps
  participant depGraph
  participant depPathCompatibility
  Consumer->>dedupeInjectedDeps: resolve injected workspace dependency
  dedupeInjectedDeps->>depGraph: read target and injected depPaths
  dedupeInjectedDeps->>depPathCompatibility: compare same-package dependency sets
  depPathCompatibility-->>dedupeInjectedDeps: return compatibility result
  dedupeInjectedDeps-->>Consumer: use link: or retain file:
Loading

Possibly related PRs

  • pnpm/pnpm#11448: Modifies injected workspace dependency deduplication and dedupeInjectedDeps subset matching.
  • pnpm/pnpm#12179: Adjusts peer-dependent deduplication logic involving nodeDepsCount and compatibility matching.

Suggested labels: 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.

@omril1
omril1 marked this pull request as ready for review July 6, 2026 06:57
@omril1
omril1 requested a review from zkochan as a code owner July 6, 2026 06:57
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Fix injected-workspace dedupe when unrelated deps differ only by peer-suffix

🐞 Bug fix 🧪 Tests ⚙️ Configuration changes 🕐 20-40 Minutes

Grey Divider

AI Description

• Allow injected workspace deps to dedupe to link: even if shared deps differ by peer-suffix.
• Reuse existing peer-compatibility logic (isCompatibleAndHasMoreDeps) instead of strict depPath
 equality.
• Add regression test and changeset for pnpm/pnpm#10433-style lockfile churn.
Diagram

graph TD
  A["Injected workspace dep (file:)"] --> B["dedupeInjectedDeps.getDedupeMap"] --> C["dedupeInjectedDeps.applyDedupeMap"] --> D["Resolved importer uses link:"]
  G[("dependenciesByProjectId")] --> B
  F[("depGraph")] --> B
  B --> E["resolvePeers.isCompatibleAndHasMoreDeps"]
  H["dedupeInjectedDeps.test"] --> B
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Run injected-dedupe after peer-deduplication
  • ➕ Avoids needing compatibility logic in dedupeInjectedDeps by letting peer dedupe normalize depPaths first
  • ➕ May reduce duplicate compatibility code paths
  • ➖ Requires reordering phases in the resolver, increasing risk of unintended behavior changes
  • ➖ Harder to reason about performance and invariants across passes
2. Compare on package identity instead of depPath strings
  • ➕ More robust to formatting/suffix differences in depPath encoding
  • ➖ depPath encodes peer context and exact child graph; weakening it risks incorrect dedupe in real peer-sensitive cases
  • ➖ Would likely require a new, carefully-defined equivalence relation anyway
3. Strip/normalize peer suffixes before subset comparison
  • ➕ Simple conceptual model (treat peer suffix as non-semantic for this check)
  • ➖ Incorrect when peer context meaningfully changes the dependency closure; may cause unsafe dedupes
  • ➖ Still needs a notion of 'safe superset' to avoid regressions

Recommendation: Keep the current approach: reusing isCompatibleAndHasMoreDeps is the smallest, most consistent change because it applies the resolver’s existing definition of “compatible superset” to injected-dedupe without reordering install phases or inventing a new equivalence rule. The added focused regression test makes the subtle lockfile/peer interaction reviewable and maintainable.

Files changed (4) +118 / -7

Bug fix (1) +20 / -6
dedupeInjectedDeps.tsTreat peer-suffixed target deps as compatible for injected dedupe +20/-6

Treat peer-suffixed target deps as compatible for injected dedupe

• Updates 'getDedupeMap' to consider a target depPath acceptable when it is compatible and has a superset of deps relative to the injected occurrence, not only when depPath strings match exactly. This prevents incorrect failure to dedupe back to 'link:' when only an unrelated shared dependency differs by a peer suffix.

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

Refactor (1) +1 / -1
resolvePeers.tsExport peer-compatibility helper for reuse +1/-1

Export peer-compatibility helper for reuse

• Exports 'isCompatibleAndHasMoreDeps' so other resolver steps can reuse the existing compatibility definition. No behavioral change besides making the function available to callers.

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

Tests (1) +91 / -0
dedupeInjectedDeps.test.tsAdd regression test for injected dedupe with peer-suffix mismatch +91/-0

Add regression test for injected dedupe with peer-suffix mismatch

• Introduces a unit test that constructs a minimal depGraph and per-project dependency maps where an unrelated shared dependency is peer-suffixed only on the target side. Verifies the injected dep still dedupes to 'link:' and is marked as a linked dependency.

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

Other (1) +6 / -0
dedupe-injected-deps-unrelated-peer-suffix.mdAdd changeset documenting injected-dedupe peer-suffix fix +6/-0

Add changeset documenting injected-dedupe peer-suffix fix

• Adds a patch changeset for both '@pnpm/installing.deps-resolver' and 'pnpm'. Describes the scenario where injected workspace deps incorrectly remain 'file:' due to unrelated peer-suffix differences.

.changeset/dedupe-injected-deps-unrelated-peer-suffix.md

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Jul 6, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

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

Context used

Grey Divider


Action required

1. Identity-blind compatibility dedupe 🐞 Bug ≡ Correctness
Description
getDedupeMap() now treats a child depPath mismatch as OK when isCompatibleAndHasMoreDeps()
returns true, but that helper doesn’t check id/pkgIdWithPatchHash/name/version equality and
can therefore consider unrelated leaf packages (no deps/peers) “compatible”. This can incorrectly
dedupe an injected workspace package to link: even when the target project resolved a different
version for the same alias, changing the effective dependency graph.
Code

pnpm11/installing/deps-resolver/src/dedupeInjectedDeps.ts[R84-97]

+        .every(([alias, depPath]) => {
+          const targetDepPath = targetProjectDeps.get(alias)
+          if (targetDepPath === depPath) return true
+          // An ordinary (non-workspace) shared dependency of the injected
+          // package can resolve to a peer-suffixed variant on one side and a
+          // peer-free variant on the other -- e.g. when reconciling against an
+          // existing lockfile pins an optional peer (debug's supports-color)
+          // for the target project's own resolution but not for the injected
+          // occurrence. Both are valid resolutions of the same package; what
+          // matters is whether the target project's own copy is at least as
+          // complete as what the injected occurrence needed, not that the two
+          // depPath strings are byte-identical. See pnpm/pnpm#10433.
+          return targetDepPath != null && isCompatibleAndHasMoreDeps(opts.depGraph, targetDepPath, depPath)
+        })
Evidence
The new subset predicate accepts non-equal depPaths via isCompatibleAndHasMoreDeps, but that
helper ignores package identity/version and only checks dependency/peer-set inclusion, so it can
return true for unrelated nodes (especially leaf nodes), enabling unsafe dedupe decisions.

pnpm11/installing/deps-resolver/src/dedupeInjectedDeps.ts[80-101]
pnpm11/installing/deps-resolver/src/resolvePeers.ts[312-329]

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

## Issue description
`dedupeInjectedDeps.getDedupeMap()` now falls back to `isCompatibleAndHasMoreDeps(depGraph, targetDepPath, depPath)` whenever the depPath strings differ. `isCompatibleAndHasMoreDeps()` only compares children depPaths and `resolvedPeerNames`, and does **not** confirm both depPaths refer to the same package identity/version. For leaf packages (empty children/peers), it can return `true` across different versions/identities, making the subset check pass and allowing an unsafe dedupe to `link:`.
### Issue Context
The compatibility predicate is safe in `deduplicateDepPaths()` because it is only used on depPath sets grouped by `pkgIdWithPatchHash`, but `dedupeInjectedDeps` does not currently enforce that constraint.
### Fix Focus Areas
- pnpm11/installing/deps-resolver/src/dedupeInjectedDeps.ts[83-97]
- pnpm11/installing/deps-resolver/src/resolvePeers.ts[312-329]
### Suggested fix
At the call site (preferred), require that the two nodes represent the same base package identity before applying compatibility:
- Guard that `opts.depGraph[targetDepPath]` and `opts.depGraph[depPath]` both exist.
- Require `opts.depGraph[targetDepPath].pkgIdWithPatchHash === opts.depGraph[depPath].pkgIdWithPatchHash` (or equivalent identity check) before calling `isCompatibleAndHasMoreDeps`.
- If identity differs, return `false` (do not dedupe).
This keeps the intended peer-suffix tolerance while preventing cross-version/identity “compatibility” from being treated as safe.

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



Remediation recommended

2. Extra allocations in dedupe 🐞 Bug ➹ Performance ⭐ New
Description
getDedupeMap() now calls isCompatibleAndHasMoreDeps() on depPath mismatches, and that helper
allocates Object.values arrays and a Set per invocation, adding CPU/GC overhead during dependency
resolution when injected workspace deps are being deduped.
Code

pnpm11/installing/deps-resolver/src/dedupeInjectedDeps.ts[R84-97]

+        .every(([alias, depPath]) => {
+          const targetDepPath = targetProjectDeps.get(alias)
+          if (targetDepPath === depPath) return true
+          // An ordinary (non-workspace) shared dependency of the injected
+          // package can resolve to a peer-suffixed variant on one side and a
+          // peer-free variant on the other -- e.g. when reconciling against an
+          // existing lockfile pins an optional peer (debug's supports-color)
+          // for the target project's own resolution but not for the injected
+          // occurrence. Both are valid resolutions of the same package; what
+          // matters is whether the target project's own copy is at least as
+          // complete as what the injected occurrence needed, not that the two
+          // depPath strings are byte-identical. See pnpm/pnpm#10433.
+          return targetDepPath != null && isCompatibleAndHasMoreDeps(opts.depGraph, targetDepPath, depPath)
+        })
Evidence
The new subset logic invokes isCompatibleAndHasMoreDeps() for mismatched child depPaths, and the
helper constructs new arrays/Sets each call, increasing allocations in the resolver loop.

pnpm11/installing/deps-resolver/src/dedupeInjectedDeps.ts[80-100]
pnpm11/installing/deps-resolver/src/resolvePeers.ts[312-329]

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

## Issue description
`getDedupeMap()` now calls `isCompatibleAndHasMoreDeps()` inside a per-child `.every(...)` loop on mismatches. `isCompatibleAndHasMoreDeps()` allocates `Object.values(...)` arrays and a `Set(...)` each time, which increases CPU and GC work in the resolver.

## Issue Context
This runs during install/update resolution and can be invoked multiple times per injected workspace dependency when peer-suffix mismatches are present.

## Fix Focus Areas
- pnpm11/installing/deps-resolver/src/dedupeInjectedDeps.ts[80-100]
- pnpm11/installing/deps-resolver/src/resolvePeers.ts[312-329]

## Suggested fix
- Add a small memoization layer in `getDedupeMap()` keyed by `(targetDepPath, depPath)` so repeated checks reuse results.
- Optionally, refactor `isCompatibleAndHasMoreDeps()` (or wrap it) to avoid repeated `Object.values()` / `new Set()` by caching a `Set<DepPath>` for `node.children` per `depPath1` within the current `getDedupeMap()` execution.

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


3. New resolvePeers import cycle 🐞 Bug ⚙ Maintainability
Description
dedupeInjectedDeps now value-imports isCompatibleAndHasMoreDeps from resolvePeers, while
resolvePeers already imports dedupeInjectedDeps, introducing a new circular dependency between
these modules. This is a maintainability/perf risk (module initialization/order sensitivity and
unnecessary load coupling) even if it happens to work today.
Code

pnpm11/installing/deps-resolver/src/dedupeInjectedDeps.ts[R9-15]

+import {
+  type DependenciesByProjectId,
+  type GenericDependenciesGraphWithResolvedChildren,
+  isCompatibleAndHasMoreDeps,
+  type PartialResolvedPackage,
+  type ProjectToResolve,
} from './resolvePeers.js'
Evidence
The PR changes dedupeInjectedDeps from a type-only import to a runtime import from resolvePeers,
while resolvePeers already imports dedupeInjectedDeps, forming a direct cycle.

pnpm11/installing/deps-resolver/src/dedupeInjectedDeps.ts[9-15]
pnpm11/installing/deps-resolver/src/resolvePeers.ts[18-20]
pnpm11/installing/deps-resolver/src/resolvePeers.ts[312-329]

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 new runtime circular dependency was introduced:
- `resolvePeers.ts` imports `dedupeInjectedDeps`.
- `dedupeInjectedDeps.ts` now imports a runtime symbol from `resolvePeers.ts`.
Even when it doesn’t break at runtime, this increases coupling and makes future refactors riskier.
### Issue Context
Previously, `dedupeInjectedDeps` imported only types from `resolvePeers` (erased at runtime), so there was no runtime cycle.
### Fix Focus Areas
- pnpm11/installing/deps-resolver/src/dedupeInjectedDeps.ts[9-15]
- pnpm11/installing/deps-resolver/src/resolvePeers.ts[18-20]
- pnpm11/installing/deps-resolver/src/resolvePeers.ts[312-329]
### Suggested fix
Move `isCompatibleAndHasMoreDeps` (and any tiny helpers it needs, like `nodeDepsCount`) into a small dedicated module (e.g. `depPathCompatibility.ts`) that both `resolvePeers.ts` and `dedupeInjectedDeps.ts` can import, avoiding the cycle entirely.

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


Grey Divider

Previous review results

Review updated until commit 3d50c9f

Results up to commit 3d50c9f


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

Context used

Action required
1. Identity-blind compatibility dedupe 🐞 Bug ≡ Correctness
Description
getDedupeMap() now treats a child depPath mismatch as OK when isCompatibleAndHasMoreDeps()
returns true, but that helper doesn’t check id/pkgIdWithPatchHash/name/version equality and
can therefore consider unrelated leaf packages (no deps/peers) “compatible”. This can incorrectly
dedupe an injected workspace package to link: even when the target project resolved a different
version for the same alias, changing the effective dependency graph.
Code

pnpm11/installing/deps-resolver/src/dedupeInjectedDeps.ts[R84-97]

+        .every(([alias, depPath]) => {
+          const targetDepPath = targetProjectDeps.get(alias)
+          if (targetDepPath === depPath) return true
+          // An ordinary (non-workspace) shared dependency of the injected
+          // package can resolve to a peer-suffixed variant on one side and a
+          // peer-free variant on the other -- e.g. when reconciling against an
+          // existing lockfile pins an optional peer (debug's supports-color)
+          // for the target project's own resolution but not for the injected
+          // occurrence. Both are valid resolutions of the same package; what
+          // matters is whether the target project's own copy is at least as
+          // complete as what the injected occurrence needed, not that the two
+          // depPath strings are byte-identical. See pnpm/pnpm#10433.
+          return targetDepPath != null && isCompatibleAndHasMoreDeps(opts.depGraph, targetDepPath, depPath)
+        })
Evidence
The new subset predicate accepts non-equal depPaths via isCompatibleAndHasMoreDeps, but that
helper ignores package identity/version and only checks dependency/peer-set inclusion, so it can
return true for unrelated nodes (especially leaf nodes), enabling unsafe dedupe decisions.

pnpm11/installing/deps-resolver/src/dedupeInjectedDeps.ts[80-101]
pnpm11/installing/deps-resolver/src/resolvePeers.ts[312-329]

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

### Issue description
`dedupeInjectedDeps.getDedupeMap()` now falls back to `isCompatibleAndHasMoreDeps(depGraph, targetDepPath, depPath)` whenever the depPath strings differ. `isCompatibleAndHasMoreDeps()` only compares children depPaths and `resolvedPeerNames`, and does **not** confirm both depPaths refer to the same package identity/version. For leaf packages (empty children/peers), it can return `true` across different versions/identities, making the subset check pass and allowing an unsafe dedupe to `link:`.

### Issue Context
The compatibility predicate is safe in `deduplicateDepPaths()` because it is only used on depPath sets grouped by `pkgIdWithPatchHash`, but `dedupeInjectedDeps` does not currently enforce that constraint.

### Fix Focus Areas
- pnpm11/installing/deps-resolver/src/dedupeInjectedDeps.ts[83-97]
- pnpm11/installing/deps-resolver/src/resolvePeers.ts[312-329]

### Suggested fix
At the call site (preferred), require that the two nodes represent the same base package identity before applying compatibility:
- Guard that `opts.depGraph[targetDepPath]` and `opts.depGraph[depPath]` both exist.
- Require `opts.depGraph[targetDepPath].pkgIdWithPatchHash === opts.depGraph[depPath].pkgIdWithPatchHash` (or equivalent identity check) before calling `isCompatibleAndHasMoreDeps`.
- If identity differs, return `false` (do not dedupe).

This keeps the intended peer-suffix tolerance while preventing cross-version/identity “compatibility” from being treated as safe.

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



Remediation recommended
2. New resolvePeers import cycle 🐞 Bug ⚙ Maintainability
Description
dedupeInjectedDeps now value-imports isCompatibleAndHasMoreDeps from resolvePeers, while
resolvePeers already imports dedupeInjectedDeps, introducing a new circular dependency between
these modules. This is a maintainability/perf risk (module initialization/order sensitivity and
unnecessary load coupling) even if it happens to work today.
Code

pnpm11/installing/deps-resolver/src/dedupeInjectedDeps.ts[R9-15]

+import {
+  type DependenciesByProjectId,
+  type GenericDependenciesGraphWithResolvedChildren,
+  isCompatibleAndHasMoreDeps,
+  type PartialResolvedPackage,
+  type ProjectToResolve,
} from './resolvePeers.js'
Evidence
The PR changes dedupeInjectedDeps from a type-only import to a runtime import from resolvePeers,
while resolvePeers already imports dedupeInjectedDeps, forming a direct cycle.

pnpm11/installing/deps-resolver/src/dedupeInjectedDeps.ts[9-15]
pnpm11/installing/deps-resolver/src/resolvePeers.ts[18-20]
pnpm11/installing/deps-resolver/src/resolvePeers.ts[312-329]

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 new runtime circular dependency was introduced:
- `resolvePeers.ts` imports `dedupeInjectedDeps`.
- `dedupeInjectedDeps.ts` now imports a runtime symbol from `resolvePeers.ts`.

Even when it doesn’t break at runtime, this increases coupling and makes future refactors riskier.

### Issue Context
Previously, `dedupeInjectedDeps` imported only types from `resolvePeers` (erased at runtime), so there was no runtime cycle.

### Fix Focus Areas
- pnpm11/installing/deps-resolver/src/dedupeInjectedDeps.ts[9-15]
- pnpm11/installing/deps-resolver/src/resolvePeers.ts[18-20]
- pnpm11/installing/deps-resolver/src/resolvePeers.ts[312-329]

### Suggested fix
Move `isCompatibleAndHasMoreDeps` (and any tiny helpers it needs, like `nodeDepsCount`) into a small dedicated module (e.g. `depPathCompatibility.ts`) that both `resolvePeers.ts` and `dedupeInjectedDeps.ts` can import, avoiding the cycle entirely.

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


ⓘ  1 issues published inline · 2 in summary

Qodo Logo

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
pnpm11/installing/deps-resolver/test/dedupeInjectedDeps.test.ts (1)

23-91: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Solid regression test; consider adding a negative case.

The fixture accurately reproduces the reported bug and correctly asserts the OS-independent link: outcome. Since the fix hinges on isCompatibleAndHasMoreDeps being a superset check (not just "differs"), a complementary case where the target is not compatible (e.g., missing a required child, or fewer deps) — asserting dedupe does not happen — would guard against a future regression that makes the check too permissive.

🧪 Example negative-case sketch
test('injected dependency does not dedupe when the target is missing a required child', () => {
  // reuse the fixture above, but set:
  // dependenciesByProjectId['packages/pkg-c'].set('debug', '[email protected]' as DepPath)
  // where '[email protected]' has no children/resolvedPeerNames overlap with '[email protected]'
  // then assert resolvedDep.pkgId is unchanged (still file:...), not link:../pkg-c
})
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pnpm11/installing/deps-resolver/test/dedupeInjectedDeps.test.ts` around lines
23 - 91, The existing test in dedupeInjectedDeps.test.ts covers the positive
link: case for deduping injected deps, but it should also protect the
compatibility check used by isCompatibleAndHasMoreDeps. Add a negative test
alongside the current dedupeInjectedDeps fixture where the target dependency is
not a superset of the injected one (for example, a missing child or fewer deps
for debug in the packages/pkg-c resolution), and assert that
resolvedImporters['packages/consumer'].directDependencies[0].pkgId stays
unchanged instead of becoming link:../pkg-c.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@pnpm11/installing/deps-resolver/test/dedupeInjectedDeps.test.ts`:
- Around line 23-91: The existing test in dedupeInjectedDeps.test.ts covers the
positive link: case for deduping injected deps, but it should also protect the
compatibility check used by isCompatibleAndHasMoreDeps. Add a negative test
alongside the current dedupeInjectedDeps fixture where the target dependency is
not a superset of the injected one (for example, a missing child or fewer deps
for debug in the packages/pkg-c resolution), and assert that
resolvedImporters['packages/consumer'].directDependencies[0].pkgId stays
unchanged instead of becoming link:../pkg-c.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 6cf7b97d-a6fe-4c8c-ad99-12cda001b70f

📥 Commits

Reviewing files that changed from the base of the PR and between 7cd1e4f and 3d50c9f.

📒 Files selected for processing (4)
  • .changeset/dedupe-injected-deps-unrelated-peer-suffix.md
  • pnpm11/installing/deps-resolver/src/dedupeInjectedDeps.ts
  • pnpm11/installing/deps-resolver/src/resolvePeers.ts
  • pnpm11/installing/deps-resolver/test/dedupeInjectedDeps.test.ts

@github-actions github-actions Bot added the reviewed: coderabbit CodeRabbit submitted an approving review label Jul 6, 2026
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

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

@omril1

omril1 commented Jul 11, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the automated review — addressed in dc4dc18:

🐞 Identity-blind compatibility dedupe (correctness) — Fixed. getDedupeMap now requires the injected child and the target project's dependency to share the same package identity (pkgIdWithPatchHash) before falling back to isCompatibleAndHasMoreDeps. You're right that the helper compares dependency/peer sets only, so two different versions of a shared leaf dep (both empty sets) would otherwise be treated as interchangeable. Added a regression test (test/dedupeInjectedDeps.test.ts) asserting a version mismatch stays file:, and made the existing peer-suffix test faithful (both debug variants now carry the same pkgIdWithPatchHash).

🐞 New resolvePeers import cycle (maintainability) — Fixed. Extracted isCompatibleAndHasMoreDeps + nodeDepsCount into a new depPathCompatibility.ts; both resolvePeers and dedupeInjectedDeps now import from it, so there's no longer a runtime value-import from dedupeInjectedDeps back into resolvePeers. The only remaining reference to resolvePeers from the new module is import type, which is erased at build time.

🐞 Extra allocations in dedupe (performance) — Not changing. dedupeInjectedDeps runs once per install over injected workspace packages' direct children only (a small, bounded set), not in the recursive resolver hot path, so the per-call Set/Object.values cost is negligible and a memoization layer would add complexity for no measurable gain. Happy to revisit if a profile shows otherwise.


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

@greptile-apps

greptile-apps Bot commented Jul 11, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

Safe to merge — the change is narrowly scoped to the isSubset check inside getDedupeMap, uses an already-proven compatibility predicate, and cannot widen the dedupe set beyond what deduplicateDepPaths already permits.

The fix is a minimal, well-reasoned relaxation of a strict equality check: three defensive guards (null, graph membership, package identity) precede the compatibility call, making false-positive dedupes impossible. Both TypeScript and Rust implementations are symmetric. Regression tests directly exercise the confirmed failure shape.

No files require special attention.

Reviews (10): Last reviewed commit: "chore(changeset): add pacquet to the inj..." | Re-trigger Greptile

@omril1
omril1 force-pushed the fix/dedupe-injected-deps-unrelated-peer-suffix branch 2 times, most recently from 74633fe to cfed4a0 Compare July 12, 2026 14:55
@zkochan
zkochan force-pushed the fix/dedupe-injected-deps-unrelated-peer-suffix branch from cfed4a0 to bb50e42 Compare July 12, 2026 20:30
@qodo-code-review

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

Copy link
Copy Markdown

Code Review by Qodo

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

Context used
✅ Compliance rules (platform): 18 rules

Grey Divider


Action required

1. Missing trailing comma ✗ Dismissed 📘 Rule violation ⚙ Maintainability
Description
The multi-line parameter list for isCompatibleAndHasMoreDeps omits a trailing comma on the last
parameter, violating the required TypeScript trailing-comma style and causing noisier future diffs.
Code

pnpm11/installing/deps-resolver/src/depPathCompatibility.ts[R27-31]

+export function isCompatibleAndHasMoreDeps<T extends PartialResolvedPackage> (
+  depGraph: GenericDependenciesGraphWithResolvedChildren<T>,
+  depPath1: DepPath,
+  depPath2: DepPath
+): boolean {
Evidence
PR Compliance ID 713434 requires trailing commas in multi-line TypeScript constructs. The function
signature for isCompatibleAndHasMoreDeps is multi-line, but depPath2: DepPath has no trailing
comma before the closing parenthesis.

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

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
The repo requires trailing commas in multi-line TypeScript constructs to keep diffs stable and consistent.

## Fix Focus Areas
- pnpm11/installing/deps-resolver/src/depPathCompatibility.ts[27-31]

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



Remediation recommended

2. DepPath identity misparsed 🐞 Bug ≡ Correctness ⭐ New
Description
child_matches_target uses get_pkg_id_with_patch_hash(depPathStr) to guard the compatibility
check, but DepPath strings are explicitly unvalidated and the suffix scanner treats any depPath
ending with ) as having a peer/patch suffix. For a file:/path depPath that legitimately ends
with parentheses (e.g. file:../foo(bar)), this can truncate identity to file:../foo, letting
different deps collide and be treated as compatible, which can incorrectly dedupe an injected
workspace snapshot to link:.
Code

pnpm/crates/resolving-deps-resolver/src/dedupe_injected_deps.rs[R126-135]

+    if !graph.contains_key(target_dep_path) || !graph.contains_key(child_dep_path) {
+        return false;
+    }
+    if get_pkg_id_with_patch_hash(target_dep_path.as_str())
+        != get_pkg_id_with_patch_hash(child_dep_path.as_str())
+    {
+        return false;
+    }
+    is_compatible_and_has_more_deps(graph, target_dep_path, child_dep_path)
+}
Evidence
The new logic relies on depPath suffix parsing for identity, but the depPath type is a
non-validating string wrapper and the suffix scanner activates purely based on a trailing ); this
makes identities ambiguous for valid path-based depPaths that end in parentheses. The graph already
stores a canonical identity (resolved_package_id) used elsewhere to group by pkgIdWithPatchHash,
which would avoid the ambiguity.

pnpm/crates/resolving-deps-resolver/src/dedupe_injected_deps.rs[114-135]
pnpm/crates/deps-path/src/dep_path.rs[1-40]
pnpm/crates/deps-path/src/suffix_index.rs[10-67]
pnpm/crates/resolving-deps-resolver/src/dependencies_graph.rs[16-35]
pnpm/crates/resolving-deps-resolver/src/dedupe_peer_dependents.rs[59-76]

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

### Issue description
`child_matches_target` currently derives identity by parsing depPath strings with `get_pkg_id_with_patch_hash`. Because `DepPath` is not validated, a depPath that happens to end with `(...)` (but where `(...)` is part of a file/path) will be interpreted as a peer suffix and stripped, potentially causing two distinct depPaths (e.g. `file:../foo(bar)` vs `file:../foo(baz)`) to be treated as the same identity.

This can allow `is_compatible_and_has_more_deps` to run on genuinely different packages/paths and return `true` (especially for leaf nodes), incorrectly allowing injected workspace snapshots to dedupe to `link:`.

### Issue Context
The graph nodes already carry a canonical package-identity string (`resolved_package_id`) which `dedupe_peer_dependents` relies on for grouping variants by `pkgIdWithPatchHash`. Using that field avoids ambiguous depPath-suffix parsing entirely.

### Fix Focus Areas
- pnpm/crates/resolving-deps-resolver/src/dedupe_injected_deps.rs[114-135]

### Suggested fix
- Replace the `get_pkg_id_with_patch_hash(...)` equality guard with a comparison of the canonical identity stored on the corresponding graph nodes (e.g. `target_node.resolved_package_id == child_node.resolved_package_id`).
- You can fetch nodes once via `graph.get(...)` (instead of `contains_key` + later indexing) and early-return `false` if either is missing.
- After this change, the `get_pkg_id_with_patch_hash` import may no longer be needed in this file.

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


3. nodeDepsCount declared too early 📘 Rule violation ⚙ Maintainability
Description
nodeDepsCount is declared before its first usage in the same file (used inside
isCompatibleAndHasMoreDeps), violating the required declaration-after-first-usage ordering.
Code

pnpm11/installing/deps-resolver/src/depPathCompatibility.ts[R14-16]

+export function nodeDepsCount (node: GenericDependenciesGraphNodeWithResolvedChildren): number {
+  return Object.keys(node.children!).length + node.resolvedPeerNames.size
+}
Evidence
PR Compliance ID 713432 requires top-level TypeScript function declarations to appear after at least
one usage in the same file. nodeDepsCount is declared at lines 14-16, but its first usage is later
at line 34 inside isCompatibleAndHasMoreDeps.

Rule 713432: Declare TypeScript functions only after their first usage
pnpm11/installing/deps-resolver/src/depPathCompatibility.ts[14-16]
pnpm11/installing/deps-resolver/src/depPathCompatibility.ts[32-35]

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

## Issue description
Top-level TypeScript function declarations must appear after their first usage in the same file.

## Issue Context
`nodeDepsCount` is first used inside `isCompatibleAndHasMoreDeps`, but is declared above it.

## Fix Focus Areas
- pnpm11/installing/deps-resolver/src/depPathCompatibility.ts[14-16]
- pnpm11/installing/deps-resolver/src/depPathCompatibility.ts[27-44]

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


4. Historical comment in test ✓ Resolved 📘 Rule violation ⚙ Maintainability
Description
New comments in dedupeInjectedDeps.test.ts describe the pre-change behavior (strict equality)
using temporal phrasing, which will become misleading now that the implementation has changed.
Code

pnpm11/installing/deps-resolver/test/dedupeInjectedDeps.test.ts[R18-22]

+// what a real install produces once an existing lockfile pins an optional
+// peer (e.g. `debug`'s optional `supports-color`) for one occurrence but not
+// the other: the injected occurrence resolves fresh, the target project's own
+// occurrence inherits the pin, and today's strict string-equality check in
+// `getDedupeMap` strands the entry as `file:(...)` instead of `link:`.
Evidence
PR Compliance ID 772199 disallows comments that describe historical behavior using temporal
phrasing. The test comment says "today's strict string-equality check" and describes it stranding
entries as file:(...), which is no longer the current behavior after this PR; another comment uses
"previously-locked" phrasing.

Rule 772199: Comments must describe current behavior, not historical implementations
pnpm11/installing/deps-resolver/test/dedupeInjectedDeps.test.ts[18-22]
pnpm11/installing/deps-resolver/test/dedupeInjectedDeps.test.ts[61-63]

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

## Issue description
Comments added in the new Jest test include temporal/historical phrasing and describe the old behavior as if it is current.

## Issue Context
The implementation has been updated to tolerate compatible peer-suffix differences, so comments should be phrased in terms of the current behavior or as a counterfactual (e.g., "Without this tolerance...").

## Fix Focus Areas
- pnpm11/installing/deps-resolver/test/dedupeInjectedDeps.test.ts[18-22]
- pnpm11/installing/deps-resolver/test/dedupeInjectedDeps.test.ts[61-63]

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


Grey Divider

Previous review results

Review updated until commit e38bdcc

Results up to commit bb50e42


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


Action required
1. Missing trailing comma ✗ Dismissed 📘 Rule violation ⚙ Maintainability
Description
The multi-line parameter list for isCompatibleAndHasMoreDeps omits a trailing comma on the last
parameter, violating the required TypeScript trailing-comma style and causing noisier future diffs.
Code

pnpm11/installing/deps-resolver/src/depPathCompatibility.ts[R27-31]

+export function isCompatibleAndHasMoreDeps<T extends PartialResolvedPackage> (
+  depGraph: GenericDependenciesGraphWithResolvedChildren<T>,
+  depPath1: DepPath,
+  depPath2: DepPath
+): boolean {
Evidence
PR Compliance ID 713434 requires trailing commas in multi-line TypeScript constructs. The function
signature for isCompatibleAndHasMoreDeps is multi-line, but depPath2: DepPath has no trailing
comma before the closing parenthesis.

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

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
The repo requires trailing commas in multi-line TypeScript constructs to keep diffs stable and consistent.

## Fix Focus Areas
- pnpm11/installing/deps-resolver/src/depPathCompatibility.ts[27-31]

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



Remediation recommended
2. nodeDepsCount declared too early 📘 Rule violation ⚙ Maintainability
Description
nodeDepsCount is declared before its first usage in the same file (used inside
isCompatibleAndHasMoreDeps), violating the required declaration-after-first-usage ordering.
Code

pnpm11/installing/deps-resolver/src/depPathCompatibility.ts[R14-16]

+export function nodeDepsCount (node: GenericDependenciesGraphNodeWithResolvedChildren): number {
+  return Object.keys(node.children!).length + node.resolvedPeerNames.size
+}
Evidence
PR Compliance ID 713432 requires top-level TypeScript function declarations to appear after at least
one usage in the same file. nodeDepsCount is declared at lines 14-16, but its first usage is later
at line 34 inside isCompatibleAndHasMoreDeps.

Rule 713432: Declare TypeScript functions only after their first usage
pnpm11/installing/deps-resolver/src/depPathCompatibility.ts[14-16]
pnpm11/installing/deps-resolver/src/depPathCompatibility.ts[32-35]

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

## Issue description
Top-level TypeScript function declarations must appear after their first usage in the same file.

## Issue Context
`nodeDepsCount` is first used inside `isCompatibleAndHasMoreDeps`, but is declared above it.

## Fix Focus Areas
- pnpm11/installing/deps-resolver/src/depPathCompatibility.ts[14-16]
- pnpm11/installing/deps-resolver/src/depPathCompatibility.ts[27-44]

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


3. Historical comment in test ✓ Resolved 📘 Rule violation ⚙ Maintainability
Description
New comments in dedupeInjectedDeps.test.ts describe the pre-change behavior (strict equality)
using temporal phrasing, which will become misleading now that the implementation has changed.
Code

pnpm11/installing/deps-resolver/test/dedupeInjectedDeps.test.ts[R18-22]

+// what a real install produces once an existing lockfile pins an optional
+// peer (e.g. `debug`'s optional `supports-color`) for one occurrence but not
+// the other: the injected occurrence resolves fresh, the target project's own
+// occurrence inherits the pin, and today's strict string-equality check in
+// `getDedupeMap` strands the entry as `file:(...)` instead of `link:`.
Evidence
PR Compliance ID 772199 disallows comments that describe historical behavior using temporal
phrasing. The test comment says "today's strict string-equality check" and describes it stranding
entries as file:(...), which is no longer the current behavior after this PR; another comment uses
"previously-locked" phrasing.

Rule 772199: Comments must describe current behavior, not historical implementations
pnpm11/installing/deps-resolver/test/dedupeInjectedDeps.test.ts[18-22]
pnpm11/installing/deps-resolver/test/dedupeInjectedDeps.test.ts[61-63]

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

## Issue description
Comments added in the new Jest test include temporal/historical phrasing and describe the old behavior as if it is current.

## Issue Context
The implementation has been updated to tolerate compatible peer-suffix differences, so comments should be phrased in terms of the current behavior or as a counterfactual (e.g., "Without this tolerance...").

## Fix Focus Areas
- pnpm11/installing/deps-resolver/test/dedupeInjectedDeps.test.ts[18-22]
- pnpm11/installing/deps-resolver/test/dedupeInjectedDeps.test.ts[61-63]

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


Qodo Logo

@qodo-code-review

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

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

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

CategorySuggestion                                                                                                                                    Impact
Possible issue
Preserve aliases during compatibility checks

Modify the dependency compatibility check to match both the alias and the
dependency path. Apply this logic to both the TypeScript and Rust
implementations to maintain parity.

pnpm11/installing/deps-resolver/src/depPathCompatibility.ts [36-38]

-const node1DepPathsSet = new Set(Object.values(node1.children!))
-const node2DepPaths = Object.values(node2.children!)
-if (!node2DepPaths.every((depPath) => node1DepPathsSet.has(depPath))) return false
+const node1Children = node1.children!
+const node2Children = node2.children!
+if (!Object.entries(node2Children).every(
+  ([alias, depPath]) => node1Children[alias] === depPath
+)) return false
  • Apply / Chat
Suggestion importance[1-10]: 7

__

Why: Checking dependency matching by alias rather than treating dependency paths as an unordered set improves correctness and avoids potential false positives.

Medium
  • More

@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 587d56f

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

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

CategorySuggestion                                                                                                                                    Impact
Possible issue
Preserve aliases during compatibility checks

Modify the dependency compatibility check to match both the alias and the
dependency path. Apply this logic to both the TypeScript and Rust
implementations to maintain parity.

pnpm11/installing/deps-resolver/src/depPathCompatibility.ts [36-38]

-const node1DepPathsSet = new Set(Object.values(node1.children!))
-const node2DepPaths = Object.values(node2.children!)
-if (!node2DepPaths.every((depPath) => node1DepPathsSet.has(depPath))) return false
+const node1Children = node1.children!
+const node2Children = node2.children!
+if (!Object.entries(node2Children).every(
+  ([alias, depPath]) => node1Children[alias] === depPath
+)) return false
  • Apply / Chat
Suggestion importance[1-10]: 7

__

Why: Checking dependency matching by alias rather than treating dependency paths as an unordered set improves correctness and avoids potential false positives.

Medium
  • More

@zkochan

zkochan commented Jul 12, 2026

Copy link
Copy Markdown
Member

Thanks @qodo — addressed both new findings:

  • Temporal/historical phrasing in the Jest test comments (summary finding): reworded in 193974d. The header no longer describes the pre-fix check as current ("today's ... check strands the entry"); it now reads as a counterfactual ("Without the compatibility tolerance ... a strict string-equality check would strand ..."), and the fixture comment names the existing lockfile as what pinned the peer instead of the "previously-locked" framing.
  • Missing trailing comma on isCompatibleAndHasMoreDeps (inline): false positive for this repo's lint config — Standard Style's comma-dangle omits the trailing comma on the last parameter of a multi-line function signature, matching every other signature in this package. eslint --fix adds nothing and the comma would break lint. Replied and resolved on the thread.

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

@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 193974d

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

Auto-approved notes - no code suggestions found
- 'approve_pr_on_self_review' flag enabled

@qodo-code-review

Copy link
Copy Markdown

Thanks @qodo — addressed both new findings:

  • Temporal/historical phrasing in the Jest test comments (summary finding): reworded in 193974d. The header no longer describes the pre-fix check as current ("today's ... check strands the entry"); it now reads as a counterfactual ("Without the compatibility tolerance ... a strict string-equality check would strand ..."), and the fixture comment names the existing lockfile as what pinned the peer instead of the "previously-locked" framing.
  • Missing trailing comma on isCompatibleAndHasMoreDeps (inline): false positive for this repo's lint config — Standard Style's comma-dangle omits the trailing comma on the last parameter of a multi-line function signature, matching every other signature in this package. eslint --fix adds nothing and the comma would break lint. Replied and resolved on the thread.

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

Thanks for the update. The historical-comment change is reflected in commit 193974d594. I’ll treat the trailing-comma report as a lint false positive based on the repository’s Standard Style configuration. The remaining active items are finding 2 and finding 3.

@github-actions

github-actions Bot commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor

Integrated-Benchmark Report (Linux)

Commit: e38bdccd9dcb

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

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 3.902 ± 0.137 3.798 4.221 1.87 ± 0.09
pacquet@main 3.860 ± 0.146 3.680 4.068 1.85 ± 0.10
pnpr@HEAD 2.091 ± 0.076 2.005 2.264 1.00
pnpr@main 2.183 ± 0.130 2.050 2.431 1.04 ± 0.07
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 3.9015159601400002,
      "stddev": 0.13693646457142403,
      "median": 3.84597484744,
      "user": 3.62390786,
      "system": 3.4925954399999997,
      "min": 3.7980312509400003,
      "max": 4.220589416939999,
      "times": [
        4.220589416939999,
        3.82503718294,
        3.81568239694,
        3.87567228394,
        3.80687354394,
        3.8115270259400003,
        3.7980312509400003,
        4.0508795609399995,
        3.94395442694,
        3.8669125119400003
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 3.86030371814,
      "stddev": 0.14595067115712082,
      "median": 3.8078377129400005,
      "user": 3.7006603599999996,
      "system": 3.48575914,
      "min": 3.67994125394,
      "max": 4.06819013294,
      "times": [
        3.7784182089400002,
        3.74980354894,
        4.057890608939999,
        4.06819013294,
        3.73444845894,
        3.67994125394,
        4.04986191194,
        3.8260224219400003,
        3.7896530039400003,
        3.86880763094
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 2.09145049984,
      "stddev": 0.07614778791265919,
      "median": 2.06819477144,
      "user": 2.70285936,
      "system": 3.0934928399999997,
      "min": 2.00498171094,
      "max": 2.26360605694,
      "times": [
        2.26360605694,
        2.09681663994,
        2.03045832294,
        2.15785561094,
        2.0460771929400003,
        2.05431639094,
        2.00498171094,
        2.13025373394,
        2.0480661869400003,
        2.08207315194
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 2.18298698334,
      "stddev": 0.1296172453778408,
      "median": 2.1406679434400004,
      "user": 2.72789146,
      "system": 3.0852371400000007,
      "min": 2.0498336739400003,
      "max": 2.4313773749400003,
      "times": [
        2.1207885179400003,
        2.36951101694,
        2.0996948099400004,
        2.21993642394,
        2.22052356494,
        2.4313773749400003,
        2.0498336739400003,
        2.16054736894,
        2.1033731659400003,
        2.05428391594
      ]
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 681.7 ± 26.5 657.9 747.2 1.00
pacquet@main 689.4 ± 32.0 642.6 745.9 1.01 ± 0.06
pnpr@HEAD 733.6 ± 36.9 696.0 822.3 1.08 ± 0.07
pnpr@main 754.4 ± 57.6 719.7 912.8 1.11 ± 0.09
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.6816573761000001,
      "stddev": 0.026548923804368175,
      "median": 0.6724756561,
      "user": 0.40868225999999996,
      "system": 1.3539632399999997,
      "min": 0.6579211811000001,
      "max": 0.7472324561000001,
      "times": [
        0.6642647921,
        0.6784035351000001,
        0.6962859181000001,
        0.6775672591,
        0.6668407881,
        0.6673840531,
        0.7472324561000001,
        0.6962985771000001,
        0.6643752011,
        0.6579211811000001
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 0.6893613189000001,
      "stddev": 0.03200098584915062,
      "median": 0.6916436961000001,
      "user": 0.40291516000000005,
      "system": 1.3622421399999998,
      "min": 0.6426264301000001,
      "max": 0.7458873181000001,
      "times": [
        0.6984848191,
        0.6725294951,
        0.6892981391,
        0.6426264301000001,
        0.6939892531,
        0.6696300791,
        0.7458873181000001,
        0.6956867721000001,
        0.7314514801,
        0.6540294031
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.7336157314,
      "stddev": 0.03694108110940039,
      "median": 0.7331143726,
      "user": 0.43216216,
      "system": 1.37176294,
      "min": 0.6959666421,
      "max": 0.8223345541000001,
      "times": [
        0.6975943631,
        0.7433558281,
        0.7449940711,
        0.7450434991,
        0.6959666421,
        0.7019754581000001,
        0.7186641531000001,
        0.7255091251000001,
        0.7407196201,
        0.8223345541000001
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.7544281899,
      "stddev": 0.05762960724288709,
      "median": 0.7359084431,
      "user": 0.42200935999999994,
      "system": 1.3774664399999996,
      "min": 0.7196825531000001,
      "max": 0.9128205281,
      "times": [
        0.7532362561,
        0.7418320491,
        0.7336351221,
        0.7210335201000001,
        0.7289277441,
        0.7265334881000001,
        0.7381817641,
        0.7196825531000001,
        0.9128205281,
        0.7683988741000001
      ]
    }
  ]
}

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 4.361 ± 0.048 4.302 4.430 1.98 ± 0.07
pacquet@main 4.339 ± 0.057 4.263 4.418 1.97 ± 0.08
pnpr@HEAD 2.199 ± 0.079 2.082 2.291 1.00
pnpr@main 2.255 ± 0.112 2.142 2.430 1.03 ± 0.06
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 4.36051421724,
      "stddev": 0.047522921281315314,
      "median": 4.35307488284,
      "user": 3.8362516999999996,
      "system": 3.4837108199999998,
      "min": 4.30172998134,
      "max": 4.43007183234,
      "times": [
        4.35290606734,
        4.43007183234,
        4.31211624134,
        4.35324369834,
        4.38945457734,
        4.31339141534,
        4.410180656340001,
        4.32724524434,
        4.4148024583400005,
        4.30172998134
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 4.33892107644,
      "stddev": 0.05731862851361171,
      "median": 4.32234076934,
      "user": 3.863405099999999,
      "system": 3.4543311200000004,
      "min": 4.26278168434,
      "max": 4.41836359534,
      "times": [
        4.41418341534,
        4.41836359534,
        4.31991725534,
        4.30745529934,
        4.26857557134,
        4.3857690083400005,
        4.30461369334,
        4.3827869583400005,
        4.32476428334,
        4.26278168434
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 2.1991402419400004,
      "stddev": 0.07893280485371389,
      "median": 2.1928398918400003,
      "user": 2.5077916,
      "system": 2.98203512,
      "min": 2.08183867434,
      "max": 2.29100613034,
      "times": [
        2.08183867434,
        2.1519421643400003,
        2.17134226134,
        2.21433752234,
        2.1126653123400003,
        2.28582540734,
        2.2842457183400002,
        2.29100613034,
        2.1342614713400003,
        2.2639377573400004
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 2.25496453414,
      "stddev": 0.11233343434737682,
      "median": 2.22622946234,
      "user": 2.5606339,
      "system": 3.0020055199999995,
      "min": 2.14240561034,
      "max": 2.42959862534,
      "times": [
        2.2190280333400003,
        2.2334308913400003,
        2.14569895134,
        2.42684613234,
        2.14240561034,
        2.3644560413400004,
        2.42959862534,
        2.15710451634,
        2.2508328303400003,
        2.18024370934
      ]
    }
  ]
}

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 1.455 ± 0.016 1.431 1.483 2.06 ± 0.16
pacquet@main 1.448 ± 0.043 1.414 1.567 2.05 ± 0.17
pnpr@HEAD 0.712 ± 0.037 0.693 0.814 1.01 ± 0.09
pnpr@main 0.706 ± 0.053 0.669 0.853 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 1.45451974934,
      "stddev": 0.016091366030999955,
      "median": 1.45250456174,
      "user": 1.44116046,
      "system": 1.7702324000000005,
      "min": 1.43148076874,
      "max": 1.48262853974,
      "times": [
        1.45409641174,
        1.44960339274,
        1.45885219074,
        1.44040881174,
        1.47032603374,
        1.43148076874,
        1.43759993274,
        1.45091271174,
        1.46928869974,
        1.48262853974
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 1.4477350871400003,
      "stddev": 0.043251009621229033,
      "median": 1.43747758324,
      "user": 1.39658666,
      "system": 1.7656389000000001,
      "min": 1.41354206174,
      "max": 1.5665989667400002,
      "times": [
        1.5665989667400002,
        1.42090360774,
        1.44120955874,
        1.45070960674,
        1.43165534574,
        1.44593259874,
        1.41354206174,
        1.44190910174,
        1.43374560774,
        1.4311444157400002
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.7119819460400001,
      "stddev": 0.036870311552646556,
      "median": 0.69879992574,
      "user": 0.37340806,
      "system": 1.3250302,
      "min": 0.69298685274,
      "max": 0.81427021174,
      "times": [
        0.69571148674,
        0.81427021174,
        0.7215560177400001,
        0.70245167874,
        0.70487923474,
        0.69589211474,
        0.6992465857400001,
        0.6944720117400001,
        0.69835326574,
        0.69298685274
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.70552925454,
      "stddev": 0.053156912701832766,
      "median": 0.6946199267400001,
      "user": 0.36882366,
      "system": 1.3172555,
      "min": 0.6685607357400001,
      "max": 0.85284003474,
      "times": [
        0.6918807827400001,
        0.68265224274,
        0.6722030117400001,
        0.6685607357400001,
        0.6982424867400001,
        0.7023649067400001,
        0.6852536427400001,
        0.69735907074,
        0.85284003474,
        0.7039356307400001
      ]
    }
  ]
}

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 3.160 ± 0.021 3.132 3.195 4.58 ± 0.08
pacquet@main 3.170 ± 0.029 3.116 3.213 4.60 ± 0.08
pnpr@HEAD 0.690 ± 0.011 0.669 0.704 1.00
pnpr@main 0.726 ± 0.036 0.696 0.817 1.05 ± 0.05
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 3.1600209163599997,
      "stddev": 0.021396458455088044,
      "median": 3.15743626066,
      "user": 1.94860082,
      "system": 2.0321578199999997,
      "min": 3.13152232416,
      "max": 3.19529773616,
      "times": [
        3.1744286021600003,
        3.13513250316,
        3.1553941401600003,
        3.18153864916,
        3.19529773616,
        3.14506482716,
        3.15947838116,
        3.14496535016,
        3.13152232416,
        3.1773866501600003
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 3.1701918353600003,
      "stddev": 0.028657072543435268,
      "median": 3.17665215116,
      "user": 1.8644539199999994,
      "system": 2.00898802,
      "min": 3.11559721316,
      "max": 3.2129158921600003,
      "times": [
        3.16003006616,
        3.18349636616,
        3.1580925731600002,
        3.17966118316,
        3.13599773016,
        3.19039837416,
        3.1736431191600003,
        3.2129158921600003,
        3.11559721316,
        3.19208583616
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.6898079931600001,
      "stddev": 0.01055904411326214,
      "median": 0.69102402316,
      "user": 0.36986172000000006,
      "system": 1.3118337199999999,
      "min": 0.66858297016,
      "max": 0.70412996516,
      "times": [
        0.69066242416,
        0.6893122461600001,
        0.67635361616,
        0.69401365216,
        0.70412996516,
        0.69230473116,
        0.6897196721600001,
        0.66858297016,
        0.7016150321600001,
        0.69138562216
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.72587789256,
      "stddev": 0.03622486614167061,
      "median": 0.71569992216,
      "user": 0.36356762,
      "system": 1.3391374199999997,
      "min": 0.69587952616,
      "max": 0.81703912316,
      "times": [
        0.7201222851600001,
        0.70228265416,
        0.7028341031600001,
        0.69587952616,
        0.71127755916,
        0.74976450916,
        0.81703912316,
        0.72413657616,
        0.73444231916,
        0.70100027016
      ]
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 666.1 ± 15.3 640.8 684.7 6.04 ± 0.21
pacquet@main 676.0 ± 12.3 652.1 692.9 6.13 ± 0.19
pnpr@HEAD 110.2 ± 2.8 106.2 115.7 1.00
pnpr@main 111.0 ± 2.2 107.2 113.9 1.01 ± 0.03
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.66611194916,
      "stddev": 0.015339936663455756,
      "median": 0.66462637276,
      "user": 0.6255671599999999,
      "system": 0.16139434,
      "min": 0.64078628926,
      "max": 0.68474104526,
      "times": [
        0.67557860626,
        0.68219154226,
        0.65557524326,
        0.67343940926,
        0.65530020126,
        0.64078628926,
        0.65508844726,
        0.68474104526,
        0.65581333626,
        0.68260537126
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 0.6759720684599999,
      "stddev": 0.012251938940567579,
      "median": 0.67384863526,
      "user": 0.64153616,
      "system": 0.15554494000000002,
      "min": 0.65211983426,
      "max": 0.6929091202600001,
      "times": [
        0.6929091202600001,
        0.68924086726,
        0.68701465426,
        0.67519635726,
        0.67250091326,
        0.66861962126,
        0.66803518426,
        0.67133222826,
        0.68275190426,
        0.65211983426
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.11024757082521738,
      "stddev": 0.002772588732426575,
      "median": 0.10978935626000001,
      "user": 0.029000107826086953,
      "system": 0.020401492173913044,
      "min": 0.10622165826,
      "max": 0.11569978226000001,
      "times": [
        0.11569978226000001,
        0.10879987526000001,
        0.11152273026000001,
        0.10922005626,
        0.10622165826,
        0.10978935626000001,
        0.11166260026000001,
        0.10686676826000001,
        0.10939669526000001,
        0.11330731026000002,
        0.11313294626,
        0.11353242926000001,
        0.11269450026000001,
        0.11190622426,
        0.10834158226000001,
        0.10718040126000002,
        0.10731446126000001,
        0.10809267926,
        0.10760126526000001,
        0.10661175426000001,
        0.11003837926000001,
        0.11394759226000001,
        0.11281308126
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.11099933855166666,
      "stddev": 0.002246695664936872,
      "median": 0.11189459276000001,
      "user": 0.029289259999999994,
      "system": 0.02057842333333333,
      "min": 0.10715800026000001,
      "max": 0.11392807526000001,
      "times": [
        0.11333970126000001,
        0.11161838826,
        0.11070135226000001,
        0.10956322826,
        0.11261673626,
        0.10715800026000001,
        0.11015010726,
        0.11179361526,
        0.11199557026000001,
        0.10732575226,
        0.10895100626000001,
        0.11231688026000002,
        0.11392807526000001,
        0.11218349926000001,
        0.10729930026000001,
        0.10749214126000001,
        0.10923015526,
        0.10857451826,
        0.11269243626000001,
        0.11296760626,
        0.11243862426000001,
        0.11271684226,
        0.11360074626000001,
        0.11332984226000001
      ]
    }
  ]
}

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 6.746 ± 0.091 6.653 6.925 1.35 ± 0.03
pacquet@main 6.678 ± 0.161 6.529 7.034 1.33 ± 0.04
pnpr@HEAD 5.010 ± 0.069 4.905 5.090 1.00
pnpr@main 5.014 ± 0.070 4.872 5.099 1.00 ± 0.02
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 6.746411383500001,
      "stddev": 0.09126891922622116,
      "median": 6.7150952827,
      "user": 3.9192254400000004,
      "system": 3.76942266,
      "min": 6.652844182200001,
      "max": 6.9252512652,
      "times": [
        6.685537920200001,
        6.9252512652,
        6.7148246682,
        6.6950097342,
        6.652844182200001,
        6.7070983902000005,
        6.715365897200001,
        6.7493133342,
        6.718812270200001,
        6.9000561732
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 6.678250071300001,
      "stddev": 0.16117149649095505,
      "median": 6.6241221467,
      "user": 3.90152634,
      "system": 3.74487036,
      "min": 6.5293218282000005,
      "max": 7.0337211452,
      "times": [
        6.859449507200001,
        6.5677908702000005,
        6.5293218282000005,
        6.5910578292,
        6.6571864642000005,
        6.551644979200001,
        6.576216892200001,
        6.6636148272,
        6.7524963702,
        7.0337211452
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 5.010376951,
      "stddev": 0.06915550022398136,
      "median": 5.0251916477,
      "user": 2.7965893399999997,
      "system": 3.3530165600000004,
      "min": 4.904893143200001,
      "max": 5.089696890200001,
      "times": [
        4.904893143200001,
        5.0468924432,
        5.008999466200001,
        5.0175419502,
        4.9353910662,
        5.0803703532,
        5.0730880502,
        5.0328413452000005,
        4.914054802200001,
        5.089696890200001
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 5.013902862,
      "stddev": 0.07002552117240265,
      "median": 5.0064791157,
      "user": 2.82069834,
      "system": 3.30266066,
      "min": 4.871748351200001,
      "max": 5.099011664200001,
      "times": [
        5.0045279032000005,
        4.983768861200001,
        5.092465109200001,
        5.0084303282,
        5.0921760842,
        5.031775249200001,
        5.099011664200001,
        4.871748351200001,
        4.9916243252,
        4.9635007442
      ]
    }
  ]
}

omril1 and others added 6 commits July 13, 2026 12:59
…r history

Per review: the module comment should explain why the file exists (avoiding a
runtime import cycle) rather than narrate that it was extracted from
resolvePeers.ts, which belongs in git history.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…Deps fixtures

main made hoistedPeerProviderNodeIds a required field on the resolvedImporters
entry type; the hand-built test fixtures need it to type-check.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Mirror the TypeScript getDedupeMap fix in pacquet's build_dedupe_map so the
two stacks stay behaviorally identical. An injected workspace dependency's
child edge is now considered satisfied by the target project's own direct dep
when the two depPaths are the same package identity (pkgIdWithPatchHash) and
the target's copy isCompatibleAndHasMoreDeps than the injected occurrence
needed, not only when the depPath strings are byte-identical. This lets an
injected dep dedupe back to link: when an unrelated shared dependency (e.g.
debug's optional supports-color peer) resolves peer-free on the injected side
but peer-suffixed for the target project after reconciling against an existing
lockfile. The pkgIdWithPatchHash guard keeps two genuinely different versions
of a shared leaf dep -- whose empty dependency/peer sets would otherwise look
compatible -- from being wrongly treated as interchangeable.

Extract node_deps_count and is_compatible_and_has_more_deps from
dedupe_peer_dependents into a shared dep_path_compatibility module so both
dedupe passes use one implementation. Add a Rust regression test matching the
TypeScript one (peer-suffix tolerated) alongside the existing version-mismatch
test that now also guards the identity check. See pnpm#10433.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Per review, the header comment described the pre-fix strict string-equality
check as if it were still current ("today's ... check strands the entry").
Reword it as a counterfactual ("Without the compatibility tolerance ... a
strict string-equality check would strand ...") so the comment states current
behavior, and drop the "previously-locked" framing in favor of naming the
existing lockfile as the thing that pinned the peer.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The injected-dep dedupe fix re-derived the same peer-suffix rationale in five
places (the getDedupeMap call site, both depPathCompatibility helpers, and the
TS and Rust tests). Per the repo comment convention -- state a shared why once,
in its natural home, and don't restate what the code says -- collapse them:

- The peer-suffix scenario now lives in a short note at the getDedupeMap /
  build_dedupe_map call site (both stacks).
- The "compares sets, not identity; callers must guard pkgIdWithPatchHash"
  precondition lives once on isCompatibleAndHasMoreDeps.
- Test comments drop the paragraph-length preambles and fixture narration the
  test names and literals already convey.

No behavior change.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Since pnpm#12949 unified the Rust release flow under changesets, a parity
change that lands in both stacks names the Rust wrapper alongside the
TypeScript packages. This fix ships in pacquet too, so add "pacquet": patch.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@zkochan
zkochan force-pushed the fix/dedupe-injected-deps-unrelated-peer-suffix branch from 28c8b23 to e38bdcc Compare July 13, 2026 11:12
@qodo-code-review

Copy link
Copy Markdown

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

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

Auto-approved notes - no code suggestions found
- 'approve_pr_on_self_review' flag enabled

@zkochan
zkochan merged commit 6986a42 into pnpm:main Jul 13, 2026
35 of 36 checks passed
@welcome

welcome Bot commented Jul 13, 2026

Copy link
Copy Markdown

Congrats on merging your first pull request! 🎉🎉🎉

@omril1
omril1 deleted the fix/dedupe-injected-deps-unrelated-peer-suffix branch July 13, 2026 12:41
omril1 added a commit to omril1/pnpm that referenced this pull request Jul 17, 2026
A workspace dependency that deduped to `link:` on install could be rewritten to
a peer-suffixed `file:` by a partial update (e.g. `pnpm update <other-pkg>
--recursive`) that re-resolves it without going through dedupeInjectedDeps.
When finalizing importer refs, keep the previous `link:` for a workspace
dependency the run doesn't target (no spec change, not matched by
`pnpm update <name>`). Follow-up to pnpm#12800 for the update path of
pnpm#10433.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
omril1 added a commit to omril1/pnpm that referenced this pull request Jul 18, 2026
A workspace dependency that deduped to `link:` on install could be rewritten to
a peer-suffixed `file:` by a partial update (e.g. `pnpm update <other-pkg>
--recursive`) that re-resolves it without going through dedupeInjectedDeps.
When finalizing importer refs, keep the previous `link:` for a workspace
dependency the run doesn't target (no spec change, not matched by
`pnpm update <name>`). Follow-up to pnpm#12800 for the update path of
pnpm#10433.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
omril1 added a commit to omril1/pnpm that referenced this pull request Jul 20, 2026
A workspace dependency that deduped to `link:` on install could be rewritten to
a peer-suffixed `file:` by a partial update (e.g. `pnpm update <other-pkg>
--recursive`) that re-resolves it without going through dedupeInjectedDeps.
When finalizing importer refs, keep the previous `link:` for a workspace
dependency the run doesn't target (no spec change, not matched by
`pnpm update <name>`). Follow-up to pnpm#12800 for the update path of
pnpm#10433.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
omril1 added a commit to omril1/pnpm that referenced this pull request Jul 21, 2026
A workspace dependency that deduped to `link:` on install could be rewritten to
a peer-suffixed `file:` by a partial update (e.g. `pnpm update <other-pkg>
--recursive`) that re-resolves it without going through dedupeInjectedDeps.
When finalizing importer refs, keep the previous `link:` for a workspace
dependency the run doesn't target (no spec change, not matched by
`pnpm update <name>`). Follow-up to pnpm#12800 for the update path of
pnpm#10433.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
omril1 added a commit to omril1/pnpm that referenced this pull request Jul 22, 2026
A workspace dependency that deduped to `link:` on install could be rewritten to
a peer-suffixed `file:` by a partial update (e.g. `pnpm update <other-pkg>
--recursive`) that re-resolves it without going through dedupeInjectedDeps.
When finalizing importer refs, keep the previous `link:` for a workspace
dependency the run doesn't target (no spec change, not matched by
`pnpm update <name>`). Follow-up to pnpm#12800 for the update path of
pnpm#10433.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
omril1 added a commit to omril1/pnpm that referenced this pull request Jul 23, 2026
A workspace dependency that deduped to `link:` on install could be rewritten to
a peer-suffixed `file:` by a partial update (e.g. `pnpm update <other-pkg>
--recursive`) that re-resolves it without going through dedupeInjectedDeps.
When finalizing importer refs, keep the previous `link:` for a workspace
dependency the run doesn't target (no spec change, not matched by
`pnpm update <name>`). Follow-up to pnpm#12800 for the update path of
pnpm#10433.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
omril1 added a commit to omril1/pnpm that referenced this pull request Jul 24, 2026
A workspace dependency that deduped to `link:` on install could be rewritten to
a peer-suffixed `file:` by a partial update (e.g. `pnpm update <other-pkg>
--recursive`) that re-resolves it without going through dedupeInjectedDeps.
When finalizing importer refs, keep the previous `link:` for a workspace
dependency the run doesn't target (no spec change, not matched by
`pnpm update <name>`). Follow-up to pnpm#12800 for the update path of
pnpm#10433.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
zkochan pushed a commit to omril1/pnpm that referenced this pull request Jul 30, 2026
A workspace dependency that deduped to `link:` on install could be rewritten to
a peer-suffixed `file:` by a partial update (e.g. `pnpm update <other-pkg>
--recursive`) that re-resolves it without going through dedupeInjectedDeps.
When finalizing importer refs, keep the previous `link:` for a workspace
dependency the run doesn't target (no spec change, not matched by
`pnpm update <name>`). Follow-up to pnpm#12800 for the update path of
pnpm#10433.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
zkochan added a commit that referenced this pull request Jul 30, 2026
…10433) (#13112)

A workspace dependency that deduped to `link:` on install could be rewritten to
a peer-suffixed `file:` by any run that re-resolves it without deduping back to
`link:` — e.g. `pnpm update <other-pkg>` (with or without --recursive), a
root/catalog bump, or a plain install that hits a genuine peer-context
divergence.

When finalizing importer refs, keep the previous `link:` for a workspace
dependency the run doesn't target: not new, specifier unchanged, and not matched
by `pnpm update <name>`. `updateSpec` is intentionally excluded from the
criterion because a plain install marks every manifest dependency with it. A
workspace `link:` dependency has no version to update, so a run that doesn't
target it must not flip it to `file:`; targeted dependencies still resolve
freely.

Adds regression tests for the update-recursive and plain-install paths (both
fail without the fix) and ports the guard to the Rust package-manager crate.

Completes the fix for #10433 — the first mechanism was fixed in #12800.

---------

Co-authored-by: Zoltan Kochan <[email protected]>
zkochan added a commit that referenced this pull request Oct 17, 2026
…olves

A plain install kept a workspace dependency's previously recorded
`link:` whenever the run did not target it, even when the injected copy
now binds a peer the linked project does not provide. The guard was
added for #10433, whose flips came from two spurious
mismatches: a same-version peer-suffix decoration, which the dedupe
pass now absorbs (#12800), and re-resolution paths the dedupe
pass did not reach. With the guard off, the update scenario from
#10433 keeps its `link:` in both stacks, so dedupe alone now
covers it. The guard's only remaining effect was that an incremental
install recorded a stale `link:` that a fresh install does not, which
left the injected package unable to find the peer its consumer provides.

The guard and the inputs only it consumed are removed in both stacks:
v12's `preserved_link_version`, `LockfileImporterReuse` and the
install path's `guard_*` fields, and v11's preserve-prior-link branch
with its previous-ref and targeted-alias bookkeeping. The importer entry
now follows the dedupe pass, which the workspaces docs already describe.

The v11 ancestor-divergence test now expects the injected copy, a new
v12 CLI test checks that an incremental install records the copy a
fresh one does, and the peer convergence harness drops this divergence.
The two rows still differing there come from #17058's moved
auto-installed peer, whose divergence now owns the injected entries
that follow from it.

Closes #17057

Co-Authored-By: Claude Opus 5.5 <[email protected]>
zkochan added a commit that referenced this pull request Oct 18, 2026
…olves (#17075)

A plain install kept a workspace dependency's previously recorded
`link:` whenever the run did not target it, even when the injected copy
now binds a peer the linked project does not provide. The guard was
added for #10433, whose flips came from two spurious
mismatches: a same-version peer-suffix decoration, which the dedupe
pass now absorbs (#12800), and re-resolution paths the dedupe
pass did not reach. With the guard off, the update scenario from
#10433 keeps its `link:` in both stacks, so dedupe alone now
covers it. The guard's only remaining effect was that an incremental
install recorded a stale `link:` that a fresh install does not, which
left the injected package unable to find the peer its consumer provides.

The guard and the inputs only it consumed are removed in both stacks:
v12's `preserved_link_version`, `LockfileImporterReuse` and the
install path's `guard_*` fields, and v11's preserve-prior-link branch
with its previous-ref and targeted-alias bookkeeping. The importer entry
now follows the dedupe pass, which the workspaces docs already describe.

The v11 ancestor-divergence test now expects the injected copy, a new
v12 CLI test checks that an incremental install records the copy a
fresh one does, and the peer convergence harness drops this divergence.
The two rows still differing there come from #17058's moved
auto-installed peer, whose divergence now owns the injected entries
that follow from it.

Closes #17057

Co-authored-by: Claude Opus 5.5 <[email protected]>
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 state: automerge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants