vex writes no document for a hosted PyPI patch under a rules_python hub when a virtualenv still holds the unpatched release, and the docs promise one

Open
#2,281 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
50/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
python, rust
Domain
backend, devtools

Research direction

Start with docs/ecosystems.md and the hosted-patch VEX verification that emits the stale_install and not_applied warnings; the issue does not name the implementation files. Compare that check with the agent-patch affected path and the pypi::hosted_pip_parse coverage in e2e_bazel_build/pypi.rs. Done when the behavior and documentation agree for a Bazel hub using the pinned lock while a virtualenv has an unpatched copy, with a regression test covering the reported commands.

Written by the indexing model from the issue text.

Description

agent:triaged bug bughunt pm:bazel priority:p1

[agent] Found by the scheduled Bazel bug-hunt routine (ledger #2262).

Summary

In a Bazel workspace whose rules_python pip.parse hub reads the project's requirements.txt, a hosted PyPI patch gets no VEX statement when a virtualenv in the project still holds the unpatched release. scan --mode hosted --yes --vex <file> pins the patch in requirements.txt and then exits 1 with "VEX generation failed"; a later socket-patch vex exits 1 as well (not_applied) and writes no document. The hub builds from requirements.txt, which now names the patched wheel, and never from the virtualenv, so the document is missing for a build that is the patched one.

docs/ecosystems.md documents exactly this for NuGet (the table cell "Supported; for a hosted patch, with no restored copy on the machine", and the known problem "vex for a hosted NuGet patch"). The PyPI cell says "Supported" with no condition, and the known problems name no PyPI case. So this is a docs promise that is wider than the behaviour, or a vex that should not let a virtualenv decide about a package the hub builds: either way the two don't agree.

Impact

A developer machine often has a .venv beside the Bazel workspace (for the editor, or for scripts outside Bazel). There the one command of hosted mode with --vex exits 1 after it wrote the pin, and vex produces nothing until that virtualenv is reinstalled, which has no bearing on what Bazel builds. Nothing is harmed and nothing false is attested: this is a missing document and a failing exit code, not a wrong statement. Vendored mode as a download cache is not affected: with the same virtualenv it attests the package from the committed wheel, with a warning.

Repro

No real bazel build ran for this report (the sandbox of the routine cannot reach the Bazel registry). The files are the checkout of tests/fixtures/bazel/rules_python/bzlmod as e2e_bazel_build/pypi.rs sets it up without a Bazel, against a loopback stand-in for the Socket API, the patch host and the index (--api-url, SOCKET_PATCH_SERVER_URL, SOCKET_PYPI_JSON_API), as that test file does. That the hub builds the patched wheel from the hosted pin is what pypi::hosted_pip_parse holds on the nightly legs (Bazel 9.3.2, 8.8.2, 7.7.2), which are green.

  1. A checkout with the fixture's MODULE.bazel (pip.parse(requirements_lock = "//:requirements.txt")), .bazelrc, BUILD.bazel, and a hashed requirements.txt that pins spvictim==1.0.0 and spdep==2.0.0.
  2. A virtualenv in the project that holds the upstream wheel: .venv/pyvenv.cfg, and the unpacked spvictim-1.0.0 wheel under .venv/lib/python3.11/site-packages/.
  3. socket-patch scan --mode hosted --yes --vex out.vex.json --vex-product pkg:generic/x
  4. socket-patch vex --product pkg:generic/x

Step 3 (the pin is written to requirements.txt, no out.vex.json):

Warning: omitting pkg:pypi/[email protected] from VEX: the installed copy is not patched (stale_install)
Warning: pkg:pypi/[email protected] was switched to a hosted patch, but installed files in ./.venv/lib/python3.11/site-packages still differ from the patched hashes. Reinstall from the rewritten lock in this interpreter and verify with `socket-patch vex`. [...]
Error: VEX generation failed: No applied patches with vulnerability metadata to attest.
exit 1

Step 4:

Warning: omitting pkg:pypi/[email protected] from VEX: the patched files still hold the original content (not_applied)
Error: No applied patches with vulnerability metadata to attest.
The patched packages are not installed yet: the installed copies still hold their original files. Reinstall from the lockfile (hosted or vendored patches) or run `socket-patch apply` (agent-mode patches), then run `socket-patch vex` again.
exit 1

Without step 2, the same two commands exit 0 and write one not_affected statement ("Patched via Socket patch ... (redirected)"). vex --no-verify writes that statement with the virtualenv present too.

Expected

docs/ecosystems.md, "Bazel workspaces: what is supported": the PyPI row says VEX is "Supported", which the section defines as "socket-patch vex and --vex say not_affected of a package the Bazel build takes patched". "Bazel workspaces: VEX" says a hub builds a package "never from node_modules, a virtualenv, a gem home, a cargo home or NuGet's packages folder".

Either the document is written for a package the hub builds from the pinned lock, whatever a virtualenv holds, or the PyPI cell and the known problems carry the condition the NuGet ones carry ("with no unpatched installed copy on the machine"), and the message says that the virtualenv, not the Bazel build, is what stands in the way.

Actual

No document, exit 1, and advice to reinstall a virtualenv that the Bazel build does not use. The run with --vex reports failure although its pin was written.

Versions

Result
main cfc870f, Linux x86_64, files of the rules_python 2.5.0-rc4 fixture, virtualenv with the upstream release reproduces (twice: scan --vex, and scan then vex)
the same without the virtualenv does not reproduce: one not_affected statement
the same with the virtualenv, scan --mode vendored (download cache) does not reproduce: one not_affected statement, with a warning that the installed tree differs
v5.1.0 not applicable: no Bazel support, and no promise about a Bazel build

Not tried: other ecosystems. The same may hold for an npm, RubyGems or Cargo hosted patch beside an installed copy that is not the patched one; only NuGet is documented.

Suspect location

The hosted-patch verification that vex runs against the installed copy (the stale_install / not_applied omission) does not ask whether a hub call of the workspace builds the package from the lock, while the affected path for agent patches does. Docs: docs/ecosystems.md, the PyPI row of the table under "Bazel workspaces: what is supported" and the known-problems list beside "vex for a hosted NuGet patch".


Generated by Claude Code

Dominant language
Rust
Stars
9
Forks
2
Avg merge
1d 8h
Merged PRs (30d)
313

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from SocketDev/socket-patch

All issues in SocketDev/socket-patch

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.