Repository navigation
Fix global_config: keep sibling subtrees contiguous when flattening config_paths - #2573
Merged
Merged
Conversation
…config_paths - Follow-up to #2572, which ordered configs by sorting globally on nesting depth. That interleaved subtrees: for [A, B] with A -> A1 and B -> B1 -> B2 the merge order was [B2, A1, B1, A, B], so A1 overrode B2 even though B is the later sibling. It also tied precedence to absolute depth, so adding a level of indirection inside one subtree changed how it ranked against unrelated ones. - Walk the include tree in post-order instead: children before parent, siblings in listed order, each subtree contiguous. Add a regression test over sibling subtrees of uneven depth. The recorded config_paths list is unaffected. Signed-off-by: Ushnish De <[email protected]>
bxyu-nvidia
approved these changes
Aug 17, 2026
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.
Follow-up to #2572, addressing review feedback from @cmunley1 that arrived after the merge.
Problem
#2572 restored sibling precedence by sorting all configs globally on nesting depth. That interleaves independent subtrees. For
config_paths: [A, B]whereA -> A1andB -> B1 -> B2, the depths areA=0, B=0, A1=1, B1=1, B2=2, so the merge order is[B2, A1, B1, A, B]andA1overridesB2even thoughBis the later sibling.It also makes precedence a function of absolute nesting depth, which is not a local property: wrapping one extra include layer inside
B— a refactor entirely withinB's subtree — silently changes how that subtree ranks againstA's.Fix
Flatten the include tree with an iterative post-order walk instead of sorting: children before parent, siblings in listed order, each subtree contiguous. The example above now merges as
[A1, A, B2, B1, B]. This matches how Hydra's defaults list behaves, which is the closest analog users will have in mind.The traversal is iterative so deep include chains cannot exhaust the stack. Termination is structural rather than relying on a visited set: an edge is only recorded when a path is appended for the first time, so a child always has a higher index than its parent and every node has at most one parent, making the edge set a forest even when configs reference each other cyclically.
Two behaviors are deliberately unchanged: the returned
config_pathslist keeps its existing discovery order (only merge order moves), and a config pulled in by two different parents still attaches at its first reference.Testing
test_get_global_config_dict_config_paths_later_sibling_subtree_wins_at_uneven_depthbuilds the reported shape (one sibling nesting one level, the other two) and pins the key both innermost configs set. It fails against Fix global_config: Preserve sibling order when outer config_paths override inner ones #2572 withcontested: 'first_inner'and passes here withsecond_inner.test_cli_utils.py::test_not_truncated_regardless_of_ambient_width, which also fails on a clean tree.