Skip to content

A merge conflict in pnpm-lock.yaml makes scan --prune unwire vendored pnpm patches and report success #2334

Backlog

Description

[agent] Found by the architecture refactor routine while putting a real git merge conflict into the lockfiles of vendored projects. Run on main at cfc870f with the binary built from it, and with pnpm 10.28.0.

Problem

A pnpm-lock.yaml with git conflict markers under packages: is read as a lock that ends at the first marker. Every vendored package keyed after that line is taken for a dependency that left the lock, although the lock still installs it from .socket/vendor/. Then:

  • vendor --check says dependency removed … (it was upgraded or uninstalled) and tells the user to run socket-patch scan --mode vendored --prune. scan --mode vendored says the same and names scan --prune.
  • scan --prune (with any mode, or none) removes those packages' overrides from package.json, from the lock's overrides: block and from pnpm-workspace.yaml (it deletes the file when vendoring created it), writes into the conflicted lock, prints GC: kept 2 drifted vendored entries, and exits 0. Under --json the status is success.

The conflict need not touch a patched package. CLI_CONTRACT.md (line 453) limits the revert to an entry "the lockfile in-use probe … proves unwired, because the dependency was upgraded or removed". Here neither happened.

Who it hurts: a developer or a bot that runs a prune while a merge or rebase has left pnpm-lock.yaml conflicted, which is where vendor --check sends them. pnpm resolves such a lock itself on the next pnpm install, so without the prune the project installs the patched packages. After the prune it installs the registry's unpatched ones with exit 0, or fails a frozen install.

Evidence

The project: kleur@4.1.3, left-pad@1.3.0 and ms@2.1.2, locked by real pnpm, with left-pad and ms vendored by socket-patch vendor against the repository's fixture vendor service and committed. Two branches then bump kleur, which has no patch, to 4.1.4 and to 4.1.5, and git merges them. package.json is resolved to one side; the lock is left as git wrote it.

$ git merge b
CONFLICT (content): Merge conflict in pnpm-lock.yaml
$ grep -n "^<<<<<<<\|^>>>>>>>" pnpm-lock.yaml          # importers, packages, snapshots: kleur's lines only
16:<<<<<<< HEAD
22:>>>>>>> b
32:<<<<<<< HEAD
38:>>>>>>> b
51:<<<<<<< HEAD
55:>>>>>>> b
$ grep -c "file:.socket/vendor/npm" pnpm-lock.yaml     # both vendored packages are still wired
12

$ socket-patch vendor --check; echo "exit $?"
pkg:npm/left-pad@1.3.0: dependency removed: no lockfile resolves pkg:npm/left-pad@1.3.0 any more (it was upgraded or uninstalled), so nothing installs .socket/vendor/npm/33333333-3333-4333-8333-333333333333; run `socket-patch scan --mode vendored --prune` to revert the vendored entry
pkg:npm/ms@2.1.2: dependency removed: no lockfile resolves pkg:npm/ms@2.1.2 any more (it was upgraded or uninstalled), so nothing installs .socket/vendor/npm/44444444-4444-4444-8444-444444444444; run `socket-patch scan --mode vendored --prune` to revert the vendored entry
exit 1

$ socket-patch scan --mode vendored; echo "exit $?"
Warning: 2 vendored entries are no longer used by the lockfile (the dependency was upgraded or removed) and were skipped (pkg:npm/left-pad@1.3.0, pkg:npm/ms@2.1.2); run `socket-patch scan --prune` to revert them (…)
No packages found. Run your package manager's install first.
exit 0

$ socket-patch scan --prune; echo "exit $?"
GC: kept 2 drifted vendored entries: lock entries were re-resolved since vendoring, so their artifacts and manifest/ledger entries were retained; undo the drift and re-run `vendor --revert` to finish.
No packages found. Run your package manager's install first.
exit 0

$ git status --short
UU package.json
UU pnpm-lock.yaml
 D pnpm-workspace.yaml
$ git diff a -- package.json | grep "^[-+]{"
-{…"dependencies":{"kleur":"4.1.4","left-pad":"1.3.0","ms":"2.1.2"},"pnpm":{"overrides":{"left-pad@1.3.0":"file:.socket/vendor/npm/33333333-…/left-pad-1.3.0.tgz","ms@2.1.2":"file:.socket/vendor/npm/44444444-…/ms-2.1.2.tgz"}}}
+{…"dependencies":{"kleur":"4.1.5","left-pad":"1.3.0","ms":"2.1.2"}}
$ sed -n "/^overrides:/,/^$/p" pnpm-lock.yaml | wc -l  # the lock's overrides block is gone
0
$ grep -c "file:.socket/vendor/npm" pnpm-lock.yaml     # the importers, packages and snapshots still name the artifacts
10

scan --prune --json over the same tree exits 0 with "status": "success". Its only events are two skipped / vendor_revert_kept rows whose reason is "lock entries were re-resolved since vendoring, so the artifact and the manifest/ledger entries were retained". Nothing in the envelope says three files were rewritten. scan --prune --dry-run prints [dry-run] GC: reverted 2 vendored entries and writes nothing.

What real pnpm then does, from the same conflicted tree:

Before pnpm install pnpm install node_modules/left-pad/index.js
nothing (control) exit 0; pnpm resolves the conflict itself the patched file
socket-patch scan --prune exit 0; pnpm resolves the conflict and locks left-pad@1.3.0 and ms@2.1.2 from the registry the registry's file
socket-patch scan --prune, then the three hunks resolved by hand, then pnpm install --frozen-lockfile exit 1, ERR_PNPM_OUTDATED_LOCKFILE: "left-pad (lockfile: file:.socket/vendor/npm/…, manifest: 1.3.0)" none
the three hunks resolved by hand, socket-patch not run, then pnpm install --frozen-lockfile (control) exit 0 the patched file

After the second row vendor --check reports wiring missing for both packages, which is then true, and the next scan --prune removes the artifacts.

Where the conflict sits decides what goes (one conflict each, the same project):

The lock vendor --check scan --prune
intact (control) both verified, exit 0 writes nothing
a conflict under importers: or under snapshots: only both verified, exit 0 writes nothing
a conflict under packages: on an entry that sorts before both vendored ones (kleur) both dependency removed, exit 1 exit 0; both overrides go from all three files
a conflict under packages: between the two (leven, placed by hand) left-pad verified, ms dependency removed, exit 1 exit 0; ms loses its override, and its importer and snapshot entries are rewritten to 2.1.2 while its packages: entry stays ms@file:…
a conflict under packages: after both (zod, placed by hand) both verified, exit 0 writes nothing

vex omits both packages over the conflicted lock (vendor_unwired), so no statement is false. vendor --revert and rollback over it remove the same overrides and keep the artifacts, with a warning for each lock entry they could not find.

Cause

One walk reads the entries of a pnpm lock for every reader: entries in core formats/pnpm/grammar.rs (lines 22 to 58). It takes any column-0 line that is not a comment for a top-level key (line 29) and leaves the packages: section there (line 42). A conflict marker is such a line, so PnpmLock holds the entries before the first marker and no error.

Lockfile discovery has a rule for a lock it cannot read: it records lockfile_unparseable, and vendor_entry_in_use (core vex/discover/mod.rs, lines 2890 to 2901) then answers None, "cannot determine, so callers keep the entry", because such a file "proves nothing absent". For pnpm the only test is whether the text has a lockfileVersion: line (core vex/discover/npm.rs, line 1027). The conflicted lock passes it, the probe answers Some(false), and the CLI (commands/vendor.rs, lines 530 to 544) reads that as proof: "only there does 'no lock resolves it' prove the dependency is gone rather than unreadable".

The other line-read locks already refuse such a file:

docs/design/lock-model-divergences.md records the rule for the two neighbours: row N18 (an unparseable npm lock: "Discovery's diagnostic, surfaced by every consumer") and row N19 (a yarn.lock with a stray top-level line: "Discovery's rule", which rejects the file). pnpm has no row, because none of its readers rejects such a lock: they agree, and read it short.

The scan's own guard does not help either. A --prune that crawls nothing prints "--prune skipped: no installed packages were found, and pruning every manifest entry is too destructive to do implicitly" (CLI commands/scan/render.rs, line 454), and that covers the manifest sweep only: the run above found no package and still ran the vendored revert.

A twin of pnpm_malformed_and_unreadable_locks_are_diagnosed_not_fatal (core vex/discover/npm.rs), with the merge's conflict in place, fails on main:

/// A lock with git conflict markers under `packages:` (two branches
/// bumped `kleur`, which has no patch) still keys both vendored
/// packages after the markers. It must read as a lock that cannot be
/// read, like its `Gemfile.lock` twin, never as one the packages left.
#[tokio::test]
async fn zz_probe_a_conflicted_pnpm_lock_is_diagnosed_not_read_short() {
    let pad = format!("file:.socket/vendor/npm/{UUID_A}/left-pad-1.3.0.tgz");
    let ms = format!("file:.socket/vendor/npm/{UUID_B}/ms-2.1.2.tgz");
    let lock = |kleur: &str| {
        format!(
            "lockfileVersion: '9.0'\n\nimporters:\n\n  .:\n    dependencies:\n      kleur:\n        specifier: 4.1.5\n        version: 4.1.5\n      left-pad:\n        specifier: {pad}\n        version: {pad}\n      ms:\n        specifier: {ms}\n        version: {ms}\n\npackages:\n\n{kleur}    engines: {{node: '>=6'}}\n\n  left-pad@{pad}:\n    resolution: {{integrity: {SRI}, tarball: {pad}}}\n    version: 1.3.0\n\n  ms@{ms}:\n    resolution: {{integrity: {SRI}, tarball: {ms}}}\n    version: 2.1.2\n\nsnapshots:\n\n  kleur@4.1.5: {{}}\n\n  left-pad@{pad}: {{}}\n\n  ms@{ms}: {{}}\n"
        )
    };
    let ours = format!("  kleur@4.1.4:\n    resolution: {{integrity: {SRI}}}\n");
    let theirs = format!("  kleur@4.1.5:\n    resolution: {{integrity: {SRI}}}\n");

    // Control: the lock as pnpm wrote it resolves both vendored packages.
    let p = Project::new();
    p.write("pnpm-lock.yaml", lock(&theirs));
    let out = run(&p).await;
    assert_eq!(diag_codes(&out), Vec::<&str>::new(), "control");
    assert!(out.resolves_package("pkg:npm/left-pad@1.3.0"), "control");
    assert!(out.resolves_package("pkg:npm/ms@2.1.2"), "control");

    // What `git merge` leaves: both sides of kleur's entry.
    let conflicted = lock(&format!("<<<<<<< HEAD\n{ours}=======\n{theirs}>>>>>>> b\n"));
    assert!(conflicted.contains(&format!("  left-pad@{pad}:")));
    let p = Project::new();
    p.write("pnpm-lock.yaml", &conflicted);
    let out = run(&p).await;
    eprintln!(
        "conflicted: diagnostics = {:?}; resolves left-pad = {}; resolves ms = {}; refs = {}",
        diag_codes(&out),
        out.resolves_package("pkg:npm/left-pad@1.3.0"),
        out.resolves_package("pkg:npm/ms@2.1.2"),
        out.refs.len()
    );
    assert_eq!(
        diag_codes(&out),
        vec[DIAG_LOCKFILE_UNPARSEABLE],
        "a lock with conflict markers"
    );
}
$ cargo test -p socket-patch-core --lib -- zz_probe_a_conflicted_pnpm
test vex::discover::npm::tests::zz_probe_a_conflicted_pnpm_lock_is_diagnosed_not_read_short ... FAILED
conflicted: diagnostics = []; resolves left-pad = false; resolves ms = false; refs = 0
assertion `left == right` failed: a lock with conflict markers
  left: []
 right: ["lockfile_unparseable"]
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 8642 filtered out

The three control assertions, over the lock as pnpm wrote it, pass. The conflicted lock gives no diagnostic and resolves neither package.

Relation to #2327

#2327 is the same reading in hosted mode: the cleanup of the pnpm registry route goes through OverrideLock::parse and section_bounds (core formats/pnpm/lines.rs), a second walk that also ends a section at the first column-0 line. Its planned fix is a refusal in OverrideLock::parse, which the vendored path never calls. The two can close with one rule if the refusal lives beside the two walks.

Planned fix

  1. One function in core formats/pnpm that names the first column-0 line of a lock that is neither a key: line, a comment nor a --- separator: the twin of stray_top_level_line for Yarn.
  2. extract_pnpm records lockfile_unparseable for such a lock and reads nothing from it. vendor_entry_in_use then answers None: vendor --check and scan --mode vendored stop calling the packages removed, and the GC keeps the entries and writes no file. The message names the line, as Yarn's does.
  3. The lock inventory says the lock could not be read, where it now says No packages found. Run your package manager's install first.
  4. OverrideLock::parse calls the same function, which is the fix A merge conflict in pnpm-lock.yaml makes repair, scan --prune and a hosted scan remove pnpm registry entries the lock still uses #2327 plans.
  5. The vendored pnpm revert (vendor --revert, rollback, the GC) refuses a lock it cannot read whole before its first write.

The unit test above goes in beside its twin, with a CLI test over a conflicted lock for vendor --check and scan --prune. The contract settles the behavior (line 453: the revert is for a dependency that was upgraded or removed), so this is not a decision issue. The routine has three PRs open and awaiting review, so no PR is opened for this yet.

Not checked: pnpm 11 or later (this sandbox has 10.28.0), Rush's pnpm locks, a hosted pin that is not through the registry route, and Yarn Berry. Seen beside it and not part of this issue: over the conflicted yarn.lock (which Yarn 1.22.22 resolves itself, installing the patched tarballs) and over a conflicted bun.lock, vendor --check says wiring missing … re-run socket-patch vendor to rewire it, where over a conflicted package-lock.json it names the parse error. For Yarn, vendor then says All 2 packages are already vendored; nothing to do: it scans the blocks of a file discovery rejects, the kind of difference row N19 lists for hosted mode and the inventory. Over a requirements.txt with markers around a neighbouring line, which pip refuses, vendor --check verifies and vex attests the vendored wheel. None of the three writes a file under scan --prune.


Generated by Claude Code

Activity

  1. added
    bug
    arch-audit
    on Nov 28, 2026
  2. mikolalysenko commented on Nov 28, 2026

    @mikolalysenko
    CollaboratorAuthor

    [agent] Triaged as priority:p1 (pnpm, vendored mode; a prune unwires patches the lock still installs and exits 0).

    Related to #2327, which reports the same trigger (git conflict markers in pnpm-lock.yaml read as a lock that ends at the first marker) for the hosted registry entries. Not closed as a duplicate: this one covers the vendored overrides and pnpm-workspace.yaml, which #2327 does not. One fix at the lock reader may cover both.


    Generated by Claude Code

  3. added a commit that references this issue on Nov 28, 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:triagedarch-auditbugpriority:p1

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions