Repository navigation
[ci/doc] Add diff-scoped @PublicAPI parameter-coverage check - #64788
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a static, diff-scoped parameter-coverage check for Ray's public API surface, ensuring newly added public APIs or parameters are documented in docstrings. Feedback on the implementation highlights a few bugs, including a path-filtering issue when the checkout directory contains a skip segment, an unhandled git subprocess error, and a parsing bug where decreased indentation does not terminate the docstring Args: block. Additionally, several type-hinting improvements are suggested to use more precise AST node types instead of generic ast.AST.
|
This pull request has been automatically marked as stale because it has not had You can always ask for help on our discussion forum or Ray's public slack channel. If you'd like to keep this open, just leave any comment, and the stale label will be removed. |
…ck (#65208) ## Why Follow-up to #65196, which stopped the API walk (`Module._is_api`) and the subpackage guard (`_import_status`) from treating an inherited annotation as an owned one. A third reader of that marker family was left on a plain `getattr`: ```python annotated_type = getattr(obj, "_annotated_type", None) # ci/ray_ci/doc/api.py ``` `_annotated_type` is a plain class attribute, so an undecorated subclass reads its base's value. That value is the only input to the "documented APIs resolve to public code" check (`split_resolvable_and_broken_doc_apis`), which means a documented, undecorated subclass of a `@Deprecated` class fails as "documented API resolves to a deprecated object" — on a doc entry that's correct, for a class nobody deprecated. Same inheritance bug as #65196, opposite direction. It's latent today and stays latent until someone documents such a subclass, at which point it presents as an unexplained premerge failure on a correct doc change. Leaving it also means the checker carries two different definitions of "annotated" on the two sides of the same discrepancy check. ## What Route `introspect_annotation_type` through `_is_directly_annotated`. This is safe in both directions: - an inherited `@Deprecated` resolves to `UNKNOWN` and is accepted, removing the false failure - an inherited `@PublicAPI` resolves to `UNKNOWN` and is still accepted, since `UNKNOWN` is already the accepted case for a documented method of an annotated class Methods are unaffected either way — functions don't inherit class attributes, so `Dataset.map_batches` already resolved to `UNKNOWN`. `_is_directly_annotated` moves from `module.py` to `api.py` so both sides share one definition. `module.py` already imports from `api.py`, so leaving it in place would have made the dependency circular. Its docstring now names `ray.util.annotations._is_annotated` as the definition it deliberately mirrors, so the name-equality edge case doesn't later get "fixed" into disagreeing with what Ray's runtime considers annotated. Also refreshes the `_import_status` docstring, which still described the `hasattr` rule #65196 replaced. ## Tests - A `@Deprecated` class and an undecorated subclass added to the mock fixture. - `test_introspect_annotation_type_ignores_inherited_annotations` — covers both directions, and asserts the directly-annotated base still reads `DEPRECATED` so the rule keeps its teeth. - `test_split_resolvable_accepts_subclass_of_deprecated_class` — end-to-end regression through the check that would actually have failed. Both new tests fail without the `api.py` change (verified locally by reverting it). Two hardening changes to the existing tests while the fixture grew: - `test_walk` is rekeyed by name instead of list index. It silently depended on `dir()` ordering of the mock module, so any annotated symbol added to the fixture renumbered its assertions. - `test_walk_ignores_inherited_api_annotations` gains a positive control. As written it asserts only absence, so it would pass if the walk found nothing at all. Full suite: 44 passed (`ci/ray_ci/doc/`, excluding `test_update_cache_env.py`, which needs Sphinx installed). ## Related Follow-up to #65196. Consistent with the AST-based `@PublicAPI` detection in #64788, which reads decorator nodes directly and so never had this bug — after this the runtime walk and the static check agree on what "annotated" means. Signed-off-by: Douglas Strodtman <[email protected]>
Adds a static, diff-scoped check that fails a PR which adds a new @publicapi callable, or a new parameter on an existing one, without a docstring Args: entry. The intent is "no new debt": pre-existing undocumented parameters are grandfathered, and only newly-undocumented parameters on the changed public surface are reported. pydoclint (already run in pre-commit) has no @publicapi awareness, so turning its argument-completeness checks on repo-wide would grandfather ~6,800 DOC101/DOC103 violations across all of python/ray, public and private, versus the ~400 gaps on the rendered public API. This check scopes exactly to the @publicapi surface with no baseline file: it parses the base-branch and working-tree versions of the changed files and diffs their undocumented-parameter sets, so it needs no Ray build or import environment. Lives in the ci/ray_ci/doc guard family next to cmd_check_api_discrepancy. Wired into the lint group as a soft_fail (visible but non-blocking) step to start; remove soft_fail to make it a required check once the false-positive rate is confirmed low. Only presence is checked: a parameter counts as documented if its name appears in an Args:/Arguments: block (or, for __init__, the class docstring). Description prose is not inspected. Signed-off-by: Douglas Strodtman <[email protected]>
…types - Match skip segments against the repo-relative path in _iter_source_files so a checkout dir whose absolute path contains a skip segment (e.g. under ".../test/...") no longer skips every source file. - Wrap the git-diff call in _changed_python_files and re-raise as RuntimeError so main() handles it under the warn/blocking posture instead of crashing. - End an Args: block when a line dedents below the first parameter's indent, so trailing "name:"-looking prose is not parsed as a documented param. - Tighten AST node type hints (Union of FunctionDef/AsyncFunctionDef/ClassDef) where .decorator_list/.args/.name are accessed. Signed-off-by: Douglas Strodtman <[email protected]>
Signed-off-by: Douglas Strodtman <[email protected]>
The param-coverage check runs in the plain lint container, which has no third-party deps, so the click import raised ModuleNotFoundError. Switch the command to stdlib argparse and drop the click bazel dep, matching the check's static, no-build design. Also suppress the docstyle grep on an intentional typed-arg test fixture (`b (int):`) with a noqa marker; the fixture verifies the parser handles typed docstring args. Signed-off-by: Douglas Strodtman <[email protected]>
70e8334 to
2583373
Compare
…asses A method of an @publicapi class was pulled into the checked surface regardless of its own annotation, so an @DeveloperAPI or @deprecated method was treated as public API. Replaying the check over the last 200 merged commits touching python/ray surfaced this as its only false positive: ray-project#64963 flagged Dataset.map_batches_internal, an @DeveloperAPI method, with 15 parameters. Skip methods carrying their own non-public annotation, while letting an explicit @publicapi on the method win over both. This matches what has_publicapi_decorator already documented but only enforced at class and module level. Signed-off-by: Douglas Strodtman <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request introduces a static, diff-scoped parameter-coverage check for Ray's public API surface, ensuring that any new or modified @PublicAPI callables have their parameters documented in their docstrings. The implementation includes the core AST-based analysis, a Git-integrated CLI tool, Bazel build configurations, and unit tests. The review feedback is highly constructive, pointing out critical cross-platform compatibility issues on Windows (such as path separator mismatches and default encoding issues in subprocess calls) and an AST parsing limitation regarding generic/subscripted base classes.
| def _git(checkout_dir: str, *args: str) -> str: | ||
| return subprocess.check_output( | ||
| ["git", "-C", checkout_dir, *args], text=True, stderr=subprocess.DEVNULL | ||
| ) |
There was a problem hiding this comment.
Using text=True in subprocess.check_output decodes the output using the system's default encoding (e.g., CP1252 on Windows), which can fail or corrupt characters if the git output contains UTF-8 characters. Specifying encoding="utf-8" ensures consistent and correct decoding across all platforms.
| def _git(checkout_dir: str, *args: str) -> str: | |
| return subprocess.check_output( | |
| ["git", "-C", checkout_dir, *args], text=True, stderr=subprocess.DEVNULL | |
| ) | |
| def _git(checkout_dir: str, *args: str) -> str: | |
| return subprocess.check_output( | |
| ["git", "-C", checkout_dir, *args], encoding="utf-8", stderr=subprocess.DEVNULL | |
| ) |
There was a problem hiding this comment.
Fixed in 2a50eb893e — _git now passes encoding="utf-8" instead of text=True, so git output decodes consistently regardless of the platform locale.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
Reviewed by Cursor Bugbot for commit 9eb7e46. Configure here.
…ng handling Review follow-ups: - git diff ran without rename detection, so a renamed file looked like a new one, _base_content returned None, and every pre-existing gap in it was reported as new debt. Renaming python/ray/exceptions.py with no content change produced 22 violations across 11 callables. Switch to --name-status -M and read base content from the pre-rename path. - _base_names ignored subscripted bases, so docstring inheritance did not resolve through a generic parent (class Impl(Base[T])). Unwrapping the subscript clears 29 callables and 41 parameters that were previously reported as gaps. - Normalize os.path.relpath output to forward slashes so working-tree paths compare correctly against git output on Windows. - Decode git output as UTF-8 explicitly rather than via the locale default. Adds six tests covering rename and copy mapping, add/modify paths, scope filtering, a rename whose destination leaves scope, and inheritance through a subscripted base. Signed-off-by: Douglas Strodtman <[email protected]>
The :doc py_library globs *.py but excludes cmd_*.py, so cmd_check_api_param_coverage.py never landed in the test's runfiles and the test failed at import. List it in srcs directly, matching the existing test_cmd_check_api_discrepancy target. Signed-off-by: Douglas Strodtman <[email protected]>
…ck (ray-project#65208) ## Why Follow-up to ray-project#65196, which stopped the API walk (`Module._is_api`) and the subpackage guard (`_import_status`) from treating an inherited annotation as an owned one. A third reader of that marker family was left on a plain `getattr`: ```python annotated_type = getattr(obj, "_annotated_type", None) # ci/ray_ci/doc/api.py ``` `_annotated_type` is a plain class attribute, so an undecorated subclass reads its base's value. That value is the only input to the "documented APIs resolve to public code" check (`split_resolvable_and_broken_doc_apis`), which means a documented, undecorated subclass of a `@Deprecated` class fails as "documented API resolves to a deprecated object" — on a doc entry that's correct, for a class nobody deprecated. Same inheritance bug as ray-project#65196, opposite direction. It's latent today and stays latent until someone documents such a subclass, at which point it presents as an unexplained premerge failure on a correct doc change. Leaving it also means the checker carries two different definitions of "annotated" on the two sides of the same discrepancy check. ## What Route `introspect_annotation_type` through `_is_directly_annotated`. This is safe in both directions: - an inherited `@Deprecated` resolves to `UNKNOWN` and is accepted, removing the false failure - an inherited `@PublicAPI` resolves to `UNKNOWN` and is still accepted, since `UNKNOWN` is already the accepted case for a documented method of an annotated class Methods are unaffected either way — functions don't inherit class attributes, so `Dataset.map_batches` already resolved to `UNKNOWN`. `_is_directly_annotated` moves from `module.py` to `api.py` so both sides share one definition. `module.py` already imports from `api.py`, so leaving it in place would have made the dependency circular. Its docstring now names `ray.util.annotations._is_annotated` as the definition it deliberately mirrors, so the name-equality edge case doesn't later get "fixed" into disagreeing with what Ray's runtime considers annotated. Also refreshes the `_import_status` docstring, which still described the `hasattr` rule ray-project#65196 replaced. ## Tests - A `@Deprecated` class and an undecorated subclass added to the mock fixture. - `test_introspect_annotation_type_ignores_inherited_annotations` — covers both directions, and asserts the directly-annotated base still reads `DEPRECATED` so the rule keeps its teeth. - `test_split_resolvable_accepts_subclass_of_deprecated_class` — end-to-end regression through the check that would actually have failed. Both new tests fail without the `api.py` change (verified locally by reverting it). Two hardening changes to the existing tests while the fixture grew: - `test_walk` is rekeyed by name instead of list index. It silently depended on `dir()` ordering of the mock module, so any annotated symbol added to the fixture renumbered its assertions. - `test_walk_ignores_inherited_api_annotations` gains a positive control. As written it asserts only absence, so it would pass if the walk found nothing at all. Full suite: 44 passed (`ci/ray_ci/doc/`, excluding `test_update_cache_env.py`, which needs Sphinx installed). ## Related Follow-up to ray-project#65196. Consistent with the AST-based `@PublicAPI` detection in ray-project#64788, which reads decorator nodes directly and so never had this bug — after this the runtime walk and the static check agree on what "annotated" means. Signed-off-by: Douglas Strodtman <[email protected]>
…ck (ray-project#65208) ## Why Follow-up to ray-project#65196, which stopped the API walk (`Module._is_api`) and the subpackage guard (`_import_status`) from treating an inherited annotation as an owned one. A third reader of that marker family was left on a plain `getattr`: ```python annotated_type = getattr(obj, "_annotated_type", None) # ci/ray_ci/doc/api.py ``` `_annotated_type` is a plain class attribute, so an undecorated subclass reads its base's value. That value is the only input to the "documented APIs resolve to public code" check (`split_resolvable_and_broken_doc_apis`), which means a documented, undecorated subclass of a `@Deprecated` class fails as "documented API resolves to a deprecated object" — on a doc entry that's correct, for a class nobody deprecated. Same inheritance bug as ray-project#65196, opposite direction. It's latent today and stays latent until someone documents such a subclass, at which point it presents as an unexplained premerge failure on a correct doc change. Leaving it also means the checker carries two different definitions of "annotated" on the two sides of the same discrepancy check. ## What Route `introspect_annotation_type` through `_is_directly_annotated`. This is safe in both directions: - an inherited `@Deprecated` resolves to `UNKNOWN` and is accepted, removing the false failure - an inherited `@PublicAPI` resolves to `UNKNOWN` and is still accepted, since `UNKNOWN` is already the accepted case for a documented method of an annotated class Methods are unaffected either way — functions don't inherit class attributes, so `Dataset.map_batches` already resolved to `UNKNOWN`. `_is_directly_annotated` moves from `module.py` to `api.py` so both sides share one definition. `module.py` already imports from `api.py`, so leaving it in place would have made the dependency circular. Its docstring now names `ray.util.annotations._is_annotated` as the definition it deliberately mirrors, so the name-equality edge case doesn't later get "fixed" into disagreeing with what Ray's runtime considers annotated. Also refreshes the `_import_status` docstring, which still described the `hasattr` rule ray-project#65196 replaced. ## Tests - A `@Deprecated` class and an undecorated subclass added to the mock fixture. - `test_introspect_annotation_type_ignores_inherited_annotations` — covers both directions, and asserts the directly-annotated base still reads `DEPRECATED` so the rule keeps its teeth. - `test_split_resolvable_accepts_subclass_of_deprecated_class` — end-to-end regression through the check that would actually have failed. Both new tests fail without the `api.py` change (verified locally by reverting it). Two hardening changes to the existing tests while the fixture grew: - `test_walk` is rekeyed by name instead of list index. It silently depended on `dir()` ordering of the mock module, so any annotated symbol added to the fixture renumbered its assertions. - `test_walk_ignores_inherited_api_annotations` gains a positive control. As written it asserts only absence, so it would pass if the walk found nothing at all. Full suite: 44 passed (`ci/ray_ci/doc/`, excluding `test_update_cache_env.py`, which needs Sphinx installed). ## Related Follow-up to ray-project#65196. Consistent with the AST-based `@PublicAPI` detection in ray-project#64788, which reads decorator nodes directly and so never had this bug — after this the runtime walk and the static check agree on what "annotated" means. Signed-off-by: Douglas Strodtman <[email protected]> Signed-off-by: 400Ping <[email protected]>
…ject#64788) ## Why Ray's public API reference accretes undocumented parameters over time: a new `@PublicAPI` callable, or a new parameter on an existing one, can ship without a docstring `Args:` entry, and nothing fails. This adds a **static, diff-scoped** check that blocks *new* debt on the `@PublicAPI` surface while grandfathering the standing backlog. ### What pydoclint already covers, and the gap it leaves pydoclint (pinned at `0.8.3` in `.pre-commit-config.yaml`) already runs its argument-completeness checks `DOC101`/`DOC103` repo-wide across `python/ray`, against an **empty** `ci/lint/pydoclint-baseline.txt`. So that class of violation is already fully enforced with zero grandfathering, and the tree is essentially clean: a repo-wide run under the exact pre-commit config flags exactly **one** callable, `_find_imported_submodules` in vendored `python/ray/cloudpickle/cloudpickle.py`, which is private. The per-module cleanups (ray-project#63500, ray-project#63509, ray-project#63518, ray-project#63541, ray-project#63571, ray-project#63632, ray-project#63633, ray-project#63634, ray-project#63639) are what got it there. The gap is `--skip-checking-short-docstrings`, which defaults to `True` and is not overridden. It makes pydoclint skip any callable whose docstring is absent or is a bare one-line summary with no sections. Those callables can gain parameters indefinitely without any check firing. Flipping that one flag is not a viable fix. Repo-wide with `--skip-checking-short-docstrings=False`, `DOC101`/`DOC103` fire on **8,285** callables across `python/ray` (public and private alike; 16,570 violations, since each callable trips both codes) -- precisely the "baseline the size of the codebase" that the config comment on master already says the team doesn't want, and it has no `@PublicAPI` awareness to narrow it. Measured on the `@PublicAPI` surface, the same unit for comparison: of 815 public callables that take parameters, **230** have at least one undocumented parameter, totalling **505** undocumented parameters. So the public surface is roughly 3% of what a repo-wide flag flip would drag in. **All 230 of them sit in pydoclint's blind spot** -- zero overlap with what `DOC101`/`DOC103` catch today. That falls out of the numbers above without relying on any modelling of pydoclint's "short docstring" rule: if any `@PublicAPI` callable had a section-bearing docstring missing a param, pydoclint would already report `DOC101` on it, and the only such callable in the tree is a private cloudpickle function. The two checks partition the problem rather than duplicating it. This check therefore scopes exactly to the `@PublicAPI` surface with **no baseline file**: it parses the base-branch and working-tree versions of the changed files and diffs their undocumented-parameter sets, so it needs **no Ray build or import environment**. ## What it does - Enumerates the `@PublicAPI` callables changed by the PR (module-level `@PublicAPI` functions and methods of `@PublicAPI` classes). A method that carries its own `@DeveloperAPI` or `@Deprecated` is out of scope even on a public class, since it isn't part of the rendered surface; an explicit `@PublicAPI` on the method wins over both. - For each, computes the signature parameters missing from the docstring `Args:`/`Arguments:` block (for `__init__`, also the class docstring, matching the default `autoclass_content="class"`), resolving docstring inheritance so an override with no own docstring isn't flagged when a base documents the param. - Fails only on parameters that are **newly** undocumented versus the base branch. Pre-existing gaps are grandfathered; the gate fires on new public callables, newly-added params, and doc entries removed from an existing param. **Scope and limits (intentional):** all signature params, not only annotated ones. Presence only -- a param counts as documented if its name appears in `Args:`; description prose is not inspected (empty-description detection would need `numpydoc.validate` and is out of scope). Static source analysis, so it does not confirm what the reference actually renders. ## Where it lives / rollout Sits in the `ci/ray_ci/doc` guard family next to `cmd_check_api_discrepancy.py`, and runs in the **lint group** (static, no docbuild). It starts as a `soft_fail: true` step -- **visible but non-blocking** -- so the measured false-positive rate above can be confirmed against live traffic before the check gates anything. Flipping it to a required check is a one-line removal of `soft_fail`. One caveat for reviewers on the warn phase: the pipeline passes `--blocking` and relies on `soft_fail` to absorb the exit code, so an environment failure (an unfetched base branch, a shallow clone deeper than `--depth=500`) surfaces the same way a finding does. Happy to drop `--blocking` from the pipeline command instead, so the script's own warn mode carries the phase and infrastructure errors stay distinguishable from real findings. Because the check is AST-based, it matches only *directly* applied `@PublicAPI` decorators, which lines up with the direct-annotation policy established in ray-project#65196 and ray-project#65208. ## Testing - `python -m pytest ci/ray_ci/doc/test_api_param_coverage.py` -- **28 passed**. Covers new API, new param, grandfathered gap, removed doc entry, non-public / private skips, `@PublicAPI(...)` call form, `__init__`-on-class-docstring, `Args:` block termination on dedent, docstring-inheritance recovery, and the `@DeveloperAPI`/`@Deprecated`-method scoping rule. - End-to-end on the pydoclint blind spot, which is the case this check exists for: adding an undocumented `strict` param to `RayError.from_bytes` (a `@PublicAPI` method with no docstring) fired on exactly `strict`, while pydoclint under the pre-commit config reported no violations on the same file. `--blocking` exits 1; documenting the param cleared it. - End-to-end on a case pydoclint *does* cover, to confirm agreement rather than contradiction: adding an undocumented `seed` param to `tune.loguniform` fired on exactly `seed` and correctly grandfathered the pre-existing gaps in the same file. pydoclint independently blocks this one at pre-commit. - `shellcheck ci/lint/lint.sh` clean; `.buildkite/lint.rayci.yml` parses. - Renaming `python/ray/exceptions.py` with no content change reported 22 violations across 11 callables before rename detection was added, and reports none after. A rename that also adds an undocumented param still fires on exactly that param. ### False-positive rate, measured against real history Replayed the check over the **200** most recent merged commits touching `python/ray/**/*.py`, each evaluated against its own parent. **Two** fired (1%): - ray-project#64963 flagged `Dataset.map_batches_internal` with 15 parameters. A genuine false positive: the method is `@DeveloperAPI`, but the check was pulling in every non-underscore method of an `@PublicAPI` class regardless of the method's own annotation. Fixed in this PR, with regression tests; the commit is clean on the replay now. - ray-project#64519 flagged `mode`, a newly added and undocumented parameter on `Catalog.resolve` (`@PublicAPI(stability="alpha")`, one-line docstring). A true positive, and squarely the blind-spot class this check exists for. It correctly grandfathered the pre-existing `table` and `reader` gaps on the same callable. Post-fix that is **one firing across 200 commits, and it is a real finding**. ### False-negative probe Coverage was probed independently of the replay: for every `@PublicAPI` callable on the surface, inject a new undocumented keyword parameter and assert the check reports it. **815 callables probed, 0 misses** -- 585 that are currently fully documented, plus the 230 that already carry gaps, which verifies that grandfathering an existing gap doesn't mask a newly added parameter. Broken out by shape: 176 module-level functions, 470 methods, 157 `__init__`, and 12 async methods, with no misses in any group. ## Alternatives considered - **Flip `--skip-checking-short-docstrings=False` repo-wide.** 8,285 callables, no `@PublicAPI` scoping. Rejected above. - **A second pydoclint invocation with that flag plus its own baseline.** pre-commit is already diff-scoped, so this is closer than it looks, but it requires committing a baseline on the order of 8,000 entries and still gates all of `python/ray` rather than the rendered public surface. ## Relationship to other open work No open PR builds a parameter-coverage gate. ray-project#64779 changes how type hints render into the Parameters list, which is a separate deliverable and does not gate new undocumented params. ## AI assistance This change was developed with AI assistance. The submitter has reviewed every changed line and run the tests above locally. --------- Signed-off-by: Douglas Strodtman <[email protected]> Signed-off-by: 400Ping <[email protected]>
…ck (ray-project#65208) ## Why Follow-up to ray-project#65196, which stopped the API walk (`Module._is_api`) and the subpackage guard (`_import_status`) from treating an inherited annotation as an owned one. A third reader of that marker family was left on a plain `getattr`: ```python annotated_type = getattr(obj, "_annotated_type", None) # ci/ray_ci/doc/api.py ``` `_annotated_type` is a plain class attribute, so an undecorated subclass reads its base's value. That value is the only input to the "documented APIs resolve to public code" check (`split_resolvable_and_broken_doc_apis`), which means a documented, undecorated subclass of a `@Deprecated` class fails as "documented API resolves to a deprecated object" — on a doc entry that's correct, for a class nobody deprecated. Same inheritance bug as ray-project#65196, opposite direction. It's latent today and stays latent until someone documents such a subclass, at which point it presents as an unexplained premerge failure on a correct doc change. Leaving it also means the checker carries two different definitions of "annotated" on the two sides of the same discrepancy check. ## What Route `introspect_annotation_type` through `_is_directly_annotated`. This is safe in both directions: - an inherited `@Deprecated` resolves to `UNKNOWN` and is accepted, removing the false failure - an inherited `@PublicAPI` resolves to `UNKNOWN` and is still accepted, since `UNKNOWN` is already the accepted case for a documented method of an annotated class Methods are unaffected either way — functions don't inherit class attributes, so `Dataset.map_batches` already resolved to `UNKNOWN`. `_is_directly_annotated` moves from `module.py` to `api.py` so both sides share one definition. `module.py` already imports from `api.py`, so leaving it in place would have made the dependency circular. Its docstring now names `ray.util.annotations._is_annotated` as the definition it deliberately mirrors, so the name-equality edge case doesn't later get "fixed" into disagreeing with what Ray's runtime considers annotated. Also refreshes the `_import_status` docstring, which still described the `hasattr` rule ray-project#65196 replaced. ## Tests - A `@Deprecated` class and an undecorated subclass added to the mock fixture. - `test_introspect_annotation_type_ignores_inherited_annotations` — covers both directions, and asserts the directly-annotated base still reads `DEPRECATED` so the rule keeps its teeth. - `test_split_resolvable_accepts_subclass_of_deprecated_class` — end-to-end regression through the check that would actually have failed. Both new tests fail without the `api.py` change (verified locally by reverting it). Two hardening changes to the existing tests while the fixture grew: - `test_walk` is rekeyed by name instead of list index. It silently depended on `dir()` ordering of the mock module, so any annotated symbol added to the fixture renumbered its assertions. - `test_walk_ignores_inherited_api_annotations` gains a positive control. As written it asserts only absence, so it would pass if the walk found nothing at all. Full suite: 44 passed (`ci/ray_ci/doc/`, excluding `test_update_cache_env.py`, which needs Sphinx installed). ## Related Follow-up to ray-project#65196. Consistent with the AST-based `@PublicAPI` detection in ray-project#64788, which reads decorator nodes directly and so never had this bug — after this the runtime walk and the static check agree on what "annotated" means. Signed-off-by: Douglas Strodtman <[email protected]>
…ject#64788) ## Why Ray's public API reference accretes undocumented parameters over time: a new `@PublicAPI` callable, or a new parameter on an existing one, can ship without a docstring `Args:` entry, and nothing fails. This adds a **static, diff-scoped** check that blocks *new* debt on the `@PublicAPI` surface while grandfathering the standing backlog. ### What pydoclint already covers, and the gap it leaves pydoclint (pinned at `0.8.3` in `.pre-commit-config.yaml`) already runs its argument-completeness checks `DOC101`/`DOC103` repo-wide across `python/ray`, against an **empty** `ci/lint/pydoclint-baseline.txt`. So that class of violation is already fully enforced with zero grandfathering, and the tree is essentially clean: a repo-wide run under the exact pre-commit config flags exactly **one** callable, `_find_imported_submodules` in vendored `python/ray/cloudpickle/cloudpickle.py`, which is private. The per-module cleanups (ray-project#63500, ray-project#63509, ray-project#63518, ray-project#63541, ray-project#63571, ray-project#63632, ray-project#63633, ray-project#63634, ray-project#63639) are what got it there. The gap is `--skip-checking-short-docstrings`, which defaults to `True` and is not overridden. It makes pydoclint skip any callable whose docstring is absent or is a bare one-line summary with no sections. Those callables can gain parameters indefinitely without any check firing. Flipping that one flag is not a viable fix. Repo-wide with `--skip-checking-short-docstrings=False`, `DOC101`/`DOC103` fire on **8,285** callables across `python/ray` (public and private alike; 16,570 violations, since each callable trips both codes) -- precisely the "baseline the size of the codebase" that the config comment on master already says the team doesn't want, and it has no `@PublicAPI` awareness to narrow it. Measured on the `@PublicAPI` surface, the same unit for comparison: of 815 public callables that take parameters, **230** have at least one undocumented parameter, totalling **505** undocumented parameters. So the public surface is roughly 3% of what a repo-wide flag flip would drag in. **All 230 of them sit in pydoclint's blind spot** -- zero overlap with what `DOC101`/`DOC103` catch today. That falls out of the numbers above without relying on any modelling of pydoclint's "short docstring" rule: if any `@PublicAPI` callable had a section-bearing docstring missing a param, pydoclint would already report `DOC101` on it, and the only such callable in the tree is a private cloudpickle function. The two checks partition the problem rather than duplicating it. This check therefore scopes exactly to the `@PublicAPI` surface with **no baseline file**: it parses the base-branch and working-tree versions of the changed files and diffs their undocumented-parameter sets, so it needs **no Ray build or import environment**. ## What it does - Enumerates the `@PublicAPI` callables changed by the PR (module-level `@PublicAPI` functions and methods of `@PublicAPI` classes). A method that carries its own `@DeveloperAPI` or `@Deprecated` is out of scope even on a public class, since it isn't part of the rendered surface; an explicit `@PublicAPI` on the method wins over both. - For each, computes the signature parameters missing from the docstring `Args:`/`Arguments:` block (for `__init__`, also the class docstring, matching the default `autoclass_content="class"`), resolving docstring inheritance so an override with no own docstring isn't flagged when a base documents the param. - Fails only on parameters that are **newly** undocumented versus the base branch. Pre-existing gaps are grandfathered; the gate fires on new public callables, newly-added params, and doc entries removed from an existing param. **Scope and limits (intentional):** all signature params, not only annotated ones. Presence only -- a param counts as documented if its name appears in `Args:`; description prose is not inspected (empty-description detection would need `numpydoc.validate` and is out of scope). Static source analysis, so it does not confirm what the reference actually renders. ## Where it lives / rollout Sits in the `ci/ray_ci/doc` guard family next to `cmd_check_api_discrepancy.py`, and runs in the **lint group** (static, no docbuild). It starts as a `soft_fail: true` step -- **visible but non-blocking** -- so the measured false-positive rate above can be confirmed against live traffic before the check gates anything. Flipping it to a required check is a one-line removal of `soft_fail`. One caveat for reviewers on the warn phase: the pipeline passes `--blocking` and relies on `soft_fail` to absorb the exit code, so an environment failure (an unfetched base branch, a shallow clone deeper than `--depth=500`) surfaces the same way a finding does. Happy to drop `--blocking` from the pipeline command instead, so the script's own warn mode carries the phase and infrastructure errors stay distinguishable from real findings. Because the check is AST-based, it matches only *directly* applied `@PublicAPI` decorators, which lines up with the direct-annotation policy established in ray-project#65196 and ray-project#65208. ## Testing - `python -m pytest ci/ray_ci/doc/test_api_param_coverage.py` -- **28 passed**. Covers new API, new param, grandfathered gap, removed doc entry, non-public / private skips, `@PublicAPI(...)` call form, `__init__`-on-class-docstring, `Args:` block termination on dedent, docstring-inheritance recovery, and the `@DeveloperAPI`/`@Deprecated`-method scoping rule. - End-to-end on the pydoclint blind spot, which is the case this check exists for: adding an undocumented `strict` param to `RayError.from_bytes` (a `@PublicAPI` method with no docstring) fired on exactly `strict`, while pydoclint under the pre-commit config reported no violations on the same file. `--blocking` exits 1; documenting the param cleared it. - End-to-end on a case pydoclint *does* cover, to confirm agreement rather than contradiction: adding an undocumented `seed` param to `tune.loguniform` fired on exactly `seed` and correctly grandfathered the pre-existing gaps in the same file. pydoclint independently blocks this one at pre-commit. - `shellcheck ci/lint/lint.sh` clean; `.buildkite/lint.rayci.yml` parses. - Renaming `python/ray/exceptions.py` with no content change reported 22 violations across 11 callables before rename detection was added, and reports none after. A rename that also adds an undocumented param still fires on exactly that param. ### False-positive rate, measured against real history Replayed the check over the **200** most recent merged commits touching `python/ray/**/*.py`, each evaluated against its own parent. **Two** fired (1%): - ray-project#64963 flagged `Dataset.map_batches_internal` with 15 parameters. A genuine false positive: the method is `@DeveloperAPI`, but the check was pulling in every non-underscore method of an `@PublicAPI` class regardless of the method's own annotation. Fixed in this PR, with regression tests; the commit is clean on the replay now. - ray-project#64519 flagged `mode`, a newly added and undocumented parameter on `Catalog.resolve` (`@PublicAPI(stability="alpha")`, one-line docstring). A true positive, and squarely the blind-spot class this check exists for. It correctly grandfathered the pre-existing `table` and `reader` gaps on the same callable. Post-fix that is **one firing across 200 commits, and it is a real finding**. ### False-negative probe Coverage was probed independently of the replay: for every `@PublicAPI` callable on the surface, inject a new undocumented keyword parameter and assert the check reports it. **815 callables probed, 0 misses** -- 585 that are currently fully documented, plus the 230 that already carry gaps, which verifies that grandfathering an existing gap doesn't mask a newly added parameter. Broken out by shape: 176 module-level functions, 470 methods, 157 `__init__`, and 12 async methods, with no misses in any group. ## Alternatives considered - **Flip `--skip-checking-short-docstrings=False` repo-wide.** 8,285 callables, no `@PublicAPI` scoping. Rejected above. - **A second pydoclint invocation with that flag plus its own baseline.** pre-commit is already diff-scoped, so this is closer than it looks, but it requires committing a baseline on the order of 8,000 entries and still gates all of `python/ray` rather than the rendered public surface. ## Relationship to other open work No open PR builds a parameter-coverage gate. ray-project#64779 changes how type hints render into the Parameters list, which is a separate deliverable and does not gate new undocumented params. ## AI assistance This change was developed with AI assistance. The submitter has reviewed every changed line and run the tests above locally. --------- Signed-off-by: Douglas Strodtman <[email protected]>
## Description This PR makes the `lint: API param coverage` step a required check by removing `soft_fail: true`. The step was added in #64788 on 2026-08-11. A comment in the step said to remove `soft_fail` "once the false-positive rate is confirmed low." This PR measures that rate from the step's CI history and fixes the four failure patterns the history turned up. While the step only warns, undocumented parameters still land on master. #65633, #66602, and #66950 all merged with the check failing. ### Warn-phase metrics These numbers come from every `premerge` build from 2026-08-11 to 2026-10-29, pulled from the Buildkite API. | | Runs | PRs | |---|--:|--:| | Completed runs of the step | 3,453 | | | Passed | 3,398 | | | Failed | 55 | 23 | | Canceled, which isn't a check outcome | 211 | | Each failure falls into one of three groups: | Failure type | PRs | Runs | Detail | |---|--:|--:|---| | Correct finding | 15 | 42 | A new parameter on a `@PublicAPI` callable has no `Args:` entry. Two of these PRs, #65823 and #65839, were stacked on #65633 before it merged and report its findings again. | | False positive | 3 | 4 | #64399 flagged the `v` argument of a pydantic `@field_validator`. #66255 flagged the private kwarg `_direct_http`. #67258 flagged an option of the `ray start` Click command, which `help=` documents. | | Infrastructure | 5 | 9 | The step printed `could not determine merge-base` and no findings. The branches of #65437 and #65809 forked 520 and 598 master commits before their builds. The step's `git fetch --depth=500` makes the full CI clone shallow, so their merge-base wasn't in the fetched history. | That's 13 spurious failures out of 3,453 runs, about 0.4%, or 13 of 55 failures. Each one would block a PR once the step is required, so this PR fixes all four patterns before removing `soft_fail`. ### Changes - **`_`-prefixed parameters:** `api_param_coverage.py` skips parameters whose names start with `_`. That's Ray's convention for private kwargs, such as `ray.put(_owner=...)`, `tune.run(_remote=...)`, and `Deployment.options(_internal=...)`. On master, 31 public callables have such parameters. - **Pydantic validators and Click commands:** The script skips callables decorated with `field_validator`, `model_validator`, `validator`, `root_validator`, `command`, or `group`. On master, this removes 59 callables from scope. All of them are Click commands, such as `ray start` and `ray job submit`, or pydantic validators on Serve config models. None of them is a Python API whose parameters a docstring documents. - **Property setters:** The script also skips callables decorated with `@<name>.setter`. A setter's `value` is documented on the property's getter, which is the docstring Sphinx renders, not in an `Args:` section of its own. - **Shallow-clone merge-base:** When `git merge-base` fails after the depth-500 fetch, `ci/lint/lint.sh` runs `git fetch --unshallow` and retries. A branch within 500 commits of the base never reaches that path. The Python check still fails closed if the base can't be resolved after that. - **Step definition:** `.buildkite/lint.rayci.yml` drops `soft_fail: true` and the warn-phase comment. The `--blocking` help text in `cmd_check_api_param_coverage.py` no longer describes a warn phase. ## Related issues Follow-up to #64788. ## Additional information ### Testing - `pytest ci/ray_ci/doc/test_api_param_coverage.py`: 40 passed. That's the 28 existing tests plus 12 new cases covering `_` params, each validator spelling, Click command forms, and property setters. The test comments name the real PR that motivated each one. - **Replay against real PRs:** I ran the master and patched versions of the check against the exact commit and base of every failing run in each of the 18 PRs with findings. Master reproduces all 18 failures. The patched check passes #64399, #66255, and #67258, and reports the same findings as master on the other 15. - **Merge-base fix:** In a local repo with 600 commits on `master` and a branch forked at commit 50, `git fetch --depth=500` followed by `git merge-base` fails, which reproduces the CI failure. With the new `lint.sh` block, it resolves the correct fork commit. A branch forked 10 commits back resolves without the fallback. - `pre-commit run` on the changed files passes, including ruff, black, shellcheck, and docstyle. ### Duplicate check `gh pr list --state open --search "param coverage"` and `--search "api_param_coverage"` return no open PR that touches this check. The script hasn't changed since #65391 on 2026-08-14. ### AI assistance I used Claude Code to pull and classify the Buildkite history, draft the changes, and run the replay. I reviewed every changed line and the classification of every failing PR. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Signed-off-by: Douglas Strodtman <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>

Why
Ray's public API reference accretes undocumented parameters over time: a new
@PublicAPIcallable, or a new parameter on an existing one, can ship without adocstring
Args:entry, and nothing fails. This adds a static, diff-scopedcheck that blocks new debt on the
@PublicAPIsurface while grandfathering thestanding backlog.
What pydoclint already covers, and the gap it leaves
pydoclint (pinned at
0.8.3in.pre-commit-config.yaml) already runs itsargument-completeness checks
DOC101/DOC103repo-wide acrosspython/ray,against an empty
ci/lint/pydoclint-baseline.txt. So that class of violationis already fully enforced with zero grandfathering, and the tree is essentially
clean: a repo-wide run under the exact pre-commit config flags exactly one
callable,
_find_imported_submodulesin vendoredpython/ray/cloudpickle/cloudpickle.py, which is private. The per-modulecleanups (#63500, #63509,
#63518, #63541, #63571, #63632, #63633, #63634, #63639) are what got it there.
The gap is
--skip-checking-short-docstrings, which defaults toTrueand is notoverridden. It makes pydoclint skip any callable whose docstring is absent or is a
bare one-line summary with no sections. Those callables can gain parameters
indefinitely without any check firing.
Flipping that one flag is not a viable fix. Repo-wide with
--skip-checking-short-docstrings=False,DOC101/DOC103fire on 8,285callables across
python/ray(public and private alike; 16,570 violations, sinceeach callable trips both codes) -- precisely the "baseline the size of the
codebase" that the config comment on master already says the team doesn't want,
and it has no
@PublicAPIawareness to narrow it.Measured on the
@PublicAPIsurface, the same unit for comparison: of 815 publiccallables that take parameters, 230 have at least one undocumented parameter,
totalling 505 undocumented parameters. So the public surface is roughly 3% of
what a repo-wide flag flip would drag in.
All 230 of them sit in pydoclint's blind spot -- zero overlap with what
DOC101/DOC103catch today. That falls out of the numbers above without relyingon any modelling of pydoclint's "short docstring" rule: if any
@PublicAPIcallable had a section-bearing docstring missing a param, pydoclint would already
report
DOC101on it, and the only such callable in the tree is a privatecloudpickle function. The two checks partition the problem rather than duplicating
it.
This check therefore scopes exactly to the
@PublicAPIsurface with no baselinefile: it parses the base-branch and working-tree versions of the changed files
and diffs their undocumented-parameter sets, so it needs no Ray build or import
environment.
What it does
@PublicAPIcallables changed by the PR (module-level@PublicAPIfunctions and methods of@PublicAPIclasses). A method thatcarries its own
@DeveloperAPIor@Deprecatedis out of scope even on apublic class, since it isn't part of the rendered surface; an explicit
@PublicAPIon the method wins over both.Args:/Arguments:block (for__init__, also the class docstring, matchingthe default
autoclass_content="class"), resolving docstring inheritance so anoverride with no own docstring isn't flagged when a base documents the param.
branch. Pre-existing gaps are grandfathered; the gate fires on new public
callables, newly-added params, and doc entries removed from an existing param.
Scope and limits (intentional): all signature params, not only annotated
ones. Presence only -- a param counts as documented if its name appears in
Args:; description prose is not inspected (empty-description detection wouldneed
numpydoc.validateand is out of scope). Static source analysis, so it doesnot confirm what the reference actually renders.
Where it lives / rollout
Sits in the
ci/ray_ci/docguard family next tocmd_check_api_discrepancy.py,and runs in the lint group (static, no docbuild). It starts as a
soft_fail: truestep -- visible but non-blocking -- so the measuredfalse-positive rate above can be confirmed against live traffic before the check
gates anything. Flipping it to a required check is a one-line removal of
soft_fail.One caveat for reviewers on the warn phase: the pipeline passes
--blockingandrelies on
soft_failto absorb the exit code, so an environment failure (anunfetched base branch, a shallow clone deeper than
--depth=500) surfaces thesame way a finding does. Happy to drop
--blockingfrom the pipeline commandinstead, so the script's own warn mode carries the phase and infrastructure
errors stay distinguishable from real findings.
Because the check is AST-based, it matches only directly applied
@PublicAPIdecorators, which lines up with the direct-annotation policy established in
#65196 and #65208.
Testing
python -m pytest ci/ray_ci/doc/test_api_param_coverage.py-- 28 passed.Covers new API, new param, grandfathered gap, removed doc entry, non-public /
private skips,
@PublicAPI(...)call form,__init__-on-class-docstring,Args:block termination on dedent, docstring-inheritance recovery, and the@DeveloperAPI/@Deprecated-method scoping rule.for: adding an undocumented
strictparam toRayError.from_bytes(a@PublicAPImethod with no docstring) fired on exactlystrict, whilepydoclint under the pre-commit config reported no violations on the same file.
--blockingexits 1; documenting the param cleared it.contradiction: adding an undocumented
seedparam totune.loguniformfiredon exactly
seedand correctly grandfathered the pre-existing gaps in the samefile. pydoclint independently blocks this one at pre-commit.
shellcheck ci/lint/lint.shclean;.buildkite/lint.rayci.ymlparses.python/ray/exceptions.pywith no content change reported 22violations across 11 callables before rename detection was added, and reports
none after. A rename that also adds an undocumented param still fires on
exactly that param.
False-positive rate, measured against real history
Replayed the check over the 200 most recent merged commits touching
python/ray/**/*.py, each evaluated against its own parent. Two fired (1%):ray_remote_args_fn#64963 flaggedDataset.map_batches_internalwith 15 parameters. A genuinefalse positive: the method is
@DeveloperAPI, but the check was pulling inevery non-underscore method of an
@PublicAPIclass regardless of the method'sown annotation. Fixed in this PR, with regression tests; the commit is clean on
the replay now.
mode, a newly added and undocumented parameter onCatalog.resolve(@PublicAPI(stability="alpha"), one-line docstring). A truepositive, and squarely the blind-spot class this check exists for. It correctly
grandfathered the pre-existing
tableandreadergaps on the same callable.Post-fix that is one firing across 200 commits, and it is a real finding.
False-negative probe
Coverage was probed independently of the replay: for every
@PublicAPIcallableon the surface, inject a new undocumented keyword parameter and assert the check
reports it. 815 callables probed, 0 misses -- 585 that are currently fully
documented, plus the 230 that already carry gaps, which verifies that
grandfathering an existing gap doesn't mask a newly added parameter. Broken out
by shape: 176 module-level functions, 470 methods, 157
__init__, and 12 asyncmethods, with no misses in any group.
Alternatives considered
--skip-checking-short-docstrings=Falserepo-wide. 8,285 callables, no@PublicAPIscoping. Rejected above.pre-commit is already diff-scoped, so this is closer than it looks, but it
requires committing a baseline on the order of 8,000 entries and still gates all
of
python/rayrather than the rendered public surface.Relationship to other open work
No open PR builds a parameter-coverage gate. #64779 changes how type hints render
into the Parameters list, which is a separate deliverable and does not gate new
undocumented params.
AI assistance
This change was developed with AI assistance. The submitter has reviewed every
changed line and run the tests above locally.