Skip to content

Judge a pnpm store under a nested modulesDir from the workspace root (#2353) - #2437

Merged
Mikola Lysenko (mikolalysenko) merged 30 commits into
mainfrom
fix/vex-pnpm-store-nested-modules-dir
Dec 2, 2026
Merged

Mikola Lysenko (mikolalysenko) merged 30 commits into
mainfrom
fix/vex-pnpm-store-nested-modules-dir

Conversation

@mikolalysenko

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

Copy link
Copy Markdown
Collaborator

Follows #2430, which is merged. Part of #2353.

Problem

#2430 keeps every pnpm store entry under a modulesDir of more than one level, so the entry an in-place install leaves behind still refuses the patch there (vex exits 1 with not_applied on the registry route; vendored mode warns vendored_tree_out_of_sync).

With modulesDir: sub/node_modules, pnpm 10.12 and later put the virtual store in sub/node_modules/.pnpm and each member's links in <member>/sub/node_modules. The lockfile in the store names the members from the workspace root. #2430 took the store to belong to the directory beside its node_modules (sub/), found no member there, and could not tell where the members' links are.

Fix

The workspace's root is looked up instead of assumed:

  • it is the directory beside the store's node_modules when pnpm-lock.yaml is there, as in every ordinary layout, and nothing above is read;
  • otherwise it is the nearest directory above whose own pnpm-workspace.yaml (modulesDir) or .npmrc (modules-dir) names that node_modules. A setting in a file further up, the home directory's among them, does not count;
  • every importer of both lockfiles has to be a directory inside the root, as before. The members' links are below it, so the sweep reads them;
  • a directory above the scanned one is read like any other upward lookup of a project run: not past the git checkout, and not at the home directory. Nothing of a project outside that is read at all.

pnpm before 10.12 moves the links and the install record under a modulesDir and leaves the store in node_modules/.pnpm (measured on 9.15.9 and 10.11.1). Where there is no record beside the store, the one in the modules dir that the settings beside the store name is read, and counts only when its virtualStoreDir names the store. A record beside the store always decides: one of another linker rules the store out, whatever an older record elsewhere says.

Everything else in #2430's rule is unchanged: a link in a member's own modules dir keeps an entry like any other link, and a member that is not on disk keeps every entry.

Still not judged

A modulesDir that no file in the project sets (pnpm's global config, the environment). Nothing says which directory installs into that node_modules, so every entry is kept, as before.

Proof

  • Real pnpm 11 and 12 (*_registry_route_in_place_install_under_a_nested_modules_dir): the legs that pinned "the patches stay refused" now expect both patches attested, a link to the upstream entry in a member's own modules dir to refuse its patch (the independent link reading must find the link), and the patch to be attested again once the link is gone.
  • Unit tests over hand-built stores of both layouts: the 10.12 layout with the setting in pnpm-workspace.yaml and in .npmrc (leftover left out; a link in the member's modules dir keeps it; a member that is not on disk, or one that pnpm-lock.yaml names outside the root, keeps every entry; a setting in a file above the root, or no setting, keeps every entry), a modulesDir of three levels scanned from the root, from a directory of members and from a member, and the older layout (judged when the record in the modules dir names the store; every entry kept with no record, a record that names another store, or a record of another linker beside the store).
  • e2e_vex_redirect: the offline twin, with the setting, without it, and with the link.
  • Locally on macOS: cargo fmt --check, cargo clippy --locked --workspace --all-features -- -D warnings, the core unit tests (8,927), the CLI unit tests, the apply, cli, rollback, e2e_vex_redirect and e2e_vex_vendor suites, and the real-pnpm suites with the toolchain required.

CI

pnpm hosted compatibility / install-proof (node 24.11.1) failed here on pnpm 11.0.0, in a cell of the vendored suite that failed the same way on main. #2434 fixed it and is merged; with main merged into this branch the check passes on every pnpm version. That push only merged main, so CI reused the previous head's results for the test jobs, as it does for such a push; the merge queue runs them again.

Code review

/code-review high ran on the first commit; the second fixes what it found:

  • an install record of another linker beside the store was overruled by an older record in a modules dir, so a store that PnP loads by path could be judged by its links;
  • the project above the scanned directory was read (install record, lockfiles, importers) before the check that it may be read at all;
  • the modulesDir setting was taken from any file above the candidate, the home directory's .npmrc among them;
  • every judged store paid for a walk up its ancestors; the walk now happens only when pnpm-lock.yaml is not beside node_modules;
  • the home rule also stopped at the scanned directory itself, so a project whose root is the home directory (a container with HOME=/app) was not judged;
  • with a modulesDir of three levels, a scan from a subdirectory stopped at the first directory unrelated to it;
  • when the lockfile in the store names the root alone, pnpm-lock.yaml at the root was not read, so an importer outside the root went unseen.

🤖 Generated with Claude Code


Generated by 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>
…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>
Under a `modulesDir` of more than one level (`sub/node_modules`), pnpm
10.12 and later put the virtual store in `<modulesDir>/.pnpm` and each
member's links in `<member>/<modulesDir>`. The lockfile in the store names
the members from the workspace root, but the store was taken to belong to
the directory beside its `node_modules`, where no member is. So every
entry was kept, and the entry an in-place install leaves behind refused
the patch (#2353).

The root is now looked up: the directory beside the store's
`node_modules`, or the nearest one above it whose `modulesDir` setting
(`pnpm-workspace.yaml`, or `modules-dir` in `.npmrc`) names that
`node_modules`, whichever holds every importer of both lockfiles. It is
read like any other file a project run looks up above the scanned
directory: not past the checkout, and not at the home directory. The
members' links are below the root, so the sweep reads them, and a link in
a member's own modules dir keeps an entry like any other.

pnpm before 10.12 moves the links and the install record under a
`modulesDir` and leaves the store in `node_modules/.pnpm` (measured on
9.15.9 and 10.11.1). The record is read from the modules dir there, and
counts only when it names the store.

Where no setting in the project says which directory installs into that
`node_modules` (the setting came from pnpm's global config), the root is
not known and every entry is kept, as before.

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

Review of the nested modulesDir change found that the root lookup read
too much and trusted too much:

- An install record of another linker beside the store (`pnp`,
  `hoisted`) was overruled by an older isolated record in a modules dir,
  so a store whose packages are loaded by path could be judged by its
  links. A record beside the store now decides; the one in a modules dir
  counts only where there is none beside it.
- The install record, the lockfiles and the importers of a project above
  the scanned directory were read before the check that it may be read at
  all. The root is now found first, and nothing of a store is read unless
  a root that may be read holds it.
- The `modulesDir` setting was taken from any `pnpm-workspace.yaml` or
  `.npmrc` above the candidate, the home directory's among them. Only
  the candidate's own two files count.
- Every judged store paid for a walk up its ancestors. The walk happens
  only when `pnpm-lock.yaml` is not beside `node_modules`, which is the
  layout a nested modulesDir leaves.
- The home rule also stopped at the scanned directory itself, so a
  project whose root is the home directory was not judged.
- With a modulesDir of three levels, a scan from a subdirectory stopped
  at the first directory unrelated to it and never reached the root.
- When the lockfile in the store names the root alone, `pnpm-lock.yaml`
  at the root was not read, so an importer outside the root went unseen.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@mikolalysenko
Mikola Lysenko (mikolalysenko) marked this pull request as ready for review December 2, 2026 05:04
@cursor

cursor Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes core npm/pnpm verification logic used by vex and apply --check; broad edge-case handling but heavily tested and read-only for installs except rollback semantics clarification.

Overview
vex and apply --check now treat Bun and pnpm virtual-store entries with no symlink path into them as non-installed copies, so stale upstream entries left after an in-place install no longer block attestation or trigger false vendored_tree_out_of_sync warnings. Judgment is shared across the manifest copy lookup and hosted consumed-copy resolution via a new LiveStoreEntries / find_manifest_package_copies_judged plumbing path.

For pnpm with modulesDir deeper than one level, the crawler no longer assumes the store belongs to the directory beside node_modules; it resolves the workspace root from pnpm-lock.yaml beside the store or from the nearest ancestor whose own modulesDir / modules-dir settings point at that store, with stricter install-record and lockfile-importer checks (declared_modules_dir, .modules.yaml layout parsing, lock_text_member_importers_exact). Rollback still restores orphaned entries; only verification skips them.

Contract and ecosystem docs document the unlinked-entry rule; large unit, apply --check, vex, rollback, and real-pnpm e2e suites (plus standalone pnpm_links oracle) lock in link-based behavior across workspaces, stray node_modules, and nested modulesDir.

Reviewed by Cursor Bugbot for commit 0cedc96. Configure here.

…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>
The walk that finds a workspace root above a nested modulesDir skips a
directory above the scanned one that is the home directory or above it,
like every other upward lookup of a project run. The lists of cases where
every store entry is hashed only named the git checkout bound.

Assisted-by: Claude Code:claude-opus-5-5
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

[agent] PR shepherd: review brief for the approver

What it does
When pnpm installs under a modulesDir of more than one level, vex and apply --check now find the workspace root by walking up to the nearest directory whose own pnpm-workspace.yaml or .npmrc names that node_modules. They no longer assume the root is the directory beside it. With the root found, an unlinked upstream leftover in the store is left out and stops refusing the patch. The older pre-10.12 layout, where only the install record moves, is handled too.

Risk: medium. Any lookup that misses or fails falls back to the old behaviour of hashing every entry, so a miss refuses a patch and never attests a wrong one. The code returns early on Windows, compares only canonical paths, and resolves modulesDir through the existing resolve_modules_folder, which rejects absolute paths and .. escapes. The one wider change is a new home-directory bound on the upward read, covered in the open question.

Look here

Verified

Changes I made
An earlier shepherd run pushed 0d68d88, which documents the home-directory bound in CLI_CONTRACT.md and docs/ecosystems.md. It is a docs-only change.

Open questions

  1. The home-directory bound also applies to the ordinary node_modules/.pnpm layout, not only to nested modulesDir. Take a host where HOME is the repository root (HOME=/app, repo at /app, common on PaaS images) and vex run from /app/packages/web. On main that store is judged. With this PR every entry is kept, so a leftover upstream entry can refuse a patch (not_applied, exit 1) where it used to pass. This only makes things stricter, but is it intended?
  2. Minor: outside a git checkout and outside HOME (for example /srv/app in a container), the walk may read pnpm-workspace.yaml/.npmrc from every ancestor up to /. This can only widen the link sweep, so it cannot cause a false attest.

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
…sted-modules-dir

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

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@mikolalysenko
Mikola Lysenko (mikolalysenko) added this pull request to the merge queue Dec 2, 2026
Merged via the queue into main with commit dfa9a96 Dec 2, 2026
45 checks passed
@mikolalysenko
Mikola Lysenko (mikolalysenko) deleted the fix/vex-pnpm-store-nested-modules-dir branch December 2, 2026 16:26
Mikola Lysenko (mikolalysenko) added a commit that referenced this pull request Dec 2, 2026
…ndows

main now holds #2437 and #2443 as squashed commits, with the same tree as
the head of #2443 that this branch already contains (39a01c2). So this
merge keeps the tree of this branch as it is.

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

Development

Successfully merging this pull request may close these issues.

4 participants