Repository navigation
[ci] Point bazel's downloader at the CI mirror - #65599
Conversation
rules_python declares its bootstrap wheels as http_archive with literal files.pythonhosted.org URLs, and http_archive never consults PIP_INDEX_URL, so no index setting we have reaches them. That is bazel's own Java downloader, and it is what failed microcheck 52470 and the docs-example jobs on postmerge 19272: WARNING: Download from https://files.pythonhosted.org/.../click-8.0.1-py3-none-any.whl failed ERROR: Error computing the main repository mapping: ... no such package '@@py_deps_py310//' It fails during repository mapping, so one 502 takes the whole analysis phase rather than a single target. When the mirror is reachable the profile script now writes a downloader config that rewrites those URLs onto the mirror, and points ~/.bazelrc at it. No proxy process, no content negotiation, no per-job address -- which is why it is set up before the proxy checks: an image carrying no proxy still gets its bazel downloads mirrored. Written per job rather than committed to .bazelrc because the hostname is VPC-internal: a checkout outside CI would rewrite its downloads to a name that does not resolve, turning a working build into a broken one. Skipped entirely for a non-https mirror, since bazel preserves the original scheme and would otherwise address an http-only host as https. Verified on bazel 7.5.0 against a throwaway workspace fetching the same click-8.0.1 wheel that failed in CI: the rewrite applies with the scheme preserved, the generated config is accepted with its escaping intact, an identity rewrite still downloads successfully, and 'common' is a safe scope for the flag. AI assistance (Claude Code) was used for this change. Signed-off-by: elliot-barn <[email protected]>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 6b3e74b. Configure here.
There was a problem hiding this comment.
Code Review
This pull request introduces a mechanism to configure Bazel's downloader to rewrite files.pythonhosted.org URLs to use a PyPI mirror, addressing issues where Bazel's Java downloader fails during repository mapping. The feedback suggests storing the generated configuration file in the user's home directory instead of /tmp to mitigate security risks, and ensuring a newline is appended before writing to .bazelrc to prevent potential file corruption.
| # VPC-internal: a checkout outside CI would rewrite its downloads to a name that does | ||
| # not resolve, turning a working build into a broken one. | ||
| _rayci_bazel_downloader_config() { | ||
| local cfg="${TMPDIR:-/tmp}/rayci_bazel_downloader.cfg" |
There was a problem hiding this comment.
Using a predictable filename in a shared world-writable directory like /tmp (or $TMPDIR) can lead to security vulnerabilities such as symlink attacks (CWE-377) or permission conflicts if multiple users or jobs run on the same host.
Since you are already using $HOME for the .bazelrc path (which is user-specific and secure), it is highly recommended to store the Bazel downloader configuration file in the user's home directory as well (e.g., ~/.rayci_bazel_downloader.cfg). This avoids any shared directory risks while keeping the path static and predictable per-user.
| local cfg="${TMPDIR:-/tmp}/rayci_bazel_downloader.cfg" | |
| local cfg="${HOME}/.rayci_bazel_downloader.cfg" |
| if ! grep -qsF -- "--experimental_downloader_config=${cfg}" "${rc}"; then | ||
| echo "common --experimental_downloader_config=${cfg}" >>"${rc}" || return 0 | ||
| fi |
There was a problem hiding this comment.
If the existing .bazelrc file does not end with a trailing newline, appending directly to it can append common --experimental_downloader_config=... to the end of the last line, corrupting both the existing option and the new one.
To prevent this, ensure a newline is appended before writing the new configuration line. Since this block is already guarded by grep and only runs once, adding an empty line is safe and robust.
| if ! grep -qsF -- "--experimental_downloader_config=${cfg}" "${rc}"; then | |
| echo "common --experimental_downloader_config=${cfg}" >>"${rc}" || return 0 | |
| fi | |
| if ! grep -qsF -- "--experimental_downloader_config=${cfg}" "${rc}"; then | |
| echo >>"${rc}" | |
| echo "common --experimental_downloader_config=${cfg}" >>"${rc}" || return 0 | |
| fi |
Review feedback on #65599, plus a bug found by reading anyscale/rayturbo#4205. The important one: a matching rewrite *replaces* the URL set rather than adding to it, so the single rule discarded the origin and turned a mirror outage into a hard build failure -- strictly worse than the 502s this is meant to soften. Adding an identity rewrite keeps the original URL alongside the mirrored one. Verified against bazel 7.5.0 with an unreachable mirror: one rule fails the build, two rules warn and fetch from the origin. rayturbo#4205 notes the same rule would also discard the fallbacks auto_http_archive builds for the C++ dependencies, which matters if the pattern is ever broadened past pythonhosted. Cursor Bugbot pointed out the rewrite was only reachable on one path, because the mirror-simple branch returned before it. That branch cannot succeed at all: the mirror parses only /<host>/<path>, so <mirror>/simple/ reads as a host named "simple", and it serves cache hits as 303s to presigned S3 URLs so it never holds a body to rewrite. Deleting it fixes the reported bug by construction, drops a wasted request per job, and leaves one reachability probe that everything below keys off. Also from review: the generated config moves from a shared /tmp to $HOME, avoiding the predictable-path problem in a world-writable directory (CWE-377), and the bazelrc append gains a leading newline so a file that does not end in one is not spliced. Signed-off-by: elliot-barn <[email protected]>
install_pypi_proxy.sh and pypi_index_proxy.py were pulled onto this branch while testing the agent hook, and git checkout <branch> -- <file> stages what it writes, so a later commit swept them in. They belong to #65597 and #65593. This branch changes the profile script only. Signed-off-by: elliot-barn <[email protected]>
…ownloader-mirror # Conflicts: # ci/pypi_proxy_profile.sh
| # Which index to use is decided by probing, not by assuming, because the mirror | ||
| # serves two different shapes and only one of them is usable directly: |
There was a problem hiding this comment.
Is this part still true?
| if ! grep -qsF -- "--experimental_downloader_config=${cfg}" "${rc}"; then | ||
| # Leading newline: the image writes this file, and appending to one that does not | ||
| # end in a newline would splice this onto the last option rather than adding it. | ||
| printf '\n%s\n' "common --experimental_downloader_config=${cfg}" >>"${rc}" || return 0 |
There was a problem hiding this comment.
This appends to ${HOME}/.bazelrc, but on buildkite CI builds, this is also run on ci/env/install-bazel.sh:
Lines 98 to 100 in f2c28c1
invoked through
ray/ci/env/install-dependencies.sh
Line 42 in f2c28c1
invoked through
Lines 308 to 312 in f2c28c1
We do seem to run ci/ci.sh init in a few places. Can we ensure that .bazelrc doesn't get overwritten?
Windows is the last platform still resolving from files.pythonhosted.org (pypi/support#11895), and it needs its own entry point: the two places that install packages there are not login shells, so the profile.d hook the Linux images use never runs. `RUN bash build_ray.sh` inside the docker build the tester starts, and the command list the wheel builder passes to `docker run`, both source ci/ray_ci/windows/pypi_proxy.sh explicitly. The proxy runs inside the container on loopback rather than on the agent. The Windows host carries Python 3.8, below what the proxy supports, while conda in the image supplies 3.10 -- enough, since the only dependency needing 3.11 is skipped by the installer and guarded at import. Loopback also means pip and uv accept it over plain HTTP with no trusted-host handling, and the venv is baked into the windowsbuild image by build_base.sh, so nothing is installed at job time. Two shared pieces gain Windows support rather than being copied: install_pypi_proxy.sh picks Scripts/ over bin/ for the venv, and pypi_proxy_profile.sh takes the interpreter from RAYCI_PYPI_PROXY_PYTHON when a caller names it, which ci/pypi_proxy_agent.sh already does for the same reason. Every failure path leaves the environment untouched, so a job resolves from public PyPI exactly as it does today. Rebased onto master: the earlier revision of this branch predated the agent hook (#65602), the bazel downloader rewrite (#65599) and the index-shape correction (#65603), and would have reverted all three. Tested: bash -n over the five touched shell scripts. The Windows paths themselves need a windowsbuild image build to exercise, which is what this PR's premerge does. AI assistance was used for this change. Signed-off-by: Elliot Barnwell <[email protected]> Signed-off-by: elliot-barn <[email protected]>
## What Follows up #65599, which pointed bazel's downloader at the CI mirror inside the images. Three gaps in that same mechanism, so one change: 1. **The agent had no rewrite at all.** `ci/pypi_proxy_agent.sh` now sets it up for the steps that never enter a container — the release pipeline's `init` step and every wanda image build. 2. **`ci/env/install-bazel.sh` clears `~/.bazelrc`** and runs *after* the hooks that write into it, so the rewrite is restored after the clear. 3. **The rewrite rules move into one file**, `ci/bazel_mirror_downloader.sh`, instead of being copied per caller. It also corrects the header comment of `ci/pypi_proxy_profile.sh`, which still described a usable "rewriting simple index at `/simple`" that the code below it had already ruled out. Addresses both review comments from @sai-miduthuri on #65599. ## Why **The agent gap is measurable.** I audited all 41 finished jobs of release build 104848 and counted mirror versus origin fetches: 58 fetches through `mirror.ci.ray.io`, 0 untrusted-host warnings, and exactly one direct `https://files.pythonhosted.org` fetch — in `init`: ``` Fetching https://files.pythonhosted.org/.../tomli-2.0.1-py3-none-any.whl; Checking in SHA-256 cache ``` That is a bazel repository fetch, not pip. The rewrite is written by `ci/pypi_proxy_profile.sh`, which only runs inside the images; `init` runs on the bare agent. That one was served from the SHA-256 cache, but a cache miss goes to the origin — and `init` failing means zero release tests run. **The clobber is real and ordered against us.** `install-bazel.sh` does `echo > ~/.bazelrc` when `CI=true` and `BUILDKITE` is set, and `ci/ci.sh init` reaches it through `install-dependencies.sh`. On macOS it is the line immediately after the proxy is sourced: ```bash source ./ci/ray_ci/macos/pypi_proxy.sh || true # writes the rewrite into ~/.bazelrc . ./ci/ci.sh init && source ~/.zshenv # truncates ~/.bazelrc ``` Restore is deliberately not a second `config`: it re-adds the option only when the config file already exists, and that file's existence is the record that a hook probed the mirror and got an answer. A job whose mirror is unreachable therefore stays on the origin rather than acquiring a rewrite from here. Image builds are unaffected either way — they never set `CI=true`, so that block does not run at image build time. ## Testing Sourced the helper directly and checked each behaviour: | case | expected | result | |---|---|---| | `config` on a reachable mirror | writes cfg + one rc line | ✅ | | second `config` call | adds nothing | ✅ | | rc cleared, then `restore` | line back, cache settings intact | ✅ | | `restore` with no cfg | no-op | ✅ | | non-https mirror | nothing written, message on stderr | ✅ | | `BUILDKITE` unset | nothing touched | ✅ | `bash -n` clean on all four scripts; pre-commit (including shellcheck) clean. AI assistance was used for this change. Not a duplicate: #65599 is merged, and this is the follow-up its own review asked for. --------- Signed-off-by: Elliot Barnwell <[email protected]> Signed-off-by: elliot-barn <[email protected]>
## Description Bazel's downloader is a separate surface from pip's index, and nothing was pointing it at the mirror. `rules_python` declares its bootstrap wheels as `http_archive` with literal `files.pythonhosted.org` URLs, and `http_archive` never consults `PIP_INDEX_URL` — so no index setting we have reaches them. That is what failed microcheck 52470 and the docs-example jobs on postmerge 19272 — bazel's own Java downloader, not pip: ``` WARNING: Download from https://files.pythonhosted.org/packages/…/click-8.0.1-py3-none-any.whl failed Error in download_and_extract: java.io.IOException: Error downloading […click-8.0.1…] ERROR: Error computing the main repository mapping: … no such package '@@py_deps_py310//' ``` It fails during repository mapping, so a single 502 takes the whole analysis phase with it rather than one target. ## What changed When the mirror is reachable, the profile script now writes a bazel downloader config and points `~/.bazelrc` at it: ``` rewrite files\.pythonhosted\.org/(.*) mirror.ci.ray.io/files.pythonhosted.org/$1 ``` ``` common --experimental_downloader_config=/tmp/rayci_bazel_downloader.cfg ``` Bazel rewrites the URL before fetching, so those archives come from the mirror. This is a different mechanism from the index proxy: no proxy process, no content negotiation, no per-job address — which is also why it is set up **before** the proxy checks. An image that carries no proxy still gets its bazel downloads mirrored. Written per job rather than committed to `.bazelrc` because the hostname is VPC-internal: a checkout outside CI would rewrite its downloads to a name that does not resolve, turning a working build into a broken one. ## Why this is worth having beyond the observed failure Bazel's downloader also fetches the github.com release tarballs, and the mirror is host-prefixed so it already serves those. Extending the same config to github is a one-line follow-up, and would have covered the `rules_python` tarball 429s from the GitHub incident on 2026-08-17. Left out here to keep the change to the surface actually measured. ## Related issues Upstream cause: pypi/support#11895. Not a duplicate: no open PR touches bazel's downloader configuration — `grep -rn experimental_downloader_config` comes back empty on master. ray-project#65593, ray-project#65597 and ray-project#65598 all concern the pip/uv index path and do not overlap with this mechanism. ## Testing Verified against bazel 7.5.0 locally, with a throwaway workspace whose `http_archive` points at the same `click-8.0.1` wheel that failed in CI: - **The rewrite applies and the scheme is preserved.** With the target host set to a deliberately nonexistent name, bazel reports `Download from https://mirror.invalid/files.pythonhosted.org/packages/…` — confirming both the URL shape and that `https` carries over. - **The generated config is accepted by bazel**, escaping intact: the config this script writes produced `Download from https://127.0.0.1:38120/files.pythonhosted.org/packages/…`, i.e. parsed and applied rather than rejected. - **An identity rewrite does not break a working download**: `All external dependencies for the requested targets fetched successfully`. - **`common` is a safe scope** for the flag — `bazel version` and `bazel query` both run clean with it in `~/.bazelrc`, no unrecognized-option error. - **Guards**: an `http://` mirror prints `mirror is not https, leaving bazel downloads on the origin` and writes no config, because bazel would otherwise address an http-only host as https and fail in a way that looks like a broken mirror. An unreachable mirror bails at the existing probe before any bazel setup. The bazelrc line is appended only once. - `pre-commit` (shellcheck) clean. Not verified: a real CI job against the real mirror, which is what the first build on this branch shows. The failure mode if the mirror cannot serve an artifact is a bazel download error naming `mirror.ci.ray.io`, which is distinguishable at a glance from the origin failing. AI assistance (Claude Code) was used for this change. --------- Signed-off-by: elliot-barn <[email protected]>
…project#65605) ## What Follows up ray-project#65599, which pointed bazel's downloader at the CI mirror inside the images. Three gaps in that same mechanism, so one change: 1. **The agent had no rewrite at all.** `ci/pypi_proxy_agent.sh` now sets it up for the steps that never enter a container — the release pipeline's `init` step and every wanda image build. 2. **`ci/env/install-bazel.sh` clears `~/.bazelrc`** and runs *after* the hooks that write into it, so the rewrite is restored after the clear. 3. **The rewrite rules move into one file**, `ci/bazel_mirror_downloader.sh`, instead of being copied per caller. It also corrects the header comment of `ci/pypi_proxy_profile.sh`, which still described a usable "rewriting simple index at `/simple`" that the code below it had already ruled out. Addresses both review comments from @sai-miduthuri on ray-project#65599. ## Why **The agent gap is measurable.** I audited all 41 finished jobs of release build 104848 and counted mirror versus origin fetches: 58 fetches through `mirror.ci.ray.io`, 0 untrusted-host warnings, and exactly one direct `https://files.pythonhosted.org` fetch — in `init`: ``` Fetching https://files.pythonhosted.org/.../tomli-2.0.1-py3-none-any.whl; Checking in SHA-256 cache ``` That is a bazel repository fetch, not pip. The rewrite is written by `ci/pypi_proxy_profile.sh`, which only runs inside the images; `init` runs on the bare agent. That one was served from the SHA-256 cache, but a cache miss goes to the origin — and `init` failing means zero release tests run. **The clobber is real and ordered against us.** `install-bazel.sh` does `echo > ~/.bazelrc` when `CI=true` and `BUILDKITE` is set, and `ci/ci.sh init` reaches it through `install-dependencies.sh`. On macOS it is the line immediately after the proxy is sourced: ```bash source ./ci/ray_ci/macos/pypi_proxy.sh || true # writes the rewrite into ~/.bazelrc . ./ci/ci.sh init && source ~/.zshenv # truncates ~/.bazelrc ``` Restore is deliberately not a second `config`: it re-adds the option only when the config file already exists, and that file's existence is the record that a hook probed the mirror and got an answer. A job whose mirror is unreachable therefore stays on the origin rather than acquiring a rewrite from here. Image builds are unaffected either way — they never set `CI=true`, so that block does not run at image build time. ## Testing Sourced the helper directly and checked each behaviour: | case | expected | result | |---|---|---| | `config` on a reachable mirror | writes cfg + one rc line | ✅ | | second `config` call | adds nothing | ✅ | | rc cleared, then `restore` | line back, cache settings intact | ✅ | | `restore` with no cfg | no-op | ✅ | | non-https mirror | nothing written, message on stderr | ✅ | | `BUILDKITE` unset | nothing touched | ✅ | `bash -n` clean on all four scripts; pre-commit (including shellcheck) clean. AI assistance was used for this change. Not a duplicate: ray-project#65599 is merged, and this is the follow-up its own review asked for. --------- Signed-off-by: Elliot Barnwell <[email protected]> Signed-off-by: elliot-barn <[email protected]>

Description
Bazel's downloader is a separate surface from pip's index, and nothing was pointing it at
the mirror.
rules_pythondeclares its bootstrap wheels ashttp_archivewith literalfiles.pythonhosted.orgURLs, andhttp_archivenever consultsPIP_INDEX_URL— so noindex setting we have reaches them.
That is what failed microcheck 52470 and the docs-example jobs on postmerge 19272 —
bazel's own Java downloader, not pip:
It fails during repository mapping, so a single 502 takes the whole analysis phase with
it rather than one target.
What changed
When the mirror is reachable, the profile script now writes a bazel downloader config and
points
~/.bazelrcat it:Bazel rewrites the URL before fetching, so those archives come from the mirror. This is a
different mechanism from the index proxy: no proxy process, no content negotiation, no
per-job address — which is also why it is set up before the proxy checks. An image
that carries no proxy still gets its bazel downloads mirrored.
Written per job rather than committed to
.bazelrcbecause the hostname is VPC-internal:a checkout outside CI would rewrite its downloads to a name that does not resolve,
turning a working build into a broken one.
Why this is worth having beyond the observed failure
Bazel's downloader also fetches the github.com release tarballs, and the mirror is
host-prefixed so it already serves those. Extending the same config to github is a
one-line follow-up, and would have covered the
rules_pythontarball 429s from theGitHub incident on 2026-08-17. Left out here to keep the change to the surface actually
measured.
Related issues
Upstream cause: pypi/support#11895. Not a duplicate: no open PR touches bazel's downloader
configuration —
grep -rn experimental_downloader_configcomes back empty on master.#65593, #65597 and #65598 all concern the pip/uv index path and do not overlap with this
mechanism.
Testing
Verified against bazel 7.5.0 locally, with a throwaway workspace whose
http_archivepoints at the same
click-8.0.1wheel that failed in CI:deliberately nonexistent name, bazel reports
Download from https://mirror.invalid/files.pythonhosted.org/packages/…— confirmingboth the URL shape and that
httpscarries over.writes produced
Download from https://127.0.0.1:38120/files.pythonhosted.org/packages/…, i.e. parsedand applied rather than rejected.
All external dependencies for the requested targets fetched successfully.commonis a safe scope for the flag —bazel versionandbazel queryboth runclean with it in
~/.bazelrc, no unrecognized-option error.http://mirror printsmirror is not https, leaving bazel downloads on the originand writes no config,because bazel would otherwise address an http-only host as https and fail in a way that
looks like a broken mirror. An unreachable mirror bails at the existing probe before any
bazel setup. The bazelrc line is appended only once.
pre-commit(shellcheck) clean.Not verified: a real CI job against the real mirror, which is what the first build on this
branch shows. The failure mode if the mirror cannot serve an artifact is a bazel download
error naming
mirror.ci.ray.io, which is distinguishable at a glance from the originfailing.
AI assistance (Claude Code) was used for this change.