Skip to content

Judge a pnpm store by its links on Windows (#2353) - #2446

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

Mikola Lysenko (mikolalysenko) merged 50 commits into
mainfrom
fix/vex-pnpm-store-windows

Conversation

@mikolalysenko

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

Copy link
Copy Markdown
Collaborator

Part of #2353. #2437 and #2443, which this was stacked on, are merged.

Problem

#2430 leaves out a pnpm store entry that nothing links, but not on Windows: there every entry is still judged. So after the in-place pnpm install that a hosted scan asks for, vex on Windows still refuses the patch as not_applied and exits 1, and after a vendored scan it still warns vendored_tree_out_of_sync. The upstream entry that pnpm leaves in the store is the cause, as on Linux and macOS before #2430.

Fix

The same rule runs on Windows. Three things were in the way:

  • The early return is gone. Rust reads a junction as a link (is_symlink), and so it reads the symbolic links pnpm writes where it may make them. Both are resolved with canonicalize.
  • A link that leads nowhere is told by Windows' own error codes. ERROR_FILE_NOT_FOUND, ERROR_PATH_NOT_FOUND and ERROR_CANT_RESOLVE_FILENAME are the codes a junction fails with when its target is missing, when a directory on the way is missing or is a file, and when it loops. std folds an unreachable network path into the same NotFound kind, which says nothing about what is there, so the kind is not used on Windows, for a link or for a directory or file that a read finds missing. Every other failure keeps every entry. Two more conditions hold before a link is left out:
    • its target fails the same way when asked for by itself. canonicalize opens the target and then names it, and the name fails for a target that is there on a volume without a drive letter;
    • the drive or share its target names is there. A mapped drive is there for one session and not for another (an elevated process does not see it), and a link into it fails like a link to a missing directory.
  • The identity of a file comes from a handle. It tells the store from another spelling of its path. Windows has no stat: the file is opened with no access to what it holds, as std::fs::metadata opens it there, and same_file compares the volume serial number and file index. A directory above the store is not opened for it, since it cannot be the store.

Every case that kept every entry before still does, on Windows too.

What pnpm does on Windows

Measured with pnpm 11 and 12 on a windows-latest runner:

  • The in-place install leaves the same entries as elsewhere: leaf@1.0.0 stays beside leaf@socket-<id>+1.0.0, with the upstream bytes.
  • pnpm links a directory with a symbolic link where it may make one (on the runner, with a relative target) and with a junction where it may not.
  • A real path is spelled \\?\C:\… with short names written out, the same way for the store and for each link's target, so they compare.
  • A launcher is three files (.bin/<cmd>, .cmd, .ps1) holding absolute paths. After the install, the ones that name the old entry sit inside the old entries.

Proof

PR CI has no Windows job, so the evidence is a dispatched run of ci.yml with os=windows.

  • Run 46922142757 on c38e5084a (Windows Server 2025), which holds the merge with Follow a link that leads out of the project when judging a pnpm store, so Bazel workspaces are covered (#2353) #2443: 22 jobs passed and 24 were skipped by the OS filter. One test shard failed on a single test that is not from this PR (see "CI"), and the summary job with it. The head of this PR has the same tree: it adds a merge of main that changes no file (main then held Judge a pnpm store under a nested modulesDir from the workspace root (#2353) #2437 and Follow a link that leads out of the project when judging a pnpm store, so Bazel workspaces are covered (#2353) #2443 squashed, with the tree this branch already contained) and an empty commit. Before the merge, run 46847576000 on ed6b8d4fd passed the same jobs (24 passed, 24 skipped by the OS filter, none failed), as did 46827236494 on fd42addd8, before the review fixes.
    • Core unit tests: 8,503 passed, 0 failed, 1 ignored. All the tests of the rule run there, with stores linked by junctions and one linked by symbolic links as the runner's pnpm writes them.
    • Real pnpm 11 and 12 (e2e_redirect_pnpm_build): 28 passed, 0 failed. The legs *_registry_route_in_place_install_is_judged_by_every_link, *_under_a_nested_modules_dir and *_survives_resolution_and_cleans_up pass: vex attests after the in-place install, a junction to the old entry brings the refusal back, and the independent link reading agrees. A junction to a directory outside the project brings the refusal back as well, and taking it away clears it.
  • The dead-link codes are pinned by test_links_that_lead_nowhere_fail_with_the_errors_read_as_such, which makes each kind of junction and resolves it. That test also checks each of them against its target. test_link_into_a_drive_that_is_not_there_does_not_lead_nowhere passes there too, but it returns early where a junction to a missing drive letter cannot be made, and a passing test shows no output: whether it made one on the runner is not known, and the code such a junction fails with is still not recorded. The rule does not depend on that code.
  • Locally on macOS, on the same tree: cargo fmt --check, clippy, the core unit tests (9,014 passed), the CLI unit tests (1,105), the apply, cli, rollback, e2e_vex_redirect and e2e_vex_vendor suites, and the real-pnpm suites with the toolchain required (28 and 25 legs).

Not covered

  • The vendored in-place leg on Windows. e2e_vendor_pnpm_build has no leg on the Windows runner, so its in-place steps stay skipped on Windows. The vendored leftover is covered there by the unit test of the rule.
  • Real pnpm writing junctions. The runner may make symbolic links, so pnpm wrote those. Junctions are covered by the unit tests and by the links the legs add themselves.
  • pnpm 12's install record on Windows. pnpm 9.15.9 and 11.27.0 record the virtual store by its absolute path there (read from their source). pnpm 12's legs pass, but its record was not inspected.
  • A junction to a file. The code it fails with was not measured. A code outside the three keeps every entry.
  • A volume without a drive letter, and a file server that denies opening a directory. The handling of both follows from the documented behaviour of Windows and was not run against either.
  • The offline CLI tests for On pnpm 11.20 and newer, vex refuses a hosted patch as not_applied after the in-place pnpm install the scan asks for (new since v5.1.0), and warns falsely in vendored mode: it judges the store entry pnpm leaves behind #2353 (apply --check, e2e_vex_redirect, e2e_vex_vendor, rollback) stay Unix-only.
  • The core unit tests take longer on Windows: 438 s in this run, and 448 s, 324 s and 446 s in the three before, against 185 s before this PR. How much the newly enabled tests add was not isolated.

Two choices for a reviewer

  • file_id opens the path itself (no access rights, FILE_FLAG_BACKUP_SEMANTICS) and hands the file to same_file::Handle::from_file, in place of Handle::from_path, which opens for reading. Nothing is read and no read permission is needed, so a link to a pipe or to a file this user cannot read does not block or fail.
  • test_pnpm_store_linked_with_symbolic_links_is_judged_on_windows fails on a GitHub runner that cannot make a symbolic link, where it would otherwise pass with the file-link cases left out. Off a runner it prints a note and returns.

Code review

/code-review high found four things, all fixed: a link into a drive that is missing from the session, or to a target on a volume without a drive letter, was read as a link that leads nowhere; a directory on a network path that dropped during the sweep was read as a directory that was removed; the vendored in-place leg was switched on for Windows without ever having run there (the skip is back); and every directory above a link's target was opened up to the drive's root, where a file server may deny it.

A second /code-review high pass ran on the merge with #2443 and found five things. None is changed here, so that the code that ran on Windows is the code that lands; all five are tracked in #2456.

  • The node_modules above a linked file is looked up without the drive check (in the diff that was approved, not from the merge). A node_modules there that is a junction into a drive missing from the session reads as none. It takes a link to a file outside the project, below such a junction, in a session that does not see the drive, and it rests on an error code that was not measured.
  • link_leads_nowhere reads the first hop only (also in the approved diff). A relative link whose path passes through a junction into a missing drive is left out. Same conditions; the fix resolves the target level by level, which is new Windows-only code that needs its own run.
  • The home directory told by identity (from the merge) could match another directory on a volume whose driver gives every directory one identity. Not verified that such a volume exists.
  • The missing-drive test passes without testing where the junction cannot be made, and the symbolic-link test fails on any Actions runner without the privilege. Both are stated under "Proof" and "Two choices for a reviewer".

Merged with #2443

#2443 (follow a link out of the project, for Bazel) changes the same function, so this branch now holds the merge of the two, made after both were approved:

Not done: following a link out of the project on Windows, and so a Bazel workspace on Windows. It needs the tests of #2443 to run with junctions, and is tracked in #2456.

CI

pnpm hosted compatibility passes on every pnpm version now that #2434 is on main. The PR checks passed on c38e5084a (55 checks). The push of the merge of main started no workflow run, so an empty commit was pushed after it to run the checks on the head.

One test fails in the Windows run and is not from this PR: quoted_url_credentials::a_hosted_warning_quotes_a_lock_entry_without_its_token (tests/scan), a PyPI scan test that #2445 added to main the same day. PR CI has no Windows job, so this run is the first to run it on Windows. This PR touches no file of that test or of the code it covers.

🤖 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>
…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>
…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>
On Windows `vex` and `apply --check` kept every entry of a pnpm store, so
the upstream entry an in-place install leaves behind still refused the
patch there (#2353). The rule was switched off because it was never built
for junctions.

Measured with real pnpm 11 and 12 on a Windows CI runner: the install
leaves the same entries, every directory link pnpm writes is a link to
Rust's `std` (a symbolic link on that runner, a junction where pnpm may
not make one), and `canonicalize` spells the store and every link target
the same way. So the rule runs there as it does elsewhere. Two steps
needed a Windows reading:

- The identity of a file, which tells the store from another spelling of
  its path, is a `same_file::Handle` there (volume serial number and file
  index). The file is opened with no access to what it holds, as
  `std::fs::metadata` opens it, so nothing is read or waited on. Unix
  keeps `stat`.
- A link that leads nowhere is read from the Windows error code: no such
  file, no such path, a directory link to a file, and a link that cannot
  be resolved (a loop). `std` folds a drive or a network path that cannot
  be reached into `NotFound` as well, and those keep every entry.

The unit tests of the rule run on Windows with junctions. A case that
links a file runs where a symbolic link to one can be made, and the cases
that need `chmod`, a named pipe or the macOS volume spelling stay on
Unix. New tests cover an install record that names the store by its
absolute path (what pnpm writes on Windows), a store linked with Windows
symbolic links, and the errors that dead links fail with. The three
tables report every failing case of a run.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The real-pnpm legs that install over an existing `node_modules` and hold
`vex` against an independent reading of the links were Unix only, since
`vex` kept every store entry on Windows (#2353). They run on every
platform:

- the two workspace legs (`*_in_place_install_is_judged_by_every_link`,
  `*_in_place_install_under_a_nested_modules_dir`) and the warm-checkout
  step of `*_registry_route_survives_resolution_and_cleans_up`;
- the in-place step of the vendored capstone, wherever that suite finds
  a pnpm.

The links a leg adds are made by `pnpm_links::link_dir`: a symbolic link
on Unix, a junction on Windows, which takes no privilege. The package a
dependent loads is found from the dependent's real path, because Windows
folds a `..` in a path before it follows a link. The reading of files
that spell out a store entry looks for `<entry>\` as well, the way a
Windows launcher writes a path.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Windows leaves the lists of layouts where every pnpm store entry is kept
(#2353): the ecosystems guide, the CLI contract and the pnpm
compatibility notes. The guide says that a junction is read as a link
and that a drive or a network path that cannot be reached keeps every
entry. The compatibility notes record what was measured on a Windows CI
runner (the entries an in-place install leaves, the links pnpm writes,
how a real path is spelled, the launchers), what a dead junction fails
with, and which test cases do not run there.

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-verification behavior on Windows (vex / apply) with nuanced filesystem and error-code logic; mitigated by broad unit/e2e coverage but affects security-sensitive “what is actually installed” judgments.

Overview
vex / apply --check on Windows now apply the same pnpm “unlinked store entry” rule as on Unix and macOS, instead of hashing every virtual-store entry because junctions were ignored.

The npm crawler removes the Windows bail-out, resolves junctions and symlinks when deciding which .pnpm entries are reachable, and drops the old judged = !cfg!(windows) gate so split-entry filtering runs on Windows too. Windows-specific I/O handling uses raw error codes for “missing” vs unreachable paths, link_leads_nowhere (including absent drives), not_there for missing files, and FileId via same_file handles so store paths can be compared without the old Unix-only stat shortcut.

Docs (CLI_CONTRACT.md, ecosystems.md, pnpm-compatibility.md) now state junctions count as links and Windows is in the e2e matrix. Tests: cross-platform link_dir / unlink in pnpm_links.rs, registry-route e2e legs on all OSes, many #2353 unit tests de-cfg(unix) with junction-based fixtures; vendored in-place e2e stays skipped on Windows until that runner exists.

Reviewed by Cursor Bugbot for commit ed6b8d4. Configure here.

@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

[agent] PR shepherd: review brief for the approver

What it does. Turns on, for Windows, the rule from #2437/#2430 that leaves out a pnpm store entry nothing links. Junctions and symbolic links are both resolved. A dead link is recognised by Windows' own error codes, never by the broad NotFound kind. File identity is read from a handle opened with no access rights. Before this, vex on Windows still refused a hosted patch as not_applied after the in-place install.

Risk: medium. It changes behaviour only on Windows, and PR CI has no Windows job. The evidence is a dispatched ci.yml run with os=windows on this exact head (46847576000, success). Every unreadable or uncertain case still hashes every entry, so a mistake would most likely leave the old refusal in place, not attest a copy that wasn't patched. Stacked on #2437, so it merges after that one.

Look here

  • [leads_nowhere / link_leads_nowhere](https://github.com/SocketDev/socket-patch/blob/ed6b8d4fd9533aecf893d64d39645b498783601d/crates/socket-patch-core/src/crawlers/npm_crawler.rs#L1186-L1291): the three Windows error codes, the re-check of the target by itself, and the drive/share check
  • not_there: the record, lockfile and sweep reads now go through this instead of NotFound
  • file_id: handle opened with access_mode(0) + FILE_FLAG_BACKUP_SEMANTICS
  • ancestor short-cut: directories above the store are no longer opened
  • the early return removed, plus the Windows tests at L10456 and L10516

Verified

Changes I made: none.

Open questions


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>
…m-store-follow-links

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

Both branches change the rule for a pnpm store entry that nothing links
(#2353): one follows a link that leads out of the project, the other runs
the rule on Windows.

Together: a link to a directory outside the project is followed
everywhere but on Windows, where it keeps every entry, as it did on both
branches before. Following was never run on Windows, where links are made
and resolved another way. A link to a file outside is judged the same way
on every platform.

Tests: the cases that expect a directory outside to be read are not built
on Windows; the keep-every-entry table gains two Windows cases for a link
to a directory outside and above the project. The rule for a file outside
below a `node_modules`, up to the home directory, is tested through the
store on every platform. The real-pnpm leg makes its links out of the
project with a junction on Windows and expects the refusal there.

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

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…m-store-follow-links

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The rule for a link to a file outside the project stops looking for a
`node_modules` at the home directory. The test passed the home directory
by its real path alone, which its path already matches. It now also
passes it as the temp dir spells it: through a link on macOS, and by a
short name without `\\?\` on Windows, where only the identity of the
directory tells that it is the home directory.

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

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@mikolalysenko
Mikola Lysenko (mikolalysenko) changed the base branch from fix/vex-pnpm-store-nested-modules-dir to fix/vex-pnpm-store-follow-links December 2, 2026 16:04
Base automatically changed from fix/vex-pnpm-store-follow-links to main December 2, 2026 16:26
…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>
The push of the merge of main (06bb36e) started no workflow run, so
the required checks never ran on it. This commit changes no file.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
GitHub had an incident with Actions and webhooks when the last two
commits were pushed, and neither started a workflow run. This commit
changes no file.

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
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to no response for status checks Dec 2, 2026
@mikolalysenko
Mikola Lysenko (mikolalysenko) added this pull request to the merge queue Dec 2, 2026
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

[agent] PR shepherd: updated brief for the commits since ed6b8d4

What it does. Unchanged from the earlier brief. Since ed6b8d4 the branch gained merges of its two base branches (since merged to main as #2437 and #2443) and of main, one test-only commit, and two empty commits that re-triggered CI after an Actions incident.

Risk. Low for the new commits: the only non-merge change is a stronger unit test.

Look here.

  • npm_crawler.rs:9735: the test now also passes the home directory as the temp dir spells it (macOS link, Windows short name), which the identity check must still recognise.

Verified. Read 0ba58cc, edd8178 and 9d60916 (the last two change no file). CHANGELOG.md is untouched. ci-ok and clippy are green on 9d60916; no open review threads.

Changes I made. None. The PR left the merge queue at 18:49Z with no merge-group run started for it, so I re-armed auto-merge once and it is back in the queue.


Generated by Claude Code

Merged via the queue into main with commit a95f10c Dec 2, 2026
58 checks passed
@mikolalysenko
Mikola Lysenko (mikolalysenko) deleted the fix/vex-pnpm-store-windows branch December 2, 2026 19:23
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