Repository navigation
Fix agent mode failing on PyPI releases that have a wheel and an sdist record (#2194) - #2409
Mikola Lysenko (mikolalysenko) wants to merge 4 commits into
Conversation
A PyPI release can have one patch record per artifact a patch was made
from: a wheel, a wheel per platform, the sdist. Agent mode matched a
record to an installed copy by the first file it replaces, which does not
tell the artifacts of a release apart.
A wheel's install also took the sdist's record. For urllib3 2.2.2 the
patch service has a record made from the wheel and one made from the
sdist, whose sources are under src/: read against an install, every file
of that record is one the patch adds, so it had no file to be matched by
and matched any copy. A plain agent-mode scan then exited 1 on every run
("File already exists, but the patch adds it as a new file"), and a
vendored scan failed on the same record. The same happens for urllib3
2.3.0, 2.2.3, 1.26.20 and 1.26.19.
A platform wheel's install took another platform's record. The platform
wheels of a release share their Python files byte for byte, so a record
that replaces one of them and the wheel's compiled module matched every
install. With two such records in the manifest, a default apply wrote the
other platform's extension module over the installed one and exited 0;
with one, --force and --allow-patch-conflicts did.
An installed copy says which wheel it came from in the Tag lines of its
WHEEL metadata, which is what a record's artifact_id spells. So:
- the record made from the copy's own wheel, when it matches the copy,
is the copy's only record, as a platform gem's copy takes its
platform's record. select_installed_variants applies it for apply
--check, vex, rollback and the download narrowing of scan and get;
apply and vendor ask it at their own gates;
- a platform wheel's record that the copy's WHEEL does not name as its
own has to match on every file it replaces, under any flag.
A release with no record of the installed wheel, and a copy with no
WHEEL tags, are matched as before, so a release whose only record was
made from the sdist still patches a wheel's install.
Fixes #2194.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A conda build never takes a platform wheel's record, and `apply` has its own account of such a record: it is tried last, refused aloud only when it is the first record tried on the copy, and quiet after another record of the release. The file-by-file check for another wheel's record ran first and skipped the record, so a pure-Python conda build whose file is not the release's reported the platform wheel's record as "no matching installed package" beside the pure wheel's failure. The check now passes over the records a conda build never takes. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The first version made the record of the copy's own wheel its only record, while that record matched the copy. Review found what that left open or broke: - when the own record did not match (a file edited after the install, a copy holding an earlier patch), the sdist's record was tried again and failed as before; - a record that says the same as the copy's own (a wheel's and its sdist's replacing one module with the same content) became "not installed", which the conda rule and its contract paragraph do not say; - a record rejected on a file other than its first was reported as not installed, with no file named; - vendor --force skipped the check. One rule replaces it. The record made from the copy's own wheel is matched as any record is. A record made from another artifact is the copy's only when every file it lists is: each file it replaces holds one side of the record, and each file it adds is absent or holds the patch. That is asked of every other record of a release that has a record of the copy's own wheel, and of a platform wheel's record on any copy that does not name that wheel. It does not depend on the own record matching, and no flag relaxes it. - select_installed_variants asks it, so apply --check, vex, rollback and the download narrowing share it; apply asks it at its variant gate. - The download narrowing hands the selector a record's added files too. It dropped them, which is why the sdist's record of a src/ layout had no file to be matched by. - A copy no record matches names the file that says so (no_matching_variant), also when that file is not a record's first. - vendor commits one artifact per package: on a copy that names its wheel it vendors that wheel's record alone, and asks no file, so --force does not skip it. - The conda fixture writes the Tag lines a real WHEEL has. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The help text of `vendor --force` says it bypasses the installed-variant probe and vendors every recorded release variant. The own-wheel check for a PyPI copy is part of that probe, so it runs where the probe runs and `--force` skips it, as it skips the rest. The previous commit had moved it out from under `--force`. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
PR SummaryMedium Risk Overview A new Download narrowing now builds variant file maps with CLI_CONTRACT documents the rule. Coverage: core unit tests, vendor gate test, and offline e2e Reviewed by Cursor Bugbot for commit 7cf1dbc. Configure here. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 7cf1dbc. Configure here.
| if let Some((name, VerifyStatus::HashMismatch)) = anothers.await { | ||
| differs.insert(name.strip_prefix("package/").unwrap_or(name)); | ||
| continue; | ||
| } |
There was a problem hiding this comment.
Missing files omitted from variant errors
Low Severity
no_variant_reason only records a file from anothers_record when the status is HashMismatch. A platform record rejected because a compiled module is absent (NotFound) falls through to the representative-file check, which often matches a shared Python file, so differs stays empty and the no_matching_variant message does not name the file that actually disqualified the record.
Reviewed by Cursor Bugbot for commit 7cf1dbc. Configure here.


Fixes #2194.
The problem
A PyPI release can have more than one patch record: one for each artifact of the release a patch was made from (
?artifact_id=py3-none-any-whl, a wheel per platform,tar-gzfor the sdist). Agent mode decided which record belongs to an installed copy by hashing one file of the record, the first one it replaces. That one file does not tell the artifacts of a release apart, and two things went wrong.1. A wheel's install also took the sdist's record. This fails today, with the patch service's real records.
For
urllib32.2.2 the service has a record made from the wheel (it replacesurllib3/response.py) and one made from the sdist. The sdist keeps its sources undersrc/, so read against an install every one of that record's 36 files is a file the patch adds. A record with no file to hash matched any copy. Onmain, afterpip install urllib3==2.2.2:The wheel's record is applied, the copy is patched, and every later
scanandapplystill exits 1. I ran the same scan for the otherurllib3releases that have both records:urllib3mainVendored mode fails on the same release for the same reason (
scan --mode vendored, exit 1:prebuilt wheel for pkg:pypi/urllib3@2.2.2 does not carry the patched files at their recorded paths, for the sdist's record), and exits 0 on this branch.The shape in the issue's comment (an sdist record that replaces a module and
setup.py, the module sorting first) is the same defect and is covered by a test.2. A platform wheel's install took another platform's record.
The platform wheels of one release share their Python files byte for byte. A record that replaces a shared
.pyfile and the wheel's compiled module was matched by the.pyfile, so every platform's record matched every install. With the macOS and the Linux wheel's records in the manifest, a plainapplyonmainover a macOS install:The installed extension module is then the Linux build. The default mismatch policy allowed it because the file held the output of another Socket patch (the macOS record's, applied a moment earlier). With the Linux record alone, the default policy refuses, and
--forceor--allow-patch-conflictswrites it. No live patch was made from a platform wheel yet, so this one has not happened to anyone; it would with the first such patch.The fix
An installed copy says which wheel it came from: an installer writes the wheel's
WHEELmetadata into<name>-<version>.dist-info, and itsTag:lines (andBuild:line) are the tags of the wheel's file name, which is what anartifact_idspells. The record made from that wheel is the copy's own and is matched as before.One rule, in a new core module
patch/pypi_wheel.rs: a record made from another artifact is the copy's only when every file it lists is. Each file it replaces must hold one side of the record, and each file it adds must be absent or hold the patch. That is asked ofNo flag relaxes it, as for a conda build:
--forceconsents to overwriting local changes to the distribution a patch was made for, not to writing one artifact's files into another's install.It runs in
select_installed_variants, soapply --check,vex,rollbackand the download narrowing ofscanandgetshare it, and atapply's own variant gate. The download narrowing now hands the selector a record's added files too (it dropped them, which is how the sdist's record had "no file").vendorcommits one artifact per package, so its installed-variant probe takes the record of the copy's own wheel and no other.vendor --forcebypasses that probe and vendors every recorded variant, as its help text says; that is unchanged.What stays as it was:
urllib31.20 is one.idna3.10 is one).WHEELtags (an.egg-infoinstall) names no wheel.How a record the rule keeps from a copy is reported:
skipped/package_not_installedwhen another record was tried on the copy; when none was, the copy fails asno_matching_variantand the message names the file that holds neither side (for the Linux record on a macOS install,PIL/_imaging.abi3.so).Review
/code-review highon the first version found six things. Five are addressed by the rework in the third commit; one is left on purpose.Tag:lines so the suite exercises it.package_not_installedwith no file named: it isno_matching_variantnow, with the file.vendor --forceskips the check: left as it is.--forceis documented as bypassing the installed-variant probe to vendor every recorded release variant, and this check is part of that probe (tested both ways).WHEELonce per record of a multi-record release; I left that, since production has about ten such releases.What it does not fix
scanof theurllib3project still lists the sdist's record underupdates[]("a newer patch available") on every run. That is the classification bug filed there; it no longer comes with a failure.urllib32.2.2 the pin ends on the patched sdist). It installs and exits 0; A release variant beside a recorded sibling is an upgrade on every scan: "1 package has a newer patch available" and updates[] never clear, and a hosted re-scan reports a rewrite it does not make #2370 describes it.setup.py), on a release with no wheel record, still cannot be applied. No live record has that shape.applythen exits 0 and reports that record as not installed.Tests
patch/pypi_wheel.rs: 11 unit tests (tag reading, compressed tag sets, build numbers, the own record, the every-file rule,select_installed_variantsandselect_installed_variants_anyover each shape).tests/apply/pypi_release_variants.rs: 9 CLI tests over hand-built site-packages, offline:apply,apply --force,apply --allow-patch-conflicts,apply --checkandrollback. Seven fail againstmain's binary; the other two pin behaviour that must not change.commands/vendor.rs: one unit test of the vendor gate for the wheel and sdist pair, with and without--force.applyover a manifest saved with--all-releases(five records of three releases) withapply --check,vexandrollback, and a vendored scan withvendor --checkand a re-scan.Overlap: #2392 rewrites the gem half of the same variant gate in
commands/apply.rs. The hunk here is placed apart from its hunks, so the two should merge without conflicts in either order.🤖 Generated with Claude Code