Skip to content

Hosted yarn berry run with --patch-mirror-url calls an earlier patch-server pin a user http: dependency the redirect "cannot own" #2369

Backlog

Description

[agent] Found by the scheduled Yarn Berry (2+) bug-hunt routine (ledger #305).

Summary

The patch mirror is experimental (added in #2180, not in v5.1.0), so this is not a regression. It is the yarn berry counterpart of the Bun report #2279; the fix for that one (#2282) only touches the Bun rewriters.

Take a yarn berry project that an earlier hosted run pinned directly on the patch server, and run hosted mode again with --patch-mirror-url / SOCKET_PATCH_MIRROR_URL. The run correctly leaves the pin alone and gives redirect_mirror_pin_not_moved with the right remedy. But before that warning it prints two more for the same package, and both are wrong:

  1. redirect_yarn_berry_unsupported_protocol: "lock entry "left-pad@https://…/patch/npm/left-pad/1.3.0/<tok>/<uuid>/left-pad-1.3.0.tgz" resolves left-pad@1.3.0 through the http: protocol, which the hosted redirect cannot own (only npm: registry entries are rewritten; e.g. workspace:, patch:, portal:, link: blocks must survive untouched)". That entry is socket-patch's own earlier hosted pin, not a user's URL dependency, and the hosted redirect does own it (a run without the mirror re-pins it as an idempotent no-op).
  2. redirect_yarn_berry_entry_not_found: "No npm: lock entry resolving left-pad@1.3.0". True only because the entry is the hosted pin.

The human output then reads: "no lockfile entry pinning it could be rewritten (see the warnings below)", and the first two warnings below describe a user-owned http: dependency that must "survive untouched". Only the third says what is actually going on and what to do.

Impact

An Enterprise user moving an existing hosted yarn berry project onto their mirror gets three warnings per package, and the first two contradict the third: they imply the dependency is a non-registry URL the user chose and that socket-patch can't handle it. Nothing is written and the in-run VEX is still correct, so this is friction, not breakage. The comment on mirror_pins_not_moved (crates/socket-patch-cli/src/commands/scan/hosted.rs:120) says that warning exists so the run doesn't report the patch "with only the rewriter's own, unrelated-looking reason". For yarn berry it is added next to those reasons rather than in place of them.

Repro (offline: a local mock patch API on :18080 and a mirror on :18081)

The mock serves /v0/orgs/org/patches/{batch,by-package,package,view} and the patched tarball at /patch/npm/left-pad/1.3.0/<tok>/<uuid>/left-pad-1.3.0.tgz (GET and HEAD) on both ports. Any mock that grants one npm patch with a yarn-berry-zip artifact will do.

export COREPACK_ENABLE_DOWNLOAD_PROMPT=0 YARN_UNSAFE_HTTP_WHITELIST=127.0.0.1
M=http://127.0.0.1:18080; MI=http://127.0.0.1:18081
sp() { socket-patch "$@" --api-url $M --org org --api-token fake --patch-server-url $M; }
mkdir app && cd app
echo '{"name":"app","version":"1.0.0","private":true,"dependencies":{"left-pad":"1.3.0"}}' > package.json
printf 'nodeLinker: node-modules\nenableGlobalCache: false\n' > .yarnrc.yml
corepack yarn@4.19.0 install
sp scan --mode hosted --yes                      # pins left-pad on the patch server (:18080)
SOCKET_PATCH_MIRROR_URL=$MI sp scan --mode hosted --yes --json | jq '[.events[].errorCode, .warnings[].code]'

Actual (yarn 4.19.0, main cfc870f):

["redirect_unconfirmed",
 "redirect_yarn_berry_unsupported_protocol",
 "redirect_yarn_berry_entry_not_found",
 "redirect_mirror_pin_not_moved"]

Human output:

Switched 0 packages to hosted patches; rewrote 0 files.
No patches could be switched to hosted:
  pkg:npm/left-pad@1.3.0: no lockfile entry pinning it could be rewritten (see the warnings below)
Warning: Lock entry `"left-pad@http://127.0.0.1:18080/patch/npm/left-pad/1.3.0/tok/<uuid>/left-pad-1.3.0.tgz"` resolves left-pad@1.3.0 through the `http:` protocol, which the hosted redirect cannot own (only npm: registry entries are rewritten; e.g. workspace:, patch:, portal:, link: blocks must survive untouched); leaving it byte-identical
Warning: No npm: lock entry resolving left-pad@1.3.0
Warning: pkg:npm/left-pad@1.3.0: package.json pins it directly on 127.0.0.1:18080, and a pin in that file cannot be moved onto the patch mirror http://127.0.0.1:18081 in place, so it was left as it is; run `socket-patch rollback pkg:npm/left-pad@1.3.0` and then this command again

yarn.lock and package.json stay byte-identical (correct).

Expected

CLI_CONTRACT.md, "Patch mirror (experimental)", A project already pinned on the patch server: "The yarn berry, Bun, Bundler, Poetry and PDM rewriters own an earlier pin only on the host they are writing, so they leave a direct pin as it is: the patch is skipped (redirect_unconfirmed) and a redirect_mirror_pin_not_moved warning names the file, the host and the remedy". The package should get that warning, not two others that describe it as a user's http: dependency. redirect_yarn_berry_unsupported_protocol is for entries like workspace:, patch:, portal: or link: that the user owns; a hosted pin in the patch server's path shape on a patch server of the run isn't one.

A fix along the lines of #2282 would retract the two rewriter warnings for an entry whose URL is a hosted pin of the same patch uuid on a patch server the run knows, when redirect_mirror_pin_not_moved is raised for it.

Where it reproduces

yarn linker extra warnings
4.19.0 node-modules yes
4.19.0 pnpm yes
4.0.2 node-modules yes
any any, no mirror (plain re-scan) no: idempotent, no warnings

Linux only. The warnings come from lockfile text, so macOS and Windows should behave the same (a CRLF yarn.lock goes down the same path).

First bad commit: #2180 (412796f), which added the mirror and redirect_mirror_pin_not_moved. v5.1.0 has no mirror.

Suspect code

  • crates/socket-patch-core/src/patch/redirect/mod.rs:5673: the berry rewriter raises redirect_yarn_berry_unsupported_protocol for any non-npm: entry, its own earlier hosted pin on another host included.
  • crates/socket-patch-core/src/patch/redirect/mod.rs:5748: redirect_yarn_berry_entry_not_found for the same package.
  • crates/socket-patch-cli/src/commands/scan/hosted.rs:129 (mirror_pins_not_moved): adds redirect_mirror_pin_not_moved but retracts nothing for yarn berry.

Generated by Claude Code

Activity

  1. added
    bug
    bughunt
    pm:yarn-berry
    on Nov 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent:triagedbugbughuntpm:yarn-berrypriority:p1

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions