Skip to content

[doc] Build Read the Docs incrementally from the doc build cache - #64277

Merged
edoakes merged 6 commits into
masterfrom
doc-1047-incremental-rtd-builds
Jun 24, 2026
Merged

edoakes merged 6 commits into
masterfrom
doc-1047-incremental-rtd-builds

Conversation

@ronny-anyscale

Copy link
Copy Markdown
Contributor

Description

PR preview builds on Read the Docs run a full cold Sphinx build every time — build logs show updating environment: [new config] 4048 added, 0 changed, 0 removed, i.e. the doctree is rebuilt from scratch on every preview.

This wires the existing doc build cache into the RTD build lifecycle so PR builds restore the latest master cache (https://ci.ray.io/ray/doc/build-cache/{commit}.tgz, populated by the Buildkite postmerge doc: build step) and rebuild only the files changed in the PR. No cache logic is reimplemented — it reuses doc/load_doc_cache.py + doc/update_cache_env.py, the same pipeline behind make local. Expected savings: ~2–4 min per preview build.

Changes

  • doc/Makefile
    • New rtd target: the incremental pipeline (load_doc_cache.py → update_cache_env.py → a one-shot sphinx-build without -a/-E so the restored environment is reused), instead of local's sphinx-autobuild.
    • HTMLDIR ?= $(BUILDDIR)/html: the html output dir is now overridable so RTD can target $READTHEDOCS_OUTPUT/html. The default is unchanged, so CI's make html and the cache upload (ci/ray_ci/doc/cmd_build.py) are untouched.
  • .readthedocs.yaml — override build.jobs.build.html:
    • PR (external) builds → make rtd, with a || make html fallback so a cache miss degrades to a clean build instead of failing the PR.
    • master / stable / release-tag builds → always a full clean build, so published output is never stale.

Related issues

Addresses DOC-1047 — Wire S3 doctree cache into RtD .readthedocs.yaml.

Additional information

Why override build.jobs.build.html rather than restore in post_install (the ticket's alternative): RTD's default Sphinx invocation chooses its own -d doctrees path, which does not match where the cache extracts (doc/_build/doctrees). Restoring in post_install and relying on the default build would silently miss the cache and rebuild everything. Overriding the build step lets us pin -d, the source dir, and the omission of -E/-a so the restored environment is actually reused. Confirmed via dry-run: sphinx-build … -d _build/doctrees … source $READTHEDOCS_OUTPUT/html.

Why PR-only incremental, clean for published: with sphinx.fail_on_warning: true, incremental builds don't re-emit warnings for un-rebuilt files and can carry subtly stale cross-page content — which is exactly why CI's make html uses -a -E. Previews trade a little staleness for speed; master/stable/tags stay clean.

Pickle compatibility: the cache pickle is built by CI's Sphinx; RTD installs from doc/requirements-doc.lock.txt. If versions ever diverge, Sphinx detects the env-version mismatch and safely falls back to a full rebuild (no corruption) — worst case is losing the speedup.

Verified locally: YAML parses, Makefile recipes/tabs, and exact command construction for all three paths (CI make html unchanged; PR rtd; clean fallback). The end-to-end network fetch and warm-build timing can only be confirmed on a live RTD preview — please check this PR's preview build log for N added, M changed (not 4048 added).

🤖 Generated with Claude Code

PR preview builds on Read the Docs currently run a full clean Sphinx
build every time. This wires the existing doc build cache (the same
artifacts `make local` uses) into the RTD build so PR builds restore the
latest master cache and rebuild only the files changed in the PR.

- doc/Makefile: add an `rtd` target that runs the incremental pipeline
  (load_doc_cache.py + update_cache_env.py, then a one-shot sphinx-build
  without -a/-E so the cached environment is reused). Make the html
  output directory overridable via HTMLDIR; the default is unchanged
  (_build/html), so CI's `make html` and the cache upload are untouched.
- .readthedocs.yaml: override build.jobs.build.html. On PR (external)
  builds run `make rtd`, falling back to a full build if no cache is
  available. On branch/tag builds (master, stable, release tags) always
  run a full clean build so published output is never stale.

Related to DOC-1047

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Signed-off-by: Ronny Roland <[email protected]>
@ronny-anyscale
ronny-anyscale requested a review from a team as a code owner June 23, 2026 13:41
Comment thread doc/Makefile Resolved

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces incremental documentation builds for Read the Docs PR previews by overriding the HTML build step in .readthedocs.yaml and adding a new rtd target in doc/Makefile. However, a critical correctness and efficiency issue was identified in the rtd target: writing the build output directly to $(HTMLDIR) (which starts empty) defeats the incremental build cache and causes missing pages. The reviewer suggested building to $(BUILDDIR)/html first and then copying the files to $(HTMLDIR) to ensure incremental builds function correctly.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread doc/Makefile Resolved
@ray-gardener ray-gardener Bot added docs An issue or change related to documentation core Issues that should be addressed in Ray Core labels Jun 23, 2026
ronny-anyscale and others added 4 commits June 23, 2026 08:02
Addresses PR review (Bugbot / Gemini): the rtd target built Sphinx output
directly into $(HTMLDIR) (= $READTHEDOCS_OUTPUT/html on RTD), but the
restored master cache extracts the full prior site into doc/_build/html and
update_cache_env.py refreshes the output timestamps there. An incremental
build into the empty RTD output dir therefore emits only the PR-changed
pages and drops the rest of the site.

Build into $(BUILDDIR)/html (matching `local` and the cache layout) so
Sphinx rewrites only the changed pages, then copy the whole tree to
$(HTMLDIR) when the two differ.

Related to DOC-1047

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Signed-off-by: Ronny Roland <[email protected]>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ 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 2657b7b. Configure here.

Comment thread doc/Makefile Resolved
…rnings

The RTD PR build failed under -W with 318 warnings. All of them were
duplicate-object / not-in-toctree errors from stale generated API stubs:
load_doc_cache.py restored a master cache predating the Sphinx 8.2.3
autosummary template change (#64070), so the tree carried orphan
per-member stubs (ray.job_submission.JobStatus.*, plus
rllib/data/tune/serve/train/core). Both the incremental build and the
old `make html` fallback failed, because the cache had already been
extracted onto disk and `make html` only cleans the serve stubs.

- rtd: drop --keep-going so an incompatible cache fails on the first
  warning and falls back quickly instead of grinding through the build.
- rtd-fallback: new target that runs `git clean -dfX .` (removes only
  git-ignored files -- the cache _build tree and all generated
  source/**/doc stubs, leaving tracked sources intact) then a full clean
  build. This matches the clean build postmerge CI produces and caches,
  so it is warning-free whenever master is green.
- .readthedocs.yaml: point the incremental fallback at rtd-fallback.

git clean is used rather than `make clean` because the clean target's
enumerated stub list can drift from the actual generated dirs (e.g. it
misses rllib/package_ref/env/doc); selecting by gitignore status stays
correct without maintenance.

Related to DOC-1047

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Signed-off-by: Ronny Roland <[email protected]>
@ronny-anyscale ronny-anyscale added the go add ONLY when ready to merge, run all tests label Jun 24, 2026

@dstrodtman dstrodtman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM. Let's just make sure that we track any potential regression around:

  • Preview fidelity
  • Incorrectly passing builds (can a build use cached files for generated API ref that should have been updated?)
  • Build time

I'm guessing this is all net-positive, but looks clean enough to tear back out if something breaks.

@edoakes
edoakes merged commit 179a440 into master Jun 24, 2026
4 checks passed
@edoakes
edoakes deleted the doc-1047-incremental-rtd-builds branch June 24, 2026 21:05
limarkdcunha pushed a commit to limarkdcunha/ray that referenced this pull request Jun 30, 2026
…-project#64277)

## Description

PR preview builds on Read the Docs run a full cold Sphinx build every
time — build logs show `updating environment: [new config] 4048 added, 0
changed, 0 removed`, i.e. the doctree is rebuilt from scratch on every
preview.

This wires the **existing** doc build cache into the RTD build lifecycle
so PR builds restore the latest master cache
(`https://ci.ray.io/ray/doc/build-cache/{commit}.tgz`, populated by the
Buildkite postmerge `doc: build` step) and rebuild **only the files
changed in the PR**. No cache logic is reimplemented — it reuses
`doc/load_doc_cache.py` + `doc/update_cache_env.py`, the same pipeline
behind `make local`. Expected savings: ~2–4 min per preview build.

### Changes

- **`doc/Makefile`**
- New `rtd` target: the incremental pipeline (`load_doc_cache.py` →
`update_cache_env.py` → a one-shot `sphinx-build` **without `-a/-E`** so
the restored environment is reused), instead of `local`'s
`sphinx-autobuild`.
- `HTMLDIR ?= $(BUILDDIR)/html`: the html output dir is now overridable
so RTD can target `$READTHEDOCS_OUTPUT/html`. The default is unchanged,
so CI's `make html` and the cache upload (`ci/ray_ci/doc/cmd_build.py`)
are untouched.
- **`.readthedocs.yaml`** — override `build.jobs.build.html`:
- PR (`external`) builds → `make rtd`, with a `|| make html` fallback so
a cache miss degrades to a clean build instead of failing the PR.
- master / stable / release-tag builds → always a full clean build, so
published output is never stale.

## Related issues

Addresses
**[DOC-1047](https://anyscale1.atlassian.net/browse/DOC-1047)** — Wire
S3 doctree cache into RtD `.readthedocs.yaml`.

## Additional information

**Why override `build.jobs.build.html` rather than restore in
`post_install`** (the ticket's alternative): RTD's default Sphinx
invocation chooses its own `-d` doctrees path, which does **not** match
where the cache extracts (`doc/_build/doctrees`). Restoring in
`post_install` and relying on the default build would silently miss the
cache and rebuild everything. Overriding the build step lets us pin
`-d`, the source dir, and the omission of `-E/-a` so the restored
environment is actually reused. Confirmed via dry-run: `sphinx-build …
-d _build/doctrees … source $READTHEDOCS_OUTPUT/html`.

**Why PR-only incremental, clean for published:** with
`sphinx.fail_on_warning: true`, incremental builds don't re-emit
warnings for un-rebuilt files and can carry subtly stale cross-page
content — which is exactly why CI's `make html` uses `-a -E`. Previews
trade a little staleness for speed; master/stable/tags stay clean.

**Pickle compatibility:** the cache pickle is built by CI's Sphinx; RTD
installs from `doc/requirements-doc.lock.txt`. If versions ever diverge,
Sphinx detects the env-version mismatch and safely falls back to a full
rebuild (no corruption) — worst case is losing the speedup.

**Verified locally:** YAML parses, Makefile recipes/tabs, and exact
command construction for all three paths (CI `make html` unchanged; PR
`rtd`; clean fallback). The end-to-end network fetch and warm-build
timing can only be confirmed on a live RTD preview — please check this
PR's preview build log for `N added, M changed` (not `4048 added`).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Signed-off-by: Ronny Roland <[email protected]>
Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
elliot-barn pushed a commit that referenced this pull request Jul 1, 2026
…uctural PRs (#64414)

## Description

Two related fixes that get the incremental Read the Docs build
(DOC-1047, #64277) actually working.

### 1. Repair the cache producer (`ci/ray_ci/doc/`)

The postmerge `doc: build` step has crashed on every run since the
Sphinx 8.2.3 upgrade (#64070), so **no doc build cache has been uploaded
since Jun 23**. `make html` builds the docs with the docbuild image's
Python (Sphinx 8.2.3) and writes `environment.pickle`, but
`_massage_cache` then unpickled it in-process under Bazel's pinned
Sphinx (6.2.1):

```
File ".../ci/ray_ci/doc/build_cache.py", line 50, in _massage_cache
    environment_cache = pickle.load(f)
ModuleNotFoundError: No module named 'sphinx.util._files'
```

(`sphinx.util._files` is new in Sphinx 8.x, so 6.2.1 can't load the
pickle.) → upload crashes → no cache. Without a fresh cache, RtD only
finds the last pre-upgrade (7.x) cache, rejects it as `build environment
version not current`, and rebuilds cold every time — so the incremental
path never engages.

**Fix:** run the pickle massage under the doc-build environment's Python
(`PYTHONPATH` unset), mirroring how `_build()` runs `make html`, so the
pickle is read by the same Sphinx that wrote it. Extracted into
`ci/ray_ci/doc/massage_cache.py` (stdlib-only) per review.

### 2. Skip the incremental build for structural PRs
(`.readthedocs.yaml`)

Incremental Sphinx doesn't delete output for sources removed/renamed in
a PR, and the restored cache carries generated stubs — so a structural
PR can leave stale pages in the preview. The fail-fast fallback only
catches cases that emit a `-W` warning; a clean rename/delete
(references updated) is silent. So if `git diff --diff-filter=D` finds
any removed/moved source under `doc/source/`, route straight to the
clean build (`rtd-fallback`). The proper prune-on-restore fix (so these
PRs can *use* the cache) is tracked in **DOC-1314**.

## Related issues

Related to
**[DOC-1047](https://anyscale1.atlassian.net/browse/DOC-1047)** (epic
[DOC-1046](https://anyscale1.atlassian.net/browse/DOC-1046)); unblocks
the incremental RtD builds added in #64277. Follow-up:
**[DOC-1314](https://anyscale1.atlassian.net/browse/DOC-1314)**.

## Additional information

- `ci/ray_ci/doc:test_build_cache` passes (3/3); `test_massage_cache`
exercises the real subprocess massage.
- The cache-upload path runs postmerge + master only, so change #1 is
fully verifiable only after merge — expected: the next postmerge
produces a Sphinx-8.2.3 cache that RtD then accepts.
- `.readthedocs.yaml` structural-detection uses `if ! git diff --quiet
--no-renames --diff-filter=D … 2>/dev/null` — the same shape as the
existing `post_checkout` step. An earlier `| grep` + `can't` version was
silently dropped by RTD's job-script preprocessor (the build step logged
`exit-code: None` and never ran), so the script now uses only constructs
already proven in `post_checkout`, with no in-script apostrophes or
pipes. Validated via YAML parse + `bash -n`.
- This bundles a `.readthedocs.yaml` (consumer) change with the `ci/`
(producer) fix at the author's request; happy to split if a reviewer
prefers.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Signed-off-by: Ronny Roland <[email protected]>
Signed-off-by: Ronny <[email protected]>
Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
richardliaw pushed a commit that referenced this pull request Jul 1, 2026
## Description

The `post_checkout` skip-guard in `.readthedocs.yaml` (added in #64277)
skips the RtD Sphinx build on PRs that touch no doc-affecting files. It
keys on a coarse pathspec:

```
git diff --quiet origin/master...HEAD -- doc/ python/ray/ rllib/ .readthedocs.yaml
```

Because it matches all of `doc/`, a PR whose only changes are under
`doc/.claude/` (Claude Code skills and agent files) counts as
doc-affecting and runs a full Sphinx build — even though those files
never participate in the build, which globs from `doc/source/`.

This surfaced on #64147 (the entire diff was under
`doc/.claude/skills/**` plus `.pre-commit-config.yaml`), which should
have been a no-op for RtD but ran a full build. While the doc build
cache was unavailable (from the Sphinx 8.2.3 upgrade until #64414), that
full build was a cold clean build that repeatedly timed out the RtD
check. A correctly-scoped guard skips the build entirely and sidesteps
the timeouts regardless of cache health.

This PR adds a `':(exclude)doc/.claude/'` git exclude pathspec to the
guard's `git diff` and to the doc-affecting-paths echo just below it, so
a PR touching only those paths skips the build. Both stay on single
lines with no backslash escapes, so RtD's job-runner preprocessor (which
silently drops scripts containing certain constructs) preserves the
script.

Verified locally: a staged change under only `doc/.claude/` makes `git
diff --quiet ...` return true (skip), while a change under `doc/source/`
still returns false (build).

## Related issues

Related to #64277, #64414.

## Additional information

The excluded set is intentionally conservative — `doc/.claude/` is the
clear build-irrelevant case today. A false skip would publish stale
output, so other non-source paths were left in scope.

---------

Signed-off-by: Douglas Strodtman <[email protected]>
Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
elliot-barn pushed a commit that referenced this pull request Jul 1, 2026
#64482)

## Description

Fixes the **consumer** side of the incremental Read the Docs build.
`find_latest_master_commit()` never finds the doc cache, so every PR
preview falls through to a full cold build — chronically near the RtD
time limit, and timing out when the full build runs slow.

### Root cause

`find_latest_master_commit()` (`doc/load_doc_cache.py`) ran `git log`
with **no ref** — i.e. against `HEAD`. But Read the Docs checks out PRs
with `git clone --depth 1`, so `HEAD`'s history is grafted: the walk
sees ~1 commit and never probes a real master commit. `post_checkout`
deepens `origin/master` to 500 commits, but the consumer looked at
`HEAD`, not `origin/master` — the two never meet. So `load_doc_cache.py`
always raises `No cache found for latest master commit`, `make rtd`
fails, and `|| make rtd-fallback` does a full `git clean` + cold Sphinx
build (~3,967 sources) on every build.

This is independent of the producer: even after #64414 repaired cache
production (caches are flowing again — e.g. `0c1f570a8bf1`,
`5612883ea63f` serve 200 today), the consumer still couldn't reach them.
It also explains why *merging master didn't help* affected PRs — the
shallow graft means `git log HEAD` never reaches a merged-in cached
commit either.

### Fix

Walk `origin/master` — the ref `post_checkout` already deepened —
instead of `HEAD`. Falls back to `HEAD` when `origin/master` isn't
available (e.g. a local checkout without that remote-tracking ref), and
the existing `|| make rtd-fallback` still covers a genuine cache miss.

### Verified

Ran the modified `find_latest_master_commit()` against the live cache:
it returns `0c1f570a8bf1` (a real cached master commit) where the old
`HEAD` walk returned nothing usable. `ruff` + `black` clean.

## Related issues

Consumer side of the incremental RtD build (**#64277**); producer
repaired in **#64414**. Related to
**[DOC-1047](https://anyscale1.atlassian.net/browse/DOC-1047)** (epic
DOC-1046).

## Additional information

Credit to the reviewer who pinpointed the shallow-`HEAD` / wrong-ref
root cause. This is only fully exercised on a real RtD PR build (the
`--depth 1` clone + `post_checkout` deepen), so worth confirming on this
PR's own preview that it logs `Use build cache for commit …` and an
incremental `N changed` instead of `3967 added, 0 changed`.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Signed-off-by: Ronny Roland <[email protected]>
Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
edoakes pushed a commit that referenced this pull request Jul 8, 2026
…4599)

## Why

The incremental RtD PR-preview build (added in #64277) isn't paying off,
and a clean build is faster and lower-variance in practice. Opening as a
draft for @ronny-anyscale to review, since this is your workstream.

Present-state evidence from read-only RtD build logs (project
`anyscale-ray`, 2026-07-08):

- Every PR preview downloads the master doctree cache successfully, then
Sphinx discards all of it and rebuilds every document:
  ```
  Use build cache for commit 1319e11...
updating environment: [config changed ('intersphinx_mapping')] 3968
added, 1 changed, 0 removed
  ```
`3968 added` = full rebuild. The discard reason has moved from `[new
config]` (the version-skew fixed by #64414/#64482) to `[config changed
('intersphinx_mapping')]` / `[config changed ('llms_txt_exclude')]` — a
config value that differs between the postmerge cache producer and the
RtD build environment.
- So the cache download and extract are pure overhead, and when the
incremental leg trips a warning the build does a second full clean build
(near 2× wall-clock).
- Measured: clean full builds land at ~7–9 min (master builds 418–525s),
faster than most PR "incremental" builds (466–1195s, median ~640s).
Turning the incremental leg off reduces both wall-clock and shared-slot
queue pressure versus today.

## What this changes

Collapses the `build.jobs.build.html` override so every build — PR
previews and branch/tag builds alike — runs a full clean `make -C doc
html`. The `rtd` / `rtd-fallback` Makefile targets and
`doc/load_doc_cache.py` stay in the tree so the incremental path can be
re-enabled later.

## Re-enable criteria (not in this PR)

1. Cache reuse actually works — a PR preview logs `N changed` rather
than `NNNN added` — which needs the config-determinism gap closed
(`intersphinx_mapping`, `llms_txt_exclude`, and any other env-signature
config that differs between producer and RtD).
2. Stale-artifact pruning lands for PRs that rename/delete sources, so
incremental previews don't publish stale pages.

The `post_checkout` skip guard (skip PR builds that don't touch
doc-affecting files) is unchanged — it's orthogonal and still valuable.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Signed-off-by: Douglas Strodtman <[email protected]>
elliot-barn pushed a commit that referenced this pull request Jul 9, 2026
…uctural PRs (#64414)

## Description

Two related fixes that get the incremental Read the Docs build
(DOC-1047, #64277) actually working.

### 1. Repair the cache producer (`ci/ray_ci/doc/`)

The postmerge `doc: build` step has crashed on every run since the
Sphinx 8.2.3 upgrade (#64070), so **no doc build cache has been uploaded
since Jun 23**. `make html` builds the docs with the docbuild image's
Python (Sphinx 8.2.3) and writes `environment.pickle`, but
`_massage_cache` then unpickled it in-process under Bazel's pinned
Sphinx (6.2.1):

```
File ".../ci/ray_ci/doc/build_cache.py", line 50, in _massage_cache
    environment_cache = pickle.load(f)
ModuleNotFoundError: No module named 'sphinx.util._files'
```

(`sphinx.util._files` is new in Sphinx 8.x, so 6.2.1 can't load the
pickle.) → upload crashes → no cache. Without a fresh cache, RtD only
finds the last pre-upgrade (7.x) cache, rejects it as `build environment
version not current`, and rebuilds cold every time — so the incremental
path never engages.

**Fix:** run the pickle massage under the doc-build environment's Python
(`PYTHONPATH` unset), mirroring how `_build()` runs `make html`, so the
pickle is read by the same Sphinx that wrote it. Extracted into
`ci/ray_ci/doc/massage_cache.py` (stdlib-only) per review.

### 2. Skip the incremental build for structural PRs
(`.readthedocs.yaml`)

Incremental Sphinx doesn't delete output for sources removed/renamed in
a PR, and the restored cache carries generated stubs — so a structural
PR can leave stale pages in the preview. The fail-fast fallback only
catches cases that emit a `-W` warning; a clean rename/delete
(references updated) is silent. So if `git diff --diff-filter=D` finds
any removed/moved source under `doc/source/`, route straight to the
clean build (`rtd-fallback`). The proper prune-on-restore fix (so these
PRs can *use* the cache) is tracked in **DOC-1314**.

## Related issues

Related to
**[DOC-1047](https://anyscale1.atlassian.net/browse/DOC-1047)** (epic
[DOC-1046](https://anyscale1.atlassian.net/browse/DOC-1046)); unblocks
the incremental RtD builds added in #64277. Follow-up:
**[DOC-1314](https://anyscale1.atlassian.net/browse/DOC-1314)**.

## Additional information

- `ci/ray_ci/doc:test_build_cache` passes (3/3); `test_massage_cache`
exercises the real subprocess massage.
- The cache-upload path runs postmerge + master only, so change #1 is
fully verifiable only after merge — expected: the next postmerge
produces a Sphinx-8.2.3 cache that RtD then accepts.
- `.readthedocs.yaml` structural-detection uses `if ! git diff --quiet
--no-renames --diff-filter=D … 2>/dev/null` — the same shape as the
existing `post_checkout` step. An earlier `| grep` + `can't` version was
silently dropped by RTD's job-script preprocessor (the build step logged
`exit-code: None` and never ran), so the script now uses only constructs
already proven in `post_checkout`, with no in-script apostrophes or
pipes. Validated via YAML parse + `bash -n`.
- This bundles a `.readthedocs.yaml` (consumer) change with the `ci/`
(producer) fix at the author's request; happy to split if a reviewer
prefers.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Signed-off-by: Ronny Roland <[email protected]>
Signed-off-by: Ronny <[email protected]>
Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
Signed-off-by: elliot-barn <[email protected]>
elliot-barn pushed a commit that referenced this pull request Jul 9, 2026
## Description

The `post_checkout` skip-guard in `.readthedocs.yaml` (added in #64277)
skips the RtD Sphinx build on PRs that touch no doc-affecting files. It
keys on a coarse pathspec:

```
git diff --quiet origin/master...HEAD -- doc/ python/ray/ rllib/ .readthedocs.yaml
```

Because it matches all of `doc/`, a PR whose only changes are under
`doc/.claude/` (Claude Code skills and agent files) counts as
doc-affecting and runs a full Sphinx build — even though those files
never participate in the build, which globs from `doc/source/`.

This surfaced on #64147 (the entire diff was under
`doc/.claude/skills/**` plus `.pre-commit-config.yaml`), which should
have been a no-op for RtD but ran a full build. While the doc build
cache was unavailable (from the Sphinx 8.2.3 upgrade until #64414), that
full build was a cold clean build that repeatedly timed out the RtD
check. A correctly-scoped guard skips the build entirely and sidesteps
the timeouts regardless of cache health.

This PR adds a `':(exclude)doc/.claude/'` git exclude pathspec to the
guard's `git diff` and to the doc-affecting-paths echo just below it, so
a PR touching only those paths skips the build. Both stay on single
lines with no backslash escapes, so RtD's job-runner preprocessor (which
silently drops scripts containing certain constructs) preserves the
script.

Verified locally: a staged change under only `doc/.claude/` makes `git
diff --quiet ...` return true (skip), while a change under `doc/source/`
still returns false (build).

## Related issues

Related to #64277, #64414.

## Additional information

The excluded set is intentionally conservative — `doc/.claude/` is the
clear build-irrelevant case today. A false skip would publish stale
output, so other non-source paths were left in scope.

---------

Signed-off-by: Douglas Strodtman <[email protected]>
Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
Signed-off-by: elliot-barn <[email protected]>
elliot-barn pushed a commit that referenced this pull request Jul 9, 2026
#64482)

## Description

Fixes the **consumer** side of the incremental Read the Docs build.
`find_latest_master_commit()` never finds the doc cache, so every PR
preview falls through to a full cold build — chronically near the RtD
time limit, and timing out when the full build runs slow.

### Root cause

`find_latest_master_commit()` (`doc/load_doc_cache.py`) ran `git log`
with **no ref** — i.e. against `HEAD`. But Read the Docs checks out PRs
with `git clone --depth 1`, so `HEAD`'s history is grafted: the walk
sees ~1 commit and never probes a real master commit. `post_checkout`
deepens `origin/master` to 500 commits, but the consumer looked at
`HEAD`, not `origin/master` — the two never meet. So `load_doc_cache.py`
always raises `No cache found for latest master commit`, `make rtd`
fails, and `|| make rtd-fallback` does a full `git clean` + cold Sphinx
build (~3,967 sources) on every build.

This is independent of the producer: even after #64414 repaired cache
production (caches are flowing again — e.g. `0c1f570a8bf1`,
`5612883ea63f` serve 200 today), the consumer still couldn't reach them.
It also explains why *merging master didn't help* affected PRs — the
shallow graft means `git log HEAD` never reaches a merged-in cached
commit either.

### Fix

Walk `origin/master` — the ref `post_checkout` already deepened —
instead of `HEAD`. Falls back to `HEAD` when `origin/master` isn't
available (e.g. a local checkout without that remote-tracking ref), and
the existing `|| make rtd-fallback` still covers a genuine cache miss.

### Verified

Ran the modified `find_latest_master_commit()` against the live cache:
it returns `0c1f570a8bf1` (a real cached master commit) where the old
`HEAD` walk returned nothing usable. `ruff` + `black` clean.

## Related issues

Consumer side of the incremental RtD build (**#64277**); producer
repaired in **#64414**. Related to
**[DOC-1047](https://anyscale1.atlassian.net/browse/DOC-1047)** (epic
DOC-1046).

## Additional information

Credit to the reviewer who pinpointed the shallow-`HEAD` / wrong-ref
root cause. This is only fully exercised on a real RtD PR build (the
`--depth 1` clone + `post_checkout` deepen), so worth confirming on this
PR's own preview that it logs `Use build cache for commit …` and an
incremental `N changed` instead of `3967 added, 0 changed`.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Signed-off-by: Ronny Roland <[email protected]>
Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
Signed-off-by: elliot-barn <[email protected]>
dstrodtman added a commit that referenced this pull request Aug 14, 2026
…65391)

## Why this change

`ci/ray_ci/doc/` holds the documentation site build and the
API-reference guards, but there's no orientation for anyone opening it.
Nine modules, three of which are entry points, and the wiring that
decides which is which lives in three other files
(`.buildkite/doc.rayci.yml`, `.buildkite/lint.rayci.yml`,
`ci/lint/lint.sh`). Reading the directory alone gives you the wrong
model of it.

The same is true one level up: `doc.rayci.yml` opens straight at `group:
doc` with no statement of what the pipeline does, and the two rules
files that decide what CI runs for *every* PR in the repo don't say
anywhere that that's what they do.

This PR is descriptive only. No step, rule, tag, or target changes
behavior.

## What's here

**New `ci/ray_ci/doc/README.md`.** What each entry point does and where
it's invoked from, what the shared libraries contribute, and two things
the layout actively misleads on:

- `cmd_check_api_discrepancy` and `cmd_check_api_param_coverage` have
`py_binary` targets but don't run through Bazel in CI. `lint.sh` invokes
them with the docbuild image's interpreter, because the Bazel targets
resolve `@py_deps_py310` wheels that can't import under the py3.11
docbuild image. There's already a `TODO(elliot-barn)` on #64070 to undo
this once hermetic py3.11 lands.
- The `doc: check API annotations` step isn't this package at all — it
runs `ci/lint/check_api_annotations.py`. Easy to assume otherwise, since
it sits next to `doc: check API doc consistency`, which *is* this
package.

**Header comment on `.buildkite/doc.rayci.yml`** listing the steps in
order and what each is for, and noting that tag rules, not this file,
decide what runs on a given PR.

**Scope notes on `.buildkite/test.rules.txt` and `always.rules.txt`.**
Both decide what CI runs for every pull request in the repository, so an
edit is a repo-wide change rather than a local one. The note also
records that rules are first-match-wins in file order, which makes rule
*position* as load-bearing as rule content, and points at the in-repo
check to run.

**Two removals.**

- `ci/ray_ci/doc/test_update_cache_env.py` imports
`ci.ray_ci.doc.cmd_update_cache_env`, which was deleted in #47233 (Aug
2024). The test was added later, in #64277, so it has never been able to
import since the day it landed. It also has no `py_test` target, which
is why nothing ran it and nothing reported it was broken.
- A stale cross-repo pointer in the `api_param_coverage` module
docstring, referencing a path outside this repository that readers here
can't follow. The paragraphs above it already describe the check's
scope, so nothing is lost.

## Not a duplicate

Checked open PRs for the touched areas per `AGENTS.md`:

```
gh pr list --repo ray-project/ray --state open --search "ray_ci/doc README"
gh pr list --repo ray-project/ray --state open --search "test_update_cache_env"
gh pr list --repo ray-project/ray --state open --search "test.rules.txt header comment"
```

No open PR adds a README here, touches the dead test, or comments these
files. Two PRs matched the third search on body text only (#65342,
#64977); I confirmed against their file lists that neither touches
`doc.rayci.yml`, `test.rules.txt`, or `always.rules.txt`. #65211 touches
`ci/ray_ci/doc/api.py`, a different file in the same directory, and
doesn't conflict.

## Testing

```
bazel test //ci/pipeline:test_doc_api_rules_sync //ci/ray_ci/doc/...
```

7/7 pass (`test_doc_api_rules_sync`, `test_api`,
`test_api_param_coverage`, `test_autodoc`, `test_build_cache`,
`test_cmd_check_api_discrepancy`, `test_module`).

Because the comments land on rule files, I also confirmed the rules
still parse and emit identical tags, loading both files through
`ci/pipeline/determine_tests_to_run.py` and comparing `match_tags`
output before and after. Comments are ignored by the parser and nothing
moved. `pre-commit run` passes on every changed file.

## AI assistance

This change was written with AI assistance. I reviewed every line, ran
the tests above myself, and can defend the change end-to-end. Every
technical claim in the added comments was verified against the source
rather than inferred: the invocation paths from `lint.sh` and the
pipeline YAML, the first-match-wins ordering from
`TagRuleSet.match_tags`, and the dead import from `git log` on the
deleted module plus a direct import attempt.

---------

Signed-off-by: Douglas Strodtman <[email protected]>
400Ping pushed a commit to 400Ping/ray that referenced this pull request Aug 18, 2026
…-project#64277)

## Description

PR preview builds on Read the Docs run a full cold Sphinx build every
time — build logs show `updating environment: [new config] 4048 added, 0
changed, 0 removed`, i.e. the doctree is rebuilt from scratch on every
preview.

This wires the **existing** doc build cache into the RTD build lifecycle
so PR builds restore the latest master cache
(`https://ci.ray.io/ray/doc/build-cache/{commit}.tgz`, populated by the
Buildkite postmerge `doc: build` step) and rebuild **only the files
changed in the PR**. No cache logic is reimplemented — it reuses
`doc/load_doc_cache.py` + `doc/update_cache_env.py`, the same pipeline
behind `make local`. Expected savings: ~2–4 min per preview build.

### Changes

- **`doc/Makefile`**
- New `rtd` target: the incremental pipeline (`load_doc_cache.py` →
`update_cache_env.py` → a one-shot `sphinx-build` **without `-a/-E`** so
the restored environment is reused), instead of `local`'s
`sphinx-autobuild`.
- `HTMLDIR ?= $(BUILDDIR)/html`: the html output dir is now overridable
so RTD can target `$READTHEDOCS_OUTPUT/html`. The default is unchanged,
so CI's `make html` and the cache upload (`ci/ray_ci/doc/cmd_build.py`)
are untouched.
- **`.readthedocs.yaml`** — override `build.jobs.build.html`:
- PR (`external`) builds → `make rtd`, with a `|| make html` fallback so
a cache miss degrades to a clean build instead of failing the PR.
- master / stable / release-tag builds → always a full clean build, so
published output is never stale.

## Related issues

Addresses
**[DOC-1047](https://anyscale1.atlassian.net/browse/DOC-1047)** — Wire
S3 doctree cache into RtD `.readthedocs.yaml`.

## Additional information

**Why override `build.jobs.build.html` rather than restore in
`post_install`** (the ticket's alternative): RTD's default Sphinx
invocation chooses its own `-d` doctrees path, which does **not** match
where the cache extracts (`doc/_build/doctrees`). Restoring in
`post_install` and relying on the default build would silently miss the
cache and rebuild everything. Overriding the build step lets us pin
`-d`, the source dir, and the omission of `-E/-a` so the restored
environment is actually reused. Confirmed via dry-run: `sphinx-build …
-d _build/doctrees … source $READTHEDOCS_OUTPUT/html`.

**Why PR-only incremental, clean for published:** with
`sphinx.fail_on_warning: true`, incremental builds don't re-emit
warnings for un-rebuilt files and can carry subtly stale cross-page
content — which is exactly why CI's `make html` uses `-a -E`. Previews
trade a little staleness for speed; master/stable/tags stay clean.

**Pickle compatibility:** the cache pickle is built by CI's Sphinx; RTD
installs from `doc/requirements-doc.lock.txt`. If versions ever diverge,
Sphinx detects the env-version mismatch and safely falls back to a full
rebuild (no corruption) — worst case is losing the speedup.

**Verified locally:** YAML parses, Makefile recipes/tabs, and exact
command construction for all three paths (CI `make html` unchanged; PR
`rtd`; clean fallback). The end-to-end network fetch and warm-build
timing can only be confirmed on a live RTD preview — please check this
PR's preview build log for `N added, M changed` (not `4048 added`).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Signed-off-by: Ronny Roland <[email protected]>
Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
Signed-off-by: 400Ping <[email protected]>
400Ping pushed a commit to 400Ping/ray that referenced this pull request Aug 18, 2026
…uctural PRs (ray-project#64414)

## Description

Two related fixes that get the incremental Read the Docs build
(DOC-1047, ray-project#64277) actually working.

### 1. Repair the cache producer (`ci/ray_ci/doc/`)

The postmerge `doc: build` step has crashed on every run since the
Sphinx 8.2.3 upgrade (ray-project#64070), so **no doc build cache has been uploaded
since Jun 23**. `make html` builds the docs with the docbuild image's
Python (Sphinx 8.2.3) and writes `environment.pickle`, but
`_massage_cache` then unpickled it in-process under Bazel's pinned
Sphinx (6.2.1):

```
File ".../ci/ray_ci/doc/build_cache.py", line 50, in _massage_cache
    environment_cache = pickle.load(f)
ModuleNotFoundError: No module named 'sphinx.util._files'
```

(`sphinx.util._files` is new in Sphinx 8.x, so 6.2.1 can't load the
pickle.) → upload crashes → no cache. Without a fresh cache, RtD only
finds the last pre-upgrade (7.x) cache, rejects it as `build environment
version not current`, and rebuilds cold every time — so the incremental
path never engages.

**Fix:** run the pickle massage under the doc-build environment's Python
(`PYTHONPATH` unset), mirroring how `_build()` runs `make html`, so the
pickle is read by the same Sphinx that wrote it. Extracted into
`ci/ray_ci/doc/massage_cache.py` (stdlib-only) per review.

### 2. Skip the incremental build for structural PRs
(`.readthedocs.yaml`)

Incremental Sphinx doesn't delete output for sources removed/renamed in
a PR, and the restored cache carries generated stubs — so a structural
PR can leave stale pages in the preview. The fail-fast fallback only
catches cases that emit a `-W` warning; a clean rename/delete
(references updated) is silent. So if `git diff --diff-filter=D` finds
any removed/moved source under `doc/source/`, route straight to the
clean build (`rtd-fallback`). The proper prune-on-restore fix (so these
PRs can *use* the cache) is tracked in **DOC-1314**.

## Related issues

Related to
**[DOC-1047](https://anyscale1.atlassian.net/browse/DOC-1047)** (epic
[DOC-1046](https://anyscale1.atlassian.net/browse/DOC-1046)); unblocks
the incremental RtD builds added in ray-project#64277. Follow-up:
**[DOC-1314](https://anyscale1.atlassian.net/browse/DOC-1314)**.

## Additional information

- `ci/ray_ci/doc:test_build_cache` passes (3/3); `test_massage_cache`
exercises the real subprocess massage.
- The cache-upload path runs postmerge + master only, so change #1 is
fully verifiable only after merge — expected: the next postmerge
produces a Sphinx-8.2.3 cache that RtD then accepts.
- `.readthedocs.yaml` structural-detection uses `if ! git diff --quiet
--no-renames --diff-filter=D … 2>/dev/null` — the same shape as the
existing `post_checkout` step. An earlier `| grep` + `can't` version was
silently dropped by RTD's job-script preprocessor (the build step logged
`exit-code: None` and never ran), so the script now uses only constructs
already proven in `post_checkout`, with no in-script apostrophes or
pipes. Validated via YAML parse + `bash -n`.
- This bundles a `.readthedocs.yaml` (consumer) change with the `ci/`
(producer) fix at the author's request; happy to split if a reviewer
prefers.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Signed-off-by: Ronny Roland <[email protected]>
Signed-off-by: Ronny <[email protected]>
Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
Signed-off-by: 400Ping <[email protected]>
400Ping pushed a commit to 400Ping/ray that referenced this pull request Aug 18, 2026
…4480)

## Description

The `post_checkout` skip-guard in `.readthedocs.yaml` (added in ray-project#64277)
skips the RtD Sphinx build on PRs that touch no doc-affecting files. It
keys on a coarse pathspec:

```
git diff --quiet origin/master...HEAD -- doc/ python/ray/ rllib/ .readthedocs.yaml
```

Because it matches all of `doc/`, a PR whose only changes are under
`doc/.claude/` (Claude Code skills and agent files) counts as
doc-affecting and runs a full Sphinx build — even though those files
never participate in the build, which globs from `doc/source/`.

This surfaced on ray-project#64147 (the entire diff was under
`doc/.claude/skills/**` plus `.pre-commit-config.yaml`), which should
have been a no-op for RtD but ran a full build. While the doc build
cache was unavailable (from the Sphinx 8.2.3 upgrade until ray-project#64414), that
full build was a cold clean build that repeatedly timed out the RtD
check. A correctly-scoped guard skips the build entirely and sidesteps
the timeouts regardless of cache health.

This PR adds a `':(exclude)doc/.claude/'` git exclude pathspec to the
guard's `git diff` and to the doc-affecting-paths echo just below it, so
a PR touching only those paths skips the build. Both stay on single
lines with no backslash escapes, so RtD's job-runner preprocessor (which
silently drops scripts containing certain constructs) preserves the
script.

Verified locally: a staged change under only `doc/.claude/` makes `git
diff --quiet ...` return true (skip), while a change under `doc/source/`
still returns false (build).

## Related issues

Related to ray-project#64277, ray-project#64414.

## Additional information

The excluded set is intentionally conservative — `doc/.claude/` is the
clear build-irrelevant case today. A false skip would publish stale
output, so other non-source paths were left in scope.

---------

Signed-off-by: Douglas Strodtman <[email protected]>
Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
Signed-off-by: 400Ping <[email protected]>
400Ping pushed a commit to 400Ping/ray that referenced this pull request Aug 18, 2026
ray-project#64482)

## Description

Fixes the **consumer** side of the incremental Read the Docs build.
`find_latest_master_commit()` never finds the doc cache, so every PR
preview falls through to a full cold build — chronically near the RtD
time limit, and timing out when the full build runs slow.

### Root cause

`find_latest_master_commit()` (`doc/load_doc_cache.py`) ran `git log`
with **no ref** — i.e. against `HEAD`. But Read the Docs checks out PRs
with `git clone --depth 1`, so `HEAD`'s history is grafted: the walk
sees ~1 commit and never probes a real master commit. `post_checkout`
deepens `origin/master` to 500 commits, but the consumer looked at
`HEAD`, not `origin/master` — the two never meet. So `load_doc_cache.py`
always raises `No cache found for latest master commit`, `make rtd`
fails, and `|| make rtd-fallback` does a full `git clean` + cold Sphinx
build (~3,967 sources) on every build.

This is independent of the producer: even after ray-project#64414 repaired cache
production (caches are flowing again — e.g. `0c1f570a8bf1`,
`5612883ea63f` serve 200 today), the consumer still couldn't reach them.
It also explains why *merging master didn't help* affected PRs — the
shallow graft means `git log HEAD` never reaches a merged-in cached
commit either.

### Fix

Walk `origin/master` — the ref `post_checkout` already deepened —
instead of `HEAD`. Falls back to `HEAD` when `origin/master` isn't
available (e.g. a local checkout without that remote-tracking ref), and
the existing `|| make rtd-fallback` still covers a genuine cache miss.

### Verified

Ran the modified `find_latest_master_commit()` against the live cache:
it returns `0c1f570a8bf1` (a real cached master commit) where the old
`HEAD` walk returned nothing usable. `ruff` + `black` clean.

## Related issues

Consumer side of the incremental RtD build (**ray-project#64277**); producer
repaired in **ray-project#64414**. Related to
**[DOC-1047](https://anyscale1.atlassian.net/browse/DOC-1047)** (epic
DOC-1046).

## Additional information

Credit to the reviewer who pinpointed the shallow-`HEAD` / wrong-ref
root cause. This is only fully exercised on a real RtD PR build (the
`--depth 1` clone + `post_checkout` deepen), so worth confirming on this
PR's own preview that it logs `Use build cache for commit …` and an
incremental `N changed` instead of `3967 added, 0 changed`.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Signed-off-by: Ronny Roland <[email protected]>
Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
Signed-off-by: 400Ping <[email protected]>
400Ping pushed a commit to 400Ping/ray that referenced this pull request Aug 18, 2026
…y-project#64599)

## Why

The incremental RtD PR-preview build (added in ray-project#64277) isn't paying off,
and a clean build is faster and lower-variance in practice. Opening as a
draft for @ronny-anyscale to review, since this is your workstream.

Present-state evidence from read-only RtD build logs (project
`anyscale-ray`, 2026-07-08):

- Every PR preview downloads the master doctree cache successfully, then
Sphinx discards all of it and rebuilds every document:
  ```
  Use build cache for commit 1319e11...
updating environment: [config changed ('intersphinx_mapping')] 3968
added, 1 changed, 0 removed
  ```
`3968 added` = full rebuild. The discard reason has moved from `[new
config]` (the version-skew fixed by ray-project#64414/ray-project#64482) to `[config changed
('intersphinx_mapping')]` / `[config changed ('llms_txt_exclude')]` — a
config value that differs between the postmerge cache producer and the
RtD build environment.
- So the cache download and extract are pure overhead, and when the
incremental leg trips a warning the build does a second full clean build
(near 2× wall-clock).
- Measured: clean full builds land at ~7–9 min (master builds 418–525s),
faster than most PR "incremental" builds (466–1195s, median ~640s).
Turning the incremental leg off reduces both wall-clock and shared-slot
queue pressure versus today.

## What this changes

Collapses the `build.jobs.build.html` override so every build — PR
previews and branch/tag builds alike — runs a full clean `make -C doc
html`. The `rtd` / `rtd-fallback` Makefile targets and
`doc/load_doc_cache.py` stay in the tree so the incremental path can be
re-enabled later.

## Re-enable criteria (not in this PR)

1. Cache reuse actually works — a PR preview logs `N changed` rather
than `NNNN added` — which needs the config-determinism gap closed
(`intersphinx_mapping`, `llms_txt_exclude`, and any other env-signature
config that differs between producer and RtD).
2. Stale-artifact pruning lands for PRs that rename/delete sources, so
incremental previews don't publish stale pages.

The `post_checkout` skip guard (skip PR builds that don't touch
doc-affecting files) is unchanged — it's orthogonal and still valuable.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Signed-off-by: Douglas Strodtman <[email protected]>
Signed-off-by: 400Ping <[email protected]>
400Ping pushed a commit to 400Ping/ray that referenced this pull request Aug 18, 2026
…ay-project#65391)

## Why this change

`ci/ray_ci/doc/` holds the documentation site build and the
API-reference guards, but there's no orientation for anyone opening it.
Nine modules, three of which are entry points, and the wiring that
decides which is which lives in three other files
(`.buildkite/doc.rayci.yml`, `.buildkite/lint.rayci.yml`,
`ci/lint/lint.sh`). Reading the directory alone gives you the wrong
model of it.

The same is true one level up: `doc.rayci.yml` opens straight at `group:
doc` with no statement of what the pipeline does, and the two rules
files that decide what CI runs for *every* PR in the repo don't say
anywhere that that's what they do.

This PR is descriptive only. No step, rule, tag, or target changes
behavior.

## What's here

**New `ci/ray_ci/doc/README.md`.** What each entry point does and where
it's invoked from, what the shared libraries contribute, and two things
the layout actively misleads on:

- `cmd_check_api_discrepancy` and `cmd_check_api_param_coverage` have
`py_binary` targets but don't run through Bazel in CI. `lint.sh` invokes
them with the docbuild image's interpreter, because the Bazel targets
resolve `@py_deps_py310` wheels that can't import under the py3.11
docbuild image. There's already a `TODO(elliot-barn)` on ray-project#64070 to undo
this once hermetic py3.11 lands.
- The `doc: check API annotations` step isn't this package at all — it
runs `ci/lint/check_api_annotations.py`. Easy to assume otherwise, since
it sits next to `doc: check API doc consistency`, which *is* this
package.

**Header comment on `.buildkite/doc.rayci.yml`** listing the steps in
order and what each is for, and noting that tag rules, not this file,
decide what runs on a given PR.

**Scope notes on `.buildkite/test.rules.txt` and `always.rules.txt`.**
Both decide what CI runs for every pull request in the repository, so an
edit is a repo-wide change rather than a local one. The note also
records that rules are first-match-wins in file order, which makes rule
*position* as load-bearing as rule content, and points at the in-repo
check to run.

**Two removals.**

- `ci/ray_ci/doc/test_update_cache_env.py` imports
`ci.ray_ci.doc.cmd_update_cache_env`, which was deleted in ray-project#47233 (Aug
2024). The test was added later, in ray-project#64277, so it has never been able to
import since the day it landed. It also has no `py_test` target, which
is why nothing ran it and nothing reported it was broken.
- A stale cross-repo pointer in the `api_param_coverage` module
docstring, referencing a path outside this repository that readers here
can't follow. The paragraphs above it already describe the check's
scope, so nothing is lost.

## Not a duplicate

Checked open PRs for the touched areas per `AGENTS.md`:

```
gh pr list --repo ray-project/ray --state open --search "ray_ci/doc README"
gh pr list --repo ray-project/ray --state open --search "test_update_cache_env"
gh pr list --repo ray-project/ray --state open --search "test.rules.txt header comment"
```

No open PR adds a README here, touches the dead test, or comments these
files. Two PRs matched the third search on body text only (ray-project#65342,
ray-project#64977); I confirmed against their file lists that neither touches
`doc.rayci.yml`, `test.rules.txt`, or `always.rules.txt`. ray-project#65211 touches
`ci/ray_ci/doc/api.py`, a different file in the same directory, and
doesn't conflict.

## Testing

```
bazel test //ci/pipeline:test_doc_api_rules_sync //ci/ray_ci/doc/...
```

7/7 pass (`test_doc_api_rules_sync`, `test_api`,
`test_api_param_coverage`, `test_autodoc`, `test_build_cache`,
`test_cmd_check_api_discrepancy`, `test_module`).

Because the comments land on rule files, I also confirmed the rules
still parse and emit identical tags, loading both files through
`ci/pipeline/determine_tests_to_run.py` and comparing `match_tags`
output before and after. Comments are ignored by the parser and nothing
moved. `pre-commit run` passes on every changed file.

## AI assistance

This change was written with AI assistance. I reviewed every line, ran
the tests above myself, and can defend the change end-to-end. Every
technical claim in the added comments was verified against the source
rather than inferred: the invocation paths from `lint.sh` and the
pipeline YAML, the first-match-wins ordering from
`TagRuleSet.match_tags`, and the dead import from `git log` on the
deleted module plus a direct import attempt.

---------

Signed-off-by: Douglas Strodtman <[email protected]>
Signed-off-by: 400Ping <[email protected]>
dstrodtman added a commit that referenced this pull request Aug 21, 2026
## Summary

Read the Docs builds intermittently fail with a bare `EOFError` and no
failing document named:

```
File ".../multiprocessing/connection.py", line 399, in _recv
    raise EOFError
EOFError

make: *** [Makefile:91: html] Error 2
```

The kernel OOM-kills one of Sphinx's parallel write workers, and the
parent process has nothing better to report than the broken pipe. This
caps the worker count on the Read the Docs builder, which is the only
builder with a hard memory ceiling.

Two changes:

- `doc/Makefile` gains `SPHINX_JOBS ?= auto`, feeding `sphinx-build -j`.
The default keeps today's behavior for every existing caller.
- The `.readthedocs.yaml` html job passes `SPHINX_JOBS=2`.

## The mechanism

The builder has 4 CPUs and a cgroup `memory.max` of 7,130,316,800 bytes,
about 6.64 GiB, which matches the memory limit Read the Docs documents
for Business. `-j auto` forks one write worker per CPU and each worker
carries its own copy of the build environment, so the write phase costs
memory in proportion to the job count.

Measured on the builder, with `memory.events` read immediately after the
build:

| Job count | `memory.peak` | Headroom under the ceiling | `oom_kill` |
Result |
|---|---|---|---|---|
| `auto` (4) | 6,371,254,272 | ~759 MB | 1 | failed, `EOFError` |
| `auto` (4) | 6,503,370,752 | ~627 MB | 0 | passed |
| 2 | 5,566,427,136 | ~1,564 MB | 0 | passed |

The two `-j auto` rows are the important pair: the run that was killed
peaked *lower* than the run that passed. There is no threshold being
crossed. The build simply runs about 600 MB under a hard ceiling with
four workers allocating independently, and whether a given run survives
depends on the timing of individual allocations. That is also why the
document Sphinx dies on moves between builds, which is what makes the
failure read as a content problem when it isn't.

Dropping to 2 workers roughly doubles the headroom, from about 600 MB to
about 1.5 GiB.

## Why this is worth doing rather than waiting

The parallelism is recent, not long-standing. Read the Docs' own Sphinx
invocation adds `-j auto` only for projects carrying the opt-in
`BUILD_IN_PARALLEL` feature flag, so RtD was building Ray's docs
serially. #64277 pointed `build.jobs.build.html` at `make -C doc html`,
which inherited the Makefile's `-j auto` — a flag that until then only
the Buildkite doc build used. #64599 then made every preview a full
clean `-a -E` build. Neither change was wrong on its own; together they
put four write workers and a thin memory margin on the one builder that
can't absorb them.

Some things that this is *not*, all checked:

- **Not content growth.** The Sphinx environment went from 4058
documents on a passing build to 4087 on a failing one. 0.7% can't move a
build across a ceiling.
- **Not dependency drift.** `doc/requirements-doc.lock.txt` is fully
hash-pinned and unchanged across the window.
- **Not worker overcommit.** Sphinx resolves `-j auto` through
`multiprocessing.cpu_count`, which is neither affinity- nor
cgroup-aware, so it can in principle fork more workers than the
container can run. On this builder `nproc` and `nproc --all` both report
4, so that isn't happening.
- **Not host contention.** The ceiling is a per-build cgroup limit, not
host pressure, so this isn't other builds crowding the machine.

## Cost

Wall clock. A paired run on one builder measured 349 seconds at `-j
auto` against 620 seconds at `SPHINX_JOBS=2`, about 78% slower. The
`SPHINX_JOBS=2` arm ran with a warm cache, so treat 78% as a lower
bound.

That cost is confined to Read the Docs. `SPHINX_JOBS` defaults to
`auto`, so local builds and the Buildkite doc build are untouched.
Verified with `make -n`: the default still renders `-j auto`, the
override renders `-j 2`, and because `RTDSPHINXOPTS` and `LINKCHECKOPTS`
derive from the same variable, the override also reaches `linkcheck`,
`rtd-build`, and `rtd-fallback`. That last part matters for when the
incremental cache path in #64277 is re-enabled — the cap will apply
there too without another change.

## Why 2 rather than 3

2 is the value with a measured peak and a clean `oom_kill 0`. 3 would
cost less wall clock and is plausibly enough, but it hasn't been
measured, and at 3 workers the expected headroom lands between the two
figures above, closer to the margin that is already producing
intermittent kills. Given the failure mode is timing-dependent rather
than threshold-dependent, the point of the change is durable headroom
rather than getting just back under a line. If the wall-clock cost
proves painful, 3 is the obvious thing to measure next.

## Follow-up

Read the Docs documents the memory limit as upgradable on Business.
Raising it would let the parallelism come back and undo the wall-clock
cost. That's a separate ask to Read the Docs rather than a change in
this repo, and it's worth making regardless of this PR.

#65631 is the measurement PR that produced the numbers above. It can be
closed once this lands; the `SPHINX_JOBS` plumbing it carried is
included here, and its diagnostic wrapper was always meant to come back
out.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Signed-off-by: Douglas Strodtman <[email protected]>
nadongjun pushed a commit to nadongjun/ray that referenced this pull request Oct 6, 2026
…ay-project#65391)

## Why this change

`ci/ray_ci/doc/` holds the documentation site build and the
API-reference guards, but there's no orientation for anyone opening it.
Nine modules, three of which are entry points, and the wiring that
decides which is which lives in three other files
(`.buildkite/doc.rayci.yml`, `.buildkite/lint.rayci.yml`,
`ci/lint/lint.sh`). Reading the directory alone gives you the wrong
model of it.

The same is true one level up: `doc.rayci.yml` opens straight at `group:
doc` with no statement of what the pipeline does, and the two rules
files that decide what CI runs for *every* PR in the repo don't say
anywhere that that's what they do.

This PR is descriptive only. No step, rule, tag, or target changes
behavior.

## What's here

**New `ci/ray_ci/doc/README.md`.** What each entry point does and where
it's invoked from, what the shared libraries contribute, and two things
the layout actively misleads on:

- `cmd_check_api_discrepancy` and `cmd_check_api_param_coverage` have
`py_binary` targets but don't run through Bazel in CI. `lint.sh` invokes
them with the docbuild image's interpreter, because the Bazel targets
resolve `@py_deps_py310` wheels that can't import under the py3.11
docbuild image. There's already a `TODO(elliot-barn)` on ray-project#64070 to undo
this once hermetic py3.11 lands.
- The `doc: check API annotations` step isn't this package at all — it
runs `ci/lint/check_api_annotations.py`. Easy to assume otherwise, since
it sits next to `doc: check API doc consistency`, which *is* this
package.

**Header comment on `.buildkite/doc.rayci.yml`** listing the steps in
order and what each is for, and noting that tag rules, not this file,
decide what runs on a given PR.

**Scope notes on `.buildkite/test.rules.txt` and `always.rules.txt`.**
Both decide what CI runs for every pull request in the repository, so an
edit is a repo-wide change rather than a local one. The note also
records that rules are first-match-wins in file order, which makes rule
*position* as load-bearing as rule content, and points at the in-repo
check to run.

**Two removals.**

- `ci/ray_ci/doc/test_update_cache_env.py` imports
`ci.ray_ci.doc.cmd_update_cache_env`, which was deleted in ray-project#47233 (Aug
2024). The test was added later, in ray-project#64277, so it has never been able to
import since the day it landed. It also has no `py_test` target, which
is why nothing ran it and nothing reported it was broken.
- A stale cross-repo pointer in the `api_param_coverage` module
docstring, referencing a path outside this repository that readers here
can't follow. The paragraphs above it already describe the check's
scope, so nothing is lost.

## Not a duplicate

Checked open PRs for the touched areas per `AGENTS.md`:

```
gh pr list --repo ray-project/ray --state open --search "ray_ci/doc README"
gh pr list --repo ray-project/ray --state open --search "test_update_cache_env"
gh pr list --repo ray-project/ray --state open --search "test.rules.txt header comment"
```

No open PR adds a README here, touches the dead test, or comments these
files. Two PRs matched the third search on body text only (ray-project#65342,
ray-project#64977); I confirmed against their file lists that neither touches
`doc.rayci.yml`, `test.rules.txt`, or `always.rules.txt`. ray-project#65211 touches
`ci/ray_ci/doc/api.py`, a different file in the same directory, and
doesn't conflict.

## Testing

```
bazel test //ci/pipeline:test_doc_api_rules_sync //ci/ray_ci/doc/...
```

7/7 pass (`test_doc_api_rules_sync`, `test_api`,
`test_api_param_coverage`, `test_autodoc`, `test_build_cache`,
`test_cmd_check_api_discrepancy`, `test_module`).

Because the comments land on rule files, I also confirmed the rules
still parse and emit identical tags, loading both files through
`ci/pipeline/determine_tests_to_run.py` and comparing `match_tags`
output before and after. Comments are ignored by the parser and nothing
moved. `pre-commit run` passes on every changed file.

## AI assistance

This change was written with AI assistance. I reviewed every line, ran
the tests above myself, and can defend the change end-to-end. Every
technical claim in the added comments was verified against the source
rather than inferred: the invocation paths from `lint.sh` and the
pipeline YAML, the first-match-wins ordering from
`TagRuleSet.match_tags`, and the dead import from `git log` on the
deleted module plus a direct import attempt.

---------

Signed-off-by: Douglas Strodtman <[email protected]>
nadongjun pushed a commit to nadongjun/ray that referenced this pull request Oct 6, 2026
…project#65643)

## Summary

Read the Docs builds intermittently fail with a bare `EOFError` and no
failing document named:

```
File ".../multiprocessing/connection.py", line 399, in _recv
    raise EOFError
EOFError

make: *** [Makefile:91: html] Error 2
```

The kernel OOM-kills one of Sphinx's parallel write workers, and the
parent process has nothing better to report than the broken pipe. This
caps the worker count on the Read the Docs builder, which is the only
builder with a hard memory ceiling.

Two changes:

- `doc/Makefile` gains `SPHINX_JOBS ?= auto`, feeding `sphinx-build -j`.
The default keeps today's behavior for every existing caller.
- The `.readthedocs.yaml` html job passes `SPHINX_JOBS=2`.

## The mechanism

The builder has 4 CPUs and a cgroup `memory.max` of 7,130,316,800 bytes,
about 6.64 GiB, which matches the memory limit Read the Docs documents
for Business. `-j auto` forks one write worker per CPU and each worker
carries its own copy of the build environment, so the write phase costs
memory in proportion to the job count.

Measured on the builder, with `memory.events` read immediately after the
build:

| Job count | `memory.peak` | Headroom under the ceiling | `oom_kill` |
Result |
|---|---|---|---|---|
| `auto` (4) | 6,371,254,272 | ~759 MB | 1 | failed, `EOFError` |
| `auto` (4) | 6,503,370,752 | ~627 MB | 0 | passed |
| 2 | 5,566,427,136 | ~1,564 MB | 0 | passed |

The two `-j auto` rows are the important pair: the run that was killed
peaked *lower* than the run that passed. There is no threshold being
crossed. The build simply runs about 600 MB under a hard ceiling with
four workers allocating independently, and whether a given run survives
depends on the timing of individual allocations. That is also why the
document Sphinx dies on moves between builds, which is what makes the
failure read as a content problem when it isn't.

Dropping to 2 workers roughly doubles the headroom, from about 600 MB to
about 1.5 GiB.

## Why this is worth doing rather than waiting

The parallelism is recent, not long-standing. Read the Docs' own Sphinx
invocation adds `-j auto` only for projects carrying the opt-in
`BUILD_IN_PARALLEL` feature flag, so RtD was building Ray's docs
serially. ray-project#64277 pointed `build.jobs.build.html` at `make -C doc html`,
which inherited the Makefile's `-j auto` — a flag that until then only
the Buildkite doc build used. ray-project#64599 then made every preview a full
clean `-a -E` build. Neither change was wrong on its own; together they
put four write workers and a thin memory margin on the one builder that
can't absorb them.

Some things that this is *not*, all checked:

- **Not content growth.** The Sphinx environment went from 4058
documents on a passing build to 4087 on a failing one. 0.7% can't move a
build across a ceiling.
- **Not dependency drift.** `doc/requirements-doc.lock.txt` is fully
hash-pinned and unchanged across the window.
- **Not worker overcommit.** Sphinx resolves `-j auto` through
`multiprocessing.cpu_count`, which is neither affinity- nor
cgroup-aware, so it can in principle fork more workers than the
container can run. On this builder `nproc` and `nproc --all` both report
4, so that isn't happening.
- **Not host contention.** The ceiling is a per-build cgroup limit, not
host pressure, so this isn't other builds crowding the machine.

## Cost

Wall clock. A paired run on one builder measured 349 seconds at `-j
auto` against 620 seconds at `SPHINX_JOBS=2`, about 78% slower. The
`SPHINX_JOBS=2` arm ran with a warm cache, so treat 78% as a lower
bound.

That cost is confined to Read the Docs. `SPHINX_JOBS` defaults to
`auto`, so local builds and the Buildkite doc build are untouched.
Verified with `make -n`: the default still renders `-j auto`, the
override renders `-j 2`, and because `RTDSPHINXOPTS` and `LINKCHECKOPTS`
derive from the same variable, the override also reaches `linkcheck`,
`rtd-build`, and `rtd-fallback`. That last part matters for when the
incremental cache path in ray-project#64277 is re-enabled — the cap will apply
there too without another change.

## Why 2 rather than 3

2 is the value with a measured peak and a clean `oom_kill 0`. 3 would
cost less wall clock and is plausibly enough, but it hasn't been
measured, and at 3 workers the expected headroom lands between the two
figures above, closer to the margin that is already producing
intermittent kills. Given the failure mode is timing-dependent rather
than threshold-dependent, the point of the change is durable headroom
rather than getting just back under a line. If the wall-clock cost
proves painful, 3 is the obvious thing to measure next.

## Follow-up

Read the Docs documents the memory limit as upgradable on Business.
Raising it would let the parallelism come back and undo the wall-clock
cost. That's a separate ask to Read the Docs rather than a change in
this repo, and it's worth making regardless of this PR.

ray-project#65631 is the measurement PR that produced the numbers above. It can be
closed once this lands; the `SPHINX_JOBS` plumbing it carried is
included here, and its diagnostic wrapper was always meant to come back
out.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

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

Labels

core Issues that should be addressed in Ray Core docs An issue or change related to documentation go add ONLY when ready to merge, run all tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants