Skip to content

[doc] Upgrade Sphinx to 9.1.0 on Python 3.12 (step 2 of 8->9) - #64944

Closed
ronny-anyscale wants to merge 1 commit into
masterfrom
doc-939-sphinx-8-to-9
Closed

ronny-anyscale wants to merge 1 commit into
masterfrom
doc-939-sphinx-8-to-9

Conversation

@ronny-anyscale

@ronny-anyscale ronny-anyscale commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Description

Step 2 of the Sphinx 8→9 docs upgrade (follow-up to #64070, which did 7→8). Bumps sphinx==8.2.3 → 9.1.0, which requires Python 3.12, so the docs build moves from Python 3.11 → 3.12.

Sphinx 9's stricter cross-reference resolution and autosummary changes surfaced ~3145 fail-on-warning errors on a cold build; all are resolved (see below) and make clean && make html is warning-free.

Related issues

Follow-up to #64070 (Sphinx 7→8).

Additional information

Toolchain

  • doc/requirements-doc.txt: sphinx 8.2.3 → 9.1.0
  • docs build Python 3.11 → 3.12: .readthedocs.yaml, .buildkite/doc.rayci.yml, ci/raydepsets/configs/docs.depsets.yaml; regenerated docbuild_depset_py3.12.lock and re-pointed the doc/requirements-doc.lock.txt symlink.

Sphinx 9 compatibility (cold make html is warning-free)

  • doc/source/api_autogen.py ⚠️ — Sphinx 9 removed sphinx.ext.autosummary.generate.setup_documenters, and its live-app generate_autosummary_docs no longer recurses into freshly-generated class pages, so per-method API stubs (e.g. Dataset.map_batches) weren't emitted and ~250 method cross-references broke. Fixed by dropping the removed import and adding a second generation pass. This touches the API-autogen machinery — reviewers familiar with it should give this a look.
  • doc/source/conf.py — suppress_warnings += ['ref.python'] (Sphinx 9 warns on ambiguous unqualified xrefs; Ray members like ray.data.expressions.Expr.str/.list/.type shadow builtin type names) and nitpick_ignore_regex += typing.*, pydantic ValidationError.
  • Removed two MyST --- transitions illegal inside a list item under docutils 0.22.
  • Documented JobDetails/DriverInfo via the class_without_autosummary template (consistent with the sibling enum entries).

⚠️ Known content delta (accepted)

Sphinx 9 + autodoc-pydantic==2.2.0 (the latest release; unmaintained and with no Sphinx 9 support — successor tracked at sphinxcontrib-pydantic#87) no longer renders methods on pydantic models. Verified via an objects.inv diff against /en/master: 4313 vs 4375 API objects, a 64-object delta, in two categories:

~46 Ray Serve methods/properties — the actual dropped docs. All non-@PublicAPI; model fields and descriptions are unaffected. They are helper/serialization/computed methods (get_*, from_*, is_*, parse_yaml, …), not data fields:

Area # Classes (examples)
Serve LLM 23 LLMConfig (14: get_engine_config, model_architecture, supports_vision, update_engine_kwargs…), CloudMirrorConfig, LoraConfig, ModelLoadingConfig, LLMServingArgs
Serve config 17 AutoscalingPolicy (6), RequestRouterConfig (5), AutoscalingConfig (4: get_downscaling_factor…), gRPCOptions, DeploymentActorConfig
Serve schema 6 ServeApplicationSchema, ServeDeploySchema, DeploymentSchema, DurationStats, ServeInstanceDetails

18 Ray Jobs field-objects — reorganized, not lost. JobDetails (15) and DriverInfo (3) fields still render inline on their pages; the class_without_autosummary change moved them from per-field sub-pages to inline, so only the individual sub-page objects went away and nothing links to them (0 broken refs).

Accepted as a tradeoff of adopting Sphinx 9 while autodoc-pydantic is unmaintained; the fields/descriptions that matter most are intact. Please confirm on the RtD preview.

Testing

  • Cold make clean && make html (Sphinx 9.1.0 / py3.12, -W --keep-going): build succeeded, 0 warnings (down from 3145).
  • pre-commit on the changed non-doc/source files: clean.
  • raydepsets --check (docbuild py3.12 lock): up to date.
  • Authoritative content check: the Read the Docs PR-preview build compared against /en/master.

AI assistance

Developed with AI assistance (Claude Code). Opened as draft pending the submitter's line-by-line review (per AGENTS.md), especially the api_autogen.py generation change and the accepted pydantic content delta.

🤖 Generated with Claude Code

Follow-on to #64070 (Sphinx 7->8). Moves the docs toolchain to the current
stable Sphinx (9.1.0), which requires Python 3.12.

Toolchain bump:
- doc/requirements-doc.txt: sphinx 8.2.3 -> 9.1.0
- docs build Python 3.11 -> 3.12 across .readthedocs.yaml,
  .buildkite/doc.rayci.yml, and ci/raydepsets/configs/docs.depsets.yaml;
  regenerated docbuild_depset_py3.12.lock and re-pointed the
  doc/requirements-doc.lock.txt symlink

Sphinx 9 compatibility (cold `make html` is warning-free):
- doc/source/api_autogen.py: drop the removed `setup_documenters` import (gone
  in Sphinx 9) and add a second generation pass -- Sphinx 9's live-app
  generate_autosummary_docs no longer recurses into generated class pages, so
  the per-method API stubs (Dataset.map_batches, etc.) were not being emitted
- doc/source/conf.py: suppress the new ref.python ambiguity warnings (Ray API
  members such as Expr.str/.list/.type shadow builtin type names) and
  nitpick-ignore typing.* / pydantic ValidationError references
- remove two MyST transitions that are illegal inside a list item under
  docutils 0.22
- document JobDetails/DriverInfo via the class_without_autosummary template

Known content delta: Sphinx 9 + autodoc-pydantic 2.2.0 (latest release; no
Sphinx 9 support) stops rendering methods on pydantic models, dropping ~46
non-@publicapi serve config/LLM method doc entries (model fields are
unaffected). Details in the PR description.

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

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown

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

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

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

@github-actions github-actions Bot added the stale The issue is stale. It will be closed within 7 days unless there are further conversation label Aug 7, 2026
dstrodtman pushed a commit that referenced this pull request Aug 19, 2026
## Summary

Pre-bakes the third-party intersphinx inventories so Sphinx no longer
fetches ~two dozen `objects.inv` files over the network at the start of
every docs build.

- Commits 26 `objects.inv` snapshots under `doc/source/_intersphinx/`
(~1.7 MB total).
- Rewires `intersphinx_mapping` in `doc/source/conf.py` to prefer the
**local snapshot**, falling back to the existing upstream URL (or the
`<base_url>objects.inv` default) if a snapshot is missing. Sphinx tries
inventory locations in order and stops at the first that loads, so a
present snapshot means **no network fetch**, and a missing one degrades
to today's remote behavior — an info message, not a `-W`-breaking
warning. The human-readable target list stays intact as
`_intersphinx_targets`; the mapping is derived from it.
- Adds `doc/source/_intersphinx/refresh.py` to rebuild the snapshots (it
reads `_intersphinx_targets` straight from `conf.py`, so it can't drift
from the build config) and a `README.md` documenting the refresh
mechanism.

Resolves **DOC-1050** (parent epic DOC-1046, "Reduce Ray docs Sphinx/RtD
build time"). Estimated impact: ~20–60s per build, plus removal of an
intermittent network-flake failure mode.

### Why

The build fetches every inventory up front on every run — slow, and a
real source of build-time variance. Two of them (pandas, scipy) go
through GitHub release-asset redirects to signed, expiring Azure blob
URLs — the most fragile of the set and the most plausible cause of
intermittent silent timeouts. Snapshotting moves the staleness window
into our control.

Cross-reference *links* still point at each project's live docs site;
only *resolution* uses the local snapshot, so the URLs Sphinx emits are
unchanged.

### What staleness costs, and the refresh mechanism

This is the load-bearing part of the change, so it's worth being
explicit about the trade. `intersphinx_cache_limit` is unset, so
Sphinx's 5-day default applies today:

| | Staleness bound | Upstream **adds** a symbol | Upstream
**removes/renames** a symbol |
|---|---|---|---|
| **Today** | published builds fetch fresh; PR builds ≤5 days | new xref
resolves | xref fails → **loud `-W` failure** |
| **With snapshots** | until someone refreshes | new xref fails → loud
`-W` failure, fix = `refresh.py` | stale snapshot still resolves →
**silent dead outbound link** |

The second column is fine — it's self-announcing and one command to fix.
The third is the real cost: a stale snapshot keeps resolving a symbol
upstream has deleted, so the build stays green while emitting a link to
a page that no longer exists. Ray CI does run the `linkcheck` builder
(`doc: linkcheck` in `.buildkite/doc.rayci.yml`), but it can't catch
this: the step is `skip-on-premerge` with `soft_fail: true`, so it runs
only after merge and never blocks, and `linkcheck_anchors = False` in
`conf.py` means it checks that the target page resolves, not the
`#anchor` a symbol-level cross-reference points at.

Most targets resolve against upstream's *moving* docs, so their
inventory changes when the upstream project *releases*, independently of
anything Ray pins — there is no Ray-side event to refresh against, which
is why it has to be a clock rather than a ride-along with Ray's
dependency bumps. Four targets are exceptions that set an explicit
inventory URL: `pandas` and `scipy` read frozen `object-mirror-*`
release assets under `ray-project`, `torch` is pinned to `docs/2.7/`
while its links point at `docs/stable/`, and `tensorflow` reads a
third-party GPflow mirror tracking its own `master`. For the three
frozen ones a refresh is a no-op and committing a snapshot changes
nothing about their staleness. All pre-existing `conf.py` behavior,
unchanged here.

How fast does this actually drift? Re-running `refresh.py` six days
after the initial capture changed **4 of 26** — `grpc` 1.82.0 → 1.83.0
(a real minor release), plus content changes in `pydantic`, `python`
3.14, and `transformers` `main`. That rate is the argument for a
scheduled refresh in one line.

The mechanism, therefore: **a scheduled monthly job runs `refresh.py`
and opens a PR when any snapshot drifted.** That bounds staleness at ~1
month, and it restores the loud failure — once the fresh inventory drops
a removed symbol, the stale cross-reference fails on the *refresh PR's*
`-W` build. That is why a refresh must land as a reviewed PR and must
never be auto-merged: that build is the entire safety net for the silent
case.

That job is
**[anyscale/docs#2441](anyscale/docs#2441 — a
GitHub Actions workflow modeled on the existing
`bump-ray-template-pins.yml`, which already refreshes Ray's docs
template pins the same way. It reuses that workflow's fork and PAT, so
it opens its PR from a fork and **needs no changes to this repo and no
new permissions here**. It commits only `doc/source/_intersphinx/*.inv`
(a guard fails the run otherwise), signs off with DCO, and reuses one
`auto-refresh-intersphinx-snapshots` branch so monthly runs can't stack
up PRs.

> **Merge order:** land this PR first, then
[anyscale/docs#2441](anyscale/docs#2441). The
workflow errors out by design if `doc/source/_intersphinx/refresh.py`
isn't on `master` yet, so merging it early just produces one noisy
failed run. `README.md` and `refresh.py` describe that job as the
mechanism, so #2441 should not be left indefinitely unmerged either.

### Refreshing by hand

```bash
python doc/source/_intersphinx/refresh.py              # refresh all
python doc/source/_intersphinx/refresh.py numpy torch  # refresh a subset
```

Needed after adding a target, or when a cross-reference to a symbol that
does exist upstream stops resolving.

### Also included

`doc/.claude/skills/sphinx-fix/rules.yaml` — two rules gave advice this
change invalidates:

- `intersphinx-inventory-unreachable` said to re-run the build first, as
a transient network blip. With snapshots committed, reaching `failed to
reach any of the inventories` means **both** locations failed: the
snapshot is missing or unreadable *and* the network fetch failed. A
green re-run then just means the network came back while the missing
snapshot is still missing, so a missing snapshot is now the first thing
to check.
- `py-xref-target-not-found` now notes that a third-party target which
*does* exist upstream points at a stale snapshot — fix by refreshing,
not by editing the reference.

### Not a duplicate

Checked open PRs for `intersphinx` / `objects.inv` / `_intersphinx`:
nothing in flight touches inventory pre-baking. (#60886 is a dependabot
`nbconvert` bump; #64944 is the Sphinx 9.1 upgrade, which mentions
`objects.inv` only incidentally and does not change the mapping.)

### Testing

- `python -m py_compile doc/source/conf.py` — passes under Python 3.11
(Sphinx 8.2.3, current) and 3.12 (Sphinx 9.1.0, the in-progress upgrade
target).
- Offline verification driving Sphinx's own inventory loader
(`_fetch_inventory_group`) with the network fetch path monkeypatched to
raise: **all 26 inventories resolve from local files, 0 network calls,
157,320 cross-reference targets** — identical on Sphinx 8.2.3 and 9.1.0.
(9.1's new `cache_dir` arg only affects remote fetches, so local-first
is unchanged.)
- `refresh.py` successfully re-fetches all 26 inventories, including the
pandas/scipy GitHub-redirect mirrors. Re-run immediately before
requesting review so the snapshots don't land stale: 26/26 succeeded, 4
drifted, all 26 verified as valid v2 inventories afterwards (`# Sphinx
inventory version` banner present, upstream project/version parsed from
each header).
- `python sphinx_fix.py --selftest` → `SELFTEST OK (16 fixtures, 15
rules, 4 suppressions)` after regenerating the three affected goldens.
The rule IDs, tiers, safety levels and unclassified count are unchanged;
only the fix text moved.
- `rules.yaml` parses under real PyYAML (the `check-yaml` hook's parser)
as well as the skill's built-in fallback parser.
- Read the Docs `-W` build: **green** on the first two commits;
rebuilding on the snapshot refresh.

I have not run the full local docs HTML build; the RtD `-W` build on
this PR is the end-to-end check.

### Repo size

The snapshots add ~1.62 MiB, and each refresh adds new blobs for
whichever files changed. `.inv` files are already zlib-compressed so
delta compression barely helps. On the observed drift rate that's
roughly 0.5–1.5 MiB per refresh — call it 6–18 MiB/year — permanently,
against ~20–60s saved on every build plus the removal of a flake class.
Worth stating explicitly rather than leaving to be discovered.

### AI assistance

This PR was prepared with AI assistance (Claude Code). I have reviewed
the change line by line and can defend it end-to-end; the commands run
and their results are listed under Testing above.

🤖 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]>
nadongjun pushed a commit to nadongjun/ray that referenced this pull request Oct 6, 2026
## Summary

Pre-bakes the third-party intersphinx inventories so Sphinx no longer
fetches ~two dozen `objects.inv` files over the network at the start of
every docs build.

- Commits 26 `objects.inv` snapshots under `doc/source/_intersphinx/`
(~1.7 MB total).
- Rewires `intersphinx_mapping` in `doc/source/conf.py` to prefer the
**local snapshot**, falling back to the existing upstream URL (or the
`<base_url>objects.inv` default) if a snapshot is missing. Sphinx tries
inventory locations in order and stops at the first that loads, so a
present snapshot means **no network fetch**, and a missing one degrades
to today's remote behavior — an info message, not a `-W`-breaking
warning. The human-readable target list stays intact as
`_intersphinx_targets`; the mapping is derived from it.
- Adds `doc/source/_intersphinx/refresh.py` to rebuild the snapshots (it
reads `_intersphinx_targets` straight from `conf.py`, so it can't drift
from the build config) and a `README.md` documenting the refresh
mechanism.

Resolves **DOC-1050** (parent epic DOC-1046, "Reduce Ray docs Sphinx/RtD
build time"). Estimated impact: ~20–60s per build, plus removal of an
intermittent network-flake failure mode.

### Why

The build fetches every inventory up front on every run — slow, and a
real source of build-time variance. Two of them (pandas, scipy) go
through GitHub release-asset redirects to signed, expiring Azure blob
URLs — the most fragile of the set and the most plausible cause of
intermittent silent timeouts. Snapshotting moves the staleness window
into our control.

Cross-reference *links* still point at each project's live docs site;
only *resolution* uses the local snapshot, so the URLs Sphinx emits are
unchanged.

### What staleness costs, and the refresh mechanism

This is the load-bearing part of the change, so it's worth being
explicit about the trade. `intersphinx_cache_limit` is unset, so
Sphinx's 5-day default applies today:

| | Staleness bound | Upstream **adds** a symbol | Upstream
**removes/renames** a symbol |
|---|---|---|---|
| **Today** | published builds fetch fresh; PR builds ≤5 days | new xref
resolves | xref fails → **loud `-W` failure** |
| **With snapshots** | until someone refreshes | new xref fails → loud
`-W` failure, fix = `refresh.py` | stale snapshot still resolves →
**silent dead outbound link** |

The second column is fine — it's self-announcing and one command to fix.
The third is the real cost: a stale snapshot keeps resolving a symbol
upstream has deleted, so the build stays green while emitting a link to
a page that no longer exists. Ray CI does run the `linkcheck` builder
(`doc: linkcheck` in `.buildkite/doc.rayci.yml`), but it can't catch
this: the step is `skip-on-premerge` with `soft_fail: true`, so it runs
only after merge and never blocks, and `linkcheck_anchors = False` in
`conf.py` means it checks that the target page resolves, not the
`#anchor` a symbol-level cross-reference points at.

Most targets resolve against upstream's *moving* docs, so their
inventory changes when the upstream project *releases*, independently of
anything Ray pins — there is no Ray-side event to refresh against, which
is why it has to be a clock rather than a ride-along with Ray's
dependency bumps. Four targets are exceptions that set an explicit
inventory URL: `pandas` and `scipy` read frozen `object-mirror-*`
release assets under `ray-project`, `torch` is pinned to `docs/2.7/`
while its links point at `docs/stable/`, and `tensorflow` reads a
third-party GPflow mirror tracking its own `master`. For the three
frozen ones a refresh is a no-op and committing a snapshot changes
nothing about their staleness. All pre-existing `conf.py` behavior,
unchanged here.

How fast does this actually drift? Re-running `refresh.py` six days
after the initial capture changed **4 of 26** — `grpc` 1.82.0 → 1.83.0
(a real minor release), plus content changes in `pydantic`, `python`
3.14, and `transformers` `main`. That rate is the argument for a
scheduled refresh in one line.

The mechanism, therefore: **a scheduled monthly job runs `refresh.py`
and opens a PR when any snapshot drifted.** That bounds staleness at ~1
month, and it restores the loud failure — once the fresh inventory drops
a removed symbol, the stale cross-reference fails on the *refresh PR's*
`-W` build. That is why a refresh must land as a reviewed PR and must
never be auto-merged: that build is the entire safety net for the silent
case.

That job is
**[anyscale/docs#2441](anyscale/docs#2441 — a
GitHub Actions workflow modeled on the existing
`bump-ray-template-pins.yml`, which already refreshes Ray's docs
template pins the same way. It reuses that workflow's fork and PAT, so
it opens its PR from a fork and **needs no changes to this repo and no
new permissions here**. It commits only `doc/source/_intersphinx/*.inv`
(a guard fails the run otherwise), signs off with DCO, and reuses one
`auto-refresh-intersphinx-snapshots` branch so monthly runs can't stack
up PRs.

> **Merge order:** land this PR first, then
[anyscale/docs#2441](anyscale/docs#2441). The
workflow errors out by design if `doc/source/_intersphinx/refresh.py`
isn't on `master` yet, so merging it early just produces one noisy
failed run. `README.md` and `refresh.py` describe that job as the
mechanism, so ray-project#2441 should not be left indefinitely unmerged either.

### Refreshing by hand

```bash
python doc/source/_intersphinx/refresh.py              # refresh all
python doc/source/_intersphinx/refresh.py numpy torch  # refresh a subset
```

Needed after adding a target, or when a cross-reference to a symbol that
does exist upstream stops resolving.

### Also included

`doc/.claude/skills/sphinx-fix/rules.yaml` — two rules gave advice this
change invalidates:

- `intersphinx-inventory-unreachable` said to re-run the build first, as
a transient network blip. With snapshots committed, reaching `failed to
reach any of the inventories` means **both** locations failed: the
snapshot is missing or unreadable *and* the network fetch failed. A
green re-run then just means the network came back while the missing
snapshot is still missing, so a missing snapshot is now the first thing
to check.
- `py-xref-target-not-found` now notes that a third-party target which
*does* exist upstream points at a stale snapshot — fix by refreshing,
not by editing the reference.

### Not a duplicate

Checked open PRs for `intersphinx` / `objects.inv` / `_intersphinx`:
nothing in flight touches inventory pre-baking. (ray-project#60886 is a dependabot
`nbconvert` bump; ray-project#64944 is the Sphinx 9.1 upgrade, which mentions
`objects.inv` only incidentally and does not change the mapping.)

### Testing

- `python -m py_compile doc/source/conf.py` — passes under Python 3.11
(Sphinx 8.2.3, current) and 3.12 (Sphinx 9.1.0, the in-progress upgrade
target).
- Offline verification driving Sphinx's own inventory loader
(`_fetch_inventory_group`) with the network fetch path monkeypatched to
raise: **all 26 inventories resolve from local files, 0 network calls,
157,320 cross-reference targets** — identical on Sphinx 8.2.3 and 9.1.0.
(9.1's new `cache_dir` arg only affects remote fetches, so local-first
is unchanged.)
- `refresh.py` successfully re-fetches all 26 inventories, including the
pandas/scipy GitHub-redirect mirrors. Re-run immediately before
requesting review so the snapshots don't land stale: 26/26 succeeded, 4
drifted, all 26 verified as valid v2 inventories afterwards (`# Sphinx
inventory version` banner present, upstream project/version parsed from
each header).
- `python sphinx_fix.py --selftest` → `SELFTEST OK (16 fixtures, 15
rules, 4 suppressions)` after regenerating the three affected goldens.
The rule IDs, tiers, safety levels and unclassified count are unchanged;
only the fix text moved.
- `rules.yaml` parses under real PyYAML (the `check-yaml` hook's parser)
as well as the skill's built-in fallback parser.
- Read the Docs `-W` build: **green** on the first two commits;
rebuilding on the snapshot refresh.

I have not run the full local docs HTML build; the RtD `-W` build on
this PR is the end-to-end check.

### Repo size

The snapshots add ~1.62 MiB, and each refresh adds new blobs for
whichever files changed. `.inv` files are already zlib-compressed so
delta compression barely helps. On the observed drift rate that's
roughly 0.5–1.5 MiB per refresh — call it 6–18 MiB/year — permanently,
against ~20–60s saved on every build plus the removal of a flake class.
Worth stating explicitly rather than leaving to be discovered.

### AI assistance

This PR was prepared with AI assistance (Claude Code). I have reviewed
the change line by line and can defend it end-to-end; the commands run
and their results are listed under Testing above.

🤖 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale The issue is stale. It will be closed within 7 days unless there are further conversation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant