Skip to content

Fix global_config: Preserve sibling order when outer config_paths override inner ones - #2572

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

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

Conversation

@ushnish-de

Copy link
Copy Markdown
Contributor

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_paths walks config_paths breadth-first and appends nested
entries to the same flat list, so it ends up as
[caller entries..., their children..., grandchildren...]. Merging that
left-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.yaml now 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 an
eval 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 referencing
    the other; the later one overrides the earlier.
  • ..._config_paths_outer_beats_inner_across_siblings — both axes at once: the
    later 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 beats
    inner.

Negative control: with global_config.py reverted to main, the two sibling
tests fail with the production symptom (a: base where a: override is
expected) 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

  • I have read the contributing guidelines.
  • The change is focused; unrelated "drive-by" edits are tracked as separate issues/PRs.
  • Tests added or updated and pass locally, or N/A for docs-only / non-code changes.
  • Pre-commit checks pass locally (pre-commit run --all-files).
  • All commits have DCO sign-off (git commit -s).

…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]>
@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.

@ushnish-de ushnish-de self-assigned this Aug 17, 2026
@ushnish-de
ushnish-de requested a review from cmunley1 August 17, 2026 02:26
@cmunley1

Copy link
Copy Markdown
Contributor

/claude review

@cmunley1
cmunley1 requested a review from bxyu-nvidia August 17, 2026 03:03
@claude

claude Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

SHIP — no reliability concerns.

Reviewed load_extra_config_paths merge-order refactor. It replaces the blanket extra_configs.reverse() in parse() with a depth-tracked, stable deepest-first sort in the loader.

Traced the logic against all cases:

  • Nesting: config1 → config2 (depths [0,1]) sorts to [config2, config1], so the outer config still overrides what it pulled in. Matches the pre-existing test_..._ordering assertions — backward-compatible.
  • Siblings: [base, override] (depths [0,0]) preserves listed order under the stable sort, so the later sibling now wins. This is the intended fix (the old reverse made the earlier sibling win); "later overrides earlier" is the conventional and less surprising semantics.
  • Index alignment: depths is appended in lockstep with config_paths inside the mutating enumerate loop, so len(depths) == len(extra_configs) at the sort; no drift.
  • dotenv/CLI precedence unchanged — dotenv still appended post-sort, CLI still merged last.

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 --config/config_paths entries and relying on the old earlier-wins behavior will silently change. Given the fix is intentional and the new semantics are the expected ones, worth a line in release notes / config docs (fern/.../reference/configuration.mdx) so the behavior change is discoverable.

@bxyu-nvidia
bxyu-nvidia merged commit 03be216 into main Aug 17, 2026
18 checks passed
@bxyu-nvidia
bxyu-nvidia deleted the fix/config-paths-sibling-order branch August 17, 2026 03:25
bxyu-nvidia pushed a commit that referenced this pull request Aug 17, 2026
…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]>
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.

3 participants