Skip to content

Vendored pip: on a copy pip built from the sdist, scan vendors both the wheel and the sdist record onto one requirements.txt line, and vendor --check then fails for good (the printed remedy is a no-op) #2524

Backlog

Description

[agent] Found by the scheduled pip / requirements.txt bug-hunt routine (ledger #309).

Summary

Vendored mode, a PyPI release with a platform-wheel record and an sdist record (the #2194 shape: the sdist record has a src/ layout, so every file it lists is one it adds), and an installed copy that pip built from the sdist (WHEEL says Tag: cp312-cp312-linux_x86_64, which names no record).

A plain scan --mode vendored then vendors both records for the one markupsafe==2.1.5 line:

  1. It downloads and commits two artifacts (.socket/vendor/pypi/<wheel-uuid>/…manylinux…whl and .socket/vendor/pypi/<sdist-uuid>/MarkupSafe-2.1.5.tar.gz), writes two ledger entries that both claim requirements.txt:1, rewrites the line twice (the last one wins), and reports Patched 2 packages, fixing 2 vulnerabilities. It exits 0.
  2. vendor --check exits 1 straight away: the losing record is reported wiring missing: no lockfile or config references .socket/vendor/pypi/<uuid> any more … re-run socket-patch vendor to rewire it.
  3. Following that remedy does nothing. vendor --yes exits 0, says Vendored 2 packages, rewrites the line to the same winner, and vendor --check still exits 1. No command makes the check pass short of vendor --revert.

vex copes ("the recorded patch … is superseded by the lockfile-wired patch …; attesting only what the lockfile wires"), and a fresh pip install -r requirements.txt installs the winning patched artifact. vendor --revert restores markupsafe==2.1.5, but it also warns "the vendor line for requirements.txt:1 changed since vendoring; left untouched" for the second entry.

Impact

  • A CI gate on socket-patch vendor --check (the documented offline audit) fails on every run right after a successful vendored scan, and the fix it prints doesn't work. The user has to read source code to find out why.
  • The project commits a second, unused patched artifact, and the summary counts one package twice.
  • Which artifact wins depends on processing order, and it changed between releases: v5.1.0 wires the sdist, main wires the manylinux wheel. When the manylinux wheel wins, the requirements line pins a platform wheel for a user whose environment built from the sdist. Typical reasons for that are Alpine/musl, --no-binary, an sdist-only private index, or a new CPython. That is the environment least likely to accept a manylinux wheel. (Untested here: the sandbox is glibc.)

The trigger is common with pip: any install built locally from the sdist, for any platform package whose fix has a wheel record and an sdist record.

Repro (Linux, pip 26.3 / CPython 3.12, local mock of the patch service)

The mock serves two records for markupsafe 2.1.5:

  • pkg:pypi/markupsafe@2.1.5?artifact_id=cp312-cp312-manylinux_2_17_x86_64-manylinux2014_x86_64-whl (uuid 21940001-…), which replaces markupsafe/__init__.py. Its artifact is the manylinux wheel with SAFE = "wheel record" appended.
  • pkg:pypi/markupsafe@2.1.5?artifact_id=tar-gz (uuid 21940002-…), which adds markupsafe/__init__.py (beforeHash: ""). Its artifact is the sdist with SAFE = "sdist record" appended to src/markupsafe/__init__.py.

The record shapes are those of stage2.py in #2438. The mock answers POST …/patches/batch, GET …/patches/view/<uuid>, GET …/patches/blob/<hash> and POST …/patches/package (artifact grant + download).

python3.12 -m venv .venv && .venv/bin/pip install -q pip==26.3
.venv/bin/pip install -q --no-binary markupsafe markupsafe==2.1.5
grep Tag .venv/lib/python3.12/site-packages/markupsafe-2.1.5.dist-info/WHEEL   # Tag: cp312-cp312-linux_x86_64
printf 'markupsafe==2.1.5\n' > requirements.txt
export SOCKET_API_URL=$MOCK SOCKET_PATCH_SERVER_URL=$MOCK SOCKET_VENDOR_URL=$MOCK SOCKET_API_TOKEN=fake SOCKET_ORG_SLUG=o
socket-patch scan --mode vendored --yes          # exit 0, "Patched 2 packages"
ls .socket/vendor/pypi                           # 21940001-… 21940002-…
socket-patch vendor --check; echo rc=$?          # rc=1
socket-patch vendor --yes                        # exit 0, "Vendored 2 packages" (the printed remedy)
socket-patch vendor --check; echo rc=$?          # still rc=1

Output on main cd7c5c5:

Patched 2 packages, fixing 2 vulnerabilities (2 high).
requirements.txt: ./.socket/vendor/pypi/21940001-0000-4000-8000-000000000001/MarkupSafe-2.1.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl  # socket-patch vendor: markupsafe==2.1.5
pkg:pypi/markupsafe@2.1.5?artifact_id=cp312-cp312-manylinux_2_17_x86_64-manylinux2014_x86_64-whl: committed artifact and wiring verified
pkg:pypi/markupsafe@2.1.5?artifact_id=tar-gz: wiring missing: no lockfile or config references .socket/vendor/pypi/21940002-0000-4000-8000-000000000002 any more, so a fresh install gets the unpatched package; re-run `socket-patch vendor` to rewire it
vendor --check rc=1

--json check: partialFailure, the tar-gz record failed / vendor_check_failed.

Expected

  • One requirement line is wired to one artifact. CLI_CONTRACT.md ("Agent-mode apply to a PyPI release with several records") says a copy takes at most one record of a release, and that "apply, apply --check, rollback and the download narrowing of scan and get share the rule". The vendored variant probe states the same intent ("only the installed distribution's variant is vendored", vendor.rs). When the copy names no record, I'd expect one record picked deterministically, or a refusal such as vendor_variant_ambiguous (which already exists for the not-installed case). Two records vendored onto one line is neither.
  • A successful vendored scan leaves vendor --check at exit 0 (CLI_CONTRACT.md: vendor --check "exits 1 on drift"; nothing drifted here), and the remedy that --check prints fixes what it reports.

Actual

Both records are vendored. The ledger has two entries keyed to requirements.txt:1, and vendor --check exits 1 for good.

Versions

socket-patch pip / Python installed copy result
main cd7c5c5 26.3 / 3.12 built from sdist (linux_x86_64) fails: both vendored, manylinux wheel wired, check 1 (3/3 runs)
v5.2.0 26.3 / 3.12 built from sdist fails (same)
v5.1.0 26.3 / 3.12 built from sdist fails: both vendored, the sdist wired, check 1
main cd7c5c5 26.3 / 3.12 published manylinux wheel (own record) pass: scan keeps only the wheel record, check 0

This is not a regression: v5.1.0 already fails. Linux only. On macOS and Windows a locally built wheel is tagged macosx_* / win_amd64, so the same path applies.

Related variant, which also fails on the published-wheel copy: an agent-mode project with a portable manifest (scan --mode agent --all-releases, which the contract describes as "portable across environments") holds both records. Switching it to vendored with socket-patch vendor --yes correctly vendors only the wheel record (exit 0). But vendor --check then exits 1 for good with pkg:pypi/markupsafe@2.1.5?artifact_id=tar-gz: patch has no vendored ledger entry, and re-running vendor doesn't change that (main cd7c5c5, 2/2 runs). The unledgered-record loop (crates/socket-patch-cli/src/commands/vendor.rs:1708-1725) exempts gem platform builds (built_through) but not a PyPI sibling variant that the ledger's recorded variant covers. By contrast, scan --mode vendored --all-releases on the same copy passes (check 0).

Suspect code

  • crates/socket-patch-cli/src/commands/vendor.rs:3857-3881 (CandidateGates::judge): when own_wheel_record is None (the copy's wheel has no record), every candidate falls through to the representative_file probe on its own. The platform-wheel record matches __init__.py, and the all-adds sdist record is admitted (all_new_file_variant_record_is_admitted), so both reach CandidateVerdict::Vendor for the same base purl and line.
  • The download narrowing of scan --mode vendored keeps both records for the same copy, so the default scan reaches this path without --all-releases.
  • crates/socket-patch-cli/src/commands/vendor.rs:693 (the wiring missing remedy) asks for a re-run that can't help when two ledger entries claim one line.

Related: #2438 (the same release shape in agent mode), #2194 / #2409 (own-wheel case).


Generated by Claude Code

Activity

  1. added
    bug
    bughunt
    pm:pip
    on Dec 5, 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:triagedbugbughuntpm:pippriority:p1

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions