Skip to content

fix(store): remove the metadata cache on store prune - #17253

Merged
zkochan merged 2 commits into
mainfrom
fix-store-prune-metadata-cache
Oct 23, 2026
Merged

zkochan merged 2 commits into
mainfrom
fix-store-prune-metadata-cache

Conversation

@zkochan

@zkochan zkochan commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Summary

In v12, pnpm store prune pruned the dlx cache, the global virtual store, and the content-addressable store, but it left the registry metadata cache in place. v11 removes that cache (pnpm11/store/controller/src/storeController/prune.ts), and the ERR_PNPM_TARBALL_INTEGRITY advice in pnpm/docs/errors.md relies on it.

With this PR, v12 removes <cacheDir>/metadata* and <cacheDir>/vN/metadata*. That covers every mirror root v12 writes (v12/metadata, v12/metadata-full, v12/metadata-full-filtered, v12/metadata-private), the v11/ legacy roots, and older top-level metadata* dirs. It runs between the GVS and CAS passes, under the exclusive store prune lock, which every install holds shared for its whole run. It prints v11's "Removed all cached metadata files". The v12 CAS prune already cleared <storeDir>/tmp (remove_tmp, which keeps private installs that are still held).

Deliberate differences from v11:

  • Narrower deletion. v11 deletes every vN directory under cacheDir whole. In v12 that would also remove v11/cargo-index, v11/tarball-resolutions, and v11/runtime-shasums, so only the metadata* children of vN are removed.
  • Protected dirs. A matching directory is kept if it is, or contains, the store, globalDir, the global packages or bin dir, the pnpm home, or the state dir. cacheDir can come from a project's pnpm-workspace.yaml. v11 has no such guard: with cacheDir set to the store's parent, v11 would rimraf the store's v11 dir. That v11 hazard should be fixed separately. The coordinator is tracking it.
  • Symlinks are kept. v11's Dirent.isDirectory() filter also keeps them.

Out of scope: v11 also prunes stale download-*/tarball-* spill directories (#16620). Only v11 creates those directories.

Part of pnpm/tasks#191

Squash Commit Body

`pnpm store prune` pruned the dlx cache, the global virtual store, and the
content-addressable store, but left the registry metadata cache in place.
The `ERR_PNPM_TARBALL_INTEGRITY` advice in the errors docs ("run pnpm store
prune") relies on prune clearing that cache, so a stale integrity
checksum stayed after following it.

pnpm v11 removes the cacheDir entries named `metadata*` or `vN` and
`<storeDir>/tmp`, and logs "Removed all cached metadata files"
(pnpm11/store/controller/src/storeController/prune.ts). The store's tmp
dir was already cleared by the v12 CAS prune.

`StoreDir::prune` now takes the cache directory and a list of protected
directories. Between the global virtual store and CAS passes, in v11's
order, it removes `<cacheDir>/metadata*` and `<cacheDir>/vN/metadata*`
and prints v11's message. That covers every mirror root v12 writes
(`v12/metadata`, `metadata-full`, `metadata-full-filtered`,
`metadata-private`), the `v11/` legacy roots, and older top-level ones.
Unlike v11 it keeps the rest of each `vN` directory (cargo index,
tarball resolutions, runtime shasums), and it keeps any matching
directory that is or holds the store, globalDir, the global packages and
bin dirs, the pnpm home, or the state dir, since a project's
pnpm-workspace.yaml can point cacheDir at a broad directory. Symbolic
links are kept, as v11's directory filter keeps them.

It runs under the exclusive store prune lock, which every install holds
shared for its whole run, so no concurrent install reads the cache
while it goes.

Tested by unit tests for the name filter, symlinks, an enclosing store,
cacheDir == globalDir, and a home-like cacheDir, and by CLI e2e tests
that install a package and prune, and that keep a pnpm home placed
inside cacheDir.

Part of pnpm/tasks#191.

Checklist

  • New features are implemented only in the Rust pnpm v12 CLI. Bug fixes
    are implemented in every affected version. (v12-only bug, v11 already clears the cache.)
  • Added a changeset (pnpm changeset) if this PR changes any published
    package. Keep it short and written for pnpm users — it becomes a release note.
  • Added or updated tests. (pnpm-store-dir prune_cached_metadata::tests, pnpm-cli store::store_prune_removes_the_metadata_cache and store::store_prune_keeps_the_pnpm_home_inside_the_cache_dir. Each failed with its fix or guard disabled.)
  • Updated the documentation if needed.

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

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • pnpm store prune now removes cached metadata directories, including those in versioned cache folders, while retaining unrelated caches and protected global packages.
    • Removing cached metadata clears outdated integrity checksums that can cause ERR_PNPM_TARBALL_INTEGRITY errors after a registry republishes a package version.
    • The next install downloads the metadata again.
  • Documentation
    • Updated the store pruning guide to describe what is removed and retained.

@coderabbitai

coderabbitai Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
📥 Commits

Reviewing files that changed from the base of the PR and between 52dce0f and cebbe95.

📒 Files selected for processing: 10
  • .changeset/store-prune-removes-metadata-cache.md
  • pnpm/crates/cli/src/cli_args/store.rs
  • pnpm/crates/cli/tests/suite/store.rs
  • pnpm/crates/store-dir/src/lib.rs
  • pnpm/crates/store-dir/src/loader_references/tests.rs
  • pnpm/crates/store-dir/src/prune.rs
  • pnpm/crates/store-dir/src/prune/tests.rs
  • pnpm/crates/store-dir/src/prune_cached_metadata.rs
  • pnpm/crates/store-dir/src/prune_cached_metadata/tests.rs
  • pnpm/docs/cli/store.md

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.

📝 Walkthrough

pnpm store prune now removes eligible metadata* directories from the cache, including those inside versioned cache directories. It preserves protected paths, retains other cache entries, and reports cache-reading or removal errors.

Changes: Cached metadata pruning

Layer / File(s) Summary
Store pruning and metadata removal
pnpm/crates/store-dir/src/prune.rs, pnpm/crates/store-dir/src/prune_cached_metadata.rs, pnpm/crates/store-dir/src/prune_cached_metadata/tests.rs, pnpm/crates/store-dir/src/prune/tests.rs, pnpm/crates/store-dir/src/loader_references/tests.rs, pnpm/crates/store-dir/src/lib.rs
StoreDir::prune now accepts a cache directory and protected paths. It removes eligible metadata directories at the cache root and inside versioned directories, while preserving candidates that contain protected paths. Tests cover removal, preservation, missing caches, and existing prune behavior.
CLI integration and documentation
pnpm/crates/cli/src/cli_args/store.rs, pnpm/crates/cli/tests/suite/store.rs, pnpm/docs/cli/store.md, .changeset/store-prune-removes-metadata-cache.md
The CLI passes global directories, the default pnpm home, and the state directory as protected paths. Tests check metadata removal and global package preservation. The documentation and changeset describe the cache cleanup.

Priority: ➖ Normal

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

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant CLI as store prune CLI
  participant StoreDir
  participant CacheFS as Cache filesystem
  CLI->>CLI: Clean expired dlx cache entries
  CLI->>StoreDir: prune(cacheDir, protectedDirs)
  StoreDir->>CacheFS: Enumerate metadata directories
  CacheFS-->>StoreDir: Return candidate paths
  StoreDir->>CacheFS: Remove unprotected metadata directories
Loading

Possibly related issues

  • pnpm/pnpm issue 17198: This change removes cached registry metadata through store prune, but does not change pnpm dedupe --check behavior.
  • pnpm/pnpm issue 17208: This change provides manual removal of stale cached metadata, but does not add online revalidation.

Suggested labels: product: pacquet

Suggested reviewers: altaywtf, tunglambk

Merge Risk: ⚪ Minimal · up to cebbe

The reviewed metadata-cache cleanup is mergeable after normal checks; no actionable issue remains.

✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Micro-Benchmark Results

Linux

group                                            main                                    pr
-----                                            ----                                    --
lockfile/parse_pnpm_lock                         1.28     20.4±6.54ms    18.4 MB/sec     1.00     16.0±1.53ms    23.5 MB/sec
packument/parse                                  1.00     45.5±3.42µs  1458.1 MB/sec     1.00     45.5±2.19µs  1456.7 MB/sec
tarball/download_dependency                      1.32  1112.6±212.94µs     3.8 MB/sec    1.00   841.7±91.86µs     5.0 MB/sec
tarball_batch/cold_store_many_medium_tarballs    1.03   254.5±21.62ms 62.9 KElem/sec     1.00   246.5±11.62ms 64.9 KElem/sec
version_pick/repeated_ranges_file                1.11      5.8±0.76ms  5.4 KElem/sec     1.00      5.2±0.50ms  6.0 KElem/sec
version_pick/repeated_ranges_raw                 1.09      5.6±0.60ms  5.6 KElem/sec     1.00      5.1±0.42ms  6.1 KElem/sec
workspace_resolution/hoist_heavy                 1.09   856.0±84.22ms        ? ?/sec     1.00  783.0±158.40ms        ? ?/sec
workspace_sort/chained_projects                  1.00     32.8±9.03ms        ? ?/sec     1.33     43.7±9.64ms        ? ?/sec

@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Same-run regression check

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

Scenario Engine main median HEAD median Change Tolerance Result
isolated-fresh-restore-cold-cache-cold-store pacquet 2949.57 ms 3067.89 ms 4.0% 147.48 ms Within tolerance
isolated-fresh-restore-cold-cache-cold-store pnpr 1511.34 ms 1479.81 ms -2.1% 75.57 ms Within tolerance
isolated-fresh-restore-hot-cache-hot-store pacquet 472.87 ms 511.00 ms 8.1% 23.64 ms Inconclusive (overlapping samples)
isolated-fresh-restore-hot-cache-hot-store pnpr 414.89 ms 558.29 ms 34.6% 20.74 ms Inconclusive (overlapping samples)
isolated-repeat-install-hot-cache-hot-store pacquet 16.58 ms 19.00 ms 14.6% 2.00 ms Inconclusive (overlapping samples)
isolated-repeat-install-hot-cache-hot-store pnpr 18.36 ms 21.15 ms 15.2% 2.00 ms Inconclusive (overlapping samples)
isolated-repeat-install-cold-cache-hot-store pacquet 12.26 ms 12.47 ms 1.7% 2.00 ms Within tolerance
isolated-repeat-install-cold-cache-hot-store pnpr 12.03 ms 12.71 ms 5.6% 2.00 ms Within tolerance
isolated-fresh-install-cold-cache-cold-store pacquet 2637.51 ms 2765.18 ms 4.8% 131.88 ms Within tolerance
isolated-fresh-install-cold-cache-cold-store pnpr 1497.91 ms 1578.28 ms 5.4% 74.90 ms Inconclusive (overlapping samples)
isolated-fresh-install-hot-cache-hot-store pacquet 975.57 ms 930.74 ms -4.6% 48.78 ms Within tolerance
isolated-fresh-install-hot-cache-hot-store pnpr 533.25 ms 562.77 ms 5.5% 26.66 ms Inconclusive (overlapping samples)
isolated-fresh-install-cold-cache-hot-store pacquet 1760.56 ms 1923.26 ms 9.2% 88.03 ms Inconclusive (overlapping samples)
isolated-fresh-install-cold-cache-hot-store pnpr 379.96 ms 352.92 ms -7.1% 19.00 ms Within tolerance
isolated-fresh-resolve-hot-cache-offline pacquet 404.37 ms 460.93 ms 14.0% 20.22 ms Inconclusive (overlapping samples)
isolated-fresh-resolve-hot-cache-offline pnpr 111.98 ms 124.83 ms 11.5% 5.60 ms Inconclusive (overlapping samples)
isolated-peer-heavy-resolve-hot-cache-offline pacquet 328.64 ms 326.35 ms -0.7% 16.43 ms Within tolerance
isolated-linked-workspace-resolve-hot-cache-offline pacquet 127.05 ms 126.49 ms -0.4% 6.35 ms Within tolerance
isolated-injected-workspace-repeat-install-hot-cache-hot-store pacquet 114.86 ms 110.17 ms -4.1% 5.74 ms Within tolerance
isolated-fresh-restore-cold-cache-cold-store-cold-pnpr pacquet 4899.27 ms 4864.89 ms -0.7% 244.96 ms Within tolerance
isolated-fresh-restore-cold-cache-cold-store-cold-pnpr pnpr 3846.97 ms 3691.33 ms -4.0% 192.35 ms Within tolerance
gvs-fresh-restore-hot-cache-hot-store pacquet 185.69 ms 190.52 ms 2.6% 9.28 ms Within tolerance
gvs-fresh-restore-hot-cache-hot-store pnpr 193.13 ms 217.78 ms 12.8% 9.66 ms Inconclusive (overlapping samples)
store-only-unlocked-direct-deps-cold-cache-hot-store pacquet 1398.30 ms 1417.76 ms 1.4% 69.92 ms Within tolerance
cargo-repeat-install-hot-cache-hot-store pacquet 36.24 ms 43.55 ms 20.2% 2.00 ms Inconclusive (overlapping samples)

Integrated-Benchmark Report (Linux)

Commit: cebbe95f7ff3

Regular scenarios report direct and pnpr installs. The peer-heavy resolver scenario compares current Rust, main Rust, and TypeScript pnpm; the linked, injected, and Cargo workspace scenarios compare 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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 3.029 ± 0.130 2.807 3.191 2.00 ± 0.17
pacquet@main 2.932 ± 0.106 2.726 3.081 1.93 ± 0.16
pnpr@HEAD 1.516 ± 0.112 1.402 1.724 1.00
pnpr@main 1.525 ± 0.062 1.423 1.622 1.01 ± 0.08
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 3.0293298080200004,
      "stddev": 0.1299144917602499,
      "median": 3.06788970632,
      "user": 3.08303908,
      "system": 2.31800026,
      "min": 2.80692136732,
      "max": 3.19101561832
    },
    {
      "command": "pacquet@main",
      "mean": 2.9315546185200003,
      "stddev": 0.10630069414593406,
      "median": 2.94956541132,
      "user": 2.99551308,
      "system": 2.17347786,
      "min": 2.72649647732,
      "max": 3.08110114432
    },
    {
      "command": "pnpr@HEAD",
      "mean": 1.51642810952,
      "stddev": 0.11222360579836917,
      "median": 1.47981026232,
      "user": 2.09624498,
      "system": 1.6752619599999996,
      "min": 1.40171443932,
      "max": 1.72400192232
    },
    {
      "command": "pnpr@main",
      "mean": 1.52490277132,
      "stddev": 0.062157109583546984,
      "median": 1.51133798332,
      "user": 2.23588868,
      "system": 1.7754386600000003,
      "min": 1.42322777532,
      "max": 1.62232125332
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 505.4 ± 35.2 415.1 538.0 1.16 ± 0.15
pacquet@main 461.7 ± 41.8 389.1 513.8 1.06 ± 0.15
pnpr@HEAD 572.0 ± 94.6 454.8 751.7 1.31 ± 0.26
pnpr@main 436.7 ± 46.0 374.1 497.0 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.50542029686,
      "stddev": 0.03520247933584032,
      "median": 0.5109998197600001,
      "user": 0.5752364600000001,
      "system": 0.9756714399999998,
      "min": 0.41514255876000006,
      "max": 0.53798750976
    },
    {
      "command": "pacquet@main",
      "mean": 0.46166768786000006,
      "stddev": 0.041762255146050996,
      "median": 0.47287191326000005,
      "user": 0.5492056599999999,
      "system": 0.9199839400000001,
      "min": 0.38905394276000005,
      "max": 0.5138372047599999
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.57195856766,
      "stddev": 0.09460702536414217,
      "median": 0.55828581576,
      "user": 0.6583496600000002,
      "system": 1.07113604,
      "min": 0.45480672976000003,
      "max": 0.7517068207600001
    },
    {
      "command": "pnpr@main",
      "mean": 0.4366705207599999,
      "stddev": 0.046010541673207006,
      "median": 0.41488634226000004,
      "user": 0.49656986,
      "system": 0.8682637400000001,
      "min": 0.37414335776,
      "max": 0.49702582976000004
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 19.5 ± 3.5 14.1 34.0 1.16 ± 0.25
pacquet@main 16.8 ± 2.1 12.1 24.7 1.00
pnpr@HEAD 23.3 ± 6.7 13.4 41.4 1.39 ± 0.43
pnpr@main 18.7 ± 2.5 13.8 28.1 1.11 ± 0.20
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.01945977086675676,
      "stddev": 0.0035006386881920953,
      "median": 0.018999698860000004,
      "user": 0.010359098378378378,
      "system": 0.010293298108108107,
      "min": 0.014113843360000001,
      "max": 0.034032655360000004
    },
    {
      "command": "pacquet@main",
      "mean": 0.01675899310375001,
      "stddev": 0.0020505868432995657,
      "median": 0.01658402436,
      "user": 0.0099932075,
      "system": 0.008141125,
      "min": 0.01214079136,
      "max": 0.024651289360000002
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.023263722882727256,
      "stddev": 0.006671399774051921,
      "median": 0.021152160860000005,
      "user": 0.012548685909090902,
      "system": 0.011657059772727274,
      "min": 0.01335414836,
      "max": 0.041397316360000005
    },
    {
      "command": "pnpr@main",
      "mean": 0.01867649124068182,
      "stddev": 0.002501439934035699,
      "median": 0.018357054360000003,
      "user": 0.010140401818181813,
      "system": 0.01010905511363636,
      "min": 0.013765129360000001,
      "max": 0.02812237236
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 13.4 ± 3.2 9.7 27.2 1.06 ± 0.31
pacquet@main 12.7 ± 2.4 9.3 24.0 1.01 ± 0.25
pnpr@HEAD 13.5 ± 3.2 8.6 26.4 1.07 ± 0.31
pnpr@main 12.6 ± 2.0 9.6 20.5 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.013366339901086969,
      "stddev": 0.0032040556781351625,
      "median": 0.0124695942,
      "user": 0.007720194347826084,
      "system": 0.006809384239130434,
      "min": 0.009724089200000001,
      "max": 0.0272139072
    },
    {
      "command": "pacquet@main",
      "mean": 0.012685317341509432,
      "stddev": 0.0023675271996220965,
      "median": 0.012258216200000002,
      "user": 0.00761217773584906,
      "system": 0.0062409126415094345,
      "min": 0.009288239200000001,
      "max": 0.0239920952
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.013534903786956516,
      "stddev": 0.003249963545089688,
      "median": 0.0127101422,
      "user": 0.007356883804347825,
      "system": 0.007449598586956519,
      "min": 0.008573663200000001,
      "max": 0.0264127402
    },
    {
      "command": "pnpr@main",
      "mean": 0.012618076022335025,
      "stddev": 0.0020346881246050916,
      "median": 0.0120327612,
      "user": 0.007093713604060909,
      "system": 0.0066740264974619315,
      "min": 0.0096088622,
      "max": 0.0205073172
    }
  ]
}

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 2.850 ± 0.250 2.671 3.507 1.83 ± 0.22
pacquet@main 2.637 ± 0.061 2.554 2.749 1.70 ± 0.15
pnpr@HEAD 1.573 ± 0.106 1.443 1.748 1.01 ± 0.11
pnpr@main 1.554 ± 0.133 1.454 1.836 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 2.85026136364,
      "stddev": 0.2501089489420422,
      "median": 2.7651756072399998,
      "user": 3.1647260399999997,
      "system": 2.22037842,
      "min": 2.67084599174,
      "max": 3.50717209474
    },
    {
      "command": "pacquet@main",
      "mean": 2.63732796584,
      "stddev": 0.06076445792969171,
      "median": 2.63750952474,
      "user": 2.7316967400000003,
      "system": 1.8228552199999999,
      "min": 2.5542216287399997,
      "max": 2.74949168374
    },
    {
      "command": "pnpr@HEAD",
      "mean": 1.5725088004399999,
      "stddev": 0.10622770452508204,
      "median": 1.57827732174,
      "user": 1.76136144,
      "system": 1.4683592199999995,
      "min": 1.4426481467399999,
      "max": 1.74776912874
    },
    {
      "command": "pnpr@main",
      "mean": 1.55357557234,
      "stddev": 0.13262035895208357,
      "median": 1.49791069174,
      "user": 1.7831385400000002,
      "system": 1.37279712,
      "min": 1.45399705274,
      "max": 1.83594153774
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 930.8 ± 55.1 848.3 1022.9 1.75 ± 0.16
pacquet@main 976.5 ± 105.4 830.7 1211.4 1.83 ± 0.23
pnpr@HEAD 564.4 ± 60.1 491.2 702.7 1.06 ± 0.13
pnpr@main 532.9 ± 35.4 469.8 605.5 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.9307658013600001,
      "stddev": 0.055051567402239314,
      "median": 0.9307408321600001,
      "user": 1.37030444,
      "system": 1.3260769199999998,
      "min": 0.84832350916,
      "max": 1.02288162016
    },
    {
      "command": "pacquet@main",
      "mean": 0.9764677702600002,
      "stddev": 0.10535302654126079,
      "median": 0.9755737961600001,
      "user": 1.41010954,
      "system": 1.3829617200000002,
      "min": 0.83074008716,
      "max": 1.21136084316
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.5644215911599999,
      "stddev": 0.06009993536085395,
      "median": 0.5627704061600001,
      "user": 0.53517334,
      "system": 0.9870534199999998,
      "min": 0.49117729016,
      "max": 0.70268328416
    },
    {
      "command": "pnpr@main",
      "mean": 0.53294492506,
      "stddev": 0.03537300080584809,
      "median": 0.5332472446600001,
      "user": 0.53047144,
      "system": 0.99902132,
      "min": 0.46984104216,
      "max": 0.6055216611600001
    }
  ]
}

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 1.921 ± 0.078 1.795 2.021 5.47 ± 0.26
pacquet@main 1.792 ± 0.076 1.689 1.884 5.11 ± 0.25
pnpr@HEAD 0.351 ± 0.009 0.334 0.361 1.00
pnpr@main 0.375 ± 0.023 0.345 0.418 1.07 ± 0.07
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 1.92092838642,
      "stddev": 0.07772700121167013,
      "median": 1.92325827862,
      "user": 1.43777482,
      "system": 1.2157185399999997,
      "min": 1.7947952441200001,
      "max": 2.02112969112
    },
    {
      "command": "pacquet@main",
      "mean": 1.7924380092200003,
      "stddev": 0.0757745469005123,
      "median": 1.76056478962,
      "user": 1.21850142,
      "system": 1.14944824,
      "min": 1.68904682312,
      "max": 1.8838086041200002
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.3509092376200001,
      "stddev": 0.008978626370839491,
      "median": 0.35291513712000006,
      "user": 0.31925351999999996,
      "system": 0.66367754,
      "min": 0.33390655812000003,
      "max": 0.36095482412
    },
    {
      "command": "pnpr@main",
      "mean": 0.37520579072000004,
      "stddev": 0.0227006269273845,
      "median": 0.37995533512,
      "user": 0.34688532000000005,
      "system": 0.71424234,
      "min": 0.34482953012000006,
      "max": 0.41774823012000006
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 459.9 ± 55.7 388.6 542.9 4.05 ± 0.56
pacquet@main 404.6 ± 28.3 368.8 448.4 3.56 ± 0.34
pnpr@HEAD 123.0 ± 6.2 113.4 136.3 1.08 ± 0.09
pnpr@main 113.6 ± 7.4 101.8 127.4 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.45993975396,
      "stddev": 0.05568899225731956,
      "median": 0.46093319266,
      "user": 0.48402938000000006,
      "system": 0.18208400000000002,
      "min": 0.38860219216,
      "max": 0.5429037281600001
    },
    {
      "command": "pacquet@main",
      "mean": 0.40462388996000004,
      "stddev": 0.028342063640944645,
      "median": 0.4043659176600001,
      "user": 0.42432818,
      "system": 0.1614329,
      "min": 0.36875493216000005,
      "max": 0.44835300016000007
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.12296111940999999,
      "stddev": 0.006247037153796726,
      "median": 0.12483485166,
      "user": 0.05265363000000001,
      "system": 0.029207300000000002,
      "min": 0.11344584016,
      "max": 0.13633044216
    },
    {
      "command": "pnpr@main",
      "mean": 0.11359513564,
      "stddev": 0.007353572066836607,
      "median": 0.11198337916000001,
      "user": 0.05132156000000001,
      "system": 0.020767839999999996,
      "min": 0.10182236316000001,
      "max": 0.12737647816
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 323.3 ± 18.4 295.7 352.2 1.00
pacquet@main 325.9 ± 13.2 302.0 343.5 1.01 ± 0.07
pnpm@HEAD 5019.2 ± 96.5 4848.3 5120.8 15.52 ± 0.93
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.3233105391466667,
      "stddev": 0.018424971507684143,
      "median": 0.32634599048,
      "user": 0.34728140888888887,
      "system": 0.06845962222222221,
      "min": 0.29571873348000005,
      "max": 0.35221640648
    },
    {
      "command": "pacquet@main",
      "mean": 0.32593961025777785,
      "stddev": 0.013175417702341293,
      "median": 0.32863993048,
      "user": 0.3452846311111111,
      "system": 0.06910662222222222,
      "min": 0.30204900348,
      "max": 0.34346560648
    },
    {
      "command": "pnpm@HEAD",
      "mean": 5.019157826146666,
      "stddev": 0.09653686931328247,
      "median": 5.08152610148,
      "user": 8.021426853333331,
      "system": 0.5679474,
      "min": 4.8482840954799995,
      "max": 5.12078076548
    }
  ]
}

Scenario: Isolated linker: linked-workspace resolve, hot cache, offline

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 128.1 ± 10.0 113.7 152.8 1.01 ± 0.11
pacquet@main 127.4 ± 10.0 113.1 146.7 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.12809899965333335,
      "stddev": 0.00997620935183826,
      "median": 0.12648985832,
      "user": 0.11918090833333332,
      "system": 0.06427482333333333,
      "min": 0.11365152832,
      "max": 0.15277984032
    },
    {
      "command": "pacquet@main",
      "mean": 0.12741097414608699,
      "stddev": 0.00996940867881025,
      "median": 0.12705299732,
      "user": 0.11809337391304349,
      "system": 0.06313369652173913,
      "min": 0.11314598932,
      "max": 0.14670519932
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 110.0 ± 5.7 100.3 122.5 1.00
pacquet@main 113.9 ± 5.4 104.4 123.3 1.04 ± 0.07
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.10997300689407412,
      "stddev": 0.005703235718751532,
      "median": 0.11016692482000001,
      "user": 0.04457859407407407,
      "system": 0.07426531333333333,
      "min": 0.10033061582000001,
      "max": 0.12252396182000001
    },
    {
      "command": "pacquet@main",
      "mean": 0.11387411744962964,
      "stddev": 0.0054168044748467,
      "median": 0.11486177182000001,
      "user": 0.046580001481481496,
      "system": 0.07719879481481484,
      "min": 0.10435769882000001,
      "max": 0.12332892182
    }
  ]
}

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 4.890 ± 0.157 4.682 5.175 1.31 ± 0.06
pacquet@main 4.858 ± 0.118 4.683 4.985 1.30 ± 0.05
pnpr@HEAD 3.729 ± 0.113 3.617 3.962 1.00
pnpr@main 3.866 ± 0.142 3.632 4.187 1.04 ± 0.05
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 4.8904500697,
      "stddev": 0.1567411252492298,
      "median": 4.8648944676,
      "user": 2.83717316,
      "system": 2.09191908,
      "min": 4.6817008871,
      "max": 5.1752561171
    },
    {
      "command": "pacquet@main",
      "mean": 4.8583883799,
      "stddev": 0.118096885007434,
      "median": 4.8992658226,
      "user": 2.9758890599999996,
      "system": 2.1138308799999996,
      "min": 4.6830342721,
      "max": 4.984630335099999
    },
    {
      "command": "pnpr@HEAD",
      "mean": 3.7288975671999998,
      "stddev": 0.1130230717196873,
      "median": 3.6913312716,
      "user": 2.3302657599999996,
      "system": 1.82180468,
      "min": 3.6165281321,
      "max": 3.9623729651
    },
    {
      "command": "pnpr@main",
      "mean": 3.866333832299999,
      "stddev": 0.14173084420720866,
      "median": 3.8469731901,
      "user": 2.65262956,
      "system": 2.02353168,
      "min": 3.6320274121000002,
      "max": 4.186871271099999
    }
  ]
}

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. Scenarios run on separate machines, so compare main and branch within each table.

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 219.0 ± 51.2 180.1 304.9 1.15 ± 0.28
pacquet@main 191.4 ± 22.0 175.3 260.8 1.01 ± 0.13
pnpr@HEAD 216.9 ± 12.2 200.8 232.2 1.14 ± 0.10
pnpr@main 190.3 ± 13.0 167.5 209.6 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.21898282936000002,
      "stddev": 0.051178092138463714,
      "median": 0.19051773655999998,
      "user": 0.26963796,
      "system": 0.21878946,
      "min": 0.18013855456,
      "max": 0.30486901956
    },
    {
      "command": "pacquet@main",
      "mean": 0.19142245706,
      "stddev": 0.02196312942139885,
      "median": 0.18569254556,
      "user": 0.2363494028571429,
      "system": 0.1858917457142857,
      "min": 0.17527395556,
      "max": 0.26079250556000005
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.21694205601454541,
      "stddev": 0.012167009055484691,
      "median": 0.21777976156,
      "user": 0.2392070781818182,
      "system": 0.2022154145454545,
      "min": 0.20078146856,
      "max": 0.23222810056
    },
    {
      "command": "pnpr@main",
      "mean": 0.19027268840615383,
      "stddev": 0.012996381875525521,
      "median": 0.19313058455999998,
      "user": 0.21586187538461535,
      "system": 0.18520211384615384,
      "min": 0.16747281156,
      "max": 0.20955608656
    }
  ]
}

Scenario: Store only: unlocked direct deps, cold cache + hot store

Store-only install (enableModulesDir: false, per-file store index, trusted lockfile) against a lockfile missing the direct dependencies that have peers, with the metadata cache wiped per iteration: the install resolves those from the registry, reuses their subtrees from the lockfile and checks the store, linking nothing. Direct installs only.

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 1.410 ± 0.036 1.362 1.479 1.01 ± 0.04
pacquet@main 1.393 ± 0.040 1.326 1.443 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 1.4098280752399999,
      "stddev": 0.036177119381696474,
      "median": 1.41775892304,
      "user": 0.90467944,
      "system": 0.38830909999999996,
      "min": 1.36184555604,
      "max": 1.47947083804
    },
    {
      "command": "pacquet@main",
      "mean": 1.39333343234,
      "stddev": 0.040247558151203684,
      "median": 1.3983008855399999,
      "user": 0.89474924,
      "system": 0.36865629999999994,
      "min": 1.32581774504,
      "max": 1.44290312504
    }
  ]
}

Scenario: Cargo: repeat install, hot cache + hot store

Frozen repeat install of a Cargo workspace (cargo.enabled: true) whose crates are already materialized in <storeDir>/v11/crates/ and linked into .pnpm/crates/crates-io. Direct installs only.

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 43.9 ± 4.2 35.0 59.5 1.17 ± 0.20
pacquet@main 37.5 ± 5.2 31.2 59.5 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.04385842099246377,
      "stddev": 0.004206298098768946,
      "median": 0.04355429192,
      "user": 0.03140666318840579,
      "system": 0.023000888695652165,
      "min": 0.03497183392000001,
      "max": 0.05954968092000001
    },
    {
      "command": "pacquet@main",
      "mean": 0.037519736999365075,
      "stddev": 0.005205106024568882,
      "median": 0.036238886920000005,
      "user": 0.028267230476190463,
      "system": 0.01855316888888889,
      "min": 0.031198148919999998,
      "max": 0.05952875992000001
    }
  ]
}

@codecov-commenter

codecov-commenter commented Oct 22, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.56522% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.54%. Comparing base (30f6d58) to head (cebbe95).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
pnpm/crates/store-dir/src/prune_cached_metadata.rs 92.85% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #17253      +/-   ##
==========================================
- Coverage   92.54%   92.54%   -0.01%     
==========================================
  Files        1864     1865       +1     
  Lines      241552   241634      +82     
==========================================
+ Hits       223550   223618      +68     
- Misses      18002    18016      +14     

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

zkochan and others added 2 commits October 23, 2026 01:50
`pnpm store prune` pruned the dlx cache, the global virtual store, and the
content-addressable store, but left the registry metadata cache in place.
The `ERR_PNPM_TARBALL_INTEGRITY` advice in the errors docs ("run pnpm store
prune") relies on prune clearing that cache, so a stale integrity
checksum stayed after following it.

pnpm v11 removes every directory directly under cacheDir whose name starts
with `metadata` or is a layout version (`vN`), plus `<storeDir>/tmp`, and
logs "Removed all cached metadata files"
(pnpm11/store/controller/src/storeController/prune.ts). The store's tmp dir
was already cleared by the v12 CAS prune.

`StoreDir::prune` now takes the cache directory and removes the same
directories between the global virtual store and CAS passes, in v11's
order, and prints the same message. It runs under the exclusive store
prune lock, which every install holds shared for its whole run, so no
concurrent install reads the cache while it goes. Symbolic links are kept,
as v11's directory filter keeps them, and a `vN` directory that holds the
store itself is kept for a cacheDir that encloses the store.

Tested by unit tests for the name filter, symlinks, and an enclosing
store, and by a CLI e2e test that installs a package, prunes, and checks
the `v12` metadata directory and the log line.

Part of pnpm/tasks#191.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The first version matched v11's filter and removed every `vN` directory
under cacheDir whole. In v12 that also removed the cargo index, the
tarball-resolution cache, and the runtime shasums cache under `v11/`, and
with a cacheDir pointing at a broad directory (a project's
pnpm-workspace.yaml can set it) it could delete global packages or other
pnpm versions' stores.

Prune now removes only `<cacheDir>/metadata*` and `<cacheDir>/vN/metadata*`,
which covers every mirror root v12 writes (`v12/metadata`,
`metadata-full`, `metadata-full-filtered`, `metadata-private`), the
`v11/` legacy roots, and older top-level ones. It also keeps any of those
directories that is or holds the store, globalDir, the global packages
and bin dirs, the pnpm home, or the state dir.

Tested by unit tests for cacheDir == globalDir and a home-like cacheDir,
and a CLI e2e test with the pnpm home inside cacheDir.

Part of pnpm/tasks#191.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@zkochan
zkochan force-pushed the fix-store-prune-metadata-cache branch from 2acb471 to cebbe95 Compare October 22, 2026 23:56
@zkochan
zkochan marked this pull request as ready for review October 23, 2026 00:19
@zkochan

zkochan commented Oct 23, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

Copilot AI balanced review requested due to automatic review settings October 23, 2026 00:19

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Your trial has ended. Reactivate Greptile to resume code reviews.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Clear registry metadata cache during store prune

🐞 Bug fix 🧪 Tests 📝 Documentation 🕐 20-40 Minutes

Grey Divider

AI Description

• Remove stale registry metadata during store prune so outdated integrity checksums do not persist.
• Preserve unrelated caches and protected directories while pruning under the store lock.
• Add unit and CLI coverage, release notes, and command documentation.
Diagram

graph TD
  Command["Store prune"] --> Dlx["Expired dlx"] --> Gvs["Virtual store"] --> Metadata["Metadata cache"] --> Cas["CAS prune"] --> Engines["Private installs"]
  Protected["Protected directories"] -.-> Metadata
Loading
High-Level Assessment

The targeted metadata-only pass is appropriate: it shares the existing exclusive prune lock and preserves other caches in versioned directories. Deleting entire versioned directories, as v11 does, risks removing unrelated caches or protected data; a separate cleanup command would lose the benefit of the existing prune workflow.

Files changed (10) +388 / -30

Bug fix (4) +155 / -19
store.rsPass cache and protected paths to store prune +25/-16

Pass cache and protected paths to store prune

• Extracts the prune command flow into a helper and passes the configured cache directory plus global, home, and state paths to StoreDir::prune. Existing dlx and private-install cleanup retain their order.

pnpm/crates/cli/src/cli_args/store.rs

lib.rsRegister metadata-pruning module +1/-0

Register metadata-pruning module

• Adds the new cached-metadata pruning module to the store-dir crate.

pnpm/crates/store-dir/src/lib.rs

prune.rsRun metadata cleanup within locked store pruning +22/-3

Run metadata cleanup within locked store pruning

• Extends StoreDir::prune to accept cache and protected paths and removes cached metadata between virtual-store and CAS pruning. Adds diagnostics for cache-directory reads and metadata-removal failures.

pnpm/crates/store-dir/src/prune.rs

prune_cached_metadata.rsRemove matching metadata directories safely +107/-0

Remove matching metadata directories safely

• Finds metadata-prefixed directories at the cache root and immediately below numeric version directories, leaving other caches and symlinks intact. Skips directories containing the store or protected paths and reports filesystem errors.

pnpm/crates/store-dir/src/prune_cached_metadata.rs

Tests (4) +223 / -11
store.rsExercise metadata cleanup through the CLI +46/-0

Exercise metadata cleanup through the CLI

• Verifies that pruning removes metadata created by an install and prints the removal message. Also checks that a pnpm home beneath a configured cache directory survives.

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

tests.rsAdapt loader-reference tests to prune arguments +11/-3

Adapt loader-reference tests to prune arguments

• Supplies a cache directory and empty protected-path list to existing loader-reference prune tests.

pnpm/crates/store-dir/src/loader_references/tests.rs

tests.rsUpdate virtual-store prune tests for new signature +24/-8

Update virtual-store prune tests for new signature

• Passes cache and protected-path arguments in existing virtual-store prune tests without changing their assertions.

pnpm/crates/store-dir/src/prune/tests.rs

tests.rsCover metadata selection and preservation rules +142/-0

Cover metadata selection and preservation rules

• Tests versioned and top-level metadata removal, unrelated-cache preservation, protected directories, symlinks, and a missing cache directory.

pnpm/crates/store-dir/src/prune_cached_metadata/tests.rs

Documentation (2) +10 / -0
store-prune-removes-metadata-cache.mdAnnounce metadata-cache pruning +5/-0

Announce metadata-cache pruning

• Adds a patch changeset explaining that store prune clears cached metadata and stale integrity checksums.

.changeset/store-prune-removes-metadata-cache.md

store.mdDocument metadata removal by store prune +5/-0

Document metadata removal by store prune

• Explains which metadata directories are removed, that other caches remain, and that subsequent installs download metadata again.

pnpm/docs/cli/store.md

@qodo-code-review

qodo-code-review Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

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

Grey Divider


Action required

1. Prune can erase files outside the cache 🐞 Bug ⛨ Security
Description
cached_metadata_dirs checks that a versioned child is a directory, then reopens its pathname and
later passes a discovered child to recursive removal without holding that parent directory stable.
If a process able to modify the cache replaces the versioned child with a symlink between those
steps, prune can follow it and remove a metadata* directory outside the configured cache.
Code

pnpm/crates/store-dir/src/prune_cached_metadata.rs[60]

+            let nested = child_dirs(&path)?
Relevance

●●● Strong

Recent store cleanup precedents accept protections against symlinked paths that could delete data
outside the configured store.

PR-#15417

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The directory check and subsequent read use the same pathname at different times. A substituted
parent symlink redirects both the later read and the path-based recursive deletion; the removal
helper protects only the final entry from symlink traversal.

pnpm/crates/store-dir/src/prune_cached_metadata.rs[54-64]
pnpm/crates/store-dir/src/prune_cached_metadata.rs[74-94]
pnpm/crates/store-dir/src/prune_cached_metadata.rs[30-38]
pnpm/crates/fs/src/remove_dirent.rs[23-27]
pnpm/crates/config/src/workspace_yaml/apply.rs[375-376]

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

## Issue description
A versioned cache directory can be replaced with a symlink after enumeration, redirecting metadata discovery and recursive deletion outside the cache.
## Fix Focus Areas
- pnpm/crates/store-dir/src/prune_cached_metadata.rs[54-96]
- pnpm/crates/store-dir/src/prune_cached_metadata.rs[30-38]
## Recommended Fix
Traverse and delete relative to stable opened directory handles without following substituted parent symlinks. Do not rely on a one-time canonicalization check before pathname-based recursive removal; add a test that swaps a versioned parent during prune.

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

Dismiss ↗ | View ↗



Remediation recommended

2. Project installations can be erased 🐞 Bug ≡ Correctness
Description
prune omits the configured modules, install-state or virtual-store, and global virtual-store
directories from protected_dirs, allowing metadata cleanup to treat them as removable cache
directories. When cacheDir contains a metadata* directory holding any of these configured
locations—including a global virtual store outside the content-addressable store—the cleanup can
remove installation files, persisted state, and package links.
Code

pnpm/crates/cli/src/cli_args/store.rs[R77-79]

+        pnpm_home_dir.as_deref(),
+        Some(config.state_dir.as_path()),
+    ]
Relevance

●●● Strong

Recent store-path precedents accept hardening destructive cleanup against configured-directory
containment and symlink hazards.

PR-#15417
PR-#17154

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
Workspace path settings allow the modules and install-state or virtual-store locations within the
cache tree, and the global virtual store is configurable as the effective package-link directory.
None appears in the new protection list, while the scanner recursively removes metadata-named
directories that contain no listed protected path.

pnpm/crates/cli/src/cli_args/store.rs[72-83]
pnpm/crates/config/src/workspace_yaml/apply.rs[158-169]
pnpm/crates/config/src/workspace_yaml/apply.rs[375-376]
pnpm/crates/config/src/layout.rs[35-60]
pnpm/crates/package-manager/src/install/apply_materialization/commit.rs[44-45]
pnpm/crates/store-dir/src/prune_cached_metadata.rs[26-38]
pnpm/crates/store-dir/src/prune_cached_metadata.rs[54-67]
pnpm/crates/config/src/layout.rs[580-593]

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

## Issue description
Metadata cleanup can remove configured project modules, install-state or virtual-store directories, or a global virtual store located beneath a metadata-named cache child.

## Fix Focus Areas
- pnpm/crates/cli/src/cli_args/store.rs[72-83]
- pnpm/crates/store-dir/src/prune_cached_metadata.rs[26-38]

## Recommended Fix
Add the effective modules, install-state or virtual-store, and global virtual-store locations to prune's protected paths, including an explicitly configured global virtual store outside the content-addressable store. Test a workspace where `cacheDir` encloses a metadata-named directory containing each configured installation location.

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

Dismiss ↗ | View ↗


3. The older release lacks matching coverage 📘 Rule violation ⌂ Architecture
Description
The new regression coverage exists only in store_prune_removes_the_metadata_cache, while the
corresponding v11 prune tests cover spill directories and missing stores but do not assert
metadata-cache removal. When the shared prune bug is changed in the Rust path, the missing
equivalent v11 scenario leaves cross-stack behavior and regression protection unverified.
Code

pnpm/crates/cli/tests/suite/store.rs[R677-697]

+#[test]
+fn store_prune_removes_the_metadata_cache() {
+    let CommandTempCwd {
+        root: _root, workspace, npmrc_info, ..
+    } = CommandTempCwd::init().add_mocked_registry();
+    pacquet_at(&workspace)
+        .with_args(["add", "[email protected]"])
+        .assert()
+        .success();
+    let metadata_dir = npmrc_info.cache_dir.join("v12/metadata");
+    assert!(metadata_dir.exists(), "add must cache the metadata it resolved");
+
+    let output = pacquet_at(&workspace)
+        .with_args(["store", "prune"])
+        .output()
+        .expect("run store prune");
+    let stderr = String::from_utf8_lossy(&output.stderr);
+    assert!(output.status.success(), "store prune failed: {stderr}");
+    assert!(stderr.contains("Removed all cached metadata files"), "stderr={stderr}");
+    assert!(!metadata_dir.exists(), "store prune must remove the metadata cache");
+}
Relevance

●●● Strong

Recent compatibility work accepts mirrored v11/v12 regression coverage for shared behavior and
cross-stack observability.

PR-#17183

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The PR adds a Rust CLI test that creates v12/metadata, runs store prune, and asserts the cache
is removed. The existing v11 prune test file contains tests for stale spill directories and missing
stores but no metadata-cache removal scenario, so the shared behavior lacks mirrored regression
coverage.

Rule 713428: Keep pnpm v11 and v12 observable behavior aligned when fixing shared bugs
pnpm/crates/cli/tests/suite/store.rs[677-697]
pnpm11/store/controller/test/prune.ts[1-134]

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 shared metadata-cache pruning behavior has a new Rust test, but no equivalent TypeScript v11 test asserts that `store prune` removes the metadata cache.

## Fix Focus Areas
- pnpm/crates/cli/tests/suite/store.rs[677-697]
- pnpm11/store/controller/test/prune.ts[1-134]

## Recommended Fix
Add or update a v11 prune regression test that creates representative top-level and versioned metadata directories, runs the v11 store-prune path, and asserts those directories are removed while unrelated cache entries remain. Keep the scenario and observable assertions equivalent to the Rust test so either stack's regression is detected.

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

Dismiss ↗ | View ↗


4. Release notes use an invalid colon 📘 Rule violation ✧ Quality
Description
The first sentence in .changeset/store-prune-removes-metadata-cache.md uses a colon to introduce a
clarification on the same line rather than a list or example. This violates the changeset
punctuation convention for the published release note.
Code

.changeset/store-prune-removes-metadata-cache.md[5]

+`pnpm store prune` now removes the package metadata cache, the `metadata*` directories in the cache directory. This clears the outdated integrity checksums that cause `ERR_PNPM_TARBALL_INTEGRITY` when a registry republishes a version.
Relevance

●●● Strong

Recent changeset precedents accept rewriting compound release-note sentences to follow punctuation
and clarity conventions.

PR-#17175
PR-#17181

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The modified changeset contains a colon between package metadata cache and the explanatory phrase
the metadata* directories; it does not introduce a newline list or a concrete example. This fails
the required changeset text formatting convention.

Rule 3058313: Changeset text formatting conventions
.changeset/store-prune-removes-metadata-cache.md[5-5]

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 first changeset sentence uses a colon that does not introduce a list or example.

## Fix Focus Areas
- .changeset/store-prune-removes-metadata-cache.md[5-5]

## Recommended Fix
Rewrite the sentence using a period or a permitted list/example structure, while preserving the user-visible description of `pnpm store prune`.

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

Dismiss ↗ | View ↗


View medium (1)
5. V12 prune change lacks migration guidance 📎 Requirement gap ⚙ Maintainability
Description
The PR updates the store command documentation but does not add a v11-to-v12 migration page
describing the restored metadata-cache pruning behavior. Users upgrading between these release lines
therefore have no dedicated migration guidance for this changed command behavior.
Code

pnpm/docs/cli/store.md[R57-60]

+`pnpm store prune` also removes the package metadata cache: the `metadata*`
+directories in the cache directory and in its versioned subdirectories, such as
+`v12/metadata`. Other caches in the cache directory are kept. The next install
+downloads the metadata again.
Relevance

●● Moderate

Documentation updates are commonly accepted, but no close precedent requires a dedicated v11-to-v12
migration page.

PR-#16422

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The PR adds command-page text describing the changed pruning behavior, while the existing migration
page is explicitly for migrating from v10 and does not describe v11-to-v12 changes. The checklist
requires a migration page collecting deliberate v11-to-v12 behavior changes and corresponding v12
documentation.

Document deliberate v11-to-v12 changes
pnpm/docs/cli/store.md[57-60]
pnpm/docs/migration.md[1-5]

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 user-visible store-prune behavior is documented on the command page, but the required v11-to-v12 migration page is absent.

## Fix Focus Areas
- pnpm/docs/cli/store.md[57-60]
- pnpm/docs/migration.md[1-5]

## Recommended Fix
Add a v11-to-v12 migration page or extend the migration documentation with the restored store-prune metadata-cache behavior, including what is removed and what remains protected, and link or update the affected v12 command documentation as appropriate.

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

Dismiss ↗ | View ↗



Informational

6. Windows users lack prune path coverage 📜 Skill insight ▣ Testability
Description
The metadata-pruning tests cover POSIX-style paths and symlinks but contain no Windows separator or
Windows-specific case. Because the changed directory discovery and deletion logic is
platform-sensitive, Windows regressions can pass the test suite unnoticed.
Code

pnpm/crates/store-dir/src/prune_cached_metadata/tests.rs[R116-132]

+#[test]
+fn prune_keeps_a_symlinked_metadata_dir_and_its_target() {
+    let root = tempdir().unwrap();
+    let store_dir = StoreDir::new(root.path().join("store"));
+    let cache_dir = root.path().join("cache");
+    let target = root.path().join("elsewhere");
+    create_dirs(&target, &["registry"]);
+    create_dirs(&cache_dir, &["v12"]);
+    symlink_dir(&target, &cache_dir.join("metadata")).unwrap();
+    symlink_dir(&target, &cache_dir.join("v12/metadata")).unwrap();
+
+    store_dir
+        .prune(&cache_dir, &[])
+        .expect("prune");
+
+    assert_kept(&cache_dir, &["metadata", "v12/metadata"]);
+    assert!(target.join("registry").exists());
Relevance

● Weak

Recent precedents reject demanding Windows-specific coverage for platform-sensitive tests when POSIX
coverage is intentional.

PR-#17065
PR-#17088

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The changed code explicitly handles directory and symlink paths, while the added tests only create
generic paths and symlinks. The compliance rule requires Windows separators or an explicit
Windows-specific case for path and symlink changes.

pnpm/crates/store-dir/src/prune_cached_metadata/tests.rs[116-132]
Skill: review-code

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 metadata-pruning change handles filesystem paths and symlinks, but its tests do not exercise Windows-specific path behavior as required by the compliance checklist.

## Fix Focus Areas
- pnpm/crates/store-dir/src/prune_cached_metadata/tests.rs[116-132]

## Recommended Fix
Add a Windows-specific test or platform-aware cases that exercise metadata discovery and protected-directory handling with Windows path semantics, while preserving the existing symlink coverage.

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

Dismiss ↗ | View ↗


Grey Divider

Context sources
✅ Compliance rules (platform): 62 rules
✅ Cross-repo context — repo relationships
  Explored: repo: pnpm/pnpm.io (sha: 0aab2bac) — View relationship
Review mode: Auto: ⚖️ Balanced: Destructive filesystem behavior warrants careful single-pass security and correctness review.

Grey Divider

Tip of the day
💡 Did you know, you can reply 'qodo' on any finding to push back, ask questions, or dig deeper

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

if name.starts_with("metadata") {
metadata_dirs.push(path);
} else if is_layout_version(&name) {
let nested = child_dirs(&path)?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Action required

1. Prune can erase files outside the cache 🐞 Bug ⛨ Security

cached_metadata_dirs checks that a versioned child is a directory, then reopens its pathname and
later passes a discovered child to recursive removal without holding that parent directory stable.
If a process able to modify the cache replaces the versioned child with a symlink between those
steps, prune can follow it and remove a metadata* directory outside the configured cache.
Agent Prompt
## Issue description
A versioned cache directory can be replaced with a symlink after enumeration, redirecting metadata discovery and recursive deletion outside the cache.
## Fix Focus Areas
- pnpm/crates/store-dir/src/prune_cached_metadata.rs[54-96]
- pnpm/crates/store-dir/src/prune_cached_metadata.rs[30-38]
## Recommended Fix
Traverse and delete relative to stable opened directory handles without following substituted parent symlinks. Do not rely on a one-time canonicalization check before pathname-based recursive removal; add a test that swaps a versioned parent during prune.

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

Dismiss ↗ | View ↗

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The finding holds: a process that can write to cacheDir could replace a vN directory with a symbolic link between the directory check and the removal and redirect the recursive removal at any metadata* directory the pruning user can delete.

Fixed in #17272: the prune now holds cacheDir and each vN open, checks and renames each metadata* child through the open descriptor on Unix, and removes it under a name a substituted directory cannot hold. The protected-directory check is verified against the open descriptor before any removal. The helper's tests include the swap itself.


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

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

@github-actions github-actions Bot added the reviewed: coderabbit CodeRabbit submitted an approving review label Oct 23, 2026
@coderabbitai

coderabbitai Bot commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

Rate Limit Exceeded

@zkochan have exceeded the limit for the number of chat messages per hour. Please wait 20 minutes and 6 seconds before sending another message.

@zkochan
zkochan merged commit 0e85843 into main Oct 23, 2026
64 checks passed
@zkochan
zkochan deleted the fix-store-prune-metadata-cache branch October 23, 2026 00:38
zkochan added a commit that referenced this pull request Oct 23, 2026
`pnpm store prune` removed `<cacheDir>/vN/metadata*` by path after
checking that `vN` was a real directory. A process that can write to
`cacheDir` could replace `vN` with a symbolic link between the check and
the removal and redirect the recursive removal at any `metadata*`
directory the pruning user can delete.

`pnpm_fs::OpenDir` holds a directory open while its children are
removed. On Unix it checks the child through the open descriptor
(`openat` with `O_NOFOLLOW | O_DIRECTORY`), renames it through the
descriptor (`renameat`) to a name only this process knows, and only then
removes it by path: a directory substituted for the opened one cannot
hold that name, so the renamed directory stays behind in the real one,
where the next prune removes it by its `metadata` prefix. The canonical
path used for the protected-directory check is verified against the open
descriptor's device and inode before any removal; a replaced directory
is skipped with a warning. On Windows and WASI every operation resolves
the path again, as the other symlink-safe helpers do there.

The prune opens `cacheDir` and each `vN` this way. The held-file id
generator of `dir_lock` moves to a shared `random_hex` helper so the
removal name and the held-file id use one implementation.

Follow-up to #17253. Part of pnpm/tasks#191.
zkochan added a commit that referenced this pull request Oct 23, 2026
…ata (#17272)

`pnpm store prune` removed `<cacheDir>/vN/metadata*` by path after
checking that `vN` was a real directory. A process that can write to
`cacheDir` could replace `vN` with a symbolic link between the check and
the removal and redirect the recursive removal at any `metadata*`
directory the pruning user can delete.

`pnpm_fs::OpenDir` holds a directory open while its children are opened
or removed. On Unix a child is opened through the parent's descriptor
(`openat` with `O_NOFOLLOW | O_DIRECTORY`) and removed through it: the
removal walks the directory with `fdopendir` and `readdir` and unlinks
every entry with `unlinkat` relative to its parent descriptor, so no
step after the open resolves a path. The canonical path used for the
protected-directory check is verified against the open descriptor's
device and inode before any removal; a replaced directory is skipped
with a warning. On Windows and WASI every operation resolves the path
again, as the other symlink-safe helpers do there.

The prune opens `cacheDir` this way and each `vN` through it.

The `OpenDir` tests cover the race at both levels: the directory is
replaced by a link after the open, and a removal and a child open
through the handle must leave the link's target intact. The store-dir
tests gain a case for a `vN` that is a symbolic link.

Follow-up to #17253. Part of pnpm/tasks#191.
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants