Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix rule graph nondeterminism due to undetected ambiguity #7379

Merged
merged 6 commits into from
Mar 14, 2019

Conversation

stuhood
Copy link
Member

@stuhood stuhood commented Mar 14, 2019

Problem

Integration tests of @console_rules would frequently flake (as in #6782) with rules self-cycling in a peculiar way. Investigating the failure lead to the conclusion that the RuleGraph was being constructed non-deterministically.

The source of the non-determinism was that we were "simplifying" all instances of one @rule that used the same number of Params, and treating them interchangeably. But that simplification was subject to rust's randomized hash ordering, and so we would choose which of the Params to use at random.

After fixing that non-determinism, we also needed to solve the underlying ambiguities (there were two or three) that lead to there being multiple options to choose from.

Solution

  • Change GraphMaker::choose_dependency to not simplify rules, and instead preserve all candidates with the current minimum Param set size.
  • Fix the ambiguity that lead to multiple choices being available by introducing an (intuitive, I think) restriction that only subgraphs that actually use the Param provided by a Get are eligible to satisfy it. See the explanation in the test.

Result

Unskips @console_rule integration tests, and adds a (previously flaky, now stable) unit test of the ambiguous case. Fixes #6782.

@stuhood
Copy link
Member Author

stuhood commented Mar 14, 2019

Individual commits are useful to review independently.

Copy link
Contributor

@illicitonion illicitonion left a comment

Choose a reason for hiding this comment

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

Thanks!

Copy link
Contributor

@ity ity left a comment

Choose a reason for hiding this comment

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

lgtm!

let mut rules_by_kind: HashMap<EntryWithDeps, (usize, &Entry)> = HashMap::new();
for satisfiable_entry in &satisfiable_entries {
// We prefer the non-ambiguous rule with the smallest set of Params, as that minimizes Node
// identities in the graph and biases toward receiving values from dependencies (which do not
Copy link
Contributor

Choose a reason for hiding this comment

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

s/identifies/selections?

Copy link
Member Author

@stuhood stuhood Mar 14, 2019

Choose a reason for hiding this comment

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

This is "identities", which is accurate here... we refer to the Params that a @rule consumes as part of its "identity", because the same @rule can be used with multiple sets of Params, which might each (as seen in this ticket!) affect their behaviour.

Copy link
Contributor

@blorente blorente left a comment

Choose a reason for hiding this comment

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

I don't have enough context for any meaningful comments. Will read through it tomorrow but would not like to block it.

…nested_raise` (because it was not installed).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

tests/python/pants_test/rules:test_integration is flaky
4 participants