Skip to content

Fix vendor reporting a mismatched installed copy as not installed (#2289) - #2463

Open
Mikola Lysenko (mikolalysenko) wants to merge 6 commits into
mainfrom
agent/fix-vendor-mismatched-install-skip
Open

Mikola Lysenko (mikolalysenko) wants to merge 6 commits into
mainfrom
agent/fix-vendor-mismatched-install-skip

Conversation

@mikolalysenko

@mikolalysenko Mikola Lysenko (mikolalysenko) commented Dec 2, 2026 •

Copy link
Copy Markdown
Collaborator

LLM Description written by Claude Code:claude-fable-5-2

Fixes #2289

Summary

scan --mode vendored, get --mode vendored and vendor refused a PyPI package or a gem whose installed copy held a patched file at bytes that are neither side of the patch, and reported it as "no installed package found on disk" (exit 1). The usual way into that state is an agent-mode project whose patch was superseded, so the switch from agent mode to vendored mode failed for every such package, after a --dry-run that previewed success.

Now the record that is the copy's is vendored, whatever the copy holds. Vendoring commits the patch service's artifact and takes no file of the installed copy, so this is what a checkout with nothing installed, vendor --force and every other ecosystem already did. The installed copy is left as it is.

Root cause

CandidateGates::judge (CLI commands/vendor.rs) hashes one patched file of the installed copy to choose among several records of one release. A miss dropped the candidate even when there was nothing to choose, and the dropped purl fell into the "not installed" report. Three earlier fixes each let one named cause through (#769, #1105, #2129). They are now one rule, probe_miss:

The candidate is Probe miss means
the only record of the package vendor it: a gem from its installed dir, a PyPI package from the stand-in source
the record the copy's own metadata names (the wheel in its WHEEL tags, the platform in its gemspec) the same
any other record, which the ledger records at an older patch vendor it from the stand-in (unchanged, #769)
any other record set aside (unchanged)

A gem keeps its installed dir so the gem backend still reads its name and gemspec and refuses a platform gem or a native extension.

When several records are set aside and none is vendored, the report now names the copy and the file ("the copy in … is installed, but nothing says which of the patches recorded for this version is its own: six.py there has neither the original nor the patched content"). The event code stays package_not_installed and the run still exits 1.

Do-no-harm notes for the reviewer

  • Only candidates that were dropped before are affected. A copy that matches its record, a re-run, --force and a package with nothing installed take the paths they took.
  • Nothing in the installed copy is written. Both end-to-end tests compare it before and after.
  • A copy that is another build of the version (a private rebuild, say) is now replaced in the lock by the service's patched build, as it already was on a checkout without that copy installed. The scan still prints "installed content differs from patch baseline; the patched content will be vendored".

Evidence

Red to green: commit 5babef7 adds the first two tests before the fix, and each failed on main with package_not_installed.

  • Gem, e2e_redirect_gem_stale_install::vendored_takes_a_gem_whose_installed_copy_holds_other_bytes: an agent-patched copy and an edited one, through scan --mode vendored and get --mode vendored; dry run, real run and re-run.
  • PyPI, mode_migration_pypi::an_installed_copy_at_other_bytes_is_vendored_not_called_missing: requirements, uv, Poetry and Pipenv projects, a venv on an earlier patch and an edited one, with one record and with a wheel record beside an sdist record.
  • PyPI, an_installed_copy_no_record_was_made_for_is_named_not_called_missing: two records, neither the copy's; nothing is wired, exit 1, the new text in --json and on stderr.
  • Unit: probe_miss_only_drops_a_record_with_siblings (every row of the table), judge_sends_a_sole_gem_record_on_from_its_installed_dir, other_bytes_detail_names_the_copy_and_the_file. They replace hosted_pin_marks_a_pypi_install_superseded and hosted_pin_keeps_a_gem_install_as_the_source, which pinned the narrower rule.

Run locally on this branch:

Command Result
cargo test -p socket-patch-cli --lib and 45 integration suites (scan, get, in_process_vendor*, scan_*, vendor_*, mode_migration_*, e2e_gem*, e2e_pypi*, e2e_redirect_gem_*, e2e_vendor_gem_build, e2e_vendor_pypi_build, e2e_vex_vendor, in_process_gem_*, hosted_superseding_pypi, in_process_rollback_vendored) all passed
cargo clippy --locked -p socket-patch-cli --all-features -- -D warnings clean

cargo clippy --all-targets reports errors in test helpers on main as well (none in files this PR touches); CI does not run it that way. The suites that need a real Ruby or Python toolchain ran only their non-ignored tests here.

Review

/code-review high ran twice. Fixed from it: a release with a wheel record and an sdist record still failed (the copy's own record is now treated like the only one); the report could name a file the copy does not have, and could differ between runs; the contract sentence said more than the code does.

Not fixed, with reasons:

  • The human summary still counts these skips as "N not installed", beside error lines that say the copy is installed. The tally reads the event code, and whether this skip keeps package_not_installed or takes apply's no_matching_variant is the point the issue leaves open. Changing an event code is a contract change for a maintainer to decide.
  • Already on main, another cause: a gem with a ruby record and a platform record, under a lock that pins only the ruby gem, fails with platform_gem_unsupported for the platform record when the installed ruby copy is pristine (the reviewer reproduced it). The gemspec is only asked after a probe miss; asking it first for gems would fix it. Not part of this change.
  • Already on main, not reproduced: the dry-run preview of a hosted gem takeover is given the installed dir where the real run can be given the stand-in, so the two could disagree about a platform gem dir.

CI

ci-ok and clippy are green on 00b8151 (83 checks, none failed). Cursor Bugbot reviewed that commit and found no issues.

Docs

CLI_CONTRACT.md, the vendor --force row: what the probe chooses, which record is vendored whatever the copy holds, and what the remaining skip says.

Not checked

Real pip and Bundler installs (the fixtures lay the installed copies down as files), a platform gem or a native-extension gem in this state, macOS and Windows.

https://claude.ai/code/session_011f9aeSrRYzNT1nGCWDjWz6


Generated by Claude Code

Refs #2289: a sole PyPI or gem record whose installed copy holds
other bytes is reported as not installed by the vendor path.

Assisted-by: Claude Code:claude-fable-5-2
Refs #2289. Two end-to-end tests that fail before the fix: a gem and a
PyPI package whose installed copy holds an earlier agent patch or an
edited file, with one patch to vendor. The run reports the package as
not installed and exits 1.

Assisted-by: Claude Code:claude-fable-5-2
The vendor path probes one patched file of an installed PyPI or gem
copy to choose among several records of one release. A copy that held
neither side of the record was dropped even when the record was the
only one for the package, and the run then reported "no installed
package found on disk" and exited 1. An agent-mode project whose patch
was superseded is in that state, so its switch to vendored mode failed.

The only record of a package is now vendored whatever the copy holds:
a gem from its installed dir, a PyPI package from the stand-in source,
as the three earlier fixes already did for the causes they named. One
of several records is still set aside, and when no sibling matches
either, the report names the copy and the file instead of calling the
package not installed.

Fixes #2289

Assisted-by: Claude Code:claude-fable-5-2
Refs #2289. With several records for a release, the copy's own wheel
metadata can set one record aside before the probe sets the other
aside, so the mismatch is kept by release: every record of it is
reported with the copy and the file, not as a package that is not
installed. An end-to-end test covers the report in both outputs.

Assisted-by: Claude Code:claude-fable-5-2
Refs #2289. Review of the fix found that a release with a record per
artifact (a wheel's and an sdist's, a ruby gem's and a platform gem's)
still failed over an agent-patched copy: with several records, none
was vendored. The copy's own metadata already says which record is its
own (the wheel in its WHEEL tags, the platform in its gemspec), so that
record is now treated like the only one.

Only a file that is there with other content is reported as the copy's
mismatch; a record for a file the copy lacks is another distribution's.
The report is chosen by purl, so it is the same on every run, and it
says only what was compared.

Assisted-by: Claude Code:claude-fable-5-2
Refs #2289. The detail names the copy and the file only when the file
is there with other content; a record for a file the copy lacks keeps
the earlier text.

Assisted-by: Claude Code:claude-fable-5-2
@mikolalysenko
Mikola Lysenko (mikolalysenko) marked this pull request as ready for review December 2, 2026 22:05
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

bugbot run


Generated by Claude Code

@cursor

cursor Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Touches core vendor variant selection and failure reporting for PyPI/gems, but behavior is narrowed to probe-miss cases with expanded tests and leaves matching installs, --force, and re-runs unchanged.

Overview
Fixes #2289: vendor, scan --mode vendored, and get --mode vendored no longer treat a PyPI or gem install whose on-disk file hashes to neither pristine nor patched bytes as "no installed package found on disk" when the manifest record is unambiguous.

Vendor gating replaces separate superseded_install / hosted_gem_install checks with probe_miss, keyed on whether the candidate is the copy's record (sole patch for the package, or the wheel/platform metadata names that record). Those records proceed to vendoring from the patch service—gems still use the installed dir; PyPI uses the existing stand-in source—without reading patched bytes from the venv. Sibling variant records are still dropped unless the ledger shows an older vendored uuid (#769); hosted-gem pin behavior is unchanged (#2129).

When multiple records apply and the installed copy has unmatched content, the run still exits 1 but adds CandidateVerdict::OtherBytes and a clear message naming the copy path and probed file (instead of implying the package is missing). CLI_CONTRACT.md documents --force, the probe, and this skip path.

Reviewed by Cursor Bugbot for commit 00b8151. Configure here.

@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 00b8151. Configure here.

@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

[agent] PR shepherd: review brief for the approver

What it does. vendor, scan --mode vendored and get --mode vendored refused a PyPI package or gem whose installed copy holds a patched file at bytes that are neither side of the patch (typically left by agent mode applying an older patch), and called it "not installed" (exit 1). Now the copy's own record (the only record of the package, or the one its WHEEL tags or gemspec name) is vendored anyway. The service's artifact is committed, and the installed copy is never read or written. With several records and none of them the copy's, the run still exits 1, but the message now names the copy and the file instead of saying "not installed".

Risk: medium. It changes which packages vendor succeeds on, so a run that used to fail now rewrites the lock. A copy that is a private rebuild gets replaced in the lock by the service's patched build, as already happens on a checkout with nothing installed. The change is limited to the PyPI/gem variant probe (supports_release_variants minus Maven), and --force, matching copies and re-runs take the same paths as before.

Look here

Verified. I read the whole diff against main. Checked that only PyPI/gem reach the probe, and that an own-wheel Some at that point always equals the candidate (any other wheel returned Skip earlier). Checked that a release where one record was vendored drops its siblings from the unmatched report, so the new message can't contradict a success. The old hosted_gem_install/superseded_install truth tables are kept in the new unit table. The installed copy is never written, and both e2e tests compare it before and after. CHANGELOG.md is untouched. Commit 5babef7 adds the e2e tests before the fix (red on main). CI on 00b8151: ci-ok and clippy green, no review threads, and Bugbot found nothing.

Changes I made. None.

Open questions

  • These skips still count toward "N not installed" in the human summary and keep event code package_not_installed, even though the detail says the copy is installed. Should this become no_matching_variant (an event-code contract change)? The PR leaves that for a maintainer, and it doesn't block merging.

Generated by Claude Code

@mikolalysenko Mikola Lysenko (mikolalysenko) added the Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review label Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review

Projects

None yet

2 participants