Skip to content

feat(pacquet): prune surplus virtual-store dirs on install - #12419

Merged
zkochan merged 7 commits into
pnpm:mainfrom
Saturate:feat/pacquet-prune-virtual-store
Jun 16, 2026
Merged

zkochan merged 7 commits into
pnpm:mainfrom
Saturate:feat/pacquet-prune-virtual-store

Conversation

@Saturate

@Saturate Saturate commented Jun 15, 2026 •

Copy link
Copy Markdown
Contributor

Ports the virtual-store sweep from pnpm's prune to pacquet's isolated linker.
After an install, node_modules/.pnpm (pacquet: .pacquet) entries the wanted
lockfile 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.

  • Sweep — prune_virtual_store: needed set = node_modules + one
    depPathToFilename per non-skipped snapshot key; readdir the virtual store;
    rimraf the rest. Mirrors prune.ts L180-190.
  • Throttle — should_prune_virtual_store mirrors the pruneVirtualStore gate
    (index.ts L471-473) and cacheExpired (L1180-1182): skip under the global
    virtual store; otherwise prune unless prunedAt is within modulesCacheMaxAge.
    An unparseable prunedAt is treated as not-expired, matching pnpm's
    NaN > maxAge == false.
  • prunedAt lifecycle — now stamped only when a sweep ran or on first install,
    else the prior value is preserved (index.ts L1828). Pacquet previously stamped
    it every install, which would have wedged the throttle off.

Notable deviation

The sweep keeps lock.yaml (the current lockfile), whereas upstream deletes it and
unconditionally rewrites it. Pacquet's current-lockfile write is conditional
(skipped when config.lockfile is off), so deleting it in the sweep could orphan
it. 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:stats removed count + pnpm:removal debug channel.

Tests

  • Unit: sweep (keeps needed + lock.yaml; removes surplus dir and skipped
    snapshot; missing-dir no-op) and throttle (both directions; empty/unparseable/
    future timestamps; global-store exclusion).
  • Integration: a first install with a pre-seeded surplus .pacquet dir asserts the
    dir 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

    • The package manager now prunes surplus, unused virtual-store snapshot directories during installation when safe and eligible, reducing disk usage.
    • The generated modules manifest now stores a deterministic prunedAt timestamp, preserving any previous value when pruning doesn’t run.
  • Bug Fixes

    • Pruning is safely skipped when the virtual-store location isn’t contained within the managed node_modules area.
  • Tests

    • Added unit and integration tests covering pruning eligibility, timestamp/age handling, filesystem sweep behavior, and safety constraints.

@Saturate
Saturate requested a review from zkochan as a code owner June 15, 2026 10:12
@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Jun 15, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (6) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0)

Grey Divider


Action required

1. NotFound containment bypass 🐞 Bug ⛨ Security
Description
prune_target_within_modules() returns the raw virtual_store_dir when canonicalization fails with
NotFound, without verifying it is a strict descendant of modules_dir. Since Install::run then
uses that returned path for the destructive sweep, a repo-controlled virtualStoreDir that is
missing at check time can be created/swapped into existence during the install and have its contents
deleted even if it is outside node_modules.
Code

pacquet/crates/package-manager/src/prune_virtual_store.rs[R143-149]

+    let modules_dir = fs::canonicalize(modules_dir).ok()?;
+    match fs::canonicalize(virtual_store_dir) {
+        Ok(dir) if dir != modules_dir && dir.starts_with(&modules_dir) => Some(dir),
+        Ok(_) => None,
+        Err(error) if error.kind() == io::ErrorKind::NotFound => {
+            Some(virtual_store_dir.to_path_buf())
+        }
Evidence
The containment gate explicitly returns Some(virtual_store_dir.to_path_buf()) on NotFound (no
descendant check), and Install::run trusts that return value as the prune root. The sweep
enumerates the directory with read_dir; if the directory exists by the time of enumeration, it
will delete entries under that path.

pacquet/crates/package-manager/src/prune_virtual_store.rs[139-151]
pacquet/crates/package-manager/src/install.rs[1355-1412]
pacquet/crates/package-manager/src/prune_virtual_store.rs[201-219]

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

## Issue description
`prune_target_within_modules()` treats `Err(NotFound)` from `fs::canonicalize(virtual_store_dir)` as safe and returns the unchecked, non-canonical path. The caller then enumerates and deletes entries under that path, which creates a race window where a previously-missing, repo-configured `virtualStoreDir` can be created or replaced outside `node_modules` before the sweep runs.
### Issue Context
This function is the safety gate for a recursive delete (`remove_dir_all` / `remove_file`) over everything in the virtual store that is not in the needed set.
### Fix Focus Areas
- pacquet/crates/package-manager/src/prune_virtual_store.rs[139-151]
### Suggested fix approach
- Keep the existing behavior that allows a not-yet-created *in-tree* virtual store under `modules_dir`.
- In the `NotFound` branch, still enforce containment by canonicalizing the closest existing ancestor of `virtual_store_dir` (typically its parent) and reconstructing the intended path from that canonical base. Then check:
- result != canonical_modules_dir
- result.starts_with(canonical_modules_dir)
- If you cannot prove containment for a missing path (e.g., no existing ancestor to canonicalize), return `None` so the sweep is refused.
- Add a unit test for: `virtual_store_dir` outside `modules_dir` and missing -> must return `None` (or otherwise refuse prune).

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


2. Prune TOCTOU symlink swap 🐞 Bug ⛨ Security
Description
Install::run checks that effective_virtual_store_dir is within modules_dir, but then prunes using
the original path without binding to the validated/canonical directory, leaving a
time-of-check/time-of-use window. A concurrent process can swap node_modules/.pacquet to a symlink
after validation and redirect recursive deletions to an attacker-chosen location.
Code

pacquet/crates/package-manager/src/install.rs[R1345-1359]

+            match fresh_lockfile.as_ref().or(lockfile) {
+                Some(wanted)
+                    if crate::prune_virtual_store::prune_target_within_modules(
+                        effective_virtual_store_dir,
+                        &config.modules_dir,
+                    ) =>
+                {
+                    crate::prune_virtual_store::prune_virtual_store(
+                        effective_virtual_store_dir,
+                        wanted.snapshots.iter().flat_map(|snapshots| snapshots.keys()),
+                        &frozen_skipped,
+                        config.virtual_store_dir_max_length as usize,
+                    )
+                    .is_some()
+                }
Evidence
The install code validates containment but then calls pruning with the original path; the prune
implementation uses that path directly for enumeration and deletion, with no further
binding/revalidation, enabling TOCTOU path swapping.

pacquet/crates/package-manager/src/install.rs[1322-1359]
pacquet/crates/package-manager/src/prune_virtual_store.rs[101-118]
pacquet/crates/package-manager/src/prune_virtual_store.rs[131-141]

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 install-time pruning does a path-containment check (`prune_target_within_modules`) but then performs `read_dir` + `remove_dir_all/remove_file` using the original `effective_virtual_store_dir` path. This creates a TOCTOU window where the path can be swapped (e.g., replaced with a symlink) between the check and use, potentially redirecting destructive deletes outside `node_modules`.
## Issue Context
- The check canonicalizes paths, but the canonicalized result is not used for pruning.
- `prune_virtual_store()` operates purely on the passed-in `&Path` and does not re-validate or use an already-open directory handle.
## Fix Focus Areas
- pacquet/crates/package-manager/src/install.rs[1322-1359]
- pacquet/crates/package-manager/src/prune_virtual_store.rs[101-141]
## Suggested direction
1. Change the containment check helper to return a *canonicalized* virtual-store directory path (or an opened directory handle) when safe.
2. Use that returned canonical path/handle for `read_dir` and removal operations, rather than the original user-configurable path.
3. Optionally re-check invariants immediately before deletion (or use openat/cap-std style APIs) to prevent symlink swaps between enumeration and removal.

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


3. Untrusted prune path deletion 🐞 Bug ⛨ Security
Description
Install::run now prunes by deleting every on-disk entry under
config.effective_virtual_store_dir() that isn’t in the needed set; because virtual_store_dir can
be set from repo-controlled workspace YAML and is resolved without normalization/containment, a
malicious repo can redirect the prune to an arbitrary directory and trigger destructive deletes
during install.
Code

pacquet/crates/package-manager/src/install.rs[R1233-1239]

+        if pruned_virtual_store && let Some(wanted) = fresh_lockfile.as_ref().or(lockfile) {
+            crate::prune_virtual_store::prune_virtual_store(
+                config.effective_virtual_store_dir(),
+                wanted.snapshots.iter().flat_map(|snapshots| snapshots.keys()),
+                &frozen_skipped,
+                config.virtual_store_dir_max_length as usize,
+            );
Evidence
The prune target comes directly from config and the prune implementation deletes entries under that
path. Repo-controlled workspace YAML can set virtual_store_dir to a relative path that escapes
base_dir, and there is no containment check before deletion.

pacquet/crates/package-manager/src/install.rs[1207-1240]
pacquet/crates/package-manager/src/prune_virtual_store.rs[89-105]
pacquet/crates/package-manager/src/prune_virtual_store.rs[171-183]
pacquet/crates/config/src/workspace_yaml.rs[710-795]
pacquet/crates/config/src/workspace_yaml.rs[963-966]

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

## Issue description
`prune_virtual_store` performs filesystem deletion under `config.effective_virtual_store_dir()` with no safety check that the directory is actually the project’s virtual store. Because repo-controlled config can set `virtual_store_dir` to an arbitrary (including `..`-escaping) path, install can delete unrelated user directories.
## Issue Context
- `pnpm-workspace.yaml` can set `virtual_store_dir`, and it is resolved by `base.join(...)` for relative paths.
- The prune loop deletes entries via `remove_dir_all` / `remove_file`.
## Fix Focus Areas
- pacquet/crates/package-manager/src/install.rs[1207-1250]
- pacquet/crates/package-manager/src/prune_virtual_store.rs[89-105]
- pacquet/crates/config/src/workspace_yaml.rs[710-795]
- pacquet/crates/config/src/workspace_yaml.rs[963-966]
## Suggested fix
1. Before calling `prune_virtual_store`, validate the target directory:
- Canonicalize (or lexical-normalize + absolute-resolve) both `effective_virtual_store_dir` and `modules_dir`.
- Require `effective_virtual_store_dir` to be a descendant of `modules_dir` *and* to have the expected basename (e.g. `.pacquet` / `.pnpm`), otherwise skip pruning and emit a warning.
2. Add a regression test that sets `virtualStoreDir: ../../..` in a workspace yaml and asserts pruning is skipped (and nothing outside the project is touched).

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


View more (1)
4. prunedAt stamped without prune ✓ Resolved 🐞 Bug ≡ Correctness
Description
install.rs updates .modules.yaml’s prunedAt whenever should_prune_virtual_store returns
true, even if the sweep didn’t run because there was no wanted lockfile (e.g.
config.lockfile=false causes fresh_lockfile to be None). This incorrectly throttles future
sweeps for modules_cache_max_age despite no prune occurring.
Code

pacquet/crates/package-manager/src/install.rs[R1233-1250]

+        if pruned_virtual_store && let Some(wanted) = fresh_lockfile.as_ref().or(lockfile) {
+            crate::prune_virtual_store::prune_virtual_store(
+                config.effective_virtual_store_dir(),
+                wanted.snapshots.iter().flat_map(|snapshots| snapshots.keys()),
+                &frozen_skipped,
+                config.virtual_store_dir_max_length as usize,
+            );
+        }
+
+        // Stamp `prunedAt` only when the sweep ran (or there was no prior
+        // `.modules.yaml`); otherwise preserve the recorded timestamp so
+        // the throttle keeps counting from the last real prune. Mirrors
+        // upstream's write at
+        // <https://github.com/pnpm/pnpm/blob/74a2dc9027/installing/deps-installer/src/install/index.ts#L1828-L1830>.
+        let pruned_at = match (&prior_modules, pruned_virtual_store) {
+            (Some(prior), false) => prior.pruned_at.clone(),
+            _ => httpdate::fmt_http_date(now),
+        };
Evidence
The prune call is conditional on a wanted lockfile, but prunedAt stamping is conditional only on
the throttle boolean. The fresh-lockfile path explicitly returns wanted_lockfile=None when
config.lockfile is false, so the code can skip the sweep while still updating prunedAt.

pacquet/crates/package-manager/src/install.rs[1219-1250]
pacquet/crates/package-manager/src/install_with_fresh_lockfile.rs[1734-1757]

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

## Issue description
`prunedAt` is advanced based on `pruned_virtual_store` (the throttle decision), not on whether a sweep actually ran. When there is no wanted lockfile, the sweep is skipped but `prunedAt` is still refreshed, delaying the next real sweep.
## Issue Context
`InstallWithFreshLockfile` can return `wanted_lockfile: None` when `config.lockfile` is false, making `fresh_lockfile` be `None` even on successful installs.
## Fix Focus Areas
- pacquet/crates/package-manager/src/install.rs[1219-1250]
- pacquet/crates/package-manager/src/install_with_fresh_lockfile.rs[1745-1757]
## Suggested fix
1. Compute `let wanted = fresh_lockfile.as_ref().or(lockfile);` once.
2. Compute `let will_sweep = pruned_virtual_store && wanted.is_some();`.
3. Use `will_sweep` (not `pruned_virtual_store`) to decide whether to stamp a fresh `prunedAt`:
- Preserve the prior `prunedAt` when `!will_sweep` and `prior_modules.is_some()`.
4. Add a unit/integration test for `config.lockfile=false` asserting `prunedAt` is preserved and no prune is attempted.

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



Remediation recommended

5. prunedAt stamped despite errors 🐞 Bug ☼ Reliability
Description
Install::run advances .modules.yaml’s prunedAt whenever prune_virtual_store() is invoked,
but the sweep intentionally converts read_dir errors into an empty listing and swallows deletion
errors. This can postpone the next retry for modules_cache_max_age even though nothing was
actually swept, delaying cleanup and allowing surplus virtual-store entries to persist longer than
intended.
Code

pacquet/crates/package-manager/src/install.rs[R1234-1259]

+        let did_prune = crate::prune_virtual_store::should_prune_virtual_store(
+            config.enable_global_virtual_store,
+            prior_modules.as_ref().map(|modules| modules.pruned_at.as_str()),
+            config.modules_cache_max_age,
+            now,
+        ) && if let Some(wanted) = fresh_lockfile.as_ref().or(lockfile) {
+            crate::prune_virtual_store::prune_virtual_store(
+                config.effective_virtual_store_dir(),
+                wanted.snapshots.iter().flat_map(|snapshots| snapshots.keys()),
+                &frozen_skipped,
+                config.virtual_store_dir_max_length as usize,
+            );
+            true
+        } else {
+            false
+        };
+
+        // Stamp `prunedAt` only when the sweep ran (or there was no prior
+        // `.modules.yaml`); otherwise preserve the recorded timestamp so
+        // the throttle keeps counting from the last real prune. Mirrors
+        // upstream's write at
+        // <https://github.com/pnpm/pnpm/blob/74a2dc9027/installing/deps-installer/src/install/index.ts#L1828-L1830>.
+        let pruned_at = match (&prior_modules, did_prune) {
+            (Some(prior), false) => prior.pruned_at.clone(),
+            _ => httpdate::fmt_http_date(now),
+        };
Evidence
did_prune is used to decide whether to write a fresh prunedAt, but did_prune only reflects
that prune_virtual_store() was called. The sweep itself treats directory read errors as an empty
list and logs/swallow removal errors, so a sweep can do no work while prunedAt still advances,
delaying the next sweep window.

pacquet/crates/package-manager/src/install.rs[1207-1259]
pacquet/crates/package-manager/src/prune_virtual_store.rs[143-160]
pacquet/crates/package-manager/src/prune_virtual_store.rs[171-183]

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

## Issue description
`prunedAt` is used to throttle future virtual-store sweeps, but it currently advances even when the sweep couldn't reliably run (e.g., `read_dir` fails, or removals fail). This delays retries and undermines the cleanup feature.
## Issue Context
- `prune_virtual_store()` currently cannot communicate "enumeration failed" / "nothing was swept due to IO" back to the caller.
- `Install::run` uses a boolean (`did_prune`) that becomes `true` as soon as the sweep is *invoked*, not when it *successfully enumerated* the virtual-store directory.
## Fix Focus Areas
- pacquet/crates/package-manager/src/prune_virtual_store.rs[143-160]
- pacquet/crates/package-manager/src/prune_virtual_store.rs[89-105]
- pacquet/crates/package-manager/src/install.rs[1234-1259]
### Suggested implementation direction
1. Change `read_virtual_store_dir` (or `prune_virtual_store`) to return a `Result` (or an `Option`) that distinguishes:
- `Ok(entries)` / sweep enumerated successfully (including `NotFound -> Ok(vec![])`), vs
- `Err(e)` / sweep could not enumerate.
2. In `Install::run`, set `did_prune` to `true` only when enumeration succeeded (and you actually attempted the sweep against a known directory listing). If enumeration fails, preserve the prior `prunedAt` so the next install can retry soon.
3. Keep current behavior of logging + non-fatal install if you want parity; the key change is preventing `prunedAt` from advancing on enumeration failure.

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


6. Global store prune bypass 🐞 Bug ⛨ Security
Description
should_prune_virtual_store disables pruning only when enable_global_virtual_store is true, not
when the effective virtual-store path equals the computed global-virtual-store path; if
virtual_store_dir is configured to /v11/links while the flag remains false, installs can prune
the shared global virtual store.
Code

pacquet/crates/package-manager/src/prune_virtual_store.rs[R38-52]

+pub fn should_prune_virtual_store(
+    enable_global_virtual_store: bool,
+    prior_pruned_at: Option<&str>,
+    modules_cache_max_age: u64,
+    now: SystemTime,
+) -> bool {
+    if enable_global_virtual_store {
+        return false;
+    }
+    match prior_pruned_at {
+        Some(pruned_at) if !pruned_at.is_empty() && modules_cache_max_age > 0 => {
+            cache_expired(pruned_at, modules_cache_max_age, now)
+        }
+        _ => true,
+    }
Evidence
The prune gate only checks the boolean flag. Config derives global_virtual_store_dir to
/.../links in the default case, and effective_virtual_store_dir() returns the configured
virtual_store_dir when the flag is false, enabling a configuration where the effective path is the
global store but the gate still allows pruning.

pacquet/crates/package-manager/src/prune_virtual_store.rs[38-52]
pacquet/crates/config/src/lib.rs[1489-1561]
pacquet/crates/config/src/lib.rs[1584-1590]
pacquet/crates/config/src/lib.rs[431-484]

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 new prune gate uses `enable_global_virtual_store` as the sole signal to skip pruning. However, `global_virtual_store_dir` is still derived to `<store_dir>/v11/links` even when the flag is false, so a config that sets `virtual_store_dir` to that same path can cause pruning to run against the shared global virtual store.
## Issue Context
`Config::effective_virtual_store_dir()` returns `virtual_store_dir` when `enable_global_virtual_store` is false, and `apply_global_virtual_store_derivation` sets `global_virtual_store_dir` to `store_dir.links()` in the common case.
## Fix Focus Areas
- pacquet/crates/package-manager/src/install.rs[1226-1239]
- pacquet/crates/package-manager/src/prune_virtual_store.rs[38-52]
- pacquet/crates/config/src/lib.rs[1489-1561]
- pacquet/crates/config/src/lib.rs[1584-1590]
## Suggested fix
1. Change the gate to skip pruning when `effective_virtual_store_dir` equals `global_virtual_store_dir` (ideally after canonicalization/normalization), regardless of the boolean flag.
- Either pass both paths into `should_prune_virtual_store`, or compute an `is_global_vs_dir` bool in the caller based on path equality.
2. Add a unit test: set `enable_global_virtual_store=false` but `virtual_store_dir=store_dir.links()` and assert pruning is skipped.

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



Informational

7. Removed count over-reported 🐞 Bug ≡ Correctness
Description
prune_virtual_store() increments its removed counter regardless of whether try_remove_pkg()
actually deleted the entry. This makes the return value incorrect (counts attempts, not successful
removals), which can mislead future callers/metrics and reduces the diagnostic value of tests that
assert the count.
Code

pacquet/crates/package-manager/src/prune_virtual_store.rs[R89-103]

+pub fn prune_virtual_store<'a>(
+    virtual_store_dir: &Path,
+    snapshot_keys: impl Iterator<Item = &'a PkgNameVerPeer>,
+    skipped: &SkippedSnapshots,
+    virtual_store_dir_max_length: usize,
+) -> usize {
+    let needed = needed_virtual_store_names(snapshot_keys, skipped, virtual_store_dir_max_length);
+    let mut removed = 0;
+    for entry_name in read_virtual_store_dir(virtual_store_dir) {
+        if needed.contains(&entry_name) {
+            continue;
+        }
+        try_remove_pkg(&virtual_store_dir.join(entry_name));
+        removed += 1;
+    }
Evidence
The loop increments removed unconditionally after calling try_remove_pkg, while try_remove_pkg
logs and swallows errors. Therefore removed can exceed the number of entries actually removed.

pacquet/crates/package-manager/src/prune_virtual_store.rs[89-105]
pacquet/crates/package-manager/src/prune_virtual_store.rs[171-183]

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

## Issue description
`prune_virtual_store()` returns a `usize` described as "directories removed", but it increments the counter even when deletion fails and is only logged.
## Issue Context
`try_remove_pkg()` intentionally swallows errors to avoid failing installs, but the caller should not treat failed deletions as successful removals.
## Fix Focus Areas
- pacquet/crates/package-manager/src/prune_virtual_store.rs[89-105]
- pacquet/crates/package-manager/src/prune_virtual_store.rs[171-183]
- pacquet/crates/package-manager/src/prune_virtual_store/tests.rs[73-110]
### Suggested implementation direction
- Change `try_remove_pkg` to return `bool` (or `Result<(), io::Error>`).
- Increment `removed` only when the deletion succeeded (or when the target was already `NotFound`, if you want to treat that as "already removed").
- Update the unit test expectations if needed (e.g., ensure it asserts on filesystem state primarily, and use the count as a secondary assertion only if it’s accurate).

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


Grey Divider

Qodo Logo

@coderabbitai

coderabbitai Bot commented Jun 15, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

A new prune_virtual_store module is introduced with a timestamp-based pruning gate and filesystem sweep to remove surplus virtual-store snapshot directories during install. The install path is updated to read the prior .modules.yaml, conditionally run the gate and sweep before writing a new manifest, and pass an externally computed pruned_at string into build_modules_manifest instead of generating it internally.

Changes

Virtual Store Pruning

Layer / File(s) Summary
Pruning module: gate, sweep, and safety checks
pacquet/crates/package-manager/src/lib.rs, pacquet/crates/package-manager/src/prune_virtual_store.rs
should_prune_virtual_store parses the prior HTTP-date pruned_at timestamp and compares elapsed time against modules_cache_max_age to decide whether to prune (skips when global virtual store, forces prune when timestamp empty/missing or max-age zero, treats unparseable timestamps as not expired). prune_virtual_store builds a required-name set from lockfile snapshot keys minus SkippedSnapshots plus node_modules and current lockfile name, enumerates the virtual-store directory, and removes surplus entries using symlink_metadata-aware deletion (missing directory treated as empty, other errors logged without aborting). prune_target_within_modules validates that virtual-store is a strict descendant of modules_dir via canonicalization. Helper functions compute needed names and read directory entries.
Install wiring: pruning step and pruned_at externalization
pacquet/crates/package-manager/src/install.rs
Before writing .modules.yaml, install reads the prior manifest to recover pruned_at, determines if effective virtual store is global, calls the gate and sweep when safe (validated via prune_target_within_modules), and derives the new pruned_at (preserving old value when no sweep ran, stamping current time RFC 1123 when it did). build_modules_manifest signature extended to accept explicit pruned_at: String, removing the internal SystemTime::now() call.
Unit and integration tests
pacquet/crates/package-manager/src/prune_virtual_store/tests.rs, pacquet/crates/package-manager/src/install/tests.rs
should_prune_virtual_store tests cover global-mode, missing/empty timestamp, zero max-age, fresh/expired cache, and invalid/future timestamp handling. Filesystem sweep tests verify surplus removal, required retention, missing-directory no-op, and unreadable-path errors. Path safety tests for prune_target_within_modules and same_dir. Integration tests install_prunes_surplus_virtual_store_dir and install_skips_prune_when_virtual_store_escapes_node_modules seed surplus directories and assert they are pruned when safe or left untouched when outside node_modules. Two existing build_modules_manifest tests updated with fixed pruned_at argument for determinism.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • pnpm/pnpm#12046: Modifies the install flow around writing .modules.yaml and node_modules artifacts, overlapping with this PR's pre-manifest pruning step in install.rs.
  • pnpm/pnpm#11896: Updates install.rs to use effective_virtual_store_dir from config, which this PR then uses as input to its global-store detection logic for pruning decisions.

Suggested reviewers

  • zkochan
  • KSXGitHub

Poem

🐇 Hop, hop, I sweep the store,
Old snapshots clutter it no more!
A timestamp checked, a max-age set,
No surplus dirs shall linger yet.
The virtual shelves stay neat and bright —
This bunny pruned things just right! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat(pacquet): prune surplus virtual-store dirs on install' directly and clearly describes the main feature addition: pruning surplus virtual-store directories during the install operation.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Prune surplus virtual-store dirs during install (isolated linker)
✨ Enhancement 🧪 Tests 🕐 40+ Minutes

Grey Divider

Walkthroughs

Description
• 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.
Diagram
graph 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
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Record and surface prune results (removed count / warnings)
  • ➕ Improves debuggability when disk bloat persists or deletions fail
  • ➕ Enables future parity with pnpm stats/debug channels without refactors
  • ➖ Adds reporting plumbing (reporter/events) beyond the scoped sweep port
2. Make current-lockfile write unconditional (full pnpm parity)
  • ➕ Allows safely deleting lock.yaml during the sweep like upstream
  • ➕ Reduces divergence and special-case reasoning in needed-set logic
  • ➖ Behavioral change when config.lockfile is disabled; broader scope than this PR
3. Compute needed set from actual linked state instead of lockfile snapshots
  • ➕ Potentially prunes less aggressively if lockfile and disk temporarily diverge
  • ➕ Could support partial installs/edge cases more explicitly
  • ➖ More complex and likely slower; harder to keep 1:1 with pnpm semantics

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 lock.yaml during sweeps.

Grey Divider

File Changes

Enhancement (3)
install.rs Wire virtual-store pruning into install and preserve 'prunedAt' semantics +51/-3

Wire virtual-store pruning into install and preserve 'prunedAt' semantics

• Adds a pnpm-aligned prune gate ('modulesCacheMaxAge', 'enableGlobalVirtualStore', prior 'prunedAt') and runs a sweep of the isolated virtual store using wanted lockfile snapshot keys. Updates '.modules.yaml' writing so 'prunedAt' is only refreshed when a sweep ran (or on first install), otherwise preserving the prior timestamp; also logs manifest read failures and treats them as fresh installs.

pacquet/crates/package-manager/src/install.rs


lib.rs Register new 'prune_virtual_store' module +1/-0

Register new 'prune_virtual_store' module

• Exports the new pruning implementation by adding the module to the crate root.

pacquet/crates/package-manager/src/lib.rs


prune_virtual_store.rs Implement pnpm-style virtual-store sweep and throttle gate +187/-0

Implement pnpm-style virtual-store sweep and throttle gate

• Adds a new module that (1) decides whether to prune based on global-store mode and 'prunedAt' age, matching pnpm’s NaN/unparseable timestamp semantics, and (2) sweeps the virtual store by removing entries not referenced by wanted lockfile snapshots (excluding skipped snapshots). Deliberately preserves 'lock.yaml' in the sweep because pacquet’s lockfile write is conditional.

pacquet/crates/package-manager/src/prune_virtual_store.rs


Tests (2)
tests.rs Add install-path regression test for pruning surplus '.pacquet' dirs +74/-0

Add install-path regression test for pruning surplus '.pacquet' dirs

• Introduces an integration-style test that seeds a surplus virtual-store directory before a first install, then asserts it is removed while the installed package’s slot survives. Updates existing 'build_modules_manifest' tests for the new 'pruned_at' parameter.

pacquet/crates/package-manager/src/install/tests.rs


tests.rs Unit tests for prune gate and sweep behavior (including edge cases) +119/-0

Unit tests for prune gate and sweep behavior (including edge cases)

• Adds deterministic unit tests for throttle behavior (missing/empty/unparseable/future timestamps; global-store exclusion; max-age behavior) and for the sweep’s keep/remove rules (keeps needed, 'node_modules', and 'lock.yaml'; removes surplus and skipped entries; missing-dir no-op).

pacquet/crates/package-manager/src/prune_virtual_store/tests.rs


Grey Divider

Qodo Logo

@codecov-commenter

codecov-commenter commented Jun 15, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.90780% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.05%. Comparing base (c112b61) to head (085f1f6).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
.../crates/package-manager/src/prune_virtual_store.rs 92.15% 8 Missing ⚠️
pacquet/crates/package-manager/src/install.rs 94.87% 2 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

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

@github-actions

github-actions Bot commented Jun 15, 2026 •

Copy link
Copy Markdown
Contributor

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 4.199 ± 0.164 4.010 4.505 2.01 ± 0.13
pacquet@main 4.105 ± 0.142 3.970 4.370 1.96 ± 0.12
pnpr@HEAD 2.205 ± 0.132 2.029 2.358 1.05 ± 0.08
pnpr@main 2.090 ± 0.106 1.949 2.280 1.00
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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 639.8 ± 7.1 626.5 651.2 1.00
pacquet@main 645.4 ± 86.6 599.9 889.7 1.01 ± 0.14
pnpr@HEAD 702.9 ± 80.1 656.9 927.8 1.10 ± 0.13
pnpr@main 680.4 ± 30.5 646.9 745.0 1.06 ± 0.05
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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 4.220 ± 0.040 4.145 4.295 1.96 ± 0.12
pacquet@main 4.195 ± 0.035 4.155 4.271 1.95 ± 0.12
pnpr@HEAD 2.152 ± 0.131 1.948 2.381 1.00
pnpr@main 2.235 ± 0.144 2.025 2.444 1.04 ± 0.09
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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 1.354 ± 0.015 1.329 1.381 2.08 ± 0.07
pacquet@main 1.372 ± 0.048 1.345 1.505 2.10 ± 0.10
pnpr@HEAD 0.652 ± 0.019 0.631 0.702 1.00
pnpr@main 0.661 ± 0.063 0.629 0.839 1.01 ± 0.10
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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 3.016 ± 0.046 2.970 3.103 4.65 ± 0.09
pacquet@main 3.044 ± 0.044 3.001 3.146 4.70 ± 0.09
pnpr@HEAD 0.672 ± 0.011 0.660 0.690 1.04 ± 0.02
pnpr@main 0.648 ± 0.007 0.638 0.659 1.00
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
      ]
    }
  ]
}

@github-actions

github-actions Bot commented Jun 15, 2026 •

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Branchpr/12419
Testbedpacquet
Click to view all benchmark results
BenchmarkLatencyBenchmark 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%)
🐰 View full continuous benchmarking report in Bencher

@github-actions

github-actions Bot commented Jun 15, 2026 •

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Branchpr/12419
Testbedpnpr

⚠️ WARNING: No Threshold found!

Without a Threshold, no Alerts will ever be generated.

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

Click to view all benchmark results
BenchmarkLatencymilliseconds (ms)
isolated-linker.fresh-install.cold-cache.cold-store📈 view plot
⚠️ NO THRESHOLD
2,152.11 ms
isolated-linker.fresh-install.cold-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
671.91 ms
isolated-linker.fresh-install.hot-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
652.03 ms
isolated-linker.fresh-restore.cold-cache.cold-store📈 view plot
⚠️ NO THRESHOLD
2,204.78 ms
isolated-linker.fresh-restore.hot-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
702.88 ms
🐰 View full continuous benchmarking report in Bencher

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Jun 15, 2026 •

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 1a30cc7

@Saturate
Saturate force-pushed the feat/pacquet-prune-virtual-store branch from 1a30cc7 to 71099b0 Compare June 16, 2026 10:51
@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Jun 16, 2026 •

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 71099b0

@Saturate
Saturate force-pushed the feat/pacquet-prune-virtual-store branch from 71099b0 to 64085fb Compare June 16, 2026 10:59
@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Jun 16, 2026 •

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 64085fb

Saturate and others added 6 commits June 16, 2026 20:03
- 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`.
@zkochan
zkochan force-pushed the feat/pacquet-prune-virtual-store branch from 64085fb to e67ebbc Compare June 16, 2026 19:05
@Saturate
Saturate force-pushed the feat/pacquet-prune-virtual-store branch from e67ebbc to 2d5d421 Compare June 16, 2026 19:12
@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Jun 16, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

Grey Divider

New Review Started

This review has been superseded by a new analysis

Grey Divider

Qodo Logo

@Saturate
Saturate force-pushed the feat/pacquet-prune-virtual-store branch from 2d5d421 to e67ebbc Compare June 16, 2026 19:14
@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Jun 16, 2026 •

Copy link
Copy Markdown

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.
@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Jun 16, 2026 •

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 085f1f6

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants