Repository navigation
Description
[agent] Found by the scheduled pip / requirements.txt bug-hunt routine (ledger #309).
Summary
pip lock -r requirements.txt is pip's way to turn a requirements file into a PEP 751 lock. When it runs over a requirements.txt that scan --mode hosted already rewrote, pip writes one [[packages]] table per patched package. Each table has name and a [packages.archive] holding the patch server URL and its sha256, and no version key. PEP 751 lets an archive entry leave out version, and pip always leaves it out for a direct URL.
socket-patch doesn't recognize these entries as hosted wiring:
- A re-run of
scan --mode hostedsays the patches failed. It printsSwitched 0 packagesandNo patches could be switched to hosted, reportsredirect_unconfirmedfor both packages andredirect_uv_entry_not_found("No pylock.toml archive entry for six@1.16.0"), and exits 0. Both patches are in fact still wired in both files. rollbackreports success but leaves the pylock pinned. It printsRestored pkg:pypi/six@1.16.0 to its upstream registry entryand exits 0, but only requirements.txt is restored.pylock.tomlstill pins both patched wheels, sopip install -r pylock.tomlkeeps installing the patched bytes. Nothing in the output mentions pylock.toml.- After the rollback,
listandvexfail.listexits 1 andvexexits 2 withpatched_ref_invalid: pylock.toml: Socket-wired entry "six" (from "<patch server URL>") has no name or version. The suggested remedy, re-runningscan --mode hosted, re-hosts requirements.txt but still reportsSwitched 0 packages/No patches could be switched.
Impact
A user who generates a pylock with pip's own command after hosting can't roll back: the command says it worked when it didn't, and the project's pylock still installs patched code. After that, every list and vex in CI fails. Before any rollback, every idempotent CI re-scan shows warnings that look like failures.
Repro (Linux, pip 26.3, CPython 3.12)
Patch data comes from the routine's local mock patch server (two free-shape patches, six 1.16.0 and idna 3.7). Any granted PyPI patch works the same.
git init -q p && cd p
python3.12 -m venv .venv && .venv/bin/pip install -q pip==26.3
printf 'six==1.16.0\nidna==3.7\n' > requirements.txt
git add requirements.txt && git commit -qm init
socket-patch scan --mode hosted # Switched 2 packages; rewrote requirements.txt
.venv/bin/pip lock -q -r requirements.txt -o pylock.toml
grep -c '^version' pylock.toml # 0: pip writes no version for an archive entry
git add pylock.toml && git commit -qm lock
socket-patch scan --mode hosted # "Switched 0 packages", "No patches could be switched", exit 0
socket-patch rollback # "Restored ... to its upstream registry entry", exit 0
git status --short # requirements.txt restored, pylock.toml untouched
grep -c '/patch/pypi/' pylock.toml # 2: still pinned on the patch server
python3.12 -m venv v2 && v2/bin/pip install -q pip==26.3 && v2/bin/pip install -q -r pylock.toml
v2/bin/python -c 'import six; print(six.SAFE)' # True: patched bytes after "rollback"
socket-patch list; echo $? # 1, patched_ref_invalid ... has no name or version
socket-patch vex --product pkg:pypi/app@1 -O v.json; echo $? # 2This reproduced 2/2 on main and on the v5.1.0 release.
Expected
- A hosted re-run is idempotent and reports the patches as already hosted (CLI_CONTRACT.md "What hosted mode writes": "a re-run is idempotent").
rollbackrestores every file that wires the patch, pylock.toml included, or refuses with a code that names the file. It shouldn't reportRestoredwhile a candidate lock still installs the patch.list/vexattribute a pylock archive entry that has noversionkey. The URL is in the patch server's path shape (/patch/pypi/<name>/<version>/…), and its wheel file name is<name>-<version>-…whl, so either one gives the version. (The same file name check,artifact_names_release, already exists inpypi_locks.rs.)
Actual
See the summary. Exit codes: re-scan 0, rollback 0, list 1, vex 2.
Versions
| socket-patch | pip | CPython | Result |
|---|---|---|---|
main cfc870f |
26.3 | 3.12 | reproduces (2/2) |
main cfc870f |
25.1 (first pip lock) |
3.12 | reproduces: re-scan and rollback the same |
| v5.1.0 release | 26.3 | 3.12 | reproduces: not a regression |
Linux only. Nothing here depends on the OS, so macOS and Windows should behave the same.
Suspect code
crates/socket-patch-core/src/vex/discover/pypi_locks.rs:619/:192:pylock_candidatesreadsversiononly from the table, andemitrejects the entry aspatched_ref_invalidwhen it's missing. It never falls back to the artifact file name or the patch path.crates/socket-patch-core/src/patch/redirect/mod.rs:7181: the pylock rewriter's lookup finds no entry forname@version(soredirect_uv_entry_not_found). The rollback and restore path presumably uses the same lookup, which is why pylock.toml is skipped without a word.
Generated by Claude Code
Activity