Skip to content

[RLlib] Fix API-doc consistency check for the new reverse/dedup policies - #64807

Merged
ArturNiederfahrenhorst merged 3 commits into
ray-project:masterfrom
ArturNiederfahrenhorst:rllib-fix-api-doc-consistency
Jul 20, 2026
Merged

ArturNiederfahrenhorst merged 3 commits into
ray-project:masterfrom
ArturNiederfahrenhorst:rllib-fix-api-doc-consistency

Conversation

@ArturNiederfahrenhorst

Copy link
Copy Markdown
Contributor

#64420 added reverse (documented-must-resolve-to-public) and dedup (documented-exactly-once) policies to the API-doc consistency check, and #64783/#64786 populated per-team exemptions for every team except RLlib (whose white_list_apis was left empty). The stricter check now flags ~30 pre-existing RLlib doc entries, failing the "doc: check API doc consistency" premerge job on every PR that merges current master.

This fixes the RLlib side:

Unresolved doc entries:

  • De-double autoclass targets that combined .. currentmodule:: with a fully-qualified name (RLlink, ConnectorV2, ConnectorPipelineV2, the observation preprocessors, and the RLModule apis classes) by making the autoclass argument relative to its currentmodule.
  • RLModuleSpec dataclass fields -> .. autoattribute:: ... :no-index: (mirrors the existing MultiRLModuleSpec block).
  • RLModule instance attributes (observation_space, action_space, inference_only, model_config) are assigned in setup(), not on the class, so they resolve to None; exempt them via doc_only_whitelist.

Documented private/dunder objects:

  • Whitelist the intentional override contract (RLModule._forward*, Learner._make_module).
  • Remove doc entries for internal helpers (Learner._check_is_built / _check_registered_optimizer / _set_optimizer_lr / _get_clip_function, Scheduler._create_tensor_variable, OfflineData/OfflinePreLearner privates, SingleAgentEpisode/MultiAgentEpisode.len).

Duplicate documentation:

  • Mark intentional cross-page duplicates as intentional_duplicate_apis (AlgorithmConfig.build_learner / build_learner_group / learners; Checkpointable.save_to_path / restore_from_path, inherited and shown on each subclass page).

@ArturNiederfahrenhorst
ArturNiederfahrenhorst requested review from a team as code owners July 16, 2026 13:14

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request cleans up the RLlib API documentation by removing private methods, magic methods (such as __len__, __init__, and __call__), and updating class references to use relative paths with the .. currentmodule:: directive. It also updates the API discrepancy checker whitelist to accommodate RLlib's specific documentation patterns. The reviewer identified a critical issue in connector-v2.rst where changing to relative class names without updating the .. currentmodule:: directive would cause Sphinx resolution failures for observation preprocessors.

@ray-gardener ray-gardener Bot added rllib RLlib related issues docs An issue or change related to documentation labels Jul 16, 2026

@dstrodtman dstrodtman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Look at gemini comment but ✅

@ArturNiederfahrenhorst ArturNiederfahrenhorst added the go add ONLY when ready to merge, run all tests label Jul 16, 2026
ArturNiederfahrenhorst and others added 2 commits July 16, 2026 14:14
(documented-exactly-once) policies to the API-doc consistency check, and
(whose white_list_apis was left empty). The stricter check now flags ~30
pre-existing RLlib doc entries, failing the "doc: check API doc
consistency" premerge job on every PR that merges current master.

This fixes the RLlib side:

Unresolved doc entries:
- De-double autoclass targets that combined `.. currentmodule::` with a
  fully-qualified name (RLlink, ConnectorV2, ConnectorPipelineV2, the
  observation preprocessors, and the RLModule `apis` classes) by making the
  autoclass argument relative to its currentmodule.
- RLModuleSpec dataclass fields -> `.. autoattribute:: ... :no-index:`
  (mirrors the existing MultiRLModuleSpec block).
- RLModule instance attributes (observation_space, action_space,
  inference_only, model_config) are assigned in setup(), not on the class,
  so they resolve to None; exempt them via doc_only_whitelist.

Documented private/dunder objects:
- Whitelist the intentional override contract (RLModule._forward*,
  Learner._make_module).
- Remove doc entries for internal helpers (Learner._check_is_built /
  _check_registered_optimizer / _set_optimizer_lr / _get_clip_function,
  Scheduler._create_tensor_variable, OfflineData/OfflinePreLearner privates,
  SingleAgentEpisode/MultiAgentEpisode.__len__).

Duplicate documentation:
- Mark intentional cross-page duplicates as intentional_duplicate_apis
  (AlgorithmConfig.build_learner / build_learner_group / learners;
  Checkpointable.save_to_path / restore_from_path, inherited and shown on
  each subclass page).

Not a duplicate of open work: ray-project#64777 changes which CI tag runs the check
and ray-project#64770 is unrelated docs content; no open PR touches
cmd_check_api_discrepancy.py or the RLlib exemptions.

Test: `python ci/ray_ci/doc/cmd_check_api_discrepancy.py <ray_dir> rllib`
exits 0 (was exit 1). AI assistance (Claude Code) was used; the change has
been reviewed and is defended by the human submitter.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Signed-off-by: Artur Niederfahrenhorst <[email protected]>
…e override docs

The Read the Docs build (fail_on_warning) failed on two issues from the
previous commit:

- The `apis` autoclass directives used a dotted `submodule.Class` argument
  under a package-level `.. currentmodule::`. Sphinx autodoc reads that as an
  absolute `import submodule` (it does not prepend currentmodule for dotted
  args, unlike the doc-consistency checker), producing "autodoc: failed to
  import class". Switch to a per-class `.. currentmodule::` = the class's
  submodule + a bare class name, matching Ray Data's convention (for example,
  `ray.data.stats` + `DatasetSummary`). The classes stay registered at their
  submodule path, so the guide :py:meth: links keep resolving.

- Removing OfflineData.__init__, OfflinePreLearner.__call__, and
  OfflinePreLearner._map_to_episodes broke :py:meth: cross-references in
  rllib-offline.rst, which documents them as the offline-RL customization
  surface (with a worked _map_to_episodes override example). Restore those
  three to the API reference and white-list them (like RLModule._forward*).

Test: `python ci/ray_ci/doc/cmd_check_api_discrepancy.py <ray_dir> rllib`
exits 0. AI assistance (Claude Code) was used.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Signed-off-by: Artur Niederfahrenhorst <[email protected]>
elliot-barn pushed a commit that referenced this pull request Jul 17, 2026
…4818)

## Why

The API-doc consistency check (`ci/ray_ci/doc/api.py`,
`cmd_check_api_discrepancy.py`) flags any documented API whose canonical
name is private, where `_is_private_name()` treats a leading-underscore
final segment as private. That heuristic conflates the two meanings a
single leading underscore carries in Python. PEP 8 uses it for
"non-public / no stability guarantee," which is what the check wants to
catch. But with no `protected` keyword, the same underscore also marks a
**template-method override hook**: a public, non-overridable wrapper
that delegates to a protected, user-overridable method. That hook is an
intentional, documented extension point, not a private leak.

RLlib relies on this pattern. `RLModule._forward`,
`_forward_exploration`, `_forward_inference`, and `_forward_train` are
documented in `doc/source/rllib/package_ref/rl_modules.rst` ("Override
these private methods to define your custom model's forward behavior").
Users call the public `forward_train` and override `_forward_train`. The
check flags all four as non-public purely because of the leading
underscore, even though they resolve cleanly and are the documented
contract for subclassing a `@PublicAPI(stability="beta")` class. They
were parked in the RLlib `tracked_doc_debt` list to green the check,
which records the exception by name and grows with every new documented
override hook.

## What

Teach the check to exempt an underscore-named object from the
private-name rule when it carries the `__is_overridden__` marker that
`@OverrideToImplementCustomLogic` (and the `_CallToSuperRecommended`
variant) sets. A method tagged as an intentional override hook is a
declared public extension point, so its leading underscore should not
read as "private." This keys the exemption off an explicit,
machine-readable signal of intent instead of a hand-maintained name
list.

- **`ci/ray_ci/doc/api.py`** — add `API._is_override_hook(obj)` and
apply it in `split_resolvable_and_broken_doc_apis`. The exemption reads
the attribute generically (`hasattr(obj, "__is_overridden__")`), so the
shared check needs no RLlib import. It affects only the non-public
classification; the unresolved-name and duplicate-documentation checks
are unchanged. A `@Deprecated` annotation is still fatal, and a plain
`_helper` with no marker still fails.
- **`ci/ray_ci/doc/cmd_check_api_discrepancy.py`** — retire the four
`RLModule._forward*` entries from the RLlib tracked-doc-debt list, now
covered by the marker exemption. The genuine private/dunder entries
stay.
- **`ci/ray_ci/doc/mock/mock_module.py`, `test_api.py`** — add coverage
for a documented underscore method that is / isn't tagged as an override
hook.

Note on the signal: the decorators set `__is_overridden__ = False` on
the base method, and `is_overridden()` returns `True` by default for
undecorated objects, so the intent signal is the *presence* of the
attribute, not its value.

## Checks

- `ci/ray_ci/doc/test_api.py` and
`ci/ray_ci/doc/test_cmd_check_api_discrepancy.py` pass locally.
- Full pre-commit suite (ruff/black/import-order/docstyle/semgrep)
passes.
- The `doc: check API doc consistency` premerge job is the authoritative
gate.

## Related

Overlaps the RLlib config block edited by #64807 (short-term whitelist +
`.rst` fixes) — this exemption makes the four `_forward*` debt entries
dead, so once it lands the RLlib side is covered regardless of merge
order. The classification function is also touched by the analogous Data
`__all__` signal-over-whitelist change; whichever merges second rebases.

---------

Signed-off-by: Douglas Strodtman <[email protected]>
Resolve the cmd_check_api_discrepancy.py conflict with ray-project#64818: drop master's
rllib tracked_doc_debt block (superseded) and keep this PR's real fixes.
The four RLModule._forward* whitelist entries are removed — they are now
exempted generically by the @OverrideToImplementCustomLogic marker added in
 ray-project#64818 (API._is_override_hook). Verified: the rllib API-doc check passes
(exit 0) against the merged tree.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Signed-off-by: Artur Niederfahrenhorst <[email protected]>
@ArturNiederfahrenhorst
ArturNiederfahrenhorst merged commit 72d251b into ray-project:master Jul 20, 2026
3 checks passed
400Ping pushed a commit to 400Ping/ray that referenced this pull request Aug 18, 2026
…y-project#64818)

## Why

The API-doc consistency check (`ci/ray_ci/doc/api.py`,
`cmd_check_api_discrepancy.py`) flags any documented API whose canonical
name is private, where `_is_private_name()` treats a leading-underscore
final segment as private. That heuristic conflates the two meanings a
single leading underscore carries in Python. PEP 8 uses it for
"non-public / no stability guarantee," which is what the check wants to
catch. But with no `protected` keyword, the same underscore also marks a
**template-method override hook**: a public, non-overridable wrapper
that delegates to a protected, user-overridable method. That hook is an
intentional, documented extension point, not a private leak.

RLlib relies on this pattern. `RLModule._forward`,
`_forward_exploration`, `_forward_inference`, and `_forward_train` are
documented in `doc/source/rllib/package_ref/rl_modules.rst` ("Override
these private methods to define your custom model's forward behavior").
Users call the public `forward_train` and override `_forward_train`. The
check flags all four as non-public purely because of the leading
underscore, even though they resolve cleanly and are the documented
contract for subclassing a `@PublicAPI(stability="beta")` class. They
were parked in the RLlib `tracked_doc_debt` list to green the check,
which records the exception by name and grows with every new documented
override hook.

## What

Teach the check to exempt an underscore-named object from the
private-name rule when it carries the `__is_overridden__` marker that
`@OverrideToImplementCustomLogic` (and the `_CallToSuperRecommended`
variant) sets. A method tagged as an intentional override hook is a
declared public extension point, so its leading underscore should not
read as "private." This keys the exemption off an explicit,
machine-readable signal of intent instead of a hand-maintained name
list.

- **`ci/ray_ci/doc/api.py`** — add `API._is_override_hook(obj)` and
apply it in `split_resolvable_and_broken_doc_apis`. The exemption reads
the attribute generically (`hasattr(obj, "__is_overridden__")`), so the
shared check needs no RLlib import. It affects only the non-public
classification; the unresolved-name and duplicate-documentation checks
are unchanged. A `@Deprecated` annotation is still fatal, and a plain
`_helper` with no marker still fails.
- **`ci/ray_ci/doc/cmd_check_api_discrepancy.py`** — retire the four
`RLModule._forward*` entries from the RLlib tracked-doc-debt list, now
covered by the marker exemption. The genuine private/dunder entries
stay.
- **`ci/ray_ci/doc/mock/mock_module.py`, `test_api.py`** — add coverage
for a documented underscore method that is / isn't tagged as an override
hook.

Note on the signal: the decorators set `__is_overridden__ = False` on
the base method, and `is_overridden()` returns `True` by default for
undecorated objects, so the intent signal is the *presence* of the
attribute, not its value.

## Checks

- `ci/ray_ci/doc/test_api.py` and
`ci/ray_ci/doc/test_cmd_check_api_discrepancy.py` pass locally.
- Full pre-commit suite (ruff/black/import-order/docstyle/semgrep)
passes.
- The `doc: check API doc consistency` premerge job is the authoritative
gate.

## Related

Overlaps the RLlib config block edited by ray-project#64807 (short-term whitelist +
`.rst` fixes) — this exemption makes the four `_forward*` debt entries
dead, so once it lands the RLlib side is covered regardless of merge
order. The classification function is also touched by the analogous Data
`__all__` signal-over-whitelist change; whichever merges second rebases.

---------

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
…ies (ray-project#64807)

ray-project#64420 added reverse (documented-must-resolve-to-public) and dedup
(documented-exactly-once) policies to the API-doc consistency check, and
ray-project#64783/ray-project#64786 populated per-team exemptions for every team except RLlib
(whose white_list_apis was left empty). The stricter check now flags ~30
pre-existing RLlib doc entries, failing the "doc: check API doc
consistency" premerge job on every PR that merges current master.

This fixes the RLlib side:

Unresolved doc entries:
- De-double autoclass targets that combined `.. currentmodule::` with a
fully-qualified name (RLlink, ConnectorV2, ConnectorPipelineV2, the
observation preprocessors, and the RLModule `apis` classes) by making
the autoclass argument relative to its currentmodule.
- RLModuleSpec dataclass fields -> `.. autoattribute:: ... :no-index:`
(mirrors the existing MultiRLModuleSpec block).
- RLModule instance attributes (observation_space, action_space,
inference_only, model_config) are assigned in setup(), not on the class,
so they resolve to None; exempt them via doc_only_whitelist.

Documented private/dunder objects:
- Whitelist the intentional override contract (RLModule._forward*,
Learner._make_module).
- Remove doc entries for internal helpers (Learner._check_is_built /
_check_registered_optimizer / _set_optimizer_lr / _get_clip_function,
Scheduler._create_tensor_variable, OfflineData/OfflinePreLearner
privates, SingleAgentEpisode/MultiAgentEpisode.__len__).

Duplicate documentation:
- Mark intentional cross-page duplicates as intentional_duplicate_apis
(AlgorithmConfig.build_learner / build_learner_group / learners;
Checkpointable.save_to_path / restore_from_path, inherited and shown on
each subclass page).

---------

Signed-off-by: Artur Niederfahrenhorst <[email protected]>
Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
Signed-off-by: 400Ping <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs An issue or change related to documentation go add ONLY when ready to merge, run all tests rllib RLlib related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants