Repository navigation
[Docs] Enable Python faulthandler on the Read the Docs build - #66452
Conversation
Since 2026-09-23 some Read the Docs builds die with a bare "Segmentation fault (core dumped)" from make about 7 seconds into sphinx-build. The log names no module or frame. Set PYTHONFAULTHANDLER=1 on the html build step so the next crash dumps a Python stack. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Signed-off-by: Douglas Strodtman <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request updates the Read the Docs configuration to prepend PYTHONFAULTHANDLER=1 to the Sphinx build command, enabling thread stack dumps on fatal signals to help debug intermittent segmentation faults. The reviewer suggested also setting PYTHONUNBUFFERED=1 to ensure that logs are flushed immediately and not lost in the event of a crash.
| html: | ||
| - | | ||
| make -C doc html HTMLDIR="$READTHEDOCS_OUTPUT/html" SPHINX_JOBS=2 | ||
| PYTHONFAULTHANDLER=1 make -C doc html HTMLDIR="$READTHEDOCS_OUTPUT/html" SPHINX_JOBS=2 |
There was a problem hiding this comment.
In addition to PYTHONFAULTHANDLER=1, it is highly recommended to also set PYTHONUNBUFFERED=1 for CI/CD builds. When a process crashes (such as due to a segmentation fault or an OOM kill), any standard output or error that is still buffered in memory may be lost. Setting PYTHONUNBUFFERED=1 ensures that all output is flushed immediately, providing complete and accurate logs up to the exact moment of the crash.
PYTHONUNBUFFERED=1 PYTHONFAULTHANDLER=1 make -C doc html HTMLDIR="$READTHEDOCS_OUTPUT/html" SPHINX_JOBS=2There was a problem hiding this comment.
Thanks. I'm leaving this one out. The traceback this PR is after doesn't need it, because faulthandler writes straight to file descriptor 2 and skips Python's I/O buffers. Sphinx's own output doesn't need it either: its log handlers subclass logging.StreamHandler, which flushes after every record, so the [autosummary] line these crashes end on is where the build really was. Unbuffered stdout would only add bare print() output from imported modules, and the fault-handler traceback will name the crash site anyway.
## Description Since #66357, `import ray.data` loads `pyarrow.dataset` and its native extensions. The legacy `parquet_datasource.py` now imports `_compute_row_hashes` from the V2 readers package at module level, and the V2 reader modules import `pyarrow.dataset` at load time. Before #66357, the dependency ran the other way and `ray.data` never reached `pyarrow.dataset` on import. This PR moves the `_compute_row_hashes` import into `_read_batches_from`, its only caller. That matches the file's existing function-level `pyarrow.dataset` imports. The import points at `readers/synthesized_columns.py`, where the helper has lived since #66390, rather than at the `file_reader` re-export. Importing from `synthesized_columns` at module level isn't enough on its own, because `read_units.py` also imports `pyarrow.dataset` at the top level. It also adds `test_import_does_not_load_pyarrow_dataset` to `python/ray/data/tests/test_import.py`. The test asserts that a fresh driver's `import ray.data` loads no `pyarrow._dataset*` modules. ### Why this matters The Ray docs Read the Docs build has been segfaulting intermittently, in about 31% of builds since 2026-09-23. The crash is in native extension init while autosummary imports RLlib → Tune → AIR → `ray.data`. A `PYTHONFAULTHANDLER=1` traceback (#66452) puts the crash inside `from pyarrow._dataset_parquet import ...`, which is reached from `parquet_datasource.py` → `file_reader.py` → `import pyarrow.dataset`. The loaded-extensions list in that traceback ends with exactly the modules this import adds. This change takes the crashing import off the `import ray.data` path. It doesn't fix the underlying native crash. I couldn't reproduce it with a bare `import pyarrow.dataset` loop in `linux/amd64` Docker: 0 of 300 runs failed, with numpy 2.2.6 and pyarrow 23.0.1 from the doc lock. So it seems to depend on process state or on the build host. The docs build and `requirements_compiled.txt` both pin pyarrow 23.0.1, and neither pin changed in the failure window. ## Related issues Related to #66357 and #66452. ## Additional information ### Not a duplicate Searched open PRs for `_compute_row_hashes`, the DSv2 reorg series, and lazy-import and segfault keywords. #66450 (DSv2 Reorg [4/6]) and #66201 are the nearest open PRs, and neither touches this import or `test_import.py`. ### Tests run These were run locally on macOS arm64, Python 3.11, pyarrow 23.0.1, numpy 2.2.6. They used the Ray nightly wheel with `ray/data` and `ray/tests` linked from this branch. * `pytest python/ray/data/tests/test_import.py`: 2 passed. With the `parquet_datasource.py` change reverted, the new test fails and lists `pyarrow._dataset`, `_dataset_orc`, `_dataset_parquet`, and `_dataset_parquet_encryption`. * `pytest python/ray/data/tests/datasource/test_parquet.py -k row_hash`: 18 passed. * `pytest python/ray/data/tests/datasource/test_parquet.py` (full module): 242 passed, 13 skipped, 13 failed, 34 errors. Rerunning the 47 failing tests with master's `parquet_datasource.py` gave an identical failing set, so none come from this change. They come from the local environment: * The S3 fixtures error in `fsspec`'s HTTP backend, because their test dependencies aren't installed. * Several local-path tests assert `string` columns and get `large_string`, which is pandas/pyarrow version skew against CI's pins. CI is the authoritative run for this module. * `pre-commit run --files python/ray/data/_internal/datasource/parquet_datasource.py`: all hooks passed, including ruff, black, pydoclint, and the import-order check. ### AI assistance AI assistance (Claude Code) was used to investigate the import graph, write the change and test, and draft this description. This PR stays in draft until the submitter has reviewed every changed line. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Signed-off-by: Douglas Strodtman <[email protected]> Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
…ject#66452) ## Why are these changes needed? Since about 2026-09-23 04:45 UTC, Read the Docs builds on `anyscale-ray` have been intermittently dying with a bare segfault in `sphinx-build`: ``` [autosummary] generating autosummary for: 404.md, ... make: *** [Makefile:100: html] Segmentation fault (core dumped) ``` What I found in the build history: - None of the 132 finished builds from 2026-09-18 up to the onset segfaulted. There have been 23 since, on both `master` and PR previews across at least 10 PRs. In one 13-hour window, 10 of 32 finished builds crashed. - Every crash is at the same point, about 6 to 7 seconds into the `make html` step, right after autosummary starts. This isn't the memory-limit failure that the `SPHINX_JOBS=2` comment describes, which surfaces as an `EOFError` from a worker much later in the build. - It isn't deterministic per commit. `master` at 8a94f8b segfaulted in builds 4473269 and 4474033, then passed in 4474041. A line-by-line diff of the failing and passing logs shows the same commands, the same Python (3.11.15), and the same installed package versions. - No doc-build input changed in the onset window. The only commit that landed on `master` in it was a core C++ change (ray-project#66383), which the docs build doesn't compile. That points to a change in the build environment rather than in this repo, but the log gives nothing to hand to Read the Docs support or to act on. This PR sets `PYTHONFAULTHANDLER=1` on the html build step so the next crash dumps the Python stack of every thread to stderr. That should name the module or C extension that crashed. The handler only does anything when a fatal signal arrives, so passing builds are unaffected. Once the cause is found and fixed, this can stay as cheap insurance or be reverted. ## Related issue number None. I searched open and closed PRs for `faulthandler`, `readthedocs segfault`, and `Segmentation fault`, and none of them cover the docs build. ray-project#66364 fixes a segfault on `import ray` when a `RAY_*` env var is malformed, which is a different path in core's static initialization. ## Testing - Ran a deliberately segfaulting Python child through a `make` recipe, the same way the build invokes `sphinx-build`. With `PYTHONFAULTHANDLER=1`, make's output includes `Fatal Python error: Segmentation fault` and the Python traceback. Without it, the output is only make's `Segmentation fault` line. - `python3 -c "import yaml; yaml.safe_load(open('.readthedocs.yaml'))"` parses, and the html build command reads back as expected. - `pre-commit run --files .readthedocs.yaml` passes. - The Read the Docs preview for this PR runs the modified step, because the preview guard builds whenever `.readthedocs.yaml` changes. ## AI assistance I used Claude Code to survey the Read the Docs build history through the RtD API, diff the build logs, and draft this change. I reviewed the diff and the evidence above. ## Checks - [x] I've signed off every commit (by using the -s flag, i.e., `git commit -s`) in this PR. - [x] I've run pre-commit jobs to lint the changes in this PR. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Signed-off-by: Douglas Strodtman <[email protected]> Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
…6463) ## Description Since ray-project#66357, `import ray.data` loads `pyarrow.dataset` and its native extensions. The legacy `parquet_datasource.py` now imports `_compute_row_hashes` from the V2 readers package at module level, and the V2 reader modules import `pyarrow.dataset` at load time. Before ray-project#66357, the dependency ran the other way and `ray.data` never reached `pyarrow.dataset` on import. This PR moves the `_compute_row_hashes` import into `_read_batches_from`, its only caller. That matches the file's existing function-level `pyarrow.dataset` imports. The import points at `readers/synthesized_columns.py`, where the helper has lived since ray-project#66390, rather than at the `file_reader` re-export. Importing from `synthesized_columns` at module level isn't enough on its own, because `read_units.py` also imports `pyarrow.dataset` at the top level. It also adds `test_import_does_not_load_pyarrow_dataset` to `python/ray/data/tests/test_import.py`. The test asserts that a fresh driver's `import ray.data` loads no `pyarrow._dataset*` modules. ### Why this matters The Ray docs Read the Docs build has been segfaulting intermittently, in about 31% of builds since 2026-09-23. The crash is in native extension init while autosummary imports RLlib → Tune → AIR → `ray.data`. A `PYTHONFAULTHANDLER=1` traceback (ray-project#66452) puts the crash inside `from pyarrow._dataset_parquet import ...`, which is reached from `parquet_datasource.py` → `file_reader.py` → `import pyarrow.dataset`. The loaded-extensions list in that traceback ends with exactly the modules this import adds. This change takes the crashing import off the `import ray.data` path. It doesn't fix the underlying native crash. I couldn't reproduce it with a bare `import pyarrow.dataset` loop in `linux/amd64` Docker: 0 of 300 runs failed, with numpy 2.2.6 and pyarrow 23.0.1 from the doc lock. So it seems to depend on process state or on the build host. The docs build and `requirements_compiled.txt` both pin pyarrow 23.0.1, and neither pin changed in the failure window. ## Related issues Related to ray-project#66357 and ray-project#66452. ## Additional information ### Not a duplicate Searched open PRs for `_compute_row_hashes`, the DSv2 reorg series, and lazy-import and segfault keywords. ray-project#66450 (DSv2 Reorg [4/6]) and ray-project#66201 are the nearest open PRs, and neither touches this import or `test_import.py`. ### Tests run These were run locally on macOS arm64, Python 3.11, pyarrow 23.0.1, numpy 2.2.6. They used the Ray nightly wheel with `ray/data` and `ray/tests` linked from this branch. * `pytest python/ray/data/tests/test_import.py`: 2 passed. With the `parquet_datasource.py` change reverted, the new test fails and lists `pyarrow._dataset`, `_dataset_orc`, `_dataset_parquet`, and `_dataset_parquet_encryption`. * `pytest python/ray/data/tests/datasource/test_parquet.py -k row_hash`: 18 passed. * `pytest python/ray/data/tests/datasource/test_parquet.py` (full module): 242 passed, 13 skipped, 13 failed, 34 errors. Rerunning the 47 failing tests with master's `parquet_datasource.py` gave an identical failing set, so none come from this change. They come from the local environment: * The S3 fixtures error in `fsspec`'s HTTP backend, because their test dependencies aren't installed. * Several local-path tests assert `string` columns and get `large_string`, which is pandas/pyarrow version skew against CI's pins. CI is the authoritative run for this module. * `pre-commit run --files python/ray/data/_internal/datasource/parquet_datasource.py`: all hooks passed, including ruff, black, pydoclint, and the import-order check. ### AI assistance AI assistance (Claude Code) was used to investigate the import graph, write the change and test, and draft this description. This PR stays in draft until the submitter has reviewed every changed line. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Signed-off-by: Douglas Strodtman <[email protected]> Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
Why are these changes needed?
Since about 2026-09-23 04:45 UTC, Read the Docs builds on
anyscale-rayhave been intermittently dying with a bare segfault insphinx-build:What I found in the build history:
masterand PR previews across at least 10 PRs. In one 13-hour window, 10 of 32 finished builds crashed.make htmlstep, right after autosummary starts. This isn't the memory-limit failure that theSPHINX_JOBS=2comment describes, which surfaces as anEOFErrorfrom a worker much later in the build.masterat 8a94f8b segfaulted in builds 4473269 and 4474033, then passed in 4474041. A line-by-line diff of the failing and passing logs shows the same commands, the same Python (3.11.15), and the same installed package versions.masterin it was a core C++ change ([core] Ensure we free objects whose location report arrives after the ref got dropped #66383), which the docs build doesn't compile.That points to a change in the build environment rather than in this repo, but the log gives nothing to hand to Read the Docs support or to act on. This PR sets
PYTHONFAULTHANDLER=1on the html build step so the next crash dumps the Python stack of every thread to stderr. That should name the module or C extension that crashed. The handler only does anything when a fatal signal arrives, so passing builds are unaffected.Once the cause is found and fixed, this can stay as cheap insurance or be reverted.
Related issue number
None. I searched open and closed PRs for
faulthandler,readthedocs segfault, andSegmentation fault, and none of them cover the docs build. #66364 fixes a segfault onimport raywhen aRAY_*env var is malformed, which is a different path in core's static initialization.Testing
makerecipe, the same way the build invokessphinx-build. WithPYTHONFAULTHANDLER=1, make's output includesFatal Python error: Segmentation faultand the Python traceback. Without it, the output is only make'sSegmentation faultline.python3 -c "import yaml; yaml.safe_load(open('.readthedocs.yaml'))"parses, and the html build command reads back as expected.pre-commit run --files .readthedocs.yamlpasses..readthedocs.yamlchanges.AI assistance
I used Claude Code to survey the Read the Docs build history through the RtD API, diff the build logs, and draft this change. I reviewed the diff and the evidence above.
Checks
git commit -s) in this PR.🤖 Generated with Claude Code