Skip to content

fix(eval): count a budget-masked sample as 0 in evaluation scores - #4847

Closed
AdamRajfer wants to merge 4 commits into
NVIDIA-NeMo:arajfer/stack/infra-masksfrom
AdamRajfer:eval/budget-masks
Closed

AdamRajfer wants to merge 4 commits into
NVIDIA-NeMo:arajfer/stack/infra-masksfrom
AdamRajfer:eval/budget-masks

Conversation

@AdamRajfer

@AdamRajfer AdamRajfer commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Part 5 of 9, merge in order. Stacked on #4868; the diff shows only this part's changes.

What and why. A verifier masked a sample when the model ran out of its own budget, and evaluation left it out of the score, so a model that stopped short scored as if the task had not run. BaseVerifyResponse.mask_reason: budget (omitted when unset) says the mask is for the model's own budget. In gym eval run, gym eval aggregate and gym eval profile such a mask counts as reward 0 in the denominator; the rollouts file keeps mask_sample. swe_agents labels max_iteration, context window, agent wall-clock timeout and test-run timeout as budget; its OOM and evaluator-launch masks carry no reason, and in evaluation name a retried failure_kind. OSWorld labels a rollout the agent stopped because its prompt no longer fit the context window as budget, in evaluation only.

Methodology. SWE-bench, Terminal-Bench and OSWorld score a task the model did not finish within its budget as unsolved.

Eval scores. swe_agents runs with budget masks, and OSWorld runs with rollouts stopped at the context window, move down. Other benchmarks do not move until they set mask_reason.

Training and RL: no change. mask_sample is set by exactly the same six conditions; mask_reason is an added label that only evaluation reads (scoring in gym eval run, gym eval aggregate and gym eval profile, and the retry rule, which does not retry a budget mask); swe_agents' infra failure_kind and OSWorld's context-window mask_reason are set only in evaluation; run_examples and the rollouts file keep the mask. Checked by test_a_mask_names_its_reason (all six conditions plus none, in training mode) and test_evaluator_failure_mask (both modes), and for OSWorld by test_training_keeps_a_context_overflow_mask_unchanged.

Unit tests. responses_api_agents/swe_agents/tests/test_app.py, responses_api_agents/osworld_agent/tests/test_app.py (test_a_context_overflow_mask_is_not_named_infra_in_evaluation, test_training_keeps_a_context_overflow_mask_unchanged), test_failure_retry_rule.py::TestBudgetMasks, test_rollout_collection.py::test_a_budget_mask_counts_as_zero_in_gym_eval_aggregate, test_reward_profile.py::test_gym_eval_profile_scores_a_budget_mask_as_zero_like_aggregation.

🤖 Generated with Claude Code

A verifier masked a sample when the model ran out of its own budget, and
evaluation left it out of the score, so a model that stopped short
scored as if the task had not run. `BaseVerifyResponse.mask_reason:
budget` (omitted when unset) says the mask is for the model's own
budget. In `gym eval run` and `gym eval aggregate` such a mask counts as
reward 0 in the denominator; the rollouts file keeps `mask_sample`.
swe_agents labels max_iteration, context window, agent wall-clock
timeout and test-run timeout as budget; its OOM and evaluator-launch
masks carry no reason, and in evaluation name a retried `failure_kind`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Adam Rajfer <[email protected]>
@AdamRajfer AdamRajfer self-assigned this Oct 21, 2026
@AdamRajfer

Copy link
Copy Markdown
Contributor Author

/ok to test 7bd0066

@copy-pr-bot

copy-pr-bot Bot commented Oct 21, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

@svcnvidia-nemo-ci svcnvidia-nemo-ci added area:evaluation Evaluation, rollout collection, reward profiling, comparison, and exporters bug Something isn't working labels Oct 21, 2026
@AdamRajfer
AdamRajfer changed the base branch from main to arajfer/stack/infra-masks October 21, 2026 14:48
@AdamRajfer
AdamRajfer marked this pull request as ready for review October 21, 2026 15:00
@AdamRajfer
AdamRajfer requested review from Glorf and ananthsub October 21, 2026 15:00
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the needs-review PR is ready for code review and waiting on a reviewer label Oct 21, 2026

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

HOLD — one BLOCKER: profiling saved rollouts can silently report a higher reward than the evaluation score for the same run.

Reviewed all seven changed files and traced SWE response assembly, failure routing, aggregation, and saved-rollout profiling. Static inspection only; tests were not executed.

Note: formal approval is not available for this request, so this review is posted as a comment only.

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

# Appending leaves a missing early repeat behind the repeats that did land. The two
# lists are zipped positionally downstream, so they are reordered together.
scored_rows = persisted_results + counted
scored_rows = _budget_masks_scored_as_zero(persisted_results) + counted

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.

BLOCKER — Apply the budget scoring rule to saved-rollout profiling too

Failure / blast radius: For one task with two repeats—one unmasked reward of 1 and one {reward: 1, mask_sample: true, mask_reason: "budget"}—this conversion makes gym eval run and gym eval aggregate report mean/reward=0.5. However, reward_profile() still passes the saved, masked results directly to select_measured(), which discards the budget repeat and publishes mean/reward=1.0. Thus profiling the same SWE evaluation artifact restores the inflated score this PR removes. Agreement between these views is an existing documented and tested invariant.

Correction: Normalize a metrics-only copy in reward_profile() before both quality selection and quality coverage accounting. Keep completeness validation and completion accounting on the original results. Suggested edits in that function (author should verify before adopting):

from nemo_gym.rollout_collection import _budget_masks_scored_as_zero, loads_jsonl_line

# After the existing align_rows_and_results(rows, results, ...) check:
metric_results = _budget_masks_scored_as_zero(results)
measured_rows, measured_results, masked, _ = select_measured(rows, metric_results)

# Replace the later coverage_by_agent call:
agent_coverage = coverage_by_agent(rows, metric_results)

Preservation: Do not modify saved rewards/masks or run_examples() training results. Unlabelled masks must remain excluded; ordinary unmasked rewards must remain unchanged. Retain the original pre-filter validation so genuinely missing or foreign results cannot disappear during selection.

Acceptance (proposed; not run): Add the two-repeat example above with matching materialized inputs, the same agent, and response: {} on each result; assert both aggregation and profiling produce 0.5 while the rollout file remains unchanged. Add an unlabelled masked repeat and assert it remains excluded, with measured/masked coverage of 2/1. Retain the existing two-view test's assertion that an unlabelled masked zero leaves the mean at 1.0, and the missing/foreign-result checks that reject incomplete or mismatched collections.

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.

Fixed in 6a95564 (fix(eval): score a budget mask as 0 when profiling saved rollouts too), with a test that fails without the fix.

Bot finding 4338971421, PR NVIDIA-NeMo#4847 (part 5, budget masks). gym eval run and gym eval aggregate count
a budget-masked sample as 0, but gym eval profile passed the saved masked results straight to
select_measured, which dropped them, so profiling the same artifact published the higher score.
reward_profile now builds the same metrics-only copy before quality selection and coverage. The
saved file and the completeness checks still see the original results; unlabelled masks stay out.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Adam Rajfer <[email protected]>
Review finding 4339108867, NVIDIA-NeMo#4847 (part 5, budget masks). A rollout the agent stopped because its prompt no longer fit the context window keeps its mask but now carries mask_reason budget in evaluation, so evaluation scores count it as 0, as OSWorld itself ends the episode and scores the task. Training is unchanged: the same mask, with no reason.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Adam Rajfer <[email protected]>
@AdamRajfer

Copy link
Copy Markdown
Contributor Author

/ok to test 3653f26

@AdamRajfer

Copy link
Copy Markdown
Contributor Author

/review reset=true

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

HOLD — one BLOCKER and one RISK remain in OSWorld budget-mask handling.

Reviewed all 11 changed files and traced response assembly, retry routing, aggregation, and saved-rollout profiling. The earlier profiling finding is fixed: reward_profile() now normalizes metrics-only input before selection and coverage, while completeness and completion accounting retain the original results.

Static inspection only; tests and model smoke rollouts were not executed.

Note: formal approval is not available for this request, so this review is posted as a comment only.

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

so training still leaves the sample out of the gradient. Any other mask keeps its treatment.
"""
return [
{**result, MASK_SAMPLE_KEY: False, "reward": 0.0}

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.

BLOCKER — Apply the zero to OSWorld’s headline scores too

Failure / blast radius: This copy changes only reward. OSWorld’s compute_metrics() instead reads verifier_metadata.osworld_score for its binary and raw success rates, and publishes both as key metrics. With one ordinary success and one {reward: 1, mask_sample: true, mask_reason: "budget", verifier_metadata: {osworld_score: 1}}, evaluation reports mean/reward=0.5 but both OSWorld success rates remain 100%. This is reachable: the client evaluates the current desktop after a context-overflow stop, so that evaluation can still return a positive score. The new budget rule must also affect these headline scores.

Correction: In OSWorldAgent.compute_metrics(), replace the score = metadata.get(...) assignment with the following metrics-only selection (suggested code; author must verify):

score = (
    rollout.get("reward", 0.0)
    if rollout.get("mask_reason") == "budget"
    else metadata.get("osworld_score", rollout.get("reward", 0.0))
)

The collector has already normalized a scored budget result’s reward to zero, while retaining its reason. Both OSWorld rates must consume that normalized value rather than restore the original score.

Preservation: Leave saved rewards, masks, and osworld_score untouched. Ordinary unmasked partial scores must still use osworld_score—for example, binary reward 0 with raw score 0.5 must retain its partial raw credit. Unlabelled masks remain excluded. Unmasked horizon outcomes retain their evaluated score.

Acceptance (proposed; not run): Pass the two distinct rollout keys above through budget normalization and agent.aggregate_metrics(): expect mean/reward=0.5, binary success rate 50%, and raw reward rate 50%; assert the original budget result remains masked with score 1. Separately retain the partial-credit assertions in test_metrics_report_binary_and_raw_osworld_scores, including raw sum 1.75 and one binary success, and the neighboring unlabelled-mask exclusion test.

):
self.failure_kind = PROVIDER_UNAVAILABLE
self.failure_reason = self.failure_reason or self.runtime_admission_reason
elif self.mask_sample and self.policy_stop_reason == CONTEXT_OVERFLOW_STOP_REASON and is_eval_mode():

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.

RISK — Let the runtime failure cause take precedence over a context stop

Failure / blast radius: A context-overflow stop can be followed by an evaluator failure. The client gives that evaluator failure precedence, returning runtime_admission_reason="evaluator_error", evaluation_completed=False, and mask_sample=True, while preserving policy_stop_reason="model_context_overflow". This new branch nevertheless labels it budget. Consequently, failure routing treats it as non-infra, collection persists it as completed, and evaluation turns an unusable evaluator result into a final model-budget zero. The context stop must not override an independently reported evaluator failure.

Correction: Replace the existing naming if/elif block in validate_runtime_admission() with cause-aware classification. For the current child-result contract, the budget exception is the context-overflow stop whose admission cause is model_call_failed, not every mask that retains that stop reason. Suggested replacement, for author verification:

if self.mask_sample and self.failure_kind is None and is_eval_mode():
    context_budget = (
        self.policy_stop_reason == CONTEXT_OVERFLOW_STOP_REASON
        and self.runtime_admission_reason == "model_call_failed"
    )
    if context_budget:
        self.mask_reason = "budget"
    else:
        self.failure_kind = PROVIDER_UNAVAILABLE
        self.failure_reason = self.failure_reason or self.runtime_admission_reason

This keeps an explicit failure kind authoritative and makes the primary runtime cause decide whether the mask is an infra failure or a budget exhaustion.

Preservation: A context overflow with admission reason model_call_failed must still receive budget in evaluation, score zero, and avoid retry. A transport failure must still receive provider_unavailable. Training must add neither label, and ordinary unmasked DONE/FAIL/horizon outcomes must remain untouched.

Acceptance (proposed; not run): Extend the context-overflow regression setup with evaluation_completed=False, admission/termination reason evaluator_error, and the same context-overflow stop. Expect mask_reason is None, failure_kind == "provider_unavailable", and _masked_result_names_infra(...) is True; collection should route it to the failures sidecar so resume can retry it. Retain the existing normal-overflow assertion of budget with no infra classification, the transport case’s infra classification, and the training assertion (True, None, None).

@AdamRajfer

Copy link
Copy Markdown
Contributor Author

Closing this version to consolidate review on #5072 (failure reporting) and #5073 (saved-state recovery). This does not mean those PRs implement every proposal from this earlier stack; scoring policy and persistence follow-ups remain separate.

@AdamRajfer AdamRajfer closed this Oct 26, 2026

This branch was previously deployed

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

Labels

area:evaluation Evaluation, rollout collection, reward profiling, comparison, and exporters 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.

2 participants