Repository navigation
Description
[agent] Found by the architecture refactor routine (lead L141). Run on main at 6280589 with real Yarn 4.12.0, and again with 4.0.2 and 4.19.0.
The problem
Vendored mode wires a Yarn berry patch with a resolutions entry keyed by the package's name alone (core vendor/yarn_berry_lock.rs, line 461):
"resolutions": { "left-pad": "file:./.socket/vendor/npm/<uuid>/left-pad-1.3.0.tgz" }Yarn applies a name-only selector to every descriptor of that name, whatever its range and whoever depends on it. vendor knows this. When the lock already holds another version, it refuses, and says why (line 1527, vendor_override_conflict):
yarn.lock also resolves left-pad@0.0.3 (`"left-pad@npm:0.0.3"`); the name-keyed resolutions
entry vendoring writes would move that version too — refusing
That check runs once, at vendor time. The selector stays in package.json afterwards, and from then on it moves every version that arrives later, with no message from Yarn and none from socket-patch:
- A dependency added later that needs another version of the package gets the vendored release.
line-numbers@0.2.0declaresleft-pad: 0.0.3; in a project that vendored a patch forleft-pad@1.3.0it runs on 1.3.0. yarn up <package>@<version>of the vendored package installs nothing new.package.jsongets the new version,yarnexits 0, andnode_moduleskeeps the vendored release. A developer who upgrades to the release that fixes the vulnerability upstream stays on the old one.
vendor --check passes in both states, a re-run of vendor says already_vendored, and list and vex report nothing unusual.
The other writers do not do this. Hosted mode on the same package manager keys the selector by the locked descriptor ("left-pad@npm:1.3.0"), vendored pnpm writes a name@version override, and the vendored Bun backend edits lock entries because "a name-keyed override collapses EVERY version" (core vendor/bun_lock.rs, line 14).
Who it hurts: any Yarn 4 project in vendored mode, the first time its tree gains a second version of a patched package (common for semver, minimatch, glob, debug and the like), or the first time someone upgrades the patched package. The first case can break the build at run time with no change in any file that names the cause; the second leaves a team believing it upgraded.
Evidence
One project, {"dependencies": {"left-pad": "1.3.0"}}, nodeLinker: node-modules, installed by Yarn 4.12.0. Three copies: untouched, after scan --mode hosted, and after vendor (the artifact came from the repository's fixture vendor service, the one e2e_vendor_yarn_berry_build uses). Then one everyday command in each:
| Project | yarn add line-numbers@0.2.0: the left-pad that line-numbers loads |
yarn up left-pad@1.2.0: the left-pad installed |
|---|---|---|
| no patch | 0.0.3 | 1.2.0 |
| hosted | 0.0.3 (the root keeps the patched 1.3.0) | 1.2.0 (upstream; the pin lets go) |
| vendored | 1.3.0, the vendored release | 1.3.0, the vendored release; package.json says 1.2.0 |
The vendored project after yarn add line-numbers@0.2.0 (exit 0; Yarn prints only + line-numbers@npm:0.2.0):
$ find . -path '*/node_modules/left-pad/package.json'
./node_modules/left-pad/package.json # 1.3.0, patched; no copy under line-numbers
$ grep -n 'left-pad' yarn.lock
12: left-pad: "npm:1.3.0"
16:"left-pad@file:./.socket/vendor/npm/1a2b…/left-pad-1.3.0.tgz::locator=app%40workspace%3A.":
18: resolution: "left-pad@file:./.socket/vendor/npm/1a2b…/left-pad-1.3.0.tgz#…"
28: left-pad: "npm:0.0.3" # line-numbers' own range; no entry resolves it
$ socket-patch vendor --check --json → exit 0, "vendor_check_ok", "committed artifact and wiring verified"
$ socket-patch vendor --json → exit 0, "already_vendored"
$ socket-patch vex --offline … → exit 0, not_affected for pkg:npm/left-pad@1.3.0
The vendored project after yarn up left-pad@1.2.0 (exit 0):
package.json: "dependencies": {"left-pad": "1.2.0"}, "resolutions": {"left-pad": "file:./.socket/vendor/…/left-pad-1.3.0.tgz"}
node_modules/left-pad: version 1.3.0, patched
$ socket-patch vendor --check --json → exit 0, "vendor_check_ok"
Yarn 4.0.2 and 4.19.0 give the vendored yarn add row the same way: one left-pad, 1.3.0.
When both versions are in the lock before vendoring, vendor exits 1 with the refusal quoted above (ran). So the state vendor refuses to create is the state the selector creates later.
What a scoped selector does
The same vendored tree with the key changed by hand to the locked descriptor, "left-pad@npm:1.3.0": "file:./.socket/vendor/…/left-pad-1.3.0.tgz", Yarn 4.12.0:
yarn install --immutable --check-cacheexits 0 and leaves the lockvendorwrote byte for byte;yarn add line-numbers@0.2.0givesline-numbersits 0.0.3 and keeps the patched 1.3.0 for the root;yarn up left-pad@1.2.0installs 1.2.0, andvendor --checkonmainthen exits 1 and names the way out (dependency removed: no lockfile resolves pkg:npm/left-pad@1.3.0 any more (it was upgraded or uninstalled) … run socket-patch scan --mode vendored --prune);vendor --checkandvexonmainalready accept it (exit 0,vendor_check_ok,not_affected).
There is one trade. A later range of the same release (a workspace member adding "left-pad": "^1.3.0") is covered by the name-only selector and not by the scoped one: Yarn locks a second, upstream copy. main already catches that state: vendor --check exits 1 (copy unpatched: … lock entry "left-pad@npm:^1.3.0" installs it from the registry), and vex withholds the statement. It is the trade hosted mode documents ("A range of the package added after the pin … re-running scan --mode hosted adds a selector for it").
The writer and the revert on main know only the name-only key: over the hand-scoped tree vendor refuses it as a user's override (vendor_override_conflict) and vendor --revert stops at vendor_lock_still_wired_revert_blocked.
Planned fix
In core vendor/yarn_berry_lock.rs: write one selector per descriptor the replaced lock entry is keyed by, as the hosted writer does; recognise both spellings as ours on a re-run and on vendor --revert, and move a name-only selector an earlier release wrote to the scoped one on the next vendor. The vendor-time refusal of a second version then has nothing left to guard, so a project that holds two versions of a package becomes vendorable.
Tests: a real-Yarn case in e2e_vendor_yarn_berry_build (after vendoring, yarn add line-numbers@0.2.0 leaves 0.0.3 under line-numbers, and yarn up left-pad@1.2.0 installs 1.2.0 with vendor --check reporting dependency removed), and unit tests for the two spellings in the writer and the revert.
This changes the key vendor writes into package.json. If a maintainer prefers to keep the name-only selector, the alternative is a check in vendor --check and vex for a lock dependencies: range, or a root range, that the vendored version does not satisfy. That reports the state at the next check; it does not stop the install.
Not run
Windows and macOS; the PnP and pnpm linkers; Yarn 2 and 3 (vendored mode refuses them); a workspace with members beyond the one case above; a catalog dependency; a real package with two majors in one tree (the mechanism is Yarn's, not the package's).
Generated by Claude Code
Activity
mikolalysenko commentedon Dec 2, 2026
[agent] Two more runs on
mainat 6280589, for whoever takes this.The other npm-family backends in vendored mode. The same project and the same two commands, each with its real tool (npm 10.9.9, pnpm 10.28, Yarn 1.22.22, Bun), vendored through the same fixture service:
line-numbers@0.2.0: theleft-padit loadsleft-padto 1.2.0: installed, andvendor --checkdependency removedleft-pad@1.3.0override)dependency removeddependency removeddependency removedvendor_check_okdependency removedis the message "no lockfile resolves pkg:npm/left-pad@1.3.0 any more (it was upgraded or uninstalled) … runsocket-patch scan --mode vendored --prune". Yarn berry is the one backend of the five that never reaches it.The revert already knows the state. In the Yarn berry project after
yarn add line-numbers@0.2.0:So the reader that finds a descriptor the vendored version does not satisfy exists, for the revert (#759, 4353a7c). While the patch is vendored nothing runs it:
vendor --check, a re-run ofvendorandvexall pass over the same lock. It also means the build changes twice:line-numbersmoves to 1.3.0 when it is added, and back to 0.0.3 when the patch is reverted or replaced.Generated by Claude Code
mikolalysenko commentedon Dec 2, 2026
[agent] A third way in, and likely the common one: the patched package is a dependency of a dependency, at an old version.
A project that depends on
line-numbers@0.2.0only, which bringsleft-pad@0.0.3.vendorwires a patch forleft-pad@0.0.3("resolutions": {"left-pad": "file:…/left-pad-0.0.3.tgz"}); a freshyarn install --immutable --check-cachepasses and the patched file is installed. Then the developer adds the current release for their own code, Yarn 4.12.0:The one
left-padinnode_modulesis the vendored 0.0.3, and the application's ownrequire("left-pad")loads it.The rest of this case is clean on
mainat 6280589: the transitive pin survives the fresh install,vex --offlineattests it, andvendor --revertputspackage.jsonandyarn.lockback byte for byte.Generated by Claude Code
refactor: #2450 filed; real Yarn berry ran