Repository navigation
Discard rust_doc_test's captured stdout when the doctests pass - #87
Merged
dzbarsky merged 1 commit intoOct 13, 2026
Merged
Conversation
`rust_doc_test` runs `rustdoc --test` in a build action and declares its stdout, stderr and exit code as outputs, which the test only replays. libtest prints results in completion order with wall-clock durations, so a passing run writes different stdout every time, and the replay misses the cache. Nothing reads that stdout except the replay; the result comes from the exit code. Add `--discard-stdout-on-success` to the process wrapper and pass it from `rust_doc_test`. When rustdoc exits with 0, the wrapper empties the stdout file, so a passing run always writes the same bytes. A failing run keeps rustdoc's full output for the failure details. Assisted-by: Claude
anagrius
force-pushed
the
rustdoc-test-reproducible-stdout
branch
from
October 11, 2026 11:09
2207175 to
c9349f3
Compare
anagrius
marked this pull request as ready for review
October 11, 2026 11:12
dzbarsky
approved these changes
Oct 13, 2026
dzbarsky
left a comment
Member
There was a problem hiding this comment.
Thanks, that's a nice catch!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
We had a problem where
rust_doc_testwrote different outputs for the same cache key on different CI runners. Our reproducibility check caught a target with zero doctests whose captured stdout saidfinished in 0.00son one runner and0.01son another.rust_doc_testrunsrustdoc --testin a build action and declares its stdout, stderr and exit code as outputs. The test only replays them. libtest prints results in completion order and reports wall-clock durations, and edition 2024 merged doctests add another timing line, so a passing run writes different stdout every time. Nothing reads that stdout except the replay, and the pass or fail result comes from the exit code file. Each time the bytes change, the replay misses the cache.We considered several alternatives before settling on this one.
The first version of this PR normalized libtest's output: it sorted the result lines and stripped the durations. A review showed that matching lines by prefix also rewrote what the doctests themselves print, such as a line starting with
testinside a failure, and that it missed other libtest output:--quietmarks in completion order,--show-outputsections,--report-timedurations and slow-test notices. We then wrote a parser for libtest's exact formats. It reached about 800 lines, and memory still grew with output size. That is a lot to review for output that only a replay reads.Running the doctests with
--test-threads=1would fix the order, but the durations remain and the doctests lose their parallelism. Normalizing in a separate action, or in the replay runner, still leaves the raw stdout as a nondeterministic cached output. Running doctests at test time again, as upstream rules_rust does, would undo this fork's deliberate move of that work into the build. Exempting the action in our own reproducibility check would hide the noise for us, but the replay would still miss the cache for everyone.Discarding the stdout of a passing run avoids parsing libtest at all, because the exit code already carries the result.
We solved it by adding
--discard-stdout-on-successto the process wrapper and passing it fromrust_doc_test. When rustdoc exits with 0, the wrapper empties the stdout file, so a passing run always writes the same bytes. A failing run keeps rustdoc's full output, because that is where the failure details are. Those details, such as thread ids and temporary paths, still differ between runs. The cost is that the test log of a passingrust_doc_testno longer lists the doctests that ran.We added process wrapper tests for both paths: a passing child leaves an empty stdout, and a failing child keeps its stdout and records exit code 1. Each test fails when the wrapper is changed to break its path. The
RustdocTestanalysis test checks for the new flag. In this repo,//test/unit/rustdoc:lib_doctestand//test/chained_direct_deps:mod3_doc_testwrote an empty stdout over three forced reruns, andbazel test //test/process_wrapper/... //util/process_wrapper:process_wrapper_test //test/unit/rustdoc:all //test/chained_direct_deps:allpasses.Assisted-by: Claude