Repository navigation
fix(deps-resolver): rename peer dependents after collapsing a variant - #16359
Conversation
A lockfile key is the package id plus a peer suffix that spells out the keys of the peers it resolved. dedupe_peer_dependents runs after those keys are built. When it collapses a variant into a larger compatible one, it rewrites the edges that pointed at the collapsed variant but kept every other node's key. A node whose suffix named the collapsed variant stayed keyed after a variant that no longer exists. When the collapse left two variants with identical edges, the dep-path tie-break could also keep the one whose key spelled the collapsed peer. pnpm v12 reads locked peer versions back from those keys, so the next resolution started from the stale names and produced a different graph. `pnpm dedupe` therefore needed a second run to settle, and `pnpm dedupe --check` failed right after `pnpm dedupe`. After the collapse, every surviving node is now renamed from the peers it resolves to. The name is rebuilt from the peer ids the final depPath pass recorded for it, so a hashed suffix is hashed again and a `name@version` peer that closes a cycle is left alone. Only the provisional depPaths the walk nests in a suffix to break a cycle are read back from their text. Keys, child edges, and importer direct deps are rewritten through the renames. The rename runs only when something collapsed. Closes #16356 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository: pnpm/pnpm/.coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review. 📝 WalkthroughWalkthroughThe resolver now records peer IDs with final dependency paths when peer-dependent deduplication is enabled. Deduplication uses those IDs to rename surviving peer-dependent nodes after package variants collapse, and updates graph references and importer dependencies. ChangesPeer-suffix renaming after deduplication
Priority: ➖ Normal Estimated code review effort: 3 (Moderate) | ~25 minutes Change: Bug fix · Severity of issue fixed: Medium Sequence Diagram(s)sequenceDiagram
participant FinishedWorkspaceGraph
participant dedupe_peer_dependents
participant rename_survivors
participant DependenciesGraph
FinishedWorkspaceGraph->>dedupe_peer_dependents: pass peer IDs and suffix-length limit
dedupe_peer_dependents->>rename_survivors: pass collapsed paths and peer suffix data
rename_survivors->>DependenciesGraph: update references and rekey survivor nodes
Assessment against linked issues
Suggested labels: Merge Risk: ⚪ Minimal · up to No actionable merge-blocking issue remains; the change is ready for normal checks. Architecture SummaryArchitecture risk: 🔵 Low · up to The change affects 1 system. Changed systems: Architecture concerns Review detailsSystems and components
Before / after behavior
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
When two survivors rename to one key, the second is dropped. Nodes only it reached had no incoming edge left but stayed in the graph and would surface as orphan snapshots. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Micro-Benchmark ResultsLinux |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #16359 +/- ##
========================================
Coverage 92.12% 92.13%
========================================
Files 1509 1510 +1
Lines 203232 203374 +142
========================================
+ Hits 187234 187384 +150
+ Misses 15998 15990 -8 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Same-run regression checkHEAD and main are measured on the same runner. The tolerance is 5% of the main median or 2 ms, whichever is larger. A regression requires both the median slowdown and the gap between the fastest retained HEAD sample and slowest retained main sample to exceed this tolerance, after trimming up to 10% from each tail. Suspected regressions are rerun once with target order reversed and only fail if reproduced. This conservative noise guard is not a statistical confidence interval. Inconclusive rows do not fail the check. They remain visible for performance review. Bencher retains absolute minimum timings for historical tracking; historical alerts do not gate this PR. Sequential measurements can still be affected by runner drift.
Integrated-Benchmark Report (Linux)Commit: Regular scenarios report direct and pnpr installs. The peer-heavy resolver scenario compares current Rust, main Rust, and TypeScript pnpm; the linked-workspace scenario compares current Rust against main Rust. Bencher consumes pacquet@HEAD and pnpr@HEAD. The tables below show mean ± σ. Bencher tracks absolute minimum latency; PR regression checks compare HEAD and main samples from the same runner. Historical timing alerts do not gate PRs. Scenario: Isolated linker: fresh restore, cold cache + cold store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 2.46632606298,
"stddev": 0.1125367033681843,
"median": 2.4147707022800002,
"user": 1.7316599399999997,
"system": 1.7255439200000002,
"min": 2.35963448528,
"max": 2.73813123228
},
{
"command": "pacquet@main",
"mean": 2.5543331897800003,
"stddev": 0.16525671933508182,
"median": 2.51425174728,
"user": 1.7943796399999996,
"system": 1.8006157200000001,
"min": 2.35568059428,
"max": 2.82762520728
},
{
"command": "pnpr@HEAD",
"mean": 1.51468271528,
"stddev": 0.11474491751038203,
"median": 1.50066687578,
"user": 1.6583676399999998,
"system": 1.6631550199999996,
"min": 1.37698797028,
"max": 1.74036907728
},
{
"command": "pnpr@main",
"mean": 1.49393931928,
"stddev": 0.11388744080724517,
"median": 1.5063854717799998,
"user": 1.63743464,
"system": 1.64974712,
"min": 1.34618687928,
"max": 1.66095218328
}
]
}Scenario: Isolated linker: fresh restore, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.42430395732,
"stddev": 0.10192167787047678,
"median": 0.40230329452,
"user": 0.46277412,
"system": 0.8502860999999999,
"min": 0.35254664502,
"max": 0.6984456880200001
},
{
"command": "pacquet@main",
"mean": 0.38019525542000004,
"stddev": 0.034020881962013305,
"median": 0.37934362102,
"user": 0.45700722000000005,
"system": 0.7862123,
"min": 0.33643803202,
"max": 0.43488291102
},
{
"command": "pnpr@HEAD",
"mean": 0.37913230162,
"stddev": 0.04734967238362764,
"median": 0.36117745152,
"user": 0.42686441999999997,
"system": 0.7577059999999998,
"min": 0.33849305002,
"max": 0.48435662802
},
{
"command": "pnpr@main",
"mean": 0.4569302283200001,
"stddev": 0.03758035687760935,
"median": 0.45381469352000003,
"user": 0.52255682,
"system": 0.8473103999999999,
"min": 0.40546583802,
"max": 0.52194112602
}
]
}Scenario: Isolated linker: repeat install, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.01115269682329005,
"stddev": 0.0016256260274843518,
"median": 0.01089758878,
"user": 0.006203249177489178,
"system": 0.006120835151515154,
"min": 0.00885262378,
"max": 0.017703085780000002
},
{
"command": "pacquet@main",
"mean": 0.01112381352654379,
"stddev": 0.0013937447862700041,
"median": 0.010904171780000001,
"user": 0.0061549443317972345,
"system": 0.006156920552995393,
"min": 0.008330306780000001,
"max": 0.01580112078
},
{
"command": "pnpr@HEAD",
"mean": 0.009856027009838711,
"stddev": 0.001603697101345028,
"median": 0.009349324280000001,
"user": 0.005441247903225808,
"system": 0.005447334354838707,
"min": 0.00784497778,
"max": 0.017670885780000003
},
{
"command": "pnpr@main",
"mean": 0.00927335718780142,
"stddev": 0.0011898138273776441,
"median": 0.00892808078,
"user": 0.005070696170212762,
"system": 0.005190344397163121,
"min": 0.00783244678,
"max": 0.015678819780000002
}
]
}Scenario: Isolated linker: repeat install, cold cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.012203241530303027,
"stddev": 0.0015382343324458851,
"median": 0.011834959500000002,
"user": 0.006772769696969699,
"system": 0.006600783272727269,
"min": 0.0098545445,
"max": 0.0179532505
},
{
"command": "pacquet@main",
"mean": 0.011311539674999998,
"stddev": 0.00147398264371004,
"median": 0.011273120000000001,
"user": 0.006469137499999996,
"system": 0.005832424166666669,
"min": 0.0074848875,
"max": 0.0166602055
},
{
"command": "pnpr@HEAD",
"mean": 0.011278095667464126,
"stddev": 0.0014862692057849415,
"median": 0.011095372499999999,
"user": 0.006325157894736848,
"system": 0.005905139138755981,
"min": 0.008176535500000002,
"max": 0.0157860745
},
{
"command": "pnpr@main",
"mean": 0.010937949541152257,
"stddev": 0.0010426119644771292,
"median": 0.010785060500000002,
"user": 0.006214600823045267,
"system": 0.00563722156378601,
"min": 0.008858854499999999,
"max": 0.014645423500000001
}
]
}Scenario: Isolated linker: fresh install, cold cache + cold store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 3.3046979602599995,
"stddev": 0.20139690415964373,
"median": 3.34675619366,
"user": 3.7009715799999996,
"system": 2.82768028,
"min": 3.0065392711600003,
"max": 3.67330935216
},
{
"command": "pacquet@main",
"mean": 3.3961059160600002,
"stddev": 0.16048931961042065,
"median": 3.37285629266,
"user": 3.9136304799999997,
"system": 2.9842157800000004,
"min": 3.16013089116,
"max": 3.71037795116
},
{
"command": "pnpr@HEAD",
"mean": 1.94655604716,
"stddev": 0.1692488264069355,
"median": 1.90924956916,
"user": 2.23881868,
"system": 2.3988673799999995,
"min": 1.7504659101600002,
"max": 2.2713377441600002
},
{
"command": "pnpr@main",
"mean": 1.8013034782600001,
"stddev": 0.11595764928425521,
"median": 1.8074122886600001,
"user": 2.09054208,
"system": 2.3237857799999997,
"min": 1.6403966251600002,
"max": 1.9806622261600002
}
]
}Scenario: Isolated linker: fresh install, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.79317295512,
"stddev": 0.06201702510516824,
"median": 0.78583941032,
"user": 1.1291499399999998,
"system": 1.1128062800000003,
"min": 0.69561652732,
"max": 0.9208213673200001
},
{
"command": "pacquet@main",
"mean": 0.77109327532,
"stddev": 0.04727611640757675,
"median": 0.75845195182,
"user": 1.08841874,
"system": 1.13269448,
"min": 0.72054923232,
"max": 0.86910764332
},
{
"command": "pnpr@HEAD",
"mean": 0.44617000732,
"stddev": 0.029424279401337582,
"median": 0.43865891732000006,
"user": 0.41477724,
"system": 0.84242358,
"min": 0.40419309732,
"max": 0.49050387732
},
{
"command": "pnpr@main",
"mean": 0.43011197252000005,
"stddev": 0.0302888671628403,
"median": 0.44217202132,
"user": 0.4051867399999999,
"system": 0.81109648,
"min": 0.37826768232,
"max": 0.45740452832
}
]
}Scenario: Isolated linker: fresh install, cold cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 1.93335741244,
"stddev": 0.0390185284572245,
"median": 1.93025822544,
"user": 1.5095787,
"system": 1.4139045199999998,
"min": 1.87556074344,
"max": 1.98836875244
},
{
"command": "pacquet@main",
"mean": 1.9026542875399997,
"stddev": 0.0998596635161799,
"median": 1.87244895444,
"user": 1.501748,
"system": 1.31886322,
"min": 1.76855328444,
"max": 2.11622805244
},
{
"command": "pnpr@HEAD",
"mean": 0.38633980794,
"stddev": 0.020429219259804763,
"median": 0.38745136844000005,
"user": 0.3759968,
"system": 0.8228778199999999,
"min": 0.35079517044,
"max": 0.42331083744000003
},
{
"command": "pnpr@main",
"mean": 0.41547656184,
"stddev": 0.02990270609385439,
"median": 0.41223529194,
"user": 0.4093428,
"system": 0.86918522,
"min": 0.37498198944000005,
"max": 0.45826538044000004
}
]
}Scenario: Isolated linker: fresh resolve, hot cache, offline
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.25084351743666666,
"stddev": 0.008673117702010845,
"median": 0.24969200552,
"user": 0.23967898333333335,
"system": 0.13934795666666666,
"min": 0.23838503752,
"max": 0.26371705052
},
{
"command": "pacquet@main",
"mean": 0.25131740615636367,
"stddev": 0.01944458016808062,
"median": 0.24758665252,
"user": 0.22782744545454545,
"system": 0.11990258545454546,
"min": 0.22224110452,
"max": 0.28972330552000003
},
{
"command": "pnpr@HEAD",
"mean": 0.09415242300275865,
"stddev": 0.003013000392615161,
"median": 0.09376174052,
"user": 0.03690096896551724,
"system": 0.013767350344827586,
"min": 0.08989592152,
"max": 0.10204953352
},
{
"command": "pnpr@main",
"mean": 0.09960607603724139,
"stddev": 0.00864476751422991,
"median": 0.09595285352,
"user": 0.03971352068965518,
"system": 0.017360350344827587,
"min": 0.09093622252,
"max": 0.12299630252
}
]
}Scenario: Isolated linker: peer-heavy resolve, hot cache, offline
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 1.1629172148355553,
"stddev": 0.1876721995033856,
"median": 1.21600764328,
"user": 1.2396468866666666,
"system": 0.3557511511111111,
"min": 0.7580558972800001,
"max": 1.3410296822799999
},
{
"command": "pacquet@main",
"mean": 1.13891477028,
"stddev": 0.17196105223079894,
"median": 1.14560782528,
"user": 1.2124768866666666,
"system": 0.34189059555555557,
"min": 0.82063113728,
"max": 1.45282092928
},
{
"command": "pnpm@HEAD",
"mean": 3.5833955200577776,
"stddev": 0.3967800491475604,
"median": 3.58207646428,
"user": 5.291036886666666,
"system": 0.3006418177777778,
"min": 3.08371314028,
"max": 4.15598014628
}
]
}Scenario: Isolated linker: linked-workspace resolve, hot cache, offline
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.28794984662,
"stddev": 0.026212028407552348,
"median": 0.28806431862000004,
"user": 0.22749276,
"system": 0.12561646,
"min": 0.24569047662000001,
"max": 0.32078490862000003
},
{
"command": "pacquet@main",
"mean": 0.27766669102,
"stddev": 0.013648711861670153,
"median": 0.27992873862,
"user": 0.22768606,
"system": 0.11677486000000001,
"min": 0.25750640562,
"max": 0.30064942462
}
]
}Scenario: Isolated linker: fresh restore, cold cache + cold store + cold pnpr
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 4.63622926906,
"stddev": 0.12002883816897413,
"median": 4.60562480586,
"user": 2.2370747799999995,
"system": 2.04703118,
"min": 4.47709904036,
"max": 4.83693004336
},
{
"command": "pacquet@main",
"mean": 4.556775259059999,
"stddev": 0.16650072905173433,
"median": 4.50243836386,
"user": 2.11714028,
"system": 1.94350918,
"min": 4.40793553536,
"max": 4.86055088736
},
{
"command": "pnpr@HEAD",
"mean": 3.62542108256,
"stddev": 0.13865497004289615,
"median": 3.59747741136,
"user": 1.9730041799999998,
"system": 1.8096209799999996,
"min": 3.45317007736,
"max": 3.88772807536
},
{
"command": "pnpr@main",
"mean": 3.53547685996,
"stddev": 0.09669065893386575,
"median": 3.52487718936,
"user": 1.9719962799999997,
"system": 1.7828795800000001,
"min": 3.42013560036,
"max": 3.79261781236
}
]
}Scenario: GVS linker: fresh restore, hot cache + hot storeSame install as the isolated fresh-restore hot/hot scenario, into the shared virtual store, the layout pnpm 12 installs into by default. Scenarios run on separate machines, so compare main and branch within each table.
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.17650982292333336,
"stddev": 0.02148222978080971,
"median": 0.17439036634000005,
"user": 0.22780989666666662,
"system": 0.17458120999999996,
"min": 0.14044322334,
"max": 0.21095652434000003
},
{
"command": "pacquet@main",
"mean": 0.19628542217333336,
"stddev": 0.028892491709620764,
"median": 0.18711228334000002,
"user": 0.25024506333333335,
"system": 0.17153620999999997,
"min": 0.16888086534000002,
"max": 0.26783743734000004
},
{
"command": "pnpr@HEAD",
"mean": 0.25488810823999997,
"stddev": 0.05734746197995981,
"median": 0.24240005584000002,
"user": 0.28108778,
"system": 0.23528175999999998,
"min": 0.17689041434000002,
"max": 0.36646086534000005
},
{
"command": "pnpr@main",
"mean": 0.2119080049763636,
"stddev": 0.02063457983834196,
"median": 0.21712186734000002,
"user": 0.24718434363636366,
"system": 0.19311100545454546,
"min": 0.17475461334000003,
"max": 0.24231133634000002
}
]
} |
PR Summary by QodoKeep peer-suffixed lockfile keys consistent after deduplication
AI Description
Diagram
High-Level Assessment
Files changed (8)
|
Code Review by Qodo
1.
|
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
…s opaque When a rename sends two nodes to one key, the second one's child aliases, optional children and transitive peers now merge into the node that keeps the key, the way the peer resolution merges records that share a depPath. Before, the second node's edges were discarded and children only it reached were pruned. The text fallback that reads peers back from a suffix now applies only to the provisional depPaths nested in a suffix. A graph node with no recorded peer ids has no peer suffix, even when its package id, such as a tarball URL, ends in parentheses. Peer ids are recorded during the final depPath pass only when the workspace dedupe of peer dependents will read them. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Replies to the findings in the Qodo review summary. 2. Merged variants lose their unique dependencies. Real, fixed in f2a31b5. When a rename sends two nodes to one key, the second node's child aliases, optional children and transitive peers now merge into the node that keeps the key. That is how the peer resolution merges records that share a depPath ( 3. Provider paths retain obsolete names. Not acting on this. 4. Every install keeps peer ids it rarely uses. Real, fixed in f2a31b5. Written by an agent (Claude Code, claude-opus-5-5). |
|
Code review by qodo was updated up to the latest commit f2a31b5 |
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
…er does When a rename merges two consumers that disagree on an alias, the child is now chosen by merge_additional_edges, the same rule the peer resolution applies to records that share a depPath: the child whose peers the consumer's suffix provides wins. Edges are retargeted to the new keys before the nodes move, so the comparison sees final names. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Code review by qodo was updated up to the latest commit 4e0d711 |
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
…merging The transitive-peer lookup that merge_additional_edges consults was built from the graph before colliding nodes merged in, so it held only the kept node's set for a shared key. A parent collision that compared that key with another child could then choose differently from the graph builder, which unions the sets of every record sharing a depPath. The lookup now includes the colliding nodes' sets under their new keys. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Code review by qodo was updated up to the latest commit 8932636 |
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
Brings in the 16 commits main gained since this branch was started, up to d162953 (#16362). Four of them touch files this branch also changes (resolve_peers.rs, resolve_peers/finalize.rs, finalize/final_paths.rs and resolve_peers/walker.rs, from the peer-dependent dedupe work in #16359 and #16361); git merged them without conflicts, and none of main's new code reads the ResolvedPackage fields this branch made private. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01QYTBQo8HY7xD2iz6hjo1CW
Summary
Closes #16356.
pnpm dedupewas not idempotent:pnpm dedupe --checkfailed right afterpnpm dedupe(first bad release 12.4.2).Root cause. A lockfile key is the package id plus a peer suffix that spells out the keys of the peers it resolved.
dedupe_peer_dependentsruns after those keys are built. When it collapses a variant into a larger compatible one, it rewrites the edges that pointed at the collapsed variant, but it keeps every other node's key. In the reporter's repro,@babel/[email protected]collapses into@babel/[email protected]([email protected]). That leaves twobabel-plugin-styled-componentsvariants with identical edges, and the dep-path tie-break keeps the one whose key still names the collapsed@babel/core. The lockfile after the first and seconddedupehas identical snapshot contents. Only two keys differ. Even the freshinstalllockfile names astyled-componentsvariant that does not exist in it.pnpm v12 reads locked peer versions back from those keys, so the next resolution starts from the stale names and produces a different graph.
#14810(12.4.2) made the collapse fire far more often, which is why the problem surfaced then. The recent convergence fixes (#14898,#15600,#15740,#16335) each made one way of reading the lockfile back less lossy. This PR fixes the writing side instead: a key's peer suffix now names the peers the node actually resolves to.Fix. After the collapse, every surviving node is renamed from the peers it resolves to (
dedupe_peer_dependents/survivor_names.rs), and keys, child edges, and importer direct deps are rewritten.FinalDepPaths.peer_ids). A hashed suffix is hashed again.name@versionpeer that closes a cycle is never renamed, even when its text matches a collapsed peerless variant.Verified on the reporter's repro:
dedupeis enough, anddedupe --checkpasses repeatedly.installleaves an existing up-to-date lockfile untouched, so keys only change when something re-resolves (dedupe,update,add).pnpm v11. v11 has the same collapse-without-rename code in
resolvePeers.ts, but it does not read peer pins back from keys the way v12 does, and 11.28.2 is clean on this repro. Renaming there would rewrite keys in maintenance-mode lockfiles without fixing a failure users see, so v11 is left unchanged.Squash Commit Body
Checklist
already linked to it solves it.
are implemented in every affected version.
pnpm changeset) if this PR changes any publishedpackage. Keep it short and written for pnpm users — it becomes a release note.
Written by an agent (Claude Code, claude-opus-5-5).
🤖 Generated with Claude Code
Summary by CodeRabbit
pnpm dedupe --checkpasses immediately afterpnpm dedupe.