Skip to content

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

Done

Description

[agent] Filed by the architecture refactor routine. Checked on main at cfc870f with the built binary, real pnpm 12.23.0 (the registry's latest), 11.29.0 and 10.28.0, and node 22. The released v5.1.0 binary ran the same project as the control.

Kind: bug, and structure that keeps causing bugs. vex judges a store entry that no install loads. That was fixed for Bun's store in vex (#599) and for pnpm's store in the scan (#1197). vex over a pnpm store was left out, and since #2167 the default mode produces such an entry on every pnpm 11.20 or newer.

Problem

pnpm keeps the store entry of a package whose lock key changed, with nothing linking to it: pnpm 7 to 11 for up to 7 days, pnpm 12 until pnpm prune (docs/ecosystems.md, lines 770 to 775, says so).

  • Hosted mode, pnpm 11.20 and newer. Since Route hosted pnpm pins through one named registry per patch #2167 (5d8378e, not in a release yet) the scan routes each patched release through its own named registry. The lock key becomes left-pad@socket-<id>:1.3.0, so the store entry becomes left-pad@socket-<id>+1.3.0. The pnpm install that the scan's next steps ask for links the project to the new entry and leaves left-pad@1.3.0, with upstream's bytes, in the store. vex counts it as an installed copy and omits the patch: not_applied, exit 1, no document. The message says the package is not installed and to reinstall; the reinstall prints "Already up to date".
  • Vendored mode, every pnpm. The vendored key (left-pad@file:.socket/vendor/…) has always renamed the entry. There the same check is a warning, vendored_tree_out_of_sync, whose remedy ("re-run your package manager's install") changes nothing.

Who it hurts: a pnpm project scanned over an existing node_modules (a developer's checkout, or a CI job that restores node_modules from a cache). A clean install is not affected. v5.1.0 is not affected in hosted mode: it keeps the lock key, so pnpm reuses the one entry.

Evidence

Hosted mode, pnpm 12.23.0

A real project (left-pad 1.3.0 from the registry, "packageManager": "pnpm@12.23.0"). The patch API is a stand-in: the search, reference and view answers in the shapes the repository's bench mock uses, the reference's npmRegistryUrl (core api/types.rs, line 313), and the patched tarball with its version document at that address.

$ pnpm install                                   # upstream left-pad 1.3.0
$ socket-patch scan
Switched 1 package to hosted patches; rewrote 2 files.
Next steps:
  1. Commit pnpm-lock.yaml and pnpm-workspace.yaml to keep the hosted patches.
  2. Reinstall from the updated lockfile, then run `socket-patch vex` to verify the installed patches.
$ pnpm install
dependencies:
- left-pad 1.3.0
+ left-pad socket-22222222:1.3.0                 # exit 0
$ readlink node_modules/left-pad
.pnpm/left-pad@socket-22222222+1.3.0/node_modules/left-pad
$ grep -c "socket-patch test marker" node_modules/left-pad/index.js
1                                                # the copy node loads is patched
$ ls node_modules/.pnpm | grep left-pad
left-pad@1.3.0
left-pad@socket-22222222+1.3.0
$ find node_modules -lname "*left-pad@1.3.0*" | wc -l
0                                                # nothing links to the old entry
$ socket-patch vex --product pkg:generic/app@1.0.0 -O vex.json
Warning: omitting pkg:npm/left-pad@1.3.0 from VEX: the patched files still hold the original content (not_applied)
Error: No applied patches with vulnerability metadata to attest.
The patched packages are not installed yet: the installed copies still hold their original files. Reinstall from the lockfile (hosted or vendored patches) or run `socket-patch apply` (agent-mode patches), then run `socket-patch vex` again.
                                                 # exit 1, no vex.json; --json: error.code no_applicable_patches
$ pnpm install
Already up to date
$ socket-patch vex --product pkg:generic/app@1.0.0 -O vex.json      # the same, exit 1

Three controls, each over the same files:

$ rm -r node_modules/.pnpm/left-pad@1.3.0 && socket-patch vex …     # or: pnpm prune
Wrote OpenVEX document with 1 statement to vex.json                  # not_affected, exit 0
$ pnpm install --frozen-lockfile && socket-patch vex …               # a clean checkout of the three committed files
Wrote OpenVEX document with 1 statement to vex.json                  # exit 0
$ socket-patch scan && pnpm install && socket-patch vex …            # the v5.1.0 binary, same project, pnpm 12.23.0
Wrote OpenVEX document with 1 statement to vex.json                  # trustLockfile, one entry: left-pad@1.3.0

pnpm 11.29.0 gives the same refusal and the same two store entries. In the same state scan --vex writes its document and says to "run socket-patch vex after installing to verify against the installed tree", which is the command that refuses.

Vendored mode, pnpm 10.28.0 and 12.23.0

The same package, vendored against the repository's fixture vendor service:

$ socket-patch vendor
Vendored 1 package.
  2. Run `pnpm install` to update the installed tree, then run `socket-patch vex` to verify the installed patches.
$ pnpm install                                   # Packages: +1 -1
$ grep -c "socket-patch test marker" node_modules/left-pad/index.js
1
$ ls node_modules/.pnpm
left-pad@1.3.0
left-pad@file+.socket+vendor+npm+<uuid>+left-pad-1.3.0.tgz
$ socket-patch vendor --check
pkg:npm/left-pad@1.3.0: committed artifact and wiring verified
$ socket-patch vex --product pkg:generic/app@1.0.0 -O vex.json
Warning: pkg:npm/left-pad@1.3.0: the installed tree does not match its vendored artifact; […] but the live tree carries different bytes — re-run your package manager's install to resync it.
Wrote OpenVEX document with 1 statement to vex.json                  # exit 0
$ pnpm install
Already up to date
$ socket-patch vex …                             # the same warning
$ pnpm prune && socket-patch vex …               # no warning

What the two orphan tests say about those trees

A throwaway unit test called both functions on the three trees pnpm left (hosted on 12.23.0, vendored on 10.28.0 and 12.23.0). The output is the same for each:

scan's test (orphaned_pnpm_store_entry_sync): left-pad@1.3.0 -> orphan=false
vex's filter (retain_live_store_copies) kept: ["left-pad@1.3.0", "left-pad@socket-22222222+1.3.0"]

Where

Planned fix

One rule for "this pnpm store entry is live", used by the scan's listing and by retain_live_store_copies, in place of the name-and-version test:

  • an entry is live when a link reaches it from the importer's node_modules, the store's hoist directory or a live entry's node_modules. That is the rule Bun's store already has (live_bun_store_entries_sync), and neither stale entry above has a link;
  • when the walk cannot tell, every entry is kept, as today;
  • rollback and remove keep resolving without it, so a patched orphan is still restored.

Tests: the three store shapes above as unit fixtures (the hosted route's entry, the vendored file+ entry, and the upgraded-away entry of #1197), and an in-place pnpm install leg in the real-pnpm hosted and vendored suites that ends in vex.


Generated by Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent:triagedarch-auditbugpriority:p1

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions