Repository navigation
[ci][doc] Check links to files on master offline; fix broken doc links - #66626
Conversation
Add ci/lint/check_ray_repo_links.py, which resolves every
github.com/ray-project/ray/{blob,tree,raw}/master/<path> and
raw.githubusercontent.com/ray-project/ray/master/<path> link in the tree
against `git ls-files`. It needs no network, so it can block: a link is
correct exactly when its path exists in the tree being committed. It runs
in the prose lint matrix, because renaming a doc file breaks links to it
elsewhere, and as a local pre-commit hook.
Fix the 10 links it reports on master, and the 12 external doc links that
the postmerge linkcheck confirms broken and that resolve to a verified
replacement.
Make linkcheck_report.py write its confirmed list to a
linkcheck-report.json build artifact instead of posting to Slack. The
webhook it read was never provisioned, and an external job now reads the
result through the Buildkite API.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Douglas Strodtman <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request introduces a new lint check (check_ray_repo_links.py) to verify that GitHub links pointing to Ray's master branch resolve to existing files in the repository, integrating it into pre-commit and Buildkite workflows. It also updates the Sphinx linkcheck reporting tool to output a build artifact rather than posting directly to Slack, and fixes several broken links across the documentation. The review feedback highlights a critical bug in parsing NUL-terminated git grep output, suggests improvements to handle templated URLs containing curly braces, and recommends falling back to the original Sphinx error code in the linkcheck report if a re-check code is missing.
| for record in result.stdout.decode("utf-8", "replace").splitlines(): | ||
| # With -z, the separators after the file name and line number are NULs. | ||
| path, lineno, text = record.split("\0", 2) | ||
| lines.append((path, int(lineno), text)) |
There was a problem hiding this comment.
Using splitlines() on the output of git grep -z is incorrect because -z causes git grep to use NUL bytes (\0) as the record terminator instead of newlines. As a result, splitlines() will not split the matches correctly, and record.split("\0", 2) will swallow all subsequent matches into the text field of the first match. This leads to incorrect filename and line number reporting for all subsequent broken links.
Instead, the entire output should be split by \0 and parsed in chunks of 3 elements (file, line number, and content).
| for record in result.stdout.decode("utf-8", "replace").splitlines(): | |
| # With -z, the separators after the file name and line number are NULs. | |
| path, lineno, text = record.split("\0", 2) | |
| lines.append((path, int(lineno), text)) | |
| out = result.stdout.decode("utf-8", "replace") | |
| if out: | |
| parts = out.split("\0") | |
| if parts and not parts[-1]: | |
| parts.pop() | |
| for i in range(0, len(parts), 3): | |
| if i + 2 < len(parts): | |
| lines.append((parts[i], int(parts[i+1]), parts[i+2])) |
There was a problem hiding this comment.
Thanks for flagging this line. The framing diagnosis doesn't hold, though: git grep -z only swaps the separators after the file name and line number for NULs, and each record still ends in a newline. Across this repo the output is 553 records with exactly 1,106 NULs, two per record, and the check reports the correct file:line for every broken link it finds. The line did have a related bug: splitlines() also breaks on form feeds and Unicode line separators inside a matched line, which would crash the unpacking. Fixed in 93af2f1 by splitting on "\n" only. I tested it against a line containing \x0c.
| r"/(?:refs/heads/)?master/" | ||
| # A path runs until whitespace or a character that ends a URL in Markdown, | ||
| # rST, HTML, Python strings, or JSON-encoded notebook text. | ||
| r"([^\s\"'`()<>\[\]{}|\\^]+)" |
There was a problem hiding this comment.
There was a problem hiding this comment.
Applied in 93af2f1, together with the TEMPLATE_CHARS change below. No current link has a brace, but a path like data_{suffix}.py would have been cut off at the brace and reported as missing.
|
|
||
| # Characters that mark a templated path, such as an f-string or a placeholder, | ||
| # rather than a literal one. | ||
| TEMPLATE_CHARS = set("$*") |
| report = { | ||
| "confirmed": [ | ||
| { | ||
| "code": record.get("recheck_code", "ERR"), |
There was a problem hiding this comment.
If recheck_code is not present in the record, defaulting to "ERR" discards the original Sphinx error code (such as 404 or 500). It is safer to fall back to the original code field from Sphinx, matching the previous behavior of the script.
| "code": record.get("recheck_code", "ERR"), | |
| "code": record.get("recheck_code", record.get("code", "ERR")), |
There was a problem hiding this comment.
Not changing this one. confirm() sets recheck_code on every record before it adds that record to confirmed, so the fallback can't be reached for anything passed to write_report.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 047b2a6. Configure here.
- linkcheck_report.py: when Sphinx wrote no output.json, write no report and don't print the all-clear line, so a consumer can tell a run that produced nothing apart from a clean one. - check_ray_repo_links.py: split git grep -z output on "\n" only. splitlines() also breaks on form feeds and Unicode line separators inside a matched line, which would crash the record unpacking. - check_ray_repo_links.py: capture braces in the path and treat them as template markers, so a templated path is skipped whole instead of being cut off at the brace. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Douglas Strodtman <[email protected]>
…ython-ray Resolves conflicts with ray-project#66626 (offline link check + doc link fixes) in the appo/dqn/ppo READMEs, examples/ray_tune/custom_experiment.py and doc/source/rllib/rl-modules.md. "Fix links" (9127161) already applied the same link fixes on top of the moved paths, so this branch's side is kept. ci/lint/check_ray_repo_links.py passes on the merged tree. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Signed-off-by: elliot-barn <[email protected]>
ray-project#66626) ## Description Docs, READMEs and docstrings often link to a file in this repo by its GitHub URL, such as `https://github.com/ray-project/ray/blob/master/<path>`. GitHub doesn't redirect those URLs when a file moves or is deleted. It doesn't resolve them through symlinked directories either, so `blob/master/python/ray/rllib/...` returns 404 today. Ten such links are broken on master. Six are in RLlib READMEs and example docstrings that the Sphinx linkcheck never sees. A network check can't catch this on a pull request, because a PR's new links point at paths that don't exist on master until the PR merges. But a link like this is correct exactly when its path exists in the tree being committed, so it can be checked offline and the check can block. This PR makes three changes. **1. `ci/lint/check_ray_repo_links.py`** - Finds every `github.com/ray-project/ray/{blob,tree,raw}/master/<path>` and `raw.githubusercontent.com/ray-project/ray/[refs/heads/]master/<path>` link in tracked text files. - Checks each path against `git ls-files` and fails on any path that doesn't exist. - Ignores pinned SHAs, tags, other branches, and `#L42` line anchors. - Runs in about 0.8s with no network. It runs in the `lint-small-prose` matrix (`always`), not in `pre_commit`. A prose-only change can fail it: renaming or deleting a doc file breaks links to it elsewhere, and `pre_commit` is filtered out of prose-only PRs. It also scans the whole tree rather than only changed files, for the same reason. It's also registered as a local pre-commit hook. **2. Link fixes.** These cover everything the new check reports on master, plus the Ray-owned links that the postmerge `doc: linkcheck` step confirms broken, wherever a replacement checked out. - RLlib READMEs, `rl-modules.md` and the `custom_experiment.py` docstring now point at current paths. The DDPPO and APEX entries for removed algorithms are dropped. - `tune-distributed.rst` now points at `python/ray/tune/examples/tune-default.yaml`. - `src/ray/.cursor/BUGBOT.md` now points at `rpc-fault-tolerance.md`, the MyST version of the page. - Starlette and Uvicorn moved their docs to `starlette.dev` and `uvicorn.dev`, which are the `homepage` values of their GitHub repos. The old hosts no longer answer. - The Arch Wiki, Vale, and Databricks statement execution API links point at those sites' current URLs. **3. `linkcheck_report.py` writes a `linkcheck-report.json` artifact instead of posting to Slack.** - The step's container already mounts the agent's artifact directory at `/artifact-mount`. - The `DOCS_LINKCHECK_SLACK_WEBHOOK` env var it read was never provisioned, so today every run ends with "not set; skipping Slack alert" and nobody sees the result. - A scheduled job maintained by the docs team now reads the result through the Buildkite API and posts the digest, so no Slack credential has to enter this repo's CI secrets. That job also parses the printed lines when the artifact is missing, so the printed format is unchanged. ## Related issues Related to ray-project#66096, which moves `rllib/` under `python/ray/` and rewrites the RLlib links for the new paths. - This PR's RLlib edits make the same choices as that PR, but use the current master paths. Whichever merges second has a small conflict on those lines. - Once this lands, the new check covers the move itself: any `/master/rllib/...` link ray-project#66096 misses fails lint on that PR, not after merge. Not a duplicate: open PR searches for "link check", "broken links", "linkcheck", and "dead links" turn up nothing in this area. ## Additional information **Left out on purpose:** - **The torch `Stream` link** that linkcheck reports comes from intersphinx. `conf.py` pins the torch inventory to 2.9 but keeps `base_url` at `docs/stable/`, and `stable` has since renamed that page. The fix is a deliberate `conf.py` decision, so it isn't bundled here. - **19 of the confirmed-broken links** live in the externally fetched `_collections/` template content, which is fixed in the templates repo, not here. **Testing:** - `python ci/lint/check_ray_repo_links.py` passes on this branch and reports the 10 links above on master. - To confirm it catches a move, I removed `python/ray/tune/examples/tune-default.yaml` from a scratch index (`GIT_INDEX_FILE`). The check then reported the `tune-distributed.rst` link and exited 1. - `bash ci/lint/lint.sh ray_repo_links` passes. - `pre-commit run --files <changed files>` passes, including the new hook, ruff, black, pydoclint and docstyle. - I ran `linkcheck_report.main()` against a synthetic `output.json` with `LINKCHECK_RECHECK_COOLDOWN=0`. One dead and one live URL produced a single confirmed entry in the artifact. An empty input produced an empty report. - Every URL this PR adds returns HTTP 200, and every anchor (`#streamingresponse`, `#timeouts`, `#using-pure-asgi-middleware`, `#Installing_and_upgrading_packages`) exists on its target page. **Review note:** `.buildkite/lint.rayci.yml` and `ci/lint/lint.sh` are shared CI surfaces, so this wants a `ray-ci` review. The lint steps don't carry `oss`, so the check also runs in downstream forks that reuse this `.buildkite/` tree, against the fork's own tree. AI assistance (Claude Code) was used to write this change. I reviewed every changed line and ran the commands above. --------- Signed-off-by: Douglas Strodtman <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>

Description
Docs, READMEs and docstrings often link to a file in this repo by its GitHub URL, such as
https://github.com/ray-project/ray/blob/master/<path>. GitHub doesn't redirect those URLs when a file moves or is deleted. It doesn't resolve them through symlinked directories either, soblob/master/python/ray/rllib/...returns 404 today. Ten such links are broken on master. Six are in RLlib READMEs and example docstrings that the Sphinx linkcheck never sees.A network check can't catch this on a pull request, because a PR's new links point at paths that don't exist on master until the PR merges. But a link like this is correct exactly when its path exists in the tree being committed, so it can be checked offline and the check can block.
This PR makes three changes.
1.
ci/lint/check_ray_repo_links.pygithub.com/ray-project/ray/{blob,tree,raw}/master/<path>andraw.githubusercontent.com/ray-project/ray/[refs/heads/]master/<path>link in tracked text files.git ls-filesand fails on any path that doesn't exist.#L42line anchors.It runs in the
lint-small-prosematrix (always), not inpre_commit. A prose-only change can fail it: renaming or deleting a doc file breaks links to it elsewhere, andpre_commitis filtered out of prose-only PRs. It also scans the whole tree rather than only changed files, for the same reason. It's also registered as a local pre-commit hook.2. Link fixes. These cover everything the new check reports on master, plus the Ray-owned links that the postmerge
doc: linkcheckstep confirms broken, wherever a replacement checked out.rl-modules.mdand thecustom_experiment.pydocstring now point at current paths. The DDPPO and APEX entries for removed algorithms are dropped.tune-distributed.rstnow points atpython/ray/tune/examples/tune-default.yaml.src/ray/.cursor/BUGBOT.mdnow points atrpc-fault-tolerance.md, the MyST version of the page.starlette.devanduvicorn.dev, which are thehomepagevalues of their GitHub repos. The old hosts no longer answer.3.
linkcheck_report.pywrites alinkcheck-report.jsonartifact instead of posting to Slack./artifact-mount.DOCS_LINKCHECK_SLACK_WEBHOOKenv var it read was never provisioned, so today every run ends with "not set; skipping Slack alert" and nobody sees the result.Related issues
Related to #66096, which moves
rllib/underpython/ray/and rewrites the RLlib links for the new paths./master/rllib/...link Move/rllib/into/python/ray/#66096 misses fails lint on that PR, not after merge.Not a duplicate: open PR searches for "link check", "broken links", "linkcheck", and "dead links" turn up nothing in this area.
Additional information
Left out on purpose:
Streamlink that linkcheck reports comes from intersphinx.conf.pypins the torch inventory to 2.9 but keepsbase_urlatdocs/stable/, andstablehas since renamed that page. The fix is a deliberateconf.pydecision, so it isn't bundled here._collections/template content, which is fixed in the templates repo, not here.Testing:
python ci/lint/check_ray_repo_links.pypasses on this branch and reports the 10 links above on master.python/ray/tune/examples/tune-default.yamlfrom a scratch index (GIT_INDEX_FILE). The check then reported thetune-distributed.rstlink and exited 1.bash ci/lint/lint.sh ray_repo_linkspasses.pre-commit run --files <changed files>passes, including the new hook, ruff, black, pydoclint and docstyle.linkcheck_report.main()against a syntheticoutput.jsonwithLINKCHECK_RECHECK_COOLDOWN=0. One dead and one live URL produced a single confirmed entry in the artifact. An empty input produced an empty report.#streamingresponse,#timeouts,#using-pure-asgi-middleware,#Installing_and_upgrading_packages) exists on its target page.Review note:
.buildkite/lint.rayci.ymlandci/lint/lint.share shared CI surfaces, so this wants aray-cireview. The lint steps don't carryoss, so the check also runs in downstream forks that reuse this.buildkite/tree, against the fork's own tree.AI assistance (Claude Code) was used to write this change. I reviewed every changed line and ran the commands above.