Skip to content

vex attests a hosted pnpm package on the registry route after its override leaves pnpm-workspace.yaml: frozen installs fail and a plain install puts the upstream release back #2404

Done

Description

[agent] Found by the architecture refactor routine on main at 1b3f422, with real pnpm 11.29.0 and 12.23.0. The registry route (#2167) is on main and in no release yet.

The 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 same override. The contract says so under Cleanup: "the file and the locks always change together (pnpm refuses a frozen install when a lock's overrides: and the file's disagree)".

vex reads the reference from the lock alone: a packages: entry whose tarball is on the patch server is a hosted reference, whatever the workspace file declares (pnpm_entry_ref, core vex/discover/npm.rs, lines 1548 to 1570). With the override gone from pnpm-workspace.yaml:

  • socket-patch vex exits 0 and attests not_affected;
  • every frozen install fails with ERR_PNPM_LOCKFILE_CONFIG_MISMATCH, and pnpm suggests pnpm install --no-frozen-lockfile;
  • that install takes the package from the registry, rewrites the lock without the patch and exits 0, with no word about the patch.

This is #2382 on the hosted route. #2382 is about vendored file: overrides, and its "Not run" list names this route; #2396's binary (82814cb) attests these rows as main does.

The writer knows the rule. A re-scan keeps a release on its route only while "the workspace file routes it" (kept_route, core hosted/engine.rs), and a hosted re-scan over the broken tree writes the override back.

How a tree gets there: the override and the lock's record of it sit in two files and have to move together. A merge that keeps one side's pnpm-workspace.yaml and the other side's lock separates them, and so does an edit of the overrides list. No pnpm command was tried for this.

A second, lesser row: with the namedRegistries entry gone as well, or the workspace file left out of the commit (it is a new file after the first scan of a project that had none), vex attests the same way and every install, frozen or not, fails with ERR_PNPM_MISSING_NAMED_REGISTRY. No unpatched copy installs there; the project does not install at all.

Evidence

A project that depends on mid@1.0.0, which depends on leaf@1.0.0; a patch of leaf. Two loopback registries stand in for npm and for the patch server (the stubs of scripts/gen-pnpm-registry-override-golden.mjs), and a third answers the patch API with the grant and its npmRegistryUrl. The route is written by socket-patch scan --mode hosted from the binary built on main, in a project that pins its pnpm with packageManager. Each row is that tree with one change to pnpm-workspace.yaml, on a fresh checkout with an empty store.

pnpm pnpm-workspace.yaml vex pnpm install --frozen-lockfile pnpm install
11.29.0, 12.23.0 as the scan wrote it not_affected patched patched, lock unchanged
11.29.0, 12.23.0 the overrides entry gone not_affected ERR_PNPM_LOCKFILE_CONFIG_MISMATCH upstream, exit 0, lock rewritten
11.29.0 namedRegistries and overrides gone not_affected ERR_PNPM_MISSING_NAMED_REGISTRY ERR_PNPM_MISSING_NAMED_REGISTRY
11.29.0 no file not_affected ERR_PNPM_MISSING_NAMED_REGISTRY ERR_PNPM_MISSING_NAMED_REGISTRY

The second row on pnpm 11.29.0 (the flags that point the CLI at the stand-in API are left out, the stub's port stands where the patch server's origin would, and the diff is abridged):

$ socket-patch scan --mode hosted --yes
Switched 1 package to hosted patches; rewrote 2 files.
$ cat pnpm-workspace.yaml
packages:
  - '.'
namedRegistries:
  socket-11111111: http://127.0.0.1:41983/patch/npm/leaf/1.0.0/22222222-2222-4222-8222-222222222222/11111111-1111-4111-8111-111111111111/
overrides:
  'leaf@1.0.0': 'socket-11111111:1.0.0'

# the two `overrides` lines taken out of pnpm-workspace.yaml

$ socket-patch vex --product pkg:npm/app@1.0.0     # exit 0
      "status": "not_affected",
      "impact_statement": "Patched via Socket patch 11111111-1111-4111-8111-111111111111 (redirected)"
Emitted 1 VEX statement

$ pnpm install --frozen-lockfile                   # exit 1
[ERR_PNPM_LOCKFILE_CONFIG_MISMATCH] Cannot proceed with the frozen installation. The current "overrides" configuration doesn't match the value found in the lockfile

Update your lockfile using "pnpm install --no-frozen-lockfile"

$ pnpm install --no-frozen-lockfile                # exit 0
$ cat node_modules/.pnpm/leaf@1.0.0/node_modules/leaf/index.js
module.exports = "leaf@1.0.0"
$ diff pnpm-lock.yaml.before pnpm-lock.yaml
< overrides:
<   leaf@1.0.0: socket-11111111:1.0.0
<   leaf@socket-11111111:1.0.0:
<     resolution: {integrity: sha512-5NKO…, tarball: http://127.0.0.1:41983/patch/npm/leaf/1.0.0/…/leaf-1.0.0.tgz}
>   leaf@1.0.0:
>     resolution: {integrity: sha512-iuZ2…}

$ socket-patch vex --product pkg:npm/app@1.0.0     # exit 2, after that install
Error: No patches in this project; nothing to attest. Run `socket-patch scan` first.

The remedy that works, on the tree before any install:

$ socket-patch scan --mode hosted --yes            # exit 0
Switched 0 packages to hosted patches; rewrote 1 file. 1 package was already on hosted patches.
Next steps:
  1. Commit pnpm-workspace.yaml to keep the hosted patches.
$ tail -2 pnpm-workspace.yaml
overrides:
  'leaf@1.0.0': 'socket-11111111:1.0.0'

A test that fails on main

In the tests of core vex/discover/npm.rs, which hold no lock in the routed shape:

#[tokio::test]
async fn pnpm_registry_routed_pin_needs_the_override_the_lock_records() {
    let url = hosted_url("npm", "leaf", "1.0.0", UUID_A, "leaf-1.0.0.tgz");
    let registry = url.strip_suffix("leaf-1.0.0.tgz").unwrap();
    let lock = format!(
        "lockfileVersion: '9.0'\n\nsettings:\n  autoInstallPeers: true\n  \
         excludeLinksFromLockfile: false\n\noverrides:\n  leaf@1.0.0: socket-7c8d9e0f:1.0.0\n\n\
         importers:\n\n  .:\n    dependencies:\n      mid:\n        specifier: 1.0.0\n        \
         version: 1.0.0\n\npackages:\n\n  leaf@socket-7c8d9e0f:1.0.0:\n    resolution: \
         {{integrity: {SRI}, tarball: {url}}}\n\n  mid@1.0.0:\n    resolution: {{integrity: \
         {SRI}}}\n\nsnapshots:\n\n  leaf@socket-7c8d9e0f:1.0.0: {{}}\n\n  mid@1.0.0:\n    \
         dependencies:\n      leaf: socket-7c8d9e0f:1.0.0\n"
    );
    const PURL: &str = "pkg:npm/leaf@1.0.0";
    let named = format!("namedRegistries:\n  socket-7c8d9e0f: {registry}\n");
    let routed = "overrides:\n  'leaf@1.0.0': 'socket-7c8d9e0f:1.0.0'\n";
    let attested = |out: &Discovery| {
        out.refs
            .iter()
            .any(|r| r.purl == PURL && r.lockfile_basis_ok())
            && marks(out, PURL).is_empty()
    };
    let p = Project::new();
    p.write(
        "package.json",
        r#"{"name":"app","packageManager":"pnpm@11.29.0","dependencies":{"mid":"1.0.0"}}"#,
    );
    p.write("pnpm-lock.yaml", &lock);
    p.write(
        "pnpm-workspace.yaml",
        format!("packages:\n  - '.'\n{named}{routed}"),
    );
    assert!(attested(&run(&p).await), "control: the route as the scan writes it");

    p.write("pnpm-workspace.yaml", format!("packages:\n  - '.'\n{named}"));
    let out = run(&p).await;
    assert!(
        !attested(&out),
        "attested with the override gone from pnpm-workspace.yaml: {:#?}",
        out.refs
    );
}
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-1a2b-4a1b-8c2d-3e4f5a6b7c8d",
        mode: Hosted,
        […]

Not run: a workspace whose members have their own locks, a project with several routed patches where one override is gone, repair, and verification against an installed tree that an earlier frozen install left patched.

Planned fix

In discovery, a hosted entry in the routed shape (keyed through a registry of the CLI's, with the lock's overrides: recording it) is a reference only while the root pnpm-workspace.yaml declares that registry and that override: the writer's own test of a kept route. Otherwise it is patched_ref_invalid, naming the file, what pnpm does with such a lock, and the remedy (socket-patch scan --mode hosted, then commit pnpm-workspace.yaml).

#2396 adds the same rule for vendored file: overrides beside this code, with a reader of the lock's overrides: records; the two should share it, so this waits for #2396. The contract's pnpm row of the discovery table then says a routed reference is confirmed by the workspace file.

Related: #2382, #2396.


Generated by Claude Code

Activity

  1. added
    bug
    arch-audit
    on Dec 1, 2026
  2. added a commit that references this issue on Dec 1, 2026
  3. mikolalysenko commented on Dec 1, 2026

    @mikolalysenko
    CollaboratorAuthor

    [agent] Claiming this for the architecture refactor routine. Branch: arch-refactor/2404-pnpm-route-needs-workspace.


    Generated by Claude Code

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:triagedarch-auditbugpriority:p1

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions