Skip to content

[ci][doc] Repair doc build cache production; skip incremental for structural PRs - #64414

Merged
elliot-barn merged 7 commits into
masterfrom
fix-doc-cache-massage-env-python
Jul 1, 2026
Merged

elliot-barn merged 7 commits into
masterfrom
fix-doc-cache-massage-env-python

Conversation

@ronny-anyscale

@ronny-anyscale ronny-anyscale commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

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 (epic DOC-1046); unblocks the incremental RtD builds added in #64277. Follow-up: 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 Move plasma, common, and photon into the Ray repository. #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

The postmerge `doc: build` step has failed to upload a doc build cache on
every run since the Sphinx 8.2.3 upgrade (#64070). `make html` builds the
docs with the docbuild image's Python (Sphinx 8.2.3) and writes
environment.pickle, but cmd_build then unpickled it in-process under Bazel's
pinned Sphinx 6.2.1 in BuildCache._massage_cache. A Sphinx 8.x environment
pickle cannot be loaded by 6.2.1 -- it raises `ModuleNotFoundError: No module
named 'sphinx.util._files'` -- so the upload crashed and no cache was produced.

Without a fresh cache, Read the Docs only finds the last pre-upgrade cache
(Sphinx 7.x), rejects it ("build environment version not current"), and runs a
full cold build every time, so the incremental build added in #64277 never
triggers.

Run the pickle load/strip/dump under the doc-build environment's Python with
PYTHONPATH unset -- mirroring how _build() runs `make html` -- so the pickle is
always read by the same Sphinx that wrote it. This decouples cache production
from Bazel's Sphinx pin and survives future Sphinx upgrades.

Verified: ci/ray_ci/doc:test_build_cache passes; test_massage_cache now
exercises the real subprocess massage.

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 29, 2026 17:14

@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 updates the documentation build cache mechanism to strip build-environment-local dependencies from the Sphinx environment pickle using a subprocess. This ensures the pickle is read by the same Sphinx version that wrote it, avoiding version mismatch issues. The tests are updated to use types.SimpleNamespace and pass the test interpreter to the cache massage function. Feedback on these changes suggests properly unsetting PYTHONPATH using env.pop instead of setting it to an empty string, and reconstructing the dependencies collection rather than modifying it in-place during the stripping process.

Comment thread ci/ray_ci/doc/build_cache.py Outdated
env = os.environ.copy()
# Unset PYTHONPATH so the environment Python (with the Sphinx that wrote
# the pickle) is used instead of the Bazel runfiles Python.
env["PYTHONPATH"] = ""

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.

medium

Setting env["PYTHONPATH"] = "" does not actually unset the environment variable; instead, it sets it to an empty string. In Python, an empty string in PYTHONPATH is often interpreted as the current working directory (.), which can lead to unexpected module shadowing or import issues. To completely unset the environment variable, use env.pop("PYTHONPATH", None).

Suggested change
env["PYTHONPATH"] = ""
env.pop("PYTHONPATH", None)

Comment thread ci/ray_ci/doc/build_cache.py Outdated
Comment on lines +26 to +30
for doc, dependencies in environment_cache.dependencies.items():
# site-packages paths are local to the build machine and would mark every
# doc that imports them as outdated when the cache is restored elsewhere.
for dependency in [d for d in dependencies if "site-packages" in d]:
environment_cache.dependencies[doc].remove(dependency)

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.

medium

Instead of modifying the collection in-place by calling .remove() repeatedly in a loop (which can be inefficient and is less idiomatic), you can reconstruct the collection using a generator expression. Using type(dependencies)(...) dynamically preserves the original collection type (e.g., set or list).

Suggested change
for doc, dependencies in environment_cache.dependencies.items():
# site-packages paths are local to the build machine and would mark every
# doc that imports them as outdated when the cache is restored elsewhere.
for dependency in [d for d in dependencies if "site-packages" in d]:
environment_cache.dependencies[doc].remove(dependency)
for doc, dependencies in environment_cache.dependencies.items():
# site-packages paths are local to the build machine and would mark every
# doc that imports them as outdated when the cache is restored elsewhere.
environment_cache.dependencies[doc] = type(dependencies)(
d for d in dependencies if "site-packages" not in d
)

- Use env.pop("PYTHONPATH", None) instead of setting it to "" so the variable
  is truly unset (an empty entry can be interpreted as the current directory).
- Rebuild each dependency collection with type(dependencies)(...) rather than
  removing entries in a loop; preserves the collection type and reads cleaner.

Related to DOC-1047

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

@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.

🤞

As long as this doesn't further break anything, we should ship!

@ray-gardener ray-gardener Bot added docs An issue or change related to documentation devprod labels Jun 29, 2026
@ronny-anyscale ronny-anyscale added the go add ONLY when ready to merge, run all tests label Jun 29, 2026
Comment thread ci/ray_ci/doc/build_cache.py Outdated
# Run as a standalone script under the doc-build environment's Python (see
# BuildCache._massage_cache) so the pickle is read by the same Sphinx that wrote
# it; it intentionally imports only the standard library.
_STRIP_LOCAL_DEPS_SCRIPT = """\

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

can we add this as its own python script? instead of embedding it in a string

ronny-anyscale and others added 2 commits June 29, 2026 16:30
Address review (@elliot-barn): extract the inline massage logic into
ci/ray_ci/doc/massage_cache.py instead of embedding it as a string in
build_cache.py. _massage_cache runs it via the doc-build environment's Python
(PYTHONPATH unset), so the pickle is still read by the same Sphinx that wrote
it. The script imports only the standard library; no behavior change. The :doc
glob already picks up *.py, so no BUILD change is needed.

Related to DOC-1047

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Signed-off-by: Ronny Roland <[email protected]>
A doc PR that deletes or moves source pages can't safely use the incremental
build: the restored cache doesn't prune the stale HTML/stubs left for the
removed sources, and a clean rename (references updated) wouldn't trip a -W
warning to force the existing fallback -- so the deleted page would linger in
the preview.

Route such PRs straight to the clean build: if `git diff --diff-filter=D`
finds any removed/moved source under doc/source/, run rtd-fallback instead of
the incremental rtd path. Uses `--name-only | grep -q` rather than
`git diff --quiet` because the latter's `--diff-filter` handling has varied
across git versions. The proper prune-on-restore fix (so these PRs can use the
cache) is tracked in DOC-1314.

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 changed the title [ci] doc build cache: massage the Sphinx pickle with the env Python [ci][doc] Repair doc build cache production; skip incremental for structural PRs Jun 29, 2026
…e/pipe)

The structural-PR skip guard made the RtD build silently fail: RTD's job runner
dropped the build.html script (logged exit-code None, never executed) because
its preprocessor can't parse certain constructs. The script had an unbalanced
apostrophe ("can't") and a `| grep` pipe -- neither used anywhere in the proven
post_checkout block.

Rewrite the structural-change check as `if ! git diff --quiet --no-renames
--diff-filter=D ... 2>/dev/null` -- the exact shape post_checkout already uses --
and reword the echo to drop the apostrophe. No behavior change: --quiet respects
--diff-filter on the ubuntu-24.04 git RtD runs (verified delete -> clean,
modify-only -> incremental).

Related to DOC-1047

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Signed-off-by: Ronny Roland <[email protected]>
Comment thread ci/ray_ci/doc/build_cache.py Resolved

@elliot-barn elliot-barn left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approving but would like the TODO comment to be added

"""
Massage the build artifacts, remove the unnecessary files so that they can
be used as a global cache
Strip build-environment-local dependencies from the Sphinx environment

@ronny-anyscale ronny-anyscale Jun 30, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
Strip build-environment-local dependencies from the Sphinx environment
TODO (elliot-barn): revert when upgrading bazel python toolchain
Strip build-environment-local dependencies from the Sphinx environment

Comment thread ci/ray_ci/doc/build_cache.py Resolved
@elliot-barn
elliot-barn merged commit 5612883 into master Jul 1, 2026
3 checks passed
@elliot-barn
elliot-barn deleted the fix-doc-cache-massage-env-python branch July 1, 2026 16:41
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]>
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

devprod 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