Repository navigation
[ci][DO NOT MERGE] PyPI mirror: the complete picture - #65600
Closed
elliot-barn wants to merge 15 commits into
Closed
elliot-barn wants to merge 15 commits into
elliot-barn wants to merge 15 commits into
Conversation
Docker builds are the one CI surface that cannot be pointed at a package index by configuring the step: BuildKit RUN steps inherit nothing from the environment of the process that started the build, so every `pip install` inside ci/docker/*.Dockerfile goes to whatever pip defaults to. On premerge 72104 that was visible as five direct files.pythonhosted.org fetches in each `wanda: wheel py3.*` job while every forge-based step in the same build resolved elsewhere. The only channel into a build is a build arg, so this adds one on the four roots of the CI image graph plus the tester image, and lets the children inherit through ENV. Deliberately generic and empty by default: nothing here names a host, and a build that passes no argument resolves from https://pypi.org/simple exactly as it does today, which is what keeps this invisible to anyone building these images outside CI. The published images under docker/ are untouched. wanda resolves the value from RAYCI_IMAGE_PIP_INDEX_URL in the environment of the job, so setting it is a CI-side decision rather than a repo one, and unsetting it is a complete rollback with no code change. Note the value has to be stable across jobs to be usable: build args are part of wanda's content-addressed cache key, so a per-job address would rebuild every image on every build. A fixed hostname is fine; anything job-scoped is not. Signed-off-by: elliot-barn <[email protected]>
The BYOD images are built by wanda in CI, not in an Anyscale account:
docker/base-extra-testdeps/{cpu,cuda}.wanda.yaml build
release/ray_release/byod/byod.Dockerfile. So they are the same reachable docker-build
gap as the wheel builds, and the previous commit missed them by only covering
ci/docker.
Worth having for the same reason the release pipeline is worth protecting at all:
this image installs python/deplocks/base_extra_testdeps/*.lock, the release tests'
extra dependencies, so one failed fetch during the build costs a nightly rather than
a single job.
Same shape as the rest -- generic arg, empty default, resolves from PyPI for anyone
building outside CI.
Signed-off-by: elliot-barn <[email protected]>
The plumbing landed inert: nothing sets RAYCI_IMAGE_PIP_INDEX_URL, so every image build resolved from PyPI exactly as before. It was parked on an unproven question -- whether a docker build RUN step can reach a proxy outside its network namespace. Measured on premerge 72149, in forge, all four combinations: DOCKER_BUILDKIT=1 network=default job-local proxy: REACHED (HTTP 200) DOCKER_BUILDKIT=1 network=host job-local proxy: REACHED (HTTP 200) DOCKER_BUILDKIT=0 network=default job-local proxy: REACHED (HTTP 200) DOCKER_BUILDKIT=0 network=host job-local proxy: REACHED (HTTP 200) Both builders, default networking, no --network=host required. So the step's own PIP_INDEX_URL is usable from inside the build, and that is what these now fall back to. RAYCI_IMAGE_PIP_INDEX_URL stays an explicit override for a fleet that needs a different value, or "" to opt out entirely. Also passes it from release/ray_release/byod/build.py, without which the ARG this PR adds to byod.Dockerfile had nothing to take. That build runs in a forge step on the release stack, so the same reasoning applies. Appended after -t so the argument prefix callers match on does not move. The wanda-built images are unaffected and stay on PyPI: those jobs are not containerised, so no proxy runs in them and the build arg resolves empty. Reaching them needs a proxy outside the job, which is a separate change. test_linux_tester_container pins both variables now. It asserts an exact command and runs in forge, where PIP_INDEX_URL is always set, so without pinning the expectation would depend on the environment. Tested: pytest over test_linux_tester_container, test_byod_build and test_custom_byod_build -- 18 passed, both with a clean environment and with PIP_INDEX_URL set as it is in CI. AI assistance (Claude Code) was used for this change. Signed-off-by: elliot-barn <[email protected]>
`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]>
Windows had no mirror wiring at all, and it is the platform actively breaking release
wheels: windows_wheels carries the release_wheels tag and uploads for 3.10 through 3.14,
so a 502 there leaves the published wheel set short a platform. Seen on premerge 72138
and again on postmerge 19272, both on whl_library fetching bazel-runfiles.
The failures are inside a docker build, not a plain container command:
Step 17/18 : RUN bash ci/ray_ci/windows/build_ray.sh
+ pip install -v -e python
-> bazel build //:gen_ray_pkg -> whl_library -> 502
So the proxy runs inside that container on loopback rather than on the agent. That
avoids needing an interpreter on the Windows host, which carries 3.8 -- below what the
proxy supports -- and avoids discovering the host's address from inside a container.
The image's conda python is 3.10, which is enough: the only dependency requiring 3.11 is
skipped by the installer and guarded at import.
The venv is baked into the windowsbuild image by build_base.sh, so nothing is installed
at job time. ci/ray_ci/windows/pypi_proxy.sh starts it and is sourced by both places
that install packages: build_ray.sh for the tester's image build, and the wheel
builder's command list, whose commands are joined into one bash invocation so the
exports carry to build-wheel-windows.sh.
Also teaches the shared pieces about Windows venv layout, which puts the interpreter in
Scripts/ rather than bin/: the installer locates the script directory, and the profile
script takes RAYCI_PYPI_PROXY_PYTHON.
Every path fails open. The wanda windowsbuild image build itself still resolves from
PyPI, unchanged: those jobs are not containerised and have no proxy in scope, which is
the same gap ray#65578 waits on.
AI assistance (Claude Code) was used for this change.
Signed-off-by: elliot-barn <[email protected]>
Review feedback on #65593. Header values are case-insensitive, so an upstream replying TEXT/HTML would have tripped the warning and told the reader to delete cache entries that are in fact correct. `or` rather than a default additionally covers a header that is present but empty. Tested: added a case where the stub upstream replies "TEXT/HTML; charset=UTF-8" and asserted the warning does not fire; the existing JSON case still fires it. Signed-off-by: elliot-barn <[email protected]>
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]>
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]>
The images cover 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 failing means zero release tests run at all: it failed on the mirror-merge commit itself, 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. It starts the proxy there and exports two addresses, because they serve different consumers: PIP_INDEX_URL 127.0.0.1, for pip and uv on the agent itself. Loopback, so both accept it over plain HTTP with no trusted-host handling. RAYCI_IMAGE_PIP_INDEX_URL the docker bridge gateway, for docker builds, which have their own loopback. wanda resolves build args from its own process environment, so exporting this is what lets an image build use the mirror -- which is what ray#65578 has been waiting for. Reachability is not assumed: measured 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, no --network=host needed. Everything is guarded. The hook runs under set -e and a package mirror must never be the reason a job fails, so every path leaves the environment untouched and a step that gets nothing exported resolves from public PyPI exactly as it does today. That includes the install itself, which necessarily fetches from PyPI and so can hit the very fault being worked around. 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. Tested against a stub mirror: the hook installs to a user-writable prefix, 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 by pointing it at a broken interpreter and at an unreachable mirror. AI assistance (Claude Code) was used for this change. 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]>
…ypi-mirror-complete # Conflicts: # ci/pypi_proxy_profile.sh
…i-mirror-complete
elliot-barn
added a commit
that referenced
this pull request
Aug 19, 2026
**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]>
elliot-barn
added a commit
that referenced
this pull request
Aug 19, 2026
**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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
DO NOT MERGE — integration preview. This branch merges the five PRs below so the end state is legible as one diff. Review and merge the individual PRs; this exists to answer "what does it look like when it is all in".
The problem
files.pythonhosted.orgreturns intermittent 502s (pypi/support#11895) in ~45 second bursts at a 10–17% error rate. A CI job cold-fetches dozens of wheels concurrently, so it samples that fault repeatedly. Retries do not clear it: pip with--retries=50exhausted on a single wheel while 47 of 62 job-level retries passed in the same build, because urllib3 reuses the pooled connection and stays pinned to the same bad Fastly edge.The fix already deployed is a caching mirror per Buildkite stack (
mirror.ci.ray.io, reef#273). These PRs are what point CI at it.The one structural fact everything follows from
The mirror is a byte cache, not an index. PyPI's
/simple/pages carry absolute artifact URLs — all 4426 links on cython's page point atfiles.pythonhosted.org— so pointing pip at the mirror's copy fetches the listing through the cache and the wheels from the origin, which is the half that fails. And the mirror cannot rewrite them: it parses only/<host>/<path>, and serves cache hits as 303 redirects to presigned S3 URLs, so it never holds a body to edit.Hence a small rewriting proxy in front of it. Everything below is a consequence of that.
The five PRs
text/htmlhttp_archive, not pipWhat each surface gets
whl_libraryhttp_archiveinitThings worth knowing while reading
The representation bug is why #65593 exists. The mirror caches
/simple/keyed on URL with noVary, and the proxy forwarded each client'sAccept. uv asks for PEP 691 JSON, so JSON got cached;whl_library's pip is 22.0.4, two releases before PEP 691 support landed in pip 22.2, so it skipped the page and reportedfrom versions: none— which reads exactly like a bad version pin. It gets worse with use, since every uv-driven job poisons more entries andcache/holds them for 180 days. Pinning stops new poisoning; the already-cached entries need thecache/pypi.org/simple/prefix deleted.A bazel rewrite replaces the URL set rather than adding to it. So the naive single rule discards the origin and turns a mirror outage into a hard build failure. #65599 emits an identity rewrite alongside, verified against bazel 7.5.0: with an unreachable mirror, one rule fails the build and two rules warn and succeed. Found by reading anyscale/rayturbo#4205, which also notes it would discard the fallbacks
auto_http_archivebuilds for the C++ dependencies if the pattern is broadened past pythonhosted.Two addresses, not one. The agent hook exports
PIP_INDEX_URLon loopback for pip running on the agent, andRAYCI_IMAGE_PIP_INDEX_URLon the docker bridge gateway for docker builds, which have their own loopback. wanda resolves build args from its own process environment, which is what lets an image build use the mirror at all.Reachability from a docker build was measured, not assumed — premerge 72149, both the BuildKit and legacy builders, default networking, no
--network=host.Everything fails open. Every path leaves the environment untouched when the mirror is unreachable, the proxy will not start, or no suitable interpreter exists, and the job then resolves from public PyPI exactly as it does today. That includes the agent install, which necessarily fetches from PyPI and so can hit the very fault being worked around.
Testing
Each PR carries its own testing notes. Across this branch:
pre-commit(shellcheck, ruff, black, semgrep) clean on all 32 files; the proxy verified on Python 3.10 and 3.11, with and without the optional middleware; the bazel rewrite verified against 7.5.0 for scheme preservation, config acceptance, identity fallback, andcommonscoping; the agent hook and the macOS path exercised end to end against a stub mirror, including their fail-open paths.Not verified anywhere: real macOS and Windows agents, and a real wanda image build against the live mirror. Those are what the first CI run on each PR shows.
AI assistance (Claude Code) was used for this change.