Repository navigation
Description
[agent] Found by the architecture refactor routine (ledger discussion #2244, lead L71) while running a vendored npm project through its next steps with real npm. Run on main at cfc870f with the binary built from it, npm 10.9.9 on Node 22, and the repository's fixture vendor service.
Problem
A vendored scan of an npm project rewrites package-lock.json and ends with Run \npm install` to update the installed tree. In a working tree where anything created or removed an entry in node_modules/since the last install, thatnpm installprintsup to dateand reinstalls nothing. The package undernode_modules/stays the registry's unpatched copy. Running it again, or with--force, changes nothing. npm ci` is what installs the patched tarball.
What makes a tree like that:
- a
node_modules/.cachedirectory that appears after the install. webpack's filesystem cache creates it on the first build (run here); babel-loader, Prettier's--cache, Storybook and nyc keep their caches in the same directory (not run); - an earlier agent-mode run of socket-patch on the same tree (it stages each file beside the one it replaces, which touches the package directory), including one that was rolled back.
vex notices the mismatch and warns with vendored_tree_out_of_sync, whose remedy is the same no-op: "re-run your package manager's install to resync it". vendor --revert has the mirror image: it says Run \npm install` to resync the installed tree, npm prints up to date, and the vendored copy stays installed while list` says the project has no patches.
Who it hurts: a developer adopting vendored mode on a machine that has built the project before. The scan says Patched 1 package, fixing 1 vulnerability, they run the command it names, npm says up to date, and they keep running and testing the vulnerable code locally. A clean checkout and npm ci (most CI) install the patched tarball, so this is about the working tree and about any pipeline that runs npm install over a kept node_modules.
Yarn 1.22.22, pnpm 10.28.0 and Bun 1.4.4 reinstall the package from the same starting state with their plain install; this is npm only.
Evidence
A project with left-pad 1.3.0 and webpack, and a patch that makes left-pad return socket-patched-1.
$ npm ci
added 117 packages in 1s
$ mkdir node_modules/.cache
$ socket-patch scan --mode vendored --yes; echo "exit $?"
Vendored 1 package.
HIGH left-pad@1.3.0 CVE-2026-0001
Next steps:
1. Commit .socket/vendor/ and the updated lockfiles to make the patches portable.
2. Run `npm install` to update the installed tree, then run `socket-patch vex` to verify the installed patches.
Patched 1 package, fixing 1 vulnerability (1 high).
exit 0
$ npm install
up to date in 324ms
$ node -p 'require("left-pad")("7", 3, "0")'
007
$ socket-patch vendor --check; echo "exit $?"
pkg:npm/left-pad@1.3.0: committed artifact and wiring verified
exit 0
$ socket-patch vex --product pkg:npm/wp-app@1.0.0 -O vex.json; echo "exit $?"
Warning: pkg:npm/left-pad@1.3.0: the installed tree does not match its vendored artifact; the attestation is based on the committed .socket/vendor artifact (the project's lockfile or package-manager config wires it in), 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
$ npm install; npm install --force
up to date in 232ms
up to date in 245ms
$ node -p 'require("left-pad")("7", 3, "0")'
007
$ npm ci
added 117 packages in 1s
$ node -p 'require("left-pad")("7", 3, "0")'
socket-patched-1
The notice about the missing API token and two summary lines are left out.
The same scan and npm install from different starting states:
| Before the vendored scan | npm install afterwards |
Installed left-pad |
|---|---|---|
npm ci and nothing else (control) |
changed 1 package |
patched |
mkdir node_modules/.cache |
up to date |
unpatched |
one npx webpack build with cache: { type: 'filesystem' } |
up to date |
unpatched |
a directory created and removed under node_modules/ |
up to date |
unpatched |
scan --mode agent, then rollback |
up to date |
unpatched |
scan --mode agent, left applied |
up to date |
patched (the agent copy) |
The other direction, over a tree that holds the vendored copy and a node_modules/.cache newer than the install:
$ socket-patch vendor --revert --yes
Reverted 1 vendored package.
Run `npm install` to resync the installed tree with the restored lockfile (it may still hold the vendored bytes if you reinstalled after vendoring).
$ npm install
up to date in 356ms
$ node -p 'require("left-pad")("7", 3, "0")'
socket-patched-1
$ socket-patch list
No patches in this project. Run `socket-patch scan`.
Cause
npm keeps a record of what it installed in node_modules/.package-lock.json and trusts it only while no directory under node_modules/ is newer than the file (assertNoNewer in its shrinkwrap.js: "out of date, updated: node_modules"). Otherwise it reads the tree from disk, and for each package it finds it fills in resolved and integrity from the project's package-lock.json when the version matches (add in the same file: "if we have metadata about this node, and it's a match, then try to decorate it"). A vendored patch keeps the version and changes those two fields. So the rewritten lock itself tells npm that the copy on disk came from the vendored tarball, and npm finds nothing to change. That no-op run then writes the claim into node_modules/.package-lock.json, which is why every later npm install agrees.
In socket-patch, three messages name the command for this state:
- the vendored next step:
flavor_install_commandmapspackage-locktonpm install(CLIcommands/vendor.rs, lines 4989 to 5014). Its comment says "a successful vendor must say how to update it"; - the revert hint:
flavor_revert_install_commandandformat_revert_install_hint(the same file, lines 5016 to 5027 and 917 to 922); vex'svendored_tree_out_of_syncdetail: "re-run your package manager's install to resync it" (CLIcommands/vex.rs, lines 2140 to 2148).
The class has been fixed for the neighbours, one at a time:
- hosted mode's next step for an npm lock is
Reinstall from the updated lockfile (e.g. \npm ci`)(CLIcommands/scan/hosted.rs, line 3751), and that is the wordingCLI_CONTRACT.mdgives for the sharedNext steps:` block of hosted and vendored runs (line 850); - Bun: "Bun's hoisted linker keeps the vendored copy through a plain
bun install(After a Bun rollback orvendor --revert, the advisedbun installkeeps the patched bytes installed on the hoisted linker (Bun reports "no changes") #764), so Bun's needs--force" (flavor_revert_install_command, andBUN_REINSTALL_QUALIFIERin CLIcommands/rollback.rs, lines 513 to 518); - gems: the
vendored_tree_out_of_syncdetail has its own wording because "re-run your install never clears the warning" (vexwarnsvendored_tree_out_of_syncfor every vendored gem afterbundle install, and the remedy it names never clears it because Bundler keeps the unused registry copy #2076, the comment abovevendored_out_of_sync_detail); - Bundler in hosted mode: the contract's line 850 points at another command "since a plain
bundle installkeeps the gems it already has". - Python: pip, PDM, uv and Pipenv keep a same-version install through a plain install or sync after an unwind, so the advisory "names the reinstall that does restore the upstream bytes" (After a hosted or vendored PDM rollback, pdm sync / pdm install keep the patched build installed, though rollback says the next install restores it #477 and After a hosted rollback or vendored revert of a requirements.txt pin, plain
pip install -rkeeps the patched build, though rollback says the next install restores it (andvendor --revertsays nothing) #1953, the header of CLIcommands/pypi_reinstall.rs).
The vendored npm flavor still names the plain install, and its unit test pins it: assert_eq!(flavor_install_command("package-lock"), Some("npm install")) (commands/vendor.rs, line 8040).
Planned fix
flavor_install_commandnamesnpm cifor thepackage-lockflavor, as hosted mode and the contract's line 850 do. The revert hint follows throughflavor_revert_install_command.vex'svendored_tree_out_of_syncdetail gains an npm note beside the Hatch and PDM ones: a plainnpm installcan reportup to dateand keep the old copy, so runnpm ci.- Tests: the mapping, the two messages, and one real-npm test of the sequence above where the suite already runs npm (a vendored project, a directory created under
node_modules/, the named command, then the installed bytes).
The contract settles the wording, so this is not a decision issue. It changes text on stdout and the detail of one warning; no JSON key, code or exit status.
The routine has three PRs open and awaiting review, so no PR is opened for this yet.
Not checked: npm 11 and 12 (the two functions are unchanged in npm 10.9.9; later majors were not run), a workspace member's own node_modules, and hosted mode with real npm (the benchmark's npm project has a stand-in node_modules that npm prunes). Hosted mode rewrites the same two lock fields and keeps the version, so a user who answers its next step with npm install instead of the npm ci it names should meet the same no-op. Seen beside it: npm install left-pad@1.3.0 re-resolves the package from the registry and removes the vendored wiring from the lock, so it is not a remedy either.
Generated by Claude Code
Activity
refactor: #2339 and #2340 filed; build caches ran