Skip to content

remove <target> reports success over a vendored package whose ledger entry is lost: the lockfile keeps installing the patched artifact and the patch record is deleted #2290

Backlog

Description

[agent] Found by the architecture refactor routine (ledger discussion #2244, lead L37), on main at cfc870f.

Problem

A lockfile still installs a package from .socket/vendor/<eco>/<uuid>/, and the vendor ledger has no entry for it. The contract names how a project gets there: a git merge that kept one side of .socket/vendor/state.json (#991), or a state.json that was deleted or never committed.

An unscoped rollback refuses that state with vendor_ledger_missing, exit 1, and writes nothing (#1739 for #991). remove <target> and rollback <target> do not ask the same question, and give four other answers. The worst one is a success:

$ socket-patch remove pkg:npm/left-pad@1.3.0 --yes
1 package already in original state

Removed 1 patch from manifest:
  - pkg:npm/left-pad@1.3.0

Manifest updated at <project>/.socket/manifest.json

Removed 2 unused blobs (65 B freed)                                                 (exit 0)

$ grep -A2 '"node_modules/left-pad"' package-lock.json
    "node_modules/left-pad": {
      "version": "1.3.0",
      "resolved": "file:.socket/vendor/npm/9f6b2c4e-1d3a-4f6b-8c2d-7e5a9b1c3d5f/left-pad-1.3.0.tgz",

The patch is reported removed and the package original. The lockfile still installs the patched tarball, and the record that described it is gone.

Who it hurts

  • Someone removes a patch, perhaps because it broke the build, and is told it is gone. npm ci keeps installing the patched package.
  • After that list no longer shows the patch, a second remove says "No patch found", and vex can no longer attest the package without the patch API (record_unavailable). Only vendor --check and repair still see the wiring.
  • In a project with no manifest (every scan --mode vendored project) the same commands exit 1 and write nothing, but say there is no patch, where rollback names the lost ledger and the way out.

Evidence on main

The binary is built from cfc870f. The projects are files only: a lockfile, the installed copies and, where stated, a manifest. vendor or scan --mode vendored ran first against the repository's prebuilt-artifact fixture (tests/prebuilt_common), and then one ledger entry or the whole state.json was removed. In every row the lockfile still names the artifact afterwards.

A project with a manifest (agent mode, then socket-patch vendor), two vendored npm packages:

Ledger Command Result
entry lost, or file deleted rollback exit 1, vendor_ledger_missing, nothing written
entry lost, or file deleted vendor --check exit 1, vendor_ledger_missing
entry lost, or file deleted rollback pkg:npm/left-pad@1.3.0 exit 0: "Rolled back 1 package: pkg:npm/left-pad@1.3.0 (already original)", "Removed 1 patch from manifest.", and the vendor_orphan_still_wired warning
entry lost, or file deleted remove pkg:npm/left-pad@1.3.0 --yes exit 0, the output above, no warning

Under --json the remove is "status": "success" with a removed event for the purl and no warnings. A requirements.txt project and a Cargo project give the same remove result (exit 0, the wiring kept, plus a rollback_not_installed skip).

What the other commands say after that remove:

$ socket-patch list                         # the patch is no longer listed
Found 1 patch:
Package: pkg:npm/is-odd@3.0.1

$ socket-patch remove pkg:npm/left-pad@1.3.0 --yes
Error: No patch found matching identifier: pkg:npm/left-pad@1.3.0                   (exit 1)

$ socket-patch vendor --check
vendor_ledger_missing: a lockfile references a vendored npm artifact under .socket/vendor/npm/ but the vendor ledger (.socket/vendor/state.json) has no entry for it; restore state.json from version control   (exit 1)

$ socket-patch vex --output - --product pkg:generic/fixture@1.0.0
Warning: omitting pkg:npm/left-pad@1.3.0 from VEX: a lockfile wires the patch, but no local record exists and the patch API could not supply one (…) (record_unavailable)

A project with no manifest (scan --mode vendored):

Ledger Command Result
entry lost rollback exit 1: "Lockfiles reference .socket/vendor/npm/9f6b2c4e-…/, which the vendor ledger (.socket/vendor/state.json) has no entry for, so rollback cannot unwind them; restore the missing entries …"
entry lost rollback pkg:npm/left-pad@1.3.0 exit 1: "No patch found matching identifier: pkg:npm/left-pad@1.3.0"
entry lost remove pkg:npm/left-pad@1.3.0 --yes exit 1: "No patch found matching identifier: pkg:npm/left-pad@1.3.0"
file deleted rollback, rollback pkg:npm/left-pad@1.3.0 exit 1: "Lockfiles still reference .socket/vendor/ artifacts but the vendor ledger is missing — restore .socket/vendor/state.json from version control, then roll back (…)"
file deleted remove pkg:npm/left-pad@1.3.0 --yes exit 1: "No patches in this project; nothing to remove."

Cause

One rule, "a lockfile reference into .socket/vendor/<eco>/<uuid>/ that no ledger entry owns cannot be unwound", is asked in two places of crates/socket-patch-cli/src/commands/rollback.rs and nowhere in remove.rs:

  • the missing-ledger early exit (line 2040), which rollback reaches only when the project has no manifest;
  • unledgered_vendor_wiring (line 1080), guarded by !scoped (line 2220).

The guard is right for a target that names another package: that run does not own the wiring. It also lets through a target that names the very package the unowned directory holds. With a manifest record for it the agent leg then finds the installed copy original and reports the patch rolled back. remove has neither check: its no-state exit (remove.rs line 614) and its unmatched-target error (line 793) never read the lockfiles.

Earlier fixes of the same class, each for one command or one cause: #1739 for #991 (unscoped rollback), #2250 for #2249 (remove and rollback <target> over a ledger that cannot be read, where the contract now says such a target "is never 'not found' while the ledger cannot be read, since the ledger may hold it").

What settles the expected behavior

Planned fix

One function answers "which unowned vendor directories does this run's target reach", and rollback and remove both call it before any write:

  1. A target that selects a manifest record whose uuid an unowned lockfile reference carries: refuse with vendor_ledger_missing, naming the directory and the remedy rollback already prints. Nothing is restored and no record is dropped.
  2. A target that selects nothing while an unowned reference exists: vendor_ledger_missing in place of "No patch found", as Report an unreadable vendor ledger instead of "No patch found" in remove and rollback #2250 did for the unreadable ledger.
  3. remove in a project whose only state is that wiring: the message rollback gives, in place of "No patches in this project; nothing to remove."
  4. A target that names another package keeps working, as the contract says.

Tests, failing on main: the first table's remove and rollback <target> rows over the npm fixture of tests/in_process_vendor.rs, and the second table's three bold rows.

One open point: the contract's error table lists vendor_ledger_missing for rollback only. Giving remove the same code is the sibling's rule and adds a row to that table.

Not checked

  • Hosted pins beside the unowned wiring.
  • --ecosystems narrowing and --global.
  • JVM artifacts, which keep their own tree layout.

Generated by Claude Code

Activity

  1. added
    bug
    arch-audit
    on Nov 26, 2026
  2. added a commit that references this issue on Nov 26, 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