Skip to content

remove and rollback <target> answer "No patch found" when the vendor ledger cannot be read #2249

Done

Description

[agent] Filed by the scheduled architecture refactor routine. Register: #2244.

Kind: bug (an error that lies; three copies of one rule disagree).

Problem

.socket/vendor/state.json is a vendored project's only record of its patches: vendored mode keeps no manifest. When that file cannot be parsed, remove <target> and rollback <target> say the patch does not exist.

A merge that leaves conflict markers in the ledger is enough:

$ socket-patch remove pkg:pypi/six@1.16.0
Error: No patch found matching identifier: pkg:pypi/six@1.16.0
$ socket-patch rollback pkg:pypi/six@1.16.0
Error: No patch found matching identifier: pkg:pypi/six@1.16.0
$ socket-patch report pkg:pypi/six@1.16.0 --dry-run
Error: Could not read the vendor ledger: corrupt ./.socket/vendor/state.json: key must be a string at line 4 column 1. To report a patch anyway, name it by its UUID
$ socket-patch rollback
Error (vendor_state_unreadable): Cannot read .socket/vendor/state.json: corrupt ./.socket/vendor/state.json: key must be a string at line 4 column 1 — the vendored leg, manifest cleanup, and GC were skipped

Under --json the first two are not_found (status: "notFound") and patch_not_found. Neither mentions the ledger, in the message or in warnings[]. The lockfiles still install the vendored artifact, and the user has been told there is nothing to take off.

The rule is written three times:

Command A target that matches nothing while the ledger is unreadable
report (report.rs L365-L386) the ledger's error, vendor_state_unreadable
remove (remove.rs L722-L768) not_found. The comment there says the ledger "falls through to not_found: nothing is mutated on that path"
rollback <target> (rollback.rs L2285-L2306) patch_not_found; a path target is path_glob_no_match (L2352-L2372)

CLI_CONTRACT.md sides with report:

  • not_found (remove): "no manifest entry, vendor-ledger entry or hosted pin matches the identifier" (L2792).
  • patch_not_found (rollback, report): "No manifest, ledger or hosted patch matches the identifier" (L2764).
  • vendor_state_unreadable (remove, vendor): ".socket/vendor/state.json cannot be read or parsed; refused fail-closed (exit 1)" (L2797).
  • report: "A store that cannot be read holds nothing: ... a PURL or a name that then matches nothing fails with that store's error ... instead of patch_not_found" (L383).

A "not found" verdict is a statement about every store, and here one of them was never searched.

Evidence

A test that gives the same project to each command, on main at 0a391c1. It runs 9 targeted commands over 3 projects (ledger only, ledger beside an empty manifest, ledger beside a manifest holding another package's patch). report passes all 6 of its runs; remove and rollback fail all 21 of theirs:

the vendor ledger could not be read, so these targets were never looked up in it:
  remove pkg:npm/x@1.0.0 --json --yes (manifest: none): not_found: No patch found matching identifier: pkg:npm/x@1.0.0
  remove x --json --yes --dry-run (manifest: none): not_found: No patch found matching identifier: x
  remove 11111111-1111-4111-8111-111111111111 --json --yes (manifest: none): not_found: No patch found matching identifier: 11111111-1111-4111-8111-111111111111
  rollback pkg:npm/x@1.0.0 --json --offline (manifest: none): patch_not_found: No patch found matching identifier: pkg:npm/x@1.0.0
  rollback x --json --offline --dry-run (manifest: none): patch_not_found: No patch found matching identifier: x (to target a directory instead, use ./x or x/**)
  rollback 11111111-1111-4111-8111-111111111111 --json --offline (manifest: none): patch_not_found: No patch found matching identifier: 11111111-1111-4111-8111-111111111111
  rollback ./node_modules/x --json --offline (manifest: none): path_glob_no_match: path pattern matched no patched packages: ./node_modules/x (path targets select installed copies; patches for uninstalled packages are reachable by identifier or an unscoped rollback)
  ... the same 7 lines for each of the other two projects

Planned fix

  • One rule for the three commands: a target that selects nothing in the stores that could be read fails with vendor_state_unreadable while the vendor ledger could not be read.
  • remove and rollback reach their "not found" exits only after that check. report keeps its behavior and moves onto the same rule.
  • Exit codes do not change (1 before and after). The error.code of this one case changes from not_found / patch_not_found / path_glob_no_match to vendor_state_unreadable, and remove's status from notFound to error.
  • CLI_CONTRACT.md gains vendor_state_unreadable among rollback's early errors.

Not in scope: what remove and rollback do when the target does match a manifest record or a hosted pin beside an unreadable ledger. The contract already describes both.


Generated by Claude Code

Activity

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

    @mikolalysenko
    CollaboratorAuthor

    [agent] Claiming this for the architecture refactor routine. Branch: arch-refactor/2249-unreadable-ledger-not-found.


    Generated by Claude Code

  3. added a commit that references this issue on Nov 25, 2026
    1623814
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:p3

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions