Skip to content

Report a kept or failed vendored revert of scan --prune truthfully - #2246

Merged
Mikola Lysenko (mikolalysenko) merged 4 commits into
mainfrom
arch-refactor/1910-prune-gc-keep-cause
Nov 25, 2026
Merged

Mikola Lysenko (mikolalysenko) merged 4 commits into
mainfrom
arch-refactor/1910-prune-gc-keep-cause

Conversation

@mikolalysenko

@mikolalysenko Mikola Lysenko (mikolalysenko) commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

LLM Description written by Claude Code

Part of #1910. This PR takes the two user-visible defects of that issue; what stays open is listed at the end.

Problem

scan --prune reverts vendored entries whose patch left the manifest or whose dependency left the lock. It reports two outcomes of that revert wrongly, to anyone who prunes a vendored project (by hand or in CI):

  1. A keep that is not a drift is reported as a drift. When the revert restores its recorded wiring but another project file still installs from the vendored artifact (a uv export or pip freeze requirements file, for example), the artifact and the ledger entry are kept. The pass says the lock was re-resolved and tells the user to undo a drift and run vendor --revert. Nothing drifted, the lock was just restored, and the file to fix is never named: the vendor_revert_residual_reference warning is dropped. remove and rollback have told the two keeps apart since remove and rollback call a vendored PyPI residual-reference keep "lockfile wiring drifted", and their "re-run scan --mode vendored to normalize, then remove" remedy loops (Pipenv pipenv requirements export) #1184, and CLI_CONTRACT.md says this keep "is a keep too, but not a drift".
  2. A failed revert loses its reason. The pass names the purl and nothing else, under a comment saying the backend had printed its error. Nothing prints it.

Evidence on main (332b3e8)

apply_gc_names_the_file_that_still_installs_a_kept_wheel (in this PR, scan/gc.rs) seeds a requirements project whose patch left the manifest, with requirements-prod.txt still installing from the vendored wheel. Run on main:

$ cargo test -p socket-patch-cli --lib apply_gc_names_the_file
human: the file that still installs from the wheel is not named:
GC: kept 1 drifted vendored entry: 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.
test result: FAILED. 0 passed; 1 failed

The test's earlier assertions pass on main: the same pass rewrote requirements.txt back to six==1.16.0. So "lock entries were re-resolved" and "retained" are both false. The --json event said the same (reason: "lock entries were re-resolved since vendoring, …") with no warnings.

A revert the backend refuses, on main:

GC: failed to revert 1 vendored entry: pkg:pypi/six@1.16.0.

Fix

  • KeepCause::of holds the rule that tells a drift keep from a residual-reference keep. VendoredBackend::revert (behind remove, rollback, vendor --revert) and the prune GC both call it.
  • The prune GC files each unreclaimed revert through one note_unreclaimed: a keep with its cause, a failure with the backend's reason. Both of its legs had their own copy of that classification.
  • A reference keep is worded from the text remove and rollback use (KeepCause::reason / remedy), and its vendor_revert_residual_reference warning joins the pass's warnings, led by the entry's purl.

After, same fixture:

GC: pkg:pypi/six@1.16.0: kept .socket/vendor/pypi/<uuid>/: requirements-prod.txt still resolves through it, and deleting the vendored wheel would make every install from it fail; point that file back at the registry release (or re-export it from the restored lock) and re-run the revert (`vendor --revert`, `remove` or `rollback`).
GC: kept 1 vendored entry: a project file still installs from the vendored artifact (see vendor_revert_residual_reference); the recorded wiring was restored; point the file named by vendor_revert_residual_reference back at the registry release (or re-export it from the restored lock), then re-run `scan --prune`.
GC: failed to revert 1 vendored entry: pkg:pypi/six@1.16.0 (this build has no vendor backend for ecosystem `frobnicate`).

Deleted

The two hand-written keep/failure branches in run_vendor_gc, the inline classification in VendoredBackend::revert, and the comment that claimed the error had been printed.

Behavior change

Reporting only; which entries are reverted, kept or failed is untouched, and so are event codes, actions, counts and exit codes.

  • Reference keep: its own GC: kept line instead of the drift line; the reason of its skipped / vendor_revert_kept event says the cause and the remedy; warnings[] gains vendor_revert_residual_reference. A reinstall advisory the backend raised with it (Bun, vlt) is no longer dropped, since that revert did restore the lock.
  • Failed revert: the reason follows the purl in the human line and sits in the reason of the vendor_revert_failed event.
  • Drift keep: unchanged, byte for byte.

CLI_CONTRACT.md's scan --prune paragraph is updated to match.

Risk

Low. A consumer that matched the old drift sentence on a reference keep sees a different sentence; one that keyed on errorCode sees no change.

Verification

  • cargo clippy -p socket-patch-cli --all-targets --all-features -- -D warnings: clean.
  • cargo test -p socket-patch-cli --lib: 1070 passed.
  • Integration suites scan, in_process_scan, in_process_vendor, scan_vendor_e2e, scan_vendor_requirements_unwired, vendor_revert_tamper_e2e, cli_scan_silent, in_process_rollback_vendored, manifest_path_ledger_root: 575 passed.
  • No cfg(windows) or cfg(unix) code changed.

Review

/code-review high on the diff returned six findings. Fixed: the dropped reinstall advisory of a reference keep, the forwarded warning that named no package, the unsanitized failure reason on the human line, and a wrong sentence about the preview in the contract and two doc comments. Not fixed here:

  • A keep for a removed dependency is still called a drift. When a lock entry is gone but a lockfile still mentions the artifact, the shared rule has no cause for it and falls back to drift, in remove, rollback and vendor as well as here. A third cause changes the output of all four commands, so it is a change of its own; it is recorded as a lead for this routine.
  • The warning and the keep line each name a way to finish (re-run the revert; re-run scan --prune). Both work. The warning's text is the backend's and is shared by every command that reverts.
  • Warnings of several keeps come in ledger order, which is unordered. That holds for the pass's other advisories on main too.

Diff

git diff --stat: 4 files, +456 −91. Production +146 −73 (about half of it doc comments), tests +309 −17, contract +1 −1.

Still open on #1910

Moving the pass onto VendoredBackend::revert wholesale, reporting the orphan dirs a lockfile still points at, and the Go undo warnings. None of them is verified yet.

https://claude.ai/code/session_011f9aeS32WBD64v7i9wx8J6


Generated by Claude Code

Refs #1910.

Assisted-by: Claude Code
A revert that keeps its artifact keeps it for one of two reasons: the
lock drifted, or the recorded wiring was restored while another project
file still installs from the artifact. VendoredBackend::revert told
them apart inline, so a caller that reverts without it could not.

KeepCause::of holds that rule. No behavior change.

Refs #1910.

Assisted-by: Claude Code
The prune GC reverts vendored entries by hand and reported two outcomes
wrongly.

A revert that restored its recorded wiring but kept the artifact
because another project file still installs from it was reported as a
drift: "lock entries were re-resolved since vendoring ... undo the
drift and re-run vendor --revert". Nothing had drifted, the lock had
just been restored, and the warning that names the file to fix was
dropped. remove and rollback have told the two keeps apart since #1184.
The pass now classifies a keep with the same rule, words it from the
same text, and carries vendor_revert_residual_reference into its
warnings.

A revert the backend refused was reported by purl alone, under a
comment saying the backend had printed its error. Nothing printed it.
The reason now follows the purl in the human line and in the reason of
the vendor_revert_failed event.

Event codes, actions and counts are unchanged. A drift keep reads as
before.

Refs #1910.

Assisted-by: Claude Code
A keep for a residual reference restored the lock, so the reinstall
advisory a backend raises with it (Bun, vlt) applies. The pass dropped
it with every kept revert; it now drops it only for a drift keep, which
restored nothing.

The forwarded vendor_revert_residual_reference detail names a uuid
dir, not a package, so two such keeps could not be told apart. The
entry's purl now leads the detail.

The reason of a failed revert can quote the committed ledger: the human
line prints it without control characters.

The contract and two doc comments said backends cannot see a keep on a
dry run. The prune preview runs no revert at all; they say that now.

Refs #1910.

Assisted-by: Claude Code
@mikolalysenko Mikola Lysenko (mikolalysenko) added arch-refactor PR opened by the scheduled architecture refactor routine refactor Structural change: duplicated code or logic, missing abstraction, layering, dead code labels Nov 25, 2026
@mikolalysenko
Mikola Lysenko (mikolalysenko) marked this pull request as ready for review November 25, 2026 16:20
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

bugbot run


Generated by Claude Code

@cursor

cursor Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

PR Summary

Low Risk
Reporting and contract text only; no change to revert logic, exit codes, or event action codes beyond clearer reason strings.

Overview
Fixes reporting-only bugs in scan --prune garbage collection when it tries to revert vendored entries: behavior (what gets reverted/kept) is unchanged; humans and --json consumers get accurate explanations.

Residual-reference keeps are no longer described as lock drift. When a revert restores recorded wiring but another project file (e.g. an exported requirements-prod.txt) still installs from the vendored artifact, the pass now classifies that as KeepCause::Reference via shared KeepCause::of, emits cause-specific vendor_revert_kept reasons and a distinct human GC: kept line, and forwards vendor_revert_residual_reference in warnings[] with the purl prefixed—matching remove and rollback.

Failed reverts now carry the backend’s reason in both the human GC: failed to revert … line (purl plus reason) and the vendor_revert_failed event reason field.

Implementation consolidates duplicate classification in note_unreclaimed (vendor.rs) and threads (purl, KeepCause) / (purl, error) through GcSummary and VendorGcSummary. CLI_CONTRACT.md documents the new warning and messaging. Extensive unit tests lock the reference-keep and failure-reason output.

Reviewed by Cursor Bugbot for commit d46d2e1. Configure here.

Mikola Lysenko (mikolalysenko) pushed a commit that referenced this pull request Nov 25, 2026
First run under the real-problems charter. PR #2246 fixes two
misreports of scan --prune's vendored reverts (issue #1910). L01, L02
and L03 ran and are rejected; L11 and L12 are already fixed; L19 to
L22 are new.

Assisted-by: Claude Code

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit d46d2e1. Configure here.

@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

[agent] PR shepherd: review brief for the approver

What it does. Part of #1910. When scan --prune keeps a vendored entry because another project file (an exported requirements file, say) still installs from the artifact, it now says so and forwards the vendor_revert_residual_reference warning naming that file, instead of calling it a lock drift. A failed revert now carries the backend's reason in the human line and the JSON event. Which entries are reverted, kept or failed is unchanged.

Risk: low. Reporting only: event codes, actions, counts and exit codes stay the same, and the drift-keep text is byte-identical. A script matching the old drift sentence on a reference keep would see a new sentence.

Look here

  • [vendored_backend/mod.rs:501](https://github.com/SocketDev/socket-patch/blob/d46d2e1d23a5fce7294fb4e860b9b9a187de95d4/crates/socket-patch-cli/src/commands/vendored_backend/mod.rs#L501) KeepCause::of, the one shared classification rule
  • vendor.rs:5481 take_advisories (reinstall advisories now kept for a reference keep) and :5502 note_unreclaimed; its two callers at :5648 and :5693 keep the same keep/fail/revert gating as before
  • scan/gc.rs:193 JSON reasons, :738 the new human keep line, :755 the failure reason, passed through printable
  • scan/gc.rs:1759 the end-to-end test that fails on main

Verified. Read the whole diff against the description. The ledger, manifest and orphan-sweep decisions in both legs of run_vendor_gc are the same as before (note_unreclaimed returns true for exactly the old failed-or-kept cases). The failure reason is sanitized on the human path; JSON escapes its own. CI on this head: ci-ok and clippy green. No open review threads; Bugbot raised nothing. CHANGELOG.md untouched.

Changes I made. None.

Open questions. None. The description lists three follow-ups left out on purpose (a third keep cause for a removed dependency, two remedies named, warning order); none blocks this PR.


Generated by Claude Code

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[agent] Reviewed KeepCause::of against the inline rule it replaces, and the forwarded residual-reference warning, which appears once. A keep with both drift and a residual reference still reports as drift. No findings.

Merged via the queue into main with commit ddf322a Nov 25, 2026
83 checks passed
@mikolalysenko
Mikola Lysenko (mikolalysenko) deleted the arch-refactor/1910-prune-gc-keep-cause branch November 25, 2026 20:36
Mikola Lysenko (mikolalysenko) pushed a commit that referenced this pull request Nov 25, 2026
#2246 merged as ddf322a, so it moves to Merged, #2253 is unblocked,
and agent:claimed is off #1910, which stays open for L21 and L22.
#2241, the old charter's last PR, merged too.

Assisted-by: Claude Code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch-refactor PR opened by the scheduled architecture refactor routine Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review refactor Structural change: duplicated code or logic, missing abstraction, layering, dead code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants