Skip to content

[ci][doc] Build the docs with 2 Sphinx workers on Read the Docs - #65643

Merged
dstrodtman merged 1 commit into
masterfrom
djs-260821-rtd-sphinx-jobs
Aug 21, 2026
Merged

dstrodtman merged 1 commit into
masterfrom
djs-260821-rtd-sphinx-jobs

Conversation

@dstrodtman

Copy link
Copy Markdown
Contributor

Summary

Read the Docs builds intermittently fail with a bare EOFError and no failing document named:

File ".../multiprocessing/connection.py", line 399, in _recv
    raise EOFError
EOFError

make: *** [Makefile:91: html] Error 2

The kernel OOM-kills one of Sphinx's parallel write workers, and the parent process has nothing better to report than the broken pipe. This caps the worker count on the Read the Docs builder, which is the only builder with a hard memory ceiling.

Two changes:

  • doc/Makefile gains SPHINX_JOBS ?= auto, feeding sphinx-build -j. The default keeps today's behavior for every existing caller.
  • The .readthedocs.yaml html job passes SPHINX_JOBS=2.

The mechanism

The builder has 4 CPUs and a cgroup memory.max of 7,130,316,800 bytes, about 6.64 GiB, which matches the memory limit Read the Docs documents for Business. -j auto forks one write worker per CPU and each worker carries its own copy of the build environment, so the write phase costs memory in proportion to the job count.

Measured on the builder, with memory.events read immediately after the build:

Job count memory.peak Headroom under the ceiling oom_kill Result
auto (4) 6,371,254,272 ~759 MB 1 failed, EOFError
auto (4) 6,503,370,752 ~627 MB 0 passed
2 5,566,427,136 ~1,564 MB 0 passed

The two -j auto rows are the important pair: the run that was killed peaked lower than the run that passed. There is no threshold being crossed. The build simply runs about 600 MB under a hard ceiling with four workers allocating independently, and whether a given run survives depends on the timing of individual allocations. That is also why the document Sphinx dies on moves between builds, which is what makes the failure read as a content problem when it isn't.

Dropping to 2 workers roughly doubles the headroom, from about 600 MB to about 1.5 GiB.

Why this is worth doing rather than waiting

The parallelism is recent, not long-standing. Read the Docs' own Sphinx invocation adds -j auto only for projects carrying the opt-in BUILD_IN_PARALLEL feature flag, so RtD was building Ray's docs serially. #64277 pointed build.jobs.build.html at make -C doc html, which inherited the Makefile's -j auto — a flag that until then only the Buildkite doc build used. #64599 then made every preview a full clean -a -E build. Neither change was wrong on its own; together they put four write workers and a thin memory margin on the one builder that can't absorb them.

Some things that this is not, all checked:

  • Not content growth. The Sphinx environment went from 4058 documents on a passing build to 4087 on a failing one. 0.7% can't move a build across a ceiling.
  • Not dependency drift. doc/requirements-doc.lock.txt is fully hash-pinned and unchanged across the window.
  • Not worker overcommit. Sphinx resolves -j auto through multiprocessing.cpu_count, which is neither affinity- nor cgroup-aware, so it can in principle fork more workers than the container can run. On this builder nproc and nproc --all both report 4, so that isn't happening.
  • Not host contention. The ceiling is a per-build cgroup limit, not host pressure, so this isn't other builds crowding the machine.

Cost

Wall clock. A paired run on one builder measured 349 seconds at -j auto against 620 seconds at SPHINX_JOBS=2, about 78% slower. The SPHINX_JOBS=2 arm ran with a warm cache, so treat 78% as a lower bound.

That cost is confined to Read the Docs. SPHINX_JOBS defaults to auto, so local builds and the Buildkite doc build are untouched. Verified with make -n: the default still renders -j auto, the override renders -j 2, and because RTDSPHINXOPTS and LINKCHECKOPTS derive from the same variable, the override also reaches linkcheck, rtd-build, and rtd-fallback. That last part matters for when the incremental cache path in #64277 is re-enabled — the cap will apply there too without another change.

Why 2 rather than 3

2 is the value with a measured peak and a clean oom_kill 0. 3 would cost less wall clock and is plausibly enough, but it hasn't been measured, and at 3 workers the expected headroom lands between the two figures above, closer to the margin that is already producing intermittent kills. Given the failure mode is timing-dependent rather than threshold-dependent, the point of the change is durable headroom rather than getting just back under a line. If the wall-clock cost proves painful, 3 is the obvious thing to measure next.

Follow-up

Read the Docs documents the memory limit as upgradable on Business. Raising it would let the parallelism come back and undo the wall-clock cost. That's a separate ask to Read the Docs rather than a change in this repo, and it's worth making regardless of this PR.

#65631 is the measurement PR that produced the numbers above. It can be closed once this lands; the SPHINX_JOBS plumbing it carried is included here, and its diagnostic wrapper was always meant to come back out.

🤖 Generated with Claude Code

Read the Docs builds intermittently fail with a bare EOFError raised from
multiprocessing/connection.py, naming no document. The kernel OOM-kills one
of the Sphinx write workers and the parent has nothing better to report.

The builder has 4 CPUs and a 7,130,316,800 byte cgroup memory ceiling, and
-j auto forks one write worker per CPU, each holding its own copy of the
build environment. Measured peaks at -j auto were 6,503,370,752 bytes on a
run that passed and 6,371,254,272 on one that was killed, so the build sits
about 600 MB under the ceiling and whether a given run survives depends on
allocation timing rather than on any threshold. At SPHINX_JOBS=2 the same
build peaked at 5,566,427,136 bytes with memory.events oom_kill 0.

Add a SPHINX_JOBS variable to doc/Makefile, defaulting to auto so every
existing caller is unchanged, and set it to 2 from the .readthedocs.yaml
html job only. Local builds and the Buildkite doc build keep -j auto.

Signed-off-by: Douglas Strodtman <[email protected]>
@dstrodtman
dstrodtman requested review from a team as code owners August 21, 2026 14:07
@dstrodtman dstrodtman added the go add ONLY when ready to merge, run all tests label Aug 21, 2026

@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 limits the number of parallel Sphinx workers during the Read the Docs build to prevent out-of-memory (OOM) failures. Specifically, it introduces a configurable SPHINX_JOBS variable in doc/Makefile (defaulting to auto) and overrides it to 2 in .readthedocs.yaml. There are no review comments, so no further feedback is provided.

@dstrodtman
dstrodtman enabled auto-merge (squash) August 21, 2026 15:31
@dstrodtman
dstrodtman merged commit 0f6eba6 into master Aug 21, 2026
7 checks passed
@dstrodtman
dstrodtman deleted the djs-260821-rtd-sphinx-jobs branch August 21, 2026 15:42
nadongjun pushed a commit to nadongjun/ray that referenced this pull request Oct 6, 2026
…project#65643)

## Summary

Read the Docs builds intermittently fail with a bare `EOFError` and no
failing document named:

```
File ".../multiprocessing/connection.py", line 399, in _recv
    raise EOFError
EOFError

make: *** [Makefile:91: html] Error 2
```

The kernel OOM-kills one of Sphinx's parallel write workers, and the
parent process has nothing better to report than the broken pipe. This
caps the worker count on the Read the Docs builder, which is the only
builder with a hard memory ceiling.

Two changes:

- `doc/Makefile` gains `SPHINX_JOBS ?= auto`, feeding `sphinx-build -j`.
The default keeps today's behavior for every existing caller.
- The `.readthedocs.yaml` html job passes `SPHINX_JOBS=2`.

## The mechanism

The builder has 4 CPUs and a cgroup `memory.max` of 7,130,316,800 bytes,
about 6.64 GiB, which matches the memory limit Read the Docs documents
for Business. `-j auto` forks one write worker per CPU and each worker
carries its own copy of the build environment, so the write phase costs
memory in proportion to the job count.

Measured on the builder, with `memory.events` read immediately after the
build:

| Job count | `memory.peak` | Headroom under the ceiling | `oom_kill` |
Result |
|---|---|---|---|---|
| `auto` (4) | 6,371,254,272 | ~759 MB | 1 | failed, `EOFError` |
| `auto` (4) | 6,503,370,752 | ~627 MB | 0 | passed |
| 2 | 5,566,427,136 | ~1,564 MB | 0 | passed |

The two `-j auto` rows are the important pair: the run that was killed
peaked *lower* than the run that passed. There is no threshold being
crossed. The build simply runs about 600 MB under a hard ceiling with
four workers allocating independently, and whether a given run survives
depends on the timing of individual allocations. That is also why the
document Sphinx dies on moves between builds, which is what makes the
failure read as a content problem when it isn't.

Dropping to 2 workers roughly doubles the headroom, from about 600 MB to
about 1.5 GiB.

## Why this is worth doing rather than waiting

The parallelism is recent, not long-standing. Read the Docs' own Sphinx
invocation adds `-j auto` only for projects carrying the opt-in
`BUILD_IN_PARALLEL` feature flag, so RtD was building Ray's docs
serially. ray-project#64277 pointed `build.jobs.build.html` at `make -C doc html`,
which inherited the Makefile's `-j auto` — a flag that until then only
the Buildkite doc build used. ray-project#64599 then made every preview a full
clean `-a -E` build. Neither change was wrong on its own; together they
put four write workers and a thin memory margin on the one builder that
can't absorb them.

Some things that this is *not*, all checked:

- **Not content growth.** The Sphinx environment went from 4058
documents on a passing build to 4087 on a failing one. 0.7% can't move a
build across a ceiling.
- **Not dependency drift.** `doc/requirements-doc.lock.txt` is fully
hash-pinned and unchanged across the window.
- **Not worker overcommit.** Sphinx resolves `-j auto` through
`multiprocessing.cpu_count`, which is neither affinity- nor
cgroup-aware, so it can in principle fork more workers than the
container can run. On this builder `nproc` and `nproc --all` both report
4, so that isn't happening.
- **Not host contention.** The ceiling is a per-build cgroup limit, not
host pressure, so this isn't other builds crowding the machine.

## Cost

Wall clock. A paired run on one builder measured 349 seconds at `-j
auto` against 620 seconds at `SPHINX_JOBS=2`, about 78% slower. The
`SPHINX_JOBS=2` arm ran with a warm cache, so treat 78% as a lower
bound.

That cost is confined to Read the Docs. `SPHINX_JOBS` defaults to
`auto`, so local builds and the Buildkite doc build are untouched.
Verified with `make -n`: the default still renders `-j auto`, the
override renders `-j 2`, and because `RTDSPHINXOPTS` and `LINKCHECKOPTS`
derive from the same variable, the override also reaches `linkcheck`,
`rtd-build`, and `rtd-fallback`. That last part matters for when the
incremental cache path in ray-project#64277 is re-enabled — the cap will apply
there too without another change.

## Why 2 rather than 3

2 is the value with a measured peak and a clean `oom_kill 0`. 3 would
cost less wall clock and is plausibly enough, but it hasn't been
measured, and at 3 workers the expected headroom lands between the two
figures above, closer to the margin that is already producing
intermittent kills. Given the failure mode is timing-dependent rather
than threshold-dependent, the point of the change is durable headroom
rather than getting just back under a line. If the wall-clock cost
proves painful, 3 is the obvious thing to measure next.

## Follow-up

Read the Docs documents the memory limit as upgradable on Business.
Raising it would let the parallelism come back and undo the wall-clock
cost. That's a separate ask to Read the Docs rather than a change in
this repo, and it's worth making regardless of this PR.

ray-project#65631 is the measurement PR that produced the numbers above. It can be
closed once this lands; the `SPHINX_JOBS` plumbing it carried is
included here, and its diagnostic wrapper was always meant to come back
out.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

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

#65643 pinned the Read the Docs build to `SPHINX_JOBS=2`. At `-j auto`
the build peaked within about 600 MB of the builder's 6.64 GiB cgroup
memory ceiling and was sometimes OOM-killed. The pin roughly doubled the
time of the Sphinx step, which takes about 700 of the 770 to 820 seconds
in recent master builds.

#66784 fixed the leak behind most of that memory. MyST `{eval-rst}`
blocks were pickling the whole build environment into each page's
doctree, and every write worker loaded those doctrees back. With that
fixed, this PR drops the pin, so the RtD build uses the `doc/Makefile`
default of `-j auto`, matching local builds and the Buildkite doc build.
It also rewrites the `.readthedocs.yaml` comment, and the `doc/Makefile`
comment that named RtD as the one caller overriding `SPHINX_JOBS`.

The comment keeps the recovery path: if bare `EOFError` failures from
`multiprocessing/connection.py` come back, set `SPHINX_JOBS=2` on the
make command.

### Other build overhead checked

Per-command timings from master build
[4532929](https://app.readthedocs.com/projects/anyscale-ray/builds/4532929/):

| Step | Seconds |
|---|---|
| `git clone` | 38 |
| pip installs (pip and setuptools, Sphinx, docs lock) | 30 |
| Sphinx build at `-j 2` | 702 |

Nothing outside the Sphinx step is worth changing. Intersphinx already
loads committed snapshots, notebook execution is off, and `llms.txt`
generation is skipped on PR builds. RtD's default step also upgrades
Sphinx before the lock reinstalls it, but that costs about 5 seconds and
removing it means overriding the whole install step.

## Duplicate check

No open `ray-project/ray` PR touches `.readthedocs.yaml` or the
`SPHINX_JOBS` setting. Searched `SPHINX_JOBS`, `readthedocs.yaml
in:title`, and `RtD parallelism`. The three PRs the `SPHINX_JOBS` search
returned don't change either file.

## Verification

Local full builds of master at 1a9ba71 with this job's flags (`python -m
sphinx --keep-going -b html -a -E -W -j N -T -D language=en`), in a
Python 3.11 venv installed from `doc/requirements-doc.lock.txt`,
sampling total RSS across the Sphinx processes every 2 seconds, the same
method #66784 used:

| Workers | Result | Wall clock | Peak summed RSS |
|---|---|---|---|
| 4 | `build succeeded.`, 0 warnings | 425 s | 4.74 GB |
| 2 | `build succeeded.`, 0 warnings | 914 s | 2.67 GB |

The 2-worker run reproduces #66784's numbers (2.53 GB, 918 s). Summed
RSS overstates the cgroup figure because it counts pages shared between
forked workers more than once. Before #66784, the same method read 9.44
GB at 2 workers, while RtD's cgroup measured 5.57 GB for the same
configuration.

#65643 measured 4 CPUs on the builder (`nproc` and `nproc --all`), and I
haven't re-measured that.

This PR's Read the Docs preview build,
[4533416](https://app.readthedocs.com/projects/anyscale-ray/builds/4533416/),
ran `sphinx-build ... -j auto` on the real builder and passed:

| Build | Sphinx step | Total |
|---|---|---|
| Master
[4532929](https://app.readthedocs.com/projects/anyscale-ray/builds/4532929/),
`-j 2` | 702 s | 793 s |
| This PR
[4533416](https://app.readthedocs.com/projects/anyscale-ray/builds/4533416/),
`-j auto` | 411 s | 520 s |

That's one build on each side. PR builds also skip `llms.txt`
generation, so the master saving might be slightly smaller.

AI assistance (Claude Code) was used to measure, write, and describe
this change. I 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 <[email protected]>
sai-miduthuri pushed a commit that referenced this pull request Nov 4, 2026
…g the build environment and restore full Sphinx parallelism on Read the Docs (#66784, #66793) (#67797)

## Description

Cherry-picks #66784 and #66793 onto `releases/2.60.0`, so the release
branch builds its docs on Read the Docs the same way master does.

The `releases-2.60.0` docs have never built on Read the Docs. All four
attempts on 2026-11-03 were cancelled partway through `make html` with
"Build terminated due to inactivity", so RtD kept no Sphinx output:
[4668524](https://app.readthedocs.com/projects/anyscale-ray/builds/4668524/),
[4668563](https://app.readthedocs.com/projects/anyscale-ray/builds/4668563/),
[4668796](https://app.readthedocs.com/projects/anyscale-ray/builds/4668796/),
and
[4668932](https://app.readthedocs.com/projects/anyscale-ray/builds/4668932/).

The branch was cut on 2026-09-30, before these two master changes:

- #66784 stops MyST `{eval-rst}` blocks from pickling the whole build
environment into each page's doctree, which every Sphinx worker then
loaded back.
- #66793 drops the `SPHINX_JOBS=2` pin from #65643, which the leak had
made necessary, so RtD builds with one Sphinx worker per CPU again.

Without them, this branch still builds with the leak and two workers.
2.59.0 built that way in 811 and 912 seconds, against about 500 seconds
for master's builds on 2026-11-03.

This may not be the whole fix. Master has both changes and still lost
about 1 in 5 RtD builds to the same inactivity kill on 2026-11-03. But
2.60.0 lost all four of its builds in the same period, so its build
setup is the likeliest difference.

## Changes

This is `git cherry-pick -x -s` of c6d7e72 (#66784) and then
cec3972 (#66793), with no conflicts. The diff matches the two PRs
exactly: 6 files, +219/−24. Only the docs build and its CI change, and
nothing that ships in the wheel:

- `doc/source/_ext/myst_eval_rst_doctree.py` and its test, registered in
`doc/source/conf.py`.
- `.buildkite/doc.rayci.yml`, which runs the new test.
- `.readthedocs.yaml` and `doc/Makefile`, which drop `SPHINX_JOBS=2`.

The two commits need to land together. #66793 on its own would run the
leaky build at full parallelism, which RtD sometimes OOM-killed before
#66784.

This branch pins the same Sphinx 8.2.3, myst-parser 5.1.0, myst-nb
1.4.0, and docutils 0.21.2 that #66784 was built against. The docs lock
differs only in `certifi`. Master's only later changes to these files,
#66807 and #66756, update `doc/Makefile` cleanup paths for pages that
moved after the cut, so they aren't included.

## Testing

Both commands ran on this branch in a Python 3.11.15 venv built from
`doc/requirements-doc.lock.txt`.

```
$ python doc/source/_ext/test_myst_eval_rst_doctree.py
PASS: myst_eval_rst_doctree re-points nested eval-rst nodes, and the pickled doctree no longer carries the build environment.
```

```
$ make -C doc rtd-build SPHINX_JOBS=4
...
✓ Environment matches the Read the Docs build.
sphinx-build --keep-going -b html -d _build/doctrees  -a -E -W -j 4 -T -D language=en source _build/html
...
build succeeded.
```

`rtd-build` first checks the venv against the RtD build. Python, Sphinx,
myst-parser, myst-nb, and the theme all match; only the operating system
differs, since this ran on macOS. The build is the clean `-a -E -W`
build that RtD runs. `-j 4` matches the RtD builder's 4 CPUs, which is
what the default `SPHINX_JOBS=auto` gives there. It succeeded in 458
seconds with no warnings.

Summed RSS across the Sphinx processes, sampled every 2 seconds, peaked
at 3.56 GB. Summed RSS overstates real use, because forked workers share
pages. #66793 measured 4.74 GB the same way on master at `-j 4`.

## Not a duplicate

No open PR targets `releases/2.60.0`, and no other PR references #66784
or #66793.

AI assistance: Claude Code investigated the failed builds, made the
cherry-pick, ran the tests above, and drafted this description.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Signed-off-by: Douglas Strodtman <[email protected]>
Signed-off-by: Ronny Roland <[email protected]>
Co-authored-by: Douglas Strodtman <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

go add ONLY when ready to merge, run all tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants