Skip to content

fix(config): resolve chained _inherit_from and _copy sources - #6040

Open
esarafian wants to merge 2 commits into
NVIDIA-NeMo:mainfrom
esarafian:fix/inherit-from-chains
Open

esarafian wants to merge 2 commits into
NVIDIA-NeMo:mainfrom
esarafian:fix/inherit-from-chains

Conversation

@esarafian

Copy link
Copy Markdown
Contributor

What does this PR do?

Resolves chained _inherit_from and _copy sources. Before this change, _recursively_swap_keys_helper merged each source as written (nemo_gym/config/global_config.py, the former TODO "We may want to recurse again after swap"). When the source itself inherits from another config, its own _inherit_from was copied into the target unresolved, and a key that an earlier swap had moved could be added back.

This breaks gym eval run <harbor task folder> --agent nooa_agent/nooa_sandboxed. The Harbor route generates harbor_<taskset>_agent: {_inherit_from: agent} (nemo_gym/data/tasks/harbor/materialize.py), and nooa_sandboxed.yaml defines agent: {_inherit_from: nooa_agent}. Resolution then fails with:

Error: In server instance 'harbor_<taskset>_environment', field 'agent_server' references responses_api_agents/'harbor_<taskset>_agent', which is not defined in the merged config.

The fix resolves each swap or copy source on a copy, with its own _inherit_from, _copy and _delete_key applied, before merging it. The result no longer depends on which key the pass reaches first. A source that leads back to itself raises InheritPathNotFoundError and names the cycle. A key that an earlier swap in the same pass moved away is skipped.

The second commit removes the --reuse-verifier scaffold check that refused an environment server derived with _inherit_from or _copy (nemo_gym/environment/scaffold.py). That check existed only because of this limitation.

Issue: none filed; found while running the sandboxed NOOA agent on local Harbor task folders.

Validation

On Linux x86_64, Python 3.13.14, uv 0.13.7:

  • pytest tests/unit_tests/config: 311 passed, including 24 new cases. The new cases cover chains in the property, ${inherit_from:...} and _copy forms and in both key orders, _delete_key, ??? sources, five cycle forms, and the Harbor-shaped case where an environment server names the derived agent. All 24 fail on main.
  • One new scaffold test for reusing a derived environment server.
  • Full unit suite with CI extras: 17240 passed, 2 failed. The 2 failures are aiohttp import errors in scripts run by path and fail the same way on unmodified main.
  • pre-commit run --files <touched files>: clean.
  • End to end without a model: resolving gym eval run <harbor folder> --agent nooa_agent/nooa_sandboxed --only-tasks <task>, with server start stubbed out, gives the error above on main. On this branch it gives one agent, harbor_<taskset>_agent, with execution_mode: sandboxed and sandbox_runner_timeout_seconds: 21600 inherited.

Rollouts

N/A for this PR: it changes config resolution only, checked without model calls. With this fix and the related NOOA agent fixes, we ran sandboxed NOOA rollouts on Harbor task folders with the docker sandbox.

Compatibility and benchmark impact

  • A cycle of _inherit_from / _copy sources used to be left partly unresolved; it now raises an error that names the cycle.
  • --reuse-verifier now accepts an environment server that is itself derived.
  • Single-level inheritance resolves as before. No benchmark-result impact.

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 (so CI unit/server checks pass when applicable).
  • Documentation added or updated, or N/A with justification. (N/A: no documented behavior changes; code comments updated.)
  • Pre-commit checks pass locally (pre-commit run --files <touched files>).
  • New source files include the required Apache-2.0 SPDX header. (No new source files.)
  • All commits have DCO sign-off (git commit -s) (so the DCO check passes).

🤖 Generated with Claude Code

esarafian and others added 2 commits November 12, 2026 10:53
A swap or copy merged its source as written, so a source that was itself
derived (a -> b -> c) kept an unresolved `_inherit_from` whenever the swap
reached the destination after the source, and a moved source whose own
swap ran later was put back under its old name. The Harbor route hits
this: `harbor_<taskset>_agent` inherits the selected flavor
(`nooa_agent/nooa_sandboxed` defines `agent: {_inherit_from: nooa_agent}`),
so the taskset agent was dropped and its environment server reported
"references responses_api_agents/'harbor_<taskset>_agent', which is not
defined".

Resolve each source, on a copy, with its own `_inherit_from`, `_copy` and
`_delete_key` applied before merging it, and skip keys an earlier move
removed. A source that leads back to itself raises
InheritPathNotFoundError naming the cycle instead of recursing forever.
Single-level inheritance, MISSING propagation and the agent/resources
rename bookkeeping are unchanged.

Signed-off-by: Elad Sarafian <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ived

`--reuse-verifier` refused a bundled environment server declared with
`_inherit_from` or `_copy` because configuration resolved inheritance
against the configs as written. Chained sources now resolve link by link,
so the workload can inherit such a server; the test resolves a scaffolded
workload whose reused server inherits a base server.

Signed-off-by: Elad Sarafian <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@copy-pr-bot

copy-pr-bot Bot commented Nov 12, 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.

@cmunley1

Copy link
Copy Markdown
Contributor

/ok to test 400e180

@github-actions

Copy link
Copy Markdown
Contributor

@svcnvidia-nemo-ci svcnvidia-nemo-ci left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SHIP WITH CARE

I found four RISK issues: detached interpolation resolution, nested moves within a source, reference repair across complete chains, and scaffold name collisions with derivation ancestors.

I inspected all six changed files and their directly affected configuration, Harbor, and scaffold paths. This was a static review; I couldn't execute tests with the available tools. The acceptance checks below are proposed tests, not reported results.


Inline comments (escaped v1):

  • nemo_gym/config/global_config.py line 1572: RISK — Don't resolve ordinary interpolations against the temporary holder

    Failure: Could source resolution retain the global interpolation context? Consider:

    config = DictConfig({
        "model": "m",
        "source": {"items": ["${model}"]},
        "target": {"_copy": "source"},
    })
    GlobalConfigDictParser()._recursively_swap_keys(config)

    The new traversal places source under a root containing only value, then indexes its list elements. That evaluates ${model} where the root has no model, producing an interpolation error instead of a target whose first item resolves to "m". The base implementation didn't perform this detached traversal. This affects ordinary single-level copies and inheritance, not just chains.

    Correction: In _resolved_swap_source and the list branch of _recursively_swap_keys_helper, either preserve the original interpolation context or traverse unresolved nodes while detached. The invariant is that resolving Gym directives must not evaluate an ordinary interpolation against the synthetic holder root. The exact patch needs to account for interpolated container aliases and relative references, so I haven't supplied an unverified replacement.

    Preservation and proposed acceptance checks: Exercise this example in both key orders with _copy, _inherit_from, and their string forms. The target item must resolve to "m"; retain source only for copies. Also test a literal dictionary inside the list containing both a nested copy directive and a relative reference, such as {"local": "m", "selected": "${.local}", "copied": "${copy:model}"}: both selected and copied values must resolve to "m". Keep the missing-list assertions, chain/delete behavior, and cycle diagnostics. These outcomes are source-derived, not executed.

  • nemo_gym/config/global_config.py line 1528: RISK — Apply nested moves to the source being resolved, not only the live global tree

    Failure: Resolving a source on a copy still sends every nested move through original_dict_config. A minimal case is:

    config = DictConfig({
        "source": {"x": 1, "y": "${inherit_from:source.x}"},
        "target": {"_inherit_from": "source"},
    })
    GlobalConfigDictParser()._recursively_swap_keys(config)

    The outer move removes source before resolving it. When the detached source reaches y, resolving its live parent path source raises InheritPathNotFoundError. Expected: {"target": {"y": 1}}.

    With _copy: source instead, the live parent remains, but the nested move removes x only from that live parent. The detached source retains x, so the target incorrectly contains both x and y. This contradicts the existing nested-move behavior, whose expected result removes the original leaf. The new eager source traversal exposes this mismatch between the detached value and the live mutation target.

    Correction: Change the working-context contract between _resolved_swap_source and _recursively_swap_keys_helper: a nested move must remove its source from the working source subtree, even after that subtree's live ancestor has been consumed. Track external consumed paths separately where needed to preserve top-level move semantics. Merely tolerating an absent live parent would avoid the exception but still leave the moved key in the target. The exact implementation needs this context distinction, so a one-line patch would be incomplete.

    Preservation and proposed acceptance checks: Test the example in both key orders, using both move and copy targets. Moves must leave only target: {y: 1}; copies must leave both source and target, each exactly {y: 1}. Repeat with a property-form nested move of a mapping. Retain the existing chain assertions: a copied intermediate survives, consumed bases don't return, overrides merge, and each link's _delete_key applies. These checks weren't executed.

  • nemo_gym/config/global_config.py line 1351: RISK — Follow consumed intermediate names before filtering rename destinations

    Failure: Could reference repair follow the complete newly resolved chain? Add "mcqa_simple_agent" to referenced in the new Harbor-shaped test. Resolution removes both mcqa_simple_agent and flavor_agent, leaving taskset_agent, but this comprehension discards the base agent's destination because flavor_agent no longer survives. Its environment server still names mcqa_simple_agent: strict mode raises AgentWithoutEnvironmentServerError; otherwise server-reference validation rejects the stale reference. Expected: the unique surviving agent remains behind the original environment server.

    The resources path has the same gap. Starting with the resources-binding fixture, add middle_resources: {_inherit_from: resources} and final_resources: {_inherit_from: middle_resources}. Only final_resources survives, but resource retargeting discards the consumed intermediate and leaves the environment naming resources.

    This one-hop bookkeeping predates the PR; it's a remaining integration gap in the newly supported chained-source behavior. The new resolver reliably consumes intermediates, but its reference consumer still assumes a single edge.

    Correction and preservation: In _recursively_swap_keys, collect all top-level move edges, including intermediate definitions without an explicit server-type block. Follow consumed destinations to surviving endpoints, deduplicate those endpoints, then apply the agent/resources type and ambiguity checks. A surviving intermediate is an endpoint; _copy isn't a rename edge. Both retargeting paths need this calculation. Preserve surviving originals, explicit references to another surviving instance, ignored non-server endpoints, and ambiguity errors for multiple valid endpoints. The coordinated graph change isn't an unambiguous small patch.

    Proposed acceptance checks: Extend the Harbor test to reference the base agent and retain its single taskset_agent mapping in both orders. Add the resources chain in both orders and expect resources_server.name == "final_resources", while the agent's null resources binding stays null. A branch with two surviving endpoints must raise the corresponding ambiguity error. Keep the existing copy and explicit-target assertions: copies must not redirect the original's environment, and explicit surviving targets must remain unchanged. These checks weren't executed.

  • nemo_gym/environment/scaffold.py line 989: RISK — Reserve derivation ancestors when choosing scaffold instance names

    Failure: The removed guard now permits a reused server whose ancestor collides with the generated workload name, but _composition's collision set contains only the selected resources, agent, and environment instances.

    A minimal regression is the new derived-server test, with both occurrences of base_environment_server renamed to reused_environment_server. The scaffold still chooses reused_environment_server as its destination and generates inheritance from shared_environment_server. Merging then creates:

    reused_environment_server:
      _inherit_from: shared_environment_server
    shared_environment_server:
      _inherit_from: reused_environment_server

    Scaffolding writes the files, but resolving the workload raises a cycle error. Expected: choose the free reused_catalog_environment_server name, as the existing direct-collision behavior does, or reject before writing if neither name is free.

    Correction: Carry the occupied instance names of the reused configuration, including its derivation ancestors, into _ReusedVerifier and use that set in _composition instead of only the three selected instances. Include ancestors supplied by included configs when collecting that namespace. Keep the existing fallback and final collision rejection. The exact loading change needs to preserve the current component-root/include handling, so I haven't supplied a partial patch limited to same-file ancestors.

    Preservation and proposed acceptance checks: Add the renamed-ancestor variant above; assert that the generated server is reused_catalog_environment_server, resolution succeeds, and the only mapping is reused_agent -> [reused_catalog_environment_server], with entrypoint == "app.py". Cover an ancestor supplied through config_paths too. If both candidate destination names are occupied, expect ScaffoldError before an asset directory is written. Retain the existing direct-collision assertions, ordinary derived reuse, independent workloads sharing a scorer, and rejection when a route names the server being retired. These checks weren't executed.

Review generated by codex. This was a full review. Request a full review with /review reset=true.

f"`_inherit_from` / `_copy` sources form a cycle: {' -> '.join((*resolving, source))}. "
"Point one of them at a config that does not derive from the others."
)
holder = OmegaConf.create({"value": deepcopy(value)})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Preserve global interpolation context when resolving sources

Resolving the source under a detached {"value": ...} holder breaks ordinary list references to global settings. For example:

policy_model_name: example-model
base:
  aliases: ["${policy_model_name}"]
derived:
  _copy: base

This resolves successfully on the base commit, but now raises InterpolationKeyError at value.aliases[0]: the existing list traversal evaluates v[i] against the holder, where policy_model_name is absent. _inherit_from has the same problem, including through full configuration parsing.

Please preserve the original interpolation context or defer ordinary list interpolation during this pass, and add this regression case.

@yuhezhang-ai

Copy link
Copy Markdown
Contributor

Could you refresh the remaining notes that describe inheritance as limited to one level? For example, the BrowseComp config says a second level “does NOT chain” and cites the TODO removed here; the HLE Diamond README gives the same limitation.

Rewording these as historical explanations would preserve the rationale for the current configurations while avoiding outdated guidance.

@yaoyu-33
yaoyu-33 requested a review from gchlebus November 16, 2026 00:15
@github-actions github-actions Bot added the sla:review-overdue Review response is over the one-business-day SLA label Nov 16, 2026
@yaoyu-33
yaoyu-33 removed the request for review from sephmard November 16, 2026 04:26
@svcnvidia-nemo-ci svcnvidia-nemo-ci added bug Something isn't working area:config Hydra configuration, schemas, composition, and compatibility needs-review PR is ready for code review and waiting on a reviewer labels Nov 16, 2026

This branch had an error being deployed

1 failed deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:config Hydra configuration, schemas, composition, and compatibility bug Something isn't working needs-review PR is ready for code review and waiting on a reviewer sla:review-overdue Review response is over the one-business-day SLA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants