Agent to vendored switch of a PyPI package or gem fails with "no installed package found on disk" once a newer patch is published, though the copy is installed and --dry-run previews success

Offen
#2,289 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Anfängerfreundlichkeit
55/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
python, ruby, rust
Bereich
backend, cli

Rechercherichtung

Start with CandidateGates::judge in crates/socket-patch-cli/src/commands/vendor.rs and read the superseded_install and hosted_gem_install helpers. Then inspect tests/scan_vendor_e2e.rs and the three named unit tests in the issue; reproduce the PyPI and gem agent-to-vendored cases with the fixtures described. Done means a single recorded package vendors despite mismatched installed bytes, while ambiguous multiple variants still report a matching-variant problem.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

agent:triaged arch-audit bug priority:p1

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

Problem

scan --mode vendored, get --mode vendored and vendor refuse a PyPI package or a gem whose installed copy holds the patched file at bytes that are neither side of the patch, and they report it as a package that is not installed:

$ socket-patch scan --mode vendored --yes
1 package has a newer patch available.
  pkg:pypi/[email protected]: installed content differs from patch baseline; the patched content will be vendored

Vendored 0 packages; 1 not installed.
Error: Cannot vendor pkg:pypi/[email protected]: no installed package found on disk      (exit 1)

The run reads the installed copy, says the patched content will be vendored, vendors nothing, and then says no installed package was found.

The usual way into that state is a project in agent mode whose patch has since been superseded. The virtualenv (or the gem directory) holds the older patch's output, which is neither the pristine file nor the newer patch's output. So the switch from agent mode to vendored mode fails for every PyPI package and gem with a newer patch published. This is the agent-mode sibling of #2129 (hosted gem), #1105 (hosted uv) and #769 (vendored Pipenv), which each fixed one cause of the same message.

Who it hurts

  • The switch to vendored mode exits 1 and the package stays on the older patch. Beside other patched packages the run vendors those and exits 1, so CI fails on a half-switched project.
  • The message sends the user the wrong way. The package is installed, so pip install or bundle install changes nothing and the next run fails the same way.
  • --dry-run on the same tree previews success ([dry-run] Would download and vendor 1 patch).
  • Any other installed copy at other bytes gets the same report: a locally edited file, or another build of the version.

No file is damaged. The requirement line, the manifest and the installed copy stay as they were.

Evidence on main

All runs use the binary built from cfc870f (cargo build -p socket-patch-cli), a file-only project, a local stand-in for the patch API, and the repository's prebuilt-artifact fixture (tests/prebuilt_common) as the vendor service.

Agent mode on an older patch, then vendored. requirements.txt holds six==1.16.0. The virtualenv's six.py holds the output of patch A, which the manifest records. The API now offers patch B for pkg:pypi/[email protected].

$ socket-patch apply --check --offline
Patches are in sync (1 patch checked).

$ socket-patch scan --mode vendored --yes --dry-run
1 package has a newer patch available.
[dry-run] Would download and vendor 1 patch. No changes made.
  HIGH  [email protected]  CVE-2024-0001                                                  (exit 0)

$ socket-patch scan --mode vendored --yes
1 package has a newer patch available.
  pkg:pypi/[email protected]: installed content differs from patch baseline; the patched content will be vendored

Vendored 0 packages; 1 not installed.

1 vulnerability left to patch: 1 is in packages this run did not patch.
Error: Cannot vendor pkg:pypi/[email protected]: no installed package found on disk      (exit 1)

Under --json the event is {"action":"skipped","purl":"pkg:pypi/[email protected]","reason":"no installed package found on disk","errorCode":"package_not_installed","details":{"mode":"vendored"}}, with status: "partialFailure".

scan --mode agent first (it moves the copy to patch B in place) and then scan --mode vendored works. Nothing in the output names that way out.

The same package in four installed states, one patch, no newer one:

Installed six.py vendor vendor --force scan --mode vendored
the pristine file vendored vendored vendored
the patch's own output vendored vendored vendored
other bytes exit 1, "no installed package found on disk" vendored exit 1, the two lines above
no copy anywhere vendored vendored vendored

A gem (Gemfile.lock with demo-gem (1.0.0), the copy under vendor/bundle/ruby/3.4.0/gems/, its lib/demo_gem.rb at other bytes):

$ socket-patch scan --mode vendored --yes
  pkg:gem/[email protected]: installed content differs from patch baseline; the patched content will be vendored
Vendored 0 packages; 1 not installed.
Error: Cannot vendor pkg:gem/[email protected]: no installed package found on disk    (exit 1)

$ socket-patch get pkg:gem/[email protected] --mode vendored --yes
Vendored 0 packages; 1 not installed.
Error: Cannot vendor pkg:gem/[email protected]: no installed package found on disk    (exit 1)

$ socket-patch vendor --force
Vendored 1 package.                                                                 (exit 0)

npm, for comparison (node_modules/left-pad/index.js at other bytes):

$ socket-patch scan --mode vendored --yes
  pkg:npm/[email protected]: installed content differs from patch baseline; the patched content will be vendored
Vendored 2 packages.                                                                (exit 0)

Two recorded variants of one release (?artifact_id= records), the installed copy matching neither: both are skipped / package_not_installed / "no installed package found on disk". With nothing installed the same two are vendor_variant_ambiguous, which says what is wrong.

Cause

CandidateGates::judge in crates/socket-patch-cli/src/commands/vendor.rs (line 3283) runs the installed-variant probe for PyPI and gems: it hashes one patched file of the installed copy against the record (line 3313). The probe exists to choose among several release variants of one version. When the file matches neither hash the candidate is dropped (CandidateVerdict::Skip, line 3328), even when it is the only record for the package and there is nothing to choose. The dropped purl then falls into the unmatched list, whose report is "no installed package found on disk" (line 4688).

Three earlier fixes each let one cause of a failed probe through, by name:

Fix Cause it lets through Where
#825 for #769 the vendor ledger records the package at an older uuid superseded_install, line 3158
#1713 for #1105 a PyPI package the lockfiles pin hosted superseded_install
#2143 for #2129 a gem the lockfiles pin hosted hosted_gem_install, line 3182

An agent-mode patch, an edit and another build are not on that list. apply got its own honest report for an installed copy that matches no record in #2237 (no_matching_variant); the vendor path was not part of that change.

What settles the expected behavior

  • CLI_CONTRACT.md, the vendor --force row: "vendoring commits the patch server's verified artifact and never reads the installed files' content, so a missing or mismatched installed file vendors the same with or without --force (no warning)". Here the two differ.
  • The scan's own line, "the patched content will be vendored", and scan_vendor_annotates_mismatched_baseline_and_vendors_anyway (tests/scan_vendor_e2e.rs, line 1625), which pins that outcome for npm.
  • --dry-run previews the vendoring.
  • Every other ecosystem, and PyPI and gems for the three causes above, already vendor.

Planned fix

  1. One record for the package: vendor it, whatever the installed copy holds. PyPI takes the stand-in source that superseded_install already selects, and a gem keeps its installed directory as hosted_gem_install does (the backend reads only its name and gemspec, to refuse a platform gem or a native extension). The two helpers lose their lists of causes.
  2. Several recorded variants and the installed copy matches none: keep the skip, since nothing can choose among them, and stop calling it not installed. The text names the copy and the file that differs, as apply does.
  3. Tests: the agent-to-vendored switch onto a newer patch for PyPI and for a gem, through scan --mode vendored, failing on main. Three unit tests pin today's narrower rule and change with the fix: hosted_pin_marks_a_pypi_install_superseded (line 5866), hosted_pin_keeps_a_gem_install_as_the_source (line 5886) and the first assertion of judge_sends_a_hosted_gem_on_from_its_installed_dir (line 5900).

One open point, for step 2 only: whether that event keeps the code package_not_installed or takes apply's no_matching_variant. The first slice keeps the code and changes the text.

Not checked

  • Real pip and Bundler installs: the fixtures are files only.
  • A gem with a native extension or a platform gem in this state (#2129 reports that the same message replaces native_extensions_unsupported there).
  • macOS and Windows. Nothing here depends on the platform.
  • One more way into the state, seen once and with synthetic hashes: a project with no virtualenv on a machine whose own Python holds the same version of the package. The probe then judges the machine's copy.

Generated by Claude Code

Vorherrschende Sprache
Rust
Sterne
9
Forks
2
Ø Merge
1 T. 8 Std.
Gemergte PRs (30 T.)
313

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus SocketDev/socket-patch

Alle Issues in SocketDev/socket-patch

Ähnliche Issues

Weitere Issues zu Rust

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.