Repository navigation
feat(pacquet): prune surplus virtual-store dirs on install - #12419
Conversation
Code Review by Qodo
1. NotFound containment bypass
|
|
Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughA new ChangesVirtual Store Pruning
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 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 QodoPrune surplus virtual-store dirs during install (isolated linker) WalkthroughsDescription• Prune unreferenced .pacquet virtual-store entries after install, matching pnpm behavior. • Add a modulesCacheMaxAge/prunedAt throttle and preserve prunedAt when no sweep ran. • Add unit + integration coverage for sweep correctness and throttle edge cases. Diagramgraph TD
A["Install pipeline"] --> B["Read .modules.yaml"] --> C{"Should prune?"} --> D["Compute needed names"] --> E["Sweep .pacquet dir"] --> F["Write .modules.yaml (prunedAt)"]
D --> G["Wanted lockfile snapshots"]
E --> H[("Virtual store: node_modules/.pacquet")]
subgraph Legend
direction LR
_proc["Process step"] ~~~ _dec{"Decision"} ~~~ _disk[("On-disk state")]
end
High-Level AssessmentThe following are alternative approaches to this PR: 1. Record and surface prune results (removed count / warnings)
2. Make current-lockfile write unconditional (full pnpm parity)
3. Compute needed set from actual linked state instead of lockfile snapshots
Recommendation: Keep this PR’s approach: porting pnpm’s sweep + throttle is the lowest-risk path and addresses the real pain (virtual-store accumulation) without broad installer refactors. Consider a follow-up to surface the removed-count via logging/metrics, and separately evaluate making current-lockfile writes unconditional to remove the need to preserve File ChangesEnhancement (3)
Tests (2)
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #12419 +/- ##
==========================================
+ Coverage 88.03% 88.05% +0.01%
==========================================
Files 309 310 +1
Lines 41595 41735 +140
==========================================
+ Hits 36618 36748 +130
- Misses 4977 4987 +10 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Integrated-Benchmark Report (Linux)Each scenario reports direct installs and pnpr installs. Bencher consumes pacquet@HEAD and pnpr@HEAD. Scenario: Isolated linker: fresh restore, cold cache + cold store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 4.198567462640001,
"stddev": 0.1635112546129539,
"median": 4.14181486964,
"user": 3.9912931200000004,
"system": 3.4268241,
"min": 4.00962080814,
"max": 4.50546953914,
"times": [
4.248851070140001,
4.50546953914,
4.04848509114,
4.42034670714,
4.28197577714,
4.08558563814,
4.16360461814,
4.1017102561400005,
4.12002512114,
4.00962080814
]
},
{
"command": "pacquet@main",
"mean": 4.104965184839999,
"stddev": 0.14154934638094363,
"median": 4.0647821016400005,
"user": 3.98909892,
"system": 3.3911195999999997,
"min": 3.9700043531399998,
"max": 4.37027618814,
"times": [
4.13821937214,
4.065118136140001,
4.3378063761400005,
4.37027618814,
3.99477836814,
3.9700043531399998,
3.99748603514,
4.10390228414,
4.0644460671400005,
4.0076146681400004
]
},
{
"command": "pnpr@HEAD",
"mean": 2.2047832696399996,
"stddev": 0.13231447680944614,
"median": 2.2311353481399996,
"user": 2.70228772,
"system": 2.8413255000000004,
"min": 2.0287267451399997,
"max": 2.3581797171399996,
"times": [
2.31191240114,
2.0454934461399996,
2.2577409821399996,
2.3581797171399996,
2.0287267451399997,
2.20452971414,
2.34050033614,
2.10322486714,
2.33024893114,
2.06727555614
]
},
{
"command": "pnpr@main",
"mean": 2.09013485414,
"stddev": 0.10593995277347404,
"median": 2.04190381964,
"user": 2.7047983199999996,
"system": 2.8847447,
"min": 1.94880660114,
"max": 2.2797120451399997,
"times": [
2.1400378611399997,
2.0201372111399998,
2.01005916014,
1.94880660114,
2.02829218814,
2.21268341114,
2.04937687714,
2.17781242414,
2.2797120451399997,
2.03443076214
]
}
]
}Scenario: Isolated linker: fresh restore, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.6398166672600001,
"stddev": 0.007129755971092611,
"median": 0.6398964945600001,
"user": 0.38574288,
"system": 1.3182167200000001,
"min": 0.6264870575600001,
"max": 0.6511560285600001,
"times": [
0.6333860945600001,
0.63854934356,
0.6264870575600001,
0.63700269456,
0.64124364556,
0.63595645556,
0.6425554545600001,
0.6511560285600001,
0.6450352285600001,
0.6467946695600001
]
},
{
"command": "pacquet@main",
"mean": 0.6454396899600001,
"stddev": 0.08660678297997833,
"median": 0.6238277560600001,
"user": 0.35653788,
"system": 1.31771582,
"min": 0.5998995935600001,
"max": 0.8896582495600001,
"times": [
0.6196915885600001,
0.6319784055600001,
0.6279639235600001,
0.5998995935600001,
0.60662524656,
0.60670178756,
0.62984354756,
0.6110900165600001,
0.8896582495600001,
0.63094454056
]
},
{
"command": "pnpr@HEAD",
"mean": 0.7028834728600001,
"stddev": 0.08009607271701158,
"median": 0.6804366775600001,
"user": 0.39157918,
"system": 1.3605299199999998,
"min": 0.6569412895600001,
"max": 0.9278495185600001,
"times": [
0.6902289385600001,
0.6643569855600001,
0.6796060895600001,
0.6812672655600001,
0.6734836045600001,
0.6569412895600001,
0.6698307805600001,
0.9278495185600001,
0.70257513656,
0.6826951195600001
]
},
{
"command": "pnpr@main",
"mean": 0.6804386866600002,
"stddev": 0.030535242320551447,
"median": 0.6734824300600001,
"user": 0.3713948799999999,
"system": 1.34212642,
"min": 0.6468873055600001,
"max": 0.7450444235600001,
"times": [
0.7450444235600001,
0.6835786835600001,
0.6468873055600001,
0.6726852175600001,
0.6756601995600001,
0.65678943856,
0.72298133356,
0.66272205256,
0.6637585695600001,
0.6742796425600001
]
}
]
}Scenario: Isolated linker: fresh install, cold cache + cold store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 4.21994227844,
"stddev": 0.04043640088581799,
"median": 4.22315053514,
"user": 3.7817532199999997,
"system": 3.29139882,
"min": 4.14509111764,
"max": 4.2953455496399995,
"times": [
4.21239288764,
4.25298955564,
4.22255714364,
4.22710403164,
4.14509111764,
4.23331380764,
4.21108593164,
4.22374392664,
4.2953455496399995,
4.17579883264
]
},
{
"command": "pacquet@main",
"mean": 4.1945426894399995,
"stddev": 0.03539131571861478,
"median": 4.191225064639999,
"user": 3.77999602,
"system": 3.2712707199999995,
"min": 4.1554930596399995,
"max": 4.27125413164,
"times": [
4.18416081264,
4.20997542464,
4.1554930596399995,
4.1982893166399995,
4.1568362176399996,
4.17350267564,
4.27125413164,
4.20989171764,
4.21945659764,
4.16656694064
]
},
{
"command": "pnpr@HEAD",
"mean": 2.15211176504,
"stddev": 0.13109364231095155,
"median": 2.15230104814,
"user": 2.53558132,
"system": 2.8040207199999996,
"min": 1.94757707264,
"max": 2.3805178926400004,
"times": [
2.2301179666400004,
2.02582121064,
2.1910973516400003,
2.0402003256400003,
2.3805178926400004,
2.2972467576400004,
1.94757707264,
2.17682371264,
2.1277783836400004,
2.10393697664
]
},
{
"command": "pnpr@main",
"mean": 2.23474154664,
"stddev": 0.14449195555723904,
"median": 2.2060396006400005,
"user": 2.53646472,
"system": 2.7789792199999996,
"min": 2.02468981864,
"max": 2.4439945476400005,
"times": [
2.4247717526400003,
2.1926503946400002,
2.3864929106400004,
2.1348070316400003,
2.4439945476400005,
2.0894652876400004,
2.2194288066400003,
2.1563184416400003,
2.02468981864,
2.27479647464
]
}
]
}Scenario: Isolated linker: fresh install, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 1.3544811689599998,
"stddev": 0.015343194671213919,
"median": 1.35090653576,
"user": 1.33982944,
"system": 1.7180758,
"min": 1.3292935047599999,
"max": 1.38109434576,
"times": [
1.35067766676,
1.35113540476,
1.34689218476,
1.3292935047599999,
1.36078972176,
1.38109434576,
1.36930775276,
1.3470191967599998,
1.34056381376,
1.36803809776
]
},
{
"command": "pacquet@main",
"mean": 1.3722953802600002,
"stddev": 0.04762588097759473,
"median": 1.36389037576,
"user": 1.3091970399999997,
"system": 1.7457981999999999,
"min": 1.3445875487599999,
"max": 1.5053693097599998,
"times": [
1.3445875487599999,
1.34839258476,
1.5053693097599998,
1.35177228976,
1.34609292176,
1.36869134276,
1.3648679927599998,
1.36539906076,
1.3647604067599999,
1.36302034476
]
},
{
"command": "pnpr@HEAD",
"mean": 0.65203177516,
"stddev": 0.019340342680285828,
"median": 0.6474298787600001,
"user": 0.3456363399999999,
"system": 1.2701635999999998,
"min": 0.63062604976,
"max": 0.7020671137600001,
"times": [
0.6464127477600001,
0.7020671137600001,
0.6550244257600001,
0.63062604976,
0.6433056117600001,
0.64392022376,
0.63878563576,
0.6543582987600001,
0.64844700976,
0.6573706347600001
]
},
{
"command": "pnpr@main",
"mean": 0.6607243431600001,
"stddev": 0.06295320442613839,
"median": 0.6428861837600001,
"user": 0.31710143999999996,
"system": 1.2828633999999997,
"min": 0.62899467076,
"max": 0.8385112047600001,
"times": [
0.63408529276,
0.6430588997600001,
0.63203742076,
0.6399801997600001,
0.6555439647600001,
0.64271346776,
0.6472838797600001,
0.6450344307600001,
0.62899467076,
0.8385112047600001
]
}
]
}Scenario: Isolated linker: fresh install, cold cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 3.01573095844,
"stddev": 0.046443378793367615,
"median": 3.0012806985399996,
"user": 1.7973564,
"system": 1.96668364,
"min": 2.97048665354,
"max": 3.10290183654,
"times": [
3.01936741954,
2.97865142954,
3.09414068854,
2.98897376054,
3.01753533754,
3.0023803505399997,
2.97048665354,
2.9826910615399997,
3.10290183654,
3.00018104654
]
},
{
"command": "pacquet@main",
"mean": 3.0436735718400003,
"stddev": 0.04429741767103705,
"median": 3.03448951254,
"user": 1.7819261000000002,
"system": 1.9924215399999998,
"min": 3.00094440654,
"max": 3.14645977954,
"times": [
3.04680455354,
3.01139627354,
3.07135411654,
3.00393489554,
3.00094440654,
3.01628468454,
3.0484653705399998,
3.06891716654,
3.14645977954,
3.02217447154
]
},
{
"command": "pnpr@HEAD",
"mean": 0.67191323914,
"stddev": 0.011303833656045908,
"median": 0.6662538255400001,
"user": 0.35366909999999996,
"system": 1.3043770399999999,
"min": 0.6598595605400001,
"max": 0.6901533965400001,
"times": [
0.6901533965400001,
0.6598595605400001,
0.67496711754,
0.6641003265400001,
0.66656380554,
0.6643841825400001,
0.6891541215400001,
0.66242630954,
0.6659438455400001,
0.6815797255400001
]
},
{
"command": "pnpr@main",
"mean": 0.6481859902400001,
"stddev": 0.007139680778895593,
"median": 0.6487484320400001,
"user": 0.32335749999999996,
"system": 1.28341444,
"min": 0.6384441255400001,
"max": 0.6591124475400001,
"times": [
0.6556060595400001,
0.6384441255400001,
0.64904457954,
0.64085988254,
0.6560930205400001,
0.6494794525400001,
0.6436930005400001,
0.64107504954,
0.64845228454,
0.6591124475400001
]
}
]
} |
|
| Branch | pr/12419 |
| Testbed | pacquet |
Click to view all benchmark results
| Benchmark | Latency | Benchmark Result milliseconds (ms) (Result Δ%) | Upper Boundary milliseconds (ms) (Limit %) |
|---|---|---|---|
| isolated-linker.fresh-install.cold-cache.cold-store | 📈 view plot 🚷 view threshold | 4,219.94 ms(+1.13%)Baseline: 4,172.95 ms | 5,007.54 ms (84.27%) |
| isolated-linker.fresh-install.cold-cache.hot-store | 📈 view plot 🚷 view threshold | 3,015.73 ms(+0.76%)Baseline: 2,992.85 ms | 3,591.42 ms (83.97%) |
| isolated-linker.fresh-install.hot-cache.hot-store | 📈 view plot 🚷 view threshold | 1,354.48 ms(+2.96%)Baseline: 1,315.54 ms | 1,578.65 ms (85.80%) |
| isolated-linker.fresh-restore.cold-cache.cold-store | 📈 view plot 🚷 view threshold | 4,198.57 ms(+5.72%)Baseline: 3,971.44 ms | 4,765.72 ms (88.10%) |
| isolated-linker.fresh-restore.hot-cache.hot-store | 📈 view plot 🚷 view threshold | 639.82 ms(+2.97%)Baseline: 621.36 ms | 745.63 ms (85.81%) |
|
| Branch | pr/12419 |
| 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 | 2,152.11 ms |
| isolated-linker.fresh-install.cold-cache.hot-store | 📈 view plot | 671.91 ms |
| isolated-linker.fresh-install.hot-cache.hot-store | 📈 view plot | 652.03 ms |
| isolated-linker.fresh-restore.cold-cache.cold-store | 📈 view plot | 2,204.78 ms |
| isolated-linker.fresh-restore.hot-cache.hot-store | 📈 view plot | 702.88 ms |
|
Code review by qodo was updated up to the latest commit 1a30cc7 |
1a30cc7 to
71099b0
Compare
|
Code review by qodo was updated up to the latest commit 71099b0 |
71099b0 to
64085fb
Compare
|
Code review by qodo was updated up to the latest commit 64085fb |
- port the virtual-store sweep from pnpm's `prune` so a `.pacquet` slot the wanted lockfile no longer references is removed on install (the isolated linker previously never pruned; only the hoisted linker removed orphans) - gate it with pnpm's `pruneVirtualStore` throttle (`enableGlobalVirtualStore`, `modulesCacheMaxAge`, `prunedAt`); record `prunedAt` only when a sweep runs or on first install, so the throttle can actually fire (it was previously stamped every install) - keep `lock.yaml` (the current lockfile) out of the sweep: pacquet's current-lockfile write is conditional, so deleting it could orphan it - match pnpm's `cacheExpired` NaN semantics (unparseable `prunedAt` is treated as not-expired, so the prune is skipped rather than forced) - add unit coverage for the sweep + throttle and an install-path regression test Refs pnpm#11633 (Rust roadmap, Stage 1 Tier 4). Ports installing/linking/modules-cleaner/src/prune.ts and the gate in installing/deps-installer/src/install/index.ts.
The throttle decision (`should_prune_virtual_store`) and the actual sweep can disagree: the sweep is skipped when there is no wanted lockfile to derive the needed set from (e.g. `config.lockfile == false` leaves both `fresh_lockfile` and a loaded `lockfile` absent). Stamping `prunedAt` off the decision instead of the action advanced the timestamp without pruning, throttling the next real sweep off for `modulesCacheMaxAge`. Track `did_prune` (decision AND a sweep actually ran) and stamp `prunedAt` off that. Found in PR review.
- Refuse to prune when the virtual store resolves outside the project node_modules. virtualStoreDir can come from repo-controlled workspace config, so the sweep now canonicalizes the path and requires a strict descendant of modules_dir, skipping (with a warning) otherwise, to avoid destructive deletes outside the managed tree. - Gate the global-store skip on path equality with the resolved global virtual store, not the enableGlobalVirtualStore flag alone, so a virtualStoreDir pointed at the shared global store is never pruned. - prune_virtual_store now returns Option: prunedAt is stamped only when the store was actually enumerated, not when read_dir failed, so a transient failure no longer throttles the next real sweep. Also fix the install test for main new catalogs_override field, allow the assembled build_modules_manifest argument count, and a spell-check typo (unparseable -> unparsable).
Address the remaining review findings on the virtual-store sweep: - TOCTOU: `prune_target_within_modules` now returns the canonicalized prune target, and the sweep enumerates/deletes from that path instead of the raw configured one. Validating one path and operating on the original (still-symlinkable) path left a time-of-check/time-of-use gap. - Removed-count accuracy: `try_remove_pkg` returns whether the entry is gone, and the sweep only counts entries it actually removed rather than every attempt (a swallowed removal error no longer inflates the count). - Rename `same_dir`'s single-letter params to satisfy the dylint Perfectionist `single-letter-function-param` lint that was rejecting the branch on push. Also restore the `dry_run` field in two install test initializers added by this branch, which stopped compiling after rebasing onto a base that introduced the field.
The new prune_virtual_store module split its std imports across several
`use std::...` lines, which the dylint Perfectionist `import-granularity`
lint rejects. Merge them into a single `use std::{...}` statement,
matching the rest of the crate. This was masked on the first push by the
single-letter-param lint aborting compilation first.
`let a = ...` in the same_dir test tripped the dylint Perfectionist `single-letter-let-binding` lint. Rename it to `store`.
64085fb to
e67ebbc
Compare
e67ebbc to
2d5d421
Compare
2d5d421 to
e67ebbc
Compare
|
Code review by qodo was updated up to the latest commit e67ebbc |
`prune_target_within_modules` returned the raw `virtual_store_dir` in the `NotFound` branch without a containment check, so a repo-configured `virtualStoreDir` pointing outside `node_modules` that was merely absent at check time could be created/swapped in mid-install and have its contents swept. Resolve missing paths through their nearest existing ancestor and apply the same strict-descendant check, refusing any path that can't be proven to land inside `node_modules`. Also disambiguate the `crate::link_hoisted_modules` intra-doc link to the function form, which `cargo doc --document-private-items -D warnings` (the CI Doc job) rejected as ambiguous between the function and module.
|
Code review by qodo was updated up to the latest commit 085f1f6 |
Ports the virtual-store sweep from pnpm's
pruneto pacquet's isolated linker.After an install,
node_modules/.pnpm(pacquet:.pacquet) entries the wantedlockfile no longer references are removed, instead of accumulating across branch
switches and downgrades. Before this, only the hoisted linker removed orphans
(
remove_orphans); the default isolated linker never pruned its virtual store.prune_virtual_store: needed set =node_modules+ onedepPathToFilenameper non-skipped snapshot key; readdir the virtual store;rimraf the rest. Mirrors
prune.tsL180-190.should_prune_virtual_storemirrors thepruneVirtualStoregate(
index.tsL471-473) andcacheExpired(L1180-1182): skip under the globalvirtual store; otherwise prune unless
prunedAtis withinmodulesCacheMaxAge.An unparseable
prunedAtis treated as not-expired, matching pnpm'sNaN > maxAge == false.prunedAtlifecycle — now stamped only when a sweep ran or on first install,else the prior value is preserved (
index.tsL1828). Pacquet previously stampedit every install, which would have wedged the throttle off.
Notable deviation
The sweep keeps
lock.yaml(the current lockfile), whereas upstream deletes it andunconditionally rewrites it. Pacquet's current-lockfile write is conditional
(skipped when
config.lockfileis off), so deleting it in the sweep could orphanit. Preserving it is end-state-equivalent whenever the rewrite runs and strictly
safer when it doesn't. Making pacquet's current-lockfile write unconditional (full
parity) is a separate, pre-existing concern.
Scope
Only the virtual-store sweep slice of
prune(). Deferred (other roadmap items /follow-ups): changed-direct-dep removal, the subset-importer orphan calculation,
and the
pnpm:statsremovedcount +pnpm:removaldebug channel.Tests
lock.yaml; removes surplus dir and skippedsnapshot; missing-dir no-op) and throttle (both directions; empty/unparseable/
future timestamps; global-store exclusion).
.pacquetdir asserts thedir is swept while the installed package's slot survives. Confirmed it fails when
the wiring is disabled.
Refs #11633 (Rust roadmap, Stage 1 Tier 4).
Written by an agent (Claude Code, claude-fable-5).
Summary by CodeRabbit
Summary by CodeRabbit
New Features
prunedAttimestamp, preserving any previous value when pruning doesn’t run.Bug Fixes
node_modulesarea.Tests