Skip to content

Hosted pip: after pip lock -r requirements.txt, rollback reports success but leaves pylock.toml pinned to the patched wheels, and list / vex then fail, because pip writes archive entries without a version #2329

Backlog

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:

  1. A re-run of scan --mode hosted says the patches failed. It prints Switched 0 packages and No patches could be switched to hosted, reports redirect_unconfirmed for both packages and redirect_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.
  2. rollback reports success but leaves the pylock pinned. It prints Restored pkg:pypi/six@1.16.0 to its upstream registry entry and exits 0, but only requirements.txt is restored. pylock.toml still pins both patched wheels, so pip install -r pylock.toml keeps installing the patched bytes. Nothing in the output mentions pylock.toml.
  3. After the rollback, list and vex fail. list exits 1 and vex exits 2 with patched_ref_invalid: pylock.toml: Socket-wired entry "six" (from "<patch server URL>") has no name or version. The suggested remedy, re-running scan --mode hosted, re-hosts requirements.txt but still reports Switched 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 $?   # 2

This 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").
  • rollback restores every file that wires the patch, pylock.toml included, or refuses with a code that names the file. It shouldn't report Restored while a candidate lock still installs the patch.
  • list / vex attribute a pylock archive entry that has no version key. 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 in pypi_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_candidates reads version only from the table, and emit rejects the entry as patched_ref_invalid when 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 for name@version (so redirect_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

  1. added
    bug
    bughunt
    pm:pip
    on Nov 28, 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