Skip to content

[ci] Make release pipeline bootstrap survive transient PyPI/GitHub errors - #65538

Closed
elliot-barn wants to merge 2 commits into
masterfrom
elliot-barn-release-ci-network-retries
Closed

elliot-barn wants to merge 2 commits into
masterfrom
elliot-barn-release-ci-network-retries

Conversation

@elliot-barn

@elliot-barn elliot-barn commented Aug 17, 2026 •

Copy link
Copy Markdown
Collaborator

Description

A transient files.pythonhosted.org 502 currently fails a CI or release build outright, because almost nothing on the PyPI fetch path retries. Today that produced red across both pipelines all day, including three consecutive nightly release failures that ran zero release tests.

This PR adds retries on every PyPI/GitHub fetch surface in the repo. It is intentionally broad so CI can be taken green in one shot; it is straightforward to split along the commit boundaries (release bootstrap vs. CI images) afterwards.

Why one 502 is fatal

Nightly release build 104422 failed three times, each on a single 502 on a different wheel:

Attempt Time (UTC) Wheel that 502'd
1 05:04 oauth2client-4.1.3
2 16:29 python_dateutil-2.9.0.post0
3 16:41 cachetools-5.3.3

Each cascaded identically: whl_library py_deps_py310_<pkg> failed → Analysis of target '//release:custom_image_build_and_test_init' failed → exit 1, no pipeline uploaded. The init step generates and uploads every release test step, so losing it loses the whole nightly.

Confirmed 502s at 02:13, 05:04, 06:59, 16:29, 16:41 and 17:13 UTC — a sustained >15-hour condition that status.python.org never posted an incident for. A job cold-fetching 47-55 wheel repositories is unlikely to survive that without retries anywhere.

The four pip surfaces

Failures were spread across four independent surfaces. Sampling premerge 71970 and 71973, every failure traced to a 502, but on different pips:

Surface Example Covered by
Bazel whl_library core: python tests, data: arrow v17 — raw HTTP error 502 on py_deps_py310_* #65518 (+ timeout here)
forge container pip lint: clang_format — pip install -c python/requirements_compiled.txt clang-format this PR
manylinux pip wanda: wheel py3.11 — pip install cython setuptools, retried and exhausted this PR
uv wanda: corebuild-py3.12, llm cpu tests — Failed to download everett==3.1.0 / Request failed after 3 retries / 502 Bad Gateway this PR

Changes

.bazelrc — downloader retries were --config=ci only

--experimental_repository_downloader_retries was scoped to build:ci, but .buildkite/release/custom-image-build-and-test-init.sh invokes bazel directly with no --config=ci, so http_archive fetches in the step that builds the entire release pipeline had no retries at all. Made unconditional, raised 3 → 6. This also covers the rules_python 0.9.0 tarball, fetched unmirrored from github.com, which returned 429 Too Many Requests during today's GitHub incident (premerge 71978).

WORKSPACE — pip_parse timeout headroom

whl_library shells out to pip, so Bazel's downloader retries never apply to wheel fetches and pip must retry itself. Retrying costs wall clock, and rules_python defaults the per-whl_library subprocess ceiling to 600s. Verified the attribute reaches every generated whl_library: pip_repository forwards it as --timeout (pip_repository.bzl:156-160) → whl_library_args = dict(vars(args)) (parse_requirements_to_bzl/__init__.py:60) → _config → **_config splatted by install_deps() → rctx.execute(timeout = rctx.attr.timeout). Without the headroom, #65518's retries can be cut off mid-flight and surface as an opaque Bazel timeout instead of the underlying HTTP error.

custom-image-build-and-test-init.sh — bootstrap downloads

The bazelisk binary and uv installer are fetched with no retry. GitHub's incident today reported "Archive downloads and raw repository content downloads are experiencing an approximate 50% error rate" — a coin flip on the step that gates all release testing.

--retry-all-errors is deliberately not used: it requires curl >= 7.71 and would be an unknown-option hard failure on older agents. Plain --retry already treats HTTP 408/429/500/502/503/504 as transient, which is exactly this failure mode.

CI image roots — PIP_RETRIES / PIP_DEFAULT_TIMEOUT / UV_HTTP_RETRIES / UV_HTTP_TIMEOUT

Set on the five roots of the image graph so all 23 descendant images inherit them, at build time and test time:

Root Base Why it needs its own copy
base.test.Dockerfile ubuntu:jammy root of oss-ci-base_test; via base.build / base.ml the ancestor of most test images
base.gpu.Dockerfile nvidia/cuda separate root for the gpu images
forge.Dockerfile ubuntu:22.04 runs the CI job commands themselves, so it covers ad hoc pip installs in ci/ scripts
manylinux.Dockerfile quay.io/pypa/manylinux2014 the wheel builds
windows.build.Dockerfile rayproject/buildenv:windows windows tests

byod.Dockerfile gets the same block, declared before its RUN so the build picks it up and kept in the image so the byod_*.sh scripts that pip install at cluster startup inherit it. Its Microsoft apt key download gets --retry too.

uv is included because its default is only 3 retries, observed being exhausted on a 502. Older uv ignores UV_HTTP_RETRIES rather than erroring; PIP_* is read because none of these pip invocations use --isolated.

Related issues

None tracked. Complements #65518, which pins pip 24.0 so whl_library retries 502 at all — without it the Bazel surface stays broken, since rules_python 0.9.0's vendored pip 22.0.4 omits 502 from urllib3's status_forcelist. The only file overlap is WORKSPACE, where #65518 adds environment / extra_pip_args to the same pip_parse call and this adds timeout; whichever lands second needs a trivial conflict resolution.

Additional information

Scope

Mitigation, not a structural fix. Retries make transient failures survivable, but a sustained outage still fails — #65518's own premerge shows nine retries being exhausted. The structural fixes are a pre-populated Bazel --repository_cache in the forge image, or an internal PyPI pull-through mirror (there is no PIP_INDEX_URL or proxy configured anywhere in the repo today). Both are out of scope.

Known remaining gap, deliberately not addressed: git clone https://github.com/wg/wrk.git in byod.Dockerfile has no retry, and git clone has no equivalent flag — it would need a wrapper loop.

Tests run

Command Result
buildifier --mode=check --lint=warn WORKSPACE exit 0
bash -n .buildkite/release/custom-image-build-and-test-init.sh passed
shellcheck -S warning .buildkite/release/custom-image-build-and-test-init.sh clean
pre-commit run --files <all 9 changed files> passed (shellcheck, semgrep, whitespace, EOF)
UV_HTTP_RETRIES=<bad> uv pip install --dry-run requests errors on parse, confirming uv reads the variable
curl --retry transient-code coverage verified 408/429/500/502/503/504; --retry-all-errors avoided as curl >= 7.71 only
image graph audit 5 roots identified, 23 descendants confirmed to inherit

Not run: a full bazel fetch of the release init target, and the image builds themselves, which need CI infrastructure and a healthy PyPI. Premerge on this PR is the real test.

AI assistance

This change was developed with AI assistance (Claude Code). The investigation — correlating the three nightly init failures to one 502 each on a different wheel, tracing the pip_parse timeout propagation through rules_python 0.9.0, finding that the release init step never passes --config=ci, classifying premerge failures by which pip surface they occur on, and auditing the image graph for its roots — was AI-assisted and then verified with the commands above.

@elliot-barn elliot-barn added the go add ONLY when ready to merge, run all tests label Aug 17, 2026
…rors

The release pipeline's init step generates and uploads every release test
step, so a single unretried network failure there means zero release tests
run for that nightly. Three consecutive nightly init failures were caused by
one transient files.pythonhosted.org 502 each, on a different wheel every
time (oauth2client, python-dateutil, cachetools).

- .bazelrc: --experimental_repository_downloader_retries was scoped to
  --config=ci, but the release init step invokes bazel directly without it,
  so http_archive fetches there had no retries at all. Make it unconditional
  and raise 3 -> 6. This also covers the rules_python tarball, which is
  fetched unmirrored from github.com and returned 429 during today's GitHub
  incident.
- .buildkite/release/custom-image-build-and-test-init.sh: retry the bazelisk
  and uv installer downloads. Archive and release downloads from github.com
  run at a heavily degraded error rate during an incident.
- release/ray_release/byod/byod.Dockerfile: set PIP_RETRIES and
  UV_HTTP_RETRIES so both the image build and the byod_*.sh scripts that pip
  install at cluster startup retry, and retry the Microsoft apt key download.

curl's --retry already treats HTTP 408/429/500/502/503/504 as transient, so
--retry-all-errors is deliberately not used: it needs curl >= 7.71 and would
be an unknown-option failure on older agents.

Only retry counts are changed, not socket timeouts. Every failure observed
was an immediate 502 response or uv exhausting its 3 retries, never a hang,
so raising pip's or uv's request timeout would only lengthen the worst-case
time to fail.

Signed-off-by: elliot-barn <[email protected]>
Premerge failures today were spread across four different pip surfaces, and
three of them are ordinary pip/uv invocations inside CI image builds that had
no retry configuration at all:

- lint: clang_format -- `pip install -c python/requirements_compiled.txt
  clang-format` in the forge container, OSError / max retries exceeded.
- wanda: wheel py3.11 -- `pip install cython setuptools` under the manylinux
  interpreters, retried and exhausted.
- wanda: corebuild-py3.12, llm cpu tests -- uv, "Failed to download
  everett==3.1.0 / Request failed after 3 retries / 502 Bad Gateway".

Set PIP_RETRIES and UV_HTTP_RETRIES on the five roots of the image graph so
all 23 descendant images inherit them, at build time and at test time:

- base.test.Dockerfile (ubuntu:jammy) -- root of oss-ci-base_test, and via
  base.build / base.ml the ancestor of most test images.
- base.gpu.Dockerfile (nvidia/cuda) -- separate root for the gpu images.
- forge.Dockerfile (ubuntu:22.04) -- runs the CI job commands themselves, so
  it also covers ad hoc pip installs in ci/ scripts.
- manylinux.Dockerfile (quay.io/pypa/manylinux2014) -- the wheel builds.
- windows.build.Dockerfile (rayproject/buildenv:windows).

uv is included because its default is only 3 retries, which was observed being
exhausted on a 502. Older uv releases ignore UV_HTTP_RETRIES rather than
erroring, and pip needs >= 24.0 for 502 itself to be retryable.

The Bazel whl_library surface is deliberately not addressed here: it runs pip
with --isolated, so PIP_* never reaches it, and rules_python 0.9.0's vendored
pip 22.0.4 omits 502 from urllib3's status_forcelist regardless of retry
count. That needs the pip 24.0 pin in #65518.

Signed-off-by: elliot-barn <[email protected]>
@elliot-barn
elliot-barn force-pushed the elliot-barn-release-ci-network-retries branch from dabe629 to 816ba6f Compare August 17, 2026 18:40
elliot-barn added a commit that referenced this pull request Aug 19, 2026
## Description

`files.pythonhosted.org` returns intermittent 502s (pypi/support#11895).
Ray CI is hit
disproportionately because a single job cold-fetches ~50 wheels
concurrently, so it
samples the fault dozens of times per job, and `rules_python` shells out
to pip inside
`whl_library`, where one 502 fails the repository rule and the build
with it.

**Retries do not fix this, which is why this PR contains none.**
Measured on premerge
build 72083: pip with `--retries=50` and a jittered 6-12s backoff
exhausted on a single
wheel with `too many 502 error responses`, while 47 of 62 *job-level*
retries in the same
build passed. urllib3 retries reuse the pooled connection and the
already-resolved
address, and anycast keeps every attempt on the same bad Fastly edge, so
fifty in-process
attempts are not fifty independent attempts. What fixes it is not asking
that edge —
i.e. a cache in front of PyPI, which fetches each `(package, version)`
once and serves it
from S3 afterwards.

Four commits, in dependency order:

1. **Make the index an environment property.** Valueless `--repo_env`
for
   `PIP_INDEX_URL`, `PIP_EXTRA_INDEX_URL`, `PIP_TRUSTED_HOST` and
`RULES_PYTHON_PIP_ISOLATED` in `.bazelrc`, and those plus the `UV_*`
equivalents
   forwarded into nested containers by `ci/ray_ci/container.py`.
`RULES_PYTHON_PIP_ISOLATED` is load-bearing: `whl_library` runs pip with
   `--isolated`, which otherwise makes it ignore every `PIP_*` variable.
The passthrough lives in the repo's `.bazelrc` rather than a generated
one because
every bazel invocation reads it, including the nested ones
`ci/ray_ci:test_in_docker`
spawns, which a `--config` flag on a step's command line never reaches.
2. **Stop the lock files overriding it.** 97 of the 99 files under
`python/deplocks`
opened with `--index-url https://pypi.org/simple`, and a requirements
file's index URL
beats both the environment and the command line. The `--extra-index-url`
and
`--find-links` entries for PyTorch, libtpu and PyG stay: those are not
PyPI, so
   nothing else supplies them at install time.
3. **Resolve through the mirror when the job can reach it.** The forge
image carries
`ci/pypi_index_proxy.py` and a `profile.d` script that probes the mirror
and picks a
   mode.

### Why a proxy and not just an index URL

One `pip install` is two requests: the project page, governed by
`--index-url`, and the
artifact, governed by the URL written in that page's body. PyPI's simple
index hands out
**absolute** `files.pythonhosted.org` URLs, so pointing `--index-url` at
a path-prefix
byte cache mirrors the metadata request and leaves the multi-megabyte
download on the
origin that is returning the 502s. The proxy rewrites those file URLs so
both hops
transit the mirror. Wheels do not stream through the proxy process —
clients fetch them
straight from the mirror at the rewritten URLs — and the `#sha256=`
fragments hash
artifact content, not URLs, so hash verification is unaffected.

### Fail-open, deliberately

The probe accepts a mode only after a real index fetch succeeds through
it, and exports
nothing otherwise, leaving pip and uv on public PyPI. That check hits
the mirror rather
than only the local process because `/healthz` never touches the mirror:
a healthy proxy
in front of an unreachable mirror answers every request with a 502,
which is strictly
worse than no proxy. Build 72083 exercised exactly that path — `mirror
unreachable from
this agent` — and the build continued.

## Related issues

Upstream cause: pypi/support#11895.

Not a duplicate: commits 1-2 are #65562 and commit 3 is #65563, opened
as standalone
reviewable units before the mirror existed. If reviewers prefer, land
those two first and
this rebases down to the single mirror commit. #65518 and #65538 raise
pip/uv retry
tolerance; they are complementary and deliberately excluded here, per
the measurement
above.

## Additional information

**Depends on infrastructure:** the mirror is a per-VPC deployment in the
Ray CI account,
so `https://mirror.ci.ray.io` only resolves inside the Buildkite stack
VPCs.
`RAYCI_PYPI_MIRROR_URL` overrides the default for a fleet that runs its
own.

**Deliberately out of scope:** image builds still resolve from PyPI. The
`pip` and `uv`
invocations in `ci/docker/*.Dockerfile` run in a separate BuildKit
context that cannot
reach a proxy bound on the forge container's loopback, and a per-job
address would change
wanda's content-addressed cache key on every build and rebuild every
image. That needs a
build-reachable index, which is a follow-up.

`ci/pypi_index_proxy.py` is vendored from a public gist, recorded at the
top of the file
along with the one local edit (the default mirror URL).

## Testing

- `PYTHONPATH=.:release python -m pytest -q
ci/ray_ci/test_linux_tester_container.py
ci/ray_ci/test_container.py ci/ray_ci/test_tester.py
ci/ray_ci/test_linux_container.py
  ci/ray_ci/test_windows_container.py` — 24 passed.
- `bazel test //ci/raydepsets:test_cli` — passed, including
`test_diff_lock_files_up_to_date`, the generated-equals-committed
invariant for the
  deplock change.
- Bazel 7.5.0: verified that a valueless `common --repo_env=NAME`
reaches
`rctx.os.environ` in a repository rule and reads unset when the variable
is unset, and
  that `bazel info`/`query`/`version` do not reject the `common` lines.
- `docker run --env NAME` with NAME unset leaves it absent in the
container, not empty —
  which is what keeps the default path unchanged.
- The mechanism as a whole ran on premerge 72083 (on a superset branch):
the probe logged
its verdict, fell back to PyPI because that fleet has no route to the
mirror at the
  time, and the build proceeded.
- `pre-commit run --files` over every changed file, shellcheck included.

AI assistance (Claude Code) was used for this change.

---------

Signed-off-by: elliot-barn <[email protected]>
Signed-off-by: Elliot Barnwell <[email protected]>
@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had
any activity for 14 days. It will be closed in another 14 days if no further activity occurs.
Thank you for your contributions.

You can always ask for help on our discussion forum or Ray's public slack channel.

If you'd like to keep this open, just leave any comment, and the stale label will be removed.

@github-actions github-actions Bot added the stale The issue is stale. It will be closed within 7 days unless there are further conversation label Sep 1, 2026
@github-actions

Copy link
Copy Markdown

This pull request has been automatically closed because there has been no more activity in the 14 days
since being marked stale.

Please feel free to reopen or open a new pull request if you'd still like this to be addressed.

Again, you can always ask for help on our discussion forum or Ray's public slack channel.

Thanks again for your contribution!

@github-actions github-actions Bot closed this Sep 15, 2026
nadongjun pushed a commit to nadongjun/ray that referenced this pull request Oct 6, 2026
## Description

`files.pythonhosted.org` returns intermittent 502s (pypi/support#11895).
Ray CI is hit
disproportionately because a single job cold-fetches ~50 wheels
concurrently, so it
samples the fault dozens of times per job, and `rules_python` shells out
to pip inside
`whl_library`, where one 502 fails the repository rule and the build
with it.

**Retries do not fix this, which is why this PR contains none.**
Measured on premerge
build 72083: pip with `--retries=50` and a jittered 6-12s backoff
exhausted on a single
wheel with `too many 502 error responses`, while 47 of 62 *job-level*
retries in the same
build passed. urllib3 retries reuse the pooled connection and the
already-resolved
address, and anycast keeps every attempt on the same bad Fastly edge, so
fifty in-process
attempts are not fifty independent attempts. What fixes it is not asking
that edge —
i.e. a cache in front of PyPI, which fetches each `(package, version)`
once and serves it
from S3 afterwards.

Four commits, in dependency order:

1. **Make the index an environment property.** Valueless `--repo_env`
for
   `PIP_INDEX_URL`, `PIP_EXTRA_INDEX_URL`, `PIP_TRUSTED_HOST` and
`RULES_PYTHON_PIP_ISOLATED` in `.bazelrc`, and those plus the `UV_*`
equivalents
   forwarded into nested containers by `ci/ray_ci/container.py`.
`RULES_PYTHON_PIP_ISOLATED` is load-bearing: `whl_library` runs pip with
   `--isolated`, which otherwise makes it ignore every `PIP_*` variable.
The passthrough lives in the repo's `.bazelrc` rather than a generated
one because
every bazel invocation reads it, including the nested ones
`ci/ray_ci:test_in_docker`
spawns, which a `--config` flag on a step's command line never reaches.
2. **Stop the lock files overriding it.** 97 of the 99 files under
`python/deplocks`
opened with `--index-url https://pypi.org/simple`, and a requirements
file's index URL
beats both the environment and the command line. The `--extra-index-url`
and
`--find-links` entries for PyTorch, libtpu and PyG stay: those are not
PyPI, so
   nothing else supplies them at install time.
3. **Resolve through the mirror when the job can reach it.** The forge
image carries
`ci/pypi_index_proxy.py` and a `profile.d` script that probes the mirror
and picks a
   mode.

### Why a proxy and not just an index URL

One `pip install` is two requests: the project page, governed by
`--index-url`, and the
artifact, governed by the URL written in that page's body. PyPI's simple
index hands out
**absolute** `files.pythonhosted.org` URLs, so pointing `--index-url` at
a path-prefix
byte cache mirrors the metadata request and leaves the multi-megabyte
download on the
origin that is returning the 502s. The proxy rewrites those file URLs so
both hops
transit the mirror. Wheels do not stream through the proxy process —
clients fetch them
straight from the mirror at the rewritten URLs — and the `#sha256=`
fragments hash
artifact content, not URLs, so hash verification is unaffected.

### Fail-open, deliberately

The probe accepts a mode only after a real index fetch succeeds through
it, and exports
nothing otherwise, leaving pip and uv on public PyPI. That check hits
the mirror rather
than only the local process because `/healthz` never touches the mirror:
a healthy proxy
in front of an unreachable mirror answers every request with a 502,
which is strictly
worse than no proxy. Build 72083 exercised exactly that path — `mirror
unreachable from
this agent` — and the build continued.

## Related issues

Upstream cause: pypi/support#11895.

Not a duplicate: commits 1-2 are ray-project#65562 and commit 3 is ray-project#65563, opened
as standalone
reviewable units before the mirror existed. If reviewers prefer, land
those two first and
this rebases down to the single mirror commit. ray-project#65518 and ray-project#65538 raise
pip/uv retry
tolerance; they are complementary and deliberately excluded here, per
the measurement
above.

## Additional information

**Depends on infrastructure:** the mirror is a per-VPC deployment in the
Ray CI account,
so `https://mirror.ci.ray.io` only resolves inside the Buildkite stack
VPCs.
`RAYCI_PYPI_MIRROR_URL` overrides the default for a fleet that runs its
own.

**Deliberately out of scope:** image builds still resolve from PyPI. The
`pip` and `uv`
invocations in `ci/docker/*.Dockerfile` run in a separate BuildKit
context that cannot
reach a proxy bound on the forge container's loopback, and a per-job
address would change
wanda's content-addressed cache key on every build and rebuild every
image. That needs a
build-reachable index, which is a follow-up.

`ci/pypi_index_proxy.py` is vendored from a public gist, recorded at the
top of the file
along with the one local edit (the default mirror URL).

## Testing

- `PYTHONPATH=.:release python -m pytest -q
ci/ray_ci/test_linux_tester_container.py
ci/ray_ci/test_container.py ci/ray_ci/test_tester.py
ci/ray_ci/test_linux_container.py
  ci/ray_ci/test_windows_container.py` — 24 passed.
- `bazel test //ci/raydepsets:test_cli` — passed, including
`test_diff_lock_files_up_to_date`, the generated-equals-committed
invariant for the
  deplock change.
- Bazel 7.5.0: verified that a valueless `common --repo_env=NAME`
reaches
`rctx.os.environ` in a repository rule and reads unset when the variable
is unset, and
  that `bazel info`/`query`/`version` do not reject the `common` lines.
- `docker run --env NAME` with NAME unset leaves it absent in the
container, not empty —
  which is what keeps the default path unchanged.
- The mechanism as a whole ran on premerge 72083 (on a superset branch):
the probe logged
its verdict, fell back to PyPI because that fleet has no route to the
mirror at the
  time, and the build proceeded.
- `pre-commit run --files` over every changed file, shellcheck included.

AI assistance (Claude Code) was used for this change.

---------

Signed-off-by: elliot-barn <[email protected]>
Signed-off-by: Elliot Barnwell <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

go add ONLY when ready to merge, run all tests stale The issue is stale. It will be closed within 7 days unless there are further conversation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant