Skip to content

Decline PyPI and RubyGems vendored mode where a Bazel hub reads the lock - #2208

Open
Mikola Lysenko (mikolalysenko) wants to merge 9 commits into
mainfrom
bazel-guard/vendored-hub-locks
Open

Mikola Lysenko (mikolalysenko) wants to merge 9 commits into
mainfrom
bazel-guard/vendored-hub-locks

Conversation

@mikolalysenko

@mikolalysenko Mikola Lysenko (mikolalysenko) commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Vendored mode now declines a PyPI or RubyGems package when a rules_python or rules_ruby hub of the project's Bazel workspace reads the lock it would rewrite (vendor_pypi_bazel_hub, vendor_gem_bazel_hub), where it used to exit 0 and leave a build that fails.

It follows #2186, which declines Composer vendored mode in a Bazel workspace. It uses that change's switch (--allow-vendored-in-bazel), its exit codes, and its one entry for refusals that rest on the Bazel workspace.

Based on main, in two commits. The first is tests only and records what main does today. The second is the change, with the expectations of the first changed to match.

Decisions for the maintainer

  1. An uncertain reading declines, and that includes a root MODULE.bazel or WORKSPACE file that cannot be read, in a workspace that may not use the ruleset at all. The other choice is to go on as today, which keeps a vendored run for such a workspace and breaks the build for one whose hub does read the lock.
  2. A WORKSPACE call counts, although Bazel 8 and 9 may not read that file. Without it, pip_parse and rb_bundle_fetch workspaces on Bazel 7 keep the broken build.
  3. The refusal is for every package whose run would write a file the hub reads, not only the packages that file pins. For a uv, Pipenv or PEP 751 project that is every package the requirements files name in any form. The narrower choice (only a pin in the exact shape that is wired with the lock) spares a range or an extras line, and has to see two more cases to stay safe: a hosted pin that a takeover restores before it wires, and the vendored line of an earlier patch.
  4. What lets an already vendored package through. The file the call names must name the copy of the same patch, and nothing passes under an uncertain reading. The looser choice (any file of the project names the copy; pass under doubt too) spares a few projects the switch on their routine runs, and can let a run that exits 0 write a vendored line into a file the hub reads.
  5. The names of the two codes, vendor_pypi_bazel_hub and vendor_gem_bazel_hub.
  6. vex for a gem vendored with the switch. rules_ruby builds a vendored gem only when the call lists the copy's files as srcs, which is not read. Should vex say affected there, as it does for PyPI?
  7. The known-problems list of "Bazel workspaces: what is supported". The entry for vendored mode lists commands that exit 0 and leave a failing build. Here it becomes NuGet alone: PyPI and RubyGems now decline, and Composer has declined since Decline Composer vendored mode in a Bazel workspace #2186. Another open pull request, Say that vendored Composer is declined in the Bazel known problems #2205, edits the same entry to give Composer one of its own for the cases where its refusal is lifted or does not apply. The two touch the same lines, so whichever lands second merges the list.
  8. Declining is the safe state, not the end state. Making vendored mode build under these hubs needs a write to a Bazel file, which is a decision of its own.
  9. Size. 281 code lines of implementation. The first cut of this change was 162. The rest closed, in two rounds, six ways a run could still exit 0 and write a file the hub reads, or refuse a project it did not need to; the three of the code review are listed under "Code review" below.
  10. A hub that names a parent requirements file. A call can name a file that brings the project's own in with -r (pip.parse(requirements_lock = "//:all.txt"), where all.txt has -r requirements.txt). A later commit on this branch (9a022a8) counts such a file as naming every file its -r includes reach, so the run is declined, and it is declined also when the project is already vendored and in step, because the parent file never names the vendored copy itself. The switch lifts it. The other choice is to let the already vendored case through after checking the included files for the copy.

What the code does today

rules_python's pip.parse and rules_ruby's ruby.bundle_fetch hand a lock of the checkout to Bazel, which builds the packages the lock names in repositories of its own. Vendored mode makes that lock name the patched copy by a path under .socket/vendor. Neither ruleset builds from such a lock.

scan --mode vendored --yes The next bazel build
PyPI, rules_python 2.5.0-rc4 exits 0, status success, 1 applied. The package's line of requirements.txt becomes ./.socket/vendor/pypi/<uuid>/<wheel> --hash=... fails while the hub is evaluated: invalid user-provided repo name 'pip_311__/_socket/vendor/pypi/<uuid>/<wheel>'
RubyGems, rules_ruby 1.0.0-rc2 exits 0, status success, 1 applied. Gemfile gets a path:, Gemfile.lock a PATH section fails in the hub's bundle install action: The path .../.socket/vendor/gem/<uuid>/<name>-<version> does not exist.

Both on Bazel 9.3.2, 8.8.2 and 7.7.2. vendor --revert puts the files and the build back. The first commit records this in two real-Bazel flows that pass on the code as it is; the second commit changes what they expect.

What changes

A package is declined when both of these hold:

  1. The project is in a Bazel workspace: its directory, or one above it up to the root of its git checkout, holds MODULE.bazel, REPO.bazel, WORKSPACE or WORKSPACE.bazel.
  2. A call of the workspace's files names, by a label written out as a string, a file of the project that the vendored run for that package would point at a copy:
Call Attributes Files of the project that count
pip.parse requirements_lock, requirements_by_platform, requirements_darwin, requirements_linux, requirements_windows, uv_lock requirements.txt and each file it includes with -r, where the run would write them; uv.lock in a uv project
ruby.bundle_fetch gemfile_lock, gemfile Gemfile, Gemfile.lock
any call of the WORKSPACE file that passes one of those attributes (pip_parse, rb_bundle_fetch) the same the same

Which files a PyPI run writes is asked of the vendored backend's own router, so the refusal follows what the run does:

  • A project with no tool lock is wired through its requirements files. They count.
  • A uv, Pipenv or PEP 751 lock is wired together with a pin of the same package in the requirements files beside it. Those files count for a package they name, and not for one they do not name.
  • A Poetry or PDM lock is wired alone. A hub that reads the requirements file exported from it stands in no run's way: the package is vendored as it is without Bazel, and that file stays as it is.

Every such call counts, also one that may not run (in a comprehension). The refusal is for every package whose run would write a file the call names, except a package that is already vendored (below).

An uncertain reading declines too. Where the files of the workspace cannot be read with certainty and a call of the hub may be behind that, every package whose run would write such a file is declined, in every project of the workspace:

  • a call of the hub whose file is not a plain string (a constant, a concatenation), or that passes * or **;
  • a hub proxy handed to anything but use_repo or inject_repo;
  • a module file that is missing or cannot be read, or a statement of one that cannot be read, where the workspace calls the hub or a file that was read names its ruleset (a bazel_dep on it, or a use_extension of the hub's .bzl file);
  • a root MODULE.bazel or a WORKSPACE file that cannot be read at all.

A file cannot be read here when one byte of it is not UTF-8 (a name in a comment is enough) or when it is over 1 MiB, and Bazel builds both. Going on there can leave a broken build behind a command that exited 0. Declining costs a vendored run, which the switch brings back. A workspace whose root MODULE.bazel and WORKSPACE file were read (or are not there), and in which no file that was read calls the hub or names its ruleset, is never declined for it.

A package that is already vendored passes. What is declined is the write of the path into the lock the hub reads. So a package is let through when the file that the call names already names the copy of the same patch (.socket/vendor/pypi/<uuid>/, .socket/vendor/gem/<uuid>/, outside a comment): the run adds nothing to what the hub reads. A project that was vendored with the switch, or by an earlier release, keeps passing its runs without the switch, a scan or get with no --mode included, which runs in vendored mode there. A new patch for that package, and any other package, is declined. This is the rule #2186 has for Composer, with three differences that come from the hub:

  • The file the call names decides, not any file of the project. A uv project whose uv.lock names the copy, while the hub reads a requirements file that still pins the registry's release, would have that file rewritten by the run. It is declined.
  • That file is read as the workspace's own files are: up to 64 MiB, and not through a link that leads out of the Bazel root. Such a link lets nothing through.
  • Where the reading is uncertain, no file is known to be the hub's, so nothing is let through.

Where nothing changes. Outside a Bazel workspace; in a workspace that calls neither hub; for a package whose run writes no file that a call names (a project beside the one a hub reads, one whose requirements.txt is not the file the hub is given, a Poetry or PDM project whose exported requirements file the hub reads); for other ecosystems and other modes. There the command prints what it printed and writes what it wrote.

What a user sees. scan --mode vendored, get --mode vendored and vendor (for a recorded patch, for the takeover of a hosted pin, and for the eject of one) report the package failed with the code and exit 1 (partialFailure; eject_refused with kept hosted: ... for the eject). scan and get with --dry-run list the package as one the run would refuse and exit 0; vendor --dry-run exits 1, as it does for any package it could not vendor. Nothing is downloaded, nothing is written, a hosted pin stays. No line a person reads is new. The message:

`pip.parse` (MODULE.bazel:15) of the Bazel workspace at /repo names requirements.txt; vendored mode makes the lock name the patched copy by a path under .socket/vendor, and rules_python fails the build on such a lock; use `--mode hosted`, which names the patched package by a URL that rules_python fetches, or pass `--allow-vendored-in-bazel` if no build takes the packages of this project from rules_python

For an uncertain reading it starts with the place and the reason instead:

the files of the Bazel workspace at /repo cannot be read with certainty, so a call of rules_python may name a lock of this project (MODULE.bazel: it cannot be read: it is not UTF-8); vendored mode makes ...

Hosted mode pins the patch in the same file and both rulesets build it; the two flows end with that build. For a gem the message names the condition of that: after "a URL that rules_ruby fetches" it says "where its call passes no gem_checksums". With a gem_checksums entry for the gem the hosted build fails, which the docs list as a known problem.

--allow-vendored-in-bazel (SOCKET_ALLOW_VENDORED_IN_BAZEL=1) lifts the refusal, and the run then does what it did before. vendor --revert is never refused.

Where the code is. The refusal goes through vendor::refusals::bazel_workspace_refusals, the one answer every vendored entry point already takes. No command's own code changes: commands/vendor.rs has no diff, and the eject still asks once, before it fetches a record.

Limits

  • Not seen, so vendored mode goes on as before and the build can break: a hub call in a .bzl file that a WORKSPACE file loads, a hub that another Bazel module declares, another tag or ruleset that reads the same file under Bzlmod (rules_ruby's older ruby.bundle, rules_pycross, aspect_rules_py), a WORKSPACE call that hides its arguments behind **, a Bazel root above the git checkout, and a hub whose call and whose bazel_dep are both in an included file that cannot be read while the files that were read name neither.
  • Declined although the build would pass: a WORKSPACE file that names the lock while the Bazel in use does not read that file (Bazel 9 never does, Bazel 8 only with --enable_workspace), a hub call that never runs, and a workspace that does not use the ruleset while its root MODULE.bazel or its WORKSPACE file cannot be read here, or while a file that was read names the ruleset and another cannot be read.
  • Declined although the run would write nothing to the file the call names: an already vendored package whose copy is named in another file than the one the call names (a requirements file that the named one includes with -r; the Gemfile when the lock does not name the copy), every already vendored package where the reading is uncertain, and a package of a uv, Pipenv or PEP 751 project that the hub's requirements file names in a form that is not wired with the lock (a range, extras). The switch, or its variable in the environment of those runs, lifts it.
  • A Poetry or PDM project is vendored beside a hub that reads its exported requirements file, and Bazel goes on building the registry's package from that file. vex does not say so yet; the docs list that among the limits of VEX.
  • A run that passes for an already vendored package does not make the build the patched one. A build that takes the project's packages from the hub is the broken one it was. For PyPI vex says affected of that state and names the way out: vendor --revert, then scan --mode hosted.
  • vex still attests a gem that was vendored with the switch as patched, while its build fails. The flow records that.
  • The refusal for a uv.lock rests on the rule, not on a build.

Contents and sizes

  • crates/socket-patch-core/src/bazel/built.rs: reader, which answers "does a call of this ecosystem's hub name one of these files, or is that in doubt" from the table and the reader of workspace files that vex already uses. uv_lock is one more attribute there; the vex judgement does not change. lock_text, which vex reads a lock with, is now also what reads the hub's lock. +161/-24 lines, 88 of them code.
  • crates/socket-patch-core/src/vendor/bazel_hub.rs (new): asks the reader about the files the run of each package would write, words the refusal, and lets an already vendored package through. 221 lines, 144 of them code.
  • vendor/pypi.rs (+45, 26 code) and vendor/pypi_requirements.rs (+30, 18 code): hub_files, which says through the backend's router which of those files a run for a package would write.
  • vendor/refusals.rs: bazel_workspace_refusals returns this refusal beside the Composer one. +15/-7 lines, 4 of them code.
  • The switch's help text (args.rs), its row in CLI_CONTRACT.md and the sentence in docs/ecosystems.md that named Composer as the one refusal it lifts now name the three.
  • Implementation in all: +483/-36 lines, 281 code lines by the count of scripts/loc-budget.py (223 before the code review). The bazel group's budget goes from 2486 to 2574, the count of this tree.
  • Tests: +533 lines of unit tests in src; +841/-158 lines in tests/e2e_bazel_build (harness.rs +134, pypi.rs +268/-79, ruby.rs +439/-79). No fixture file and no binary file is added.
  • Docs: +190/-19 lines. docs/ecosystems.md: the new section "Bazel workspaces: PyPI and RubyGems vendored mode", the two matrix rows, and the VEX section's sentences about a vendored gem. In "Bazel workspaces: what is supported" the two vendored cells stay "Not supported"; the note on that word now says that the command declines for PyPI, RubyGems and Composer; and the known-problems entry for vendored mode, which lists commands that exit 0 and leave a failing build, is now NuGet alone. CLI_CONTRACT.md: a row for the two codes, the switch's row, three rows of the vendored table.
  • Workflows: bazel-ruby.yml says that its legs run both modes; both workflows start their legs for a change to vendor/bazel_hub.rs and vendor/refusals.rs, bazel-pypi.yml for vendor/pypi.rs, and bazel-ruby.yml for vendor/gem.rs.

What it proves, and where

  • Real Bazel 9.3.2, 8.8.2 and 7.7.2 (run locally on macOS arm64; the Linux legs of bazel-pypi.yml and bazel-ruby.yml run on this pull request). pypi::vendored_pip_parse and ruby::vendored_bundle_fetch: the scan declines (exit 1, the code, the message, no file changed, no request for the patched wheel or gem); the same build passes on the upstream package; with the switch the package is vendored and the build fails with the ruleset's message; vendor --revert restores the build; scan --mode hosted then builds the patched package. pypi::hosted_pip_parse and ruby::hosted_bundle_fetch pass on the same three releases. Both failure messages are compared without white space, since Bundler breaks its message at the width of its console.
  • The flows fail without the change. Held against a binary of main's product code on 9.3.2, both vendored flows fail at the first new assertion (exit 0 where 1 is expected).
  • No harm. A binary of main's product code and a binary of this head ran 80 command sequences in projects where no hub reads the lock: no Bazel workspace (with and without .git), a project beside the one the hubs read, and the root of a workspace whose hubs name other files; PyPI and RubyGems; scan, rescan, dry run, get, vendor, eject, takeover, revert, as JSON and as a person reads them. Exit codes, both streams and every file are equal byte for byte (only timestamps are normalised). In the control, where the hubs read the project's files, all 20 sequences differ.
  • Already vendored. In a project that main's binary vendored beside a hub that reads its lock, 16 later sequences of the two binaries (rescan, a scan with no mode, get, vendor, dry run, vendor --check, revert; PyPI and RubyGems) are equal byte for byte. A Poetry project that main's binary vendored beside a hub that reads its exported requirements.txt passes its later runs with this head, with the exit codes and events of main's.
  • Hermetic tests in pypi.rs and ruby.rs: every command that would vendor declines and writes nothing, the dry runs and the eject among them; the switch and its variable; a later run without them passes and writes nothing; vendor --revert needs no switch; no refusal where the hub reads another file, beside the project it reads, with no workspace file, or for a Poetry project whose exported requirements the hub reads; a hub file that is not written out declines, and so does a MODULE.bazel with a byte that is not UTF-8.
  • Unit tests of the reader's answer (each attribute, a call that may not run, uv_lock, another project, another repository, each kind of doubt, a hub that is not called, the WORKSPACE file; a root module file, an included file and a WORKSPACE file that cannot be read), of the refusal (codes, words, the switch, the Gemfile alone; a package the named lock already names by the patch's copy, and the same copy named in a comment, in another file, behind a link out of the root, or under a doubt; Poetry, PDM, uv and Pipenv locks beside a requirements file that names the package or does not) and of its dispatch.
  • Mutations. Fifteen changes to what the last revision added (which files count per Python tool, the three ways an unread file counts, the bounded read of the hub's lock, the Gemfile alone, the gem's hosted condition) were tried one at a time; each fails a test.
  • Existing suites. 31 existing test targets that exercise vendored PyPI or RubyGems (1,425 tests) pass with no change. Four tests of pypi.rs vendored a wheel beside the hub that reads the requirements, to hold vex to what it says of that state; the command that writes the line now has the switch there, and they assert what they asserted.

Not covered

  • On real Bazel only the two fixtures on main ran (pip.parse with a hashed requirements.txt; ruby.bundle_fetch without gem_checksums), with one release of each ruleset. The WORKSPACE forms, uv_lock, a file brought in with -r, the uncertain reading, a file that cannot be read, a Poetry project and the already vendored pass are covered by unit and hermetic tests, not by a build.
  • No build was run on a vendored uv.lock, and no build after a vendored run under a module file with a byte that is not UTF-8 (Bazel 9.3.2 was only seen to accept such a file).
  • Nothing ran on Linux or Windows before this pull request.
  • The byte for byte comparisons cover requirements.txt and Gemfile projects. uv, Pipenv and PDM projects were not run with a binary; what counts for them rests on unit tests of the rule over the backend's router.
  • get with no --mode in an already vendored project is not tested on its own (the scan with no mode is).

Code review

Nine findings on the two commits. Each was checked against the code; three were also held to a failing unit test before the fix. The fixes are one further commit, "Close three ways a vendored run could still write a file a Bazel hub reads".

Fixed:

  • A Poetry or PDM project with a hosted pin in the file the hub reads was let through. The lock of such a project is wired alone, so its requirements files did not count. A vendored run that takes a hosted pin over restores the line that holds it. The files now count for a package they hold by a URL. A run of this repository's test fixture showed that the refusal did not fire in that state; the restore itself was read in the code, not run to the end.
  • A WORKSPACE call that names the lock as @<name>//..., where the file says workspace(name = "<name>"), was taken for another repository's file: no refusal and no doubt. It is the main repository now for the calls of that file.
  • The pass for an already vendored package read one file. Where the calls name more than one file of the project, a uv.lock locked again beside a vendored requirements file passed, and the run rewrote the lock. Each file a call names that holds the package now has to name the copy; one that cannot be read may hold it.
  • requirements.txt was listed twice in the files of a project with no tool lock.
  • The gem's two file names were typed again and the files of a package were chosen by the text of its purl type. They are the gem backend's constants and the package's ecosystem now.

Not fixed, and why:

  • A project with no tool lock is declined for a package that a hub-read file of its requirements set does not pin (the hub reads base.txt, the package is pinned in dev.txt). Narrowing this to the files that pin the package would miss a hub-read file that brings in the rewritten one with -r, and that is a failed build after exit 0. The decline is kept; the module docs, the docs table and the contract row now say that the files count as one set, and the case is in the limits.
  • pip_install(requirements = ...) of an older rules_python in a WORKSPACE file is not seen. No build was run on it, and the attribute name is one that other rules use for other things (a test holds that an http_archive with it is not taken for a hub). It is in the docs' list of what is not seen.
  • The files of a package are worked out for every PyPI candidate before the workspace is asked whether it calls the hub. It is the walk the vendored run itself does per package, so the cost is that walk a second time in a Bazel workspace, not a new order of cost. Left for a change of its own.
  • The list of files each lock flavor writes is kept beside the wiring code, not derived from the run's own plan. Deriving it needs a dry plan from the backend; the unit tests hold the list to each flavor today.

After the fixes, on macOS: cargo check on all targets, clippy with -D warnings on the workspace and on the e2e_bazel_build target, rustfmt --check on the changed files, the whole core unit suite (8378), e2e_bazel_build without Bazel (55), cli, cli_global_args and spawn_env_hygiene (152), the vendored PyPI and gem integration targets (716), the script tests, the line budget and actionlint: all pass. On real Bazel 9.3.2 the two PyPI flows and the two RubyGems flows pass. Three mutations, one per behaviour fix, each fail a unit test. Bazel 8.8.2 and 7.7.2 were not rerun after the fixes; the CI legs run them.

A later commit, 9a022a8, closes two more states a review bot found, each with a unit test that fails without the fix: a hub that names a requirements file which includes the project's own with -r (decision 10 above), and an already vendored package whose other file a call may name where the reading is in doubt. It takes the bazel line budget from 2574 to 2611.

🤖 Generated with Claude Code

Tests only. rules_python's `pip.parse` and rules_ruby's
`ruby.bundle_fetch` hand a lock of the checkout to Bazel. The real-Bazel
flows ran hosted mode beside both hubs, and vendored mode beside the
Python one (pypi::vendored_pip_parse, which holds `vex` to saying that
the build is not the patched one). No flow ran vendored mode for a gem,
and the PyPI flow did not build between its undo and its hosted scan.

ruby::vendored_bundle_fetch records what the command does today, in the
fixture of the hosted flow (rules_ruby 1.0.0-rc2; the call names the
`Gemfile` and the `Gemfile.lock` of the root). `scan --mode vendored
--yes` exits 0 with status `success` and one package applied. It commits
the unpacked gem with its specification and the ledger under
`.socket/vendor/gem/<uuid>`, gives the gem's declaration in `Gemfile` a
`path:`, and moves the gem's entry of `Gemfile.lock` into a `PATH`
section. The next `bazel build` fails in the `bundle install` action of
the hub. rules_ruby copies the two files into a repository of Bazel's
and runs Bundler there, which stops with

    The path
    `<execroot>/external/<hub>/.socket/vendor/gem/<uuid>/sp-victim-1.0.0`
    does not exist.

`vex` attests the gem as patched meanwhile: it reads the committed copy,
and what rules_ruby builds from one is not judged. `vendor --revert`
puts every file back, and the build with them.

pypi::vendored_pip_parse now names the failure it asserts. rules_python
makes the name of a repository from the path of the vendored line, and
Bazel stops with `invalid user-provided repo name
'pip_311__/_socket/vendor/pypi/<uuid>/spvictim_1_0_0_py2_py3_none_any_whl'`.
The flow also builds right after `vendor --revert`: the unpatched build
is back before hosted mode pins the patch.

Both flows pass on Bazel 9.3.2 with the product code as it is. Each
compares the tool's message without white space: Bundler breaks its
message at the width of the console it runs in, which differs from one
machine to the next.

The two Ruby flows share their stand-in. `Served::to` builds the gems of
a run, serves them, grants the patch and routes Bazel's downloads, as
the hosted flow did inline. The grant now holds what the patch service
grants for a gem: the patched gem with a sha512, and its specification.
Vendored mode downloads both, and hosted mode neither. The record of the
patch holds the hashes of the gem's one file, in place of the
placeholders of the shared stand-in.

bazel-ruby.yml says in its header that the legs run both modes, and a
pull request that changes vendor/gem.rs now starts them: the file was
in the list of the pushes to main alone.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
rules_python's `pip.parse` and rules_ruby's `ruby.bundle_fetch` build
the packages of a lock in repositories of Bazel's own. Vendored mode
makes that lock name the patched copy by a path under `.socket/vendor`,
and neither ruleset builds from such a lock. The command exited 0 with
status `success`, and the next `bazel build` failed for everything the
hub serves (Bazel 9.3.2, 8.8.2 and 7.7.2, the flows of the previous
commit):

- PyPI: rules_python 2.5.0-rc4 makes the name of a repository from the
  path of the vendored line, `invalid user-provided repo name
  'pip_311__/_socket/vendor/pypi/<uuid>/<wheel>'`.
- RubyGems: rules_ruby 1.0.0-rc2 runs `bundle install` in a repository
  that holds the Gemfile and its lock and not the copy, `The path
  .../.socket/vendor/gem/<uuid>/<name>-<version> does not exist.`

Vendored mode now declines such a package before it downloads or writes
anything, with `vendor_pypi_bazel_hub` or `vendor_gem_bazel_hub`. The
refusal rests on what the files of the workspace say and on what the
run would write, so it is for a run that would write a file a hub
reads, and for no other.

When it declines. The project is in a Bazel workspace
(`bazel::bazel_root`), and a call of its files names, by a label
written out as a string, a file of the project that the run for the
package would point at a copy:

- a `pip.parse` whose `requirements_lock`, `requirements_by_platform`,
  `requirements_darwin`, `requirements_linux`, `requirements_windows`
  or `uv_lock` names a requirements file of the project that the run
  would write (`requirements.txt` or a file it includes with `-r`), or
  the `uv.lock` of a uv project;
- a `ruby.bundle_fetch` whose `gemfile` or `gemfile_lock` names the
  project's `Gemfile` or `Gemfile.lock`;
- a call of a `WORKSPACE` file that passes one of those attributes,
  which is how the older form of either ruleset is called there
  (`pip_parse`, `rb_bundle_fetch`).

Which files a PyPI run writes is asked of the backend's own router
(`vendor::pypi::hub_files`). A project with no tool lock is wired
through its requirements files, so they count. A uv, Pipenv or PEP 751
lock is wired together with a pin of the package in the requirements
files beside it, so they count for a package they name (a pin, a
hosted pin that a takeover restores first, or the vendored line of an
earlier patch) and not for one they do not name. A Poetry or PDM lock
is wired alone: such a project is not declined beside a hub that reads
the requirements file exported from its lock, and is vendored as it is
without Bazel.

Every such call counts, also one that may not run (in a comprehension).
Every package whose run would write a file the call names is declined,
since the lock is the project's, but one that is already vendored
(below).

What an uncertain reading does. Where the files of the workspace
cannot be read with certainty and a call of the hub may be behind
that, every package whose run would write such a file is declined, in
every project of the workspace:

- a call of the hub whose file is not a plain string, or that passes
  `*` or `**`, and a hub proxy handed to anything but `use_repo` or
  `inject_repo`;
- a module file that is missing or cannot be read, or a statement of
  one that cannot be read, where the workspace calls the hub or a file
  that was read names its ruleset (a `bazel_dep` on it, or a
  `use_extension` of the hub's `.bzl` file under any repository name);
- a root `MODULE.bazel` or a `WORKSPACE` file that cannot be read at
  all.

The last two matter because Bazel builds files that are not read here:
one byte that is not UTF-8 is enough, in a comment too, and so is a
file over 1 MiB. Without them the call in such a file was not seen and
the run went on. Going on there can leave a broken build behind a
command that exited 0, and declining costs a vendored run that the
switch brings back. A workspace whose root `MODULE.bazel` and
`WORKSPACE` file were read or are not there, and in which no file that
was read calls the hub or names its ruleset, is never declined for it,
whatever else cannot be read.

Where nothing changes. Outside a Bazel workspace, in a workspace that
calls neither hub, and for a package whose run writes no file that a
call names (a project beside the one a hub reads, one whose
`requirements.txt` is not the file the hub is given, a Poetry or PDM
project whose exported requirements the hub reads), vendored mode
prints what it printed and writes what it wrote. Other ecosystems,
hosted mode and agent mode are not touched.

Where it is asked. `bazel::built` already says for `vex` which hub
reads which lock; `reader` there answers this question from the same
table and the same reader of workspace files, and takes `uv_lock` as
one more attribute. `vendor::bazel_hub::refusals` asks it about the
files the run of each package would write and words the refusal.
`vendor::refusals::bazel_workspace_refusals`, the one answer every
vendored entry point takes for a refusal that rests on the Bazel
workspace, returns it beside the Composer refusal. So it reaches
`scan --mode vendored`, `get --mode vendored`, `vendor` for a patch the
manifest records, the takeover of a hosted pin by a vendored scan, and
the eject of one by `vendor`, which asks once and before it fetches a
record. No command's own code changes.

The package is a `failed` event and the run exits 1 (`partialFailure`;
for the eject `eject_refused`, detail `kept hosted: ...`). A dry run of
`scan` or `get` lists the package as one the run would refuse and exits
0; `vendor --dry-run` reports the refusal and exits 1, as it does for
any package it could not vendor. Nothing is written, no patch is
downloaded, and a hosted pin stays. These are the exit codes of the
Composer refusal. The detail names the call with its file and line, the
lock, the Bazel root and hosted mode:

    `pip.parse` (MODULE.bazel:15) of the Bazel workspace at /repo names
    requirements.txt; vendored mode makes the lock name the patched
    copy by a path under .socket/vendor, and rules_python fails the
    build on such a lock; use `--mode hosted`, which names the patched
    package by a URL that rules_python fetches, or pass
    `--allow-vendored-in-bazel` if no build takes the packages of this
    project from rules_python

For a doubt it names the file, the line and the reason in the place of
the call. Hosted mode pins the patch in the same file, and both
rulesets build it: the two flows end with that build. For a gem the
detail adds the condition under which rules_ruby builds a hosted pin,
"where its call passes no `gem_checksums`": with an entry for the gem
there the hosted build fails, which the docs list as a known problem.

`--allow-vendored-in-bazel` (SOCKET_ALLOW_VENDORED_IN_BAZEL) lifts the
refusal, as it lifts the Composer one: for a hub that no build uses, a
`WORKSPACE` file that the Bazel in use does not read, or a
`ruby.bundle_fetch` that is given the files of the copy as `srcs`. Its
help text, its row in CLI_CONTRACT.md and the sentence of
docs/ecosystems.md that named Composer as the one refusal it lifts now
name the three.

`vendor --revert` is not refused. Neither is a package that is already
vendored, as for Composer. What is declined is the write of the path
into the lock the hub reads, so a package that the file the call names
already names by the copy of the same patch
(`.socket/vendor/pypi/<uuid>/`, `.socket/vendor/gem/<uuid>/`, outside a
comment) is let through: the run adds nothing to what the hub reads. A
project vendored with the switch, or by an earlier release, keeps
passing its in-sync runs without the switch, a `scan` or `get` that
names no mode included, which runs in vendored mode there. A new patch
for that package, and any other package, is declined as before. It is
the named file that decides, not any file of the project: a uv project
whose lock names the copy while the hub reads a requirements file that
still pins the registry's release would have that file rewritten by
the run, and is declined. That file is read as a lock of the workspace
is (`built::lock_text`): up to 64 MiB, and not through a link that
leads out of the Bazel root, so such a link lets nothing through.
Where the reading is in doubt no file is known to be the hub's, so
nothing is let through there. Such a run passing does not make the
build the patched one: for PyPI `vex` says `affected` of that state.

No line a person reads is new: the refusal prints where every refused
vendored package does.

Tests:

- pypi::vendored_pip_parse and ruby::vendored_bundle_fetch (real
  Bazel) now hold the command to the refusal: exit 1, the code, a
  detail that names the call, the lock, `--mode hosted` and the switch,
  no file changed and no request for the patched wheel or gem. The same
  build passes on the upstream package. With the switch the
  expectations of the previous commit are back: the package is
  vendored, the build fails with the ruleset's message, and
  `vendor --revert` restores the build. Hosted mode then builds the
  patched package.
- Hermetic tests of both files, on steps the harness now holds for
  both: every command that would vendor declines and writes nothing,
  the dry runs and the eject among them; vendored mode goes on with
  the switch and with its variable, a later run without them passes
  and writes nothing, a scan that names no mode included, and
  `vendor --revert` needs neither; it goes on with no switch in a
  workspace whose hub reads another file, in a project beside the one
  it reads, and in no workspace; a hub whose file is not written out
  declines. For PyPI also: a Poetry project beside a hub that reads its
  exported `requirements.txt` is vendored with no switch, that file
  stays as it is and the later runs pass; and a `MODULE.bazel` with one
  byte that is not UTF-8 declines.
- Unit tests of `built::reads` (each attribute, a call that may not
  run, `uv_lock`, another project, another repository, a doubt of the
  call, of the proxy and of the workspace, a hub that is not called,
  the `WORKSPACE` file; a root module file, an included file and a
  `WORKSPACE` file that cannot be read, with a root that names the
  ruleset as a dependency, by its extension, or not at all), of the
  refusal (codes, words, the switch, a file brought in with `-r`, the
  `Gemfile` alone, no workspace; a package the named lock already
  names by the patch's copy, and the same copy named in a comment, in
  another file, behind a link out of the root or under a doubt; a
  Poetry and a PDM lock, and a uv and a Pipenv lock beside a
  requirements file that names the package or does not) and of its
  dispatch.

Four tests of pypi.rs vendored a wheel beside the hub that reads the
requirements, to hold `vex` to what it says of that state. The command
that writes the line now has the switch there, and they assert what
they asserted; the in-sync runs after it have none, as before.

Docs: docs/ecosystems.md "Bazel workspaces: PyPI and RubyGems vendored
mode", the two rows of the matrix, and what "Bazel workspaces: VEX"
says of a vendored gem, which a build has now shown; the rows of the
two codes, of the switch and of the vendored table in CLI_CONTRACT.md.
In "Bazel workspaces: what is supported" the two vendored cells stay
"Not supported", and the note on that word now says that the command
declines there. The entry of the known problems for vendored mode
listed commands that exit 0 and leave a failing build: PyPI and
RubyGems leave it, and so does Composer, which declines since the
change before this one; NuGet stays. bazel-pypi.yml and bazel-ruby.yml
start their legs for a change to vendor/bazel_hub.rs and
vendor/refusals.rs, and bazel-pypi.yml for one to vendor/pypi.rs. The
`bazel` group of scripts/loc-budget.json follows the 69 lines added to
built.rs.

Not covered: a hub call in a `.bzl` file that a `WORKSPACE` file
loads, a hub of another Bazel module, another tag or ruleset that reads
the same file under Bzlmod, a `WORKSPACE` call that hides its arguments
behind `**`, a Bazel root above the git checkout, and a hub whose call
and whose `bazel_dep` are both in an included file that cannot be read
while the files that were read name neither: vendored mode goes on
there as before. A package of a uv, Pipenv or PEP 751 project that the
hub's requirements file names in a form that is not wired with the
lock (a range, extras) is declined although the run would leave that
file alone. `vex` still attests a gem that was vendored with the switch
as patched, while its build fails.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…reads

A review of the PyPI and RubyGems vendored declines found three states in
which the run was let through and would write a file that a hub of the
Bazel workspace reads:

- A Poetry or PDM project whose exported requirements file holds the package
  by a URL, which is what a hosted pin is. The lock of such a project is
  wired alone, so its requirements files did not count, but a vendored run
  that takes a hosted pin over restores that line. The files now count for a
  package they hold by a URL. A package they pin from the registry is
  vendored as before.
- A `WORKSPACE` call that names the lock through the name the file gives
  the main repository (`@shop//api:requirements.txt` beside
  `workspace(name = "shop")`). The label was taken for another
  repository's. It is the main repository now, for the calls of that file.
- A package that is already vendored, where the calls name more than one
  file of the project. Only the first file a call names was read, so a
  `uv.lock` locked again beside a vendored requirements file let the package
  pass, and the run rewrote the lock. Each file a call names that holds the
  package now has to name the copy; one that cannot be read may hold it.

Also from the review: the requirements file is no longer listed twice, the
gem's two files are the gem backend's own constants, and the files of a
package are chosen by its ecosystem and not by the text of its purl type.

The docs and the contract row say what was imprecise: the requirements
files of a project with no tool lock count as one set, also for a package a
file of the set does not pin, because a file the hub reads can bring in the
rewritten one with `-r`; and the `pip_install(requirements = ...)` of an
older rules_python is not seen.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@mikolalysenko
Mikola Lysenko (mikolalysenko) marked this pull request as ready for review November 23, 2026 22:10
@cursor

cursor Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes vendored-mode preflight for Bazel PyPI/Ruby projects and conservative parsing of MODULE.bazel/WORKSPACE; wrong hub detection could refuse valid vendoring or still miss edge hubs, but default is safer than silent build breaks.

Overview
Vendored mode now refuses PyPI and RubyGems packages when a Bazel workspace hub (rules_python pip.parse / pip_parse, or rules_ruby ruby.bundle_fetch / rb_bundle_fetch) reads a lock file the run would rewrite to .socket/vendor paths—codes vendor_pypi_bazel_hub and vendor_gem_bazel_hub. Previously those commands could exit 0 and leave a broken bazel build; they now fail upfront with a message pointing to hosted mode or --allow-vendored-in-bazel.

A new bazel::built::reader parses workspace/module/WORKSPACE calls to see which project locks a hub consumes (including uv_lock and legacy WORKSPACE forms). Uncertain parses (non-literal labels, unreadable UTF-8 files, missing includes, etc.) fail closed with a doubt-style refusal. vendor/bazel_hub.rs ties reader output to per-package files the PyPI/gem backends would write (hub_files, requirements sibling logic), skips packages whose hub lock already references the same vendored copy, and integrates through existing bazel_workspace_refusals.

--allow-vendored-in-bazel documentation and CLI help now cover all three refusal types (Composer + PyPI + RubyGems). Bazel compatibility workflows gain path triggers for the new vendor modules; e2e Bazel PyPI/Ruby flows assert default decline, opt-in vendoring with the flag, and hosted/revert recovery; CLI_CONTRACT and loc budget updated accordingly.

Reviewed by Cursor Bugbot for commit 2d652c5. Configure here.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 2d652c5. Configure here.

@mikolalysenko Mikola Lysenko (mikolalysenko) added the Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review label Nov 23, 2026
Two states in which a vendored PyPI run was still let through and would
write a file a Bazel hub reads:

- A hub that names a requirements file which brings the project's own
  in with `-r` (`all.txt` with `-r requirements.txt`). The files a run
  writes are walked down from `requirements.txt`, so the file the hub
  named was not among them and nothing was declined. A requirements file
  a call names now counts as naming each file its `-r` includes reach,
  read inside the Bazel root as any lock is, and the refusal names it.
- An already-vendored package whose other files a call may name where
  the reading is in doubt: a second attribute that is not written out,
  or a call that may be behind a file that could not be read. Only a
  certain answer had that file read; a doubt was dropped and the package
  let through. A doubt now has the file read as well, so the package is
  declined where that file holds it and not by the copy.

The `bazel` line budget goes from 2574 to 2611.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011f9aeQFeU3sKRPzawaNLsm
Assisted-by: Claude Code:claude-opus-5-5
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

[agent] PR shepherd: this PR needs a person for two things.

  1. Restore the description. At 2026-11-24T00:41Z my edit replaced this PR's description with another PR's text by mistake (two agents shared a scratch file). I put a placeholder in its place. GraphQL is blocked in this sandbox, so I can't read the edit history. Please put back the last version before 00:41Z from the "edited" menu on the description, then swap its agent-status block for the current one (state: ready, fixes at 9a022a8, CI pending).
  2. One product question from the Bugbot fixes in 9a022a8. A hub can name a parent requirements file that -r-includes the project's own, for example pip.parse(requirements_lock = "//:all.txt") where all.txt has -r requirements.txt. That case is now declined in vendored mode, even when the project is already vendored and in sync, because the parent file never names the vendored copy itself. --allow-vendored-in-bazel lifts it. Is failing closed here what you want, or should the already-vendored case be let through after checking the included files for the copy?

Both Bugbot threads are fixed, each with a unit test that fails without the fix, and resolved. I'll post the review brief once CI is green on 9a022a8 and this label is removed.


Generated by Claude Code

@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

The description is back: the version from before the mistaken edit, with a tenth decision for the parent-file case of 9a022a8, a line on that commit under "Code review", and the current status. The label stays until the maintainer has answered decision 10.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[agent] Found an unnecessary refusal on Bazel 9 workspaces.

let tag = format!("{}.{}", hub.extension.name, hub.tag);
let tagged = tags.calls.iter().map(|at| (at.file, at.call, tag.as_str()));
// In a `WORKSPACE` file, the calls that pass one of the hub's files.
let legacy = workspace

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[agent] Please exclude legacy WORKSPACE files when the checkout pins Bazel 9 or later. A retained WORKSPACE from a migration can still mention Gemfile.lock or requirements.txt, but Bazel 9 never loads it. Counting it here makes a previously working vendored run exit 1 in a workspace with no active hub consuming the lock. The Maven reader already gates its legacy check on the declared Bazel release, which would preserve the Bazel 7 protection here.

…hub-locks

Three files conflicted. The RubyGems tests of e2e_bazel_build keep one
`Served` (this branch's `Served::to`, with main's `neighbour_gem`), one
`run` and every test of both sides; main's tests beside a `gem_checksums`
use them, and its `checkout` is `checkout_with`, which this branch's
`checkout` is built on. docs/ecosystems.md keeps the entries of both
sides, and its paragraph on hosted mode beside a `gem_checksums` entry
now says what hosted mode does there since main. The `bazel` cap of
scripts/loc-budget.json is the count of the merged tree, 3740.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…hub-locks

No file conflicted. Main's change to hosted pnpm pins adds to bazel/pnpm.rs,
so the `bazel` cap of scripts/loc-budget.json is the count of the merged
tree again, 3858.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…gnore line

`cargo::vendored_from_cargo_with_config` comments out the line the scan
wrote in `.bazelignore` and expects `bazel cquery //...` and
`bazel query 'deps(//...)'` to fail on a repository that the main
repository does not see. It looked for the hub's repository
(`@crates__...`) alone. The build file that cargo-bazel writes into the
committed copy names `@platforms` as well, and Bazel reports the first one
it meets: on a Linux runner with Bazel 9.3.2 the query named `@platforms`
and the flow failed on its own check.

The flow now takes either name for that failure. Test only: nothing the
command does changes.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The check of the commands that fail once the ignore line is commented out
now reads the name out of Bazel's message and takes it only when the
message is about the main repository's view: `platforms`, or a repository
of the crate hub. The same words about another repository's view, or
about another name, are a different failure and no longer pass for the
expected one. A test without Bazel holds the check to the two messages
that were seen and to three it must not take.

The module docs, the comment at the call and the section on the build
file in a vendored crate said the commands end on the dependency's
repository alone. They now name `platforms` as well, which is what a
user who comments the line out can see.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…hub-locks

Two files conflicted. vendor/refusals.rs keeps every refusal of both
sides in the one dispatch of `bazel_workspace_refusals`, which is still
asked once and before any fetch: Composer's, then this branch's for a
PyPI or RubyGems project whose lock a hub reads, then main's for a Maven
jar that only a rules_jvm_external hub builds. Its docs say which of them
the user's word lifts. The `bazel` cap of scripts/loc-budget.json is the
count of the merged tree, 4042.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

Decided by the maintainer on 2026-11-25 (decision 10 of the description): keep the refusal where a hub names a parent requirements file that brings the project's own in with -r. Vendored mode declines there, also for a project that is already vendored and in step, and --allow-vendored-in-bazel lifts it. Nothing in the code changes for this; the pull request now waits only for a review.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[agent] Re-reviewed the commits since the last approval; no major findings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants