Skip to content

fix(competitive_coding_challenges): emit extracted_code so aggregate metrics count answers - #5336

Merged
weijiac0619 merged 2 commits into
mainfrom
qiaochuz/nvb-6853145-ccc-aggregate-metrics
Nov 3, 2026
Merged

weijiac0619 merged 2 commits into
mainfrom
qiaochuz/nvb-6853145-ccc-aggregate-metrics

Conversation

@qiaochuz-nv

@qiaochuz-nv qiaochuz-nv commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

competitive_coding_challenges aggregate metrics now count submitted code as answers. Before this change every rollout
was reported as no_answer (100%), so majority@k/accuracy dropped to 0 even when pass@k/accuracy was not.

Fixes NVBug 6853145 part B. Refs #4521. Linear GYM-1046.

Cause

compute_metrics calls compute_pass_majority_metrics(..., answer_key="extracted_code"), but
CompetitiveCodingChallengesVerifyResponse has no extracted_code field and verify never set it. Both date from
#1124 (f40a73177). compute_pass_majority_metrics marks a row without the answer key as no_answer and leaves it
out of the majority vote. TestComputeMetrics builds its rows by hand with extracted_code already set, which hid
the gap.

Fix

verify now returns extracted_code: the answer the evaluator graded. CCCEvaluator._evaluate_entry already picks
the last ```txt block for SIMULATION problems and the last ```cpp block otherwise (the whole text
when there is none). It now returns that answer, before includes are added, under GRADED_ANSWER_KEY. verify pops it
from details into extracted_code, so the vote identity is exactly what was graded and the task-type dispatch stays
in one place. The sandbox runner already returns eval_single's full result, so both execution paths carry it. When
evaluation raises, verify falls back to the last ```cpp block. An empty or whitespace-only answer, including
an empty ```cpp block, is None, so it counts as no_answer. The field is set on the response payload rather
than passed as a keyword next to **payload, so a request that already carries it is overwritten instead of raising
TypeError: got multiple values for keyword argument. verify also extracts the answer text once instead of three
times.

Not in this PR: part A of the NVBug. With grade_all_subtasks: false (the default), a subtask that shares tests with
the row's own subtask is scored from the shared tests alone, so total_score can overcount. The README and the
compute_metrics docstring already describe this, so it is a design question for the maintainers, not a bug fix.

Before the fix

Gym 99594f29e (main), with the new tests from this branch:

pytest resources_servers/competitive_coding_challenges/tests/test_app.py -k "extracted_code or no_answer"
E       KeyError: 'extracted_code'
E       AssertionError: assert 'stale' == 'int main() { return 0; }\n'
E       KeyError: 'extracted_code'
FAILED tests/test_app.py::test_verify_emits_the_extracted_code_that_aggregation_reads
FAILED tests/test_app.py::test_verify_replaces_extracted_code_carried_by_a_saved_rollout
FAILED tests/test_app.py::test_verify_reports_an_empty_answer_as_no_answer
3 failed, 44 deselected

The NVBug's standalone reproduction (two rollouts of one problem through verify, then compute_metrics):

rewards: [1.0, 0.0] | extracted_code: [None, None]
metrics: {"majority@1/accuracy": 0.0, "pass@1/accuracy": 50.0, "pass@1/no_answer": 100.0}

After the fix

Gym ef84f51ea (this branch), same commands:

3 passed, 44 deselected
rewards: [1.0, 0.0] | extracted_code: ['int main() { return 0; }\n', 'int main() { return 0; }\n']
metrics: {"majority@1/accuracy": 50.0, "pass@1/accuracy": 50.0, "pass@1/no_answer": 0.0}

Validation

  • pytest resources_servers/competitive_coding_challenges/tests (macOS): 98 passed, 4 skipped, 2 failed. The two
    failures (test_sandbox_evaluator.py::TestProcessSandbox::test_status_follows_exit_code and
    ::test_applies_the_skills_memory_rlimits) fail the same way on main on macOS.
  • New tests: verify then compute_metrics count submitted code as an answer; an extracted_code already on the
    request is overwritten; an empty answer and an empty ```cpp block are no_answer; verify votes on the
    answer the evaluator graded and does not leak it into details; _evaluate_entry reports the ```txt answer
    for SIMULATION and the pre-include ```cpp answer for Batch. All fail on main (or on the previous head) and
    pass here.
  • pre-commit run on the changed files: passed.

Real rollouts (h100)

IOI'24 prepared with gym eval prepare --benchmark ioi, NeMo Skills sandbox built from Skills bcf059af55c2 per the
README, policy Qwen/Qwen3-8B on vLLM. 35 rows × 4 repeats = 140 rollouts, generated once on this branch:

gym eval run --no-serve --agent ioi_simple_agent --input benchmarks/ioi/data/ioi24_benchmark.jsonl \
  --prompt-config benchmarks/prompts/generic/default.yaml --output ioi_rollouts.jsonl \
  --num-repeats 4 --temperature 0.6 --top-p 0.95 --max-output-tokens 16384 +num_repeats_add_seed=true

The same 140 rollouts were then re-verified on main c69f3b15f (twice) and on this branch 4f9bfe482:

gym eval reverify --benchmark ioi --model-type vllm_model ++force=true \
  --inputs ioi_rollouts_materialized_inputs.jsonl --rollouts ioi_rollouts.jsonl --output <side>.jsonl

(++force=true because CCC does not declare a reverify_mode; its verify only recompiles and reruns the code in the
response. The branch's reverified rewards match the rewards recorded at rollout time on all 140 rows.)

main run 1 main run 2 this branch
rows / masked / failure_kind set 140 / 0 / 0 140 / 0 / 0 140 / 0 / 0
extracted_code absent on 140 absent on 140 65 strings, 75 None
pass@1/no_answer 100.0 100.0 53.6
majority@4/no_answer 100.0 100.0 34.3
  • extracted_code is None on exactly the 75 rollouts whose final text is empty (the model ran out of tokens while
    thinking). It is a string on the other 65 (60 with a ```cpp block, 5 without one). No row has the
    bits/stdc++.h include added by grading, and no row has graded_answer left in details.
  • mask_sample and failure_kind match on every row in all three runs.
  • Rewards: the branch differs from main run 1 on 13 rows and from main run 2 on 9 rows, but the two main runs differ
    from each other on 22 rows, and no row differs from both. These flips predate this change. In 13 mosaic rows, main
    run 1 failed to link the problem's checker (undefined reference to 'main') before any test ran. In 9 nile rows, the
    test harness in main run 2 could not find ./graders/nile. Both are infra failures in the
    per-process precompile, which scores them 0 instead of masking them. That is a separate issue, not fixed here.
  • No IOI'24 problem is SIMULATION (IOI'24 uses Batch and Communication), so the ```txt path is covered only by
    the unit tests.

Compatibility

  • Verify responses and rollout files gain an extracted_code field.
  • pass@k/no_answer and majority@k/* for this server change from the always-no-answer values to real ones. Earlier
    reported majority@k numbers for this server were 0 because of this bug.

@qiaochuz-nv qiaochuz-nv added bug Something isn't working QA_fix Fix implemented by a QA team member area:environment Individual environments, benchmarks, verifiers, and environment-specific resources servers needs-review PR is ready for code review and waiting on a reviewer complexity:low Localized change in one scope with a small, straightforward review surface labels Oct 29, 2026
@copy-pr-bot

copy-pr-bot Bot commented Oct 29, 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.

@qiaochuz-nv
qiaochuz-nv requested a review from yaoyu-33 October 29, 2026 22:07
@qiaochuz-nv

Copy link
Copy Markdown
Contributor Author

/ok to test ef84f51

@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

One RISK correctness issue is inline: SIMULATION answers acquire vote identities that differ from the artifact being graded. The C++ path, stale-field replacement, empty-answer handling, and aggregation plumbing otherwise look consistent. Both changed files and their directly affected contracts were inspected; tests were not executed.

RISK — Add representative real-rollout validation

The PR provides unit-test results and a two-response reproduction, but explicitly marks real rollout evidence N/A. This leaves the changed verification-to-rollout-to-aggregation path without the representative model smoke evidence required by the trusted quality bar. This server also supplies the IOI benchmark, so the pinned rubric's before/after benchmark-verifier evidence requirement applies. This is a validation gap, not evidence that per-row rewards changed.

Correction: Record a representative real CCC/IOI model smoke check, identifying the model, tasks/configuration, sample count, commands or artifacts, and before/after reward and aggregate results. Re-verifying the same real generated responses on base and head can isolate this change; a full benchmark run is unnecessary. No source patch is indicated for this evidence gap.

Preservation and acceptance: On those same responses, show unchanged per-row rewards, reward distribution, and masking/failure classifications. Confirm that nonempty submitted answers survive the public verification/rollout response as extracted_code, stop counting as no_answer, and produce the expected majority results. Retain the regression assertions that ordinary C++ extraction is exact, stale values are overwritten, and empty output yields None and 100% no-answer. These are requested validation checks, not executions performed during this review.

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

payload["name"] = payload.get("name") or body.problem_id
generation = _extract_last_assistant_text(body)
# Set on payload, not as a keyword, so a re-verified rollout that already carries the field is overwritten.
payload["extracted_code"] = extract_final_code_block(generation, ("cpp",)) if generation.strip() else None

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 — Use the SIMULATION extractor for simulation vote identities

Failure: For metadata declaring task_type: "SIMULATION", _evaluate_entry extracts the last txt/text/plain block, which is written to solution.odo. This assignment always extracts cpp. Thus Explanation\n```txt\nMOVE\n```` (with actual newlines and a three-backtick closing fence) is graded as MOVE\n, but its vote identity is the entire response. An unrelated C++ fence instead becomes the vote identity. Identical simulation submissions with different explanations therefore split votes. As a static counterexample, three same-task rollouts with scores [1, 1, 0], two identical successful text solutions wrapped in distinct explanations, and one distinct failed solution produce three tied identities: majority@3/accuracy` is approximately 66.7 instead of 100 under the current voting implementation. Both execution backends use this evaluator.

Correction: Preserve the current C++ assignment as the fallback, import extract_task_config from the evaluator module, and insert this task-specific override at the start of the existing try block, before constructing evaluation_entry:

await self._evaluator.load_metadata()
problem_metadata = self._evaluator.get_problem_metadata(body.problem_id, body.competition_id)
task_type = str(extract_task_config(problem_metadata).get("task_type", "Batch"))
if task_type == "SIMULATION":
    payload["extracted_code"] = (
        extract_final_code_block(generation, ("txt", "text", "plain")) if generation.strip() else None
    )

This keeps metadata failures inside the existing error handling and restores task-specific answer extraction before compiler-added includes. Continue sending the original generation to evaluation. Update the field description and evaluator test doubles (load_metadata must be awaitable and metadata lookup must return a dictionary). This suggested code has been traced statically, not executed; verify it before adopting it.

Preservation and acceptance — proposed checks: With SIMULATION metadata, each supported text-fence label must return its content; the last matching text fence must win, unrelated C++ fences must be ignored, and different explanations around the same solution must yield equal identities. The three-rollout example above must then yield 100% majority@3. Batch and MULTIFILE must still select the last C++ block while ignoring text fences; fence-free output must retain the whole-text fallback. Retain the new assertions for exact C++ extraction, stale-field overwrite, and empty output yielding None/100% no-answer. Also preserve existing reward, provider-error masking, unknown-problem handling, and lone-surrogate scoring assertions when updating fixtures.

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.

Agreed that the mismatch is real when problem metadata declares SIMULATION. With the real extract_final_code_block and compute_pass_majority_metrics, your three-rollout example gives majority@3/accuracy 66.7 on this head, versus 100 with the txt/text/plain extraction that _evaluate_entry grades.

I'd rate it a NOTE for this PR, though:

  • No in-repo benchmark reaches SIMULATION. IOI'24 and IOI'26 run on the huggingface/ioi harness, which handles only Batch and Communication (ioi26/prepare.py).
  • Only majority@k moves. Rewards, pass@k, total_score and no_answer don't.
  • On main, that metric is 0 for every problem.

If it gets fixed, here or in a follow-up, loading metadata in verify() has two costs. It copies the evaluator's task-type dispatch into a second place. The extra lookup also breaks the MagicMock evaluators and the assert_called_once_with checks at test_app.py#L234 and #L268.

A single-source option avoids both:

  1. Have _evaluate_entry return the pre-add_includes completion it graded. The sandbox path already passes the runner's full result back (sandbox_evaluator.py#L67-L74).
  2. Pop that completion from details in verify().
  3. Fall back to the current cpp extraction when evaluation raises.

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 4f9bfe4, using yaoyu-33's single-source option rather than a second metadata lookup in verify(). _evaluate_entry now returns the answer it graded (the last txt/text/plain block for SIMULATION, otherwise the last cpp block before includes are added) under GRADED_ANSWER_KEY. verify() pops it from details into extracted_code and falls back to the cpp block only when evaluation raises. The sandbox runner already returns eval_single's full result, so both backends carry it. New tests: test_verify_votes_on_the_answer_the_evaluator_graded (two different explanations around the same txt answer give one identity, and the key does not leak into details), plus test_a_simulation_problem_reports_the_text_answer_it_graded and test_a_batch_problem_reports_its_code_before_includes_are_added in test_ccc_eval.py. All three fail on c9ef060 and pass on 4f9bfe4.

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

Thanks for tracking this down. The fix is small and does what it says: verify() now emits the answer that compute_metrics already votes on, so no_answer and majority@k stop reporting 100% and 0 for every CCC/IOI run. The evaluator still receives the same generation string, so per-row rewards can't change.

There is one small inline NOTE (an empty ```cpp block, and the re-verify comment). Nothing blocking.

On the existing automated review:

  • SIMULATION vote identity: it reproduces, but we'd rate it a NOTE for this PR. The thread reply has the details and a single-source fix option.
  • Real-rollout evidence: the N/A looks justified to us. The evaluator input is byte-identical before and after, and only majority@k and no_answer move; neither is in get_key_metrics.

Checked locally (macOS, no GPU):

  • test_app.py: 47 passed at this head.
  • The 3 new tests fail against main's app.py.
  • The full server suite matches the PR body: 94 passed, 4 skipped, and the 2 known macOS TestProcessSandbox failures.

Comment on lines +415 to +416
# Set on payload, not as a keyword, so a re-verified rollout that already carries the field is overwritten.
payload["extracted_code"] = extract_final_code_block(generation, ("cpp",)) if generation.strip() else None

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.

app.py:415-416

NOTE. An empty or whitespace-only ```cpp block still gives extracted_code == "", which counts as an answer and casts a vote, because compute_pass_majority_metrics treats only None as no_answer. The field comment says an empty answer is None, and checking the extracted code instead of the generation covers both cases. The "re-verified rollout" rationale also doesn't quite hold: gym eval reverify never sends extracted_code back, and a full saved row would still collide on reward/details at L466-L476. So "a request that already carries the field" is more accurate, here and in the name and comment of test_verify_replaces_extracted_code_carried_by_a_saved_rollout.

Suggested change
# Set on payload, not as a keyword, so a re-verified rollout that already carries the field is overwritten.
payload["extracted_code"] = extract_final_code_block(generation, ("cpp",)) if generation.strip() else None
# Set on payload, not as a keyword, so a request that already carries the field is overwritten.
code = extract_final_code_block(generation, ("cpp",))
payload["extracted_code"] = code if code.strip() else None

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.

Done in 4f9bfe4. extracted_code is now None whenever the extracted answer is empty or whitespace-only, which covers an empty ```cpp block as well as an empty generation (test_verify_reports_an_empty_code_block_as_no_answer). The comment now says "a request that already carries the field", and the test is renamed to `test_verify_overwrites_extracted_code_already_on_the_request`. The SIMULATION point is addressed as you suggested; see the reply on the bot thread.

@ananthsub
ananthsub requested a review from yfw October 30, 2026 15:33
yaoyu-33
yaoyu-33 previously approved these changes Oct 30, 2026

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

Approving at ef84f51. The inline NOTE is optional.

@yaoyu-33 yaoyu-33 added ready-to-merge PR is approved, current, and waiting for final CI or merge and removed needs-review PR is ready for code review and waiting on a reviewer labels Oct 30, 2026
@github-actions github-actions Bot added the sla:review-overdue Review response is over the one-business-day SLA label Nov 2, 2026
…ing no_answer

compute_metrics votes on answer_key='extracted_code', but verify never returned that field, so every
rollout counted as no_answer and majority@k accuracy collapsed to 0 (NVBug 6853145, part B). verify now
returns the answer's last cpp block (the whole text when it has none; None for an empty answer). It is set
on the payload so re-verifying a saved rollout that already carries the field replaces it.

Part A of the NVBug (shared-test subtasks credited when grade_all_subtasks is false) is a design question
and is not changed here.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: qiaochuz <[email protected]>
@qiaochuz-nv

Copy link
Copy Markdown
Contributor Author

/ok to test c9ef060

Address review on #5336. extracted_code was always the last cpp block, but SIMULATION
problems grade the last txt block, so identical answers wrapped in different explanations
split majority votes. _evaluate_entry now returns the answer it graded (before includes are
added) under GRADED_ANSWER_KEY; verify pops it into extracted_code and falls back to the cpp
block when evaluation raises. The sandbox runner returns eval_single's full result, so both
backends carry it. An empty or whitespace-only block is now None (no_answer), not "".

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: qiaochuz <[email protected]>
@qiaochuz-nv

Copy link
Copy Markdown
Contributor Author

/ok to test 4f9bfe4

@qiaochuz-nv

Copy link
Copy Markdown
Contributor Author

Real-rollout validation, for the svcnvidia-nemo-ci review (2026-10-29) asking for a representative CCC/IOI smoke run. The full table is in the PR description under Validation → Real rollouts (h100).

Setup on h100: IOI'24 (35 rows × 4 repeats = 140 rollouts) from Qwen/Qwen3-8B on vLLM, using the NeMo Skills sandbox built per the README. The rollouts were generated once, then the same 140 were re-verified with gym eval reverify on main c69f3b15f (twice) and on 4f9bfe482.

  • Masking and failure classification: mask_sample and failure_kind are the same on every row in all three runs (0 masked).
  • extracted_code and no_answer: extracted_code is absent on main. On this branch it is a string for the 65 rollouts with a submitted answer and None for the 75 whose final text is empty (the model ran out of tokens while thinking). pass@1/no_answer goes from 100.0 to 53.6, and majority@4/no_answer from 100.0 to 34.3. The graded answer does not stay in details, and no extracted_code contains the include that grading adds.
  • Rewards: this branch reproduces the rewards recorded at rollout time on all 140 rows. Against main it differs on 13 rows (main run 1) and 9 rows (main run 2). The two main runs differ from each other on 22 rows, and no row differs from both. These flips predate this PR. In 13 mosaic rows, main run 1 failed to link the problem's checker. In 9 nile rows, the test harness in main run 2 could not find ./graders/nile. Both are per-process precompile infra failures that are scored 0 rather than masked. That is out of scope here.
  • SIMULATION: IOI'24 has no SIMULATION problems, so that path is covered only by the unit tests in 4f9bfe482.

@weijiac0619
weijiac0619 enabled auto-merge November 2, 2026 22:48
@weijiac0619
weijiac0619 added this pull request to the merge queue Nov 3, 2026
@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/41574406993

Merged via the queue into main with commit 6c67577 Nov 3, 2026
48 of 51 checks passed
@weijiac0619
weijiac0619 deleted the qiaochuz/nvb-6853145-ccc-aggregate-metrics branch November 3, 2026 04:29
AdamRajfer added a commit that referenced this pull request Nov 3, 2026
…er/run-records-on-store

Brings in #5072 at 4df4ac2, which merged main 101a442 (#5142 single-agent-turn
seed observations, #5336 extracted_code), and the recovery stack on top of it.

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

This branch was previously deployed

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

Labels

area:environment Individual environments, benchmarks, verifiers, and environment-specific resources servers bug Something isn't working complexity:low Localized change in one scope with a small, straightforward review surface QA_fix Fix implemented by a QA team member ready-to-merge PR is approved, current, and waiting for final CI or merge 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