Skip to content

scan --prune reports a clean pass over a vendor ledger it could not read #2253

In review

Description

[agent] Filed by the scheduled architecture refactor routine. Register: register comment, leads L23 and L24.

Kind: bug (an error that is dropped). Checked on main at da012af.

Problem

A merge conflict left in the committed .socket/vendor/state.json makes the vendor ledger unreadable. rollback, list and vendor --check say so. scan --prune does not: its vendored half returns without doing anything, and the run reports a clean pass.

$ cat .socket/vendor/state.json
{
<<<<<<< HEAD
$ socket-patch scan --prune --json      # the envelope's status and gc; it has no warnings[]
"status": "success",
"gc": { "removedBlobs": 0, "removedDiffArchives": 0, "removedPackageArchives": 0, "bytesFreed": 0, "removedRegistryEntries": 0 }
$ socket-patch scan --prune             # human mode: no GC line, no warning, exit 0
No SOCKET_API_TOKEN set (and no socket-cli login found) — using the public patch API proxy (free patches only). […]
Found 1 package (1 npm)
No patches available for installed packages.

(The scans ran against a local stand-in for the patch API that answers "no patches".)

The same project, the other commands:

Command What it reports
rollback --json partialFailure, warnings[]: vendor_state_unreadable and gc_skipped ("artifact GC skipped: the vendor ledger is unreadable, so artifact ownership cannot be established"), exit 1
list --json warnings[]: vendor_state_unreadable
vendor --check --json error.code: vendor_state_unreadable, exit 1
scan --prune --json, also with --dry-run or --mode vendored success, a gc of zeros, no warning

So someone who runs scan --prune in CI to keep vendored state reconciled gets a green run that reconciled nothing, for as long as the ledger stays broken, and nothing in the output tells them to look at the ledger.

The manifest half is safe: with an unreadable ledger the scan recovers the vendored purls from the committed artifacts, so no vendored package's manifest record is pruned (corrupt_ledger_recovers_vendored_purls_from_committed_artifacts and its siblings in scan/discovery.rs). Only the report is wrong.

Where the error is dropped

  1. run_vendor_gc matches the ledger load with _ => return out, so a read error and an empty ledger give the same empty summary.
  2. One step earlier, has_ledger is metadata(..).is_ok_and(..): a ledger that cannot be stat'd counts as no ledger, and with no manifest the pass returns before the lock (run with state.json as a symlink to itself: the same clean success). Just above its use in run_apply_gc, a manifest that cannot be stat'd counts as present, under the comment "A manifest that cannot be stated is not absent". (Report an unreadable vendor ledger instead of "No patch found" in remove and rollback #2250 fixes this stat probe in remove, rollback and repair.)

The same class, in plain vendor

With no manifest and an unreadable ledger, plain vendor warns in human mode and says nothing under --json (vendor.rs L1109-L1116 loads the ledger only when the run is neither --json nor --silent):

$ socket-patch vendor
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 3 column 1
  Run `socket-patch repair` to check the vendored artifacts.
$ socket-patch vendor --json            # the envelope's status; it has no warnings[]
"status": "noManifest"

list --json had the same gap and closed it: the contract's vendor_state_unreadable row says "list --json (additive): … the warning says so (human mode already printed it on stderr)".

Evidence

A unit test in scan/gc.rs, next to apply_gc_reports_drift_kept_vendored_entry: seed a manifest, write the conflicted ledger above, run run_apply_gc, and assert that the recorded envelope has a vendor_state_unreadable warning. On da012af it fails:

recorded: {"command":"scan","status":"success","dryRun":false,"events":[], … ,"gc":{"removedBlobs":0,"removedDiffArchives":0,"removedPackageArchives":0,"bytesFreed":0,"removedRegistryEntries":0},"removedVendorOrphanDirs":0}
the vendored half did not run, and the pass must say why
test result: FAILED. 0 passed; 1 failed

Planned fix

  • run_vendor_gc returns the ledger's load error instead of an empty summary. The prune pass records it as a vendor_state_unreadable entry in warnings[] (human: a GC: … line), as rollback and list do. The manifest half still runs.
  • has_ledger takes only "not found" for absence.
  • vendor --json's noManifest envelope carries the warning human mode prints.
  • Exit codes stay as they are: in the contract a failed GC revert and a skipped pass leave the scan's exit alone, and the no-manifest vendor is a clean exit-0 no-op. CLI_CONTRACT.md gains the warning in the scan --prune paragraph and the vendor_state_unreadable row.

#2246 changes run_vendor_gc and scan/gc.rs, so this waits for it to merge.


Generated by Claude Code

Activity

  1. added
    bug
    arch-audit
    on Nov 25, 2026
  2. added 2 commits that reference this issue on Nov 25, 2026
  3. mikolalysenko commented on Nov 25, 2026

    @mikolalysenko
    CollaboratorAuthor

    [agent] Claiming this for the architecture refactor routine. Branch: arch-refactor/2253-prune-unreadable-ledger.

    Re-ran on main at cfc870f: scan --prune --json is still success with no warning over a conflicted ledger and over a ledger that cannot be stat'd, and vendor --json is still a bare noManifest. Three unit tests in scan/gc.rs that assert the warning fail there.

    The PR also takes the still-wired orphan bullet of #1910: it is in the same function, and the prune pass is the only one of the sweep's four callers that says nothing about a vendored directory a project file installs from and no ledger entry owns.


    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:claimedagent:triagedarch-auditbugpriority:p3

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions