Repository navigation
Description
[agent] Found by the architecture refactor routine on main at cfc870f, with real yarn 1.22.22, real npm 10.9.9 and the binary built from main.
The problem
Hosted mode keeps no record of a lock entry's original. rollback and remove rebuild it from a registry's version document. Which registry they ask differs by lock:
pnpm-lock.yaml,bun.lock,bun.lockb, a yarn berryyarn.lockandvlt-lock.jsonask the registry the project resolves the package against (its.npmrc,.yarnrc.yml,bunfig.toml, the vlt node's registry), and fall back to the default one with anupstream_registry_fallbackwarning.package-lock.json/npm-shrinkwrap.jsonand a yarn classicyarn.lockask the default registry only (registry.npmjs.org, orSOCKET_NPM_REGISTRY). The project's.npmrcor.yarnrcis not read.
So in a project that installs through a mirror (Artifactory, Nexus, Verdaccio, a cloud artifact registry), the last two give a lock back that the project never had:
- yarn classic: the entry comes back as
https://registry.yarnpkg.com/…. yarn 1 fetches a lock's URL as written, so the next cold install goes around the mirror. Where only the mirror is reachable (an allow-listed or air-gapped CI),yarn install --frozen-lockfilefails.rollbackexits 0 and warns of nothing. - npm: the entry comes back as
https://registry.npmjs.org/…. npm swaps that host for the configured registry by default, sonpm cistill works; withreplace-registry-host=neverit fails. The committed lock differs from the one before the scan either way. - both: on a machine that cannot reach the public registry the undo is refused, although the project's own mirror answers. The message names the public URL and
git checkout -- <lock>; it does not nameSOCKET_NPM_REGISTRY, which is the one way out and appears inCLI_CONTRACT.mdonly (one table row).
This is the class of #908 and #521 (yarn berry and vlt), #919 (pnpm) and #992 (bun), fixed one lock at a time. These two locks were left.
Evidence
Five locks, the same project shape
The bench's hosted fixtures (60 packages, one patched), each turned into a mirror project: the registry setting names http://127.0.0.1:18081/, and the lock's URLs are that mirror's. Then a real scan in hosted mode against the bench's patch API, then rollback --yes. Two stand-in registries log what they are asked: the mirror on 18081, and the default one (SOCKET_NPM_REGISTRY), whose documents carry registry.npmjs.org tarball URLs as npmjs's do.
| Lock | Asked for the version document | Both registries up | The default registry unreachable |
|---|---|---|---|
package-lock.json |
the default registry; the mirror gets no request | exit 0, no warning about it; resolved is https://registry.npmjs.org/… |
exit 1, hosted_restore_refused; the lock stays hosted |
yarn.lock (classic) |
the default registry; the mirror gets no request | exit 0, no warning about it; resolved is the default registry's URL |
exit 1, hosted_restore_refused; the lock stays hosted |
pnpm-lock.yaml |
the mirror | exit 0; the lock is byte for byte the one before the scan | exit 0; the same |
bun.lock |
the mirror | exit 0; the registry slot is the mirror's tarball URL | exit 0; the same |
yarn.lock (berry) |
the mirror | not comparable here: the bench's patch server has no upstream-checksum document, so the run stops after the lookup |
The npm row, as a diff of the lock before the scan against the lock after the rollback:
< "resolved": "http://127.0.0.1:18081/fefiba30/-/fefiba30-25.24.3.tgz",
---
> "resolved": "https://registry.npmjs.org/fefiba30/-/fefiba30-25.24.3.tgz",
The refusal, with no SOCKET_NPM_REGISTRY and the public registry unreachable:
$ socket-patch rollback --yes
Error: Cannot restore pkg:npm/fefiba30@25.24.3 to its upstream registry entry: fefiba30@25.24.3: GET https://registry.npmjs.org/fefiba30/25.24.3: error sending request for url (https://registry.npmjs.org/fefiba30/25.24.3): client error (Connect): tunnel error: failed to create underlying connection: tcp connect error: Connection refused (os error 111); restore it from version control instead (`git checkout -- package-lock.json`)
# exit 1
The pnpm project in the same network:
$ socket-patch rollback --yes
Restored pkg:npm/dehino30@24.21.11 to its upstream registry entry # exit 0; the mirror's log: GET /dehino30/24.21.11
Real yarn 1.22.22
A real left-pad 1.3.0 served by a stand-in mirror on loopback. "Behind the firewall" is a shell in which only loopback answers.
$ cat .yarnrc
registry "http://127.0.0.1:18083/"
$ yarn install # behind the firewall: exit 0, through the mirror
$ grep resolved yarn.lock
resolved "http://127.0.0.1:18083/left-pad/-/left-pad-1.3.0.tgz#5b8a3a7765dfe001261dde915589e782f8c94d1e"
# the entry pinned to the patch server, as a hosted scan writes it; then, on a machine that reaches the public registry:
$ socket-patch rollback --yes --patch-server-url https://patch.test
Restored pkg:npm/left-pad@1.3.0 to its upstream registry entry
Note: 1 unwired package keeps its patched bytes in installed trees until the next package-manager install.
# exit 0; the mirror's log is empty
$ grep resolved yarn.lock
resolved "https://registry.yarnpkg.com/left-pad/-/left-pad-1.3.0.tgz#5b8a3a7765dfe001261dde915589e782f8c94d1e"
# CI behind the firewall: a fresh checkout and a cold cache
$ yarn install --frozen-lockfile
info There appears to be trouble with your network connection. Retrying...
error Error: https://registry.yarnpkg.com/left-pad/-/left-pad-1.3.0.tgz: tunneling socket could not be established, cause=connect ECONNREFUSED 127.0.0.1:9
# exit 1; the mirror's log is empty
# the same checkout with the lock from before the scan
$ yarn install --frozen-lockfile # exit 0; the mirror's log: GET /left-pad/-/left-pad-1.3.0.tgz
remove pkg:npm/left-pad@1.3.0 --yes writes the same entry. With SOCKET_NPM_REGISTRY=http://127.0.0.1:18083 the rollback asks the mirror and the lock comes back byte for byte.
The host changes for a project on the public registry too. With registry "https://registry.npmjs.org/" in .yarnrc, yarn writes registry.npmjs.org URLs, and after a scan and a rollback the entry reads registry.yarnpkg.com: a second host for an allow-list, and a changed line in a lock the user meant to put back.
Real npm 10.9.9
The same mirror, registry=http://127.0.0.1:18083/ in .npmrc:
$ socket-patch rollback --yes --patch-server-url https://patch.test # exit 0; the mirror's log is empty
< "resolved": "http://127.0.0.1:18083/left-pad/-/left-pad-1.3.0.tgz",
---
> "resolved": "https://registry.npmjs.org/left-pad/-/left-pad-1.3.0.tgz",
$ npm ci # behind the firewall, cold cache: exit 0 (npm asks the mirror for /left-pad/-/left-pad-1.3.0.tgz)
$ npm ci --replace-registry-host=never # exit 1: npm asks registry.npmjs.org
Where
Core patch/redirect/upstream/npm.rs. fetch_dists (lines 22 to 33) reads the default registry and has two callers: restore_npm_locks (line 235) and restore_classic (line 399). The other five restores call fetch_dists_on with the project's registry: berry (line 916), pnpm (line 2049), bun.lock (line 2868), bun.lockb (upstream/bun_lockb.rs, line 110) and vlt (upstream/vlt.rs, line 247).
The earlier fixes, from git log -S'fetch_dists_on':
- 216a750, "Fix npm-family restore ignoring project registry (Hosted yarn berry rollback/remove still drops a custom registry's
::__archiveUrl=binding (#817 fix incomplete): the restore looks updist.tarballon npmjs, not the project'snpmRegistryServer, so cold installs 404 #908, vlt hosted rollback and remove rewrite slot [3] to a synthesized/<name>/-/<leaf>-<ver>.tgzURL instead of the registry's dist.tarball, so the next coldvlt ci404s #521)": berry and vlt. - 60300b8 (Fix 15 open pnpm issues across hosted, vendored and agent modes #1007): pnpm, for Hosted pnpm rollback/remove restores
pnpm-lock.yamlfrom npmjs's version document instead of the project's.npmrcregistry, so a mirror project loses itstarball:URL (cold frozen install 404s) or is moved to npmjs #919, which opens "This is the pnpm side of Hosted yarn berry rollback/remove still drops a custom registry's::__archiveUrl=binding (#817 fix incomplete): the restore looks updist.tarballon npmjs, not the project'snpmRegistryServer, so cold installs 404 #908 (yarn berry) and vlt hosted rollback and remove rewrite slot [3] to a synthesized/<name>/-/<leaf>-<ver>.tgzURL instead of the registry's dist.tarball, so the next coldvlt ci404s #521 (vlt)." - 2044d9e (Fix open bun issues (#992, #861, #784, #764, #735, #635, #599, #578, #497, #443, #371) #1009): bun, for Hosted Bun rollback/remove writes an empty registry slot that Bun < 1.3.7 resolves against npmjs, so custom-registry projects can't frozen-install after a revert #992.
vendor/registry_fetch.rs (lines 16 to 18) still calls SOCKET_NPM_REGISTRY "the enterprise-mirror / test escape hatch" and says .npmrc parsing is out of scope. Four of the six lock families have parsed the project's settings since.
CLI_CONTRACT.md describes today's split: line 2064 names berry, pnpm and bun as reading the project's registry, and the rows of SOCKET_NPM_REGISTRY (line 2320) and upstream_registry_fallback (line 2506) list the same locks. Nothing there says npm and yarn classic are meant to differ.
Planned fix
restore_npm_locks and restore_classic call fetch_dists_on with the registry the package manager resolves the package against, as their five siblings do, with the same fallback to the default registry and the same upstream_registry_fallback warning:
- npm: the
.npmrcregistryand@scope:registryof the project and the user, andnpm_config_registry. The readers the pnpm and bun restores use for.npmrcare in the same file. - yarn classic:
registryfrom yarn 1's settings layers (.yarnrc,.npmrc,YARN_*andnpm_config_*). The hosted rewriter already reads those layers foryarn-offline-mirrorandglobal-folder(corepatch/redirect/yarnrc.rs). - yarn classic keeps the document's
dist.tarballwhen it came from the project's registry, and maps npmjs toregistry.yarnpkg.comonly when the project names no registry.
fetch_dists then has no caller and goes. The three contract passages gain the two locks. Tests: one in-process rollback per lock with two mock registries, asserting which one was asked and the restored entry; they fail on main.
The refusal can name SOCKET_NPM_REGISTRY in the same change.
Related
- Decide: should hosted rollback keep an originals sidecar, or restore only formats whose original is a pure function of registry data? #1130 asks whether hosted rollback should keep the originals in a sidecar. That would remove this class for every lock. This issue is the smaller fix under today's design.
- Not run: the hosted to vendored takeover, which uses the same restore, and scoped packages under
@scope:registry.
Generated by Claude Code
Activity
refactor: #2367 filed; mirrors and the undo ran