Repository navigation
Conversation
`needs_build_marker_triggers_reimport_on_next_install` overwrites a file in a global-virtual-store slot to prove the retry re-imports pristine content. When the store and the slot share a filesystem the importer hardlinks, so writing through the slot's copy rewrote the store's content-addressed file too — after which no re-import could restore the original bytes, and the test failed on the very assertion it exists to make. Unlink the slot's entry first so only the slot's copy is replaced.
…ally A frozen install of an unchanged project re-imported a varying subset of its packages on every repeat run (#13316), instead of reusing the slots the previous install materialized. `calc_dep_graph_hash` breaks dependency cycles by hashing a node that re-enters through one of its own ancestors with its children truncated — and it memoizes that truncated digest until the outermost visit overwrites it. The digest a cycle member ends up with therefore depends on which node the walk entered the cycle from. Upstream is deterministic because JS objects iterate in insertion order; pacquet drove the same walk from `HashMap`s, whose iteration order differs per process, so every install re-derived a different global-virtual-store hash — and a different slot path — for the packages caught in a cycle. The current-lockfile skip gate then found no directory at the new path and re-imported them. Both iteration orders are now pinned to the ones upstream's objects carry: - `DepsGraphNode::children` becomes an `IndexMap`, and the one shared builder inserts `dependencies` before `optionalDependencies`, each in lockfile key order — upstream's `{...dependencies, ...optionalDependencies}` spread. `virtual_store_layout`'s private copy of that builder is gone. - `VirtualStoreLayout::new` walks the snapshots in lockfile key order rather than `HashMap` order, so the per-install memo is filled from the same entry points upstream uses. `BuildModules` shares one `DepsStateCache` across concurrently dispatched chunk members, which has the same entry-point sensitivity, so it primes that cache in lockfile key order before the chunks run — otherwise the side-effects-cache key of a cyclic builder moved between runs and the build re-ran on every install. The unit test pins the digests against the ones pnpm's own `@pnpm/deps.graph-hasher` produces for the same graph: the two CLIs share one global virtual store, so a cyclic package has to land on the same slot whichever of them installed it. Closes #13316
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughThe PR makes dependency graph traversal and cache initialization deterministic, updates global virtual store hashing for cyclic dependencies, adds graph and install regression tests, and records a pacquet patch release. ChangesDeterministic cyclic GVS hashing
Estimated code review effort: 4 (Complex) | ~45 minutes Possibly related PRs
Suggested labels: Suggested reviewers: ✨ 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 |
PR Summary by QodoFix deterministic global-virtual-store slot hashing for cyclic dependencies
AI Description
Diagram
High-Level Assessment
Files changed (12)
|
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains. Reviews (3): Last reviewed commit: "perf(graph-hasher): skip already-memoize..." | Re-trigger Greptile |
Micro-Benchmark ResultsLinux |
`slot_dir` builds its tail from native path components, so the Windows run of the new parity test compared `@\a\1.0.0\<digest>` against the `/`-separated form the global-virtual-store path is canonically written in. Only the separators differed — the digests already matched.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #13368 +/- ##
=======================================
Coverage 87.21% 87.21%
=======================================
Files 536 536
Lines 92034 92049 +15
=======================================
+ Hits 80269 80283 +14
- Misses 11765 11766 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Code Review by Qodo
Context used✅ Compliance rules (platform):
24 rules 1.
|
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
pnpm/crates/cli/tests/global_virtual_store.rs (1)
750-754: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick winSecond corruption step still writes over
package_manifestwithout unlinking first.
corrupt_pristine_filewas introduced (and used at line 737) precisely to avoid truncating a hardlinked slot file in place, since that would corrupt the shared content-addressed store copy and make it impossible to recover the pristine bytes. The second corruption at line 753 (fs::write(&package_manifest, "{}")) still does the unguarded in-place write, right after a reimport at line 740 that (under the default hardlink import method) would have re-hardlinked this file to the store. This risks corrupting the store's copy and making the laterpristine_manifestcomparisons (761-765) unreliable/flaky.🛠️ Proposed fix
fs::write(&marker, "").expect("write the second incomplete-build marker"); fs::remove_file(&postinstall_artifact).expect("remove the rebuilt artifact"); - fs::write(&package_manifest, "{}").expect("corrupt the pristine file again"); + corrupt_pristine_file(&package_manifest); pacquet(&workspace).with_arg("install").assert().success();🤖 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 `@pnpm/crates/cli/tests/global_virtual_store.rs` around lines 750 - 754, Replace the second direct fs::write(&package_manifest, "{}") in the repeat-install scenario with the existing corrupt_pristine_file helper, preserving the same corruption behavior while unlinking the hardlinked slot file before rewriting it. Keep the surrounding marker, artifact removal, install, and pristine-manifest assertions unchanged.
🤖 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.
Outside diff comments:
In `@pnpm/crates/cli/tests/global_virtual_store.rs`:
- Around line 750-754: Replace the second direct fs::write(&package_manifest,
"{}") in the repeat-install scenario with the existing corrupt_pristine_file
helper, preserving the same corruption behavior while unlinking the hardlinked
slot file before rewriting it. Keep the surrounding marker, artifact removal,
install, and pristine-manifest assertions unchanged.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: a0afb7f8-1438-4feb-b2e6-c967ae7837fc
⛔ Files ignored due to path filters (1)
Cargo.lockis excluded by!**/*.lock,!Cargo.lock
📒 Files selected for processing (11)
.changeset/deterministic-gvs-hashes-for-cycles.mdpnpm/crates/cli/tests/global_virtual_store.rspnpm/crates/graph-hasher/Cargo.tomlpnpm/crates/graph-hasher/src/dep_state.rspnpm/crates/graph-hasher/src/dep_state/tests.rspnpm/crates/graph-hasher/src/global_virtual_store_path/tests.rspnpm/crates/graph-hasher/src/lib.rspnpm/crates/package-manager/src/build_modules.rspnpm/crates/package-manager/src/deps_graph.rspnpm/crates/package-manager/src/virtual_store_layout.rspnpm/crates/package-manager/src/virtual_store_layout/tests.rs
|
Code review by qodo was updated up to the latest commit 5a1b25b |
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
The warm-up walked every key with a freshly allocated `parents` set, even though the walker returns immediately once a key is memoized — so priming a graph whose earlier walks already covered most of it paid an allocation and a call per node for nothing. Guard on the cache and thread one set through instead; each walk restores it to empty, which the test now pins against per-key walks from fresh sets.
|
Thanks — went through all three findings. 1. Warm cache alloc overhead — fixed in f78dadc. 2. Changeset missing 3. Written by an agent (Claude Code, claude-opus-5). |
|
Code review by qodo was updated up to the latest commit f78dadc |
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
Integrated-Benchmark Report (Linux)Commit: Each scenario reports direct installs and pnpr installs. 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
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 2.5710746369599997,
"stddev": 0.1840941601682281,
"median": 2.54891354206,
"user": 1.56451922,
"system": 1.2826190199999998,
"min": 2.36487973806,
"max": 2.79409548706,
"times": [
2.3906514090599997,
2.73817264706,
2.79409548706,
2.36487973806,
2.7642516760599998,
2.39967841006,
2.38283812206,
2.60465377306,
2.49317331106,
2.77835179606
]
},
{
"command": "pacquet@main",
"mean": 2.5907083303600005,
"stddev": 0.1131200706121093,
"median": 2.61357777006,
"user": 1.50337682,
"system": 1.3416448200000002,
"min": 2.36690659406,
"max": 2.74506128806,
"times": [
2.66090835306,
2.5652479330599998,
2.62566313106,
2.60149240906,
2.64035238706,
2.44831474306,
2.69374918206,
2.36690659406,
2.55938728306,
2.74506128806
]
},
{
"command": "pnpr@HEAD",
"mean": 1.59025028596,
"stddev": 0.13470064135678284,
"median": 1.5468901370600001,
"user": 1.0789652200000002,
"system": 1.13037812,
"min": 1.4022696700600001,
"max": 1.80208994206,
"times": [
1.80208994206,
1.54928949606,
1.53731778306,
1.4022696700600001,
1.64311125806,
1.7771964570600003,
1.5444907780600001,
1.51510338006,
1.6921655090600003,
1.43946858606
]
},
{
"command": "pnpr@main",
"mean": 1.49672958366,
"stddev": 0.1131463787275212,
"median": 1.5080918440600002,
"user": 1.06336822,
"system": 1.12465612,
"min": 1.35759713006,
"max": 1.6541971510600002,
"times": [
1.5836084420600003,
1.40571329806,
1.5306058770600002,
1.3739222960600002,
1.4855778110600002,
1.35759713006,
1.5841778960600001,
1.3709857170600002,
1.6541971510600002,
1.6209102180600001
]
}
]
}Scenario: Isolated linker: fresh restore, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.25559146336,
"stddev": 0.005342097847691387,
"median": 0.25554190676,
"user": 0.21341278,
"system": 0.52485116,
"min": 0.24608385026000001,
"max": 0.26411087626,
"times": [
0.25884927526,
0.25370171726,
0.24608385026000001,
0.25699039826,
0.25409341526,
0.24967298826000003,
0.26411087626,
0.26045042326,
0.25885662826,
0.25310506126
]
},
{
"command": "pacquet@main",
"mean": 0.25004286366,
"stddev": 0.006528431851242669,
"median": 0.24784394526000003,
"user": 0.20602218,
"system": 0.51483016,
"min": 0.24222602526,
"max": 0.26238603426,
"times": [
0.24888728826,
0.25278690226,
0.25689956726,
0.24222602526,
0.24358481726000003,
0.24660265926000002,
0.24511839926,
0.25513634126,
0.26238603426,
0.24680060226000003
]
},
{
"command": "pnpr@HEAD",
"mean": 0.27059496466,
"stddev": 0.008773548120581806,
"median": 0.26938733175999996,
"user": 0.20480197999999997,
"system": 0.5301293599999999,
"min": 0.25802328726,
"max": 0.29026062126,
"times": [
0.25802328726,
0.26092453826,
0.26836727326,
0.27608048926,
0.27184974026,
0.27354927626,
0.26919415226,
0.26958051126,
0.26811975726,
0.29026062126
]
},
{
"command": "pnpr@main",
"mean": 0.27509394796,
"stddev": 0.0037472575770994944,
"median": 0.27515386726,
"user": 0.23302757999999996,
"system": 0.5247284600000001,
"min": 0.26893411225999997,
"max": 0.28202676326,
"times": [
0.26893411225999997,
0.27159385726,
0.28202676326,
0.27861663226,
0.27595465126,
0.27730524825999997,
0.27412377026,
0.27503724226,
0.27527049226,
0.27207671025999997
]
}
]
}Scenario: Isolated linker: fresh install, cold cache + cold store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 2.7935676746399993,
"stddev": 0.027407137764178774,
"median": 2.7965593437400003,
"user": 1.71762172,
"system": 1.3253944599999998,
"min": 2.74104499124,
"max": 2.84668640924,
"times": [
2.80383395724,
2.77051300224,
2.74104499124,
2.84668640924,
2.79632251724,
2.79041439924,
2.79679617024,
2.81007269824,
2.80042063224,
2.77957196924
]
},
{
"command": "pacquet@main",
"mean": 2.7913133385399993,
"stddev": 0.015926430584589917,
"median": 2.79545670374,
"user": 1.71584652,
"system": 1.31051046,
"min": 2.76923507324,
"max": 2.81120649624,
"times": [
2.79981933924,
2.80754638624,
2.80346866824,
2.76923507324,
2.77834707124,
2.81120649624,
2.80338864224,
2.77017651024,
2.79109406824,
2.77885113024
]
},
{
"command": "pnpr@HEAD",
"mean": 1.58142764074,
"stddev": 0.1362722292313111,
"median": 1.54382240774,
"user": 1.0137647200000002,
"system": 1.1904341599999997,
"min": 1.43369076324,
"max": 1.82980210324,
"times": [
1.70024703224,
1.76342054824,
1.43369076324,
1.82980210324,
1.46964792924,
1.54872351124,
1.51830425224,
1.55852596724,
1.53892130424,
1.45299299624
]
},
{
"command": "pnpr@main",
"mean": 1.55524630974,
"stddev": 0.08851296943303374,
"median": 1.55307172674,
"user": 1.01946652,
"system": 1.1666681599999997,
"min": 1.42513346324,
"max": 1.68544571224,
"times": [
1.63321240524,
1.68544571224,
1.55792221924,
1.5106894092399998,
1.51301001324,
1.44496507424,
1.42513346324,
1.67594134724,
1.55730725024,
1.54883620324
]
}
]
}Scenario: Isolated linker: fresh install, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.5874565833600002,
"stddev": 0.007742150362112578,
"median": 0.5885067935600001,
"user": 0.6928834199999999,
"system": 0.7007068799999999,
"min": 0.5744941690600001,
"max": 0.5982339010600001,
"times": [
0.5744941690600001,
0.5824885870600001,
0.5912930890600001,
0.59061468106,
0.5781485970600001,
0.59631726906,
0.5839141130600001,
0.5982339010600001,
0.5926625210600001,
0.5863989060600001
]
},
{
"command": "pacquet@main",
"mean": 0.5872891274600001,
"stddev": 0.010417519343374005,
"median": 0.5868297530600001,
"user": 0.7010605199999999,
"system": 0.69376488,
"min": 0.5716013670600001,
"max": 0.60496749106,
"times": [
0.5834330660600001,
0.5812094550600001,
0.58785330706,
0.5754125600600001,
0.5858061990600001,
0.6008017200600001,
0.5882592820600001,
0.60496749106,
0.5935468270600001,
0.5716013670600001
]
},
{
"command": "pnpr@HEAD",
"mean": 0.30545663276,
"stddev": 0.0055854560915820795,
"median": 0.30417086856,
"user": 0.21020832,
"system": 0.5269856799999999,
"min": 0.29862142006000003,
"max": 0.31391339006,
"times": [
0.30439988006,
0.30819344006,
0.31246323606,
0.30063912206,
0.30394185706,
0.30234980606,
0.31090879706,
0.31391339006,
0.29913537906,
0.29862142006000003
]
},
{
"command": "pnpr@main",
"mean": 0.30652028216000005,
"stddev": 0.006810996027967106,
"median": 0.30556922856,
"user": 0.19022441999999998,
"system": 0.56494848,
"min": 0.29604045506,
"max": 0.31948119306,
"times": [
0.30246244806,
0.30919916506,
0.31290076206,
0.30022050406,
0.29604045506,
0.30304910406,
0.30411374006,
0.30702471706,
0.31948119306,
0.31071073306
]
}
]
}Scenario: Isolated linker: fresh install, cold cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 1.9184411981,
"stddev": 0.0090007182868924,
"median": 1.9189533299000001,
"user": 0.9488908,
"system": 0.7751988599999999,
"min": 1.9037261129,
"max": 1.9357408779,
"times": [
1.9250087819000001,
1.9357408779,
1.9183212589,
1.9195854009000002,
1.9156468789,
1.9068726319,
1.9206895159000001,
1.9037261129,
1.9225941209000001,
1.9162264009
]
},
{
"command": "pacquet@main",
"mean": 1.9167477697,
"stddev": 0.012614905301016244,
"median": 1.9141454294,
"user": 0.9831888000000001,
"system": 0.7433483599999999,
"min": 1.8989128229,
"max": 1.9432834919000002,
"times": [
1.9138853689000002,
1.9432834919000002,
1.9322172559000002,
1.9144054899,
1.9179475448999999,
1.8989128229,
1.9054373699,
1.9135140098999999,
1.9147700259,
1.9131043169
]
},
{
"command": "pnpr@HEAD",
"mean": 0.3060954783,
"stddev": 0.007736663857170112,
"median": 0.3056316334,
"user": 0.18950379999999997,
"system": 0.55369646,
"min": 0.2918119309,
"max": 0.31886914190000004,
"times": [
0.31886914190000004,
0.30884807690000005,
0.3062625829,
0.30193574790000005,
0.3050006839,
0.31385379890000004,
0.2918119309,
0.30086356890000004,
0.3120921099,
0.30141714090000005
]
},
{
"command": "pnpr@main",
"mean": 0.3087175940000001,
"stddev": 0.007017885808663972,
"median": 0.30581355740000005,
"user": 0.19938399999999998,
"system": 0.5392269599999999,
"min": 0.3020328319,
"max": 0.3240758629,
"times": [
0.3060217699,
0.3056053449,
0.30334045690000006,
0.30330020990000006,
0.3037537449,
0.3240758629,
0.3020328319,
0.31518878590000005,
0.31151417090000005,
0.31234276190000004
]
}
]
}Scenario: Isolated linker: fresh resolve, hot cache, offline
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.36414927818000004,
"stddev": 0.025977482555368702,
"median": 0.35377120338,
"user": 0.35389446,
"system": 0.058750219999999985,
"min": 0.34402455038,
"max": 0.41859955038,
"times": [
0.40521024738,
0.35036756438,
0.34943571738,
0.34402455038,
0.34705870838,
0.41859955038,
0.34851226838,
0.35717484238,
0.36079237938000003,
0.36031695338
]
},
{
"command": "pacquet@main",
"mean": 0.35844965008,
"stddev": 0.006908845045490837,
"median": 0.35672921288000004,
"user": 0.35511016000000006,
"system": 0.05378172,
"min": 0.35123956838000003,
"max": 0.37373756638,
"times": [
0.36275523038,
0.36327464738000004,
0.35360094638,
0.35338991938000003,
0.35449133538,
0.35123956838000003,
0.36036534438,
0.37373756638,
0.35896709038,
0.35267485238
]
},
{
"command": "pnpr@HEAD",
"mean": 0.08648620495575757,
"stddev": 0.0021272880211936074,
"median": 0.08678488538,
"user": 0.020535902424242417,
"system": 0.008593841818181817,
"min": 0.08150033638,
"max": 0.09010467238,
"times": [
0.08683170438,
0.08678159838,
0.08780028938,
0.08705138738,
0.08731109738,
0.08678488538,
0.08884672237999999,
0.08766815938,
0.08930120838,
0.08411772938,
0.08869801138,
0.08646126638,
0.08703600838,
0.09010467238,
0.08790005638,
0.08507611638,
0.08599114838,
0.08265192738,
0.08372303438,
0.08654558438,
0.08959074438,
0.08536120238,
0.08773623938,
0.08765967338,
0.08753085238,
0.08150033638,
0.08549963438,
0.08523592638,
0.08919164238,
0.08575473538,
0.08173048938,
0.08589331638,
0.08467736338
]
},
{
"command": "pnpr@main",
"mean": 0.08635507771333334,
"stddev": 0.0019804464141062942,
"median": 0.08642989638,
"user": 0.01921835696969697,
"system": 0.009721431515151514,
"min": 0.08240958038,
"max": 0.09036028338,
"times": [
0.08737805238,
0.08766547638,
0.08760274738,
0.08559746938,
0.08740348138,
0.08345561138,
0.08870803038,
0.08796973838,
0.08532320138,
0.09036028338,
0.08434192238,
0.08929639838,
0.08515764038,
0.08240958038,
0.08432338738,
0.08535152438,
0.08246300038,
0.08276707438,
0.08574867238,
0.08515864138,
0.08729816238,
0.08763411638,
0.08903757138,
0.08842772238,
0.08508897038,
0.08656886838,
0.08636426338,
0.08580517938,
0.08683552138,
0.08811916938,
0.08595815838,
0.08642989638,
0.08766803138
]
}
]
}Scenario: Isolated linker: fresh restore, cold cache + cold store + cold pnpr
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 4.64753136826,
"stddev": 0.18592770181400822,
"median": 4.59481113906,
"user": 1.7399543199999996,
"system": 1.37422162,
"min": 4.44112306956,
"max": 4.89617243956,
"times": [
4.881168983559999,
4.44112306956,
4.4467582195599995,
4.47414289756,
4.54310032156,
4.52908736456,
4.89617243956,
4.64652195656,
4.75911751256,
4.85812091756
]
},
{
"command": "pacquet@main",
"mean": 4.53870282826,
"stddev": 0.0914705989132989,
"median": 4.5125059280599995,
"user": 1.7211192199999998,
"system": 1.4087267200000002,
"min": 4.44626520656,
"max": 4.72526719356,
"times": [
4.72526719356,
4.482314071559999,
4.57839561756,
4.54269778456,
4.468834762559999,
4.650887668559999,
4.46905819356,
4.47042866456,
4.44626520656,
4.55287911956
]
},
{
"command": "pnpr@HEAD",
"mean": 3.5220704522600004,
"stddev": 0.0590827880636769,
"median": 3.50826130156,
"user": 1.1974666199999997,
"system": 1.2191200199999996,
"min": 3.4366467595600003,
"max": 3.63443288956,
"times": [
3.5681019585600002,
3.51517580456,
3.45695605656,
3.5609393815600003,
3.4366467595600003,
3.63443288956,
3.4963855285600003,
3.49024186356,
3.50134679856,
3.56047748156
]
},
{
"command": "pnpr@main",
"mean": 3.5047916097600003,
"stddev": 0.05964424839568193,
"median": 3.4839919320600004,
"user": 1.1636166199999998,
"system": 1.2335154200000003,
"min": 3.43863473556,
"max": 3.62404798956,
"times": [
3.47689962456,
3.49108423956,
3.4520899865600003,
3.43863473556,
3.46988964856,
3.52864314456,
3.62404798956,
3.4540445115600003,
3.5542801495600003,
3.55830206756
]
}
]
} |
|
| Project | pnpm's project |
| Branch | pr/13368 |
| Testbed | pnpr |
⚠️ 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-thresholdsflag.
Click to view all benchmark results
| Benchmark | Latency | milliseconds (ms) |
|---|---|---|
| isolated-linker.fresh-install.cold-cache.cold-store | 📈 view plot | 1,433.69 ms |
| isolated-linker.fresh-install.cold-cache.hot-store | 📈 view plot | 291.81 ms |
| isolated-linker.fresh-install.hot-cache.hot-store | 📈 view plot | 298.62 ms |
| isolated-linker.fresh-resolve.hot-cache.offline | 📈 view plot | 81.50 ms |
| isolated-linker.fresh-restore.cold-cache.cold-store | 📈 view plot | 1,402.27 ms |
| isolated-linker.fresh-restore.cold-cache.cold-store.cold-pnpr | 📈 view plot | 3,436.65 ms |
| isolated-linker.fresh-restore.hot-cache.hot-store | 📈 view plot | 258.02 ms |
…ally (pnpm#13368) A frozen install of an unchanged project re-imported a varying subset of its packages on every repeat run, instead of reusing the slots the previous install materialized. `calc_dep_graph_hash` breaks dependency cycles by hashing a node that re-enters through one of its own ancestors with its children truncated — and it memoizes that truncated digest until the outermost visit overwrites it. The digest a cycle member ends up with therefore depends on which node the walk entered the cycle from. Upstream is deterministic because JS objects iterate in insertion order; pacquet drove the same walk from `HashMap`s, whose iteration order differs per process, so every install re-derived a different global-virtual-store hash — and a different slot path — for the packages caught in a cycle. The current-lockfile skip gate then found no directory at the new path and re-imported them. Both iteration orders are now pinned to the ones upstream's objects carry: - `DepsGraphNode::children` becomes an `IndexMap`, and the one shared builder inserts `dependencies` before `optionalDependencies`, each in lockfile key order — upstream's `{...dependencies, ...optionalDependencies}` spread. `virtual_store_layout`'s private copy of that builder is gone. - `VirtualStoreLayout::new` walks the snapshots in lockfile key order rather than `HashMap` order, so the per-install memo is filled from the same entry points upstream uses. `BuildModules` shares one `DepsStateCache` across concurrently dispatched chunk members, which has the same entry-point sensitivity, so it primes that cache in lockfile key order before the chunks run — otherwise the side-effects-cache key of a cyclic builder moved between runs and the build re-ran on every install. The unit test pins the digests against the ones pnpm's own `@pnpm/deps.graph-hasher` produces for the same graph: the two CLIs share one global virtual store, so a cyclic package has to land on the same slot whichever of them installed it. Closes pnpm#13316
Summary
Closes #13316 — pnpm 12 re-imported a varying subset of packages on every repeat frozen install of an unchanged project (reported on
mui/material-ui, whereeslint,vitest,@vitest/*,@mui/internal-*came back run after run).Root cause.
calc_dep_graph_hashbreaks dependency cycles by hashing a node that re-enters through one of its own ancestors with its children truncated, and it memoizes that truncated digest until the outermost visit overwrites it. So the digest a cycle member ends up with depends on which node the walk entered the cycle from. pnpm's TypeScript CLI is deterministic here only because JS objects iterate in insertion order; pacquet drove the same walk fromHashMaps — the lockfile'ssnapshotsmap and each node'schildrenmap — whose iteration order changes on every process. Every install therefore re-derived a different global-virtual-store hash, and thus a different slot path, for whichever packages happened to sit in a cycle.CreateVirtualStore's current-lockfile skip gate then found no directory at the new path, emittedpnpm:_broken_node_modules, and re-imported them.Only the packages caught in a cycle moved, and which ones moved changed per run — matching the issue's "varying subset" exactly.
Fix. Pin both iteration orders to the ones upstream's objects carry:
DepsGraphNode::childrenbecomes anIndexMap, and the single shared builder insertsdependenciesbeforeoptionalDependencies, each in lockfile key order — upstream's{...dependencies, ...optionalDependencies}spread.virtual_store_layout's private duplicate of that builder is gone.VirtualStoreLayout::newwalks snapshots in lockfile key order instead ofHashMaporder, so the per-install memo is filled from the same entry points upstream uses.BuildModulesshares oneDepsStateCacheacross concurrently dispatched chunk members, which has the same entry-point sensitivity, so it now primes that cache in lockfile key order before the chunks run. Otherwise the side-effects-cache key of a builder inside a cycle moved between runs and its build re-ran on every install.Cross-stack parity. The unit test pins the eight digests of a two-cycle fixture against the values pnpm's own
@pnpm/deps.graph-hasherproduces for the same graph (obtained by running the compiled TS package). The two CLIs share one global virtual store, so a cyclic package has to land on the same slot whichever of them installed it; the fixture is built so that both a plain alphabetical children merge and anoptionalDependencies-first merge produce different digests, and either mistake fails the test.TypeScript side. No change needed: the TS CLI's iteration orders are already fixed by insertion order. Worth noting as a follow-up (not fixed here, and not a regression):
building/after-installcomputes side-effects-cache keys from a shareddepsStateCacheinside its concurrent chunk loop, so the key of a cyclic builder there is scheduling-dependent in the same way pacquet's was.Drive-by.
needs_build_marker_triggers_reimport_on_next_installcorrupted a slot file withfs::write. When the store and the slot share a filesystem the importer hardlinks, so that rewrote the store's content-addressed file too and no re-import could restore the original bytes — the test failed locally on the very assertion it exists to make (it passes on CI, where the two land on different filesystems). It now unlinks before writing. Kept as its own commit.Squash Commit Body
Checklist
pnpm/port, or the description notes what still needs porting.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).
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Summary by CodeRabbit
Bug Fixes
--frozen-lockfileinstalls re-importing an inconsistent subset of packages by making global virtual store slot assignment deterministic for dependency cycles.Reliability
Tests