Skip to content

Conversation

@werkt
Copy link
Contributor

@werkt werkt commented Oct 22, 2025

The duration report introduces unnecessary noise in determinism for build which otherwise represent identical behaviors - each test that varies in execution enough to cross a second threshold would appear with a different action, making it extremely difficult to isolate determinism across a build's worth of actions.

Duration reporting takes place in bazel through alternative means.

@github-actions github-actions bot added the awaiting-review PR is awaiting review from an assigned reviewer label Oct 22, 2025
@bharadwaj08-one
Copy link

@werkt Could you please take a look at the failing checks?

@bharadwaj08-one bharadwaj08-one added awaiting-user-response Awaiting a response from the author and removed awaiting-review PR is awaiting review from an assigned reviewer labels Oct 22, 2025
@werkt werkt force-pushed the test-xml-discard-duration branch 2 times, most recently from f44c6ab to 70899ca Compare October 22, 2025 05:50
The duration report introduces unnecessary noise in determinism for
build which otherwise represent identical behaviors - each test that
varies in execution enough to cross a second threshold would appear with
a different action, making it extremely difficult to isolate determinism
across a build's worth of actions.

Duration reporting takes place in bazel through alternative means.
@werkt werkt force-pushed the test-xml-discard-duration branch from 70899ca to a2fe525 Compare October 22, 2025 06:16
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuite name="${test_name}" tests="1" failures="0" errors="${errors}">
<testcase name="${test_name}" status="run" duration="${DURATION_IN_SECONDS}" time="${DURATION_IN_SECONDS}">${error_msg}</testcase>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very useful for interop with test infrastructure that isn't Bazel-aware. JUnit XML is pretty much universally supported, other means for getting this information would need an adapter.

Generally speaking, wouldn't the test logs, which are also inputs to this action, usually be non-deterministic as well? In that case the XML generation spawn would differ anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test outputs can be deterministic, or not. The problem here is that regardless of whether they are, if the wall time for the test crosses a second threshold, it automatically changes the command definition from one value to the next, and prevents even deterministically outputting tests from avoiding differences between no-change builds being run to locate determinism issues elsewhere. Objectively, the test isn't in control of whether it gets scheduled enough to avoid modifying its own wall time, no matter how much an author seeks deterministic, reproducible output.
I'm game for marking this up as a test-command option, but figured it may be more useful to avoid this very subjective data altogether than try to cobble conditional xml output.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I see how it can be annoying that this introduces non-determinism into an otherwise deterministic test, I've honestly never seen a non-trivial project in which every test emits a deterministic log. In the context of detecting non-determinism, getting rid of the runtime argument would only really make a qualitative difference if that was the case though.

bb explain has special handling for this particular spawn, which is recognized by its TestRunner mnemonic and the basename of the output. What do you think of introducing a distinctive mnemonic (say TestXmlGeneration)? That would make it very easy to filter this out without taking away value from non-Bazel-aware test integrations.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mnemonic should be switched regardless of the outcome here. Qualifying this activity with the TestRunner is ambiguous and something I've wanted changed for a while, I will submit a separate change.

It's not satisfactory though to say that unlikeliness of universal determinism is a reason to permit this behavior to introduce arbitrary nondeterminism. Cases where overt remote cache misses occur here solely because of this change is the domain of this improvement. Less convincing still is the interest to maintain external tooling. I don't have the option to disable this step of output entirely from bazel's execution, and I don't necessarily know that removing this timing will break any particular downstream parser to ignore the missing content (and its obvious duplication for the use in two fields).
Real timing information is clearly available in bazel-specific contexts, because it exists at higher precision than 1s.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One better than this with further thought. This is a mechanism that, outside of java, no other user of bazel can perform (starlark for instance): modifying the composite state of an action in its command args such that they are only effective and known during the execution phase. I don't care about the presence in the xml, it can be zero for all that matters here, but the unpredictable nature of the action makes the graph mutable, something against the stated intention of bazel. This represents bazel mutating its own "immutable build graph".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a breaking change to multiple repos I'm aware of. Can we at least put it behind an incompatible flag?

(+1 that in my experience most tests do not have deterministic logging, it's common for logs to contain randomly-generated IDs, timestamps, etc.)

Copy link
Collaborator

@fmeum fmeum Oct 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cases where overt remote cache misses occur here solely because of this change is the domain of this improvement.

Which situation are you referring to here? If the test execution itself is a cache hit, the subsequent XML generation should be as well since the test runtime is obtained from the cached action result. If a test is forced to rerun somehow then this action could potentially be a cache hit if it didn't contain the time, but that seems to be a pretty rare case.

Note that rules can always avoid running this spawn by generating the XML directly as part of the test action. But that's of course not something users can add without patching or forking rules they don't own.

modifying the composite state of an action in its command args such that they are only effective and known during the execution phase

Starlark can't access action timing data, but aren't tree artifacts and the newly exposed action templates examples of this?

@bharadwaj08-one bharadwaj08-one added awaiting-review PR is awaiting review from an assigned reviewer and removed awaiting-user-response Awaiting a response from the author labels Oct 22, 2025
@iancha1992 iancha1992 added the team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website label Oct 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-review PR is awaiting review from an assigned reviewer team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants