Skip to content

With an unreadable vendor ledger (a git merge conflict in .socket/vendor/state.json), vex says to re-run vendor, vendor exits 0 and says to run repair, and repair fails with no remedy #2275

Backlog

Description

[agent] Found by the scheduled npm bug-hunt routine (ledger #302).

Summary

When .socket/vendor/state.json can't be parsed, the remedies the CLI prints send the user around in a loop, and none of them fixes the ledger:

  1. vex refuses (exit 2, vendor_ledger_corrupt) and says "Restore it from version control or re-run socket-patch vendor".
  2. socket-patch vendor exits 0 with only a warning: "the vendor ledger could not be read … Run socket-patch repair to check the vendored artifacts."
  3. socket-patch repair exits 1 ("Could not read the vendor ledger: …") and gives no remedy.

scan --mode vendored, rollback and vendor --check also fail (exit 1) without saying what to do. The only thing that works is fixing the JSON by hand or restoring it from git.

The realistic way to get here is a plain git merge. Two branches each vendor a different patch, and git conflicts on state.json (add/add on the same entries map) while it auto-merges package-lock.json cleanly. After the merge, npm ci installs both patched packages, but every socket-patch command that reads the ledger fails. "Restore it from version control" doesn't help here, because neither side alone is right. The user has to merge both sides' entries by hand, and nothing says so. The closed #1072 fixed the same kind of loop for the orphan-artifact remedy, which now explains "if a git merge kept one side of state.json, merge both sides". These remedies don't.

The maintainers decided in #1072 not to rebuild the ledger automatically, so this issue only asks for remedy text that works, and arguably for vendor to exit non-zero.

Impact

  • In CI, a socket-patch vex step fails after a routine merge. The user is told to run socket-patch vendor, which reports success (exit 0) and changes nothing, so a CI step that runs vendor before vex still fails on vex.
  • A user following the printed advice can't get out of the state.

Repro (npm 12.2.3 / Node 22, Linux; a local mock of the patch API serving free patches for left-pad@1.3.0 and is-number@7.0.0)

mkdir app && cd app
echo '{"name":"app","version":"1.0.0","private":true,"dependencies":{"left-pad":"1.3.0","is-number":"7.0.0"}}' > package.json
npm install && echo node_modules > .gitignore
git init -q && git add -A && git commit -qm init
SP="socket-patch --api-url $MOCK --api-token fake --org o --patch-server-url $MOCK"
git checkout -qb a && $SP get <left-pad-uuid> --mode vendored --yes && git add -A && git commit -qm a
git checkout -q main && git checkout -qb b && $SP get <is-number-uuid> --mode vendored --yes && git add -A && git commit -qm b
git merge a        # CONFLICT (add/add) in .socket/vendor/state.json; package-lock.json auto-merges
rm -rf node_modules && npm ci        # exit 0, both packages patched
$SP vex --output v.json; echo $?     # 2: "... Restore it from version control or re-run `socket-patch vendor`."
$SP vendor; echo $?                  # 0: "Warning: ... Run `socket-patch repair` to check the vendored artifacts."
$SP repair; echo $?                  # 1: "Error: Could not read the vendor ledger: corrupt ./.socket/vendor/state.json: key must be a string at line 4 column 1"

It also reproduces with any hand-corrupted state.json (echo '{broken' > .socket/vendor/state.json), with the same three messages.

Expected

Each command that refuses should name a step that gets the user out. For example: ".socket/vendor/state.json is not valid JSON (a git merge conflict?). Resolve it by keeping both sides' entries, or restore it with git checkout -- .socket/vendor/state.json, then re-run." vendor shouldn't exit 0 while it can't read the ledger it owns, or at least shouldn't send the user to repair, which refuses the same input. CLI_CONTRACT's vex section treats a corrupt vendor ledger as a failure ("a corrupt vendor ledger … exits non-zero"), and the remedy text is the user's only guide.

Actual

The remedies loop: vex → vendor (exit 0) → repair (exit 1, no remedy).

Build npm Reproduces
main cfc870f 12.2.3 yes (merge conflict and hand-corrupted)
v5.1.0 12.2.3 yes (same messages; not a regression)

This isn't specific to npm: the ledger and these messages are shared by every vendored ecosystem. It should behave the same on macOS and Windows.

Suspect code

  • crates/socket-patch-cli/src/commands/vex.rs:2473: "… or re-run socket-patch vendor."
  • crates/socket-patch-cli/src/commands/vendor.rs:2678 (no_manifest_ledger_unreadable): the warning, exit 0, "Run socket-patch repair".
  • crates/socket-patch-cli/src/commands/vendor.rs:755: Could not read the vendor ledger with no remedy (used by repair / scan).

Generated by Claude Code

Activity

  1. added
    bug
    bughunt
    on Nov 26, 2026
  2. mikolalysenko commented on Dec 1, 2026

    @mikolalysenko
    CollaboratorAuthor

    [agent] Re-checked on main 1b3f422 (npm 10.9.9 / Node 22, Linux) with a hand-corrupted .socket/vendor/state.json ({broken).

    5af6187 (#2261) changed part of the loop. vendor no longer sends the user to repair. The rest still reproduces:

    $ socket-patch vex --output v.json; echo $?
    Error: The vendor ledger .socket/vendor/state.json is unreadable (corrupt ./.socket/vendor/state.json: key must be a string at line 1 column 2); refusing to attest from a partial view. Restore it from version control or re-run `socket-patch vendor`.
    2
    $ socket-patch vendor; echo $?
    Warning: No manifest to vendor from, and the vendor ledger could not be read: corrupt ./.socket/vendor/state.json: key must be a string at line 1 column 2
      Restore .socket/vendor/state.json from version control.
    0
    $ socket-patch repair; echo $?
    Error: Could not read the vendor ledger: corrupt ./.socket/vendor/state.json: key must be a string at line 1 column 2
    Repair finished with errors.
    1
    

    What's still open:

    • vex still says "or re-run socket-patch vendor" (crates/socket-patch-cli/src/commands/vex.rs:2474). That command exits 0 and fixes nothing.
    • vendor still exits 0 when it can't read the ledger.
    • No message covers the merge-conflict case, where "restore from version control" doesn't work because neither side alone is right.

    I'm leaving the issue open.


    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:triagedbugbughuntpm:npmpriority:p1

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions