Repository navigation
fix(competitive_coding_challenges): emit extracted_code so aggregate metrics count answers - #5336
Conversation
|
/ok to test ef84f51 |
svcnvidia-nemo-ci
left a comment
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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@kmoves. Rewards, pass@k,total_scoreandno_answerdon'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:
- Have
_evaluate_entryreturn the pre-add_includescompletion it graded. The sandbox path already passes the runner's full result back (sandbox_evaluator.py#L67-L74). - Pop that completion from
detailsinverify(). - Fall back to the current
cppextraction when evaluation raises.
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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@kandno_answermove; neither is inget_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
TestProcessSandboxfailures.
| # 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 |
There was a problem hiding this comment.
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.
| # 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 |
There was a problem hiding this comment.
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.
…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]>
|
/ok to test c9ef060 |
ef84f51 to
c9ef060
Compare
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]>
|
/ok to test 4f9bfe4 |
|
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
|
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/41574406993 |
…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]>
What does this PR do?
competitive_coding_challengesaggregate metrics now count submitted code as answers. Before this change every rolloutwas reported as
no_answer(100%), somajority@k/accuracydropped to 0 even whenpass@k/accuracywas not.Fixes NVBug 6853145 part B. Refs #4521. Linear GYM-1046.
Cause
compute_metricscallscompute_pass_majority_metrics(..., answer_key="extracted_code"), butCompetitiveCodingChallengesVerifyResponsehas noextracted_codefield andverifynever set it. Both date from#1124 (
f40a73177).compute_pass_majority_metricsmarks a row without the answer key asno_answerand leaves itout of the majority vote.
TestComputeMetricsbuilds its rows by hand withextracted_codealready set, which hidthe gap.
Fix
verifynow returnsextracted_code: the answer the evaluator graded.CCCEvaluator._evaluate_entryalready picksthe last
```txtblock for SIMULATION problems and the last```cppblock otherwise (the whole textwhen there is none). It now returns that answer, before includes are added, under
GRADED_ANSWER_KEY.verifypops itfrom
detailsintoextracted_code, so the vote identity is exactly what was graded and the task-type dispatch staysin one place. The sandbox runner already returns
eval_single's full result, so both execution paths carry it. Whenevaluation raises,
verifyfalls back to the last```cppblock. An empty or whitespace-only answer, includingan empty
```cppblock, isNone, so it counts asno_answer. The field is set on the response payload ratherthan passed as a keyword next to
**payload, so a request that already carries it is overwritten instead of raisingTypeError: got multiple values for keyword argument.verifyalso extracts the answer text once instead of threetimes.
Not in this PR: part A of the NVBug. With
grade_all_subtasks: false(the default), a subtask that shares tests withthe row's own subtask is scored from the shared tests alone, so
total_scorecan overcount. The README and thecompute_metricsdocstring 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"The NVBug's standalone reproduction (two rollouts of one problem through
verify, thencompute_metrics):After the fix
Gym
ef84f51ea(this branch), same commands:Validation
pytest resources_servers/competitive_coding_challenges/tests(macOS): 98 passed, 4 skipped, 2 failed. The twofailures (
test_sandbox_evaluator.py::TestProcessSandbox::test_status_follows_exit_codeand::test_applies_the_skills_memory_rlimits) fail the same way on main on macOS.verifythencompute_metricscount submitted code as an answer; anextracted_codealready on therequest is overwritten; an empty answer and an empty
```cppblock areno_answer;verifyvotes on theanswer the evaluator graded and does not leak it into
details;_evaluate_entryreports the```txtanswerfor SIMULATION and the pre-include
```cppanswer for Batch. All fail on main (or on the previous head) andpass here.
pre-commit runon the changed files: passed.Real rollouts (h100)
IOI'24 prepared with
gym eval prepare --benchmark ioi, NeMo Skills sandbox built from Skillsbcf059af55c2per theREADME, policy
Qwen/Qwen3-8Bon 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=trueThe same 140 rollouts were then re-verified on main
c69f3b15f(twice) and on this branch4f9bfe482:(
++force=truebecause CCC does not declare areverify_mode; itsverifyonly recompiles and reruns the code in theresponse. The branch's reverified rewards match the rewards recorded at rollout time on all 140 rows.)
failure_kindsetextracted_codeNonepass@1/no_answermajority@4/no_answerextracted_codeisNoneon exactly the 75 rollouts whose final text is empty (the model ran out of tokens whilethinking). It is a string on the other 65 (60 with a
```cppblock, 5 without one). No row has thebits/stdc++.hinclude added by grading, and no row hasgraded_answerleft indetails.mask_sampleandfailure_kindmatch on every row in all three runs.from each other on 22 rows, and no row differs from both. These flips predate this change. In 13
mosaicrows, mainrun 1 failed to link the problem's checker (
undefined reference to 'main') before any test ran. In 9nilerows, thetest harness in main run 2 could not find
./graders/nile. Both are infra failures in theper-process precompile, which scores them 0 instead of masking them. That is a separate issue, not fixed here.
```txtpath is covered only bythe unit tests.
Compatibility
extracted_codefield.pass@k/no_answerandmajority@k/*for this server change from the always-no-answer values to real ones. Earlierreported
majority@knumbers for this server were 0 because of this bug.