Skip to content

Stop vex refusing a hosted or vendored pnpm patch over the store entry an in-place install leaves behind (#2353) - #2430

Merged
Mikola Lysenko (mikolalysenko) merged 24 commits into
mainfrom
fix/vex-pnpm-stale-store-entries
Dec 2, 2026
Merged

Mikola Lysenko (mikolalysenko) merged 24 commits into
mainfrom
fix/vex-pnpm-stale-store-entries

Conversation

@mikolalysenko

@mikolalysenko Mikola Lysenko (mikolalysenko) commented Dec 2, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #2353.

Problem

After a hosted scan on pnpm 11.20 or later, the pnpm install the scan asks for, run over the existing node_modules, does what it should: every importer, the hoist directory and each dependent link the patched release. vex then exits 1 and says the patch is not_applied.

pnpm installs a release that is routed through its patch's registry as another entry of its virtual store (node_modules/.pnpm/<name>@socket-<id>+<version>) and keeps the upstream entry (<name>@<version>) in the store, with nothing linking to it: pnpm 7 to 11 remove such an entry after 7 days, pnpm 12 on pnpm prune. vex hashes every copy it finds, the leftover among them. A vendored scan leaves the same leftover on every pnpm, and there vex warns vendored_tree_out_of_sync on a tree that is in sync.

Reproduced against the production patch service with minimist@1.2.2 on pnpm 11.29.0 and 12.25.1 (hosted) and on 9.15.9, 10.34.9, 11.29.0 and 12.25.1 (vendored).

Fix

vex and apply --check judge the copies the install links. A store entry that no link leads into is left out, as an unlinked entry of Bun's store already is. rollback and remove still restore it.

The rule for pnpm is narrow on purpose:

  • It only applies where a leftover can change the verdict. A store is judged for a package version only when that version's copies sit in two or more of its entries and do not hold the same bytes in each (copies over 64 MB or 50,000 files are not compared and count as differing), which is what such an install leaves. A version in one entry is hashed as before, whether or not anything links it (a removed package, an upgraded-away version). So are the peer variants of a package, which hold the same bytes: leaving one out would change no verdict. The project is not read for either, so a project without a leftover pays nothing.
  • Every link counts. For such a version, every symbolic link below the scanned directory is read (below the project that holds the store, when the scan started inside it), in every directory whatever its name: vendor/, dist/, hidden directories, a package's own node_modules, a directory that left the workspace.
  • An entry is hashed when a path from outside the store's entries leads into it: a link outside the entries resolves into it, or a link inside a hashed entry does. The entries left out are those that only other left-out entries link.
  • An entry is left out only beside a linked entry of the same version. When none of a version's entries is linked, all are hashed as before.
  • If the links cannot all be read, every entry is hashed, as on main. The list is below.

Why "only other left-out entries link it" and not "nothing links it"

When the patched package is a peer dependency of another package, the registry route gives the dependent a new entry as well (<dependent>_<name>@socket-<id>+<version>), and the dependent's old entry keeps its link to the old <name>@<version> (measured on pnpm 11.29.0 and 12.25.1). With "nothing links it", vex would still refuse for every package that something names as a peer. Nothing outside the two old entries links either of them, so both are left out.

Where every entry is still hashed

  • on Windows, where pnpm links directories with junctions;
  • when the scanned directory neither holds the store's project nor lies inside it (--global, a node_modules that is a link to another checkout's), or the store's project lies above the git checkout the run started in;
  • under node-linker=hoisted or pnp, shamefully-hoist, a store layout other than the one pnpm 6 to 12 write, or a virtual store elsewhere;
  • when the install record or the lockfile in the store is missing or unreadable, pnpm-lock.yaml is unreadable, or either lists its importers in a way pnpm does not write;
  • when a lockfile names an importer that is not a directory inside the store's project (a member outside it, a checkout of part of a workspace). pnpm links each importer's dependencies below the importer, so those links would not be read. A modulesDir of more than one level falls under this too. This is the one thing the lockfiles are still read for;
  • when a directory or the target of a link cannot be read, or the directory holds more than 500,000 directories and links (a monorepo with a store of 5,200 entries holds about 98,000 and 20,000);
  • when a link resolves to a directory outside the directory that is read (a link: dependency on another checkout, a convenience link to build output elsewhere): what the node_modules behind it link is not read;
  • when a link resolves to a file outside it and a directory above that file holds a node_modules: node loads the file from where it is, with the packages it finds there, and a member that left the workspace keeps the links pnpm wrote for it. The home directory and what lies above it are not looked at, so a virtualenv's link to python and a stray ~/node_modules change nothing;
  • when a link resolves to the store itself, or into it by a path that names none of its entries (another spelling of the store's path, as macOS allows under /System/Volumes/Data and a case-folding file system may, or of an entry's name);
  • when no link resolves into any entry.

In these layouts the leftover reads as an unpatched copy until it is gone, as today. pnpm prune removes it (measured on pnpm 11.29.0 and 12.25.1), and a clean node_modules has none.

A link that leads nowhere (no target, a loop, a path through a file) is left out. Nothing outside the scanned directory is listed or opened. The one thing looked at there is whether a node_modules exists in a directory above a file that a link leads to, up to the home directory.

What is not read

  • Links above the scanned directory. See "One choice for a maintainer".
  • What a file outside the project loads by a relative path of its own.
  • A path to an entry that a file spells out, and NODE_PATH. pnpm writes such a path into the launchers of a package's commands (node_modules/.bin). Measured on pnpm 11.29.0 and 12.25.1, hosted and vendored, single project and workspace, with a patched package that ships a command and has a dependent (json5@1.0.1): the install rewrites the launchers, and afterwards the only file that names the upstream entry's directory is the launcher inside that entry. A real-pnpm leg now asserts this.

One choice for a maintainer

Node looks a package up in the node_modules of every directory above the one it starts in, so a link in <parent>/node_modules into this project's store is a way to load the leftover. The sweep does not read above the scanned directory.

pnpm writes no such link: an install links into its own store, below its own project. Reading above would only guard against a link placed by hand, and it has a cost. Together with the rule that a link to an unread directory keeps every entry, a project that sits in another pnpm workspace's checkout (examples/demo with its own lockfile) would never be judged, because that workspace links its members from its own node_modules. Every judged run would also read the outer install, and the result would depend on directories nobody scanned. A unit test pins the choice. Reading above the project is a small change if a maintainer wants it.

Cost

vex --offline, release builds, median of 20 interleaved runs on a busy machine (load average 13). main is the merge base.

Project main this branch
1,222 store entries, no leftover 65 ms 69 ms
the same project with a leftover (7,377 directories, 4,111 links) 81 ms, warns 322 ms, attests
a leftover in a tree of 63,625 directories and 22,006 links 536 ms 2,304 ms

The sweep runs only when a version's entries hold other bytes, so the first row is what every project without a leftover sees. The third row is the second project with a real monorepo's install cloned into it, to time the sweep on a large tree; the clone's links lead out of the project, so every entry is kept there and the warning stays.

Proof

Against the production patch service, anonymous, with real pnpm 12.25.1, 11.29.0, 10.34.9 and 9.15.9, hosted and vendored. The project is a workspace where minimist@1.2.2 is a direct dependency of one member, a hoisted transitive one of another, and a peer dependency of a tarball package. 122 checks, 0 failures:

  • After the in-place install, main exits 1 with not_applied (hosted, pnpm 11.29.0 and 12.25.1) or warns vendored_tree_out_of_sync (vendored, all four). This branch exits 0 with not_affected and no warning.
  • A link walker written in Python, which shares no code with the CLI, agrees each time that nothing reaches the old entry (and, on the hosted route, the old entry of the peer-dependent package).
  • One link to the old entry makes vex judge it again, and removing the link clears it: from vendor/, dist/, build/, a hidden directory, a nested node_modules in a member and in a live entry, a deep unrelated directory, a link to a single file of the old copy, and a chain of two links. So do a link to a directory outside the project, a link to a file outside it that sits below a node_modules, and an unreadable directory below the project. A link to a file outside it with no node_modules above changes nothing.
  • On pnpm 10.34.9 and 9.15.9 a hosted scan keeps the lock key, so there is no leftover, and this branch answers as main does.
  • rollback exits 0 afterwards.

The four lifecycle cells of the release QA that found the bug (pnpm 11 and 12, hosted and vendored: scan, install, list, vex, rollback) pass with this build: 132 checks pass, none fail. The two hosted cells failed on vex before.

Tests:

  • Real pnpm, in e2e_redirect_pnpm_build: four new legs (pnpm 12 and pnpm 11) run the in-place install in a workspace whose patched package is hoisted, ships a command, and is the peer dependency of a tarball package. They hold vex against an independent reading of the links (tests/common/pnpm_links.rs), add links from vendor/, dist/, a hidden directory and a package's own node_modules, read every file for a path to an upstream entry, and cover a nested modulesDir, where the patches stay refused. The vendored capstone (e2e_vendor_pnpm_build) gains the same reading and a vendor/ link.
  • Unit tests in crawlers::npm_crawler over hand-built stores of the shapes pnpm leaves: tables of links that keep an entry (each also removes the link again and expects the entry left out, so "keep everything" cannot pass), of things that must not keep one, and of layouts that keep every entry (each with a control from before the change).
  • e2e_vex_redirect, e2e_vex_vendor, the apply --check suite and the rollback suite cover the commands over the same stores offline.

CI passes on Linux, macOS and Windows. Run locally on macOS as well: cargo fmt --check, cargo clippy --locked --workspace --all-features -- -D warnings, the core unit tests (8,805 pass), the CLI unit tests (1,086), the apply, cli, rollback, e2e_vex_redirect and e2e_vex_vendor suites, and the real-pnpm suites with the toolchain required (e2e_redirect_pnpm_build --ignored: 28 legs; e2e_vendor_pnpm_build: 25 legs).

The pnpm hosted compatibility workflow, which runs both real-pnpm suites against pinned pnpm versions, is switched off in this repository and did not run here. Its pinned legs were run locally on pnpm 9.0.0, 9.15.9, 10.0.0, 10.33.0, 10.34.5, 11.0.0, 11.27.0, 12.0.0 and 12.4.2. Both suites pass on every version but one: the vendored suite fails on 11.0.0 in a cell this PR does not touch (vex after a lock-only revert and a plain reinstall exits 1 with vendor_unwired), and it fails the same way on main. The in-place leg this PR adds passes on 11.0.0.

Code review

/code-review high ran four times: on the branch, and after each round of fixes. The last run found nothing it rated important.

Fixed along the way:

  • a link to a named pipe could hang vex and apply --check: the check that a link is no other spelling of the store opened the path. It compares device and inode from stat now;
  • a link that reaches the store through another spelling of its path inside the project was missed;
  • the sweep ran on every vex for the peer variants of a patched package. Copies that hold the same bytes are not judged now;
  • the sweep kept every link in memory and gave up only after 1,000,000 directories. Links count against the budget, which is 500,000;
  • a copy in the store's hoist directory counted as a second entry;
  • a run from a git checkout that is a member of a workspace rooted above it read the outer workspace;
  • a link to a file outside the project, beside the node_modules of a member that left the workspace, was accepted: apply --check reported the patch in place while node loaded the leftover through that file (reproduced). Such a link keeps every entry now;
  • with no entry of a version linked, every copy was left out and the package read as not installed. An entry is left out only beside a linked one;
  • a link to the store directory itself was ignored;
  • a link that loops or passes through a file kept every entry, though nothing is loaded through it;
  • a directory removed while the sweep runs made the store unjudgeable for that run;
  • the contract said a missing pnpm-lock.yaml keeps every entry. It does not, and the text says which reads count;
  • the byte comparison left out a package's whole node_modules, where the dependencies it bundles are unpacked. Only node_modules/.bin is left out now, which is all pnpm writes there;
  • the byte comparison ran on Windows and in --global runs, where no store is judged.

Not fixed, on purpose:

  • A link to a directory outside the project keeps every entry, so the fix does not reach a project that has one (bazel-bin, a link: dependency elsewhere). Such a project behaves as on main. Reading what lies behind the link under the same budget is a possible follow-up.
  • Windows: every entry is still hashed. pnpm links with junctions there, and the sweep was not built for them.
  • One unlinked entry of a package the project no longer installs is still hashed, as on main: the rule needs two entries of a version.
  • apply --check leaves out an unlinked entry that apply itself would still write, as it does for Bun's store. The contract says the check covers the copies the install loads.
  • A tree over the budget pays for the sweep up to the budget on each run, and then hashes every entry.
  • When the store cannot be judged, the refusal does not name the directory or link that stopped the judgement. The messages are those of main; a reason needs a new warning and is left for a follow-up.
  • The spelling check for a path inside the project matters on a file system that folds case and keeps the typed spelling. macOS gives the listed spelling back, so it could not be run here; the existing case test covers it where the file system behaves that way.

Not in this PR

  • On pnpm 9 a hosted scan keeps the lock key, and pnpm install over an existing node_modules reports "Already up to date" without replacing the copy. vex refuses not_applied there, which is true; the scan's warning already says existing node_modules can still hold upstream files.
  • vex run from inside a workspace member says "No patches in this project", because the scan's files are at the workspace root. Unchanged.

🤖 Generated with Claude Code

After the `pnpm install` that a scan asks for, run over an existing
`node_modules`, pnpm links the project to a new virtual-store entry and
keeps the upstream one with nothing linking to it:
`<name>@socket-<id>+<version>` beside `<name>@<version>` after a hosted
scan on pnpm 11.20 and later (the release is routed through the registry
of its patch), and `<name>@file+...` after a vendored scan on every pnpm.
`vex` counted the leftover as an installed copy. It omitted the hosted
patch as `not_applied` and exited 1, or warned
`vendored_tree_out_of_sync` for the vendored one, and the reinstall it
asked for changed nothing (#2353).

The live-copy filter that skips Bun's orphaned store entries now skips
pnpm's too. A pnpm entry is live when a link reaches it from an
importer's `node_modules` (the root, and the members named by the
lockfile in the store or by `pnpm-lock.yaml`), from the hoist directory
`node_modules/.pnpm/node_modules`, from a live entry's own
`node_modules`, or from the `node_modules` in which a checked copy was
found. A copy that a link reaches is always judged, so an unpatched one
still refuses or warns.

Every entry is kept, as before, wherever the walk cannot be sure it read
every link: on Windows, under `node-linker=hoisted` or
`shamefully-hoist`, with a moved virtual store or another store layout,
without the install record or the lockfile in the store, when a
directory or a link cannot be read, when a lockfile lists its importers
in a layout pnpm does not write or names a member that is no directory,
when an importer's `node_modules` or the hoist directory holds a package
as a real directory, and when no link reaches the store at all.

`apply --check` verifies through the same copy lookup, so it follows the
same rule. The scan's listing keeps its own test (the packages of the
lockfile in the store), and `rollback` and `remove` resolve without the
filter, so they still restore an unlinked entry.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Hand-built pnpm stores in the shapes real pnpm leaves (#2353):

- `vex` over a hosted patch routed through its registry attests from
  the entry the importer links, and refuses the patch while that copy is
  pristine, whichever entry it is in and whatever an unlinked entry
  holds;
- `vex` over a vendored patch does not warn
  `vendored_tree_out_of_sync` for the upstream entry nothing links, and
  still warns for an unpatched linked copy;
- `apply --check` is in sync when the linked copy is patched and drift
  when it is not;
- `rollback` still restores a patched entry that nothing links.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The registry-route legs (pnpm 11 and 12) and the vendored capstone (each
pnpm of its matrix from 9 up) now also run the install a scan asks for
over a `node_modules` that holds the upstream packages, in a second
checkout so the project under test stays as it was. Each leg checks that
pnpm kept the upstream entry in the store and linked the patched one,
that `vex` attests from the linked copy (hosted) or does not warn
(vendored), and that a linked copy put back on the upstream bytes is
refused or warned about again (#2353).

The capstone's first `vex`, which runs before any reinstall, now also
expects the `vendored_tree_out_of_sync` warning: the project still links
the upstream package there.

The scan's files are written anew in the second checkout: pnpm 10.0
takes files no newer than its last install for unchanged and skips the
install. The legs do not run on Windows, where the check keeps judging
every store entry.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
`docs/ecosystems.md` says which links make a pnpm store entry an
installed copy and where every entry is still judged; the CLI contract
says the same for the verification basis of `vex` and `apply --check`;
the pnpm compatibility notes record what the in-place install leaves in
the store on each measured pnpm and which tests cover it (#2353).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
`lock_text_member_importers_exact` promises `None` for a lock whose
importers it may misread, but a line at column 0 that is no top-level
key (the markers of a merge conflict) ended the `importers` section and
the members after it were left out without a word. The walk that judges
which pnpm store entries are live reads its seeds from that list, so a
member it does not hear of is a `node_modules` it does not read.

Inside the section, only a plain top-level key ends it now; any other
line at column 0 gives `None` (#2353).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The walk that tells `vex` and `apply --check` which pnpm store entries
are live read the links of the project's `node_modules`, the hoist
directory and the members the lockfiles name. Two installs it judged
wrong, each time dropping an unpatched copy that node still loads
(#2353):

- A `node_modules` that no lockfile names. A directory that left the
  workspace keeps the links of its last install: with real pnpm 11.27.0,
  `packages/b/node_modules/mkdirp` still links `mkdirp@0.5.1`, whose
  `minimist` link still points at the upstream `minimist@0.0.8` entry
  after member `a` moved to the patched one. Hosted `vex` attested
  `not_affected`, vendored `vex` lost its `vendored_tree_out_of_sync`
  warning and `apply --check` read in sync.
- A `node_modules` the crawl reaches through a link (a git worktree that
  shares the main checkout's install). The members were read below the
  link's target, not below the crawled project, so an entry only the
  project's own member links was dropped and a hosted patch was attested
  from the lock's pin with nothing hashed.

The walk now takes the `node_modules` roots the crawl searched and reads
the links of every one of them, so an entry is live when any reaches it,
through other entries too. It keeps every entry unless the store's own
`node_modules` is among those roots as the real directory of its
project.

Each store is judged once per run (`LiveStoreEntries`), by the same
links for `vex`'s record check and its hosted one: the second lookup
used to judge the store again from the hosted copies alone.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Two smaller points of the walk over a pnpm store's links (#2353):

- A member the lockfiles name that is not on disk made the walk keep
  every entry, so `vex` kept refusing a hosted patch over the entry an
  in-place install left behind wherever part of a workspace is checked
  out (a container image that copies some members; real pnpm 11.27.0
  installs that frozen, and both lockfiles still name the rest). A path
  that is not there links nothing, so the walk goes on; one that is
  there and is no directory still keeps every entry.
- A child of the store whose type could not be read was left out of the
  entries, so a copy in it read as one nothing links. The walk keeps
  every entry now when the type of a child that is not hidden cannot be
  read.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Hand-built pnpm trees where the check passed while node still loads the
pristine copy (#2353):

- a directory that left the workspace still links a package whose
  dependency link points at the upstream entry: `vex` refuses the hosted
  patch while that `node_modules` is there and attests once it is gone,
  and `apply --check` reads drift, then in sync;
- a worktree whose `node_modules` is a link to the main checkout's, and
  whose own member reaches the pristine entry: the copy is hashed and
  the patch refused, where it was attested from the lock's pin.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The contract said a copy that a link reaches is always hashed, which
was not true of a link in a `node_modules` that no lockfile names. It
and `docs/ecosystems.md` now say which links are read: those of every
`node_modules` the crawl searches, of the members the lockfiles name,
of the hoist directory and of each reached entry. They also say that a
link in a `node_modules` the crawl does not search is not read, that a
store reached through a linked `node_modules` or from inside a member is
not judged, and that a member that is not on disk links nothing
(#2353).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
With every searched `node_modules` read, the members in the unit
fixtures were reached without the lockfiles, so nothing held the
lockfile's members in place. A member below `vendor/`, which the crawl
skips, has no other word of it: the entry it alone links stays live when
the lockfile in the store names it, when only `pnpm-lock.yaml` does and
under a quoted key, and is an orphan when neither names it (#2353).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
After the in-place `pnpm install` that a hosted or vendored scan asks for,
the upstream `<name>@<version>` entry stays in `node_modules/.pnpm` with
nothing linking to it, and `vex` and `apply --check` refused the patch for
it (#2353). The first rule on this branch proved such an entry dead by
walking the links pnpm should have written: the crawl's roots, the
lockfiles' members, the hoist dir. Two reviews each found a layout it did
not read, where a copy that still loads was left out: a link under a
directory the crawl skips by name, a link in a real package's own
`node_modules`, a `modulesDir` of more than one level.

The rule now reads the links there are. For a package version whose copies
sit in two or more entries of one store, every symbolic link below the
outer of the scanned directory and the store's project is listed, in every
directory whatever its name, and resolved, never followed. An entry is
kept when a link outside the store's entries resolves into it, or a link
inside a kept entry does. The closure is needed: on pnpm 11.29.0 and
12.25.1 a hosted scan gives a package that names the patched one as a peer
a new entry too, and its old entry keeps its link to the old one.

A version that sits in one entry is not judged, and the project is not
read for it, so a removed package and an upgraded-away version are hashed
as on main.

Every entry is kept where a link may have gone unread: on Windows, when
the two directories are unrelated, when the install record is not the
isolated linker's over this store, when a lockfile is missing or not laid
out as pnpm writes it, when a lockfile names an importer that is not a
directory inside the store's project, when a directory or a link cannot be
read, past 1,000,000 directories, and when no link resolves into any entry.

Five more cases keep entries that the sweep alone would leave out. The
first four were reproduced with real node against a store that pnpm
12.25.1 left:

- A copy that sits in the store but in none of its entries (a real
  directory of the hoist dir, which every store package resolves through)
  was dropped whenever its version sat in two entries. Only a copy in an
  entry dir is judged now.
- A link whose target is spelled another way than the store's path was
  not matched to its entry. macOS reaches every volume under
  `/System/Volumes/Data` as well, and `canonicalize` keeps that spelling.
  A link that leaves the trees read is now checked against the store by
  file identity, and every entry is kept when it lies in the store.
- Node looks a package up in the `node_modules` of every directory above
  the one it starts in. Each `node_modules` above the swept directory is
  swept as well.
- A link to a directory outside the trees read (a `link:` dependency on
  another checkout) leads to a `node_modules` that is not read, which may
  link back into the store. Every entry is kept then.
- A link that resolves to a child of the store which could be an entry
  and is not one of those listed cannot be matched to an entry: a file
  system that folds case need not give an entry's listed spelling back
  (macOS does). Every entry is kept then. This one was not reproduced:
  no such file system was at hand.

The unit tests are rewritten for the rule: the hosted and the vendored
leftover, the peer pair, a link from each kind of place, the gate, and one
case for every condition that keeps all entries. Each of the first four
cases above has a test that was seen to fail without its change.

The CLI hands the filter the scanned directory in place of the crawl's
`node_modules` roots.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The real-pnpm suites ran the in-place install in a one-importer project.
Two more legs per pnpm (11 and 12, on the registry route) run it in a
workspace where the patched package is hoisted and is also the peer
dependency of a tarball package. That is the layout in which the old
entry of the dependent keeps its link to the old entry of the patched
package (#2353):

- `vex` attests both patches after the install.
- A link to the upstream entry from `vendor/`, `dist/`, a hidden directory
  or a real package's own `node_modules` makes `vex` refuse the patch as
  `not_applied` until the link is gone.
- Under `modulesDir: sub/node_modules` the store sits in
  `sub/node_modules/.pnpm` and each member's links in
  `<member>/sub/node_modules` (measured on pnpm 10.12.1, 10.34.9, 11.29.0
  and 12.25.1; 9.15.9 and 10.11.1 keep the store in `node_modules/.pnpm`).
  Every entry is hashed there, so both patches stay refused. A run from a
  member finds no patch to attest: the scan's files are the workspace
  root's.

`tests/common/pnpm_links.rs` reads the links a second time, with its own
walk and none of the crates' code. Where `vex` attests, no path from
outside the store's entries may lead into an entry that holds the upstream
bytes; where a link was added, it must find that link. The registry-route
leg and the vendored capstone that already ran the install use it too, and
the capstone links the upstream entry from `vendor/` to see the warning
come back.

Offline, the hosted suite builds the nested `modulesDir` store by hand.
The store of another checkout now holds both entries of the package, so
that the test shows unrelated directories keeping them, and not a version
that sits in one entry. `apply --check` is run from inside a workspace
member: it is in sync while nothing links the entry that holds the
original bytes, and a link to that entry from `vendor/` at the workspace
root is drift, which shows that the whole project is read.

Ran with `SOCKET_PATCH_PNPM_E2E_REQUIRED=1` on pnpm 12.23.0 and 11.29.0
(the route legs), 10.34.9, 9.15.9 and 11.29.0 (the vendored capstone) and
12.25.1 (its pinned matrix leg).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
`CLI_CONTRACT.md`, `docs/ecosystems.md` and the pnpm compatibility notes
described the first rule of this branch: the links of the `node_modules`
the crawl searches, of the lockfiles' members and of the hoist directory.
They now describe the rule in the code (#2353):

- which entries are left out, and that only a package version that sits
  in two entries of one store is judged at all;
- the tree whose links are read, and the `node_modules` above it;
- every condition under which all entries are still hashed;
- what was measured with real pnpm: the pair of old entries a hosted scan
  leaves when the patched package is a peer dependency, the `.bin` shims,
  and where a `modulesDir` of more than one level puts the store.

What the sweep costs, for the record. Release builds, `vex --offline` on a
pnpm 12.25.1 project of 1,222 store entries (7,377 directories, 4,111
links), 40 runs of each binary, interleaved, on a machine that was busy
with other work (load average 21 to 34). The base is this branch's merge
base, 1b3f422:

    state of the project                    merge base      this branch
    one entry per patched version           50 / 75 ms      51 / 73 ms
    four versions in two entries each       44 / 98 ms      218 / 365 ms
                                            (minimum / median)

Where no version sits in two entries nothing is read, and the run costs
what it cost before. Where one does, the links are read once: 172 to
326 ms on that project, 0.8 to 1.8 s on a tree of 29,120 directories, and
5.6 to 7.6 s on one of 235,697, against 0.12 s and 4.8 s for
`find -type l` on the first and the last. A project whose patched package
has two peer variants pays for the sweep on every run, leftover or not.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The sweep that decides which entries of a pnpm store an install links
(#2353) also read each node_modules of a directory above the scanned one.
pnpm writes no link there into a store below it, so the read only guarded
against a link placed by hand, and it had a cost: with the rule that keeps
every entry when a link leads to a directory that is not read, a project
that sits in another pnpm workspace's checkout was never judged (that
workspace links its members from its own node_modules), every judged run
read the outer install, and the outcome depended on directories nobody
scanned.

The links read are now those below the scanned directory, or below the
project that holds the store when the scan started inside it. A link to a
directory outside it still keeps every entry. The docs say what is not
read: links above that directory, a path to an entry that a file spells
out, and NODE_PATH.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…stall

pnpm writes the path of a store entry into the launchers of a package's
commands (node_modules/.bin), where no link shows it. Measured on pnpm
11.29.0 and 12.25.1, hosted and vendored, in a single project and a
workspace: the install that changes the entry rewrites the launchers, and
afterwards the only file that names the upstream entry's directory is the
launcher inside that entry.

The patched package of the real-pnpm workspace legs now ships a command,
and the in-place leg reads every file below the project: none outside the
upstream entries may name one of them, and a launcher must name the entry
of the patch's registry.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ta volume

The case that reaches the leftover entry through /System/Volumes/Data
asserted that the temp dir is on the volume mounted there. It is on a
stock macOS, and the case now runs only then, so a runner whose temp dir
sits on another volume skips it instead of failing.

Also formats the launcher assertion of the real-pnpm in-place leg.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
- A link to a named pipe could hang vex and apply --check: the check that
  a link's target is no other spelling of the store opened each path. It
  now compares device and inode from stat and opens nothing.
- A link that reaches the store through another spelling of its path
  inside the swept tree was dropped (a file system that folds case and
  keeps the typed spelling), so the entry behind it read as unlinked. The
  spelling check now runs on every target that is not below the store as
  spelled, inside the tree or outside it.
- The sweep ran for the peer variants of a patched package, which hold the
  same bytes, on every vex and apply --check. A store is now judged for a
  version only when its copies in two or more entries do not hold the same
  bytes: leaving out a copy that holds the same bytes as the others changes
  no verdict, so the project is not read for them.
- The sweep kept every link in memory with no bound and gave up only after
  1,000,000 directories. Links count against the budget, which is 500,000
  directories and links (a monorepo with a store of 5,200 entries holds
  about 98,000 and 20,000).
- A copy in the hoist dir or a hidden child of the store counted as a
  second entry, so a version in one entry was judged against the docs.
- A run from a git checkout that is a member of a workspace rooted above
  it read the outer workspace. The project above the scanned directory is
  now read only inside the checkout, as other upward lookups are.
- An assert message held a run of spaces.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…nly beside a linked copy

Findings of a second review of the pnpm link sweep (#2353):

- A link to a file outside the scanned directory was accepted, but node
  loads that file from where it is and looks its packages up in the
  node_modules above it. A member that left the workspace keeps the links
  pnpm wrote for it, so `scripts/gen.js -> ../../shared/gen.js` loaded the
  leftover while apply --check reported the patch in place. The package
  links of each node_modules above such a file now count like the links
  below the project, and every entry is kept when one cannot be read.
- With no entry of a version linked, every copy was dropped and the
  package read as not installed, where one unlinked entry is hashed. An
  entry is now left out only beside a linked entry of the same version.
- A link to the store directory itself was ignored though the contract
  says a link into the store that names no entry keeps every entry. It
  does now.
- A link that loops or passes through a file kept every entry. Nothing is
  loaded through one, so it is left out like a link whose target is gone.
- The byte comparison read files with a bare read; it goes through the
  reader that refuses a pipe, as the crawlers' guard requires.
- The contract said every entry is hashed when a lockfile is missing; a
  missing pnpm-lock.yaml is fine, and the text now says which reads count.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The list of rules gained a point, so "the last case" named the wrong
one, and "a link is never followed" now has one exception.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…s outside the project

Findings of a third review of the pnpm link sweep (#2353), all on the
step that read the node_modules above a file a link leads to outside the
scanned directory:

- A link there that spelled the store's path another way, a link to a
  directory with a node_modules of its own, and a linked @scope were not
  followed, so a leftover that node reaches in two hops was left out.
- The step listed node_modules directories anywhere on disk, and an
  unreadable one changed the verdict.

Nothing outside the scanned directory is read any more. A link to a file
outside it keeps every entry when a directory above that file holds a
node_modules, which is where node looks up the packages of a file it
loads from there (a member that left the workspace keeps the links pnpm
wrote for it). This asks one stat per directory, stops at the home
directory as git's own lookup does, and covers every chain that starts in
those node_modules. A link to an interpreter under the home directory, as
in a virtualenv, changes nothing.

Also: a directory that is removed while the sweep runs (a build's temp
dir) no longer makes the store unjudgeable for that run.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@cursor

cursor Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes patch attestation and apply --check semantics for npm/pnpm installs, which are security-sensitive, though behavior is gated by extensive e2e and documented fallbacks that hash all entries when link analysis is unsafe.

Overview
vex and apply --check now ignore unlinked pnpm (and Bun) virtual-store entries left after an in-place install routes a package to a new store entry while keeping the upstream copy on disk. Verification keys off which copies the install can actually load via symbolic links under the scanned project, not every duplicate path the crawler finds.

The CLI wires this through LiveStoreEntries: find_manifest_package_copies_judged returns copy lists plus a shared store judgement, and hosted_consumed_copies reuses that judgement so agent and hosted npm paths agree. Core adds pnpm layout detection (.modules.yaml), stricter lockfile importer parsing for “can we trust link analysis?”, and the link sweep in npm_crawler. rollback/remove still restore orphaned entries; only read-only checks skip them.

Docs (CLI_CONTRACT.md, ecosystems.md, pnpm compatibility) spell out when every entry is still hashed (Windows junctions, nested modulesDir, unreadable locks, etc.). Tests add pnpm_links oracle helpers, large real-pnpm e2e legs, and offline fixtures for redirect/vendor/check/rollback.

Reviewed by Cursor Bugbot for commit 7a25662. Configure here.

…e no store is judged

Findings of a fourth review of the pnpm link sweep (#2353):

- The comparison of two copies of a version left out each package's whole
  node_modules. Dependencies a package bundles are unpacked there, so two
  copies that differ only in a bundled dependency read as the same bytes
  and were never judged by their links. Only node_modules/.bin is left
  out, which is all pnpm 11.29.0 and 12.25.1 write there.
- The copies were read through on Windows, in a --global run and for a
  store already found unjudgeable, where the result cannot matter.
- One unit case linked to a file outside the project without the guard
  its siblings have, so it failed on a machine with a node_modules above
  the temp dir.
- The docs did not say that copies over 64 MB or 50,000 files are not
  compared.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Where a store is not judged (Windows, a link to a directory outside the
project, a nested modulesDir), the upstream entry an in-place install
leaves behind still reads as an unpatched copy. pnpm prune removes it at
once on pnpm 11.29.0 and 12.25.1 (measured on the registry route), so
the docs name it beside a clean node_modules.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

[agent] PR shepherd: review brief for the approver

What it does. After a hosted or vendored scan and the in-place pnpm install it asks for, pnpm leaves the old upstream <name>@<version> entry in node_modules/.pnpm with nothing linking it, and vex / apply --check hashed it and refused (not_applied) or warned (vendored_tree_out_of_sync). Now, for a package version whose copies sit in two or more store entries with different bytes, the check reads every symlink below the scanned project and skips the entries no outside link reaches, but only next to a linked entry of the same version. rollback and remove still restore every copy. Fixes #2353.

Risk: medium. It changes vex verdicts, and the bad direction is a false attestation. The design leans conservative: any layout it can't fully read (Windows, hoisted/pnp, links leading out of the tree, unreadable dirs, odd lockfile importers, over 500k entries) hashes every entry as main does. It costs nothing for projects without a leftover. With a leftover the link sweep adds time: 81 → 322 ms on a mid-size project, 0.5 → 2.3 s on a 64k-directory tree.

Look here

Verified

Changes I made. None.

Open questions

  • The body's "One choice for a maintainer": the sweep does not read links above the scanned directory, so a hand-placed <parent>/node_modules link into this store would go unseen. Reading above it is a small change, but a project nested in another workspace's checkout would then never be judged. The current choice looks right to me; a maintainer should confirm it.
  • The body says the pnpm hosted compatibility workflow is switched off. It is on again now, and it ran on this PR (see above).
  • Judge a pnpm store under a nested modulesDir from the workspace root (#2353) #2437 (draft) follows up on the nested-modulesDir case this PR still refuses.

Generated by Claude Code

@mikolalysenko Mikola Lysenko (mikolalysenko) added the Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review label Dec 2, 2026

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.

[agent] Reviewed the production diff at b8d98e5: a store entry is skipped only when the same version has a linked sibling entry with different bytes and the store is fully judgeable; every uncertain layout falls back to hashing all entries, and a linked copy is still hashed. No defects found.

Non-blocking notes
  • wanted (pnpm-lock.yaml) is not checked with is_pnpm_lock_text the way the store's lock.yaml is; harmless because the store lock is checked.
  • Paths spelled out in .bin launchers and links above the scanned directory are not read, as documented.

@mikolalysenko
Mikola Lysenko (mikolalysenko) added this pull request to the merge queue Dec 2, 2026
Merged via the queue into main with commit 53a2f72 Dec 2, 2026
82 of 83 checks passed
@mikolalysenko
Mikola Lysenko (mikolalysenko) deleted the fix/vex-pnpm-stale-store-entries branch December 2, 2026 04:42
Mikola Lysenko (mikolalysenko) added a commit that referenced this pull request Dec 2, 2026
…sted-modules-dir

main holds #2430 as one commit, so the merge keeps this branch's own
changes on top of it: the tree is main with the nested modulesDir changes
applied.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Mikola Lysenko (mikolalysenko) added a commit that referenced this pull request Dec 2, 2026
…s-dir' into fix/vex-pnpm-store-windows

The base branch took in main, which holds #2430 (the rule this branch
extends) and the two fixes for the stack that the in-process gem tests
overflow on Windows (#2402, #2432). Without them the Windows test shard
fails on a test this branch does not touch.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review

Projects

None yet

2 participants