Skip to content

fix: address CLI issues - #1829

Merged
marta-sd merged 9 commits into
mainfrom
martas/dx-review-cli-fixes
Jul 1, 2026
Merged

marta-sd merged 9 commits into
mainfrom
martas/dx-review-cli-fixes

Conversation

@marta-sd

Copy link
Copy Markdown
Contributor

No description provided.

marta-sd added 4 commits June 30, 2026 12:38
…ion errors

Signed-off-by: Marta Stepniewska-Dziubinska <[email protected]>
…nt matches

Signed-off-by: Marta Stepniewska-Dziubinska <[email protected]>
…status and pip_list

Signed-off-by: Marta Stepniewska-Dziubinska <[email protected]>
…sonl files

Signed-off-by: Marta Stepniewska-Dziubinska <[email protected]>
@marta-sd
marta-sd requested a review from wprazuch June 30, 2026 10:40
@marta-sd marta-sd self-assigned this Jun 30, 2026
@copy-pr-bot

copy-pr-bot Bot commented Jun 30, 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.

@marta-sd

Copy link
Copy Markdown
Contributor Author

/ok to test 00536e7

Comment thread nemo_gym/cli/main.py Outdated
_value_flag("prompt-config", "prompt_config", "Prompt template YAML to apply."),
_value_flag("output", "output_jsonl_fpath", "Output JSONL file.", aliases=("-o",)),
_value_flag("input", "input_jsonl_fpath", "Raw input JSONL file.", aliases=("-i",), required=True),
_value_flag("prompt-config", "prompt_config", "Prompt template YAML to apply.", required=True),

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.

nit: this closes the hydra path of overriding, if this is fine then we should be good:

uv run gym eval profile +materialized_inputs_jsonl_fpath=/tmp/i.jsonl +rollouts_jsonl_fpath=/tmp/r.jsonl
usage: gym eval profile [-h] [-v] --inputs INPUTS --rollouts
                        ROLLOUTS
gym eval profile: error: the following arguments are required: --inputs, --rollouts

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

oh right, I couldn't remember why I didn't mark these flags as required... xD let me revert and just rely on error handling

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

reverted in 346ee19

Comment thread nemo_gym/cli/main.py
command.target(args, overrides)
else:
dispatch(command.target, overrides)
except ValidationError as exc:

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.

So not sure, if this will be always ValidationError - I asked my Claude to investigate it and here is what it got:

What the PR was trying to do

When you run a gym command, the first thing each command does is validate your config (the flags/overrides you passed) with pydantic. If you forget a required value, pydantic raises a ValidationError — normally an ugly multi-line traceback. The PR wanted to catch that and print a friendly one-liner instead. So in main() it added (main.py:675–682):

try:
    if callable(command.target):
        command.target(args, overrides)   # 677
    else:
        dispatch(command.target, overrides)  # 679
except ValidationError as exc:
    getattr(args, "_parser", parser).error(_format_validation_error(exc))  # 682

And _format_validation_error turns a ValidationError into either:
- "missing required configuration: <field>. Provide each via its flag (see --help) or as a +<field>=<value> override." (for a missing field), or
- "invalid configuration: <field> (<msg>)." (for a wrong type/value).

The bug: the try is wrapped around the wrong scope

Look at what's inside the try: command.target(...) / dispatch(...) — that's the entire command, start to finish, not just the config-validation step.

The intended target is the validation at the top of a command, e.g. collect_rollouts (eval.py:390):
config = RolloutCollectionConfig.model_validate(get_global_config_dict())  # <-- user's config; nice to catch
Catching that ValidationError and rendering it as "missing config" is correct.

But the command keeps running after that line — it does the actual rollout work, which makes HTTP calls to resources servers. And there's a second, unrelated model_validate buried deep in that work (rollout_collection.py:610):
agg_result = AggregateMetrics.model_validate(await get_response_json(agg_response))
This validates the JSON a resources server sent back from its /aggregate_metrics endpoint. It has nothing to do with your CLI config.

The failure trace

1. A resources server returns a malformed/incomplete aggregate-metrics payload (a server bug, a version mismatch, a truncated response — anything).
2. Line 610 AggregateMetrics.model_validate(...) raises a pydantic ValidationError.
3. That error is not a ConfigError, so the @exit_cleanly_on_config_error decorator on collect_rollouts (eval.py:388) does not catch it. It propagates up and out of the command.
4. It lands in main()'s except ValidationError (line 680), which calls _format_validation_error and prints:
gym eval run: error: invalid configuration: group_level_metrics (Input should be a valid list); agent_metrics (Input should be a valid dictionary).

Why that message is wrong

- Your CLI invocation and config were perfectly fine. The real problem is a server returned bad data.
- The message says "fix your configuration… pass it as a flag or +field=value" — but group_level_metrics / agent_metrics are server-response fields. There is no such CLI flag or config key. Following the advice does nothing.
- It hides the real cause and sends you debugging your command line instead of the server. (And if the server omits a required field, you get the even more misleading "missing required configuration: group_level_metrics. Provide via +group_level_metrics=<value>".)

In one line: the catch is meant for "the user's config failed validation" but it actually catches "any pydantic ValidationError raised anywhere in the whole command," including data validation deep in the rollout.

Why the repro is Python, not a gym command

To hit this via the real CLI you'd need a live resources server returning a malformed /aggregate_metrics body — heavy to stand up. So the repro constructs the exact same failing validation and feeds it through the exact same renderer main() uses, proving the message that would be shown:

uv run python -c "
from pydantic import ValidationError
from nemo_gym.base_resources_server import AggregateMetrics   # the model validated at rollout_collection.py:610
from nemo_gym.cli.main import _format_validation_error          # the renderer main() calls at line 682
try:
    AggregateMetrics.model_validate({'group_level_metrics':'x','agent_metrics':1})  # simulate a bad server response
except ValidationError as e:
    print('gym eval run: error:', _format_validation_error(e))
"
# -> gym eval run: error: invalid configuration: group_level_metrics (...); agent_metrics (...).

The fix

Scope the friendly rendering to only the config-validation step. Either:
- (a) validate the command's config in main() before dispatch, wrap only that in the try, and run the command itself outside the try; or
- (b) keep the catch but only render-and-exit when the ValidationError came from the command's own config model, and re-raise otherwise so a genuine server/data error surfaces as a real error rather than a fake "missing config" message.

Sorry for parsing Claude exactly, but maybe it's easier with grabbing entire context

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

so the purpose of this was to capture errors related to misconfiguration. I don't try to catch all possible errors, just the ones that are directly related to user passing wrong params. but it caught one important thing - that the source of validation error might be different. Let me try to fix

@marta-sd marta-sd Jun 30, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I went with the option b (460d991)

@marta-sd

Copy link
Copy Markdown
Contributor Author

/ok to test 24f5561

@marta-sd
marta-sd enabled auto-merge (squash) June 30, 2026 17:19
@marta-sd marta-sd added the r0.4.0 Auto-cherrypick to release branch. Apply before merge; cherrypick happens after merge. label Jul 1, 2026
@marta-sd

marta-sd commented Jul 1, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 1ca4fca

@marta-sd
marta-sd merged commit 4703bdc into main Jul 1, 2026
22 checks passed
@marta-sd
marta-sd deleted the martas/dx-review-cli-fixes branch July 1, 2026 06:34
ko3n1g pushed a commit that referenced this pull request Jul 1, 2026
beep boop [🤖]: Hi @marta-sd 👋,

    we've cherry picked #1829 into  for you! 🚀

    Please review and approve this cherry pick by your convenience!

Signed-off-by: Marta Stepniewska-Dziubinska <[email protected]>
Signed-off-by: NeMo Bot <[email protected]>
Co-authored-by: Marta Stepniewska-Dziubinska <[email protected]>

This branch was previously deployed

1 inactive deployment
public — 1ca4fcaa Deployed Jul 1, 2026 by copy-pr-bot[bot] via release / finalize / notify #579
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

r0.4.0 Auto-cherrypick to release branch. Apply before merge; cherrypick happens after merge.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants