Repository navigation
Description
[agent] Filed by the scheduled architecture refactor routine as a decision issue: the behavior below is the documented one, so it is not this routine's to change. main at cd7c5c5.
The question
A Python project with no environment of its own installs into the interpreter on PATH, and that interpreter is shared (distro packages, Homebrew formulae, other projects). Since #2170 a scan keeps only the packages the project declares and what those require (docs/ecosystems.md, "PyPI: projects without a virtualenv").
The filter is skipped when socket-patch "cannot read every declaration", and the list of such cases includes a PEP 751 lock. In the code it is one early return: [crawlers/python_crawler/scope.rs lines 141 to 145](https://github.com/SocketDev/socket-patch/blob/cd7c5c56e3e0049a5c06260c354a597b8f07658b/crates/socket-patch-core/src/crawlers/python_crawler/scope.rs#L141-L145), "a uv.lock, PEP 751 or PEP 723 lock lists a resolved set this module does not read either".
For the other locks on that list the skip costs nothing: a uv, Poetry or Pipenv project is never read from the shared interpreter at all (#964, #1023, #947), and PDM has #2310. A PEP 751 lock is the one that reaches it: pip installs a pylock.toml into the interpreter on PATH, as it does a requirements file (pip install -r pylock.toml, experimental in pip 26.2). So adding a pylock.toml to a pip project turns the filter off, and the scan takes every package of the shared interpreter as the project's.
Should a PEP 751 lock be read as the project's package set, so that a project that has one is scoped to the packages the lock lists (plus what its requirements files declare)? The lock is a complete resolved set by definition, which is more than a requirements file states.
What happens today
The interpreter on PATH here is /usr/local/bin/python3 (3.13), with 70 packages in /usr/local/lib/python3.13/site-packages, six 1.17.0 among them. The project pins one package, idna 3.7, which does not require six. The stand-in patch service has a patch for each. Nothing is installed for the project.
The same project without and with the lock, agent mode (dry run):
$ cat requirements.txt
idna==3.7
$ socket-patch scan --mode agent --dry-run --yes
Found 2 packages (2 python)
No patches selected. # six is not this project's
$ uv pip compile requirements.txt --format pylock.toml -o pylock.toml # uv 0.11.32; the lock lists idna only
$ socket-patch scan --mode agent --dry-run --yes
Found 71 packages (71 python)
[dry-run] Would download and apply 1 patch. No changes made.
HIGH six@1.17.0 CVE-2024-10000 # the shared interpreter's copy
A wet agent run was not made: it would write into this machine's Python.
Vendored mode, wet, same project with the lock:
$ socket-patch scan --mode vendored --yes
Found 71 packages (71 python)
Warning: pylock.toml do not contain this package version; their sources are unchanged
Vendored 2 packages. # exit 0
$ cat requirements.txt
./.socket/vendor/pypi/<uuid>/idna-3.7-py3-none-any.whl # socket-patch vendor: idna==3.7
./.socket/vendor/pypi/<uuid>/six-1.17.0-py2.py3-none-any.whl # socket-patch vendor: six==1.17.0 (transitive)
The project now installs six, and commits a wheel of it, though neither file named it and nothing it uses requires it. requirements.txt and pylock.toml no longer agree. rollback puts both files back byte for byte.
Vendored mode with the lock and no requirements.txt (a requirements.in, or a pyproject.toml): the package of the shared interpreter cannot be wired, the run exits 1 on every run, and the refusal says the project has no lockfile (#2521 covers that message).
Error: Cannot vendor pkg:pypi/six@1.17.0: no uv.lock, pyproject.toml, or requirements.txt found at the project root; use agent mode instead (…)
Vendored 1 package; 1 failed. # exit 1
Hosted mode skips the package with a true warning ("no pylock.toml archive entry for six@1.17.0") and exits 0.
The choices
- Scope by the lock. Read the package names of every PEP 751 lock at the project root and use them as the project's set in a shared interpreter, together with the declarations the scope already reads. A package of the interpreter that no lock and no declaration names is then not the project's, as for a requirements project. The docs sentence that lists a PEP 751 lock among the unread declarations would change.
- Keep it, as documented: the lock leaves the crawl unscoped.
A uv.lock or a PEP 723 script lock needs no change either way: a project with one is never read from the shared interpreter.
Not run: a pip lock pylock, a pylock.<name>.toml, a conda root as the shared interpreter, Windows and macOS.
Generated by Claude Code
Activity
refactor: L228 to L230 filed (#2521 to #2523)