Skip to content

Vendored pip: when the hashes live in a -c constraints file, scan --mode vendored writes unhashed vendor lines, and pip 26.1+ then refuses every install #2357

Backlog

Description

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

Summary

When a project keeps its hashes in a -c constraints file (for example pip-compile --generate-hashes -o constraints.txt) and its root requirements.txt lists the packages unhashed, scan --mode vendored writes the vendor lines without --hash. Since pip 26.1, that layout installs: hashes in a constraints file satisfy hash-checking mode. After vendoring, the next pip install -r requirements.txt fails with "Hashes are required in --require-hashes mode, but they are missing from some requirements". The scan, vendor --check and vex all report success.

The cause: when vendored mode decides whether the tree is in hash-checking mode, it reads only the root file and its -r includes. It never reads the -c files, but pip turns hash-checking mode on for a hash in a constraints file too.

Impact

This breaks the "do no harm" rule. A project that installed cleanly with pip ≥ 26.1 can no longer install after scan --mode vendored, and CI fails on its next pip install -r requirements.txt. Nothing in the run warns about it: the scan exits 0, and vendor --check reports "committed artifact and wiring verified".

Repro (Linux, pip 26.3 / CPython 3.12, local mock of the patch API serving free patches for idna 3.7 and six 1.16.0)

git init p && cd p
printf 'idna==3.7\nsix==1.16.0\n' > requirements.in
pip-compile --generate-hashes -o constraints.txt requirements.in   # hashed pins
printf -- '-c constraints.txt\nidna==3.7\nsix==1.16.0\n' > requirements.txt
git add -A && git commit -qm init

python3.12 -m venv v0 && v0/bin/pip install -q pip==26.3
v0/bin/pip install -r requirements.txt            # exit 0 (baseline installs)

socket-patch scan --mode vendored                 # "Vendored 2 packages.", exit 0
cat requirements.txt
# -c constraints.txt
# ./.socket/vendor/pypi/<uuid>/idna-3.7-py3-none-any.whl  # socket-patch vendor: idna==3.7
# ./.socket/vendor/pypi/<uuid>/six-1.16.0-py2.py3-none-any.whl  # socket-patch vendor: six==1.16.0
socket-patch vendor --check                       # both "committed artifact and wiring verified", exit 0

python3.12 -m venv v1 && v1/bin/pip install -q pip==26.3
v1/bin/pip install -r requirements.txt
# ERROR: Hashes are required in --require-hashes mode, but they are missing from some requirements. ...
#     file:///…/.socket/vendor/pypi/<uuid>/idna-3.7-py3-none-any.whl --hash=sha256:589c20c6…
# exit 1

It also reproduces with a single package and a hand-written constraints.txt (six==1.16.0 --hash=sha256:<PyPI wheel hash>).

If the vendor line carries --hash=sha256:<vendored wheel sha256>, which is what vendored mode already writes when the requirements tree itself has a hash, the same install succeeds and installs the patched code on pip 26.3 and on pip 25.1. The constraint's upstream hash does not conflict with it.

Expected

The module docs for crates/socket-patch-core/src/vendor/pypi_requirements.rs say the --hash is written "only when the requirements tree is already in pip's hash-checking mode … any --hash on any line turns that mode on for the whole install". A hash in a -c file turns that mode on too, so the vendor line should carry its --hash here. Failing that, the run should refuse or warn rather than leave a project that cannot install. "Do no harm" (a project that installed cleanly before must still do so afterwards) applies.

Actual

The vendor lines are unhashed. Every later pip install -r requirements.txt fails, and the scan, vendor --check and vex give no sign of it.

Versions (Linux)

pip baseline pip install -r (before scan) after scan --mode vendored
26.3, 26.2.2, 26.1 pass fail
26.0, 25.3, 25.2, 25.1, 25.0.1, 24.3.1, 24.2, 24.0, 23.3.2, 20.3.4 fail (pip refuses hashed constraints next to an unhashed root) fail (unchanged)
socket-patch result
main cfc870f reproduces
v5.1.0 reproduces (not a regression; the layout only became installable with pip 26.1)

Hosted mode on the same project is fine: the six @ <url>#sha256=… pin installs on pip 26.3 next to the hashed constraint.

Probably the same on macOS and Windows: it comes from the requirements-tree walk, not from anything platform-specific. Not tested there (Linux-only routine).

Suspect code

  • crates/socket-patch-core/src/vendor/pypi_requirements.rs:1209 (plan_requirements) and :1397 (the re-wire planner): let hashed = files.iter().any(|f| requires_hashes(&f.content)); runs over collect_requirements_files.
  • crates/socket-patch-core/src/vendor/pypi_requirements.rs:1502: collect_requirements_files documents that "-c constraints files are never followed". That is right for editing them, but the hash-checking decision needs to read them too (and the -c files of includes, plus PIP_CONSTRAINT / pip.conf constraint = if those are in scope).

The pip ledger's known-non-bugs list ruled this layout out earlier because "pip 24 refuses hashed constraints next to an unhashed root". That stopped being true with pip 26.1.


Generated by Claude Code

Activity

  1. added
    bug
    bughunt
    pm:pip
    on Nov 29, 2026
  2. mikolalysenko commented on Nov 30, 2026

    @mikolalysenko
    CollaboratorAuthor

    [agent] More layouts that hit the same bug, from the scheduled pip / requirements.txt bug-hunt routine (ledger #309). Main cfc870f, pip 26.3 / CPython 3.12, Linux. Each baseline pip install -r requirements.txt exits 0, and each post-scan install fails with "Hashes are required in --require-hashes mode, but they are missing from some requirements" while vendor --check exits 0:

    Layout Vendor lines written Install after the change
    -c sub/constraints.txt (hashed) inside an -r base.txt include, unhashed pins in both files unhashed in base.txt and in requirements.txt fail
    Hashed constraints passed through PIP_CONSTRAINT=constraints.txt, unhashed requirements.txt unhashed fail
    Hosted first (six @ <url>#sha256=… next to -c constraints.txt, which installs patched), then socket-patch vendor to eject unhashed fail

    So the fix needs to read the -c files of includes too, and to cover the eject path, not just scan --mode vendored. PIP_CONSTRAINT (and pip.conf constraint =) live outside the project. Writing the vendored wheel's --hash whenever a constraints source is in play would cover them, and on pip 26.3 that hash doesn't conflict with the constraint's upstream hash.

    H=$(sha256sum six-1.16.0-py2.py3-none-any.whl | cut -d' ' -f1)   # the PyPI wheel
    mkdir sub && printf "six==1.16.0 --hash=sha256:$H\n" > sub/constraints.txt
    printf -- '-c sub/constraints.txt\nsix==1.16.0\n' > base.txt
    printf -- '-r base.txt\n' > requirements.txt
    git add -A && git commit -qm init
    pip install -r requirements.txt        # exit 0 (pip 26.3)
    socket-patch scan --mode vendored      # exit 0; base.txt: ./.socket/vendor/pypi/<uuid>/six-…whl  (no --hash)
    pip install -r requirements.txt        # in a fresh venv: exit 1, "Hashes are required …"

    Generated by Claude Code

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