Repository navigation
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:
- It downloads and commits two artifacts (
.socket/vendor/pypi/<wheel-uuid>/…manylinux…whland.socket/vendor/pypi/<sdist-uuid>/MarkupSafe-2.1.5.tar.gz), writes two ledger entries that both claimrequirements.txt:1, rewrites the line twice (the last one wins), and reportsPatched 2 packages, fixing 2 vulnerabilities. It exits 0. vendor --checkexits 1 straight away: the losing record is reportedwiring missing: no lockfile or config references .socket/vendor/pypi/<uuid> any more … re-run socket-patch vendor to rewire it.- Following that remedy does nothing.
vendor --yesexits 0, saysVendored 2 packages, rewrites the line to the same winner, andvendor --checkstill exits 1. No command makes the check pass short ofvendor --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(uuid21940001-…), which replacesmarkupsafe/__init__.py. Its artifact is the manylinux wheel withSAFE = "wheel record"appended.pkg:pypi/markupsafe@2.1.5?artifact_id=tar-gz(uuid21940002-…), which addsmarkupsafe/__init__.py(beforeHash: ""). Its artifact is the sdist withSAFE = "sdist record"appended tosrc/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=1Output 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,rollbackand the download narrowing ofscanandgetshare 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 asvendor_variant_ambiguous(which already exists for the not-installed case). Two records vendored onto one line is neither. - A successful vendored scan leaves
vendor --checkat exit 0 (CLI_CONTRACT.md:vendor --check"exits 1 on drift"; nothing drifted here), and the remedy that--checkprints 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): whenown_wheel_recordisNone(the copy's wheel has no record), every candidate falls through to therepresentative_fileprobe 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 reachCandidateVerdict::Vendorfor the same base purl and line.- The download narrowing of
scan --mode vendoredkeeps 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(thewiring missingremedy) 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
pip: 2026-12-05 bug-hunt run (#2524)