Skip to content

Stop attesting a hosted pnpm pin whose registry route pnpm-workspace.yaml no longer declares - #2427

Merged
Mikola Lysenko (mikolalysenko) merged 5 commits into
mainfrom
arch-refactor/2404-pnpm-route-needs-workspace
Dec 2, 2026
Merged

Mikola Lysenko (mikolalysenko) merged 5 commits into
mainfrom
arch-refactor/2404-pnpm-route-needs-workspace

Conversation

@mikolalysenko

@mikolalysenko Mikola Lysenko (mikolalysenko) commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

LLM Description written by Claude Code

Fixes #2404.

Problem

Hosted mode's registry route writes one patch into two files: a namedRegistries entry and an overrides entry in pnpm-workspace.yaml, and the lock in the form pnpm writes for them (an overrides: record and the name@socket-<id>:version keys). pnpm installs that lock only while the workspace file declares the route:

  • with the override gone, a frozen install fails (ERR_PNPM_LOCKFILE_CONFIG_MISMATCH) and a plain pnpm install takes the upstream release back and rewrites the lock, with no word about the patch;
  • with the registry gone, or the file left out of the commit, nothing installs (ERR_PNPM_MISSING_NAMED_REGISTRY).

vex read the hosted reference from the lock alone and attested not_affected in each of those states. Who it hurts: anyone who ships the VEX document. A tree gets there when a merge keeps one side's pnpm-workspace.yaml and the other side's lock, or when the workspace file (new after the first scan of a project that had none) is left out of the commit. The issue has the rows on real pnpm 11.29.0 and 12.23.0.

Evidence on main (9f2bc04)

The test from the issue, added to core vex/discover/npm.rs and run before the fix:

test vex::discover::npm::tests::pnpm_registry_routed_pin_needs_the_override_the_lock_records ... FAILED
attested with the override gone from pnpm-workspace.yaml: [
    PatchedRef { purl: "pkg:npm/leaf@1.0.0", uuid: "7c8d9e0f-…", mode: Hosted, […]

It passes on this branch, and so does the new CLI test, which runs the binary over the same four states.

Fix

One rule, the writer's own. A hosted pin that the lock routes through a registry of hosted mode's keeps the lock's pin only while the root pnpm-workspace.yaml routes that release to that registry, at an address that serves the lock's tarball (kept_route in core hosted/engine.rs asks the same of a route it keeps). The check is confirm_pnpm_routes in core vex/discover/npm.rs, beside the vendored-override check of #2396, and it reads the workspace file with the readers hosted mode already has (routes, declared, Owned).

A pin that fails it is not dropped. It loses the lock's basis, as the pins of a lock pnpm does not read do, so vex attests it only from an installed tree whose every copy verifies. It is diagnosed as patched_ref_invalid with the file, what is missing and the remedy:

Warning: pnpm-lock.yaml: the lock routes pkg:npm/kept-pkg@1.0.0 through the registry `socket-aaaaaaaa`, but pnpm-workspace.yaml `overrides` does not declare `'kept-pkg@1.0.0': 'socket-aaaaaaaa:1.0.0'`. pnpm installs such a lock only while the file declares the registry and the override: […] Run `socket-patch scan --mode hosted` to declare the route again, and commit pnpm-workspace.yaml

Keeping the reference matters: list still shows the pin, a hosted re-scan still reads it as the project's and writes the route back without touching the lock, and rollback and remove still restore the upstream entry. The CLI test holds each of those.

Not asked for, so those pins stand as before: a Rush lock; a lock that records no override for the release; a workspace file that cannot be read, is not a single block mapping, sets either map in a shape the line reader does not follow, or holds pnpm 12's registries map; and a workspace member run from its own directory, whose settings are in the workspace file above it.

Deleted

Nothing.

Behavior change

  • vex omits a routed pnpm pin whose route pnpm-workspace.yaml does not declare, unless an installed tree verifies, and warns as above. It attested not_affected before.
  • A hosted re-scan over such a tree reports details.pinChanged: true for the pin, where it reported false: the pin it reads before the run has no lock basis and the one after has. The run does put a reference of the patch back into pnpm-workspace.yaml, which then has to be committed, and the contract's wording ("the local dependency files show a new or updated hosted reference") covers that, so the CLI test holds the value. Reviewer: say so if false is wanted there; the change would be in CLI scan/pin_changes.rs.
  • No other command changes: exit codes, JSON shapes and files written are as on main.

Risk

Low for a tree the scan wrote: the route is found as the writer finds it, with CRLF, a BOM and an address without its final / covered. The risk is a false omission for a workspace file that declares the route in a way the readers miss; the shapes known to do that leave the pin standing.

Review

/code-review high on the diff gave five findings. Three are fixed in 8a41e6d, each with a test: the member run, the flow-style document and registries map, and the emptied inline map (overrides: {}), which was taken for a shape that may hold the route. Two are left:

  • A lock keyed through a registry with no overrides: record is not checked for its registry. That is the issue's rule (a route the lock itself records), nothing unpatched installs in that state, and widening it is a second rule to measure on real pnpm first.
  • pinChanged, above.

Not in this PR

CLI_CONTRACT.md and docs/ecosystems.md are changed by the open #2425 and #2402, so this PR leaves both alone. The sentence for the pnpm paragraph of docs/ecosystems.md ("Commit both files.") and for the contract's pnpm row of the discovery table: "A routed reference is confirmed by pnpm-workspace.yaml: vex attests it from the lock only while the file declares the registry and the override, and otherwise names what is missing (patched_ref_invalid); a hosted re-scan declares the route again."

Not run: real pnpm on this branch (the issue's rows are from main; the fix changes no file pnpm reads), Windows and macOS.

Checks

  • cargo clippy --locked --workspace --all-features -- -D warnings: clean.
  • On the final commit (ccccbe6): core lib 8770 passed, CLI lib 1086 passed.
  • CLI suites in_process_pnpm_registry_cleanup (23, one new), in_process_redirect_pnpm, in_process_rollback_hosted, hosted_memory_engine, hosted_memory_parity, e2e_vex_redirect, e2e_vex, vex, scan, cli, in_process_scan, vendor_pnpm_override_e2e, remove, rollback, report_e2e, in_process_vendor_pnpm_takeover, in_process_get_modes, in_process_get_hosted_ecosystems, e2e_hosted_production, user_patches, e2e_embedded_vex, e2e_bazel_build, mode_migration_npm: all passed.
  • in_process_redirect: 135 passed; its 3 chmod tests fail as root in the sandbox, on main too.
  • CI: 126 checks pass on ccccbe6. Bugbot reviewed that commit and found no issue.

Diff

4 files, +626 −1: production +208 −1 (core vex/discover/npm.rs +160 −1, formats/pnpm/named_registries.rs +41, vex/discover/mod.rs +7), tests +416 (unit +224, CLI +192).

https://claude.ai/code/session_011f9aePHgySeqcFGZTWRvcU


Generated by Claude Code

Assisted-by: Claude Code
@mikolalysenko Mikola Lysenko (mikolalysenko) added arch-refactor PR opened by the scheduled architecture refactor routine refactor Structural change: duplicated code or logic, missing abstraction, layering, dead code labels Dec 1, 2026
Hosted mode's registry route writes a patch into two files: a
namedRegistries entry and an overrides entry in pnpm-workspace.yaml,
and the lock in the form pnpm writes for them. pnpm installs that lock
only while the file declares both. With the override gone a frozen
install fails (ERR_PNPM_LOCKFILE_CONFIG_MISMATCH) and a plain install
takes the upstream release back; with the registry gone nothing
installs (ERR_PNPM_MISSING_NAMED_REGISTRY).

Discovery read the hosted reference from the lock alone, so vex
attested not_affected for such a tree.

A hosted pin the lock routes through a registry of hosted mode's now
keeps the lock's pin only while the root pnpm-workspace.yaml routes
the release to that registry at an address that serves the lock's
tarball: the test the writer applies to a route it keeps. Otherwise
the pin is diagnosed (patched_ref_invalid, with the file, what is
missing and the remedy) and is attested only from an installed tree
whose every copy verifies, as the pins of a lock pnpm does not read
are. The reference itself stays, so a hosted re-scan still reads the
pin as the project's and declares the route again, and rollback and
remove still restore the upstream entry.

Not asked for: a Rush lock, a lock that records no override for the
release, and a workspace file that cannot be read or that sets either
map in a shape the line reader does not follow.

Refs #2404.

Assisted-by: Claude Code
Runs the binary over the tree a hosted scan routes, then over the same
tree with the override gone, the registry gone, both gone and no
pnpm-workspace.yaml. vex attests the first from the lock and none of
the others, and names what the file lacks. For each, the remedy the
message gives (a hosted re-scan) declares the route again without
touching the lock, and vex attests once more. rollback still restores
the upstream entry of a pin whose route is undeclared.

Refs #2404.

Assisted-by: Claude Code
Review of the route check found three states it judged wrongly.

A workspace member with a lock of its own, run from its directory,
has no pnpm-workspace.yaml: the route is in the file above it, which
pnpm reads. The check took that for a missing file and stopped
attesting a pin that installs. Such a run is now left as it was.

A workspace file written as one flow-style mapping, or one that holds
pnpm 12's registries map, was read as declaring no route. Both may
declare it, so the pin stands, as it does for the other shapes the
line reader does not follow.

An emptied inline map (overrides: {}, namedRegistries: ~) was taken
for a shape that may hold the route. It declares nothing, so the pin
now loses the lock's basis there too.

Refs #2404.

Assisted-by: Claude Code
A hosted re-scan over a routed lock whose route the workspace file
dropped writes the route back and leaves the lock as it is. Its event
now carries pinChanged: true, where it used to carry false: the pin
read before the run has no lock basis, and the one read after it has.
The run did put a reference of the patch back into the project's
files, and the file it rewrote has to be committed, so the test holds
the value.

Refs #2404.

Assisted-by: Claude Code
@mikolalysenko
Mikola Lysenko (mikolalysenko) marked this pull request as ready for review December 1, 2026 22:58
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

bugbot run


Generated by Claude Code

@cursor

cursor Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes VEX discovery and attestation semantics for hosted pnpm registry routes; incorrect workspace parsing could omit valid pins, though unreadable shapes are explicitly left standing.

Overview
Fixes #2404: vex no longer treats a hosted pnpm pin as attestable from the lock alone when pnpm-workspace.yaml does not still declare the registry route (namedRegistries + matching overrides) that the lock records.

Discovery now runs confirm_pnpm_routes alongside the existing vendored-override check: mismatches clear locked_integrity (same pattern as unreadable locks) and emit patched_ref_invalid diagnostics that name what is missing and suggest socket-patch scan --mode hosted. Pins are not dropped—hosted re-scan can restore the route; rollback/remove behavior is unchanged.

routes_unreadable guards against falsely claiming “no route” when the workspace file uses YAML shapes the line reader cannot follow (flow style, duplicate maps, pnpm 12 registries, etc.). DiscoverCtx::on_patch_server wires patch-server origin checks into route validation.

New unit and CLI tests cover override/registry/file-missing cases, member workspaces, re-scan restoring attestation, and rollback.

Reviewed by Cursor Bugbot for commit ccccbe6. Configure here.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit ccccbe6. Configure here.

Mikola Lysenko (mikolalysenko) pushed a commit that referenced this pull request Dec 1, 2026
The run began with three approved PRs open and put 56 mutants into the
--offline gates; #2390, #2393 and #2396 merged during it, so it then
fixed #2404 (a false not_affected on the pnpm registry route).

Assisted-by: Claude Code
@mikolalysenko Mikola Lysenko (mikolalysenko) added the Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review label Dec 2, 2026
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

[agent] PR shepherd: review brief for the approver

What it does. Hosted mode's pnpm registry route stores one patch across two files: pnpm-workspace.yaml (namedRegistries + overrides) and pnpm-lock.yaml. Until now vex read the pin from the lock alone and attested not_affected even when the workspace file no longer declared the route, a state where pnpm either refuses a frozen install or quietly installs the upstream release. Now such a pin loses its lock basis: it is attested only from an installed tree that verifies, and a patched_ref_invalid warning names what is missing and how to fix it.

Risk: low. Only vex discovery changes, and only for pins the lock routes through a hosted registry that is also recorded in the lock's overrides:. Exit codes, JSON shapes and the files written stay the same. If the workspace file can't be read, is a shape the reader can't follow, uses pnpm 12's registries map, or the project is a workspace member or a Rush lock, the pin stands as before (fails open). The pin is never dropped, so list, rollback, remove and a hosted re-scan still see it.

Look here

Verified. I read the whole diff against #2404. The check reuses hosted mode's own readers (routes, declared, Owned, Address::serves), so the rule matches the writer's kept_route. The lock's overrides: come from the existing section parser, and the BOM is stripped. CHANGELOG.md is untouched. There are no debug leftovers or unrelated edits. The issue's regression test is in the diff and the description shows it failing on main. CI on ccccbe6: ci-ok and clippy are green, and Bugbot reviewed with no findings. I could not run the tests locally this run because the build ran out of memory in the sandbox, so I relied on CI.

Changes I made. None.

Open questions

  • After a hosted re-scan of such a tree, details.pinChanged is now true (it was false), because the re-scan writes the route back into pnpm-workspace.yaml. The author asks whether false is wanted instead; the change would be in CLI scan/pin_changes.rs.
  • A lock keyed through a registry with no overrides: record is not checked. This is deliberate and listed in the description.

Generated by Claude Code

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[agent] Reviewed the full diff at ccccbe6: confirm_pnpm_routes drops locked_integrity for a hosted pin only when the root pnpm-workspace.yaml is readable and no longer declares both the override and a registry serving the lock's tarball, matching the writer's kept_route; the ref is kept so list, re-scan and rollback still see it. No defects found.

Non-blocking note

A namedRegistries entry declared only in global pnpm config or the environment reads as missing; the result is an omitted statement with a warning, not a false attestation.

@mikolalysenko
Mikola Lysenko (mikolalysenko) added this pull request to the merge queue Dec 2, 2026
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

[agent] On the non-blocking note: agreed, and left as it is. The check reads the project's root pnpm-workspace.yaml only, which is the one place hosted mode writes a route. A registry declared only in pnpm's global config or the environment therefore reads as missing, and vex omits the pin with the warning; it does not attest. I have not run real pnpm to see whether it takes a namedRegistries entry from either place, so this is not measured.


Generated by Claude Code

Merged via the queue into main with commit 7d78f2f Dec 2, 2026
126 checks passed
@mikolalysenko
Mikola Lysenko (mikolalysenko) deleted the arch-refactor/2404-pnpm-route-needs-workspace branch December 2, 2026 04:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch-refactor PR opened by the scheduled architecture refactor routine Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review refactor Structural change: duplicated code or logic, missing abstraction, layering, dead code

Projects

None yet

3 participants