Repository navigation
Fix global_config: Preserve sibling order when outer config_paths override inner ones - #2572
Conversation
…erride inner ones Reversing the flat BFS list of loaded configs made outer configs beat inner ones, but it also reversed the caller's own entries against each other, so the first --config listed silently won over the last. Track each entry's nesting depth and merge deepest-first with a stable sort: outer still beats inner at any depth, and a later sibling beats an earlier one. Signed-off-by: Ushnish De <[email protected]>
|
/claude review |
|
SHIP — no reliability concerns. Reviewed Traced the logic against all cases:
Tests assert real merged output (not vacuous) and cover sibling-wins, outer-beats-inner-across-siblings, and two-level nesting. One thing to flag for the author, not a blocker: this flips sibling precedence — any existing setup passing multiple sibling |
…onfig_paths (#2573) 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 - New `test_get_global_config_dict_config_paths_later_sibling_subtree_wins_at_uneven_depth` builds the reported shape (one sibling nesting one level, the other two) and pins the key both innermost configs set. It fails against #2572 with `contested: 'first_inner'` and passes here with `second_inner`. - The three ordering tests from #2572 pass both before and after, confirming the new test is the one carrying this case. - Full unit suite: 2462 passed, 41 skipped. One unrelated pre-existing failure in `test_cli_utils.py::test_not_truncated_regardless_of_ambient_width`, which also fails on a clean tree. Signed-off-by: Ushnish De <[email protected]>
What does this PR do?
Nesting depth and sibling order are two independent precedence axes in
config_paths, and a single list reversal cannot express both.load_extra_config_pathswalksconfig_pathsbreadth-first and appends nestedentries to the same flat list, so it ends up as
[caller entries..., their children..., grandchildren...]. Merging thatleft-to-right let children override their parents, so #2478 (0051ad8) reversed
the whole list. That correctly made outer configs win, but it also reversed the
caller's own entries against each other, inverting sibling precedence: given
--config base.yaml --config override.yaml,base.yamlnow wins.The failure is silent. The override still loads, still resolves, and still
appears in the final
config_paths; it just loses every key it sets. For aneval config that means the run completes and reports plausible numbers scored
against the wrong judge prompt and reward mode.
This PR tracks each entry's nesting depth as it is discovered and orders the
configs deepest-first with a stable sort. Deepest-first keeps #2478's intent at
any depth: an outer config merges last and overrides anything it pulled in.
Stability restores sibling precedence, so same-level configs keep the order they
were listed in and a later one overrides an earlier one. The blanket
extra_configs.reverse()at the call site is no longer needed.Nothing in
docs/describes this precedence, so the added tests are the spec.Tests
Three additive cases in
TestGlobalConfig; no existing assertion changed...._config_paths_later_sibling_wins— two caller entries, neither referencingthe other; the later one overrides the earlier.
..._config_paths_outer_beats_inner_across_siblings— both axes at once: thelater sibling wins its key while the parent still beats the config it pulled in.
..._config_paths_outer_beats_inner_two_levels_deep— outer beats middle beatsinner.
Negative control: with
global_config.pyreverted tomain, the two siblingtests fail with the production symptom (
a: basewherea: overrideisexpected) while the three-level nesting test passes either way, confirming the
property #2478 added is preserved rather than traded away.
Full unit suite: 2435 passed. One unrelated pre-existing failure
(
test_cli_utils.py::TestPrintRichTable::test_not_truncated_regardless_of_ambient_width),which fails identically on unmodified
main.Checklist
pre-commit run --all-files).git commit -s).