Repository navigation
[ci] Resolve macOS packages through the CI mirror - #65597
elliot-barn wants to merge 4 commits into
Conversation
`reef: raydepsets tests` went red on master in postmerge 19272, and the mirror caused it rather than failing to prevent it: WARNING: Skipping page http://172.16.0.2:35999/simple/exceptiongroup/ because the GET request got Content-Type: application/vnd.pypi.simple.v1+json. The only supported Content-Type is text/html ERROR: Could not find a version that satisfies the requirement exceptiongroup==1.3.1 (from versions: none) The mirror caches `/simple/` keyed on the URL alone, with no Vary, so whichever representation is fetched first is what every later client receives. The proxy forwarded the client's Accept, so uv asking for PEP 691 JSON stored JSON, and then whl_library's pip -- which reads only text/html -- skipped the page entirely. The "from versions: none" that follows looks like a bad pin, which is what makes this worth a comment in the code: exceptiongroup 1.3.1 is the current release and is present in PyPI's HTML index. Pins Accept to text/html. HTML rather than the JSON that product's copy of this proxy pins, because that pip cannot read JSON at all while uv reads both. Pinning stops new entries going in but cannot evict the ones already cached, since Accept is not part of the mirror's cache key. Clearing those means deleting the cache/pypi.org/simple/ prefix from the bucket, at a cost of one re-fetch per page. So the proxy now logs loudly when it asks for HTML and gets something else, because the client-side symptom otherwise points at the wrong thing entirely. Testing: started the proxy against a stub upstream that records the Accept it receives and replies with JSON. A client requesting application/vnd.pypi.simple.v1+json results in the upstream seeing text/html, and the stale-entry warning fires. Both asserted. AI assistance (Claude Code) was used for this change. Signed-off-by: elliot-barn <[email protected]>
macOS jobs fetch every package straight from files.pythonhosted.org, so they are fully exposed to the intermittent 502s (pypi/support#11895). macos_wheels_arm64 carries the release_wheels tag and publishes to the wheels destination on master, so a failure there leaves the published wheel set short a platform. The mirror was already reachable: these builders take vpc_id from module.prod_environment, the same VPC as that stack's mirror-cache and its private zone. What was missing was a way to use it, since the Linux images get the proxy via /etc/profile.d and a macOS step is not a login shell into an image. Adds ci/ray_ci/macos/pypi_proxy.sh, sourced from macos_ci.sh and macos_ci_build.sh before their first installs, which installs the proxy if needed and then hands off to ci/pypi_proxy_profile.sh for the probe, mode selection and fail-open paths rather than reimplementing them. Three changes make the shared pieces work off-image: an install prefix and a skip-profile switch, so a host installs without sudo; an address override, because hostname -i is Linux-only and returns nothing on macOS, plus nohup where setsid is absent; and a guarded asgi_cross_origin_protection import, the only dependency needing 3.11 when these agents have none -- its middleware only rejects cross-site state-changing requests and every route here is a GET. The venv is now created with --clear. Without it an attempt that failed partway leaves stale bin/ symlinks that a later attempt inherits, giving a venv whose python cannot start; found by testing that exact sequence. Cheap here because the agents are long-lived with a persistent HOME, so the venv is built once per machine rather than once per job, and loopback suffices with no containers to reach it. AI assistance (Claude Code) was used for this change. Signed-off-by: elliot-barn <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request extends the job-local PyPI index proxy to support macOS agents running directly on the host. It relaxes the Python version requirement to 3.10+, makes the cross-origin protection middleware optional, and updates the proxy to always request HTML from upstream to prevent cache poisoning on the mirror. Additionally, it introduces a macOS-specific setup script and integrates it into the macOS CI workflows. The review feedback highlights three key improvements: converting the content-type header to lowercase to handle case-insensitive MIME types, respecting the existing RAYCI_PYPI_PROXY_PREFIX environment variable in the macOS script, and refactoring the Python candidate search to prevent premature exits under set -e when certain Python versions are missing.
| status_code=response.status_code, | ||
| media_type=response.headers.get("content-type", "text/html"), | ||
| ) | ||
| content_type = response.headers.get("content-type", "text/html") |
There was a problem hiding this comment.
MIME types are case-insensitive per RFC 2045. To prevent false-positive warnings if a server returns mixed-case or uppercase headers (e.g., TEXT/HTML), convert the content-type header value to lowercase before performing the substring check. Also, handle potential None values safely.
| content_type = response.headers.get("content-type", "text/html") | |
| content_type = (response.headers.get("content-type") or "text/html").lower() |
| # necessarily fetches from PyPI itself and can hit the very 502s this works around. | ||
|
|
||
| _rayci_macos_pypi_proxy() { | ||
| local prefix="${HOME}/.pypiproxy" |
There was a problem hiding this comment.
To allow users or other scripts to override the proxy installation directory, respect the existing RAYCI_PYPI_PROXY_PREFIX environment variable if it is set, rather than unconditionally overwriting it with ${HOME}/.pypiproxy.
| local prefix="${HOME}/.pypiproxy" | |
| local prefix="${RAYCI_PYPI_PROXY_PREFIX:-${HOME}/.pypiproxy}" |
| local candidate found="" | ||
| for candidate in \ | ||
| /Library/Frameworks/Python.framework/Versions/3.12/bin/python3.12 \ | ||
| /Library/Frameworks/Python.framework/Versions/3.11/bin/python3.11 \ | ||
| /Library/Frameworks/Python.framework/Versions/3.10/bin/python3.10 \ | ||
| /opt/homebrew/opt/miniforge/bin/python3 \ | ||
| "$(command -v python3.12 2>/dev/null)" \ | ||
| "$(command -v python3.11 2>/dev/null)" \ | ||
| "$(command -v python3.10 2>/dev/null)"; do | ||
| if [[ -n "${candidate}" && -x "${candidate}" ]]; then | ||
| found="${candidate}" | ||
| break | ||
| fi | ||
| done |
There was a problem hiding this comment.
Running command -v inside the word list of a for loop can trigger premature exits under set -e if any of the searched Python versions are missing (which is highly likely on these agents). A safer and cleaner approach is to build the list of candidates using an array and safely check for command existence using if command -v (which is immune to set -e exits).
| local candidate found="" | |
| for candidate in \ | |
| /Library/Frameworks/Python.framework/Versions/3.12/bin/python3.12 \ | |
| /Library/Frameworks/Python.framework/Versions/3.11/bin/python3.11 \ | |
| /Library/Frameworks/Python.framework/Versions/3.10/bin/python3.10 \ | |
| /opt/homebrew/opt/miniforge/bin/python3 \ | |
| "$(command -v python3.12 2>/dev/null)" \ | |
| "$(command -v python3.11 2>/dev/null)" \ | |
| "$(command -v python3.10 2>/dev/null)"; do | |
| if [[ -n "${candidate}" && -x "${candidate}" ]]; then | |
| found="${candidate}" | |
| break | |
| fi | |
| done | |
| local candidate found="" | |
| local -a candidates=( | |
| /Library/Frameworks/Python.framework/Versions/3.12/bin/python3.12 | |
| /Library/Frameworks/Python.framework/Versions/3.11/bin/python3.11 | |
| /Library/Frameworks/Python.framework/Versions/3.10/bin/python3.10 | |
| /opt/homebrew/opt/miniforge/bin/python3 | |
| ) | |
| local p | |
| for p in python3.12 python3.11 python3.10; do | |
| if command -v "$p" >/dev/null 2>&1; then | |
| candidates+=("$(command -v "$p")") | |
| fi | |
| done | |
| for candidate in "${candidates[@]}"; do | |
| if [[ -n "${candidate}" && -x "${candidate}" ]]; then | |
| found="${candidate}" | |
| break | |
| fi | |
| done |
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]>
**Stacked on #65597** — base branch is `elliot-barn/proxy-host-support`, which carries the off-image install support this depends on (an install prefix, a skip-profile switch, and the guarded import that lets the proxy run on 3.10). Review that one first; GitHub will retarget this to master when it merges. See #65600 for how this fits with the rest. ## Description The images cover the steps that run inside them: forge and manylinux each carry the proxy and start it from `/etc/profile.d`. What no image can cover is anything that **never enters a container** — the release pipeline's `init` step, and every wanda image build, both of which run directly on the agent. Those are the surfaces still resolving from `files.pythonhosted.org` (pypi/support#11895), and `init` is the one that hurts: when it fails, **zero release tests run**. It failed on the mirror-merge commit itself (release 104738, on `c1bac99054`), and 104422 only got through after three retries. `.buildkite/hooks/pre-command` runs on the agent before every step, **including wanda steps**, so it is the one place that reaches them. ## Two addresses, because they serve different consumers ``` PIP_INDEX_URL http://127.0.0.1:35999/simple RAYCI_IMAGE_PIP_INDEX_URL http://<docker bridge gateway>:35999/simple ``` The first is for pip and uv running on the agent itself — loopback, so both accept it over plain HTTP with no trusted-host handling. The second is for docker builds, which have their own loopback and reach the agent on the bridge gateway. That second one is what unparks **#65578**: wanda resolves build args from its own process environment, so exporting it is what lets an image build use the mirror. Until now nothing set it, so the `ARG` defaulted to empty and every image build silently fell back to PyPI. ## Reachability was measured, not assumed On premerge 72149, a `docker build` RUN step reached a proxy outside its network namespace on **both the BuildKit and legacy builders, with default networking and no `--network=host`**: ``` DOCKER_BUILDKIT=1 network=default build -> job-local proxy: REACHED (HTTP 200) DOCKER_BUILDKIT=1 network=host build -> job-local proxy: REACHED (HTTP 200) DOCKER_BUILDKIT=0 network=default build -> job-local proxy: REACHED (HTTP 200) DOCKER_BUILDKIT=0 network=host build -> job-local proxy: REACHED (HTTP 200) ``` ## Fail-open, deliberately and everywhere The hook runs under `set -e`, and a package mirror must never be the reason a job fails. Every path leaves the environment untouched — an unreachable mirror, no suitable interpreter, a failed install, a proxy that starts but cannot serve — and a step that gets nothing exported resolves from public PyPI exactly as it does today. Hence `source … || true` at the call site. That includes the install itself, which necessarily fetches from PyPI and so can hit the very fault being worked around. It is never worse than not trying. ## Notes for review - **`RAYCI_PYPI_PROXY_PYTHON`** names the interpreter for agents where the search would not find one. The Windows host carries 3.8, below what the proxy supports, so it needs one provisioned separately (`uv python install`) and named here. - **The agent-side cost differs by platform.** Linux agents terminate per job, so the install runs each time; macOS and Windows agents are long-lived with a persistent `HOME`, so their venv is built once per machine. A follow-up worth considering is running the proxy *from* the forge image rather than installing it, since the venv is already baked in there — but the forge tag is per-build and does not exist yet for early jobs, so it cannot be the primary mechanism. - **The proxy is probed through, not just pinged.** `/healthz` does not touch the mirror, so a process that is up but cannot reach its upstream would otherwise be advertised as working. ## Related issues Upstream cause: pypi/support#11895. Not a duplicate: no open PR adds an agent-side proxy. #65597 and #65598 wire macOS and Windows from inside their own scripts and this supersedes the need for that on the agent side; #65578 is the consumer of `RAYCI_IMAGE_PIP_INDEX_URL`. ## Testing Exercised end to end against a stub mirror on Linux: - installs to a user-writable prefix with no sudo, starts the proxy, and exports both addresses with the bridge gateway detected automatically (`http://172.17.0.1:35999/simple`) - the index it serves has artifact URLs rewritten onto the mirror - **fail-open verified twice** — with a deliberately broken interpreter (`ensurepip` failure) and with an unreachable mirror, both printed a warning and exported nothing - `pre-commit` (shellcheck) clean Not verified: a real agent of any kind, and the interaction with a real wanda image build. The failure mode if the gateway detection or the install is wrong on a real agent is a printed warning and a job that resolves from PyPI, which is the status quo rather than a new failure. AI assistance (Claude Code) was used for this change. Signed-off-by: Elliot Barnwell <[email protected]>
**Stacked on #65597** — base branch is `elliot-barn/proxy-host-support`, which carries the off-image install support this depends on (an install prefix, a skip-profile switch, and the guarded import that lets the proxy run on 3.10). Review that one first; GitHub will retarget this to master when it merges. See #65600 for how this fits with the rest. ## Description The images cover the steps that run inside them: forge and manylinux each carry the proxy and start it from `/etc/profile.d`. What no image can cover is anything that **never enters a container** — the release pipeline's `init` step, and every wanda image build, both of which run directly on the agent. Those are the surfaces still resolving from `files.pythonhosted.org` (pypi/support#11895), and `init` is the one that hurts: when it fails, **zero release tests run**. It failed on the mirror-merge commit itself (release 104738, on `c1bac99054`), and 104422 only got through after three retries. `.buildkite/hooks/pre-command` runs on the agent before every step, **including wanda steps**, so it is the one place that reaches them. ## Two addresses, because they serve different consumers ``` PIP_INDEX_URL http://127.0.0.1:35999/simple RAYCI_IMAGE_PIP_INDEX_URL http://<docker bridge gateway>:35999/simple ``` The first is for pip and uv running on the agent itself — loopback, so both accept it over plain HTTP with no trusted-host handling. The second is for docker builds, which have their own loopback and reach the agent on the bridge gateway. That second one is what unparks **#65578**: wanda resolves build args from its own process environment, so exporting it is what lets an image build use the mirror. Until now nothing set it, so the `ARG` defaulted to empty and every image build silently fell back to PyPI. ## Reachability was measured, not assumed On premerge 72149, a `docker build` RUN step reached a proxy outside its network namespace on **both the BuildKit and legacy builders, with default networking and no `--network=host`**: ``` DOCKER_BUILDKIT=1 network=default build -> job-local proxy: REACHED (HTTP 200) DOCKER_BUILDKIT=1 network=host build -> job-local proxy: REACHED (HTTP 200) DOCKER_BUILDKIT=0 network=default build -> job-local proxy: REACHED (HTTP 200) DOCKER_BUILDKIT=0 network=host build -> job-local proxy: REACHED (HTTP 200) ``` ## Fail-open, deliberately and everywhere The hook runs under `set -e`, and a package mirror must never be the reason a job fails. Every path leaves the environment untouched — an unreachable mirror, no suitable interpreter, a failed install, a proxy that starts but cannot serve — and a step that gets nothing exported resolves from public PyPI exactly as it does today. Hence `source … || true` at the call site. That includes the install itself, which necessarily fetches from PyPI and so can hit the very fault being worked around. It is never worse than not trying. ## Notes for review - **`RAYCI_PYPI_PROXY_PYTHON`** names the interpreter for agents where the search would not find one. The Windows host carries 3.8, below what the proxy supports, so it needs one provisioned separately (`uv python install`) and named here. - **The agent-side cost differs by platform.** Linux agents terminate per job, so the install runs each time; macOS and Windows agents are long-lived with a persistent `HOME`, so their venv is built once per machine. A follow-up worth considering is running the proxy *from* the forge image rather than installing it, since the venv is already baked in there — but the forge tag is per-build and does not exist yet for early jobs, so it cannot be the primary mechanism. - **The proxy is probed through, not just pinged.** `/healthz` does not touch the mirror, so a process that is up but cannot reach its upstream would otherwise be advertised as working. ## Related issues Upstream cause: pypi/support#11895. Not a duplicate: no open PR adds an agent-side proxy. #65597 and #65598 wire macOS and Windows from inside their own scripts and this supersedes the need for that on the agent side; #65578 is the consumer of `RAYCI_IMAGE_PIP_INDEX_URL`. ## Testing Exercised end to end against a stub mirror on Linux: - installs to a user-writable prefix with no sudo, starts the proxy, and exports both addresses with the bridge gateway detected automatically (`http://172.17.0.1:35999/simple`) - the index it serves has artifact URLs rewritten onto the mirror - **fail-open verified twice** — with a deliberately broken interpreter (`ensurepip` failure) and with an unreachable mirror, both printed a warning and exported nothing - `pre-commit` (shellcheck) clean Not verified: a real agent of any kind, and the interaction with a real wanda image build. The failure mode if the gateway detection or the install is wrong on a real agent is a printed warning and a job that resolves from PyPI, which is the status quo rather than a new failure. AI assistance (Claude Code) was used for this change. Signed-off-by: elliot-barn <[email protected]>
Signed-off-by: Elliot Barnwell <[email protected]>
d0173b7 to
764b784
Compare
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 764b784. Configure here.
| fi | ||
| if [[ -n "${gateway}" ]]; then | ||
| export RAYCI_IMAGE_PIP_INDEX_URL="http://${gateway}:${port}/simple" | ||
| echo "pypi index: image builds -> ${RAYCI_IMAGE_PIP_INDEX_URL}" |
There was a problem hiding this comment.
Docker HTTP index lacks trusted host
High Severity
RAYCI_IMAGE_PIP_INDEX_URL is an http:// bridge-gateway address, but nothing sets PIP_TRUSTED_HOST or UV_INSECURE_HOST for that host. Wanda wheel Dockerfiles copy this into PIP_INDEX_URL inside the build. Pip and uv treat a non-loopback HTTP index as insecure and skip it, so those image builds fail to resolve packages instead of using the mirror or public PyPI.
Reviewed by Cursor Bugbot for commit 764b784. Configure here.
) Replaces #65597 and #65601, which accumulated a tangled history (a squash-merge between them, a master merge, and two DCO repairs). Same content, byte-identical to #65597's head, as two clean commits. ## Description Two surfaces still resolve from `files.pythonhosted.org` (pypi/support#11895), and neither can be reached by the images: - **macOS** — steps run directly on the agent, so there is no image to install the proxy into and no `/etc/profile.d` being sourced. `macos_wheels_arm64` carries the `release_wheels` tag and publishes to the wheels destination on master, so a 502 there leaves the published wheel set short a platform. - **The release pipeline's `init` step, and every wanda image build** — both run directly on the agent too. `init` is the one that hurts: when it fails, **zero release tests run**. It failed on the mirror-merge commit itself (release 104738), and 104422 only got through after three retries. The mirror was already reachable from all of them — the macOS builders take `vpc_id` from `module.prod_environment`, the same VPC as that stack's `mirror-cache` and its private zone. What was missing was a way to use it. ## What changed **`ci/ray_ci/macos/pypi_proxy.sh`** — sourced from `macos_ci.sh` and `macos_ci_build.sh` before their first installs. **`.buildkite/hooks/pre-command`** + **`ci/pypi_proxy_agent.sh`** — the hook runs on the agent before every step, *including wanda steps*, so it is the one place that reaches them. It exports two addresses because they serve different consumers: ``` PIP_INDEX_URL 127.0.0.1 for pip and uv on the agent itself RAYCI_IMAGE_PIP_INDEX_URL bridge gateway for docker builds, which have their own loopback ``` The second is what unparks **#65578**: wanda resolves build args from its own process environment, and nothing set that variable before, so the `ARG` defaulted to empty and every image build silently fell back to PyPI. **Shared-script changes** that any off-image install needs: an install prefix and a skip-profile switch (so a host installs without sudo); an address override, because `hostname -i` is Linux-only and returns nothing on macOS, plus `nohup` where `setsid` is absent; a guarded `asgi_cross_origin_protection` import, the only dependency requiring 3.11 when these agents have none; and `venv --clear`, without which a half-finished install leaves stale `bin/` symlinks that a retry inherits, producing a venv whose python cannot start. ## Reachability was measured On premerge 72149, a `docker build` RUN step reached a proxy outside its network namespace on **both the BuildKit and legacy builders, default networking, no `--network=host`**. ## Known cost, worth reviewing carefully Linux agents terminate per job, so the hook's install runs on **every job**, including ones that never touch Python. macOS and Windows agents are long-lived and install once per machine. Two ways to remove that, neither done here: scope the hook to the steps that actually need it (containerised steps already get a proxy from `profile.d`), or run the proxy *from* the forge image, which already carries it at `/opt/pypiproxy`, instead of installing. ## Fail-open everywhere The hook runs under `set -e` and a package mirror must never be the reason a job fails. An unreachable mirror, no suitable interpreter, a failed install, or a proxy that starts but cannot serve all leave the environment untouched, and the step resolves from public PyPI exactly as today. ## Testing Exercised end to end against a stub mirror: installs to a user-writable prefix with no sudo, starts the proxy, exports both addresses with the bridge gateway detected automatically, and serves an index whose artifact URLs are rewritten onto the mirror. Fail-open verified twice, with a broken interpreter and with an unreachable mirror. The proxy runs on 3.10 with the optional middleware absent and on 3.11 with it present. `pre-commit` (shellcheck, ruff, black, semgrep) clean. Not verified: real macOS agents, and the interaction with a real wanda image build. The failure mode if the interpreter search, the loopback bind, or the gateway detection is wrong on a real agent is a printed warning and a job that resolves from PyPI — the status quo, not a new failure. AI assistance (Claude Code) was used for this change. --------- 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. #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_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#65602) Replaces ray-project#65597 and ray-project#65601, which accumulated a tangled history (a squash-merge between them, a master merge, and two DCO repairs). Same content, byte-identical to ray-project#65597's head, as two clean commits. ## Description Two surfaces still resolve from `files.pythonhosted.org` (pypi/support#11895), and neither can be reached by the images: - **macOS** — steps run directly on the agent, so there is no image to install the proxy into and no `/etc/profile.d` being sourced. `macos_wheels_arm64` carries the `release_wheels` tag and publishes to the wheels destination on master, so a 502 there leaves the published wheel set short a platform. - **The release pipeline's `init` step, and every wanda image build** — both run directly on the agent too. `init` is the one that hurts: when it fails, **zero release tests run**. It failed on the mirror-merge commit itself (release 104738), and 104422 only got through after three retries. The mirror was already reachable from all of them — the macOS builders take `vpc_id` from `module.prod_environment`, the same VPC as that stack's `mirror-cache` and its private zone. What was missing was a way to use it. ## What changed **`ci/ray_ci/macos/pypi_proxy.sh`** — sourced from `macos_ci.sh` and `macos_ci_build.sh` before their first installs. **`.buildkite/hooks/pre-command`** + **`ci/pypi_proxy_agent.sh`** — the hook runs on the agent before every step, *including wanda steps*, so it is the one place that reaches them. It exports two addresses because they serve different consumers: ``` PIP_INDEX_URL 127.0.0.1 for pip and uv on the agent itself RAYCI_IMAGE_PIP_INDEX_URL bridge gateway for docker builds, which have their own loopback ``` The second is what unparks **ray-project#65578**: wanda resolves build args from its own process environment, and nothing set that variable before, so the `ARG` defaulted to empty and every image build silently fell back to PyPI. **Shared-script changes** that any off-image install needs: an install prefix and a skip-profile switch (so a host installs without sudo); an address override, because `hostname -i` is Linux-only and returns nothing on macOS, plus `nohup` where `setsid` is absent; a guarded `asgi_cross_origin_protection` import, the only dependency requiring 3.11 when these agents have none; and `venv --clear`, without which a half-finished install leaves stale `bin/` symlinks that a retry inherits, producing a venv whose python cannot start. ## Reachability was measured On premerge 72149, a `docker build` RUN step reached a proxy outside its network namespace on **both the BuildKit and legacy builders, default networking, no `--network=host`**. ## Known cost, worth reviewing carefully Linux agents terminate per job, so the hook's install runs on **every job**, including ones that never touch Python. macOS and Windows agents are long-lived and install once per machine. Two ways to remove that, neither done here: scope the hook to the steps that actually need it (containerised steps already get a proxy from `profile.d`), or run the proxy *from* the forge image, which already carries it at `/opt/pypiproxy`, instead of installing. ## Fail-open everywhere The hook runs under `set -e` and a package mirror must never be the reason a job fails. An unreachable mirror, no suitable interpreter, a failed install, or a proxy that starts but cannot serve all leave the environment untouched, and the step resolves from public PyPI exactly as today. ## Testing Exercised end to end against a stub mirror: installs to a user-writable prefix with no sudo, starts the proxy, exports both addresses with the bridge gateway detected automatically, and serves an index whose artifact URLs are rewritten onto the mirror. Fail-open verified twice, with a broken interpreter and with an unreachable mirror. The proxy runs on 3.10 with the optional middleware absent and on 3.11 with it present. `pre-commit` (shellcheck, ruff, black, semgrep) clean. Not verified: real macOS agents, and the interaction with a real wanda image build. The failure mode if the interpreter search, the loopback bind, or the gateway detection is wrong on a real agent is a printed warning and a job that resolves from PyPI — the status quo, not a new failure. AI assistance (Claude Code) was used for this change. --------- 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]>


Description
macOS jobs resolve every package straight from
files.pythonhosted.org, so they arefully exposed to the intermittent 502s (pypi/support#11895). That matters more than a
red test:
macos_wheels_arm64carries therelease_wheelstag and publishes withcopy_files --destination wheelson master, so a failure there means the publishedwheel set is missing a platform.
The mirror has been reachable from these agents all along — the macOS builders take
vpc_idfrommodule.prod_environment, the same VPC as that stack'smirror-cachedeployment and its private zone. What was missing was any way to use it: the Linux
images get the proxy through
/etc/profile.d, and a macOS step is not a login shellinto an image.
What changed
ci/ray_ci/macos/pypi_proxy.shis a new sourceable entry point, called frommacos_ci.shandmacos_ci_build.shimmediately before their first installs. Itinstalls the proxy if needed, then hands off to the existing
ci/pypi_proxy_profile.shfor the mirror probe, mode selection, readiness wait andfail-open paths, rather than reimplementing them.
Three small changes make the shared pieces usable off-image:
install_pypi_proxy.shtakesRAYCI_PYPI_PROXY_PREFIX(default unchanged at/opt/pypiproxy) so a host can install without sudo, andRAYCI_PYPI_PROXY_SKIP_PROFILE=1because there is no/etc/profile.dworth writing.It now also creates the venv with
--clear: without it a first attempt that failedpartway leaves stale
bin/symlinks that a later attempt inherits, producing a venvwhose python cannot start at all. Found while testing exactly that sequence.
pypi_proxy_profile.shtakesRAYCI_PYPI_PROXY_HOST, because the address camefrom
hostname -i, a Linux-only spelling that returns nothing on macOS. It alsodetaches with
nohupwheresetsidis absent, which is every macOS agent.pypi_index_proxy.pyguards theasgi_cross_origin_protectionimport, and theinstaller skips that dependency below 3.11. It is the only dependency requiring 3.11
— starlette and uvicorn need 3.10, niquests 3.7 — and these agents have no 3.11: reef
provisions 3.9.13 and 3.10.11, plus a miniforge 3.10. The middleware rejects
cross-site state-changing requests and every route here is a GET, which it always
allows, so where it is absent nothing it would have done is skipped. Images with 3.11+
still install it and behave exactly as before.
Why this is cheap on these agents
They are long-lived — a launchd service with no
disconnect-after-joband a persistentHOME— so the venv is built once per machine, not once per job. And with no containersinvolved, nothing else needs to reach the proxy, so it binds loopback, which pip and uv
accept over plain HTTP with no trusted-host handling.
Every failure path leaves the environment untouched and the job resolves from PyPI as it
does today, including the first install on a cold machine, which necessarily fetches
from PyPI itself. The
source ... || trueat both call sites is deliberate: underset -ethis must never be the reason a wheel build fails.Related issues
Upstream cause: pypi/support#11895. Not a duplicate: no open PR touches the macOS CI
scripts or the proxy install; ray#65593 changes the same proxy file but only pins the
Acceptheader, and the two do not overlap in content.Testing
Run locally on Linux against a stub mirror, since the macOS agents cannot be reproduced
here. What was verified end to end:
profile.d, using Python 3.10,correctly omitting the 3.11-only dependency.
RAYCI_PYPI_INDEX_MODE=local-proxy,PIP_INDEX_URL/UV_INDEX_URL=http://127.0.0.1:35999/simpleandRULES_PYTHON_PIP_ISOLATED=0, and the proxy serves an index whose artifact URLs arerewritten onto the mirror.
with it present.
printed, and no index variables are exported.
--clearrepairs a venv left broken by a previous failed attempt; before that changethe retry produced an unusable interpreter.
pre-commit(shellcheck, ruff, black, semgrep) clean on every changed file.Not verified: a real macOS agent, which needs this branch in CI. The failure mode if the
interpreter search or the loopback bind is wrong on a real agent is a printed warning
and a job that resolves from PyPI, which is the status quo rather than a new failure.
AI assistance (Claude Code) was used for this change.