Skip to content

[ci] Route API reference pages and autodoc machinery to the API-surface checks - #64812

Merged
dstrodtman merged 3 commits into
ray-project:masterfrom
dstrodtman:djs-260716-docs-api-go-label
Aug 5, 2026
Merged

dstrodtman merged 3 commits into
ray-project:masterfrom
dstrodtman:djs-260716-docs-api-go-label

Conversation

@dstrodtman

@dstrodtman dstrodtman commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

The problem

Two premerge checks in .buildkite/doc.rayci.yml cross-check every @PublicAPI symbol against the autosummary pages that document it:

  • doc: check API annotations
  • doc: check API doc consistency

They currently run on the wrong set of changes, in both directions.

They miss changes they should catch. API reference pages are .rst and .md, so the leading prose-and-image skip rule in test.rules.txt matches them first. Editing doc/source/data/api/api.rst changes the documented public API surface and triggers no premerge step at all.

They run on changes that can't affect the API surface. Both steps carry the blanket doc tag. Since #64775 reserved doc for documentation validation, that tag now covers two unlike things: the autodoc machinery that decides what the API reference contains, and rendering config that can't change it. So a Vale vocabulary tweak pays for a docbuild plus both checks.

The fix

Add a doc_api tag, and route to it everything that can change the documented API surface or how it's computed. Then take the blanket doc tag off the two steps.

A change to today with this PR
An API reference page skip run
The checker's own source (ci/ray_ci/doc/) skip run
conf.py, api_autogen.py, api_mock_imports.py, _ext/ run run
Docs dependency locks (deplocks/docs/*.lock) run run
Library Python source run run
.vale.ini, Vale vocabularies run skip
rtd_doctor.py, template_collections.py run skip
.readthedocs.yaml, gallery configs run skip
Narrative prose, images skip skip

What's in the diff

Three commits, 7 files.

  1. a0b545cc3e declares doc_api and routes the six per-team API reference directories to it, ahead of the skip rule. Also splits the doc-build infra block in two: the autodoc machinery emits doc doc_api, the rendering-only half emits doc alone. Then drops the bare doc tag from both check steps.

  2. e0d520381d adds two drift guards in //ci/pipeline:test_doc_api_rules_sync. Both doc_api lists are hand-maintained and fail silently when they drift — a missing entry means those paths quietly stop being checked. One guard keeps the page list aligned with API_PATH_PREFIXES in doc/source/_ext/api_sidebar.py. The other requires every local module conf.py imports to be routed to doc_api or named as an explicit rendering-only exception.

  3. f3db137384 routes api_sidebar.py to tools as well, so the first guard actually runs. It was one-directional before: test.rules.txt emits tools, so the guard fired on a rules-side edit, but api_sidebar.py didn't, so growing API_PATH_PREFIXES without the matching rule never executed it — the likelier mistake, and exactly the drift the guard exists to catch. Also removes four duplicated assertions.

Three details worth knowing, since each looks like an oversight otherwise:

  • ci/ray_ci/doc/ keeps tools alongside doc_api. It declares six ci_unit py_test targets and tools is what selects the job that runs them, so dropping it would mean editing the checker never runs the checker's own unit tests.
  • doc.rayci.yml also emits doc_api, so editing a check's step definition exercises the check it defines.
  • doc/source/ray-observability/reference/ is routed even though it sits outside doc/source/*/api/. Ray Core's api/index.rst toctrees into its api.rst, so it's part of the Core API-surface walk.

Testing

test.rules.test.txt gains cases for the API pages (including a nested leaf page, to pin recursive directory matching), the checker source, each machinery path, and negative cases asserting the rendering half still emits doc alone. These are the real gate: the test-rules step runs them through rayci's parser as exact set equality, so a passing case proves a path emits precisely those tags and nothing else.

Locally, against the in-repo reference engine (ci/pipeline/determine_tests_to_run.py):

  • check_rules() passes; 115 of 115 replay cases pass.
  • Across all 10,213 tracked files the routing change is purely additive: 95 files gain tags, none lose any.
  • No executable asset (.py, .ipynb) lives under the routed API directories, so no library docs-example step loses coverage.
python -m pytest ci/pipeline/test_doc_api_rules_sync.py

Two notes for reviewers

One behavior change to sanity-check. Neither check carries an if: guard now, including the docs-go one they had before. A content-only PR labeled docs-go that touches an API reference page will run both checks plus their docbuild dependency, where it previously skipped them. That's intended — docs-go exists to skip per-team doc example execution, and an API reference edit is exactly the content-only change these checks must still cover — but it's a real cost change for that workflow. docs-go keeps its role everywhere else: 12 per-team doc example steps across core, data, llm, ml, rllib, serve, and linux_aarch64, plus the lint: validate docs-go scope step that enforces the label is only used on doc-only PRs.

This PR changed shape, so earlier comments describe an older design. It began as a docs-api-go PR label that would re-enable the checks on a docs-go PR. That's removed: tag selection and Buildkite if: are separate passes, and if: can only suppress a step the tags already emitted, so with the routing correct the label could only ever subtract. Dropping the if: achieves the same thing with no label to create or remember. Consequently the earlier Gemini review and the 2026-08-04 comment above both reference a docs-api-go label that no longer exists. Everything else in that comment still stands, including its decision that doc_code/ and examples/ should not grow into doc_api.

🤖 Written with assistance from Claude Code.

@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 a new doc_api tag and a docs-api-go label to allow running API-consistency checks on content-only PRs that touch public API reference pages, even when the broader docs-go label is used to skip full library tests. It maps specific API reference directories to this tag and updates the Buildkite pipeline configuration accordingly. The reviewer suggested adding test cases for the train and tune API reference pages in .buildkite/test.rules.test.txt to ensure comprehensive test coverage for all newly mapped directories.

Comment thread .buildkite/test.rules.test.txt Resolved
@dstrodtman
dstrodtman force-pushed the djs-260716-docs-api-go-label branch from 21d15c6 to 166be9e Compare July 16, 2026 18:03
@dstrodtman
dstrodtman marked this pull request as ready for review July 16, 2026 18:13
@dstrodtman
dstrodtman requested review from a team as code owners July 16, 2026 18:13
@ray-gardener ray-gardener Bot added docs An issue or change related to documentation core Issues that should be addressed in Ray Core devprod labels Jul 16, 2026
@dstrodtman dstrodtman added the go add ONLY when ready to merge, run all tests label Jul 22, 2026
Comment thread .buildkite/test.rules.txt Resolved
@dstrodtman

Copy link
Copy Markdown
Contributor Author

A third case for the API checks, surfaced while validating #64775

Recording this here rather than only on #64775, since this PR is where the reasoning about keeping doc: check API annotations and doc: check API doc consistency alive lives, and I don't want it dropped as follow-up.

The finding. #64775's rules change alone already removes those two checks from library doc-example changes. Both steps carry the blanket doc tag among their library tags, and today doc/source/<lib>/doc_code/ and doc/source/<lib>/examples/ emit doc, so a doc-example edit incidentally triggers a premerge make -C doc/ html. After #64775 those paths emit <lib>_doc instead, and the two checks drop out of the pipeline.

I confirmed this by generating the real pipeline locally with the pinned rayci v0.46.0 release binary (-repo . -output -, with BUILDKITE_PULL_REQUEST_BASE_BRANCH and BUILDKITE_COMMIT set so the change lister does the merge-base diff), for a one-file change to doc/source/serve/doc_code/app_builder.py:

base=master              selected tags: always doc lint
  -> doc: check API annotations [g9_s3], doc: check API doc consistency [g9_s4]
     plus all six teams' doc example steps

base=<the #64775 branch>  selected tags: always lint serve_doc
  -> serve: docs example tests [g16_s12], serve: docs example gpu tests [g16_s21]
     the two API checks are not emitted

Why it's a third case. This PR's doc_api tag covers the autosummary API reference pages under doc/source/*/api/ and doc/source/rllib/package_ref/, which are prose files that would otherwise hit the leading skip rule. The docs-api-go label covers the case where docs-go gates the checks off. Neither covers a doc-example change with no label at all, where the checks simply stop being selected.

My read, for the record: dropping them there is correct. api_policy_check guards the documented public API surface, and a doc example can't change it. The example is still executed by the owning library's step, and the render is gated by Read the Docs. So I don't think doc_api should grow to cover doc_code/ and examples/. But it should be a decision rather than a side effect, which is the point of writing it down.

One thing to check on the rebase

When this rebases onto the batch, the doc_api rule block has to stay ahead of the leading skip block in test.rules.txt. #64775 extends that block to lines 39-47 (it adds doc/.claude/ and the image extensions alongside the existing doc/*.md and doc/*.rst). First match wins per ruleset, and * is fnmatch here so it crosses / — meaning doc/*.rst matches doc/source/serve/api/api.rst. If the rebase lands the doc_api block below that, the API reference pages silently go back to emitting nothing and this PR's gate is inert with green fixtures for everything else.

The per-library directory rules #64775 adds sit well after the skip block (around line 282), so they don't compete with doc_api for .rst pages. The ordering constraint is only against the skip block.

Worth adding a test.rules.test.txt case post-rebase asserting an API reference page under a library directory emits exactly doc_api and not <lib>_doc, since the exact-set-equality assertion would catch precisely this regression.

AI assistance (Claude Code) was used for the pipeline generation and analysis above.

dstrodtman added a commit that referenced this pull request Aug 5, 2026
…per library (#64775)

## Reviewer summary

**What this does.** The per-team `X: doc tests` steps are library
example and doctest suites that live under `doc/`. They exercise library
code, not documentation quality. Today every executable doc asset emits
the blanket `doc` tag and all six teams' steps are tagged `doc`, so a
one-library doc change starts every team's step. This gives each step a
dedicated `<lib>_doc` tag, routes `doc/source/<lib>/**` to the owning
library's tag, renames the steps to `X: docs example tests`, and leaves
`doc` for documentation validation (the build and the Vale/config
infra). The library tag stays on each step, so a library **code** change
runs its doc example tests exactly as before.

**What's verified.**

| Claim | Evidence |
|---|---|
| Each path emits exactly the intended tag, and no other | `test-rules`
green on this PR. That's the pinned `rayci` binary replaying all 103
`test.rules.test.txt` assertions (up from 57 on master) with **exact set
equality**, so each case also proves the blanket `doc` tag does *not*
come along. |
| The emitted tags resolve to the intended steps, and only those |
Generated the real pipeline locally with the pinned `rayci v0.46.0`
release binary for a one-file Serve doc-example change, before and after
this branch. Output below. |
| The renamed steps still run and pass | All five plus the GPU and dask
siblings green on this PR, selected via the library tags this change
preserves. |
| Every executable target under `doc/` routes to a step that can
actually select it | Swept all 948 (file, target) claims against the
per-team `team:` / `--only-tags` / `--except-tags` filters. One
deliberate exception (`doc/test_myst_doc.py`, below) and two
pre-existing gaps that this change doesn't create. |
| The rename doesn't reset step identity | rayci derives step IDs
positionally (`fmt.Sprintf("g%d_s%d", i, j)`, `converter.go`), not from
the label. The generated pipelines confirm it: `g16_s12`, `g16_s21`,
`g6_s22`, `g13_s26` are identical before and after. |

**What I need from a reviewer.**

1. **One question I can't answer from inside the repo.**
`ci/build/get_build_info.py` sets `config.env` to `"Buildkite " +
BUILDKITE_LABEL`, and `ci/build/upload_build_info.sh` uploads it on
postmerge pipelines on `master` only. Does anything downstream of that
`metadata.json` treat `config.env` as an identity or grouping key? If
it's descriptive, renaming five steps is free. If something groups on
it, those five steps' postmerge history splits at the merge commit.
Flaky-test selection and target selection both key on `team` (unchanged
here) and test identity is the bazel target name (`f"{system}:{name}"`
in `release/ray_release/test.py`), so I believe `config.env` is the only
place the label escapes.
1. **Confirm the API-check behavior change below is acceptable.**
1. **Confirm the catch-all owner.** Executable doc assets in directories
with no per-team step route to the core step: roughly 25 files, being 18
`doc/source/templates/*/start.ipynb` plus a handful under
`doc/source/cluster/doc_code/`, `doc/source/ray-contribute/doc_code/`,
and `doc/source/_templates/`. The templates majority may be retired or
externally managed, in which case a skip rule is the better answer than
core ownership.

**Known behavior change worth your eyes.** Because
`doc/source/<lib>/doc_code/` and `examples/` now emit `<lib>_doc`
instead of `doc`, the two API-surface checks (`doc: check API
annotations`, `doc: check API doc consistency`) stop running on library
doc-example changes. They carry the blanket `doc` tag among their
library tags, so today a `doc_code` edit incidentally triggers a
premerge `make -C doc/ html`. I think that's correct: those checks guard
the documented public API surface, which a doc example can't change, and
the example itself is still executed by the owning library's step while
the render is gated by Read the Docs. But it is a premerge signal that
disappears, so it should be a decision rather than a side effect. Raised
on #64812, which routes the API **reference** pages to a dedicated
`doc_api` tag for the related case.

**Out of scope, tracked separately.** `.buildkite/others.rayci.yml:13`
declares a sixth step labeled `doc tests`, running `//python/ray/...
//doc/... none --only-tags doctest` and tagged `python`, a tag no rule
in `test.rules.txt` emits. Generating the full-fan-out pipeline shows it
does get emitted (`doc tests [g14_s1]`), so it is live. After this
rename it becomes the only step in the repo still called "doc tests."
This PR doesn't touch `others.rayci.yml` and the fix is independent.

---

## What this changes

1. **Dedicated per-library tag.** Each step gets a `<lib>_doc` tag
(`core_doc`, `data_doc`, `ml_doc`, `rllib_doc`, `serve_doc`) and drops
the blanket `doc` tag. The library tag stays.
1. **Path routing.** `test.rules.txt` routes `doc/source/<lib>/**` to
that library's tag, so a doc change runs only the owning library's
example tests. LLM doc assets already route to `llm` and keep doing so.
1. **`doc` reserved for validation.** It now stays only on the
documentation build and the Vale/config infra.
1. **Rename** to `X: docs example tests`, since a failure in these steps
means library code or an example broke, not that the docs are wrong.
1. **Build-file rule fix.** `test.rules.txt` matched `doc/BUILD` and
`doc/*/BUILD`, but the files are `BUILD.bazel`, so editing a file that
*defines* the doc test targets ran no doc tests premerge. It now matches
the `.bazel` files and routes them to the same per-library steps. The
root `doc/BUILD.bazel` defines every library's targets, so it routes to
all of them.

### Scoping exceptions, and why each exists

Several paths sit under a library doc directory but can't be
meaningfully tested by that library's example step, so they're routed
explicitly rather than by directory:

- **Static images skip entirely.** Image extensions sit on the leading
skip rule, ahead of the per-library rules, so a `.png` or `.svg` edit
triggers nothing. 310 tracked image files. `.yaml` and `.sh` stay
routed, since unlike an image they can change what a test does.
- **Sphinx build machinery routes to `doc`.** `conf.py` imports
`custom_directives`, `api_autogen`, `api_mock_imports`, and
`template_collections`; none was listed in the validation-infra rule, so
all fell to the `doc/*.py` catch-all and emitted `core_doc`, running Ray
Core's doctests for a docs-build-machinery edit. Those four plus
`preprocess_github_markdown` and the doc-root build helpers now route to
`doc`. They're enumerated one per line on purpose: `*` is fnmatch here
and crosses `/`, so a `doc/source/*.py` pattern would also swallow every
example script under `doc/source/<lib>/doc_code/`. There's a comment on
the rule saying so.
- **Gallery configs route to `doc`.**
`doc/source/{data,serve,train}/examples.yml` are parsed by
`custom_directives.py` (`EXAMPLE_GALLERY_CONFIGS`) to generate the
gallery pages. They hold no executable code and can't change what any
example does. Narrowed to a three-path exception rather than a blanket
`.yml` skip, because a sibling `.yml` under a library doc directory can
be a config an example consumes.
- **`doc/.claude/` triggers nothing.** Agent files never participate in
the Sphinx build and define no test targets, but
`doc/.claude/skills/sphinx-fix/sphinx_fix.py` matched the `doc/*.py`
catch-all. The Read the Docs build guard already excludes this exact
path for the same reason, so the two guards now agree. Pre-existing
rather than a regression from this PR: on master the file emits the
blanket `doc` tag, which reaches all five per-team steps.
- **Four `team:ml` notebooks under `ray-core/` route to `ml_doc`.**
`plot_hyperparameter`, `batch_prediction`, `plot_parameter_server`, and
`plot_pong_example` live under `doc/source/ray-core/examples/` but their
targets are tagged `team:ml`, and the team argument to
`//ci/ray_ci:test_in_docker` filters targets by `team:<team>`
(`_get_all_test_query`, `ci/ray_ci/tester.py`). Routing them to
`core_doc` would run a step that tests everything under `ray-core/`
except the file that changed. Re-tagging the four `team:core` in
`doc/BUILD.bazel` is the alternative fix and would let the rule lines go
away.
- **`highly_parallel.ipynb` routes to `doc`.** Its `py_test` carries a
`highly_parallel` tag that the ml docs example step excludes, and the
notebook glob in `doc/source/ray-core/examples/BUILD.bazel` excludes it
too, as a release test needing a live multi-node cluster. The remaining
ml `//doc/...` steps select `gpu` / `train_v2_gpu` and the target has
neither, so no premerge step executes it. Routing to `doc` means the
build renders it (`nb_execution_mode` defaults to `off`, so
render-and-lint only), which is the only validation premerge offers
here.
- **`doc/external/` routes to `ml_doc`.** Its `test_external_hashes`
target is tagged `team:ml`; it had fallen through the `doc/*.py`
catch-all to `core_doc`, where the core step's `team:core` query never
sees it.
- **The `llms.txt` files route to `doc`.** #64458 adds
`doc/test_llms_txt.py` and `doc/source/llms_txt_summary.txt` with no
`test.rules.txt` change. Left alone the test would land on the
`doc/*.py` catch-all and emit `core_doc`, running Ray Core's doctests
for a test its own docstring describes as hermetic, while never running
the step that executes it. Rules for absent paths are inert, so there's
no ordering dependency: this PR doesn't touch `doc.rayci.yml`, #64458
doesn't touch `test.rules.txt`, and whichever lands first the other
merges correctly scoped.
- **Declined:** fanning `doc/test_myst_doc.py` out to all five
`<lib>_doc` tags. It backs 19 targets across every team, but it's shared
infrastructure, so a break surfaces in core as readily as anywhere. One
library's worth of execution is a sufficient smoke signal and the
post-merge build covers the rest. The rule carries a comment recording
that trade and when to revisit it.

### Effect on a doc-only PR (no `docs-go`)

| Change | Before | After |
|---|---|---|
| A Serve doc example | every team's `doc tests` step | `serve: docs
example tests` and its GPU sibling |
| A Data doc example | every team's `doc tests` step | `data: docs
example tests`, plus the dask and GPU siblings |
| An image under a library doc dir | that library's example step |
nothing |
| A Sphinx build module (`custom_directives.py` etc.) | `core: docs
example tests` | `doc: build` only (post-merge) |
| A gallery config (`examples.yml`) | that library's example step |
`doc: build` only (post-merge) |
| Editing `doc/BUILD.bazel` | nothing (rule was dead) | the doc example
steps it defines |
| The two `doc: check API*` checks | ran, via the blanket `doc` tag |
don't run (see reviewer summary) |

The GPU and dask siblings carry `<lib>_doc` too, and tag matching is a
non-empty intersection, so they're selected alongside the main step.
That's unchanged behavior: they carried the blanket `doc` tag before, so
a doc change already started them. No new GPU cost.

## Verification

**Rule conformance, under the authoritative evaluator.** `test-rules` is
green on this PR. It replays all 103 `test.rules.test.txt` assertions
through the pinned `rayci` binary, and `runTestRules` compares the full
computed tag set per path, so every case is also a negative assertion
that no other tag fires.

**Tag-to-step resolution, generated locally.** The tag set isn't the
step set: rayci filters steps by tag, then `markDeps` pulls in
everything reachable through `depends_on` regardless of that step's own
tags. To confirm the composition rather than infer it, I ran the pinned
`rayci v0.46.0` release binary against a one-file Serve doc-example
change, on master and on this branch:

```
before (base=master)
  changed files: [doc/source/serve/doc_code/app_builder.py]
  selected tags: always doc lint
  doc-related steps emitted:
    core: doc tests [g6_s22]             ml: doc tests [g13_s26]
    data: doc tests [g7_s21]             rllib: doc tests [g15_s8]
    data: dask doc tests [g7_s22]        serve: doc tests [g16_s12]
    data: doc gpu tests [g7_s23]         serve: doc gpu tests [g16_s21]
    doc: check API annotations [g9_s3]   doc: check API doc consistency [g9_s4]

after (this branch)
  changed files: [doc/source/serve/doc_code/app_builder.py]
  selected tags: always lint serve_doc
  doc-related steps emitted:
    serve: docs example tests [g16_s12]
    serve: docs example gpu tests [g16_s21]
```

Six teams' example steps collapse to the owning team's two, and the step
IDs are unchanged across the rename.

**Routing versus coverage.** Correct routing isn't sufficient: the step
that starts still has to select the target. `ci/ray_ci/tester.py`
filters by `attr(tags, 'team:<team>')`, then intersects `--only-tags`
and subtracts `--except-tags`, so a change can route perfectly, start
the right-looking step, and be invisible to every command in it. I swept
all 948 (file, target) claims under `doc/` against the per-team filters.
After the exceptions above, the only deliberate team mismatch left is
`doc/test_myst_doc.py`. Two pre-existing gaps fell out, neither created
by this change:

- **GPU-tagged ml and core doc examples have no owning step** — six
`team:ml` notebooks tagged `gpu`, five `team:core` `doc_code` modules
tagged `multi_gpu`, and one `post_wheel_build` module. `data` and
`serve` each have a GPU doc-example step; ml and core never got one, so
the only steps that would run these are gated on `train_gpu` and
`cgraphs_direct_transport`, which no doc path emits. No `doc`-tagged
step ran them before the split either. This needs a REEf and
library-team decision rather than a rules change.
- **Prose doctests aren't triggered by prose edits.** The
`doc/BUILD.bazel` `doctest` targets over `doc/source/**/*.{md,rst}` are
reachable only from the `others.rayci.yml` step gated on `python`, while
prose paths hit the leading skip rule. Roughly 700 files. I consider
this correct as-is: given current coverage the Read the Docs render
build is the gate a prose change needs.

**Also swept** all 1,628 tracked `doc/` files against the previous rules
to confirm exactly which paths changed routing and that nothing else
moved.

## Change log

Consolidated above; kept here so the review history stays legible.

- `6a1310d3b5` — the split: per-library tags, path routing, rename,
`BUILD.bazel` rule fix.
- `c6302c8a21`, `b1d03629cf` — first bot-review pass: static images
skip; Sphinx build modules route to `doc`.
- `99c3af2c28` — pre-route the `llms.txt` extension test and summary
ahead of #64458.
- `3795c6161b` — skip `doc/.claude/`; route the `team:ml` `ray-core`
notebooks to `ml_doc`.
- `e88e8a4b52` — remove a stray `TEMP(do-not-merge)` marker that reached
master with #65040. Inert, and independent of this PR's thesis; happy to
split it out.
- `f8347baf54` — second bot-review pass: gallery configs to `doc`;
correct `highly_parallel.ipynb` to `doc`.
- `6a050a0511` — route `doc/external/` to `ml_doc` so the hash guard
still runs.

## AI assistance

This change was drafted with AI assistance (Claude Code) and reviewed by
me.

---------

Signed-off-by: Douglas Strodtman <[email protected]>
@dstrodtman
dstrodtman force-pushed the djs-260716-docs-api-go-label branch from 725125f to 1700f32 Compare August 5, 2026 14:04
Comment thread ci/pipeline/test_doc_api_rules_sync.py Resolved
@dstrodtman
dstrodtman force-pushed the djs-260716-docs-api-go-label branch from 1700f32 to 1f3a92e Compare August 5, 2026 14:26
@dstrodtman dstrodtman changed the title [ci] Add docs-api-go label to re-run API-surface checks under docs-go [ci] Route API reference pages and autodoc machinery to the API-surface checks Aug 5, 2026

@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

Reviewed by Cursor Bugbot for commit 1f3a92e. Configure here.

Comment thread .buildkite/test.rules.test.txt Resolved
@dstrodtman dstrodtman removed the go add ONLY when ready to merge, run all tests label Aug 5, 2026
…ce checks

The two API-surface checks cross-check every @publicapi symbol against the
autosummary pages documenting it. They currently fire on the wrong set of
changes in both directions.

They miss changes they should catch. API reference pages are .rst and .md, so
the leading prose-and-image skip rule matches them first and an edit to
doc/source/data/api/api.rst triggers no premerge step at all. The same holds
for the checker's own source under ci/ray_ci/doc/, which reaches the general
tools rule but nothing that runs the checks it implements.

They also fire on changes that cannot affect the API surface. Both steps carry
the blanket doc tag, and since ray-project#64775 reserved doc for documentation
validation that tag covers a mixed population: the autodoc machinery that
decides what the API reference contains, and rendering config that cannot
change it. A Vale vocabulary tweak or a gallery config edit pays for a
docbuild plus both checks.

Declare a doc_api tag and route to it everything that can change the
documented API surface or how it is computed: the six per-team API reference
directories (matching API_PATH_PREFIXES in doc/source/_ext/api_sidebar.py)
plus ray-observability/reference/, which Ray Core's api/index.rst toctrees
into; the autodoc machinery conf.py, api_autogen.py, api_mock_imports.py,
custom_directives.py, doc/source/_ext/ and requirements-doc.txt; the docs
dependency locks, which pin the Sphinx version that generates the stubs;
ci/ray_ci/doc/; and doc.rayci.yml, so editing a check's step definition
exercises that check. The doc-build infra block splits accordingly: part 1
emits doc doc_api, part 2 emits doc alone.

ci/ray_ci/doc/ keeps tools alongside doc_api. It declares six ci_unit py_test
targets and the job running ci_unit is selected by tools, so dropping it would
mean editing the checker never runs the checker's unit tests.

The two steps then keep their library tags plus doc_api and drop the bare doc
tag. They also drop their docs-go if: guard, so their trigger set is defined
entirely by tags. Tag selection and Buildkite if: are separate passes -- tags
choose which steps are emitted, if: can only suppress an already-emitted step
-- so a label guard could only subtract from a trigger set the rules now
compute correctly. docs-go exists to skip the per-team doc example execution
on a content-only PR, and an API reference page edit is precisely the
content-only change these checks must still cover.

Across all 10213 tracked files the change is purely additive: 95 files gain
tags and none lose any. 67 API reference pages go from no tags to doc_api, 16
under ci/ray_ci/doc/ gain doc_api on top of tools, and 9 machinery files plus
3 dependency files gain doc_api on top of doc. No executable asset lives under
the routed API directories, so no library docs-example step loses coverage.

Signed-off-by: Douglas Strodtman <[email protected]>
The doc_api rules are two hand-maintained lists, and both fail silently when
they drift. A missing entry means the paths stay prose-skipped or fall to a
catch-all, so the API-consistency checks quietly stop covering them. Nothing
errors; coverage just shrinks.

Add a ci_unit test with one check per list.

The page list duplicates API_PATH_PREFIXES in doc/source/_ext/api_sidebar.py,
the source of truth for "this page documents public API surface." Read both
sets and fail when they diverge. Two documented exceptions: apis/ is
prefix-only, being curated navigation with no autosummary directives, and
ray-observability/reference/ is rule-only, because Ray Core's api/index.rst
toctrees into it from outside ray-core/api/.

The machinery list can't be replaced by a pattern, since fnmatch * crosses /
and doc/source/*.py would swallow every example script under
doc/source/<lib>/doc_code/. So require every local module conf.py imports to
be routed to doc_api or named in an explicit rendering-only exception list.
Today that exception is template_collections, which fetches example templates
and cannot change which symbols autodoc resolves. Without this check, a new
conf.py import lands on the doc/*.py catch-all and emits core_doc: it would
run Ray Core's doctests and examples while never running the documentation
build or the API checks.

The import scan decides "is this local" by resolving each name under
doc/source/, so it needs those files in the sandbox and would pass vacuously
without them. doc/BUILD.bazel exports them as a globbed filegroup rather than
individual data deps, because a new machinery module is exactly what the test
exists to catch and cannot be named ahead of being written.
_MACHINERY_IMPORT_FLOOR asserts the four known imports are found, turning a
data-dep regression into a failure instead of a silent no-op.

Both checks were verified against mutated copies of the tree: a new
API_PATH_PREFIXES entry with no rule, a rule directory absent from the
prefixes, a removal from either side, an unlisted machinery directory in the
doc_api block, a new unrouted conf.py import, a machinery module demoted to
the doc-only block, and a sandbox missing doc/source/*.py are all caught,
while a correctly routed or explicitly allowlisted new import passes.

Signed-off-by: Douglas Strodtman <[email protected]>
@dstrodtman
dstrodtman force-pushed the djs-260716-docs-api-go-label branch from 1f3a92e to e0d5203 Compare August 5, 2026 14:44
The doc_api drift guard (//ci/pipeline:test_doc_api_rules_sync) compares
API_PATH_PREFIXES in doc/source/_ext/api_sidebar.py against the doc_api rule
dirs in test.rules.txt. It is a ci_unit target, and ci_unit is selected by
`tools`.

test.rules.txt itself emits `tools`, so the guard ran on an edit to the rules
side. api_sidebar.py emitted only `doc doc_api`, so it did not run on an edit to
the prefixes side -- growing API_PATH_PREFIXES without adding the matching rule
never executed the guard, which is precisely the drift it exists to catch.

Add a file rule for api_sidebar.py emitting `doc doc_api tools`, placed ahead of
the doc/source/_ext/ directory entry since first match wins, plus a replay case
locking in the tag set.

Also drop four duplicated assertions in test.rules.test.txt (.vale.ini,
.readthedocs.yaml, doc/rtd_doctor.py, doc/source/template_collections.py) that
were already asserted elsewhere in the file, and reword the boundary comment to
point at the surviving cases.

Verified: check_rules clean; replay 115/115; drift-guard pytest passes; every
master assertion preserved with all 8 changes pure tag additions; full sweep of
10,213 tracked files shows exactly one delta, api_sidebar.py gaining `tools`.

Signed-off-by: Douglas Strodtman <[email protected]>
@dstrodtman dstrodtman added the go add ONLY when ready to merge, run all tests label Aug 5, 2026
@dstrodtman
dstrodtman merged commit 127c512 into ray-project:master Aug 5, 2026
7 checks passed
Artimislyy pushed a commit to Artimislyy/ray that referenced this pull request Aug 11, 2026
…per library (ray-project#64775)

## Reviewer summary

**What this does.** The per-team `X: doc tests` steps are library
example and doctest suites that live under `doc/`. They exercise library
code, not documentation quality. Today every executable doc asset emits
the blanket `doc` tag and all six teams' steps are tagged `doc`, so a
one-library doc change starts every team's step. This gives each step a
dedicated `<lib>_doc` tag, routes `doc/source/<lib>/**` to the owning
library's tag, renames the steps to `X: docs example tests`, and leaves
`doc` for documentation validation (the build and the Vale/config
infra). The library tag stays on each step, so a library **code** change
runs its doc example tests exactly as before.

**What's verified.**

| Claim | Evidence |
|---|---|
| Each path emits exactly the intended tag, and no other | `test-rules`
green on this PR. That's the pinned `rayci` binary replaying all 103
`test.rules.test.txt` assertions (up from 57 on master) with **exact set
equality**, so each case also proves the blanket `doc` tag does *not*
come along. |
| The emitted tags resolve to the intended steps, and only those |
Generated the real pipeline locally with the pinned `rayci v0.46.0`
release binary for a one-file Serve doc-example change, before and after
this branch. Output below. |
| The renamed steps still run and pass | All five plus the GPU and dask
siblings green on this PR, selected via the library tags this change
preserves. |
| Every executable target under `doc/` routes to a step that can
actually select it | Swept all 948 (file, target) claims against the
per-team `team:` / `--only-tags` / `--except-tags` filters. One
deliberate exception (`doc/test_myst_doc.py`, below) and two
pre-existing gaps that this change doesn't create. |
| The rename doesn't reset step identity | rayci derives step IDs
positionally (`fmt.Sprintf("g%d_s%d", i, j)`, `converter.go`), not from
the label. The generated pipelines confirm it: `g16_s12`, `g16_s21`,
`g6_s22`, `g13_s26` are identical before and after. |

**What I need from a reviewer.**

1. **One question I can't answer from inside the repo.**
`ci/build/get_build_info.py` sets `config.env` to `"Buildkite " +
BUILDKITE_LABEL`, and `ci/build/upload_build_info.sh` uploads it on
postmerge pipelines on `master` only. Does anything downstream of that
`metadata.json` treat `config.env` as an identity or grouping key? If
it's descriptive, renaming five steps is free. If something groups on
it, those five steps' postmerge history splits at the merge commit.
Flaky-test selection and target selection both key on `team` (unchanged
here) and test identity is the bazel target name (`f"{system}:{name}"`
in `release/ray_release/test.py`), so I believe `config.env` is the only
place the label escapes.
1. **Confirm the API-check behavior change below is acceptable.**
1. **Confirm the catch-all owner.** Executable doc assets in directories
with no per-team step route to the core step: roughly 25 files, being 18
`doc/source/templates/*/start.ipynb` plus a handful under
`doc/source/cluster/doc_code/`, `doc/source/ray-contribute/doc_code/`,
and `doc/source/_templates/`. The templates majority may be retired or
externally managed, in which case a skip rule is the better answer than
core ownership.

**Known behavior change worth your eyes.** Because
`doc/source/<lib>/doc_code/` and `examples/` now emit `<lib>_doc`
instead of `doc`, the two API-surface checks (`doc: check API
annotations`, `doc: check API doc consistency`) stop running on library
doc-example changes. They carry the blanket `doc` tag among their
library tags, so today a `doc_code` edit incidentally triggers a
premerge `make -C doc/ html`. I think that's correct: those checks guard
the documented public API surface, which a doc example can't change, and
the example itself is still executed by the owning library's step while
the render is gated by Read the Docs. But it is a premerge signal that
disappears, so it should be a decision rather than a side effect. Raised
on ray-project#64812, which routes the API **reference** pages to a dedicated
`doc_api` tag for the related case.

**Out of scope, tracked separately.** `.buildkite/others.rayci.yml:13`
declares a sixth step labeled `doc tests`, running `//python/ray/...
//doc/... none --only-tags doctest` and tagged `python`, a tag no rule
in `test.rules.txt` emits. Generating the full-fan-out pipeline shows it
does get emitted (`doc tests [g14_s1]`), so it is live. After this
rename it becomes the only step in the repo still called "doc tests."
This PR doesn't touch `others.rayci.yml` and the fix is independent.

---

## What this changes

1. **Dedicated per-library tag.** Each step gets a `<lib>_doc` tag
(`core_doc`, `data_doc`, `ml_doc`, `rllib_doc`, `serve_doc`) and drops
the blanket `doc` tag. The library tag stays.
1. **Path routing.** `test.rules.txt` routes `doc/source/<lib>/**` to
that library's tag, so a doc change runs only the owning library's
example tests. LLM doc assets already route to `llm` and keep doing so.
1. **`doc` reserved for validation.** It now stays only on the
documentation build and the Vale/config infra.
1. **Rename** to `X: docs example tests`, since a failure in these steps
means library code or an example broke, not that the docs are wrong.
1. **Build-file rule fix.** `test.rules.txt` matched `doc/BUILD` and
`doc/*/BUILD`, but the files are `BUILD.bazel`, so editing a file that
*defines* the doc test targets ran no doc tests premerge. It now matches
the `.bazel` files and routes them to the same per-library steps. The
root `doc/BUILD.bazel` defines every library's targets, so it routes to
all of them.

### Scoping exceptions, and why each exists

Several paths sit under a library doc directory but can't be
meaningfully tested by that library's example step, so they're routed
explicitly rather than by directory:

- **Static images skip entirely.** Image extensions sit on the leading
skip rule, ahead of the per-library rules, so a `.png` or `.svg` edit
triggers nothing. 310 tracked image files. `.yaml` and `.sh` stay
routed, since unlike an image they can change what a test does.
- **Sphinx build machinery routes to `doc`.** `conf.py` imports
`custom_directives`, `api_autogen`, `api_mock_imports`, and
`template_collections`; none was listed in the validation-infra rule, so
all fell to the `doc/*.py` catch-all and emitted `core_doc`, running Ray
Core's doctests for a docs-build-machinery edit. Those four plus
`preprocess_github_markdown` and the doc-root build helpers now route to
`doc`. They're enumerated one per line on purpose: `*` is fnmatch here
and crosses `/`, so a `doc/source/*.py` pattern would also swallow every
example script under `doc/source/<lib>/doc_code/`. There's a comment on
the rule saying so.
- **Gallery configs route to `doc`.**
`doc/source/{data,serve,train}/examples.yml` are parsed by
`custom_directives.py` (`EXAMPLE_GALLERY_CONFIGS`) to generate the
gallery pages. They hold no executable code and can't change what any
example does. Narrowed to a three-path exception rather than a blanket
`.yml` skip, because a sibling `.yml` under a library doc directory can
be a config an example consumes.
- **`doc/.claude/` triggers nothing.** Agent files never participate in
the Sphinx build and define no test targets, but
`doc/.claude/skills/sphinx-fix/sphinx_fix.py` matched the `doc/*.py`
catch-all. The Read the Docs build guard already excludes this exact
path for the same reason, so the two guards now agree. Pre-existing
rather than a regression from this PR: on master the file emits the
blanket `doc` tag, which reaches all five per-team steps.
- **Four `team:ml` notebooks under `ray-core/` route to `ml_doc`.**
`plot_hyperparameter`, `batch_prediction`, `plot_parameter_server`, and
`plot_pong_example` live under `doc/source/ray-core/examples/` but their
targets are tagged `team:ml`, and the team argument to
`//ci/ray_ci:test_in_docker` filters targets by `team:<team>`
(`_get_all_test_query`, `ci/ray_ci/tester.py`). Routing them to
`core_doc` would run a step that tests everything under `ray-core/`
except the file that changed. Re-tagging the four `team:core` in
`doc/BUILD.bazel` is the alternative fix and would let the rule lines go
away.
- **`highly_parallel.ipynb` routes to `doc`.** Its `py_test` carries a
`highly_parallel` tag that the ml docs example step excludes, and the
notebook glob in `doc/source/ray-core/examples/BUILD.bazel` excludes it
too, as a release test needing a live multi-node cluster. The remaining
ml `//doc/...` steps select `gpu` / `train_v2_gpu` and the target has
neither, so no premerge step executes it. Routing to `doc` means the
build renders it (`nb_execution_mode` defaults to `off`, so
render-and-lint only), which is the only validation premerge offers
here.
- **`doc/external/` routes to `ml_doc`.** Its `test_external_hashes`
target is tagged `team:ml`; it had fallen through the `doc/*.py`
catch-all to `core_doc`, where the core step's `team:core` query never
sees it.
- **The `llms.txt` files route to `doc`.** ray-project#64458 adds
`doc/test_llms_txt.py` and `doc/source/llms_txt_summary.txt` with no
`test.rules.txt` change. Left alone the test would land on the
`doc/*.py` catch-all and emit `core_doc`, running Ray Core's doctests
for a test its own docstring describes as hermetic, while never running
the step that executes it. Rules for absent paths are inert, so there's
no ordering dependency: this PR doesn't touch `doc.rayci.yml`, ray-project#64458
doesn't touch `test.rules.txt`, and whichever lands first the other
merges correctly scoped.
- **Declined:** fanning `doc/test_myst_doc.py` out to all five
`<lib>_doc` tags. It backs 19 targets across every team, but it's shared
infrastructure, so a break surfaces in core as readily as anywhere. One
library's worth of execution is a sufficient smoke signal and the
post-merge build covers the rest. The rule carries a comment recording
that trade and when to revisit it.

### Effect on a doc-only PR (no `docs-go`)

| Change | Before | After |
|---|---|---|
| A Serve doc example | every team's `doc tests` step | `serve: docs
example tests` and its GPU sibling |
| A Data doc example | every team's `doc tests` step | `data: docs
example tests`, plus the dask and GPU siblings |
| An image under a library doc dir | that library's example step |
nothing |
| A Sphinx build module (`custom_directives.py` etc.) | `core: docs
example tests` | `doc: build` only (post-merge) |
| A gallery config (`examples.yml`) | that library's example step |
`doc: build` only (post-merge) |
| Editing `doc/BUILD.bazel` | nothing (rule was dead) | the doc example
steps it defines |
| The two `doc: check API*` checks | ran, via the blanket `doc` tag |
don't run (see reviewer summary) |

The GPU and dask siblings carry `<lib>_doc` too, and tag matching is a
non-empty intersection, so they're selected alongside the main step.
That's unchanged behavior: they carried the blanket `doc` tag before, so
a doc change already started them. No new GPU cost.

## Verification

**Rule conformance, under the authoritative evaluator.** `test-rules` is
green on this PR. It replays all 103 `test.rules.test.txt` assertions
through the pinned `rayci` binary, and `runTestRules` compares the full
computed tag set per path, so every case is also a negative assertion
that no other tag fires.

**Tag-to-step resolution, generated locally.** The tag set isn't the
step set: rayci filters steps by tag, then `markDeps` pulls in
everything reachable through `depends_on` regardless of that step's own
tags. To confirm the composition rather than infer it, I ran the pinned
`rayci v0.46.0` release binary against a one-file Serve doc-example
change, on master and on this branch:

```
before (base=master)
  changed files: [doc/source/serve/doc_code/app_builder.py]
  selected tags: always doc lint
  doc-related steps emitted:
    core: doc tests [g6_s22]             ml: doc tests [g13_s26]
    data: doc tests [g7_s21]             rllib: doc tests [g15_s8]
    data: dask doc tests [g7_s22]        serve: doc tests [g16_s12]
    data: doc gpu tests [g7_s23]         serve: doc gpu tests [g16_s21]
    doc: check API annotations [g9_s3]   doc: check API doc consistency [g9_s4]

after (this branch)
  changed files: [doc/source/serve/doc_code/app_builder.py]
  selected tags: always lint serve_doc
  doc-related steps emitted:
    serve: docs example tests [g16_s12]
    serve: docs example gpu tests [g16_s21]
```

Six teams' example steps collapse to the owning team's two, and the step
IDs are unchanged across the rename.

**Routing versus coverage.** Correct routing isn't sufficient: the step
that starts still has to select the target. `ci/ray_ci/tester.py`
filters by `attr(tags, 'team:<team>')`, then intersects `--only-tags`
and subtracts `--except-tags`, so a change can route perfectly, start
the right-looking step, and be invisible to every command in it. I swept
all 948 (file, target) claims under `doc/` against the per-team filters.
After the exceptions above, the only deliberate team mismatch left is
`doc/test_myst_doc.py`. Two pre-existing gaps fell out, neither created
by this change:

- **GPU-tagged ml and core doc examples have no owning step** — six
`team:ml` notebooks tagged `gpu`, five `team:core` `doc_code` modules
tagged `multi_gpu`, and one `post_wheel_build` module. `data` and
`serve` each have a GPU doc-example step; ml and core never got one, so
the only steps that would run these are gated on `train_gpu` and
`cgraphs_direct_transport`, which no doc path emits. No `doc`-tagged
step ran them before the split either. This needs a REEf and
library-team decision rather than a rules change.
- **Prose doctests aren't triggered by prose edits.** The
`doc/BUILD.bazel` `doctest` targets over `doc/source/**/*.{md,rst}` are
reachable only from the `others.rayci.yml` step gated on `python`, while
prose paths hit the leading skip rule. Roughly 700 files. I consider
this correct as-is: given current coverage the Read the Docs render
build is the gate a prose change needs.

**Also swept** all 1,628 tracked `doc/` files against the previous rules
to confirm exactly which paths changed routing and that nothing else
moved.

## Change log

Consolidated above; kept here so the review history stays legible.

- `6a1310d3b5` — the split: per-library tags, path routing, rename,
`BUILD.bazel` rule fix.
- `c6302c8a21`, `b1d03629cf` — first bot-review pass: static images
skip; Sphinx build modules route to `doc`.
- `99c3af2c28` — pre-route the `llms.txt` extension test and summary
ahead of ray-project#64458.
- `3795c6161b` — skip `doc/.claude/`; route the `team:ml` `ray-core`
notebooks to `ml_doc`.
- `e88e8a4b52` — remove a stray `TEMP(do-not-merge)` marker that reached
master with ray-project#65040. Inert, and independent of this PR's thesis; happy to
split it out.
- `f8347baf54` — second bot-review pass: gallery configs to `doc`;
correct `highly_parallel.ipynb` to `doc`.
- `6a050a0511` — route `doc/external/` to `ml_doc` so the hash guard
still runs.

## AI assistance

This change was drafted with AI assistance (Claude Code) and reviewed by
me.

---------

Signed-off-by: Douglas Strodtman <[email protected]>
Artimislyy pushed a commit to Artimislyy/ray that referenced this pull request Aug 11, 2026
…ce checks (ray-project#64812)

## The problem

Two premerge checks in `.buildkite/doc.rayci.yml` cross-check every
`@PublicAPI` symbol against the autosummary pages that document it:

- `doc: check API annotations`
- `doc: check API doc consistency`

They currently run on the wrong set of changes, in both directions.

**They miss changes they should catch.** API reference pages are `.rst`
and `.md`, so the leading prose-and-image skip rule in `test.rules.txt`
matches them first. Editing `doc/source/data/api/api.rst` changes the
documented public API surface and triggers **no premerge step at all**.

**They run on changes that can't affect the API surface.** Both steps
carry the blanket `doc` tag. Since ray-project#64775 reserved `doc` for
documentation validation, that tag now covers two unlike things: the
autodoc machinery that decides what the API reference *contains*, and
rendering config that can't change it. So a Vale vocabulary tweak pays
for a `docbuild` plus both checks.

## The fix

Add a `doc_api` tag, and route to it everything that can change the
documented API surface or how it's computed. Then take the blanket `doc`
tag off the two steps.

| A change to | today | with this PR |
|---|---|---|
| An API reference page | **skip** | run |
| The checker's own source (`ci/ray_ci/doc/`) | **skip** | run |
| `conf.py`, `api_autogen.py`, `api_mock_imports.py`, `_ext/` | run |
run |
| Docs dependency locks (`deplocks/docs/*.lock`) | run | run |
| Library Python source | run | run |
| `.vale.ini`, Vale vocabularies | run | **skip** |
| `rtd_doctor.py`, `template_collections.py` | run | **skip** |
| `.readthedocs.yaml`, gallery configs | run | **skip** |
| Narrative prose, images | skip | skip |

## What's in the diff

Three commits, 7 files.

1. **`a0b545cc3e`** declares `doc_api` and routes the six per-team API
reference directories to it, ahead of the skip rule. Also splits the
doc-build infra block in two: the autodoc machinery emits `doc doc_api`,
the rendering-only half emits `doc` alone. Then drops the bare `doc` tag
from both check steps.

2. **`e0d520381d`** adds two drift guards in
`//ci/pipeline:test_doc_api_rules_sync`. Both `doc_api` lists are
hand-maintained and fail *silently* when they drift — a missing entry
means those paths quietly stop being checked. One guard keeps the page
list aligned with `API_PATH_PREFIXES` in
`doc/source/_ext/api_sidebar.py`. The other requires every local module
`conf.py` imports to be routed to `doc_api` or named as an explicit
rendering-only exception.

3. **`f3db137384`** routes `api_sidebar.py` to `tools` as well, so the
first guard actually runs. It was one-directional before:
`test.rules.txt` emits `tools`, so the guard fired on a rules-side edit,
but `api_sidebar.py` didn't, so growing `API_PATH_PREFIXES` without the
matching rule never executed it — the likelier mistake, and exactly the
drift the guard exists to catch. Also removes four duplicated
assertions.

Three details worth knowing, since each looks like an oversight
otherwise:

- **`ci/ray_ci/doc/` keeps `tools` alongside `doc_api`.** It declares
six `ci_unit` `py_test` targets and `tools` is what selects the job that
runs them, so dropping it would mean editing the checker never runs the
checker's own unit tests.
- **`doc.rayci.yml` also emits `doc_api`,** so editing a check's step
definition exercises the check it defines.
- **`doc/source/ray-observability/reference/` is routed even though it
sits outside `doc/source/*/api/`.** Ray Core's `api/index.rst` toctrees
into its `api.rst`, so it's part of the Core API-surface walk.

## Testing

`test.rules.test.txt` gains cases for the API pages (including a nested
leaf page, to pin recursive directory matching), the checker source,
each machinery path, and negative cases asserting the rendering half
still emits `doc` alone. **These are the real gate:** the `test-rules`
step runs them through rayci's parser as exact set equality, so a
passing case proves a path emits precisely those tags and nothing else.

Locally, against the in-repo reference engine
(`ci/pipeline/determine_tests_to_run.py`):

- `check_rules()` passes; **115 of 115** replay cases pass.
- Across all 10,213 tracked files the routing change is **purely
additive: 95 files gain tags, none lose any.**
- No executable asset (`.py`, `.ipynb`) lives under the routed API
directories, so no library docs-example step loses coverage.

```
python -m pytest ci/pipeline/test_doc_api_rules_sync.py
```

## Two notes for reviewers

**One behavior change to sanity-check.** Neither check carries an `if:`
guard now, including the `docs-go` one they had before. A content-only
PR labeled `docs-go` that touches an API reference page will run both
checks plus their `docbuild` dependency, where it previously skipped
them. That's intended — `docs-go` exists to skip per-team doc *example
execution*, and an API reference edit is exactly the content-only change
these checks must still cover — but it's a real cost change for that
workflow. `docs-go` keeps its role everywhere else: 12 per-team doc
example steps across `core`, `data`, `llm`, `ml`, `rllib`, `serve`, and
`linux_aarch64`, plus the `lint: validate docs-go scope` step that
enforces the label is only used on doc-only PRs.

**This PR changed shape, so earlier comments describe an older design.**
It began as a `docs-api-go` PR label that would re-enable the checks on
a `docs-go` PR. That's removed: tag selection and Buildkite `if:` are
separate passes, and `if:` can only suppress a step the tags already
emitted, so with the routing correct the label could only ever subtract.
Dropping the `if:` achieves the same thing with no label to create or
remember. Consequently the earlier Gemini review and the 2026-08-04
comment above both reference a `docs-api-go` label that no longer
exists. Everything else in that comment still stands, including its
decision that `doc_code/` and `examples/` should *not* grow into
`doc_api`.

🤖 Written with assistance from Claude Code.

---------

Signed-off-by: Douglas Strodtman <[email protected]>
dstrodtman added a commit that referenced this pull request Aug 14, 2026
## Why are these changes needed?

The YAML under `doc/redirects/` is the source of truth for the
docs.ray.io Read the Docs redirect configuration, managed with
[rtd-redirects](https://github.com/anyscale/rtd-redirects). Today a PR
that edits only redirect YAML runs no check at all, so a malformed or
unreachable redirect can merge unnoticed.

Nothing routes redirect YAML anywhere. `.yaml` isn't covered by the
leading prose-and-image skip rule, nor by the
`doc/*.py`/`doc/*.ipynb`/`doc/*/BUILD.bazel` catch-all, so it falls
through to the broad `doc/` pass rule at the bottom of the doc section
and emits no tag at all. Confirmed against the rule engine on master:
`doc/redirects/current.yaml` emits `set()`.

This adds a lightweight, credential-free premerge gate for
`doc/redirects/*.yaml` that validates the redirects and prints the
redirect-level diff. The change is purely additive: it gives redirect
YAML a check where it previously had none, and no other path's selection
changes.

## What changed

- **`.buildkite/test.rules.txt`** — declare a `doc_redirects` test tag
and route `doc/redirects/*.yaml` to it. The rule sits ahead of every
`doc/` rule, which matters because the final `doc/` pass rule is what
currently swallows these files.

The rule emits `doc_redirects` alone, deliberately not `doc` or
`doc_api`. A redirect edit can't change the documented API surface, and
the check needs neither a rendered documentation build nor a compiled
Ray: it parses the YAML and diffs it against the base ref.
- **`.buildkite/test.rules.txt`** — route `.buildkite/doc.rayci.yml` to
`doc_redirects` as well, on its own rule rather than by extending the
autodoc-machinery block, so a `conf.py` edit doesn't start running the
redirect check. An edit to a step definition has to be able to select
the step it edits, which is the same reason that file already emits
`doc_api`. This also covers the `anyscale-rtd-redirects` version pin,
which lives in the redirect step's commands, so a version bump re-runs
the check.
- **`.buildkite/test.rules.test.txt`** — three cases:
`doc/redirects/current.yaml: doc_redirects`, `doc/redirects/README.md:`
asserting the prose beside it stays unrouted, and
`.buildkite/doc.rayci.yml: doc doc_api doc_redirects`. The last one
revises an assertion that already existed on master, since that file's
tag set genuinely changes here.
- **`.buildkite/doc.rayci.yml`** — add a `forge`-based step (no doc
image) that installs the pinned `anyscale-rtd-redirects==0.2.0` from
PyPI and runs:
  ```
  rtd-redirects validate doc/redirects/current.yaml
rtd-redirects diff-file --file doc/redirects/current.yaml --base
FETCH_HEAD --head HEAD --repo .
  ```
The step diffs against `FETCH_HEAD` after fetching the PR's base branch,
rather than against `origin/<base>`: a clone with a restricted refspec
may never create a local remote-tracking ref, and
`doc/test_no_new_rst.py` already solves the same problem the same way.
The base branch resolves at runtime from
`$${BUILDKITE_PULL_REQUEST_BASE_BRANCH:-master}`, escaped so the shell
expands it rather than Buildkite interpolating it at pipeline-upload
time, matching the `$${...}` convention used across the other pipeline
files.

The step also fails closed if `doc/redirects/` grows a YAML file the
commands don't name. The tag selects on a glob, but multiple redirect
files compose in the order given and a shell glob can't express that
order, so the guard forces the compose-order decision to be made
explicitly instead of letting a new file select the step and then go
unvalidated.

## Verification

Verified with Ray's rule parser
(`ci/pipeline/determine_tests_to_run.py`), the same first-match-wins
engine rayci uses:

- `check_rules()` parses clean, and all 126 cases in
`test.rules.test.txt` replay green. That file is enforced by the
`test-rules` CI step, and rayci asserts exact set equality, so a passing
case proves the path emits exactly those tags and nothing else.
- A sweep of all 10,333 tracked files against master shows **exactly two
deltas** — `doc/redirects/current.yaml` gaining `doc_redirects`, and
`.buildkite/doc.rayci.yml` gaining it alongside its existing `doc
doc_api` — and **zero tag losses** on any path. Every pre-existing
assertion in `test.rules.test.txt` is preserved except the
`doc.rayci.yml` one this PR deliberately revises.
- Ran the step's commands locally in a clean venv with
`anyscale-rtd-redirects==0.2.0` against the current
`doc/redirects/current.yaml`: `validate` reports 0 errors (49 chain
warnings, informational), and `diff-file --base FETCH_HEAD` reports the
redirect-level diff and exits 0 with no Read the Docs credentials.
- Exercised the drift guard both ways: it passes with only
`current.yaml` present and exits non-zero when a second
`doc/redirects/*.yaml` appears.

Because `.buildkite/doc.rayci.yml` now emits `doc_redirects`, **this PR
selects the new step and runs it**. Replaying this PR's own changed
files through the rule engine gives a tag union of `doc`, `doc_api`,
`doc_redirects`, and `tools`, so the step's commands are exercised in CI
here rather than only on some later PR that happens to edit redirect
YAML. It runs against an unchanged `current.yaml`, so `diff-file`
reports an empty redirect diff and exits 0, which is exactly the smoke
test that catches a typo in the step definition.

## Update: rebased onto the doc-tag reorg

Rebased after #64775 and #64812 landed, which reorganized the doc tags:
doc example tests moved to per-library `<lib>_doc` tags, and `doc` was
split so the autodoc machinery emits `doc doc_api` while the
rendering-only surface emits `doc`. This branch's four commits (one an
upstream merge) are collapsed into one. Two conflicts in
`test.rules.txt` (the tag declaration line, and the rule insertion
point) and one in `test.rules.test.txt` (three expectations the reorg
had since updated) were resolved in favor of master, then the
`doc_redirects` rule and cases re-applied on top.

The rebase also invalidated this PR's original rationale, so the rule
and step comments have been rewritten. The earlier framing was that
`doc_redirects` keeps redirect YAML from pulling in docbuild, the API
checks, and the per-team doc tests. That's no longer accurate on any of
the three: the per-team tests are selected by `<lib>_doc`, the two API
checks carry `doc_api` plus the library tags and no longer carry bare
`doc`, and the only remaining step carrying bare `doc` is `doc: build`,
which is `skip-on-premerge`. Since redirect YAML emits nothing at all on
master, this rule was never preventing over-triggering. It's additive,
and the comments now say so.

## Update: the step now selects itself

Cursor Bugbot caught that the redirect step wasn't reachable from an
edit to its own definition: `.buildkite/doc.rayci.yml` emitted `doc
doc_api` but never `doc_redirects`, so changing the redirect step's
commands wouldn't have run the redirect step. That contradicted the
rule's own stated reason for emitting `doc_api`, and this PR
demonstrated the gap: its previous revision noted that the new step
didn't execute here.

Fixed by giving `.buildkite/doc.rayci.yml` its own rule emitting `doc
doc_api doc_redirects`. It's a separate rule rather than an extra tag on
the autodoc-machinery block, because that block also covers `conf.py`,
`api_autogen.py`, and `doc/source/_ext/`, and a `conf.py` edit has no
business running the redirect check. The first attempt at this appended
the tag to the shared block and the full-repo sweep caught it
immediately: seven machinery files picked up `doc_redirects`.

AI assistance (Claude Code) was used to draft the CI step, the rebase
conflict resolution, and this description. Every changed line was
reviewed by hand, and the verification above was run as described. This
isn't duplicating existing work: no other open PR adds redirect
validation to premerge, and the `doc_redirects` tag doesn't exist on
master.

## Update: uv, and a recursive fail-closed guard

Two review follow-ups.

**Install with `uv`** (Elliot's suggestion).
`ci/docker/forge.Dockerfile` already installs uv to `/usr/local/bin` and
uses it for the image's Python, so the step needs no extra setup. It's
`uv tool install` rather than `uv pip install --system` for a PATH
reason: the previous revision's premerge log shows `pip install` fell
back to a user install, so the `rtd-redirects` entry point resolved from
`~/.local/bin`. `uv tool install` writes executables to that same
directory, so PATH resolution is unchanged. `uv pip install --system`
would target the uv-managed interpreter and put the entry point in that
env's `bin`, which isn't on PATH.

**The fail-closed guard now recurses.** Cursor Bugbot caught that the
guard's single-level shell glob didn't cover a nested redirect file, and
it was right. The rule engine matches with `fnmatch`, whose `*` crosses
`/`, so `doc/redirects/nested/foo.yaml` emits `doc_redirects` and
selects this step, while `ls doc/redirects/*.yaml` never saw it and the
guard passed. Replacing the glob with `find` closes the gap. Exercised
three ways locally: passes with only `current.yaml`, exits non-zero for
a nested file and for a sibling file.

A `.yml` file stays out of scope. The tag rule matches `*.yaml` only, so
`doc/redirects/current.yml` emits no tags and never selects the step,
putting it beyond the guard's reach. That matches the pre-PR baseline
for every redirect file rather than regressing anything, and
`rtd-redirects` uses `.yaml`.

Re-verified after the change: rules parse clean and all 126 cases in
`test.rules.test.txt` replay green (the rule files are untouched by this
revision).

## Related issue number

N/A

## Checks

- [x] I've signed off every commit (`-s`), because all commits are
squashed into one when merged.
- [x] I've run `scripts/format.sh` to lint the changes in this PR. (Via
`pre-commit`; the applicable hooks pass.)
- [x] I've made sure the tests are passing.
- Testing Strategy
   - [x] Unit tests
   - [ ] Release tests
   - [ ] This PR is not tested :(

---------

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

## Reviewer summary

**What this does.** The per-team `X: doc tests` steps are library
example and doctest suites that live under `doc/`. They exercise library
code, not documentation quality. Today every executable doc asset emits
the blanket `doc` tag and all six teams' steps are tagged `doc`, so a
one-library doc change starts every team's step. This gives each step a
dedicated `<lib>_doc` tag, routes `doc/source/<lib>/**` to the owning
library's tag, renames the steps to `X: docs example tests`, and leaves
`doc` for documentation validation (the build and the Vale/config
infra). The library tag stays on each step, so a library **code** change
runs its doc example tests exactly as before.

**What's verified.**

| Claim | Evidence |
|---|---|
| Each path emits exactly the intended tag, and no other | `test-rules`
green on this PR. That's the pinned `rayci` binary replaying all 103
`test.rules.test.txt` assertions (up from 57 on master) with **exact set
equality**, so each case also proves the blanket `doc` tag does *not*
come along. |
| The emitted tags resolve to the intended steps, and only those |
Generated the real pipeline locally with the pinned `rayci v0.46.0`
release binary for a one-file Serve doc-example change, before and after
this branch. Output below. |
| The renamed steps still run and pass | All five plus the GPU and dask
siblings green on this PR, selected via the library tags this change
preserves. |
| Every executable target under `doc/` routes to a step that can
actually select it | Swept all 948 (file, target) claims against the
per-team `team:` / `--only-tags` / `--except-tags` filters. One
deliberate exception (`doc/test_myst_doc.py`, below) and two
pre-existing gaps that this change doesn't create. |
| The rename doesn't reset step identity | rayci derives step IDs
positionally (`fmt.Sprintf("g%d_s%d", i, j)`, `converter.go`), not from
the label. The generated pipelines confirm it: `g16_s12`, `g16_s21`,
`g6_s22`, `g13_s26` are identical before and after. |

**What I need from a reviewer.**

1. **One question I can't answer from inside the repo.**
`ci/build/get_build_info.py` sets `config.env` to `"Buildkite " +
BUILDKITE_LABEL`, and `ci/build/upload_build_info.sh` uploads it on
postmerge pipelines on `master` only. Does anything downstream of that
`metadata.json` treat `config.env` as an identity or grouping key? If
it's descriptive, renaming five steps is free. If something groups on
it, those five steps' postmerge history splits at the merge commit.
Flaky-test selection and target selection both key on `team` (unchanged
here) and test identity is the bazel target name (`f"{system}:{name}"`
in `release/ray_release/test.py`), so I believe `config.env` is the only
place the label escapes.
1. **Confirm the API-check behavior change below is acceptable.**
1. **Confirm the catch-all owner.** Executable doc assets in directories
with no per-team step route to the core step: roughly 25 files, being 18
`doc/source/templates/*/start.ipynb` plus a handful under
`doc/source/cluster/doc_code/`, `doc/source/ray-contribute/doc_code/`,
and `doc/source/_templates/`. The templates majority may be retired or
externally managed, in which case a skip rule is the better answer than
core ownership.

**Known behavior change worth your eyes.** Because
`doc/source/<lib>/doc_code/` and `examples/` now emit `<lib>_doc`
instead of `doc`, the two API-surface checks (`doc: check API
annotations`, `doc: check API doc consistency`) stop running on library
doc-example changes. They carry the blanket `doc` tag among their
library tags, so today a `doc_code` edit incidentally triggers a
premerge `make -C doc/ html`. I think that's correct: those checks guard
the documented public API surface, which a doc example can't change, and
the example itself is still executed by the owning library's step while
the render is gated by Read the Docs. But it is a premerge signal that
disappears, so it should be a decision rather than a side effect. Raised
on ray-project#64812, which routes the API **reference** pages to a dedicated
`doc_api` tag for the related case.

**Out of scope, tracked separately.** `.buildkite/others.rayci.yml:13`
declares a sixth step labeled `doc tests`, running `//python/ray/...
//doc/... none --only-tags doctest` and tagged `python`, a tag no rule
in `test.rules.txt` emits. Generating the full-fan-out pipeline shows it
does get emitted (`doc tests [g14_s1]`), so it is live. After this
rename it becomes the only step in the repo still called "doc tests."
This PR doesn't touch `others.rayci.yml` and the fix is independent.

---

## What this changes

1. **Dedicated per-library tag.** Each step gets a `<lib>_doc` tag
(`core_doc`, `data_doc`, `ml_doc`, `rllib_doc`, `serve_doc`) and drops
the blanket `doc` tag. The library tag stays.
1. **Path routing.** `test.rules.txt` routes `doc/source/<lib>/**` to
that library's tag, so a doc change runs only the owning library's
example tests. LLM doc assets already route to `llm` and keep doing so.
1. **`doc` reserved for validation.** It now stays only on the
documentation build and the Vale/config infra.
1. **Rename** to `X: docs example tests`, since a failure in these steps
means library code or an example broke, not that the docs are wrong.
1. **Build-file rule fix.** `test.rules.txt` matched `doc/BUILD` and
`doc/*/BUILD`, but the files are `BUILD.bazel`, so editing a file that
*defines* the doc test targets ran no doc tests premerge. It now matches
the `.bazel` files and routes them to the same per-library steps. The
root `doc/BUILD.bazel` defines every library's targets, so it routes to
all of them.

### Scoping exceptions, and why each exists

Several paths sit under a library doc directory but can't be
meaningfully tested by that library's example step, so they're routed
explicitly rather than by directory:

- **Static images skip entirely.** Image extensions sit on the leading
skip rule, ahead of the per-library rules, so a `.png` or `.svg` edit
triggers nothing. 310 tracked image files. `.yaml` and `.sh` stay
routed, since unlike an image they can change what a test does.
- **Sphinx build machinery routes to `doc`.** `conf.py` imports
`custom_directives`, `api_autogen`, `api_mock_imports`, and
`template_collections`; none was listed in the validation-infra rule, so
all fell to the `doc/*.py` catch-all and emitted `core_doc`, running Ray
Core's doctests for a docs-build-machinery edit. Those four plus
`preprocess_github_markdown` and the doc-root build helpers now route to
`doc`. They're enumerated one per line on purpose: `*` is fnmatch here
and crosses `/`, so a `doc/source/*.py` pattern would also swallow every
example script under `doc/source/<lib>/doc_code/`. There's a comment on
the rule saying so.
- **Gallery configs route to `doc`.**
`doc/source/{data,serve,train}/examples.yml` are parsed by
`custom_directives.py` (`EXAMPLE_GALLERY_CONFIGS`) to generate the
gallery pages. They hold no executable code and can't change what any
example does. Narrowed to a three-path exception rather than a blanket
`.yml` skip, because a sibling `.yml` under a library doc directory can
be a config an example consumes.
- **`doc/.claude/` triggers nothing.** Agent files never participate in
the Sphinx build and define no test targets, but
`doc/.claude/skills/sphinx-fix/sphinx_fix.py` matched the `doc/*.py`
catch-all. The Read the Docs build guard already excludes this exact
path for the same reason, so the two guards now agree. Pre-existing
rather than a regression from this PR: on master the file emits the
blanket `doc` tag, which reaches all five per-team steps.
- **Four `team:ml` notebooks under `ray-core/` route to `ml_doc`.**
`plot_hyperparameter`, `batch_prediction`, `plot_parameter_server`, and
`plot_pong_example` live under `doc/source/ray-core/examples/` but their
targets are tagged `team:ml`, and the team argument to
`//ci/ray_ci:test_in_docker` filters targets by `team:<team>`
(`_get_all_test_query`, `ci/ray_ci/tester.py`). Routing them to
`core_doc` would run a step that tests everything under `ray-core/`
except the file that changed. Re-tagging the four `team:core` in
`doc/BUILD.bazel` is the alternative fix and would let the rule lines go
away.
- **`highly_parallel.ipynb` routes to `doc`.** Its `py_test` carries a
`highly_parallel` tag that the ml docs example step excludes, and the
notebook glob in `doc/source/ray-core/examples/BUILD.bazel` excludes it
too, as a release test needing a live multi-node cluster. The remaining
ml `//doc/...` steps select `gpu` / `train_v2_gpu` and the target has
neither, so no premerge step executes it. Routing to `doc` means the
build renders it (`nb_execution_mode` defaults to `off`, so
render-and-lint only), which is the only validation premerge offers
here.
- **`doc/external/` routes to `ml_doc`.** Its `test_external_hashes`
target is tagged `team:ml`; it had fallen through the `doc/*.py`
catch-all to `core_doc`, where the core step's `team:core` query never
sees it.
- **The `llms.txt` files route to `doc`.** ray-project#64458 adds
`doc/test_llms_txt.py` and `doc/source/llms_txt_summary.txt` with no
`test.rules.txt` change. Left alone the test would land on the
`doc/*.py` catch-all and emit `core_doc`, running Ray Core's doctests
for a test its own docstring describes as hermetic, while never running
the step that executes it. Rules for absent paths are inert, so there's
no ordering dependency: this PR doesn't touch `doc.rayci.yml`, ray-project#64458
doesn't touch `test.rules.txt`, and whichever lands first the other
merges correctly scoped.
- **Declined:** fanning `doc/test_myst_doc.py` out to all five
`<lib>_doc` tags. It backs 19 targets across every team, but it's shared
infrastructure, so a break surfaces in core as readily as anywhere. One
library's worth of execution is a sufficient smoke signal and the
post-merge build covers the rest. The rule carries a comment recording
that trade and when to revisit it.

### Effect on a doc-only PR (no `docs-go`)

| Change | Before | After |
|---|---|---|
| A Serve doc example | every team's `doc tests` step | `serve: docs
example tests` and its GPU sibling |
| A Data doc example | every team's `doc tests` step | `data: docs
example tests`, plus the dask and GPU siblings |
| An image under a library doc dir | that library's example step |
nothing |
| A Sphinx build module (`custom_directives.py` etc.) | `core: docs
example tests` | `doc: build` only (post-merge) |
| A gallery config (`examples.yml`) | that library's example step |
`doc: build` only (post-merge) |
| Editing `doc/BUILD.bazel` | nothing (rule was dead) | the doc example
steps it defines |
| The two `doc: check API*` checks | ran, via the blanket `doc` tag |
don't run (see reviewer summary) |

The GPU and dask siblings carry `<lib>_doc` too, and tag matching is a
non-empty intersection, so they're selected alongside the main step.
That's unchanged behavior: they carried the blanket `doc` tag before, so
a doc change already started them. No new GPU cost.

## Verification

**Rule conformance, under the authoritative evaluator.** `test-rules` is
green on this PR. It replays all 103 `test.rules.test.txt` assertions
through the pinned `rayci` binary, and `runTestRules` compares the full
computed tag set per path, so every case is also a negative assertion
that no other tag fires.

**Tag-to-step resolution, generated locally.** The tag set isn't the
step set: rayci filters steps by tag, then `markDeps` pulls in
everything reachable through `depends_on` regardless of that step's own
tags. To confirm the composition rather than infer it, I ran the pinned
`rayci v0.46.0` release binary against a one-file Serve doc-example
change, on master and on this branch:

```
before (base=master)
  changed files: [doc/source/serve/doc_code/app_builder.py]
  selected tags: always doc lint
  doc-related steps emitted:
    core: doc tests [g6_s22]             ml: doc tests [g13_s26]
    data: doc tests [g7_s21]             rllib: doc tests [g15_s8]
    data: dask doc tests [g7_s22]        serve: doc tests [g16_s12]
    data: doc gpu tests [g7_s23]         serve: doc gpu tests [g16_s21]
    doc: check API annotations [g9_s3]   doc: check API doc consistency [g9_s4]

after (this branch)
  changed files: [doc/source/serve/doc_code/app_builder.py]
  selected tags: always lint serve_doc
  doc-related steps emitted:
    serve: docs example tests [g16_s12]
    serve: docs example gpu tests [g16_s21]
```

Six teams' example steps collapse to the owning team's two, and the step
IDs are unchanged across the rename.

**Routing versus coverage.** Correct routing isn't sufficient: the step
that starts still has to select the target. `ci/ray_ci/tester.py`
filters by `attr(tags, 'team:<team>')`, then intersects `--only-tags`
and subtracts `--except-tags`, so a change can route perfectly, start
the right-looking step, and be invisible to every command in it. I swept
all 948 (file, target) claims under `doc/` against the per-team filters.
After the exceptions above, the only deliberate team mismatch left is
`doc/test_myst_doc.py`. Two pre-existing gaps fell out, neither created
by this change:

- **GPU-tagged ml and core doc examples have no owning step** — six
`team:ml` notebooks tagged `gpu`, five `team:core` `doc_code` modules
tagged `multi_gpu`, and one `post_wheel_build` module. `data` and
`serve` each have a GPU doc-example step; ml and core never got one, so
the only steps that would run these are gated on `train_gpu` and
`cgraphs_direct_transport`, which no doc path emits. No `doc`-tagged
step ran them before the split either. This needs a REEf and
library-team decision rather than a rules change.
- **Prose doctests aren't triggered by prose edits.** The
`doc/BUILD.bazel` `doctest` targets over `doc/source/**/*.{md,rst}` are
reachable only from the `others.rayci.yml` step gated on `python`, while
prose paths hit the leading skip rule. Roughly 700 files. I consider
this correct as-is: given current coverage the Read the Docs render
build is the gate a prose change needs.

**Also swept** all 1,628 tracked `doc/` files against the previous rules
to confirm exactly which paths changed routing and that nothing else
moved.

## Change log

Consolidated above; kept here so the review history stays legible.

- `6a1310d3b5` — the split: per-library tags, path routing, rename,
`BUILD.bazel` rule fix.
- `c6302c8a21`, `b1d03629cf` — first bot-review pass: static images
skip; Sphinx build modules route to `doc`.
- `99c3af2c28` — pre-route the `llms.txt` extension test and summary
ahead of ray-project#64458.
- `3795c6161b` — skip `doc/.claude/`; route the `team:ml` `ray-core`
notebooks to `ml_doc`.
- `e88e8a4b52` — remove a stray `TEMP(do-not-merge)` marker that reached
master with ray-project#65040. Inert, and independent of this PR's thesis; happy to
split it out.
- `f8347baf54` — second bot-review pass: gallery configs to `doc`;
correct `highly_parallel.ipynb` to `doc`.
- `6a050a0511` — route `doc/external/` to `ml_doc` so the hash guard
still runs.

## AI assistance

This change was drafted with AI assistance (Claude Code) and reviewed by
me.

---------

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
…ce checks (ray-project#64812)

## The problem

Two premerge checks in `.buildkite/doc.rayci.yml` cross-check every
`@PublicAPI` symbol against the autosummary pages that document it:

- `doc: check API annotations`
- `doc: check API doc consistency`

They currently run on the wrong set of changes, in both directions.

**They miss changes they should catch.** API reference pages are `.rst`
and `.md`, so the leading prose-and-image skip rule in `test.rules.txt`
matches them first. Editing `doc/source/data/api/api.rst` changes the
documented public API surface and triggers **no premerge step at all**.

**They run on changes that can't affect the API surface.** Both steps
carry the blanket `doc` tag. Since ray-project#64775 reserved `doc` for
documentation validation, that tag now covers two unlike things: the
autodoc machinery that decides what the API reference *contains*, and
rendering config that can't change it. So a Vale vocabulary tweak pays
for a `docbuild` plus both checks.

## The fix

Add a `doc_api` tag, and route to it everything that can change the
documented API surface or how it's computed. Then take the blanket `doc`
tag off the two steps.

| A change to | today | with this PR |
|---|---|---|
| An API reference page | **skip** | run |
| The checker's own source (`ci/ray_ci/doc/`) | **skip** | run |
| `conf.py`, `api_autogen.py`, `api_mock_imports.py`, `_ext/` | run |
run |
| Docs dependency locks (`deplocks/docs/*.lock`) | run | run |
| Library Python source | run | run |
| `.vale.ini`, Vale vocabularies | run | **skip** |
| `rtd_doctor.py`, `template_collections.py` | run | **skip** |
| `.readthedocs.yaml`, gallery configs | run | **skip** |
| Narrative prose, images | skip | skip |

## What's in the diff

Three commits, 7 files.

1. **`a0b545cc3e`** declares `doc_api` and routes the six per-team API
reference directories to it, ahead of the skip rule. Also splits the
doc-build infra block in two: the autodoc machinery emits `doc doc_api`,
the rendering-only half emits `doc` alone. Then drops the bare `doc` tag
from both check steps.

2. **`e0d520381d`** adds two drift guards in
`//ci/pipeline:test_doc_api_rules_sync`. Both `doc_api` lists are
hand-maintained and fail *silently* when they drift — a missing entry
means those paths quietly stop being checked. One guard keeps the page
list aligned with `API_PATH_PREFIXES` in
`doc/source/_ext/api_sidebar.py`. The other requires every local module
`conf.py` imports to be routed to `doc_api` or named as an explicit
rendering-only exception.

3. **`f3db137384`** routes `api_sidebar.py` to `tools` as well, so the
first guard actually runs. It was one-directional before:
`test.rules.txt` emits `tools`, so the guard fired on a rules-side edit,
but `api_sidebar.py` didn't, so growing `API_PATH_PREFIXES` without the
matching rule never executed it — the likelier mistake, and exactly the
drift the guard exists to catch. Also removes four duplicated
assertions.

Three details worth knowing, since each looks like an oversight
otherwise:

- **`ci/ray_ci/doc/` keeps `tools` alongside `doc_api`.** It declares
six `ci_unit` `py_test` targets and `tools` is what selects the job that
runs them, so dropping it would mean editing the checker never runs the
checker's own unit tests.
- **`doc.rayci.yml` also emits `doc_api`,** so editing a check's step
definition exercises the check it defines.
- **`doc/source/ray-observability/reference/` is routed even though it
sits outside `doc/source/*/api/`.** Ray Core's `api/index.rst` toctrees
into its `api.rst`, so it's part of the Core API-surface walk.

## Testing

`test.rules.test.txt` gains cases for the API pages (including a nested
leaf page, to pin recursive directory matching), the checker source,
each machinery path, and negative cases asserting the rendering half
still emits `doc` alone. **These are the real gate:** the `test-rules`
step runs them through rayci's parser as exact set equality, so a
passing case proves a path emits precisely those tags and nothing else.

Locally, against the in-repo reference engine
(`ci/pipeline/determine_tests_to_run.py`):

- `check_rules()` passes; **115 of 115** replay cases pass.
- Across all 10,213 tracked files the routing change is **purely
additive: 95 files gain tags, none lose any.**
- No executable asset (`.py`, `.ipynb`) lives under the routed API
directories, so no library docs-example step loses coverage.

```
python -m pytest ci/pipeline/test_doc_api_rules_sync.py
```

## Two notes for reviewers

**One behavior change to sanity-check.** Neither check carries an `if:`
guard now, including the `docs-go` one they had before. A content-only
PR labeled `docs-go` that touches an API reference page will run both
checks plus their `docbuild` dependency, where it previously skipped
them. That's intended — `docs-go` exists to skip per-team doc *example
execution*, and an API reference edit is exactly the content-only change
these checks must still cover — but it's a real cost change for that
workflow. `docs-go` keeps its role everywhere else: 12 per-team doc
example steps across `core`, `data`, `llm`, `ml`, `rllib`, `serve`, and
`linux_aarch64`, plus the `lint: validate docs-go scope` step that
enforces the label is only used on doc-only PRs.

**This PR changed shape, so earlier comments describe an older design.**
It began as a `docs-api-go` PR label that would re-enable the checks on
a `docs-go` PR. That's removed: tag selection and Buildkite `if:` are
separate passes, and `if:` can only suppress a step the tags already
emitted, so with the routing correct the label could only ever subtract.
Dropping the `if:` achieves the same thing with no label to create or
remember. Consequently the earlier Gemini review and the 2026-08-04
comment above both reference a `docs-api-go` label that no longer
exists. Everything else in that comment still stands, including its
decision that `doc_code/` and `examples/` should *not* grow into
`doc_api`.

🤖 Written with assistance from 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
…ect#64413)

## Why are these changes needed?

The YAML under `doc/redirects/` is the source of truth for the
docs.ray.io Read the Docs redirect configuration, managed with
[rtd-redirects](https://github.com/anyscale/rtd-redirects). Today a PR
that edits only redirect YAML runs no check at all, so a malformed or
unreachable redirect can merge unnoticed.

Nothing routes redirect YAML anywhere. `.yaml` isn't covered by the
leading prose-and-image skip rule, nor by the
`doc/*.py`/`doc/*.ipynb`/`doc/*/BUILD.bazel` catch-all, so it falls
through to the broad `doc/` pass rule at the bottom of the doc section
and emits no tag at all. Confirmed against the rule engine on master:
`doc/redirects/current.yaml` emits `set()`.

This adds a lightweight, credential-free premerge gate for
`doc/redirects/*.yaml` that validates the redirects and prints the
redirect-level diff. The change is purely additive: it gives redirect
YAML a check where it previously had none, and no other path's selection
changes.

## What changed

- **`.buildkite/test.rules.txt`** — declare a `doc_redirects` test tag
and route `doc/redirects/*.yaml` to it. The rule sits ahead of every
`doc/` rule, which matters because the final `doc/` pass rule is what
currently swallows these files.

The rule emits `doc_redirects` alone, deliberately not `doc` or
`doc_api`. A redirect edit can't change the documented API surface, and
the check needs neither a rendered documentation build nor a compiled
Ray: it parses the YAML and diffs it against the base ref.
- **`.buildkite/test.rules.txt`** — route `.buildkite/doc.rayci.yml` to
`doc_redirects` as well, on its own rule rather than by extending the
autodoc-machinery block, so a `conf.py` edit doesn't start running the
redirect check. An edit to a step definition has to be able to select
the step it edits, which is the same reason that file already emits
`doc_api`. This also covers the `anyscale-rtd-redirects` version pin,
which lives in the redirect step's commands, so a version bump re-runs
the check.
- **`.buildkite/test.rules.test.txt`** — three cases:
`doc/redirects/current.yaml: doc_redirects`, `doc/redirects/README.md:`
asserting the prose beside it stays unrouted, and
`.buildkite/doc.rayci.yml: doc doc_api doc_redirects`. The last one
revises an assertion that already existed on master, since that file's
tag set genuinely changes here.
- **`.buildkite/doc.rayci.yml`** — add a `forge`-based step (no doc
image) that installs the pinned `anyscale-rtd-redirects==0.2.0` from
PyPI and runs:
  ```
  rtd-redirects validate doc/redirects/current.yaml
rtd-redirects diff-file --file doc/redirects/current.yaml --base
FETCH_HEAD --head HEAD --repo .
  ```
The step diffs against `FETCH_HEAD` after fetching the PR's base branch,
rather than against `origin/<base>`: a clone with a restricted refspec
may never create a local remote-tracking ref, and
`doc/test_no_new_rst.py` already solves the same problem the same way.
The base branch resolves at runtime from
`$${BUILDKITE_PULL_REQUEST_BASE_BRANCH:-master}`, escaped so the shell
expands it rather than Buildkite interpolating it at pipeline-upload
time, matching the `$${...}` convention used across the other pipeline
files.

The step also fails closed if `doc/redirects/` grows a YAML file the
commands don't name. The tag selects on a glob, but multiple redirect
files compose in the order given and a shell glob can't express that
order, so the guard forces the compose-order decision to be made
explicitly instead of letting a new file select the step and then go
unvalidated.

## Verification

Verified with Ray's rule parser
(`ci/pipeline/determine_tests_to_run.py`), the same first-match-wins
engine rayci uses:

- `check_rules()` parses clean, and all 126 cases in
`test.rules.test.txt` replay green. That file is enforced by the
`test-rules` CI step, and rayci asserts exact set equality, so a passing
case proves the path emits exactly those tags and nothing else.
- A sweep of all 10,333 tracked files against master shows **exactly two
deltas** — `doc/redirects/current.yaml` gaining `doc_redirects`, and
`.buildkite/doc.rayci.yml` gaining it alongside its existing `doc
doc_api` — and **zero tag losses** on any path. Every pre-existing
assertion in `test.rules.test.txt` is preserved except the
`doc.rayci.yml` one this PR deliberately revises.
- Ran the step's commands locally in a clean venv with
`anyscale-rtd-redirects==0.2.0` against the current
`doc/redirects/current.yaml`: `validate` reports 0 errors (49 chain
warnings, informational), and `diff-file --base FETCH_HEAD` reports the
redirect-level diff and exits 0 with no Read the Docs credentials.
- Exercised the drift guard both ways: it passes with only
`current.yaml` present and exits non-zero when a second
`doc/redirects/*.yaml` appears.

Because `.buildkite/doc.rayci.yml` now emits `doc_redirects`, **this PR
selects the new step and runs it**. Replaying this PR's own changed
files through the rule engine gives a tag union of `doc`, `doc_api`,
`doc_redirects`, and `tools`, so the step's commands are exercised in CI
here rather than only on some later PR that happens to edit redirect
YAML. It runs against an unchanged `current.yaml`, so `diff-file`
reports an empty redirect diff and exits 0, which is exactly the smoke
test that catches a typo in the step definition.

## Update: rebased onto the doc-tag reorg

Rebased after ray-project#64775 and ray-project#64812 landed, which reorganized the doc tags:
doc example tests moved to per-library `<lib>_doc` tags, and `doc` was
split so the autodoc machinery emits `doc doc_api` while the
rendering-only surface emits `doc`. This branch's four commits (one an
upstream merge) are collapsed into one. Two conflicts in
`test.rules.txt` (the tag declaration line, and the rule insertion
point) and one in `test.rules.test.txt` (three expectations the reorg
had since updated) were resolved in favor of master, then the
`doc_redirects` rule and cases re-applied on top.

The rebase also invalidated this PR's original rationale, so the rule
and step comments have been rewritten. The earlier framing was that
`doc_redirects` keeps redirect YAML from pulling in docbuild, the API
checks, and the per-team doc tests. That's no longer accurate on any of
the three: the per-team tests are selected by `<lib>_doc`, the two API
checks carry `doc_api` plus the library tags and no longer carry bare
`doc`, and the only remaining step carrying bare `doc` is `doc: build`,
which is `skip-on-premerge`. Since redirect YAML emits nothing at all on
master, this rule was never preventing over-triggering. It's additive,
and the comments now say so.

## Update: the step now selects itself

Cursor Bugbot caught that the redirect step wasn't reachable from an
edit to its own definition: `.buildkite/doc.rayci.yml` emitted `doc
doc_api` but never `doc_redirects`, so changing the redirect step's
commands wouldn't have run the redirect step. That contradicted the
rule's own stated reason for emitting `doc_api`, and this PR
demonstrated the gap: its previous revision noted that the new step
didn't execute here.

Fixed by giving `.buildkite/doc.rayci.yml` its own rule emitting `doc
doc_api doc_redirects`. It's a separate rule rather than an extra tag on
the autodoc-machinery block, because that block also covers `conf.py`,
`api_autogen.py`, and `doc/source/_ext/`, and a `conf.py` edit has no
business running the redirect check. The first attempt at this appended
the tag to the shared block and the full-repo sweep caught it
immediately: seven machinery files picked up `doc_redirects`.

AI assistance (Claude Code) was used to draft the CI step, the rebase
conflict resolution, and this description. Every changed line was
reviewed by hand, and the verification above was run as described. This
isn't duplicating existing work: no other open PR adds redirect
validation to premerge, and the `doc_redirects` tag doesn't exist on
master.

## Update: uv, and a recursive fail-closed guard

Two review follow-ups.

**Install with `uv`** (Elliot's suggestion).
`ci/docker/forge.Dockerfile` already installs uv to `/usr/local/bin` and
uses it for the image's Python, so the step needs no extra setup. It's
`uv tool install` rather than `uv pip install --system` for a PATH
reason: the previous revision's premerge log shows `pip install` fell
back to a user install, so the `rtd-redirects` entry point resolved from
`~/.local/bin`. `uv tool install` writes executables to that same
directory, so PATH resolution is unchanged. `uv pip install --system`
would target the uv-managed interpreter and put the entry point in that
env's `bin`, which isn't on PATH.

**The fail-closed guard now recurses.** Cursor Bugbot caught that the
guard's single-level shell glob didn't cover a nested redirect file, and
it was right. The rule engine matches with `fnmatch`, whose `*` crosses
`/`, so `doc/redirects/nested/foo.yaml` emits `doc_redirects` and
selects this step, while `ls doc/redirects/*.yaml` never saw it and the
guard passed. Replacing the glob with `find` closes the gap. Exercised
three ways locally: passes with only `current.yaml`, exits non-zero for
a nested file and for a sibling file.

A `.yml` file stays out of scope. The tag rule matches `*.yaml` only, so
`doc/redirects/current.yml` emits no tags and never selects the step,
putting it beyond the guard's reach. That matches the pre-PR baseline
for every redirect file rather than regressing anything, and
`rtd-redirects` uses `.yaml`.

Re-verified after the change: rules parse clean and all 126 cases in
`test.rules.test.txt` replay green (the rule files are untouched by this
revision).

## Related issue number

N/A

## Checks

- [x] I've signed off every commit (`-s`), because all commits are
squashed into one when merged.
- [x] I've run `scripts/format.sh` to lint the changes in this PR. (Via
`pre-commit`; the applicable hooks pass.)
- [x] I've made sure the tests are passing.
- Testing Strategy
   - [x] Unit tests
   - [ ] Release tests
   - [ ] This PR is not tested :(

---------

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

## Reviewer summary

**What this does.** The per-team `X: doc tests` steps are library
example and doctest suites that live under `doc/`. They exercise library
code, not documentation quality. Today every executable doc asset emits
the blanket `doc` tag and all six teams' steps are tagged `doc`, so a
one-library doc change starts every team's step. This gives each step a
dedicated `<lib>_doc` tag, routes `doc/source/<lib>/**` to the owning
library's tag, renames the steps to `X: docs example tests`, and leaves
`doc` for documentation validation (the build and the Vale/config
infra). The library tag stays on each step, so a library **code** change
runs its doc example tests exactly as before.

**What's verified.**

| Claim | Evidence |
|---|---|
| Each path emits exactly the intended tag, and no other | `test-rules`
green on this PR. That's the pinned `rayci` binary replaying all 103
`test.rules.test.txt` assertions (up from 57 on master) with **exact set
equality**, so each case also proves the blanket `doc` tag does *not*
come along. |
| The emitted tags resolve to the intended steps, and only those |
Generated the real pipeline locally with the pinned `rayci v0.46.0`
release binary for a one-file Serve doc-example change, before and after
this branch. Output below. |
| The renamed steps still run and pass | All five plus the GPU and dask
siblings green on this PR, selected via the library tags this change
preserves. |
| Every executable target under `doc/` routes to a step that can
actually select it | Swept all 948 (file, target) claims against the
per-team `team:` / `--only-tags` / `--except-tags` filters. One
deliberate exception (`doc/test_myst_doc.py`, below) and two
pre-existing gaps that this change doesn't create. |
| The rename doesn't reset step identity | rayci derives step IDs
positionally (`fmt.Sprintf("g%d_s%d", i, j)`, `converter.go`), not from
the label. The generated pipelines confirm it: `g16_s12`, `g16_s21`,
`g6_s22`, `g13_s26` are identical before and after. |

**What I need from a reviewer.**

1. **One question I can't answer from inside the repo.**
`ci/build/get_build_info.py` sets `config.env` to `"Buildkite " +
BUILDKITE_LABEL`, and `ci/build/upload_build_info.sh` uploads it on
postmerge pipelines on `master` only. Does anything downstream of that
`metadata.json` treat `config.env` as an identity or grouping key? If
it's descriptive, renaming five steps is free. If something groups on
it, those five steps' postmerge history splits at the merge commit.
Flaky-test selection and target selection both key on `team` (unchanged
here) and test identity is the bazel target name (`f"{system}:{name}"`
in `release/ray_release/test.py`), so I believe `config.env` is the only
place the label escapes.
1. **Confirm the API-check behavior change below is acceptable.**
1. **Confirm the catch-all owner.** Executable doc assets in directories
with no per-team step route to the core step: roughly 25 files, being 18
`doc/source/templates/*/start.ipynb` plus a handful under
`doc/source/cluster/doc_code/`, `doc/source/ray-contribute/doc_code/`,
and `doc/source/_templates/`. The templates majority may be retired or
externally managed, in which case a skip rule is the better answer than
core ownership.

**Known behavior change worth your eyes.** Because
`doc/source/<lib>/doc_code/` and `examples/` now emit `<lib>_doc`
instead of `doc`, the two API-surface checks (`doc: check API
annotations`, `doc: check API doc consistency`) stop running on library
doc-example changes. They carry the blanket `doc` tag among their
library tags, so today a `doc_code` edit incidentally triggers a
premerge `make -C doc/ html`. I think that's correct: those checks guard
the documented public API surface, which a doc example can't change, and
the example itself is still executed by the owning library's step while
the render is gated by Read the Docs. But it is a premerge signal that
disappears, so it should be a decision rather than a side effect. Raised
on ray-project#64812, which routes the API **reference** pages to a dedicated
`doc_api` tag for the related case.

**Out of scope, tracked separately.** `.buildkite/others.rayci.yml:13`
declares a sixth step labeled `doc tests`, running `//python/ray/...
//doc/... none --only-tags doctest` and tagged `python`, a tag no rule
in `test.rules.txt` emits. Generating the full-fan-out pipeline shows it
does get emitted (`doc tests [g14_s1]`), so it is live. After this
rename it becomes the only step in the repo still called "doc tests."
This PR doesn't touch `others.rayci.yml` and the fix is independent.

---

## What this changes

1. **Dedicated per-library tag.** Each step gets a `<lib>_doc` tag
(`core_doc`, `data_doc`, `ml_doc`, `rllib_doc`, `serve_doc`) and drops
the blanket `doc` tag. The library tag stays.
1. **Path routing.** `test.rules.txt` routes `doc/source/<lib>/**` to
that library's tag, so a doc change runs only the owning library's
example tests. LLM doc assets already route to `llm` and keep doing so.
1. **`doc` reserved for validation.** It now stays only on the
documentation build and the Vale/config infra.
1. **Rename** to `X: docs example tests`, since a failure in these steps
means library code or an example broke, not that the docs are wrong.
1. **Build-file rule fix.** `test.rules.txt` matched `doc/BUILD` and
`doc/*/BUILD`, but the files are `BUILD.bazel`, so editing a file that
*defines* the doc test targets ran no doc tests premerge. It now matches
the `.bazel` files and routes them to the same per-library steps. The
root `doc/BUILD.bazel` defines every library's targets, so it routes to
all of them.

### Scoping exceptions, and why each exists

Several paths sit under a library doc directory but can't be
meaningfully tested by that library's example step, so they're routed
explicitly rather than by directory:

- **Static images skip entirely.** Image extensions sit on the leading
skip rule, ahead of the per-library rules, so a `.png` or `.svg` edit
triggers nothing. 310 tracked image files. `.yaml` and `.sh` stay
routed, since unlike an image they can change what a test does.
- **Sphinx build machinery routes to `doc`.** `conf.py` imports
`custom_directives`, `api_autogen`, `api_mock_imports`, and
`template_collections`; none was listed in the validation-infra rule, so
all fell to the `doc/*.py` catch-all and emitted `core_doc`, running Ray
Core's doctests for a docs-build-machinery edit. Those four plus
`preprocess_github_markdown` and the doc-root build helpers now route to
`doc`. They're enumerated one per line on purpose: `*` is fnmatch here
and crosses `/`, so a `doc/source/*.py` pattern would also swallow every
example script under `doc/source/<lib>/doc_code/`. There's a comment on
the rule saying so.
- **Gallery configs route to `doc`.**
`doc/source/{data,serve,train}/examples.yml` are parsed by
`custom_directives.py` (`EXAMPLE_GALLERY_CONFIGS`) to generate the
gallery pages. They hold no executable code and can't change what any
example does. Narrowed to a three-path exception rather than a blanket
`.yml` skip, because a sibling `.yml` under a library doc directory can
be a config an example consumes.
- **`doc/.claude/` triggers nothing.** Agent files never participate in
the Sphinx build and define no test targets, but
`doc/.claude/skills/sphinx-fix/sphinx_fix.py` matched the `doc/*.py`
catch-all. The Read the Docs build guard already excludes this exact
path for the same reason, so the two guards now agree. Pre-existing
rather than a regression from this PR: on master the file emits the
blanket `doc` tag, which reaches all five per-team steps.
- **Four `team:ml` notebooks under `ray-core/` route to `ml_doc`.**
`plot_hyperparameter`, `batch_prediction`, `plot_parameter_server`, and
`plot_pong_example` live under `doc/source/ray-core/examples/` but their
targets are tagged `team:ml`, and the team argument to
`//ci/ray_ci:test_in_docker` filters targets by `team:<team>`
(`_get_all_test_query`, `ci/ray_ci/tester.py`). Routing them to
`core_doc` would run a step that tests everything under `ray-core/`
except the file that changed. Re-tagging the four `team:core` in
`doc/BUILD.bazel` is the alternative fix and would let the rule lines go
away.
- **`highly_parallel.ipynb` routes to `doc`.** Its `py_test` carries a
`highly_parallel` tag that the ml docs example step excludes, and the
notebook glob in `doc/source/ray-core/examples/BUILD.bazel` excludes it
too, as a release test needing a live multi-node cluster. The remaining
ml `//doc/...` steps select `gpu` / `train_v2_gpu` and the target has
neither, so no premerge step executes it. Routing to `doc` means the
build renders it (`nb_execution_mode` defaults to `off`, so
render-and-lint only), which is the only validation premerge offers
here.
- **`doc/external/` routes to `ml_doc`.** Its `test_external_hashes`
target is tagged `team:ml`; it had fallen through the `doc/*.py`
catch-all to `core_doc`, where the core step's `team:core` query never
sees it.
- **The `llms.txt` files route to `doc`.** ray-project#64458 adds
`doc/test_llms_txt.py` and `doc/source/llms_txt_summary.txt` with no
`test.rules.txt` change. Left alone the test would land on the
`doc/*.py` catch-all and emit `core_doc`, running Ray Core's doctests
for a test its own docstring describes as hermetic, while never running
the step that executes it. Rules for absent paths are inert, so there's
no ordering dependency: this PR doesn't touch `doc.rayci.yml`, ray-project#64458
doesn't touch `test.rules.txt`, and whichever lands first the other
merges correctly scoped.
- **Declined:** fanning `doc/test_myst_doc.py` out to all five
`<lib>_doc` tags. It backs 19 targets across every team, but it's shared
infrastructure, so a break surfaces in core as readily as anywhere. One
library's worth of execution is a sufficient smoke signal and the
post-merge build covers the rest. The rule carries a comment recording
that trade and when to revisit it.

### Effect on a doc-only PR (no `docs-go`)

| Change | Before | After |
|---|---|---|
| A Serve doc example | every team's `doc tests` step | `serve: docs
example tests` and its GPU sibling |
| A Data doc example | every team's `doc tests` step | `data: docs
example tests`, plus the dask and GPU siblings |
| An image under a library doc dir | that library's example step |
nothing |
| A Sphinx build module (`custom_directives.py` etc.) | `core: docs
example tests` | `doc: build` only (post-merge) |
| A gallery config (`examples.yml`) | that library's example step |
`doc: build` only (post-merge) |
| Editing `doc/BUILD.bazel` | nothing (rule was dead) | the doc example
steps it defines |
| The two `doc: check API*` checks | ran, via the blanket `doc` tag |
don't run (see reviewer summary) |

The GPU and dask siblings carry `<lib>_doc` too, and tag matching is a
non-empty intersection, so they're selected alongside the main step.
That's unchanged behavior: they carried the blanket `doc` tag before, so
a doc change already started them. No new GPU cost.

## Verification

**Rule conformance, under the authoritative evaluator.** `test-rules` is
green on this PR. It replays all 103 `test.rules.test.txt` assertions
through the pinned `rayci` binary, and `runTestRules` compares the full
computed tag set per path, so every case is also a negative assertion
that no other tag fires.

**Tag-to-step resolution, generated locally.** The tag set isn't the
step set: rayci filters steps by tag, then `markDeps` pulls in
everything reachable through `depends_on` regardless of that step's own
tags. To confirm the composition rather than infer it, I ran the pinned
`rayci v0.46.0` release binary against a one-file Serve doc-example
change, on master and on this branch:

```
before (base=master)
  changed files: [doc/source/serve/doc_code/app_builder.py]
  selected tags: always doc lint
  doc-related steps emitted:
    core: doc tests [g6_s22]             ml: doc tests [g13_s26]
    data: doc tests [g7_s21]             rllib: doc tests [g15_s8]
    data: dask doc tests [g7_s22]        serve: doc tests [g16_s12]
    data: doc gpu tests [g7_s23]         serve: doc gpu tests [g16_s21]
    doc: check API annotations [g9_s3]   doc: check API doc consistency [g9_s4]

after (this branch)
  changed files: [doc/source/serve/doc_code/app_builder.py]
  selected tags: always lint serve_doc
  doc-related steps emitted:
    serve: docs example tests [g16_s12]
    serve: docs example gpu tests [g16_s21]
```

Six teams' example steps collapse to the owning team's two, and the step
IDs are unchanged across the rename.

**Routing versus coverage.** Correct routing isn't sufficient: the step
that starts still has to select the target. `ci/ray_ci/tester.py`
filters by `attr(tags, 'team:<team>')`, then intersects `--only-tags`
and subtracts `--except-tags`, so a change can route perfectly, start
the right-looking step, and be invisible to every command in it. I swept
all 948 (file, target) claims under `doc/` against the per-team filters.
After the exceptions above, the only deliberate team mismatch left is
`doc/test_myst_doc.py`. Two pre-existing gaps fell out, neither created
by this change:

- **GPU-tagged ml and core doc examples have no owning step** — six
`team:ml` notebooks tagged `gpu`, five `team:core` `doc_code` modules
tagged `multi_gpu`, and one `post_wheel_build` module. `data` and
`serve` each have a GPU doc-example step; ml and core never got one, so
the only steps that would run these are gated on `train_gpu` and
`cgraphs_direct_transport`, which no doc path emits. No `doc`-tagged
step ran them before the split either. This needs a REEf and
library-team decision rather than a rules change.
- **Prose doctests aren't triggered by prose edits.** The
`doc/BUILD.bazel` `doctest` targets over `doc/source/**/*.{md,rst}` are
reachable only from the `others.rayci.yml` step gated on `python`, while
prose paths hit the leading skip rule. Roughly 700 files. I consider
this correct as-is: given current coverage the Read the Docs render
build is the gate a prose change needs.

**Also swept** all 1,628 tracked `doc/` files against the previous rules
to confirm exactly which paths changed routing and that nothing else
moved.

## Change log

Consolidated above; kept here so the review history stays legible.

- `6a1310d3b5` — the split: per-library tags, path routing, rename,
`BUILD.bazel` rule fix.
- `c6302c8a21`, `b1d03629cf` — first bot-review pass: static images
skip; Sphinx build modules route to `doc`.
- `99c3af2c28` — pre-route the `llms.txt` extension test and summary
ahead of ray-project#64458.
- `3795c6161b` — skip `doc/.claude/`; route the `team:ml` `ray-core`
notebooks to `ml_doc`.
- `e88e8a4b52` — remove a stray `TEMP(do-not-merge)` marker that reached
master with ray-project#65040. Inert, and independent of this PR's thesis; happy to
split it out.
- `f8347baf54` — second bot-review pass: gallery configs to `doc`;
correct `highly_parallel.ipynb` to `doc`.
- `6a050a0511` — route `doc/external/` to `ml_doc` so the hash guard
still runs.

## AI assistance

This change was drafted with AI assistance (Claude Code) and reviewed by
me.

---------

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

## The problem

Two premerge checks in `.buildkite/doc.rayci.yml` cross-check every
`@PublicAPI` symbol against the autosummary pages that document it:

- `doc: check API annotations`
- `doc: check API doc consistency`

They currently run on the wrong set of changes, in both directions.

**They miss changes they should catch.** API reference pages are `.rst`
and `.md`, so the leading prose-and-image skip rule in `test.rules.txt`
matches them first. Editing `doc/source/data/api/api.rst` changes the
documented public API surface and triggers **no premerge step at all**.

**They run on changes that can't affect the API surface.** Both steps
carry the blanket `doc` tag. Since ray-project#64775 reserved `doc` for
documentation validation, that tag now covers two unlike things: the
autodoc machinery that decides what the API reference *contains*, and
rendering config that can't change it. So a Vale vocabulary tweak pays
for a `docbuild` plus both checks.

## The fix

Add a `doc_api` tag, and route to it everything that can change the
documented API surface or how it's computed. Then take the blanket `doc`
tag off the two steps.

| A change to | today | with this PR |
|---|---|---|
| An API reference page | **skip** | run |
| The checker's own source (`ci/ray_ci/doc/`) | **skip** | run |
| `conf.py`, `api_autogen.py`, `api_mock_imports.py`, `_ext/` | run |
run |
| Docs dependency locks (`deplocks/docs/*.lock`) | run | run |
| Library Python source | run | run |
| `.vale.ini`, Vale vocabularies | run | **skip** |
| `rtd_doctor.py`, `template_collections.py` | run | **skip** |
| `.readthedocs.yaml`, gallery configs | run | **skip** |
| Narrative prose, images | skip | skip |

## What's in the diff

Three commits, 7 files.

1. **`a0b545cc3e`** declares `doc_api` and routes the six per-team API
reference directories to it, ahead of the skip rule. Also splits the
doc-build infra block in two: the autodoc machinery emits `doc doc_api`,
the rendering-only half emits `doc` alone. Then drops the bare `doc` tag
from both check steps.

2. **`e0d520381d`** adds two drift guards in
`//ci/pipeline:test_doc_api_rules_sync`. Both `doc_api` lists are
hand-maintained and fail *silently* when they drift — a missing entry
means those paths quietly stop being checked. One guard keeps the page
list aligned with `API_PATH_PREFIXES` in
`doc/source/_ext/api_sidebar.py`. The other requires every local module
`conf.py` imports to be routed to `doc_api` or named as an explicit
rendering-only exception.

3. **`f3db137384`** routes `api_sidebar.py` to `tools` as well, so the
first guard actually runs. It was one-directional before:
`test.rules.txt` emits `tools`, so the guard fired on a rules-side edit,
but `api_sidebar.py` didn't, so growing `API_PATH_PREFIXES` without the
matching rule never executed it — the likelier mistake, and exactly the
drift the guard exists to catch. Also removes four duplicated
assertions.

Three details worth knowing, since each looks like an oversight
otherwise:

- **`ci/ray_ci/doc/` keeps `tools` alongside `doc_api`.** It declares
six `ci_unit` `py_test` targets and `tools` is what selects the job that
runs them, so dropping it would mean editing the checker never runs the
checker's own unit tests.
- **`doc.rayci.yml` also emits `doc_api`,** so editing a check's step
definition exercises the check it defines.
- **`doc/source/ray-observability/reference/` is routed even though it
sits outside `doc/source/*/api/`.** Ray Core's `api/index.rst` toctrees
into its `api.rst`, so it's part of the Core API-surface walk.

## Testing

`test.rules.test.txt` gains cases for the API pages (including a nested
leaf page, to pin recursive directory matching), the checker source,
each machinery path, and negative cases asserting the rendering half
still emits `doc` alone. **These are the real gate:** the `test-rules`
step runs them through rayci's parser as exact set equality, so a
passing case proves a path emits precisely those tags and nothing else.

Locally, against the in-repo reference engine
(`ci/pipeline/determine_tests_to_run.py`):

- `check_rules()` passes; **115 of 115** replay cases pass.
- Across all 10,213 tracked files the routing change is **purely
additive: 95 files gain tags, none lose any.**
- No executable asset (`.py`, `.ipynb`) lives under the routed API
directories, so no library docs-example step loses coverage.

```
python -m pytest ci/pipeline/test_doc_api_rules_sync.py
```

## Two notes for reviewers

**One behavior change to sanity-check.** Neither check carries an `if:`
guard now, including the `docs-go` one they had before. A content-only
PR labeled `docs-go` that touches an API reference page will run both
checks plus their `docbuild` dependency, where it previously skipped
them. That's intended — `docs-go` exists to skip per-team doc *example
execution*, and an API reference edit is exactly the content-only change
these checks must still cover — but it's a real cost change for that
workflow. `docs-go` keeps its role everywhere else: 12 per-team doc
example steps across `core`, `data`, `llm`, `ml`, `rllib`, `serve`, and
`linux_aarch64`, plus the `lint: validate docs-go scope` step that
enforces the label is only used on doc-only PRs.

**This PR changed shape, so earlier comments describe an older design.**
It began as a `docs-api-go` PR label that would re-enable the checks on
a `docs-go` PR. That's removed: tag selection and Buildkite `if:` are
separate passes, and `if:` can only suppress a step the tags already
emitted, so with the routing correct the label could only ever subtract.
Dropping the `if:` achieves the same thing with no label to create or
remember. Consequently the earlier Gemini review and the 2026-08-04
comment above both reference a `docs-api-go` label that no longer
exists. Everything else in that comment still stands, including its
decision that `doc_code/` and `examples/` should *not* grow into
`doc_api`.

🤖 Written with assistance from Claude Code.

---------

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

## Why are these changes needed?

The YAML under `doc/redirects/` is the source of truth for the
docs.ray.io Read the Docs redirect configuration, managed with
[rtd-redirects](https://github.com/anyscale/rtd-redirects). Today a PR
that edits only redirect YAML runs no check at all, so a malformed or
unreachable redirect can merge unnoticed.

Nothing routes redirect YAML anywhere. `.yaml` isn't covered by the
leading prose-and-image skip rule, nor by the
`doc/*.py`/`doc/*.ipynb`/`doc/*/BUILD.bazel` catch-all, so it falls
through to the broad `doc/` pass rule at the bottom of the doc section
and emits no tag at all. Confirmed against the rule engine on master:
`doc/redirects/current.yaml` emits `set()`.

This adds a lightweight, credential-free premerge gate for
`doc/redirects/*.yaml` that validates the redirects and prints the
redirect-level diff. The change is purely additive: it gives redirect
YAML a check where it previously had none, and no other path's selection
changes.

## What changed

- **`.buildkite/test.rules.txt`** — declare a `doc_redirects` test tag
and route `doc/redirects/*.yaml` to it. The rule sits ahead of every
`doc/` rule, which matters because the final `doc/` pass rule is what
currently swallows these files.

The rule emits `doc_redirects` alone, deliberately not `doc` or
`doc_api`. A redirect edit can't change the documented API surface, and
the check needs neither a rendered documentation build nor a compiled
Ray: it parses the YAML and diffs it against the base ref.
- **`.buildkite/test.rules.txt`** — route `.buildkite/doc.rayci.yml` to
`doc_redirects` as well, on its own rule rather than by extending the
autodoc-machinery block, so a `conf.py` edit doesn't start running the
redirect check. An edit to a step definition has to be able to select
the step it edits, which is the same reason that file already emits
`doc_api`. This also covers the `anyscale-rtd-redirects` version pin,
which lives in the redirect step's commands, so a version bump re-runs
the check.
- **`.buildkite/test.rules.test.txt`** — three cases:
`doc/redirects/current.yaml: doc_redirects`, `doc/redirects/README.md:`
asserting the prose beside it stays unrouted, and
`.buildkite/doc.rayci.yml: doc doc_api doc_redirects`. The last one
revises an assertion that already existed on master, since that file's
tag set genuinely changes here.
- **`.buildkite/doc.rayci.yml`** — add a `forge`-based step (no doc
image) that installs the pinned `anyscale-rtd-redirects==0.2.0` from
PyPI and runs:
  ```
  rtd-redirects validate doc/redirects/current.yaml
rtd-redirects diff-file --file doc/redirects/current.yaml --base
FETCH_HEAD --head HEAD --repo .
  ```
The step diffs against `FETCH_HEAD` after fetching the PR's base branch,
rather than against `origin/<base>`: a clone with a restricted refspec
may never create a local remote-tracking ref, and
`doc/test_no_new_rst.py` already solves the same problem the same way.
The base branch resolves at runtime from
`$${BUILDKITE_PULL_REQUEST_BASE_BRANCH:-master}`, escaped so the shell
expands it rather than Buildkite interpolating it at pipeline-upload
time, matching the `$${...}` convention used across the other pipeline
files.

The step also fails closed if `doc/redirects/` grows a YAML file the
commands don't name. The tag selects on a glob, but multiple redirect
files compose in the order given and a shell glob can't express that
order, so the guard forces the compose-order decision to be made
explicitly instead of letting a new file select the step and then go
unvalidated.

## Verification

Verified with Ray's rule parser
(`ci/pipeline/determine_tests_to_run.py`), the same first-match-wins
engine rayci uses:

- `check_rules()` parses clean, and all 126 cases in
`test.rules.test.txt` replay green. That file is enforced by the
`test-rules` CI step, and rayci asserts exact set equality, so a passing
case proves the path emits exactly those tags and nothing else.
- A sweep of all 10,333 tracked files against master shows **exactly two
deltas** — `doc/redirects/current.yaml` gaining `doc_redirects`, and
`.buildkite/doc.rayci.yml` gaining it alongside its existing `doc
doc_api` — and **zero tag losses** on any path. Every pre-existing
assertion in `test.rules.test.txt` is preserved except the
`doc.rayci.yml` one this PR deliberately revises.
- Ran the step's commands locally in a clean venv with
`anyscale-rtd-redirects==0.2.0` against the current
`doc/redirects/current.yaml`: `validate` reports 0 errors (49 chain
warnings, informational), and `diff-file --base FETCH_HEAD` reports the
redirect-level diff and exits 0 with no Read the Docs credentials.
- Exercised the drift guard both ways: it passes with only
`current.yaml` present and exits non-zero when a second
`doc/redirects/*.yaml` appears.

Because `.buildkite/doc.rayci.yml` now emits `doc_redirects`, **this PR
selects the new step and runs it**. Replaying this PR's own changed
files through the rule engine gives a tag union of `doc`, `doc_api`,
`doc_redirects`, and `tools`, so the step's commands are exercised in CI
here rather than only on some later PR that happens to edit redirect
YAML. It runs against an unchanged `current.yaml`, so `diff-file`
reports an empty redirect diff and exits 0, which is exactly the smoke
test that catches a typo in the step definition.

## Update: rebased onto the doc-tag reorg

Rebased after ray-project#64775 and ray-project#64812 landed, which reorganized the doc tags:
doc example tests moved to per-library `<lib>_doc` tags, and `doc` was
split so the autodoc machinery emits `doc doc_api` while the
rendering-only surface emits `doc`. This branch's four commits (one an
upstream merge) are collapsed into one. Two conflicts in
`test.rules.txt` (the tag declaration line, and the rule insertion
point) and one in `test.rules.test.txt` (three expectations the reorg
had since updated) were resolved in favor of master, then the
`doc_redirects` rule and cases re-applied on top.

The rebase also invalidated this PR's original rationale, so the rule
and step comments have been rewritten. The earlier framing was that
`doc_redirects` keeps redirect YAML from pulling in docbuild, the API
checks, and the per-team doc tests. That's no longer accurate on any of
the three: the per-team tests are selected by `<lib>_doc`, the two API
checks carry `doc_api` plus the library tags and no longer carry bare
`doc`, and the only remaining step carrying bare `doc` is `doc: build`,
which is `skip-on-premerge`. Since redirect YAML emits nothing at all on
master, this rule was never preventing over-triggering. It's additive,
and the comments now say so.

## Update: the step now selects itself

Cursor Bugbot caught that the redirect step wasn't reachable from an
edit to its own definition: `.buildkite/doc.rayci.yml` emitted `doc
doc_api` but never `doc_redirects`, so changing the redirect step's
commands wouldn't have run the redirect step. That contradicted the
rule's own stated reason for emitting `doc_api`, and this PR
demonstrated the gap: its previous revision noted that the new step
didn't execute here.

Fixed by giving `.buildkite/doc.rayci.yml` its own rule emitting `doc
doc_api doc_redirects`. It's a separate rule rather than an extra tag on
the autodoc-machinery block, because that block also covers `conf.py`,
`api_autogen.py`, and `doc/source/_ext/`, and a `conf.py` edit has no
business running the redirect check. The first attempt at this appended
the tag to the shared block and the full-repo sweep caught it
immediately: seven machinery files picked up `doc_redirects`.

AI assistance (Claude Code) was used to draft the CI step, the rebase
conflict resolution, and this description. Every changed line was
reviewed by hand, and the verification above was run as described. This
isn't duplicating existing work: no other open PR adds redirect
validation to premerge, and the `doc_redirects` tag doesn't exist on
master.

## Update: uv, and a recursive fail-closed guard

Two review follow-ups.

**Install with `uv`** (Elliot's suggestion).
`ci/docker/forge.Dockerfile` already installs uv to `/usr/local/bin` and
uses it for the image's Python, so the step needs no extra setup. It's
`uv tool install` rather than `uv pip install --system` for a PATH
reason: the previous revision's premerge log shows `pip install` fell
back to a user install, so the `rtd-redirects` entry point resolved from
`~/.local/bin`. `uv tool install` writes executables to that same
directory, so PATH resolution is unchanged. `uv pip install --system`
would target the uv-managed interpreter and put the entry point in that
env's `bin`, which isn't on PATH.

**The fail-closed guard now recurses.** Cursor Bugbot caught that the
guard's single-level shell glob didn't cover a nested redirect file, and
it was right. The rule engine matches with `fnmatch`, whose `*` crosses
`/`, so `doc/redirects/nested/foo.yaml` emits `doc_redirects` and
selects this step, while `ls doc/redirects/*.yaml` never saw it and the
guard passed. Replacing the glob with `find` closes the gap. Exercised
three ways locally: passes with only `current.yaml`, exits non-zero for
a nested file and for a sibling file.

A `.yml` file stays out of scope. The tag rule matches `*.yaml` only, so
`doc/redirects/current.yml` emits no tags and never selects the step,
putting it beyond the guard's reach. That matches the pre-PR baseline
for every redirect file rather than regressing anything, and
`rtd-redirects` uses `.yaml`.

Re-verified after the change: rules parse clean and all 126 cases in
`test.rules.test.txt` replay green (the rule files are untouched by this
revision).

## Related issue number

N/A

## Checks

- [x] I've signed off every commit (`-s`), because all commits are
squashed into one when merged.
- [x] I've run `scripts/format.sh` to lint the changes in this PR. (Via
`pre-commit`; the applicable hooks pass.)
- [x] I've made sure the tests are passing.
- Testing Strategy
   - [x] Unit tests
   - [ ] Release tests
   - [ ] This PR is not tested :(

---------

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

2 participants