Skip to content

Fix pnpm hosted patch over a vendored dependency (#2263) - #2266

Open
Mikola Lysenko (mikolalysenko) wants to merge 6 commits into
mainfrom
agent/fix-pnpm-hosted-parent-vendored-dep
Open

Mikola Lysenko (mikolalysenko) wants to merge 6 commits into
mainfrom
agent/fix-pnpm-hosted-parent-vendored-dep

Conversation

@mikolalysenko

@mikolalysenko Mikola Lysenko (mikolalysenko) commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

LLM Description written by Claude Code:claude-fable-5-2

Fixes #2263

Summary

On pnpm 12.23.0, a project with a package patched in hosted mode and one of its dependencies patched in vendored mode can no longer install: every pnpm install, frozen or not, stops on ERR_PNPM_LOCAL_SUBDEP_NOT_ALLOWED. Both socket-patch runs exited 0 and told the user to commit.

Now whichever run would create that pair is refused before anything is written, and the project keeps installing:

Second run Before Now
get <dependency> --mode vendored under a hosted package exit 0, lock pnpm refuses exit 1, vendor_lock_entry_unsupported, nothing written
get <package> --mode hosted over a vendored dependency exit 0, lock pnpm refuses exit 0, warning redirect_pnpm_local_dependency, patch skipped / redirect_unconfirmed, nothing written
scan --mode vendored that can vendor the dependency but not the package exit 1, lock pnpm refuses (as the issue reports) exit 1, both stay hosted

Both refusals name the remedy: one mode for the package and its dependency. scan --mode hosted takes a vendored dependency over.

Root cause

pnpm 12.23 refuses a lock in which a package that is not local depends on a local file, unless it can tie the workspace override to that package. It can for a package on the default registry. It can't for one that a hosted patch pins (the tarball of the pin, or the named registry of the route). pnpm 12.23.0 resolves the workspace file the two modes leave to the byte-identical lock and then refuses that lock itself, so there is no lock shape to write instead: only an override with no version in its selector passes, and that would redirect every release of the dependency.

Neither side looked at what the other mode had left:

  • the vendored pnpm backend rewrote a dependent's name: version ref to the file: tarball whatever the dependent resolved from;
  • the hosted pnpm planner pinned a package whatever its snapshots: entry depended on.

The change

  • vendor/pnpm_lock.rs: check_hosted_dependents, called from the pre-flight beside the other ref gate, and from the Rush planner's gate list. It refuses when a registry-keyed dependent resolves to a tarball in a patch server's path shape.
  • formats/pnpm/hosted.rs: the planner refuses a pin that would make a hosted package of one whose snapshot has a file: dependency. The patch is refused across the whole lock set, as for the existing residual gate. A package an earlier patch already pins is re-pinned as before, so a project already in this state keeps getting its grants refreshed.
  • CLI_CONTRACT.md and docs/ecosystems.md describe both refusals.

The refusals don't depend on the pnpm version a project pins: the lock would break as soon as the project moves to 12.23.

Evidence

All real-pnpm runs used pnpm 12.23.0.

Test Covers Before the fix After
e2e_redirect_pnpm_build: pnpm12_vendored_dependency_of_a_hosted_patch_is_refused, pnpm12_hosted_patch_over_a_vendored_dependency_is_refused #2263 in both orders, then the hosted scan that patches both, then the vendored scan that must leave both hosted; a fresh frozen install from an empty store after each step both fail (second run exits 0) pass
pnpm_hosted.rs: a_package_with_a_local_dependency_is_not_taken_off_the_registry, the_local_dependency_refusal_is_scoped_to_the_new_pin hosted gate, including a second lock, a quoted value, link:, another package's dependency, an already pinned package new pass
vendor::pnpm_lock: hosted_dependents_refuse_vendoring_their_dependency vendored gate by scan and by index: pinned tarball, peer context, named registry, scoped name; not refused for a registry dependent (with or without its tarball URL), a vendored dependent, another release new pass
vendor::pnpm_lock::rush: a_dependency_of_a_hosted_package_is_refused the Rush gate new pass
in_process_vendor_pnpm_parent_child: two takeover tests see "Behavior to review" new pass

Local runs after the last change:

  • cargo test -p socket-patch-core: all pass.
  • cargo clippy --locked --workspace --all-features -- -D warnings (the CI command): clean. --all-targets reports errors, all in test files this PR doesn't touch.
  • CLI suites in_process_vendor_pnpm_takeover, in_process_redirect_pnpm, in_process_pnpm_registry_cleanup, in_process_vendor_pnpm_parent_child: pass.
  • in_process_redirect: 3 tests fail in my sandbox (partial_lockfile_write_failure_exits_1_and_writes_no_ledger, redirect_json_mode_write_failures_emit_error_envelope, vlt::scan_redirect_vlt_heal_invalidation_failure_warns). They simulate write failures through file permissions and the sandbox runs as root.
  • e2e_redirect_pnpm_build (the six pnpm12 legs) and e2e_vendor_pnpm_build (all but the pinned matrix): pass.

CI on this head: clippy is green. The required ci-ok is red, only because hosted-e2e fails in gem_bundler_hosted_install_proof: the live patch service now selects a patch for activestorage@6.0.3 that the test's pinned GEM_UUIDS set doesn't list. This PR doesn't touch gem code or that test.

Behavior to review

A hosted to vendored takeover of a package and its dependency now takes two runs. scan --mode vendored over a hosted debug and its hosted dependency ms vendors debug, refuses ms and exits 1; the next run vendors ms. Before, one run did both (checked by switching the gate off). The takeover pre-pass judges each pin against the lock as the run found it, where debug is still hosted. Exempting a dependent that the same run takes over would need the run to undo the dependency when the dependent then fails, and I left that out. Two hosted packages that depend on each other are refused on every such run. socket-patch vendor (the eject) restores every pin first and moves them in one run; the refusal says so. vendored_takeover_keeps_the_child_hosted_until_the_parent_is_vendored and eject_vendors_a_hosted_parent_and_child_in_one_run pin both.

Review findings not fixed

/code-review high ran on the first cut. Fixed: the vendored gate was too wide (any tarball), link: was treated as local, the hosted gate skipped any package with a tarball, the Rush planner was not gated, the gate built a whole index when it had none, and the pre-pass comment was stale. Not fixed:

  • The two-run takeover: kept, for the reason above.
  • A git or URL-keyed dependent is not refused: I have no evidence pnpm refuses that pair, and the gate only covers what was reproduced.
  • No gate on the project's pnpm version: see "The change".

Follow-ups

  • Not covered, and it breaks installs today: with lockfileIncludeTarballUrl: true, pnpm 12.23.0 also refuses a vendored-only project (a registry mid with its tarball URL in the lock, over a vendored leaf). pnpm 12.22.0 installs the same lock. Refusing there would stop vendoring almost anything in such a project on every pnpm, so it needs a decision (a gate on the pinned pnpm version, or a different wiring) and its own issue.
  • Legacy pnpm locks (5.4 / 6.0) are not gated: pnpm 7 and 8 have no such check.
  • A project already in the mixed state is left as it is and gets no warning.
  • Worth reporting to pnpm: 12.23.0 refuses a lock it writes itself.

https://claude.ai/code/session_011f9aeTAwXzUmgdCtoh8Trm


Generated by Claude Code

pnpm 12.23 refuses a lock in which a package fetched from a hosted
patch depends on a vendored file: tarball (#2263). This empty commit
opens the branch; the fix follows.

Assisted-by: Claude Code:claude-fable-5-2
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011f9aeTAwXzUmgdCtoh8Trm
Two legs for the registry-route suite, against a real pnpm 12: a
hosted patch of peer-user and a vendored patch of its dependency
leaf, in either order. The second run must be refused and change
nothing, the project must still install frozen, and the hosted scan
both refusals name must then patch both packages.

Both legs fail on main with pnpm 12.23.0: the second run exits 0 and
the frozen install then stops on ERR_PNPM_LOCAL_SUBDEP_NOT_ALLOWED
(#2263).

Assisted-by: Claude Code:claude-fable-5-2
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011f9aeTAwXzUmgdCtoh8Trm
pnpm 12.23 refuses a lock in which a package that is not local
depends on a local file, unless it can tie the workspace override to
that package. It cannot for a registry package whose resolution
names a tarball URL, which is what a hosted patch leaves. pnpm writes
that lock itself for the workspace file the two modes leave together
and then refuses it, frozen or not, so every install of the project
fails with ERR_PNPM_LOCAL_SUBDEP_NOT_ALLOWED.

Whichever run comes second is now refused before anything is
written:

- vendoring a package is refused (vendor_lock_entry_unsupported)
  when a dependent of it is a registry package fetched from a
  tarball URL;
- the hosted pin of a package is refused
  (redirect_pnpm_local_dependency) when it would take a package with
  a file: or link: dependency off the default registry. A package
  that already names a tarball is re-pinned as before.

Fixes #2263

Assisted-by: Claude Code:claude-fable-5-2
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011f9aeTAwXzUmgdCtoh8Trm
A hosted to vendored takeover judges each hosted pin against the
lock as the run found it, so the dependency of a package that is
still hosted is refused in the run that vendors the package, and
vendored by the next run. The eject restores every pin first and
moves both in one run. Two tests pin that, and the e2e legs now end
with a vendored scan that can vendor the dependency but not the
package: both stay hosted and the project still installs frozen.

The vendored refusal names the package and its lock key, not the
tarball URL, and points at the eject. CLI_CONTRACT.md and
docs/ecosystems.md describe both refusals.

Refs #2263

Assisted-by: Claude Code:claude-fable-5-2
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011f9aeTAwXzUmgdCtoh8Trm
The check walked the packages section by hand when it was given no
index, which the pnpm architecture guard counts as a new raw reader
in vendor/pnpm_lock.rs. It now builds the index in that case and
reads both sections through it, so the guard's count is unchanged.

Refs #2263

Assisted-by: Claude Code:claude-fable-5-2
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011f9aeTAwXzUmgdCtoh8Trm
Review of the first cut found the gates too wide and one too narrow:

- The vendored gate refused any registry dependent whose resolution
  names a tarball, which is every package of a project that sets
  lockfileIncludeTarballUrl. It now refuses only a dependent a hosted
  patch pins: a tarball in a patch server's path shape.
- The hosted gate treated link: like file:, and pnpm writes link:
  for a peer a workspace project satisfies. Only file: refuses now.
- The hosted gate skipped a package whose resolution already named
  any tarball. It now skips only one an earlier patch already pins.
- Rush's planner has its own gate list and did not call the
  vendored gate; it does now, with a test.
- Off the index, the vendored gate scans the two sections instead of
  building a whole index per package; the pnpm architecture guard
  lists that read with its reason.
- The takeover pre-pass comment said no pnpm gate reads a
  resolution; it now says which one does and what follows.

Refs #2263

Assisted-by: Claude Code:claude-fable-5-2
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011f9aeTAwXzUmgdCtoh8Trm
@mikolalysenko
Mikola Lysenko (mikolalysenko) marked this pull request as ready for review November 26, 2026 02:38
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

[agent] bugbot run


Generated by Claude Code

@cursor

cursor Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Medium: changes core pnpm hosted/vendored lock rewrite and takeover preflight gates; wrong scoping could block valid pins or still allow broken locks.

Overview
pnpm 12.23+ rejects locks where a non-local package (including hosted patch tarballs) depends on a local file: dependency (ERR_PNPM_LOCAL_SUBDEP_NOT_ALLOWED). The CLI previously could still write that combination.

Hosted mode (formats/pnpm/hosted.rs) now scans v9 snapshots: for file: deps on the package being newly pinned to hosted; if found, the patch is refused lock-wide with redirect_pnpm_local_dependency and nothing is rewritten (already-hosted re-pins still work; link: peers are ignored).

Vendored mode adds check_hosted_dependents in vendor/pnpm_lock.rs (Rush path too): vendoring a package is blocked when a registry-keyed dependent still resolves from a hosted patch URL. That surfaces as vendor_lock_entry_unsupported.

Takeover behavior: scan --mode vendored over two hosted parent/child pins may require two runs (parent vendored first, child on the next); plain vendor eject restores all hosted pins first and vendors both in one shot. Contract docs and e2e/in-process tests cover both orderings and frozen installs.

Reviewed by Cursor Bugbot for commit 2ee69e7. Configure here.

@mikolalysenko

Mikola Lysenko (mikolalysenko) commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator Author

[agent] hosted-e2e fails on this head and it isn't this PR's. It is the only failing job, and it turns the required ci-ok red, so this PR can't merge until it is fixed. clippy is green. (Edited: an earlier version of this comment said ci-ok was green; that was a run that finished before hosted-e2e did.)

  • What fails: gem_bundler_hosted_install_proof in e2e_hosted_production, on all 3 attempts. The live patch service now selects patch 146ef6aa-f43e-42aa-9891-0983435220e2 for pkg:gem/activestorage@6.0.3, and that uuid is not in the test's pinned GEM_UUIDS set.
  • Why it isn't this PR's: the diff only touches the pnpm hosted planner, the pnpm vendored backend, their tests and docs. The suite reads the production catalog, which changed after the last main run (green at 2026-11-25T22:40Z); every PR's next run should hit the same failure.
  • What fixes it: verify the new patch and append its uuid to GEM_UUIDS, as the test's message says. That is a separate change from this one, so I left it out.

Generated by Claude Code

@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

[agent] PR shepherd: review brief

What it does
pnpm 12.23 refuses every install (ERR_PNPM_LOCAL_SUBDEP_NOT_ALLOWED) of a lock where a package pinned to a hosted patch depends on a vendored file: package. socket-patch used to write that pair and exit 0. Now the run that would create it refuses before anything is written. A hosted pin over a vendored dependency is skipped with the warning redirect_pnpm_local_dependency, and vendoring a dependency of a hosted package fails with vendor_lock_entry_unsupported. Fixes #2263.

Risk
Medium. Nothing new is written, but two flows that used to exit 0 now refuse, on every pnpm version, not only 12.23+. A hosted → vendored takeover (scan --mode vendored) of a package and its hosted dependency now takes two runs (the first exits 1). socket-patch vendor still moves both in one run.

Look here

Verified
I read the core diff against #2263 and the description. Both gates cover only lockfile v9 (legacy 5.4/6.0 locks are unaffected, as documented). The vendored gate fires only on a dependent whose tarball has a patch-server path shape, so a registry dependent, a local dependent or one with any other tarball keeps today's behavior. link: values are not treated as local. The description reports real pnpm 12.23.0 e2e legs that fail on main and pass here. No review threads are open. CI on 2ee69e7: clippy and every other check are green. ci-ok is red only through hosted-e2e's gem leg, the main-wide failure in #2270, which this PR doesn't touch. A merge of main and a re-run are needed once #2270 is fixed.

Changes I made
None.

Open questions

  • Is the two-run hosted → vendored takeover of a parent and child acceptable? The description explains why the author didn't exempt a dependent that the same run takes over.
  • The description's follow-up (with lockfileIncludeTarballUrl: true, pnpm 12.23.0 also refuses a vendored-only project) has no issue filed yet, and it breaks installs today.

Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review

Projects

None yet

2 participants