Skip to content

Follow a link that leads out of the project when judging a pnpm store, so Bazel workspaces are covered (#2353) - #2443

Merged
Mikola Lysenko (mikolalysenko) merged 6 commits into
fix/vex-pnpm-store-nested-modules-dirfrom
fix/vex-pnpm-store-follow-links
Dec 2, 2026
Merged

Mikola Lysenko (mikolalysenko) merged 6 commits into
fix/vex-pnpm-store-nested-modules-dirfrom
fix/vex-pnpm-store-follow-links

Conversation

@mikolalysenko

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

Copy link
Copy Markdown
Collaborator

Stacked on #2437. Part of #2353.

Problem

#2430 keeps every pnpm store entry when a link in the project leads to a directory outside it, because what that directory's node_modules link was not read. One such link switches the fix off for the whole project: the entry an in-place install leaves behind still refuses the patch (not_applied), or still warns vendored_tree_out_of_sync.

Every Bazel workspace has such links (bazel-bin, bazel-out, bazel-testlogs, bazel-<name>), and so does a project with a link: dependency on another checkout.

Fix

A link to a directory outside what is read is followed, since node loads what is behind it from where it really is:

  • the directory behind such a link is read like the project: every link below it, in every directory;
  • so is each node_modules in a directory above it, which is where node looks up the packages of what it loads from there. A member that left the workspace keeps the links pnpm wrote for it. A node_modules that is a link itself is followed like any other link;
  • a directory is read once, however many links lead into it and in whatever order. Bazel's bazel-bin, bazel-out and bazel-<name> lead to directories inside each other;
  • one budget of 500,000 holds for everything read: the directories, the links, and each node_modules looked for. Every link found goes through the same checks as the ones in the project (another spelling of the store's path, the store itself, an entry that is not listed);
  • the home directory and what lies above it are not read: a node_modules there is not looked at, and a link to the home directory or above keeps every entry. The home directory is told by identity, so another spelling of its path (/System/Volumes/Data/Users/… on macOS) is the home directory still;
  • every entry is still kept when a directory cannot be read, or the budget runs out. What was read is shared by the stores of one run, so a tree over the budget is walked once.

A link to a file outside the project is handled as in #2430: it keeps every entry when a node_modules sits in a directory above the file, because what the file loads by paths of its own is not read.

With #2446

#2446 (the rule on Windows) is stacked on this PR and holds the merge of the two. On this branch alone every entry is still kept on Windows, and its tests are Unix-only. In #2446 a link to a directory outside the project keeps every entry on Windows, as it did before both PRs: following such a link was never run there, so it is not switched on there. Bazel on Windows is not claimed by either PR.

One choice for a maintainer

Following a link out of the project lists directories and resolves links outside the git checkout: Bazel's output tree and the contents of its external repositories are there. No file is opened, nothing read there is reported, and the budget bounds it. Elsewhere a project run reads no project file outside its checkout, and this is the one place that leaves it.

Three things are given up against #2430, which kept every entry for any such link:

Keeping every entry when a link leads out of the checkout is one condition if that is preferred; Bazel workspaces would then stay as on main.

Proof

  • A real Bazel workspace (Bazel 9.3.2, aspect_rules_js 3.6.0, about 1,200 packages, production patch service): the bazel-* links lead into an output tree of about 7,000 directories and 6,700 links, and from there into the contents of the external repositories (about 9,200 directories). After a vendored scan and pnpm install over the existing node_modules, Stop vex refusing a hosted or vendored pnpm patch over the store entry an in-place install leaves behind (#2353) #2430's build warns vendored_tree_out_of_sync; this build attests without a warning. A link to the old entry placed in bazel-bin, in an external repository's contents (two links away), or in a node_modules above the output tree's workspace directory brings the warning back, and removing it clears it. vex takes 1.5 s there instead of 0.6 s (release builds).
  • Production patch service, real pnpm 9.15.9, 10.34.9, 11.29.0 and 12.25.1, hosted and vendored: 134 checks, 0 failures. Besides the checks of Stop vex refusing a hosted or vendored pnpm patch over the store entry an in-place install leaves behind (#2353) #2430: a link to a directory outside the project that links nothing changes nothing; once a node_modules above it links the old entry, vex judges the old copy again; a link to a file outside, below a node_modules, keeps every entry as before.
  • Real pnpm 11 and 12 (*_in_place_install_is_judged_by_every_link): a link from the project to a directory beside it that links nothing changes nothing; once that directory's node_modules links the upstream package, or is itself a link into the upstream entry, vex refuses the patch, and the independent link reading (which follows links out the same way, in its own code) finds the link. These steps run with the test's own directory as the home directory, so nothing the machine keeps above it is read.
  • Unit tests: a directory outside whose node_modules links the leftover, one whose node_modules is a link into the leftover's entry, a directory below such a node_modules, a chain of two directories outside (each kept while the link in the project is there, left out once it is gone); directories outside that link nothing; an unreadable directory outside; the home rule (a node_modules in the home directory and above it is not read, one below it is, a link to the home directory keeps every entry, also by another spelling of its path); a node_modules that is a link, with the node_modules above what it leads to; and one budget across the project and directories outside that lie inside each other, each read once.
  • Locally on macOS: cargo fmt --check, cargo clippy --locked --workspace --all-features -- -D warnings, the core unit tests (8,928), 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 (28 and 25 legs).

Code review

Three /code-review high passes. Fixed: a linked node_modules above a followed directory was not followed; a link to the home directory was read like any other; directories inside each other were read and charged twice; the pass was repeated per store; a file outside was judged before every directory was read; the bookkeeping of the directories read was quadratic in their number; the node_modules lookups were not charged to the budget; the home directory was told by its path alone; the real-pnpm steps read node_modules above the machine's temp directory; the independent reading missed a linked node_modules; the docs still said nothing above the scanned directory is read.

Not changed, and why: the three points under "One choice for a maintainer" were raised as findings. Each follows from reading what a link leads to at all, within the limits #2430 already has, so they are stated there for the decision and not worked around.

CI

pnpm hosted compatibility passes on every pnpm version now that #2434 is on main and main is merged in. 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. Locally on the merged head (macOS): cargo fmt --check, clippy, the core unit tests (8,995 passed), 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 (28 and 25 legs). One interactive rollback test that this PR does not touch failed once while two builds ran beside it, and passed three reruns.

🤖 Generated with Claude Code

…pnpm entry

A link in the project to a directory outside it kept every pnpm store
entry, because what that directory's `node_modules` link was not read
(#2430). One such link switched the fix of #2353 off for the whole
project, and every Bazel workspace has four of them (`bazel-bin`,
`bazel-out`, `bazel-testlogs`, `bazel-<name>`); a `link:` dependency on
another checkout is one too.

Such a link is now followed, since node loads what is behind it from
where it really is. A directory behind it is read like the project. So
is each `node_modules` in a directory above it, or above a file behind
such a link, which is where node looks up the packages of what it loads
from there: 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, as
in git's own lookup. One budget of 500,000 directories and links holds
for everything read, every link goes through the same checks as the ones
in the project, and every entry is still kept when a directory cannot be
read or the budget runs out.

This also replaces the rule for a link to a file outside the project
(every entry kept when a `node_modules` sits above the file): those
`node_modules` are read, so one that links nothing changes nothing.

Measured in a Bazel 9.3.2 workspace that links about 1,200 packages with
aspect_rules_js 3.6.0: about 7,000 directories and 6,700 links behind the
`bazel-*` links, and 9,200 directories of external repository contents
behind those. After a vendored scan and the in-place install, vex attests
without a warning; a link to the upstream entry in `bazel-bin`, in an
external repository's contents or in a `node_modules` above the output
tree's workspace directory brings the warning back.

Following the links lists directories and resolves links outside the git
checkout. No file is opened there.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Following a link out of the project was done per store and per link, which
left several gaps the review found:

- A `node_modules` above a directory outside the project that is itself a
  link was not followed, so a link into the store behind it went unread.
- A link to the home directory, or to one above it, was read like any
  other directory. It now keeps every entry, and no `node_modules` at the
  home directory or above it is looked at.
- Bazel's `bazel-bin`, `bazel-out` and `bazel-<name>` lead to directories
  inside each other. Each was read in full and charged against the budget
  again. A directory is now read once, around what was read already.
- Each store of a project repeated the whole pass, and a pass that failed
  was repeated as well. The links reached from a tree are now kept for the
  run, failures included.
- A link to a file outside the project is handled as before this branch:
  it keeps every entry when a `node_modules` sits in a directory above the
  file. It is judged after every directory is read, so a file inside a
  directory that a later link leads to is not held against a `node_modules`
  that was read.

The unit tests take the home directory as a value, so nothing of the
machine's own home or temp directory is read by them.

Part of #2353.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Review findings on following a link out of the project:

- The home directory was told by its path alone, so a link that spells it
  another way (macOS reaches it under /System/Volumes/Data as well) had
  the whole home directory read. It is told by identity now.
- Each directory read was held against every directory read before it.
  With many separate directories outside that is quadratic. They are kept
  in order, and those below one are found by range.
- A `node_modules` looked for above a directory outside was not charged
  to the budget. Each lookup counts now.
- The real-pnpm steps read `node_modules` in every directory above the
  machine's temp directory. They run with the test's own directory as the
  home directory.
- The independent reading in the tests did not record a `node_modules`
  that is a link, so it missed one that leads into the store. It records
  it and reads what lies above its target, and a leg now makes such a
  link.
- The docs still said nothing above the scanned directory is read. A
  directory above it is read when a link leads to it or below it.
- Two doc comments named a function that was renamed.

Part of #2353.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…s-dir' into fix/vex-pnpm-store-follow-links

# Conflicts:
#	crates/socket-patch-cli/CLI_CONTRACT.md
@mikolalysenko
Mikola Lysenko (mikolalysenko) marked this pull request as ready for review December 2, 2026 09:14
@cursor

cursor Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes filesystem traversal and patch attestation for pnpm/Bun installs, including paths outside the git checkout, though bounded by home-dir rules and a sweep budget with extensive test coverage.

Overview
vex and apply --check no longer treat every pnpm virtual-store entry as “live” just because a symlink leaves the project. Outbound directory links are now followed the way Node resolves modules: the target tree is swept for symlinks, each ancestor’s node_modules is considered (including when it is itself a link), reads are deduplicated, and a single 500,000 link/directory budget spans the project plus anything reached this way—stopping at the home directory and above.

That fixes false not_applied / vendored_tree_out_of_sync when stale store entries are only reachable via bazel-* output trees, link: deps on sibling checkouts, or former workspace members outside the repo. Behavior when traversal is incomplete (unreadable paths, budget, link into home) is unchanged: every entry stays live.

Docs (CLI_CONTRACT.md, ecosystems.md, pnpm compatibility notes) and tests (core crawler, shared pnpm_links, e2e route_vex with HOME override) are updated to match.

Reviewed by Cursor Bugbot for commit ace988a. Configure here.

@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

[agent] PR shepherd: review brief for the approver

What it does. Part of #2353, stacked on #2437. When vex / apply --check decides which pnpm store entries are still linked, a link that leads out of the project (Bazel's bazel-* links, a link: dependency on another checkout) used to switch the rule off and keep every entry. Now the directory behind that link is read too, along with each node_modules above it. The home directory and what lies above it are never read, and one 500,000 budget covers everything read. So in a Bazel workspace the leftover upstream entry no longer refuses the patch or warns vendored_tree_out_of_sync.

Risk: medium. It only lists directories and resolves links, opens no file and reports nothing it reads outside. Every failure (unreadable directory, budget spent, a link to home or above) falls back to keeping every entry, which is today's stricter behaviour. The real cost is time and scope: a project run now lists directories outside its git checkout, and a link to a large tree is walked until the budget runs out.

Look here

Verified

Changes I made. None.

Open questions

  1. Is it acceptable for a project run to list directories and resolve links outside the git checkout, bounded by the budget and the home rule? The PR's "One choice for a maintainer" section covers this. Without it, Bazel workspaces stay as on main. Approving means yes.
  2. Windows: Judge a pnpm store by its links on Windows (#2353) #2446 is stacked on the same base and changes the same function. Whichever of the two lands second turns this walk on for Windows, and this PR's tests are Unix-only. Make sure the second one to merge runs them on Windows.
  3. Auto-merge can't be armed while this PR is stacked (the API answers "not supported for stacked pull requests"). Once Judge a pnpm store under a nested modulesDir from the workspace root (#2353) #2437 merges and this PR's base moves to main, a later run arms it.

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

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

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 7beca2f Dec 2, 2026
45 checks passed
@mikolalysenko
Mikola Lysenko (mikolalysenko) deleted the fix/vex-pnpm-store-follow-links 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.

3 participants