Skip to content

Fix global_config: keep sibling subtrees contiguous when flattening config_paths - #2573

Merged
bxyu-nvidia merged 1 commit into
mainfrom
fix/config-paths-postorder
Aug 17, 2026
Merged

bxyu-nvidia merged 1 commit into
mainfrom
fix/config-paths-postorder

Conversation

@ushnish-de

Copy link
Copy Markdown
Contributor

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] where A -> A1 and B -> B1 -> B2, the depths are A=0, B=0, A1=1, B1=1, B2=2, so the merge order is [B2, A1, B1, A, B] and A1 overrides B2 even though B is 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 within B's subtree — silently changes how that subtree ranks against A'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_paths list 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

…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]>
@copy-pr-bot

copy-pr-bot Bot commented Aug 17, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@bxyu-nvidia
bxyu-nvidia merged commit 7f3fc38 into main Aug 17, 2026
18 checks passed
@bxyu-nvidia
bxyu-nvidia deleted the fix/config-paths-postorder branch August 17, 2026 04:50
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.

2 participants