Skip to content

fix(peers): reuse cached owner during finalization - #14451

Merged
zkochan merged 2 commits into
pnpm:mainfrom
zhsama:fix/pnpm-cyclic-alias-peer-cache-owner
Sep 2, 2026
Merged

zkochan merged 2 commits into
pnpm:mainfrom
zhsama:fix/pnpm-cyclic-alias-peer-cache-owner

Conversation

@zhsama

@zhsama zhsama commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Fixes a pnpm 12 lockfile corruption where a cached occurrence in a cyclic aliased peer graph was finalized to a snapshot key that the graph never emitted.
  • Records the fully walked owner of each peer-cache entry and canonicalizes cached occurrences through that owner during final depPath and SCC lookup.
  • Keeps dependency aliases as edge labels and leaves cache matching, cache short-circuiting, and lockfile serializer fallbacks unchanged.
  • Adds resolver-level graph-closure coverage and an end-to-end lockfile-only to frozen-install regression test.
  • Rust-only because the TypeScript resolver already behaves this way: resolvePeers.ts records peersCacheOwnerByNodeId and a cache hit awaits the owner's depPath promise, so the hit inherits the owner's final depPath. pacquet's post-walk finalizer lacked that step.
  • Builds the peer-graph SCC table over cache owners as well, so a cycle that runs through a cache-hit occurrence still collapses whichever occurrence the walk visited first.

Fixes #14449.

Reproduction: zhsama/pnpm12-hoisted-cyclic-alias-peer-repro

Design

A peer-cache hit is a claim that the reused occurrence has the same peer-resolution semantics as the occurrence that produced the cache entry. The finalizer must therefore use the same semantic node identity. If an occurrence requires a distinct long-form peer key, the cache match is invalid and it must be fully walked instead.

PeersCacheItem now carries its producer NodeId. A cache hit records occurrence -> owner, and final depPath construction, graph edge rendering, and SCC comparisons resolve through that owner. The occurrence remains distinct in the dependency tree, and aliases remain on dependency edges; only final peer-graph identity is shared.

This fixes the producer/consumer mismatch directly rather than removing the existing lockfile fallback or adding another production validation pass. The end-to-end frozen replay test guards the observable closure invariant.

Validation

  • node pnpm/scripts/run-rust-tests.mjs --no-fail-fast -j 8: 9793 passed, 5 skipped, 0 failed.
  • Official pre-push hook: TypeScript compile/lint/spellcheck/meta checks, Rust fmt, Clippy with warnings denied, and private-item rustdoc all passed.
  • The public reproduction passes both lockfile-only generation and frozen installation with the patched binary.
  • Ablation: recording the owner without consuming it in the finalizer still fails; bypassing owner canonicalization reproduces the missing-snapshot CLI error; the complete producer and consumer change passes.
  • Twelve interleaved release benchmark runs showed no peerless regression (+0.11%), while peer-heavy and hoist-heavy workspace resolution improved by 13.93% and 8.18%. Peak RSS showed no regression.

Squash Commit Body

The peer walker can reuse one occurrence from another compatible occurrence and return before creating a second node record. The post-walk finalizer previously discarded that equivalence and recomputed the cached occurrence by its own NodeId, which could produce a longer peer-qualified key with no corresponding graph entry.

Track the fully walked occurrence that produces each peer-cache entry. Canonicalize cache hits through that owner while finalizing depPaths, rendering graph edges, and building and comparing peer SCCs. Keep aliases on dependency edges and preserve the existing cache fast path.

Fixes pnpm/pnpm#14449.

Checklist

  • I checked the referenced issue and verified that none of the PRs already linked to it solves it.
  • The description explains why this pacquet-only fix requires no TypeScript CLI port.
  • Added a pacquet patch changeset.
  • Added resolver and CLI regression tests.

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

Summary by CodeRabbit

  • Bug Fixes

    • Fixed lockfile generation for npm-aliased dependencies involved in cyclic peer-dependency graphs.
    • Frozen installs now correctly reuse cached dependency resolutions and reference valid snapshots.
    • Prevented broken lockfiles caused by unresolved peer-suffixed snapshots in these scenarios.
  • Tests

    • Added coverage for lockfile-only and frozen installations involving cyclic aliased peer dependencies.

@zhsama
zhsama requested a review from zkochan as a code owner September 2, 2026 10:07
@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Reuse cached peer owners when finalizing cyclic alias graphs

🐞 Bug fix 🧪 Tests 📝 Documentation 🕐 40+ Minutes

Grey Divider

AI Description

• Canonicalizes cached peer occurrences to their fully walked owner during finalization.
• Prevents cyclic npm aliases from referencing snapshots absent from generated lockfiles.
• Adds resolver closure and frozen-install regression coverage.
Diagram

graph TD
  A["Peer Walker"] --> B["Peer Cache"] --> C["Cached Occurrence"] --> D["Owner Mapping"] --> E["Peer Finalizer"] --> F["Closed Dependency Graph"] --> G["Frozen Install"]
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Disable cache reuse for cyclic aliases
  • ➕ Simplifies correctness by forcing each occurrence through a complete peer walk.
  • ➕ Avoids maintaining a separate semantic-owner mapping.
  • ➖ Sacrifices existing peer-resolution caching performance.
  • ➖ Repeats equivalent work for compatible occurrences.
  • ➖ Treats the symptom more broadly than necessary.
2. Validate graph closure after finalization
  • ➕ Provides a general safeguard against dangling snapshot references.
  • ➕ Could detect unrelated graph-construction defects.
  • ➖ Adds another production graph traversal.
  • ➖ Requires fallback or repair semantics after incorrect identities are already produced.
  • ➖ Masks the producer-consumer identity mismatch instead of correcting it.

Recommendation: Keep the PR’s owner-canonicalization approach. It directly preserves the semantic guarantee implied by a cache hit, retains aliases and distinct tree occurrences, avoids a new validation pass, and preserves cache performance; the alternatives are useful safeguards but are either broader or more expensive.

Files changed (6) +158 / -3

Bug fix (3) +28 / -3
cache.rsPropagate peer-cache producer ownership on cache hits +11/-3

Propagate peer-cache producer ownership on cache hits

• Extends peer-cache entries and cached outputs with the fully walked producer NodeId. Cache hits record non-self owner mappings while preserving existing peer and missing-peer output handling.

pnpm/crates/resolving-deps-resolver/src/resolve_peers/cache.rs

finalize.rsCanonicalize cached occurrences during peer finalization +12/-0

Canonicalize cached occurrences during peer finalization

• Resolves cache-hit occurrences through their owner before final depPath lookup, graph edge rendering, peer identity construction, and SCC comparisons. Tree occurrences and dependency aliases remain distinct.

pnpm/crates/resolving-deps-resolver/src/resolve_peers/finalize.rs

walker.rsTrack cache-hit occurrences by their producer NodeId +5/-0

Track cache-hit occurrences by their producer NodeId

• Adds owner mapping state to the peer walker and records each fully walked node as the owner of its cache entry. This gives finalization the semantic identity associated with reused cache verdicts.

pnpm/crates/resolving-deps-resolver/src/resolve_peers/walker.rs

Tests (2) +125 / -0
hoisted_node_linker.rsCover frozen replay of cyclic aliased peer snapshots +53/-0

Cover frozen replay of cyclic aliased peer snapshots

• Adds an end-to-end hoisted-linker regression test that generates a lockfile-only install for a cyclic aliased peer graph, then verifies a frozen install can replay it successfully.

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

tests.rsVerify cached cyclic aliases produce a closed graph +72/-0

Verify cached cyclic aliases produce a closed graph

• Adds resolver-level coverage asserting that direct and nested cached occurrences share the same final depPath and that every resulting dependency edge targets an existing graph node.

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

Documentation (1) +5 / -0
closed-cyclic-peer-cache.mdDocument the cyclic aliased peer lockfile fix +5/-0

Document the cyclic aliased peer lockfile fix

• Adds a patch changeset for pacquet explaining that frozen installs now reference the cached occurrence’s emitted snapshot.

.changeset/closed-cyclic-peer-cache.md

@coderabbitai

coderabbitai Bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Team

Run ID: 6384ff10-61c6-425c-9f4b-fa65fb4da0e1

📥 Commits

Reviewing files that changed from the base of the PR and between 256bc20 and 48d92a3.

📒 Files selected for processing (4)
  • .changeset/closed-cyclic-peer-cache.md
  • pnpm/crates/resolving-deps-resolver/src/resolve_peers/cache.rs
  • pnpm/crates/resolving-deps-resolver/src/resolve_peers/finalize.rs
  • pnpm/crates/resolving-deps-resolver/src/resolve_peers/tests.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • .changeset/closed-cyclic-peer-cache.md

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


📝 Walkthrough

Walkthrough

The resolver now tracks the fully walked owner of cached peer resolutions and canonicalizes reused node IDs during final dependency-path generation. Unit and hoisted-linker tests cover cyclic npm aliases and frozen lockfile replay. A patch changeset documents the fix.

Changes

Cyclic peer cache resolution

Layer / File(s) Summary
Cache-owner tracking
pnpm/crates/resolving-deps-resolver/src/resolve_peers/cache.rs, pnpm/crates/resolving-deps-resolver/src/resolve_peers/walker.rs
Cached peer results retain their producing node ID. Cache hits record mappings for reused nodes.
Canonical final paths
pnpm/crates/resolving-deps-resolver/src/resolve_peers/finalize.rs
Final dependency paths, peer IDs, and strongly connected components use the cached owner for canonical resolution.
Cyclic alias validation and release metadata
pnpm/crates/resolving-deps-resolver/src/resolve_peers/tests.rs, pnpm/crates/cli/tests/suite/hoisted_node_linker.rs, .changeset/closed-cyclic-peer-cache.md
Tests verify closed cyclic peer graphs and successful frozen installation. The changeset records a patch release.

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

Merge Risk: ⚪ Minimal · up to 48d92

The PR corrects cached peer-owner canonicalization for cyclic aliased dependency graphs and adds regression coverage; no actionable merge-blocking risk remains after normal checks and review.

Sequence Diagram(s)

sequenceDiagram
  participant Walker
  participant PeerCache
  participant Finalizer
  participant FrozenInstall
  Walker->>PeerCache: cache peer verdict with owner node
  PeerCache-->>Walker: reuse verdict and owner node
  Walker->>Finalizer: finalize reused occurrence
  Finalizer->>Finalizer: resolve through cache owner
  Finalizer-->>FrozenInstall: emit canonical depPath
  FrozenInstall->>FrozenInstall: replay lockfile
Loading

Assessment against linked issues

Objective Addressed Explanation
Ensure cyclic aliased peer graphs produce closed lockfiles whose dependency references resolve to emitted snapshots [#14449] ✅
Ensure a frozen install replays the generated lockfile successfully [#14449] ✅

Possibly related PRs

  • pnpm/pnpm#13866: Both changes modify peer-resolution caching and cyclic peer handling.

Suggested labels: product: pacquet

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

@qodo-code-review

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

Copy link
Copy Markdown

Code Review by Qodo

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

Grey Divider


Action required

1. Raw SCC graph breaks canonicalization ✓ Resolved 🐞 Bug ≡ Correctness
Description
final_peer_id looks up canonical owner IDs in an SCC table built from raw occurrence IDs, so a
cycle through a cached occurrence can be misclassified when the hit and owner belong to different
raw SCCs. With aliased peer names, the name-based fallback does not recover the cycle, producing
incorrect nested peer-suffixed depPaths instead of cycle-collapsed identities.
Code

pnpm/crates/resolving-deps-resolver/src/resolve_peers/finalize.rs[R370-371]

+        let node_id = self.cache_owner_node_id(node_id);
+        let peer_node_id = self.cache_owner_node_id(peer_node_id);
Relevance

●●● Strong

Recent resolver precedents accept concrete peer-identity and lockfile correctness fixes, especially
alias and cycle-related cases.

PR-#14314
PR-#14277
PR-#13545

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
Cache hits store the owner mapping while copying the owner's raw peer map under the hit occurrence.
Cache entries can themselves retain occurrence IDs as resolved peers, but peer_sccs constructs
vertices and edges directly from those raw keys and values; final_peer_id then canonicalizes both
IDs before querying that incompatible SCC map. For example, raw edges A → B_hit, B_hit → A, and
B_owner → A place A with B_hit, while the changed lookup compares A with B_owner and
misses the cycle; aliases can also keep the package-name cycle fallback from applying.

pnpm/crates/resolving-deps-resolver/src/resolve_peers/cache.rs[378-410]
pnpm/crates/resolving-deps-resolver/src/resolve_peers/walker.rs[963-985]
pnpm/crates/resolving-deps-resolver/src/resolve_peers/finalize.rs[526-551]
pnpm/crates/resolving-deps-resolver/src/resolve_peers/finalize.rs[367-404]

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 finalizer canonicalizes peer IDs before SCC comparison, but `peer_sccs` computes components from raw cache-hit occurrence IDs. Build the SCC graph using the same cache-owner identity so cycles through cached occurrences are classified correctly.

## Issue Context
A walked node may resolve a peer to a cache-hit occurrence while that occurrence maps to another owner. The raw graph can contain `A → B_hit → A`, but finalization compares `A` with `B_owner`; aliased peer labels may prevent `cyclic_peer_names` from masking this mismatch.

## Fix Focus Areas
- pnpm/crates/resolving-deps-resolver/src/resolve_peers/finalize.rs[526-551]
- pnpm/crates/resolving-deps-resolver/src/resolve_peers/finalize.rs[367-404]
- pnpm/crates/resolving-deps-resolver/src/resolve_peers/tests.rs[442-512]

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



Remediation recommended

2. pnpm missing from changeset 📘 Rule violation § Compliance
Description
The new changeset declares only pacquet, although the checklist requires every changed changeset
to include an explicit pnpm bump. This can prevent the pnpm package from receiving the required
patch release entry.
Code

.changeset/closed-cyclic-peer-cache.md[2]

+"pacquet": patch
Relevance

●●● Strong

Recent precedents consistently accept adding pnpm bumps to pacquet-only changesets under this
compliance rule.

PR-#13748
PR-#13885
PR-#14178

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
PR Compliance ID 713436 requires each new or modified changeset to contain a pnpm package entry
with a valid bump type. The new changeset front matter contains only "pacquet": patch, so pnpm
is absent.

Rule 713436: Explicitly declare pnpm package and correct bump type in changesets
.changeset/closed-cyclic-peer-cache.md[1-3]

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 changeset lists only `pacquet`, but PR Compliance ID 713436 requires an explicit valid bump entry for `pnpm`.

## Issue Context
This PR is a bug fix, so the appropriate `pnpm` bump type is `patch`. Keep the existing `pacquet` entry if that package must also be released.

## Fix Focus Areas
- .changeset/closed-cyclic-peer-cache.md[1-3]

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


Grey Divider

Context sources
✅ Compliance rules (platform): 27 rules
Review mode: ⚖️ Balanced

Grey Divider

Tip of the day
💡 Did you know, you can turn on the rule miner and Qodo learns your standards from review history

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@greptile-apps

greptile-apps Bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Reviews (2): Last reviewed commit: "fix(peers): detect peer cycles through c..." | Re-trigger Greptile

@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 256bc20

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

codecov-commenter commented Sep 2, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.23810% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 88.86%. Comparing base (1d00e70) to head (48d92a3).

Files with missing lines Patch % Lines
...resolving-deps-resolver/src/resolve_peers/cache.rs 90.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #14451   +/-   ##
=======================================
  Coverage   88.85%   88.86%           
=======================================
  Files         703      703           
  Lines      125944   125961   +17     
=======================================
+ Hits       111912   111930   +18     
+ Misses      14032    14031    -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

github-actions Bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Integrated-Benchmark Report (Linux)

Commit: 48d92a39027b

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

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

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 2.506 ± 0.070 2.410 2.644 1.84 ± 0.14
pacquet@main 2.416 ± 0.095 2.337 2.577 1.78 ± 0.14
pnpr@HEAD 1.397 ± 0.124 1.281 1.598 1.03 ± 0.11
pnpr@main 1.361 ± 0.093 1.285 1.529 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 2.50629971546,
      "stddev": 0.07025781956413735,
      "median": 2.50609283436,
      "user": 1.64276266,
      "system": 1.46583856,
      "min": 2.41011848836,
      "max": 2.64374059036
    },
    {
      "command": "pacquet@main",
      "mean": 2.41633426246,
      "stddev": 0.09543833663945228,
      "median": 2.38142806136,
      "user": 1.51638546,
      "system": 1.3553886599999996,
      "min": 2.33676443636,
      "max": 2.57674597636
    },
    {
      "command": "pnpr@HEAD",
      "mean": 1.39718851616,
      "stddev": 0.12362489166177061,
      "median": 1.34568249786,
      "user": 1.07492776,
      "system": 1.2210029599999999,
      "min": 1.28097889336,
      "max": 1.59821113936
    },
    {
      "command": "pnpr@main",
      "mean": 1.36079976146,
      "stddev": 0.09324873129475636,
      "median": 1.31079875836,
      "user": 1.09557016,
      "system": 1.2299318600000002,
      "min": 1.28468933836,
      "max": 1.52946948136
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 206.3 ± 5.3 200.3 215.7 1.00
pacquet@main 211.4 ± 11.2 188.9 230.4 1.02 ± 0.06
pnpr@HEAD 230.6 ± 5.6 222.4 242.0 1.12 ± 0.04
pnpr@main 229.0 ± 8.1 221.1 248.7 1.11 ± 0.05
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.20634661436000004,
      "stddev": 0.0053104402266169,
      "median": 0.20518953176000002,
      "user": 0.20798634,
      "system": 0.5021170999999999,
      "min": 0.20033308426000002,
      "max": 0.21567170226000001
    },
    {
      "command": "pacquet@main",
      "mean": 0.21140679986000005,
      "stddev": 0.011220234149849705,
      "median": 0.21138861576,
      "user": 0.22074633999999996,
      "system": 0.49950610000000006,
      "min": 0.18893174626000003,
      "max": 0.23044777626000001
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.23060278006000004,
      "stddev": 0.00561561584392017,
      "median": 0.23084098326000002,
      "user": 0.20656864000000003,
      "system": 0.5257783999999999,
      "min": 0.22235802526000004,
      "max": 0.24201559726000002
    },
    {
      "command": "pnpr@main",
      "mean": 0.22899358606000003,
      "stddev": 0.00809483558782477,
      "median": 0.22677006426000001,
      "user": 0.22598264,
      "system": 0.5117603,
      "min": 0.22110933426,
      "max": 0.24866811526000002
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 6.2 ± 0.4 5.4 8.3 1.03 ± 0.12
pacquet@main 6.0 ± 0.6 5.3 9.7 1.00
pnpr@HEAD 6.7 ± 0.4 5.7 8.6 1.11 ± 0.12
pnpr@main 6.8 ± 0.5 5.7 8.6 1.12 ± 0.13
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.0062225705594936625,
      "stddev": 0.00039816496530175097,
      "median": 0.0062068936,
      "user": 0.0038476194936708846,
      "system": 0.0027906058227848106,
      "min": 0.0053672006,
      "max": 0.0082701926
    },
    {
      "command": "pacquet@main",
      "mean": 0.006044007533842237,
      "stddev": 0.0005709415817077386,
      "median": 0.0059427196,
      "user": 0.0036769968956742965,
      "system": 0.0027259765903307875,
      "min": 0.0053211656,
      "max": 0.0097065636
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.006720908298005699,
      "stddev": 0.00040121645645441813,
      "median": 0.0067025636,
      "user": 0.004111098176638174,
      "system": 0.0030686162393162397,
      "min": 0.0056937936,
      "max": 0.0086355066
    },
    {
      "command": "pnpr@main",
      "mean": 0.006766900853846149,
      "stddev": 0.00046276992273528453,
      "median": 0.0067010201,
      "user": 0.0040369215384615355,
      "system": 0.003179250769230769,
      "min": 0.0056724626,
      "max": 0.0086424096
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 6.5 ± 0.4 5.8 8.8 1.00
pacquet@main 6.6 ± 0.5 5.8 8.9 1.02 ± 0.09
pnpr@HEAD 7.1 ± 0.5 5.6 9.3 1.09 ± 0.10
pnpr@main 7.2 ± 0.4 6.2 9.2 1.10 ± 0.09
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.006509937644561401,
      "stddev": 0.0003579333392562921,
      "median": 0.00648917532,
      "user": 0.0038976540350877187,
      "system": 0.0029655527485380104,
      "min": 0.00583784882,
      "max": 0.008751700820000001
    },
    {
      "command": "pacquet@main",
      "mean": 0.006623379090270268,
      "stddev": 0.00047865948718181224,
      "median": 0.00653351382,
      "user": 0.0040457216816816854,
      "system": 0.0029624066066066047,
      "min": 0.00581584782,
      "max": 0.00889843482
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.007082899905808583,
      "stddev": 0.0005147715307971659,
      "median": 0.0070253348200000005,
      "user": 0.00412775287128713,
      "system": 0.0034090195379537975,
      "min": 0.00560913082,
      "max": 0.009290660820000001
    },
    {
      "command": "pnpr@main",
      "mean": 0.00716835213730769,
      "stddev": 0.00040984829101321774,
      "median": 0.00715053982,
      "user": 0.004191716282051283,
      "system": 0.0034240334615384615,
      "min": 0.0061988958200000005,
      "max": 0.009218494820000001
    }
  ]
}

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 2.679 ± 0.014 2.655 2.695 1.78 ± 0.17
pacquet@main 2.673 ± 0.014 2.645 2.694 1.78 ± 0.17
pnpr@HEAD 1.506 ± 0.145 1.371 1.727 1.00
pnpr@main 1.512 ± 0.103 1.386 1.742 1.00 ± 0.12
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 2.67861695824,
      "stddev": 0.013724443495553598,
      "median": 2.6839212254400002,
      "user": 1.54311462,
      "system": 1.2864601599999999,
      "min": 2.65459665844,
      "max": 2.69491880144
    },
    {
      "command": "pacquet@main",
      "mean": 2.6729818939400003,
      "stddev": 0.014380505329682275,
      "median": 2.67286323794,
      "user": 1.56280472,
      "system": 1.2550714599999995,
      "min": 2.64478941244,
      "max": 2.69373895944
    },
    {
      "command": "pnpr@HEAD",
      "mean": 1.5057276700400002,
      "stddev": 0.14545268918965706,
      "median": 1.4523939934399999,
      "user": 1.07196312,
      "system": 1.20835786,
      "min": 1.37102916244,
      "max": 1.72715436644
    },
    {
      "command": "pnpr@main",
      "mean": 1.5116951443399997,
      "stddev": 0.10277304644539963,
      "median": 1.49810551844,
      "user": 1.0040600200000003,
      "system": 1.23418466,
      "min": 1.38555662744,
      "max": 1.74227749844
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 350.7 ± 17.7 330.6 373.5 1.40 ± 0.08
pacquet@main 366.5 ± 12.3 345.2 387.6 1.46 ± 0.06
pnpr@HEAD 251.2 ± 7.0 242.4 260.0 1.00
pnpr@main 253.3 ± 8.7 242.2 270.9 1.01 ± 0.04
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.35071265536000007,
      "stddev": 0.017668343164440166,
      "median": 0.34261798686,
      "user": 0.39792204,
      "system": 0.5775071599999999,
      "min": 0.33062287336000007,
      "max": 0.37348483936000004
    },
    {
      "command": "pacquet@main",
      "mean": 0.36646245006000006,
      "stddev": 0.012268861331738053,
      "median": 0.3668862163600001,
      "user": 0.40858064,
      "system": 0.59826856,
      "min": 0.34524328336000004,
      "max": 0.38756035736000005
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.25122054556000006,
      "stddev": 0.0070038556056158385,
      "median": 0.25330519636000004,
      "user": 0.16926734,
      "system": 0.4422680600000001,
      "min": 0.24236703736,
      "max": 0.26001735536000004
    },
    {
      "command": "pnpr@main",
      "mean": 0.25330995466000006,
      "stddev": 0.008687529836617813,
      "median": 0.25198714136000006,
      "user": 0.16133544,
      "system": 0.46364365999999996,
      "min": 0.24217006936000002,
      "max": 0.27091642036
    }
  ]
}

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 1.805 ± 0.018 1.783 1.832 6.43 ± 0.43
pacquet@main 1.818 ± 0.012 1.799 1.843 6.48 ± 0.43
pnpr@HEAD 0.281 ± 0.019 0.259 0.319 1.00 ± 0.09
pnpr@main 0.281 ± 0.019 0.260 0.314 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 1.80533407556,
      "stddev": 0.017838867399611887,
      "median": 1.80679854716,
      "user": 0.6350571599999999,
      "system": 0.6703059,
      "min": 1.7829485656600002,
      "max": 1.8324576086600002
    },
    {
      "command": "pacquet@main",
      "mean": 1.81806409786,
      "stddev": 0.011986703803389405,
      "median": 1.8178738116600002,
      "user": 0.6344464599999999,
      "system": 0.6797273,
      "min": 1.79945556066,
      "max": 1.8431705946599999
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.28103942216,
      "stddev": 0.01867375840021756,
      "median": 0.28003719566,
      "user": 0.20441476,
      "system": 0.4796055,
      "min": 0.25937706266,
      "max": 0.31887062766
    },
    {
      "command": "pnpr@main",
      "mean": 0.28071969576,
      "stddev": 0.018512204488740143,
      "median": 0.27642503166,
      "user": 0.19281726000000002,
      "system": 0.5157205,
      "min": 0.25958451066,
      "max": 0.31373788766
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 247.1 ± 16.0 223.9 276.9 2.54 ± 0.17
pacquet@main 243.1 ± 18.2 218.3 282.6 2.50 ± 0.19
pnpr@HEAD 98.4 ± 2.5 94.4 104.0 1.01 ± 0.03
pnpr@main 97.2 ± 1.9 92.4 101.7 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.24707546980545458,
      "stddev": 0.016038350505696054,
      "median": 0.24753328826,
      "user": 0.21066942545454548,
      "system": 0.057526374545454534,
      "min": 0.22393762826,
      "max": 0.27686793226000006
    },
    {
      "command": "pacquet@main",
      "mean": 0.24314840692666664,
      "stddev": 0.018167081704059652,
      "median": 0.24018318326,
      "user": 0.21263213,
      "system": 0.06687191999999999,
      "min": 0.21825269326000002,
      "max": 0.28262949026000006
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.09844689515285716,
      "stddev": 0.002510642800672492,
      "median": 0.09754811426000001,
      "user": 0.03589723714285714,
      "system": 0.013926705714285713,
      "min": 0.09437100526000002,
      "max": 0.10398308926000001
    },
    {
      "command": "pnpr@main",
      "mean": 0.09722905501862068,
      "stddev": 0.0018767698393916392,
      "median": 0.09730224826000002,
      "user": 0.033509638620689654,
      "system": 0.014978713103448275,
      "min": 0.09238060526000001,
      "max": 0.10167295926000001
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 586.9 ± 134.6 345.2 779.1 1.00
pacquet@main 688.9 ± 126.2 498.9 886.2 1.17 ± 0.34
pnpm@HEAD 2973.5 ± 127.7 2844.5 3162.0 5.07 ± 1.18
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.5868620322111112,
      "stddev": 0.13455796108366264,
      "median": 0.5873842661,
      "user": 0.5802898133333333,
      "system": 0.12439363777777775,
      "min": 0.3452437751,
      "max": 0.7790639021000001
    },
    {
      "command": "pacquet@main",
      "mean": 0.6889125655444445,
      "stddev": 0.12623394369740526,
      "median": 0.7271944471,
      "user": 0.6804747022222223,
      "system": 0.13646663777777776,
      "min": 0.4989314121,
      "max": 0.8861505081000001
    },
    {
      "command": "pnpm@HEAD",
      "mean": 2.9734550237666664,
      "stddev": 0.12774290037303918,
      "median": 2.8997235061,
      "user": 4.54586448,
      "system": 0.27217285999999996,
      "min": 2.8445186301,
      "max": 3.1619568231
    }
  ]
}

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 4.550 ± 0.175 4.391 4.888 1.32 ± 0.07
pacquet@main 4.553 ± 0.177 4.403 4.843 1.32 ± 0.07
pnpr@HEAD 3.480 ± 0.082 3.366 3.601 1.01 ± 0.04
pnpr@main 3.446 ± 0.126 3.354 3.744 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 4.54951115844,
      "stddev": 0.17477407778814344,
      "median": 4.47565874644,
      "user": 1.9044407799999998,
      "system": 1.6614404,
      "min": 4.3911579304399995,
      "max": 4.88778704644
    },
    {
      "command": "pacquet@main",
      "mean": 4.553210502640001,
      "stddev": 0.17683202320189784,
      "median": 4.46256355044,
      "user": 1.72388098,
      "system": 1.6046333000000002,
      "min": 4.40302687144,
      "max": 4.84267884644
    },
    {
      "command": "pnpr@HEAD",
      "mean": 3.4801185658400002,
      "stddev": 0.08199602232939032,
      "median": 3.4710149069400003,
      "user": 1.2529960800000002,
      "system": 1.3962157,
      "min": 3.36602015944,
      "max": 3.6006072804400002
    },
    {
      "command": "pnpr@main",
      "mean": 3.4460400685400012,
      "stddev": 0.126251444751017,
      "median": 3.38493084144,
      "user": 1.31191048,
      "system": 1.4196629,
      "min": 3.3537833754400004,
      "max": 3.7442150624400004
    }
  ]
}

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

Same install as the isolated fresh-restore hot/hot scenario, into the shared virtual store — the layout pnpm 12 installs into by default. Comparable to that scenario head-to-head.

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 167.7 ± 21.9 143.8 216.0 1.00
pacquet@main 176.3 ± 15.7 155.2 211.5 1.05 ± 0.17
pnpr@HEAD 178.6 ± 11.5 166.5 204.6 1.06 ± 0.16
pnpr@main 174.8 ± 7.3 162.7 183.7 1.04 ± 0.14
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.1677188168258823,
      "stddev": 0.021905752102728968,
      "median": 0.16210677712,
      "user": 0.22491334705882354,
      "system": 0.1939771764705882,
      "min": 0.14375212812,
      "max": 0.21599251312
    },
    {
      "command": "pacquet@main",
      "mean": 0.17633478905749997,
      "stddev": 0.015717320502457117,
      "median": 0.17055596711999998,
      "user": 0.22303751249999998,
      "system": 0.21158425000000003,
      "min": 0.15521357512,
      "max": 0.21151119112
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.17860143865333333,
      "stddev": 0.011517575718225264,
      "median": 0.17357857212,
      "user": 0.22087363333333332,
      "system": 0.19668726666666664,
      "min": 0.16652207412,
      "max": 0.20455142512
    },
    {
      "command": "pnpr@main",
      "mean": 0.17478437578666667,
      "stddev": 0.007296704039090895,
      "median": 0.17676516511999998,
      "user": 0.2162609666666667,
      "system": 0.1913983999999999,
      "min": 0.16267275812,
      "max": 0.18371462412
    }
  ]
}

@github-actions

github-actions Bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Projectpnpm's project
Branchpr/14451
Testbedpacquet
Click to view all benchmark results
BenchmarkLatencyBenchmark Result
milliseconds (ms)
(Result Δ%)
Upper Boundary
milliseconds (ms)
(Limit %)
gvs-linker.fresh-restore.hot-cache.hot-store📈 view plot
🚷 view threshold
143.75 ms
(-5.25%)Baseline: 151.72 ms
182.06 ms
(78.96%)
isolated-linker.fresh-install.cold-cache.cold-store📈 view plot
🚷 view threshold
2,654.60 ms
(-1.67%)Baseline: 2,699.72 ms
3,239.66 ms
(81.94%)
isolated-linker.fresh-install.cold-cache.hot-store📈 view plot
🚷 view threshold
1,782.95 ms
(-2.96%)Baseline: 1,837.32 ms
2,204.78 ms
(80.87%)
isolated-linker.fresh-install.hot-cache.hot-store📈 view plot
🚷 view threshold
330.62 ms
(-7.89%)Baseline: 358.96 ms
430.76 ms
(76.75%)
isolated-linker.fresh-resolve.hot-cache.offline📈 view plot
🚷 view threshold
223.94 ms
(+6.45%)Baseline: 210.38 ms
252.45 ms
(88.71%)
isolated-linker.fresh-restore.cold-cache.cold-store📈 view plot
🚷 view threshold
2,410.12 ms
(-0.08%)Baseline: 2,411.98 ms
2,894.38 ms
(83.27%)
isolated-linker.fresh-restore.cold-cache.cold-store.cold-pnpr📈 view plot
🚷 view threshold
4,391.16 ms
(-0.25%)Baseline: 4,402.18 ms
5,282.61 ms
(83.12%)
isolated-linker.fresh-restore.hot-cache.hot-store📈 view plot
🚷 view threshold
200.33 ms
(-6.42%)Baseline: 214.09 ms
256.90 ms
(77.98%)
isolated-linker.peer-heavy-resolve.hot-cache.offline📈 view plot
🚷 view threshold
345.24 ms
(-28.02%)Baseline: 479.64 ms
575.57 ms
(59.98%)
isolated-linker.repeat-install.cold-cache.hot-store📈 view plot
🚷 view threshold
5.84 ms
(-10.67%)Baseline: 6.53 ms
7.84 ms
(74.44%)
isolated-linker.repeat-install.hot-cache.hot-store📈 view plot
🚷 view threshold
5.37 ms
(-15.50%)Baseline: 6.35 ms
7.62 ms
(70.42%)
🐰 View full continuous benchmarking report in Bencher

@github-actions

github-actions Bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Projectpnpm's project
Branchpr/14451
Testbedpnpr

⚠️ WARNING: No Threshold found!

Without a Threshold, no Alerts will ever be generated.

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

Click to view all benchmark results
BenchmarkLatencymilliseconds (ms)
gvs-linker.fresh-restore.hot-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
166.52 ms
isolated-linker.fresh-install.cold-cache.cold-store📈 view plot
⚠️ NO THRESHOLD
1,371.03 ms
isolated-linker.fresh-install.cold-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
259.38 ms
isolated-linker.fresh-install.hot-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
242.37 ms
isolated-linker.fresh-resolve.hot-cache.offline📈 view plot
⚠️ NO THRESHOLD
94.37 ms
isolated-linker.fresh-restore.cold-cache.cold-store📈 view plot
⚠️ NO THRESHOLD
1,280.98 ms
isolated-linker.fresh-restore.cold-cache.cold-store.cold-pnpr📈 view plot
⚠️ NO THRESHOLD
3,366.02 ms
isolated-linker.fresh-restore.hot-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
222.36 ms
isolated-linker.repeat-install.cold-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
5.61 ms
isolated-linker.repeat-install.hot-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
5.69 ms
🐰 View full continuous benchmarking report in Bencher

zhsama and others added 2 commits September 2, 2026 14:13
Track the fully walked occurrence that produced each peer-cache entry.
Treat every cache hit as the same semantic node during final depPath and SCC lookup,
while preserving aliases on dependency edges. This prevents finalization from writing
references to peer-qualified snapshots that were never emitted.

Closes pnpm#14449.
The finalizer canonicalized a cache-hit occurrence to its owner when it
looked up peer-graph SCCs, but still built the SCC table from raw
occurrence ids. A peer edge that targets the hit occurrence therefore
landed in a different component than the owner, so the cycle was not
collapsed and the lockfile key depended on the order of the direct
dependencies.

Build the SCC table over cache owners, assert that an owner is never a
cache hit itself, and cover the walk order in which the hit occurrence
is the peer target.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01ALFhydtRaoShFmsRNUsFcQ
@zkochan
zkochan force-pushed the fix/pnpm-cyclic-alias-peer-cache-owner branch from 256bc20 to 48d92a3 Compare September 2, 2026 12:20
@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 48d92a3

@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 af838db into pnpm:main Sep 2, 2026
39 checks passed
@welcome

welcome Bot commented Sep 2, 2026

Copy link
Copy Markdown

Congrats on merging your first pull request! 🎉🎉🎉

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

Labels

product: pacquet reviewed: coderabbit CodeRabbit submitted an approving review state: automerge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pnpm 12 + hoisted writes a dangling snapshot reference for a cyclic aliased peer graph

3 participants