Skip to content

Agent-mode PyPI variant selection uses one representative file, not the installed wheel's tags, so wheels that share .py files all match #2194

Open

Description

Summary

In agent mode a release variant of a PyPI package (a record keyed ?artifact_id=<wheel filename>) is matched to the installed distribution by the hash state of ONE file: the lexicographically smallest key with a non-empty beforeHash (representative_file, crates/socket-patch-cli/src/commands/apply.rs:1199, mirrored by select_installed_variants in core). The installed wheel's own WHEEL Tag: lines are not consulted; they are read only on the hosted path (crates/socket-patch-core/src/hosted/wheel_record.rs:121).

Why this matters

Platform wheels of one release usually share their .py files byte for byte and differ only in the compiled extension. Measured on pillow 12.3.0: all 97 .py files are identical across the manylinux x86_64, manylinux aarch64, musllinux and macOS arm64 wheels. If a patch changes both a .py file and the extension (or only the extension, with a .py file also listed), the representative file is the shared .py, so every variant record "matches" the install. Each matching variant is then applied; for the variants built for another platform the extension's beforeHash does not match. With the default policy that fails closed, so the user gets a failure for a package that has a correct variant; with --force / --allow-patch-conflicts a library built for another platform can be written.

This is from reading the code; I did not reproduce it end to end.

Suggested direction

Select the variant from what the install says it is: the Tag: lines of *.dist-info/WHEEL (and the gem platform, which agent mode already consults) against the variant's artifact_id. Keep the hash probe as a second check, on a file that actually differs between variants when one exists.

Activity

  1. added
    enhancement
    pm:pip
    on Nov 22, 2026
  2. mikolalysenko commented on Nov 29, 2026

    @mikolalysenko
    Collaborator

    [agent] Reproduced end to end on main at cfc870f, with the built binary and a stand-in patch API. It needs no compiled extension. A pure-Python release with a wheel record and an sdist record is enough, because the wheel and the sdist hold the same module bytes.

    Two real releases, installed from their wheels by uv: requests 2.31.0 and six 1.16.0. Each has two records. The wheel's replaces one module. The sdist's replaces the same module and setup.py, which only the sdist holds. A plain socket-patch scan --mode agent, without --all-releases:

                     file that decides    the sdist's record              scan
    requests 2.31.0  requests/utils.py    kept, then tried on the wheel   exit 1
    six 1.16.0       setup.py             narrowed away                   clean
    
    Error: Failed to patch pkg:pypi/requests@2.31.0?artifact_id=tar-gz: Cannot apply patch: setup.py - File not found
    Applied 2 of 3 patches: 1 failed.
    Error: Some patches could not be applied.
    

    The two releases differ only in which name sorts first: requests/utils.py, then setup.py, then six.py. The doc comment of variant_matches_installed (crates/socket-patch-cli/src/commands/apply.rs, line 1170) names this very input as one to skip: "an sdist patching setup.py while a wheel is installed".

    The installed requests is fully patched by the wheel's record, and the project still fails from then on:

    Command Result
    scan, apply exit 1 on every run, 1 failed
    apply --check exit 1: "a patched file is missing from an installed copy. Run socket-patch apply to regenerate them." apply cannot
    rollback --yes exit 1: "Cannot roll back: setup.py - File not found". The wheel's record is rolled back and removed, the sdist's stays
    remove 'pkg:pypi/requests@2.31.0?artifact_id=tar-gz' exit 1: "Rollback failed during patch removal"
    the same with --skip-rollback removes the record and apply passes, until the next scan downloads the record again (as an upgrade of its sibling, #2370) and fails
    vex exit 0: attests the wheel's record and warns that it omits the sdist's

    Not checked: what the patch service's records hold. This sandbox has no route to it, so the two records per release are a stand-in's. If an sdist record never replaces a file that the wheel lacks, the platform wheels of this issue are the input that remains.

    The fixture is 30 lines of Python beside a stand-in API. Both are in the architecture refactor routine's ledger entry of 2026-11-29, 16:55Z, on the arch-audit/ledger branch.


    Generated by Claude Code

  3. added a commit that references this issue on Nov 29, 2026
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:triagedenhancementpm:pippriority:p1

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions