resolve conflicts by insertion order#9862
Conversation
|
Hmm: I'd definitely like to make these deterministic. However, I still don't love falling back to insertion order. Can we use a seeded RNG, with user control over the seed? Or even better, some seed that can be used for a more stable mapping? That gives us reproducibility without the painful implicitness of insertion order, and lets users test for insertion order bugs more easily. |
|
I agree with Alice's seeded RNG idea. If we use insertion order to make it deterministic, then many users will start relying on that implicit behavior as the primary way to order systems. We want to encourage users to always use explicit ordering when it matters. |
|
If there's a need for a RNG source, |
|
Sure, I'm happy enough with this as a compromise, especially with strong warnings in the docs. |
|
This PR isn't going to work correctly with the current algorithm. It can add cycles into the graph fairly easily. We'd have to check for existing transitive dependencies each time we add an edge to avoid this. Probably too expensive to be worth it. I'm not sure this is the right solution to the problem anyways, given that this just hides bugs that are easy to expose during refactors. I think we should:
I'll leave this PR open for a little bit in case someone who sees it thinks of a way of adding edges without introducing cycles, but will otherwise close this PR soonish. |
|
Hmm. If we add the edges one at a time, checking for ambiguities each time, it should be impossible to introduce cycles. Obviously that would be very slow, but there's definitely an algorithm here. |
|
How are random system orderings currently chosen? Could we take the current approach and make it seeded? Apologies if this has an obvious answer, I haven't done any due diligence before asking. |
|
They're currently incidental based on how the topological sort shakes out. |
|
🤔 I don't know if there's a "good" solution that can circumvent a dependence on insertion order. We can prevent executor variation by choosing an ordering for ambiguous nodes that follows their topological order, but we can't guarantee the topological order itself will be the same every time. The topological sort is essentially a DFS, so any randomness in its output comes from the order DFS visits nodes, which ultimately derives from (1) the order nodes and edges were inserted and (2) the first node visited by the sorting algorithm. I believe the first node visited in the To control (1), we'd need to reassemble the graph with a new insertion order that comes from something stable, like UUIDs. Let's say we give up on that and look for a solution that can be applied after a "random" topological sort. I don't know if one that is particularly cheap exists. The best I can come up with is this.
|
|
closing this as any future work will require a new pr. |
Objective
Solution
NodeIdwas already being generated when inserting new systems.AmbiguityDetectionthat has aResolvevariant added. Otherwise has the same variants asLogLevel.Resolvethe default instead ofIgnore. Having the random behavior was hard for users to understand. Now if they have an incorrect ambiguity it will always be present.Changelog
Migration Guide
ScheduleBuildSetings::ambiguity_detectionnow takes aAmbiguityDetectionthat has an extra variantResolveoverLogLevel.IgnoretoResolve. If you want the previous behavior you'll need to useschedule.set_build_settingsto change it back.Future Work
I'd like to also add in resolving by placing writes before reads, but this is more work as this information is not currently available in the reported conflicts, so this will require more extensive changes. This feature should also help a bit with the confusing bugs by reordering plugins mentioned above.
There will be systems that can't be resolved by write-before-read ordering. They could be writing the same component or one will write one component while the other reads that component, but writes another. In these cases we can fall back to system insertion order, but we provide the options to error or warn in these situations.