Repository navigation
Description
[agent] Found by the scheduled pip / requirements.txt bug-hunt routine (ledger #309).
Summary
On a plain pip requirements.txt project whose venv already has the release installed (the usual case: scan reads the venv), every message that tells the user how to pick up a hosted or vendored patch says to reinstall from the lockfile. Following that literally with pip install -r requirements.txt keeps the unpatched same-version install. pip treats the installed six==1.16.0 as satisfying six @ <patched wheel URL> or ./.socket/vendor/.../six-1.16.0-…whl, so it downloads the wheel and then doesn't reinstall it. The command that works (pip uninstall -y six then pip install -r requirements.txt, or pip install --force-reinstall -r requirements.txt) is never named. rollback / vendor --revert already name it, since #1953 (pypi_reinstall_required, crates/socket-patch-cli/src/commands/pypi_reinstall.rs:170).
These are the messages that lead to the dead end:
- Hosted scan,
redirect_pypi_stale_install: "… still differ from the patched hashes. Reinstall from the rewritten lock in this interpreter and verify withsocket-patch vex. Poetry before 1.4 may keep same-version packages: recreate the project virtualenv or uninstall this package before installing." Pipenv, Hatch and Pixi each get a verified remedy. Plain pip gets the generic one, which also mentions Poetry in a project that has no Poetry. - Hosted and vendored scan, "Next steps: 2. Reinstall from the updated lockfile, then run
socket-patch vex…". In vendored mode this is the only hint, because pip has no vendored stale-install warning (Pipenv haspypi_pipenv_stale_installand Hatch haspypi_hatch_stale_install). vex, hosted: "The patched packages are not installed yet … Reinstall from the lockfile (hosted or vendored patches) …" (exit 1).vex, vendored,vendored_tree_out_of_sync: "… re-run your package manager's install to resync it." The document still attestsnot_affectedfrom the committed artifact, as documented, while the interpreter keeps importing upstream six.
vex omits the hosted packages correctly. Nothing is mis-attested, so this is friction: the remedy doesn't work when followed. A user who follows it, runs vex again and gets the same "not installed yet" answer has no next step that works.
Impact
Anyone who adopts hosted or vendored mode on an existing pip checkout and follows the printed advice ends up running unpatched code in their dev venv or in a cached CI venv. Hosted vex keeps failing with advice that loops back to the same command. Vendored vex passes while the venv is unpatched. Fresh venvs, such as a clean CI or Docker build, are not affected.
Repro
This uses the repo's usual patch-API mock: batch / by-package / view / package grant pkg:pypi/six@1.16.0 and pkg:pypi/idna@3.7, and each artifact is the real PyPI wheel with SAFE = True appended. Real pip from PyPI.
printf 'six==1.16.0\nidna==3.7\n' > requirements.txt
python -m venv .venv && .venv/bin/pip install -r requirements.txt
VIRTUAL_ENV=$PWD/.venv socket-patch scan --mode hosted --yes # or --mode vendored
# hosted: Warning: pkg:pypi/six@1.16.0 was switched to a hosted patch, but installed files in …/.venv/… still differ …
# Reinstall from the rewritten lock in this interpreter … Poetry before 1.4 may keep same-version packages …
# both: Next steps: 2. Reinstall from the updated lockfile, then run `socket-patch vex` …
.venv/bin/pip install -r requirements.txt # follow the advice
# Collecting six @ http://…/six-1.16.0-py2.py3-none-any.whl … Downloading … (no reinstall)
.venv/bin/python -c 'import six; print(hasattr(six, "SAFE"))' # False: still upstream
VIRTUAL_ENV=$PWD/.venv socket-patch vex --product pkg:pypi/app@1 -O vex.json
# hosted: exit 1, "omitting 2 packages … (not_applied)" + "Reinstall from the lockfile (hosted or vendored patches) …"
# vendored: exit 0, not_affected [idna, six] + "re-run your package manager's install to resync it"
.venv/bin/pip install --force-reinstall --no-deps -r requirements.txt
.venv/bin/python -c 'import six; print(hasattr(six, "SAFE"))' # TrueExpected vs actual
- Expected: for a pip-managed interpreter, the remedy names a command that replaces a same-version install, the same way
pypi_reinstall_requireddoes after a rollback (pip uninstall -y <pkg>thenpip install -r <the requirements file that pins it>, orpip install --force-reinstall …), and leaves out the Poetry clause when the project has no Poetry lock. CLI_CONTRACT.md, "Python stale-install guard", says "Reinstall from the rewritten lock in the affected interpreter and verify withsocket-patch vex". It already special-cases Hatch because "Hatch's pip installer … keeps a same-version release". Plain pip keeps one too. Vendored pip could get the twin warning that Pipenv and Hatch have. - Actual: every message points to a plain reinstall, and with pip that is a no-op for a same-version pin.
Matrix (Linux; the message paths are OS-independent, and on Windows the venv is Scripts\ / Lib\site-packages, same behaviour expected)
| pip / Python | mode | plain pip install -r after the advice |
vex |
--force-reinstall |
|---|---|---|---|---|
| 26.3 / 3.12 | hosted | unpatched (2/2 runs) | exit 1, "Reinstall from the lockfile" | patched |
| 20.3.4 / 3.8 | hosted | unpatched | exit 1, same | patched |
| 26.3 / 3.12 | vendored | unpatched, no stale warning at all | exit 0 not_affected + "re-run your package manager's install" | patched |
| 26.3 / 3.12 | hosted, fresh venv | patched (not affected) | exit 0 | n/a |
Not a regression: v5.1.0 has the same wording.
Suspect code
crates/socket-patch-cli/src/commands/scan/hosted/python.rs:302: the generic remedy used for pip.crates/socket-patch-cli/src/commands/vex.rs:2147(vendored_tree_out_of_sync) andcrates/socket-patch-cli/src/commands/vex.rs:3406(the "not installed yet" hint).crates/socket-patch-cli/src/commands/scan/hosted.rs:3787/crates/socket-patch-cli/src/commands/vendor.rs:4821: the "Reinstall from the updated lockfile" next step.- The pip-specific wording to reuse:
crates/socket-patch-cli/src/commands/pypi_reinstall.rs:170.
Generated by Claude Code
Activity
pip: 2026-11-27 run, file #2302
refactor: Bazel support and Composer ran clean